diff --git a/README.md b/README.md
index 007fd0cd6..37c919ac2 100644
--- a/README.md
+++ b/README.md
@@ -1,58 +1,15 @@
-XMind
-=====
-
-[XMind](http://www.xmind.net) is an open source project that contributes to
-building a cutting-edge brainstorming/mind-mapping facility, focused on both
-usability and extendability. It helps people in capturing ideas into visually
-self-organized charts and sharing them for collaboration and communication.
-Currently supporting mind maps, fishbone diagrams, tree diagrams, org-charts,
-logic charts, and even spreadsheets. Often used for knowledge management,
-meeting minutes, task management, and GTD.
-
-**[Downloads Available For Windows/Mac/Ubuntu](http://www.xmind.net/download/?ref=github-home)**
-
-License
--------
-
-XMind is dual licensed under 2 open source licenses: the [Eclipse Public
-License (EPL) v1.0](http://www.eclipse.org/legal/epl-v10.html) and the [GNU
-Lesser General Public License (LGPL) v3](http://www.gnu.org/licenses/lgpl.html).
-
-For licensees that wish to distribute XMind 3, modify the source code, and/or
-build extensions, the EPL can be used to maintain copyleft of the original code
-base while encouraging innovation with commercial and other open source
-offerings incorporating XMind.
-
-At the same time, for licensees that are concerned with incompatibility between
-the EPL and GPL, we are providing the LGPL as an option to license XMind.
-
-Please note that we are not providing legal advice here and you should not rely
-on the above statements as such. For a full understanding of your rights and
-obligations under these licenses, please consult the full text of the EPL
-and/or LGPL, and your legal counsel as appropriate.
-
-How To Run/Debug
-----------------
-
-1. Download and install [JDK v1.8 or higher](http://www.oracle.com/technetwork/java/javase/downloads/index.html).
-1. Download and install [Eclipse SDK v4.6 or higher](http://download.eclipse.org/eclipse/downloads/).
-1. Make a clean workspace.
-1. Import all bundles, features and releng projects into the workspace.
-1. Open `org.xmind.cathy.target/cathy.target` with the default *Target Editor*
- and click on 'Set as Target Platform' in the top-right corner of the opened
- editor (you may have to wait for Eclipse to download all necessary
- dependencies).
-1. Open `org.xmind.cathy.product/cathy.product` with the default *Product
- Configuration Editor* and, in the first 'Overview' tab, click on 'Launch an
- Eclipse application' or 'Launch an Eclipse application in Debug mode'.
-
-And, by the way...
-
-- If you're using an OS *other than* Windows and encounter compiling errors
- in plugin `org.xmind.cathy.win32`, just delete it from the workspace.
-
-How To Contribute
------------------
-
-Any issue report or pull request will be highly welcomed!
-
+XMind is an open source project that contributes to building a cutting-edge brainstorming/mind-mapping facility, focused on both usability and extendability. It helps people in capturing ideas into visually self-organized charts and sharing them for collaboration and communication. Currently supporting mind maps, fishbone diagrams, tree diagrams, org-charts, logic charts, and even spreadsheets. Often used for knowledge management, meeting minutes, task management, and GTD.
+
+XMind is dual licensed under 2 open source licenses: the Eclipse Public License v1.0 (EPL), which is available at http://www.eclipse.org/legal/epl-v10.html , and the GNU Lesser General Public License v3 (LGPL), which is available at http://www.gnu.org/licenses/lgpl.html.
+
+For licensees that wish to distribute XMind 3, modify the source code, and/or build extensions, the EPL can be used to maintain copyleft of the original code base while encouraging innovation with commercial and other open source offerings incorporating XMind.
+
+At the same time, for licensees that are concerned with incompatibility between the EPL and GPL, we are providing the LGPL as an option to license XMind.
+
+Please note that we are not providing legal advice here and you should not rely on the above statements as such.
+
+For a full understanding of your rights and obligations under these licenses, please consult the full text of the EPL and/or LGPL, and your legal counsel as appropriate.
+
+XMind source pack doesn't include required Eclipse plug-ins. To compile XMind source pack, you need download XMind.
+
+**[Download XMind for Windows/Mac/Ubuntu Now!](https://www.xmind.net/download/)**
diff --git a/bundles/org.xmind.cathy.fonts/.gitignore b/bundles/org.xmind.cathy.fonts/.gitignore
index 3ffab8564..278670924 100644
--- a/bundles/org.xmind.cathy.fonts/.gitignore
+++ b/bundles/org.xmind.cathy.fonts/.gitignore
@@ -1,15 +1,15 @@
-.metadata
-bin
-tmp
-*.tmp
-*.bak
-*.swp
-*~.nib
-local.properties
-.loadpath
-
-# External tool builders
-.externalToolBuilders/
-
-# Folder containing Maven build results
-target/
+.metadata
+bin
+tmp
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Folder containing Maven build results
+target/
diff --git a/bundles/org.xmind.cathy.fonts/.project b/bundles/org.xmind.cathy.fonts/.project
index 8bf2e3897..49b3d3299 100644
--- a/bundles/org.xmind.cathy.fonts/.project
+++ b/bundles/org.xmind.cathy.fonts/.project
@@ -1,22 +1,22 @@
-
-
- org.xmind.cathy.fonts
-
-
-
-
-
- org.eclipse.pde.ManifestBuilder
-
-
-
-
- org.eclipse.pde.SchemaBuilder
-
-
-
-
-
- org.eclipse.pde.PluginNature
-
-
+
+
+ org.xmind.cathy.fonts
+
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+
+
diff --git a/bundles/org.xmind.cathy.fonts/.settings/org.eclipse.core.resources.prefs b/bundles/org.xmind.cathy.fonts/.settings/org.eclipse.core.resources.prefs
index 4824b8026..99f26c020 100644
--- a/bundles/org.xmind.cathy.fonts/.settings/org.eclipse.core.resources.prefs
+++ b/bundles/org.xmind.cathy.fonts/.settings/org.eclipse.core.resources.prefs
@@ -1,2 +1,2 @@
-eclipse.preferences.version=1
-encoding/=UTF-8
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/bundles/org.xmind.cathy.fonts/.settings/org.eclipse.core.runtime.prefs b/bundles/org.xmind.cathy.fonts/.settings/org.eclipse.core.runtime.prefs
index f8a67de1d..deae05a97 100644
--- a/bundles/org.xmind.cathy.fonts/.settings/org.eclipse.core.runtime.prefs
+++ b/bundles/org.xmind.cathy.fonts/.settings/org.eclipse.core.runtime.prefs
@@ -1,2 +1,2 @@
-eclipse.preferences.version=1
-line.separator=\r\n
+eclipse.preferences.version=1
+line.separator=\r\n
diff --git a/bundles/org.xmind.cathy.fonts/META-INF/MANIFEST.MF b/bundles/org.xmind.cathy.fonts/META-INF/MANIFEST.MF
index 1a96f3eb9..9dc4a9148 100644
--- a/bundles/org.xmind.cathy.fonts/META-INF/MANIFEST.MF
+++ b/bundles/org.xmind.cathy.fonts/META-INF/MANIFEST.MF
@@ -1,6 +1,6 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %Bundle-Name
-Bundle-SymbolicName: org.xmind.cathy.fonts
-Bundle-Version: 3.7.0.qualifier
-Bundle-Vendor: %Bundle-Vendor
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name
+Bundle-SymbolicName: org.xmind.cathy.fonts
+Bundle-Version: 3.7.9.qualifier
+Bundle-Vendor: %Bundle-Vendor
diff --git a/bundles/org.xmind.cathy.fonts/OSGI-INF/l10n/bundle.properties b/bundles/org.xmind.cathy.fonts/OSGI-INF/l10n/bundle.properties
index 4e2900fed..79659b9c5 100644
--- a/bundles/org.xmind.cathy.fonts/OSGI-INF/l10n/bundle.properties
+++ b/bundles/org.xmind.cathy.fonts/OSGI-INF/l10n/bundle.properties
@@ -1,3 +1,3 @@
-#Properties file for org.xmind.cathy.fonts
-Bundle-Vendor = XMind Ltd.
+#Properties file for org.xmind.cathy.fonts
+Bundle-Vendor = XMind Ltd.
Bundle-Name = Additional Fonts For XMind
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy.fonts/README b/bundles/org.xmind.cathy.fonts/README
index fbf4c43f4..3b537de10 100644
--- a/bundles/org.xmind.cathy.fonts/README
+++ b/bundles/org.xmind.cathy.fonts/README
@@ -1,3 +1,3 @@
-This plugin does not provide font files directly, but provides legal
-information in about.html for custom fonts bundled with XMind RCP product
-distribution.
+This plugin does not provide font files directly, but provides legal
+information in about.html for custom fonts bundled with XMind RCP product
+distribution.
diff --git a/bundles/org.xmind.cathy.fonts/about.html b/bundles/org.xmind.cathy.fonts/about.html
index 7820c2dcf..c9a97bc34 100644
--- a/bundles/org.xmind.cathy.fonts/about.html
+++ b/bundles/org.xmind.cathy.fonts/about.html
@@ -1,20 +1,20 @@
-
-
-
-
-About
-
-
-About This Content
-
-Oct 12, 2015
-
-
-This software include open source fonts which are available with
-Apache License 2.0 or SIL Open Font License .
-
-
-
-
-
+
+
+
+
+About
+
+
+About This Content
+
+Oct 12, 2015
+
+
+This software include open source fonts which are available with
+Apache License 2.0 or SIL Open Font License .
+
+
+
+
+
diff --git a/bundles/org.xmind.cathy.fonts/build.properties b/bundles/org.xmind.cathy.fonts/build.properties
index 3d1164dce..7f8c70717 100644
--- a/bundles/org.xmind.cathy.fonts/build.properties
+++ b/bundles/org.xmind.cathy.fonts/build.properties
@@ -1,2 +1,2 @@
-bin.includes = META-INF/,\
- OSGI-INF/
+bin.includes = META-INF/,\
+ OSGI-INF/
diff --git a/bundles/org.xmind.cathy.fonts/pom.xml b/bundles/org.xmind.cathy.fonts/pom.xml
index 57e73351d..579e83c8a 100644
--- a/bundles/org.xmind.cathy.fonts/pom.xml
+++ b/bundles/org.xmind.cathy.fonts/pom.xml
@@ -1,16 +1,16 @@
-
-
- 4.0.0
- org.xmind.cathy.plugins
- org.xmind.cathy.fonts
- 3.7.0-SNAPSHOT
- eclipse-plugin
-
- org.xmind.releng
- org.xmind.cathy.releng
- 3.7.0-SNAPSHOT
- ../../
-
-
+
+
+ 4.0.0
+ org.xmind.cathy.plugins
+ org.xmind.cathy.fonts
+ 3.7.9-SNAPSHOT
+ eclipse-plugin
+
+ org.xmind.releng
+ org.xmind.cathy.releng
+ 3.7.9-SNAPSHOT
+ ../../
+
+
diff --git a/bundles/org.xmind.cathy.win32/.classpath b/bundles/org.xmind.cathy.win32/.classpath
index 9643481c7..68de192ec 100644
--- a/bundles/org.xmind.cathy.win32/.classpath
+++ b/bundles/org.xmind.cathy.win32/.classpath
@@ -1,12 +1,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bundles/org.xmind.cathy.win32/.gitignore b/bundles/org.xmind.cathy.win32/.gitignore
index 3ffab8564..278670924 100644
--- a/bundles/org.xmind.cathy.win32/.gitignore
+++ b/bundles/org.xmind.cathy.win32/.gitignore
@@ -1,15 +1,15 @@
-.metadata
-bin
-tmp
-*.tmp
-*.bak
-*.swp
-*~.nib
-local.properties
-.loadpath
-
-# External tool builders
-.externalToolBuilders/
-
-# Folder containing Maven build results
-target/
+.metadata
+bin
+tmp
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Folder containing Maven build results
+target/
diff --git a/bundles/org.xmind.cathy.win32/.settings/org.eclipse.core.resources.prefs b/bundles/org.xmind.cathy.win32/.settings/org.eclipse.core.resources.prefs
index 4824b8026..99f26c020 100644
--- a/bundles/org.xmind.cathy.win32/.settings/org.eclipse.core.resources.prefs
+++ b/bundles/org.xmind.cathy.win32/.settings/org.eclipse.core.resources.prefs
@@ -1,2 +1,2 @@
-eclipse.preferences.version=1
-encoding/=UTF-8
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/bundles/org.xmind.cathy.win32/.settings/org.eclipse.core.runtime.prefs b/bundles/org.xmind.cathy.win32/.settings/org.eclipse.core.runtime.prefs
index f8a67de1d..deae05a97 100644
--- a/bundles/org.xmind.cathy.win32/.settings/org.eclipse.core.runtime.prefs
+++ b/bundles/org.xmind.cathy.win32/.settings/org.eclipse.core.runtime.prefs
@@ -1,2 +1,2 @@
-eclipse.preferences.version=1
-line.separator=\r\n
+eclipse.preferences.version=1
+line.separator=\r\n
diff --git a/bundles/org.xmind.cathy.win32/.settings/org.eclipse.pde.prefs b/bundles/org.xmind.cathy.win32/.settings/org.eclipse.pde.prefs
index 050e14d72..9ba90cb01 100644
--- a/bundles/org.xmind.cathy.win32/.settings/org.eclipse.pde.prefs
+++ b/bundles/org.xmind.cathy.win32/.settings/org.eclipse.pde.prefs
@@ -1,32 +1,32 @@
-compilers.f.unresolved-features=1
-compilers.f.unresolved-plugins=1
-compilers.incompatible-environment=2
-compilers.p.build=1
-compilers.p.build.bin.includes=1
-compilers.p.build.encodings=2
-compilers.p.build.java.compiler=2
-compilers.p.build.java.compliance=1
-compilers.p.build.missing.output=2
-compilers.p.build.output.library=1
-compilers.p.build.source.library=1
-compilers.p.build.src.includes=1
-compilers.p.deprecated=1
-compilers.p.discouraged-class=1
-compilers.p.internal=1
-compilers.p.missing-packages=2
-compilers.p.missing-version-export-package=2
-compilers.p.missing-version-import-package=2
-compilers.p.missing-version-require-bundle=2
-compilers.p.no-required-att=0
-compilers.p.not-externalized-att=2
-compilers.p.unknown-attribute=1
-compilers.p.unknown-class=1
-compilers.p.unknown-element=1
-compilers.p.unknown-identifier=1
-compilers.p.unknown-resource=1
-compilers.p.unresolved-ex-points=0
-compilers.p.unresolved-import=0
-compilers.s.create-docs=false
-compilers.s.doc-folder=doc
-compilers.s.open-tags=1
-eclipse.preferences.version=1
+compilers.f.unresolved-features=1
+compilers.f.unresolved-plugins=1
+compilers.incompatible-environment=2
+compilers.p.build=1
+compilers.p.build.bin.includes=1
+compilers.p.build.encodings=2
+compilers.p.build.java.compiler=2
+compilers.p.build.java.compliance=1
+compilers.p.build.missing.output=2
+compilers.p.build.output.library=1
+compilers.p.build.source.library=1
+compilers.p.build.src.includes=1
+compilers.p.deprecated=1
+compilers.p.discouraged-class=1
+compilers.p.internal=1
+compilers.p.missing-packages=2
+compilers.p.missing-version-export-package=2
+compilers.p.missing-version-import-package=2
+compilers.p.missing-version-require-bundle=2
+compilers.p.no-required-att=0
+compilers.p.not-externalized-att=2
+compilers.p.unknown-attribute=1
+compilers.p.unknown-class=1
+compilers.p.unknown-element=1
+compilers.p.unknown-identifier=1
+compilers.p.unknown-resource=1
+compilers.p.unresolved-ex-points=0
+compilers.p.unresolved-import=0
+compilers.s.create-docs=false
+compilers.s.doc-folder=doc
+compilers.s.open-tags=1
+eclipse.preferences.version=1
diff --git a/bundles/org.xmind.cathy.win32/META-INF/MANIFEST.MF b/bundles/org.xmind.cathy.win32/META-INF/MANIFEST.MF
index 3b2247e59..6003ec241 100644
--- a/bundles/org.xmind.cathy.win32/META-INF/MANIFEST.MF
+++ b/bundles/org.xmind.cathy.win32/META-INF/MANIFEST.MF
@@ -1,13 +1,13 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-SymbolicName: org.xmind.cathy.win32;singleton:=true
-Bundle-Version: 3.7.0.qualifier
-Bundle-Vendor: %providerName
-Fragment-Host: org.xmind.cathy
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ClassPath: .
-Bundle-Localization: fragment_win32
-Export-Package: org.xmind.cathy.internal;x-internal:=true,
- org.xmind.cathy.internal.win32;x-internal:=true
-Eclipse-PlatformFilter: (osgi.ws=win32)
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.xmind.cathy.win32;singleton:=true
+Bundle-Version: 3.7.9.qualifier
+Bundle-Vendor: %providerName
+Fragment-Host: org.xmind.cathy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ClassPath: .
+Bundle-Localization: fragment_win32
+Export-Package: org.xmind.cathy.internal;x-internal:=true,
+ org.xmind.cathy.internal.win32;x-internal:=true
+Eclipse-PlatformFilter: (osgi.ws=win32)
diff --git a/bundles/org.xmind.cathy.win32/about.html b/bundles/org.xmind.cathy.win32/about.html
index 9aac69101..424d7e78e 100644
--- a/bundles/org.xmind.cathy.win32/about.html
+++ b/bundles/org.xmind.cathy.win32/about.html
@@ -1,22 +1,22 @@
-
-
-
-
-License
-
-
-License
-
-Nov 6, 2008
-
-
-XMind 3 is dual licensed under 2 open source licenses:
-the Eclipse Public License v1.0 (EPL),
-which is available at http://www.eclipse.org/legal/epl-v10.html ,
-and the GNU Lesser General Public License v3 (LGPL),
-which is available at http://www.gnu.org/licenses/lgpl.html .
-
-
-
-
+
+
+
+
+License
+
+
+License
+
+Nov 6, 2008
+
+
+XMind 3 is dual licensed under 2 open source licenses:
+the Eclipse Public License v1.0 (EPL),
+which is available at http://www.eclipse.org/legal/epl-v10.html ,
+and the GNU Lesser General Public License v3 (LGPL),
+which is available at http://www.gnu.org/licenses/lgpl.html .
+
+
+
+
diff --git a/bundles/org.xmind.cathy.win32/fragment_win32.properties b/bundles/org.xmind.cathy.win32/fragment_win32.properties
index f7dcb8cc1..90072c547 100644
--- a/bundles/org.xmind.cathy.win32/fragment_win32.properties
+++ b/bundles/org.xmind.cathy.win32/fragment_win32.properties
@@ -1,3 +1,3 @@
-#Properties file for org.xmind.cathy.win32
-providerName = XMind Ltd.
+#Properties file for org.xmind.cathy.win32
+providerName = XMind Ltd.
pluginName = Cathy Win32 Fragment
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy.win32/pom.xml b/bundles/org.xmind.cathy.win32/pom.xml
index e14039d05..eb3606880 100644
--- a/bundles/org.xmind.cathy.win32/pom.xml
+++ b/bundles/org.xmind.cathy.win32/pom.xml
@@ -1,36 +1,36 @@
-
-
- 4.0.0
- org.xmind.cathy.plugins
- org.xmind.cathy.win32
- 3.7.0-SNAPSHOT
- eclipse-plugin
-
- org.xmind.releng
- org.xmind.cathy.releng
- 3.7.0-SNAPSHOT
- ../../
-
-
-
-
-
- org.eclipse.tycho
- target-platform-configuration
- ${tycho.version}
-
- p2
-
-
- win32
- win32
- x86
-
-
-
-
-
-
-
+
+
+ 4.0.0
+ org.xmind.cathy.plugins
+ org.xmind.cathy.win32
+ 3.7.9-SNAPSHOT
+ eclipse-plugin
+
+ org.xmind.releng
+ org.xmind.cathy.releng
+ 3.7.9-SNAPSHOT
+ ../../
+
+
+
+
+
+ org.eclipse.tycho
+ target-platform-configuration
+ ${tycho.version}
+
+ p2
+
+
+ win32
+ win32
+ x86
+
+
+
+
+
+
+
diff --git a/bundles/org.xmind.cathy.win32/src/org/xmind/cathy/internal/ApplicationValidator.java b/bundles/org.xmind.cathy.win32/src/org/xmind/cathy/internal/ApplicationValidator.java
index c2eeaba7d..637e7086b 100644
--- a/bundles/org.xmind.cathy.win32/src/org/xmind/cathy/internal/ApplicationValidator.java
+++ b/bundles/org.xmind.cathy.win32/src/org/xmind/cathy/internal/ApplicationValidator.java
@@ -6,7 +6,7 @@
* which is available at http://www.eclipse.org/legal/epl-v10.html
* and the GNU Lesser General Public License (LGPL),
* which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
+ * See https://www.xmind.net/license.html for details.
*
* Contributors:
* XMind Ltd. - initial API and implementation
diff --git a/bundles/org.xmind.cathy.win32/src/org/xmind/cathy/internal/win32/Startup.java b/bundles/org.xmind.cathy.win32/src/org/xmind/cathy/internal/win32/Startup.java
index 4805f5823..9733f9dfc 100644
--- a/bundles/org.xmind.cathy.win32/src/org/xmind/cathy/internal/win32/Startup.java
+++ b/bundles/org.xmind.cathy.win32/src/org/xmind/cathy/internal/win32/Startup.java
@@ -1,103 +1,103 @@
-/*
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and above are dual-licensed
- * under the Eclipse Public License (EPL), which is available at
- * http://www.eclipse.org/legal/epl-v10.html and the GNU Lesser General Public
- * License (LGPL), which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors: XMind Ltd. - initial API and implementation
- */
-package org.xmind.cathy.internal.win32;
-
-import java.lang.reflect.Field;
-
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IStartup;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.cathy.internal.Log;
-
-public class Startup implements IStartup {
-
- public void earlyStartup() {
- final IWorkbench workbench = PlatformUI.getWorkbench();
- final Display display = workbench.getDisplay();
- display.syncExec(new Runnable() {
- public void run() {
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- if (window != null) {
- hookWindow(window);
- }
- }
- });
- }
-
- private void hookWindow(IWorkbenchWindow window) {
- Shell shell = window.getShell();
- if (shell != null && !shell.isDisposed()) {
- int hWnd = findWindowHandle(shell);
- logPrimaryWindow(hWnd);
- shell.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Log.get(Log.SINGLETON).delete();
- e.display.asyncExec(new Runnable() {
- public void run() {
- checkRemainingWindow();
- }
- });
- }
- });
- }
- }
-
- /**
- * Obtain shell.handle using reflection.
- *
- * @param shell
- * @return
- */
- private int findWindowHandle(Shell shell) {
- try {
- Field handleField = shell.getClass().getField("handle"); //$NON-NLS-1$
- Object handle = handleField.get(shell);
- if (handle instanceof Integer) {
- return ((Integer) handle).intValue();
- }
- } catch (Exception e) {
- //ignore
- }
- return 0;
- }
-
- private void checkRemainingWindow() {
- if (!PlatformUI.isWorkbenchRunning())
- return;
- IWorkbenchWindow window = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- if (window == null) {
- IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
- .getWorkbenchWindows();
- if (windows == null || windows.length <= 0)
- return;
- window = windows[0];
- }
- hookWindow(window);
- }
-
- private void logPrimaryWindow(int hWnd) {
- Log log = Log.get(Log.SINGLETON);
- if (log.exists()) {
- log.delete();
- }
- log.getProperties().setProperty(Log.K_PRIMARY_WINDOW,
- String.valueOf(hWnd));
- log.saveProperties();
- }
-
+/*
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and above are dual-licensed
+ * under the Eclipse Public License (EPL), which is available at
+ * http://www.eclipse.org/legal/epl-v10.html and the GNU Lesser General Public
+ * License (LGPL), which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors: XMind Ltd. - initial API and implementation
+ */
+package org.xmind.cathy.internal.win32;
+
+import java.lang.reflect.Field;
+
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IStartup;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.cathy.internal.Log;
+
+public class Startup implements IStartup {
+
+ public void earlyStartup() {
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ final Display display = workbench.getDisplay();
+ display.syncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window != null) {
+ hookWindow(window);
+ }
+ }
+ });
+ }
+
+ private void hookWindow(IWorkbenchWindow window) {
+ Shell shell = window.getShell();
+ if (shell != null && !shell.isDisposed()) {
+ int hWnd = findWindowHandle(shell);
+ logPrimaryWindow(hWnd);
+ shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ Log.get(Log.SINGLETON).delete();
+ e.display.asyncExec(new Runnable() {
+ public void run() {
+ checkRemainingWindow();
+ }
+ });
+ }
+ });
+ }
+ }
+
+ /**
+ * Obtain shell.handle using reflection.
+ *
+ * @param shell
+ * @return
+ */
+ private int findWindowHandle(Shell shell) {
+ try {
+ Field handleField = shell.getClass().getField("handle"); //$NON-NLS-1$
+ Object handle = handleField.get(shell);
+ if (handle instanceof Integer) {
+ return ((Integer) handle).intValue();
+ }
+ } catch (Exception e) {
+ //ignore
+ }
+ return 0;
+ }
+
+ private void checkRemainingWindow() {
+ if (!PlatformUI.isWorkbenchRunning())
+ return;
+ IWorkbenchWindow window = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (window == null) {
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
+ .getWorkbenchWindows();
+ if (windows == null || windows.length <= 0)
+ return;
+ window = windows[0];
+ }
+ hookWindow(window);
+ }
+
+ private void logPrimaryWindow(int hWnd) {
+ Log log = Log.get(Log.SINGLETON);
+ if (log.exists()) {
+ log.delete();
+ }
+ log.getProperties().setProperty(Log.K_PRIMARY_WINDOW,
+ String.valueOf(hWnd));
+ log.saveProperties();
+ }
+
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/.classpath b/bundles/org.xmind.cathy/.classpath
index 6e9b53707..362f47e08 100644
--- a/bundles/org.xmind.cathy/.classpath
+++ b/bundles/org.xmind.cathy/.classpath
@@ -1,20 +1,20 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bundles/org.xmind.cathy/.gitignore b/bundles/org.xmind.cathy/.gitignore
index 3ffab8564..278670924 100644
--- a/bundles/org.xmind.cathy/.gitignore
+++ b/bundles/org.xmind.cathy/.gitignore
@@ -1,15 +1,15 @@
-.metadata
-bin
-tmp
-*.tmp
-*.bak
-*.swp
-*~.nib
-local.properties
-.loadpath
-
-# External tool builders
-.externalToolBuilders/
-
-# Folder containing Maven build results
-target/
+.metadata
+bin
+tmp
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Folder containing Maven build results
+target/
diff --git a/bundles/org.xmind.cathy/.options b/bundles/org.xmind.cathy/.options
index bfc5774a6..162403b0c 100644
--- a/bundles/org.xmind.cathy/.options
+++ b/bundles/org.xmind.cathy/.options
@@ -1,3 +1,3 @@
-org.xmind.cathy/debug/checkopenfile=false
-org.xmind.cathy/debug/udc/showUploadButton=false
-org.xmind.cathy/debug/notshowwelcome=false
+org.xmind.cathy/debug/checkopenfile=false
+org.xmind.cathy/debug/udc/showUploadButton=false
+org.xmind.cathy/debug/notshowwelcome=false
diff --git a/bundles/org.xmind.cathy/.settings/org.eclipse.core.resources.prefs b/bundles/org.xmind.cathy/.settings/org.eclipse.core.resources.prefs
index 4824b8026..99f26c020 100644
--- a/bundles/org.xmind.cathy/.settings/org.eclipse.core.resources.prefs
+++ b/bundles/org.xmind.cathy/.settings/org.eclipse.core.resources.prefs
@@ -1,2 +1,2 @@
-eclipse.preferences.version=1
-encoding/=UTF-8
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/bundles/org.xmind.cathy/.settings/org.eclipse.core.runtime.prefs b/bundles/org.xmind.cathy/.settings/org.eclipse.core.runtime.prefs
index f8a67de1d..deae05a97 100644
--- a/bundles/org.xmind.cathy/.settings/org.eclipse.core.runtime.prefs
+++ b/bundles/org.xmind.cathy/.settings/org.eclipse.core.runtime.prefs
@@ -1,2 +1,2 @@
-eclipse.preferences.version=1
-line.separator=\r\n
+eclipse.preferences.version=1
+line.separator=\r\n
diff --git a/bundles/org.xmind.cathy/.settings/org.eclipse.jdt.launching.prefs b/bundles/org.xmind.cathy/.settings/org.eclipse.jdt.launching.prefs
index dcf51f5a2..3bb235278 100644
--- a/bundles/org.xmind.cathy/.settings/org.eclipse.jdt.launching.prefs
+++ b/bundles/org.xmind.cathy/.settings/org.eclipse.jdt.launching.prefs
@@ -1,2 +1,2 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.launching.PREF_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE=ignore
+eclipse.preferences.version=1
+org.eclipse.jdt.launching.PREF_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE=ignore
diff --git a/bundles/org.xmind.cathy/Application.e4xmi b/bundles/org.xmind.cathy/Application.e4xmi
index d61b8d70c..bf3b138d1 100644
--- a/bundles/org.xmind.cathy/Application.e4xmi
+++ b/bundles/org.xmind.cathy/Application.e4xmi
@@ -1,85 +1,85 @@
-
-
-
- CathyShowDashboard
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- stretch
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- stretch
-
-
-
-
-
-
-
-
- TrimBarLayout:begining
-
-
- TrimBarLayout:center
-
-
- TrimBarLayout:end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ CathyShowDashboard
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ stretch
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ stretch
+
+
+
+
+
+
+
+
+ TrimBarLayout:begining
+
+
+ TrimBarLayout:center
+
+
+ TrimBarLayout:end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bundles/org.xmind.cathy/META-INF/MANIFEST.MF b/bundles/org.xmind.cathy/META-INF/MANIFEST.MF
index bc188f91b..8e10c71f1 100644
--- a/bundles/org.xmind.cathy/META-INF/MANIFEST.MF
+++ b/bundles/org.xmind.cathy/META-INF/MANIFEST.MF
@@ -1,53 +1,53 @@
-Manifest-Version: 1.0
-Bundle-SymbolicName: org.xmind.cathy;singleton:=true
-Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.ui,
- org.xmind.ui;bundle-version="[3.7.0,3.8.0)",
- org.xmind.ui.imports;bundle-version="[3.7.0,3.8.0)",
- org.xmind.ui.toolkit;bundle-version="[3.7.0,3.8.0)",
- org.xmind.core.command;bundle-version="[3.7.0,3.8.0)",
- org.xmind.core.command.remote;bundle-version="[3.7.0,3.8.0)",
- org.eclipse.e4.ui.workbench,
- org.eclipse.ui.themes,
- org.eclipse.e4.ui.model.workbench,
- org.eclipse.e4.core.di,
- javax.inject,
- org.eclipse.e4.ui.css.swt.theme,
- org.eclipse.e4.core.contexts,
- org.eclipse.e4.ui.css.swt,
- org.eclipse.e4.ui.css.core,
- org.eclipse.e4.ui.workbench.renderers.swt,
- org.eclipse.e4.ui.workbench.swt,
- javax.annotation,
- org.eclipse.e4.core.services,
- org.eclipse.e4.ui.services,
- org.eclipse.e4.ui.di,
- org.eclipse.osgi.services,
- org.eclipse.e4.core.di.extensions,
- org.eclipse.core.expressions,
- org.eclipse.e4.core.commands,
- org.xmind.ui.dashboard,
- org.xmind.core.usagedata;bundle-version="[3.7.0,3.8.0)",
- org.json,
- org.xmind.ui.browser;bundle-version="[3.7.0,3.8.0)",
- org.xmind.core.licensing;bundle-version="[3.7.0,3.8.0)",
- org.eclipse.e4.ui.workbench.addons.swt,
- org.xmind.ui.mindmap;bundle-version="3.7.0",
- org.eclipse.ui.net;bundle-version="1.3.0",
- org.eclipse.emf.ecore.xmi
-Bundle-ManifestVersion: 2
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ActivationPolicy: lazy
-Bundle-Vendor: %providerName
-Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
- javax.inject;version="1.0.0"
-Service-Component: OSGI-INF/serviceManager.xml
-Export-Package: org.xmind.cathy.internal;x-internal:=true,org.xmind.ca
- thy.internal.css;x-internal:=true,org.xmind.cathy.internal.dashboard;
- x-internal:=true,org.xmind.cathy.internal.handlers;x-internal:=true,o
- rg.xmind.cathy.internal.jobs;x-internal:=true,org.xmind.cathy.interna
- l.renderer;x-internal:=true,org.xmind.ui.internal.e4handlers;x-intern
- al:=true
-Bundle-Name: %pluginName
-Bundle-Version: 3.7.0.qualifier
-Bundle-Activator: org.xmind.cathy.internal.CathyPlugin
+Manifest-Version: 1.0
+Bundle-SymbolicName: org.xmind.cathy;singleton:=true
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.ui,
+ org.xmind.ui;bundle-version="[3.7.9,3.8.0)",
+ org.xmind.ui.imports;bundle-version="[3.7.9,3.8.0)",
+ org.xmind.ui.toolkit;bundle-version="[3.7.9,3.8.0)",
+ org.xmind.core.command;bundle-version="[3.7.9,3.8.0)",
+ org.xmind.core.command.remote;bundle-version="[3.7.9,3.8.0)",
+ org.eclipse.e4.ui.workbench,
+ org.eclipse.ui.themes,
+ org.eclipse.e4.ui.model.workbench,
+ org.eclipse.e4.core.di,
+ javax.inject,
+ org.eclipse.e4.ui.css.swt.theme,
+ org.eclipse.e4.core.contexts,
+ org.eclipse.e4.ui.css.swt,
+ org.eclipse.e4.ui.css.core,
+ org.eclipse.e4.ui.workbench.renderers.swt,
+ org.eclipse.e4.ui.workbench.swt,
+ javax.annotation,
+ org.eclipse.e4.core.services,
+ org.eclipse.e4.ui.services,
+ org.eclipse.e4.ui.di,
+ org.eclipse.osgi.services,
+ org.eclipse.e4.core.di.extensions,
+ org.eclipse.core.expressions,
+ org.eclipse.e4.core.commands,
+ org.xmind.ui.dashboard,
+ org.xmind.core.usagedata;bundle-version="[3.7.9,3.8.0)",
+ org.json,
+ org.xmind.ui.browser;bundle-version="[3.7.9,3.8.0)",
+ org.xmind.core.licensing;bundle-version="[3.7.9,3.8.0)",
+ org.eclipse.e4.ui.workbench.addons.swt,
+ org.xmind.ui.mindmap;bundle-version="3.7.9",
+ org.eclipse.ui.net;bundle-version="1.3.0",
+ org.eclipse.emf.ecore.xmi
+Bundle-ManifestVersion: 2
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor: %providerName
+Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
+ javax.inject;version="1.0.0"
+Service-Component: OSGI-INF/serviceManager.xml
+Export-Package: org.xmind.cathy.internal;x-internal:=true,org.xmind.ca
+ thy.internal.css;x-internal:=true,org.xmind.cathy.internal.dashboard;
+ x-internal:=true,org.xmind.cathy.internal.handlers;x-internal:=true,o
+ rg.xmind.cathy.internal.jobs;x-internal:=true,org.xmind.cathy.interna
+ l.renderer;x-internal:=true,org.xmind.ui.internal.e4handlers;x-intern
+ al:=true
+Bundle-Name: %pluginName
+Bundle-Version: 3.7.9.qualifier
+Bundle-Activator: org.xmind.cathy.internal.CathyPlugin
diff --git a/bundles/org.xmind.cathy/OSGI-INF/l10n/bundle.properties b/bundles/org.xmind.cathy/OSGI-INF/l10n/bundle.properties
index dd6c0e9ac..9812f9eec 100644
--- a/bundles/org.xmind.cathy/OSGI-INF/l10n/bundle.properties
+++ b/bundles/org.xmind.cathy/OSGI-INF/l10n/bundle.properties
@@ -1,103 +1,104 @@
-productName = XMind
-providerName = XMind Ltd.
-pluginName = XMind Application
-prefPage.general.name = General
-prefPage.share.name = Share
-prefPage.spelling.name = Spelling
-prefPage.keys.name = Keys
-prefPage.language.name = Language
-prefPage.advanced.name = Advanced
-prefPage.appearance.name = Appearance
-view.progress.name = Progress
-productBlurb=Version: XMind{0} ({1})\n\
-\n\
-{2}{3}{4}\n\
-{5}\n\
-\n\
-Official Website: {6}
-
-view.outline.name = Outline
-view.properties.name = Properties
-command.showHome.description = Show the Home UI
-command.showHome.name = Show Home UI
-commandParameter.homePage.name = Home Page Id
-command.toggleHome.description = Show/Hide the Home UI
-command.toggleHome.name = Toggle Home
-command.welcome.description = Show welcome information
-command.welcome.name = Welcome to XMind
-menu.file.new.label = &New...
-menu.file.close.label = &Close
-menu.file.closeAll.label = C&lose All
-menu.file.save.label = &Save
-menu.file.saveAs.label = Save &As...
-menu.file.saveall.label = Sa&ve All
-menu.file.print.label = &Print
-menu.file.import.label = &Import...
-menu.file.export.label = &Export...
-menu.file.share.label = S&hare
-menu.file.exit.label = E&xit
-menu.edit.undo.label = &Undo
-menu.edit.redo.label = &Redo
-menu.edit.cut.label = Cu&t
-menu.edit.copy.label = &Copy
-menu.edit.paste.label = &Paste
-menu.edit.delete.label = &Delete
-menu.edit.selectAll.label = Select &All
-menu.edit.find.label = &Find/Replace...
-menu.edit.preference.label = &Preferences...
-menu.help.welcome.label = &Welcome to XMind
-menu.help.xmindHelp.label = XMind &Help
-menu.help.keyAssist.label = &Key Assist
-menu.help.about.label = &About XMind
-context.showHome.name = Home UI Is Shown
-toolbar.dashboard.home.label = Home
-toolbar.dashboard.home.tooltip = Show Home
-toolbar.edit.save.label = Save
-toolbar.edit.save.tooltip = Save
-toolbar.edit.undo.label = Undo
-toolbar.edit.undo.tooltip = Undo
-toolbar.edit.redo.label = Redo
-toolbar.edit.redo.tooltip = Redo
-toolbar.export.label=Export
-toolbar.export.tooltip=Export
-toolbar.share.label=Share
-toolbar.share.tooltip=Share
-toolbar.export.more.label=More...
-toolbar.export.more.tooltip=Show all export options...
-
-command.showDashboard.label = More...
-command.pinRecent.name = Pin Recent File
-command.unpinRecent.name = Unpin Recent File
-command.clearRecent.name = Clear Recent File
-command.pinThis.label = Pin This Map
-command.unpinThis.label = Unpin This Map
-command.clearUnpinned.label = Clear Unpinned Maps
-command.home.label = Home
-command.openCloud.name = Open Cloud Page
-theme.cathy.name = Cathy
-
-command.pinRecentFile.name = Pin Recent File
-command.unpinRecentFile.name = Unpin Recent File
-command.clearRecentFile.name = Clear Recent File
-
-command.duplicateTemplate.name = Duplicate Template
-command.renameTemplate.name = Rename Template
-command.deleteTemplate.name = Delete Template
-
-command.openCloudPage.name = Open Cloud Page
-category.cloud.name = Cloud
-
-prefPage.section.startup.label = Startup
-prefPage.section.fileList.label = File List
-prefPage.section.saveBackup.label = Save and Backup
-
-
-product.name = XMind
-command.showDashboard.name = More...
-command.pinMap.name = Pin This Map
-command.unpinMap.name = Unpin This Map
-command.clearUnpinnedMap.name = Clear Unpinned Maps
-command.home.name = Home
-command.rename.name = Rename
-command.duplicate.name = Duplicate
-command.delete.name = Delete
\ No newline at end of file
+productName = XMind
+providerName = XMind Ltd.
+pluginName = XMind Application
+prefPage.general.name = General
+prefPage.share.name = Share
+prefPage.spelling.name = Spelling
+prefPage.keys.name = Keys
+prefPage.language.name = Language
+prefPage.advanced.name = Advanced
+prefPage.appearance.name = Appearance
+view.progress.name = Progress
+productBlurb=Version: XMind{0} ({1})\n\
+\n\
+{2}{3}{4}\n\
+{5}\n\
+\n\
+Official Website: {6}
+
+view.outline.name = Outline
+view.properties.name = Properties
+command.showHome.description = Show the Home UI
+command.showHome.name = Show Home UI
+commandParameter.homePage.name = Home Page Id
+command.toggleHome.description = Show/Hide the Home UI
+command.toggleHome.name = Toggle Home
+command.welcome.description = Show welcome information
+command.welcome.name = Welcome to XMind
+menu.file.new.label = &New...
+menu.file.close.label = &Close
+menu.file.closeAll.label = C&lose All
+menu.file.save.label = &Save
+menu.file.saveAs.label = Save &As...
+menu.file.saveall.label = Sa&ve All
+menu.file.print.label = &Print
+menu.file.import.label = &Import...
+menu.file.export.label = &Export...
+menu.file.share.label = S&hare
+menu.file.exit.label = E&xit
+menu.edit.undo.label = &Undo
+menu.edit.redo.label = &Redo
+menu.edit.cut.label = Cu&t
+menu.edit.copy.label = &Copy
+menu.edit.paste.label = &Paste
+menu.edit.delete.label = &Delete
+menu.edit.selectAll.label = Select &All
+menu.edit.find.label = &Find/Replace...
+menu.edit.preference.label = &Preferences...
+menu.help.welcome.label = &Welcome to XMind
+menu.help.xmindHelp.label = XMind &Help
+menu.help.keyAssist.label = &Key Assist
+menu.help.about.label = &About XMind
+context.showHome.name = Home UI Is Shown
+toolbar.dashboard.home.label = Home
+toolbar.dashboard.home.tooltip = Show Home
+toolbar.edit.save.label = Save
+toolbar.edit.save.tooltip = Save
+toolbar.edit.undo.label = Undo
+toolbar.edit.undo.tooltip = Undo
+toolbar.edit.redo.label = Redo
+toolbar.edit.redo.tooltip = Redo
+toolbar.export.label=Export
+toolbar.export.tooltip=Export
+toolbar.share.label=Share
+toolbar.share.tooltip=Share
+toolbar.export.more.label=More...
+toolbar.export.more.tooltip=Show all export options...
+
+command.showDashboard.label = More...
+command.pinRecent.name = Pin Recent File
+command.unpinRecent.name = Unpin Recent File
+command.clearRecent.name = Clear Recent File
+command.pinThis.label = Pin This Map
+command.unpinThis.label = Unpin This Map
+command.clearUnpinned.label = Clear Unpinned Maps
+command.home.label = Home
+command.openCloud.name = Open Cloud Page
+theme.cathy.name = Cathy
+
+command.pinRecentFile.name = Pin Recent File
+command.unpinRecentFile.name = Unpin Recent File
+command.clearRecentFile.name = Clear Recent File
+
+command.duplicateTemplate.name = Duplicate Template
+command.renameTemplate.name = Rename Template
+command.deleteTemplate.name = Delete Template
+
+command.openCloudPage.name = Open Cloud Page
+category.cloud.name = Cloud
+
+prefPage.section.startup.label = Startup
+prefPage.section.fileList.label = File List
+prefPage.section.saveBackup.label = Save and Backup
+
+
+product.name = XMind
+command.showDashboard.name = More...
+command.pinMap.name = Pin This Map
+command.unpinMap.name = Unpin This Map
+command.clearUnpinnedMap.name = Clear Unpinned Maps
+command.home.name = Home
+command.rename.name = Rename
+command.duplicate.name = Duplicate
+command.delete.name = Delete
+xmind.product.name = XMind
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/OSGI-INF/serviceManager.xml b/bundles/org.xmind.cathy/OSGI-INF/serviceManager.xml
index 6e162e2f3..291e29b14 100644
--- a/bundles/org.xmind.cathy/OSGI-INF/serviceManager.xml
+++ b/bundles/org.xmind.cathy/OSGI-INF/serviceManager.xml
@@ -1,7 +1,7 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/bundles/org.xmind.cathy/about.html b/bundles/org.xmind.cathy/about.html
index 9aac69101..424d7e78e 100644
--- a/bundles/org.xmind.cathy/about.html
+++ b/bundles/org.xmind.cathy/about.html
@@ -1,22 +1,22 @@
-
-
-
-
-License
-
-
-License
-
-Nov 6, 2008
-
-
-XMind 3 is dual licensed under 2 open source licenses:
-the Eclipse Public License v1.0 (EPL),
-which is available at http://www.eclipse.org/legal/epl-v10.html ,
-and the GNU Lesser General Public License v3 (LGPL),
-which is available at http://www.gnu.org/licenses/lgpl.html .
-
-
-
-
+
+
+
+
+License
+
+
+License
+
+Nov 6, 2008
+
+
+XMind 3 is dual licensed under 2 open source licenses:
+the Eclipse Public License v1.0 (EPL),
+which is available at http://www.eclipse.org/legal/epl-v10.html ,
+and the GNU Lesser General Public License v3 (LGPL),
+which is available at http://www.gnu.org/licenses/lgpl.html .
+
+
+
+
diff --git a/bundles/org.xmind.cathy/about.mappings b/bundles/org.xmind.cathy/about.mappings
index 7b9d202ed..129c9dab7 100644
--- a/bundles/org.xmind.cathy/about.mappings
+++ b/bundles/org.xmind.cathy/about.mappings
@@ -1,7 +1,7 @@
-0=$org.xmind.product.brandingVersion$
-1=$org.xmind.product.buildid$
-2=$org.xmind.product.license.restrictions$
-3=$org.xmind.product.license.type$
-4=$org.xmind.product.license.licensee$
-5=$org.xmind.product.about.copyright$
-6=$org.xmind.product.about.homepage$
+0=$org.xmind.product.brandingVersion$
+1=$org.xmind.product.buildid$
+2=$org.xmind.product.license.restrictions$
+3=$org.xmind.product.license.type$
+4=$org.xmind.product.license.licensee$
+5=$org.xmind.product.about.copyright$
+6=$org.xmind.product.about.homepage$
diff --git a/bundles/org.xmind.cathy/build.properties b/bundles/org.xmind.cathy/build.properties
index 4dd15c799..8cc524132 100644
--- a/bundles/org.xmind.cathy/build.properties
+++ b/bundles/org.xmind.cathy/build.properties
@@ -1,18 +1,18 @@
-output.. = bin/
-bin.includes = plugin.xml,\
- META-INF/,\
- .,\
- plugin_customization.ini,\
- icons/,\
- splash.bmp,\
- about.html,\
- about.mappings,\
- resource/,\
- Application.e4xmi,\
- css/,\
- dashboard/,\
- images/,\
- OSGI-INF/,\
- OSGI-INF/l10n/bundle.properties
-src.includes = about.html
-source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ plugin_customization.ini,\
+ icons/,\
+ splash.bmp,\
+ about.html,\
+ about.mappings,\
+ resource/,\
+ Application.e4xmi,\
+ css/,\
+ dashboard/,\
+ images/,\
+ OSGI-INF/,\
+ OSGI-INF/l10n/bundle.properties
+src.includes = about.html
+source.. = src/
diff --git a/bundles/org.xmind.cathy/css/default.css b/bundles/org.xmind.cathy/css/default.css
index c6897e959..fc8e36f7b 100644
--- a/bundles/org.xmind.cathy/css/default.css
+++ b/bundles/org.xmind.cathy/css/default.css
@@ -1,196 +1,196 @@
-.MPartStack{
- swt-tab-renderer:url("bundleclass://org.xmind.cathy/org.xmind.cathy.internal.css.CathyCTabFolderRendering");
- /*outer border */
- xmind-swt-outer-border-visible:true;
- swt-outer-keyline-color:#9f9f9f;
-
- /*inner border */
- xmind-swt-inner-border-visible:true;
- swt-inner-keyline-color:#9f9f9f;
-
- /*shadow */
- swt-shadow-visible:false;
-
- /*corner radius */
- swt-corner-radius:0px;
-
- /*selected tab color */
- swt-selected-tab-fill:#ffffff 100%;
-
- /*selected tab area color */
- xmind-swt-selected-tab-area-color:#ffffff 100%;
-
- /*unselected tab color */
- xmind-swt-unselected-tabs-color:#35a6b9 100%;
-
- /*hover tab color */
- xmind-swt-hover-tab-color:#ffffff;
-
- xmind-swt-image-visible:false;
-
- xmind-swt-minimize-visible:false;
- xmind-swt-maximize-visible:false;
-
- /*visibility of unselected tabs bg */
- xmind-swt-unselected-tabs-bg-visible:false;
- /*
- * xswt-chevron-visible:false;
- *
- */
-
- /*custom maximize image */
- /*xmind-swt-maximize-image:url("platform:/plugin/org.xmind.ui.menus/icons/export.png");*/
-
- xmind-swt-minimize-image:url("platform:/plugin/org.xmind.cathy/icons/views/view_minimize.png");
-
- /*tab height */
- swt-tab-height:20px;
-
- xmind-swt-close-image:url("platform:/plugin/org.xmind.cathy/icons/views/close.png");
- xmind-swt-close-hover-image:url("platform:/plugin/org.xmind.cathy/icons/views/close_hover.png");
-}
-
-.MPartStack.active{
- swt-tab-renderer:url("bundleclass://org.xmind.cathy/org.xmind.cathy.internal.css.CathyCTabFolderRendering");
- xmind-swt-outer-border-visible:true;
- swt-outer-keyline-color:#35a6d9;
-
- xmind-swt-inner-border-visible:true;
- swt-inner-keyline-color:#35a6d9;
-
- swt-shadow-visible:false;
- swt-corner-radius:0px;
- /*swt-selected-tab-fill:#35a6d9 100%;*/
- xmind-swt-selected-tab-area-color:#35a6d9 100%;
- xmind-swt-unselected-tabs-color:#35a6d9 #35a6d9 100%;
- xmind-swt-hover-tab-color:#ffffff;
- xmind-swt-image-visible:false;
-
- xmind-swt-minimize-visible:fasle;
- xmind-swt-maximize-visible:false;
-
- xmind-swt-minimize-image:url("platform:/plugin/org.xmind.cathy/icons/views/view_minimize.png");
-
- xmind-swt-unselected-tabs-bg-visible:false;
- /*
- * xswt-chevron-visible:false;
- */
-
- swt-tab-height:20px;
-}
-
-.MPartStack>CTabItem {
- /* unselected tab text */
- color: #2c3e50;
- xmind-swt-show-close:false;
-}
-
-.MPartStack>CTabItem:selected {
- /* selected tab text */
- color: #2c3e50;
- xmind-swt-show-close:false;
-}
-
-.MPartStack.active>CTabItem:selected {
- /* text color of active and selected tab */
- color: #ffffff;
- xmind-swt-show-close:false;
-}
-
-#org-eclipse-ui-editorss .MPartStack>CTabItem {
- xmind-swt-show-close:true;
-}
-
-#org-eclipse-ui-editorss .MPartStack>CTabItem:selected {
- xmind-swt-show-close:true;
-}
-
-#org-eclipse-ui-editorss .MPartStack{
- xmind-swt-minimize-visible:false;
- xmind-swt-maximize-visible:false;
-}
-
-#org-eclipse-ui-editorss .MPartStack.active{
- xmind-swt-minimize-visible:false;
- xmind-swt-maximize-visible:false;
-}
-
-#org-eclipse-ui-editorss .MArea{
- swt-tab-renderer:url("bundleclass://org.xmind.cathy/org.xmind.cathy.internal.css.CathyCTabFolderRendering");
- /*xmind-swt-minimize-visible:false;
- xmind-swt-maximize-visible:false;*/
- swt-tab-height:0px;
- xmind-ctabfolder-render-none:true;
-}
-
-#org-eclipse-ui-editorss .MArea.active{
- swt-tab-renderer:url("bundleclass://org.xmind.cathy/org.xmind.cathy.internal.css.CathyCTabFolderRendering");
- /*xmind-swt-minimize-visible:false;
- xmind-swt-maximize-visible:false;*/
- swt-tab-height:0px;
- xmind-ctabfolder-render-none:true;
-}
-
-.MPartStack .MPart>Composite{
- background-color: #ffffff;
-}
-
-CTabFolder{
- swt-simple:true;
-}
-
-ToolBar{
- xmind-swt-view-menu-image:url("platform:/plugin/org.xmind.cathy/images/viewmenu.png");
-}
-
-/**************************************************
- * Window
- **************************************************/
-Shell.MTrimmedWindow {
- margin-top: 0px;
- margin-right: 0px;
- margin-bottom: 0px;
- margin-left: 0px;
-}
-
-.MPartSashContainer {
- xmind-sash-width : 0px;
-}
-
-/**************************************************
- * Main ToolBar
- **************************************************/
-#org-eclipse-ui-main-toolbar {
- xmind-margin-top:4pt;
- xmind-margin-bottom:4pt;
-}
-
-/**
- * Status Bar
- */
-#org-eclipse-ui-trim-status,
-#org-eclipse-ui-trim-status *
-{
- color : #ffffff;
-}
-
-/**
- * Form
- */
-.MPart Form {
- text-background-color: #ecf0f1 #ecf0f1 100%;
- color : #000000;
- h-bottom-keyline-1-color: #ffffff;
- h-bottom-keyline-2-color: #b1d1f3;
-}
-.MPart Section {
- background-color-titlebar: #ffffff;
- border-color-titlebar: #ffffff;
- xmind-title-bar-text-color : #216592;
- xmind-title-bar-active-text-color : #7b8fa5;
-}
-.MPart FormText {
- xmind-hyperlink-color: #1949d9;
- xmind-active-hyperlink-color: #11149b;
-}
-
+.MPartStack{
+ swt-tab-renderer:url("bundleclass://org.xmind.cathy/org.xmind.cathy.internal.css.CathyCTabFolderRendering");
+ /*outer border */
+ xmind-swt-outer-border-visible:true;
+ swt-outer-keyline-color:#9f9f9f;
+
+ /*inner border */
+ xmind-swt-inner-border-visible:true;
+ swt-inner-keyline-color:#9f9f9f;
+
+ /*shadow */
+ swt-shadow-visible:false;
+
+ /*corner radius */
+ swt-corner-radius:0px;
+
+ /*selected tab color */
+ swt-selected-tab-fill:#ffffff 100%;
+
+ /*selected tab area color */
+ xmind-swt-selected-tab-area-color:#ffffff 100%;
+
+ /*unselected tab color */
+ xmind-swt-unselected-tabs-color:#35a6b9 100%;
+
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#ffffff;
+
+ xmind-swt-image-visible:false;
+
+ xmind-swt-minimize-visible:false;
+ xmind-swt-maximize-visible:false;
+
+ /*visibility of unselected tabs bg */
+ xmind-swt-unselected-tabs-bg-visible:false;
+ /*
+ * xswt-chevron-visible:false;
+ *
+ */
+
+ /*custom maximize image */
+ /*xmind-swt-maximize-image:url("platform:/plugin/org.xmind.ui.menus/icons/export.png");*/
+
+ xmind-swt-minimize-image:url("platform:/plugin/org.xmind.cathy/icons/views/view_minimize.png");
+
+ /*tab height */
+ swt-tab-height:20px;
+
+ xmind-swt-close-image:url("platform:/plugin/org.xmind.cathy/icons/views/close.png");
+ xmind-swt-close-hover-image:url("platform:/plugin/org.xmind.cathy/icons/views/close_hover.png");
+}
+
+.MPartStack.active{
+ swt-tab-renderer:url("bundleclass://org.xmind.cathy/org.xmind.cathy.internal.css.CathyCTabFolderRendering");
+ xmind-swt-outer-border-visible:true;
+ swt-outer-keyline-color:#35a6d9;
+
+ xmind-swt-inner-border-visible:true;
+ swt-inner-keyline-color:#35a6d9;
+
+ swt-shadow-visible:false;
+ swt-corner-radius:0px;
+ /*swt-selected-tab-fill:#35a6d9 100%;*/
+ xmind-swt-selected-tab-area-color:#35a6d9 100%;
+ xmind-swt-unselected-tabs-color:#35a6d9 #35a6d9 100%;
+ xmind-swt-hover-tab-color:#ffffff;
+ xmind-swt-image-visible:false;
+
+ xmind-swt-minimize-visible:fasle;
+ xmind-swt-maximize-visible:false;
+
+ xmind-swt-minimize-image:url("platform:/plugin/org.xmind.cathy/icons/views/view_minimize.png");
+
+ xmind-swt-unselected-tabs-bg-visible:false;
+ /*
+ * xswt-chevron-visible:false;
+ */
+
+ swt-tab-height:20px;
+}
+
+.MPartStack>CTabItem {
+ /* unselected tab text */
+ color: #2c3e50;
+ xmind-swt-show-close:false;
+}
+
+.MPartStack>CTabItem:selected {
+ /* selected tab text */
+ color: #2c3e50;
+ xmind-swt-show-close:false;
+}
+
+.MPartStack.active>CTabItem:selected {
+ /* text color of active and selected tab */
+ color: #ffffff;
+ xmind-swt-show-close:false;
+}
+
+#org-eclipse-ui-editorss .MPartStack>CTabItem {
+ xmind-swt-show-close:true;
+}
+
+#org-eclipse-ui-editorss .MPartStack>CTabItem:selected {
+ xmind-swt-show-close:true;
+}
+
+#org-eclipse-ui-editorss .MPartStack{
+ xmind-swt-minimize-visible:false;
+ xmind-swt-maximize-visible:false;
+}
+
+#org-eclipse-ui-editorss .MPartStack.active{
+ xmind-swt-minimize-visible:false;
+ xmind-swt-maximize-visible:false;
+}
+
+#org-eclipse-ui-editorss .MArea{
+ swt-tab-renderer:url("bundleclass://org.xmind.cathy/org.xmind.cathy.internal.css.CathyCTabFolderRendering");
+ /*xmind-swt-minimize-visible:false;
+ xmind-swt-maximize-visible:false;*/
+ swt-tab-height:0px;
+ xmind-ctabfolder-render-none:true;
+}
+
+#org-eclipse-ui-editorss .MArea.active{
+ swt-tab-renderer:url("bundleclass://org.xmind.cathy/org.xmind.cathy.internal.css.CathyCTabFolderRendering");
+ /*xmind-swt-minimize-visible:false;
+ xmind-swt-maximize-visible:false;*/
+ swt-tab-height:0px;
+ xmind-ctabfolder-render-none:true;
+}
+
+.MPartStack .MPart>Composite{
+ background-color: #ffffff;
+}
+
+CTabFolder{
+ swt-simple:true;
+}
+
+ToolBar{
+ xmind-swt-view-menu-image:url("platform:/plugin/org.xmind.cathy/images/viewmenu.png");
+}
+
+/**************************************************
+ * Window
+ **************************************************/
+Shell.MTrimmedWindow {
+ margin-top: 0px;
+ margin-right: 0px;
+ margin-bottom: 0px;
+ margin-left: 0px;
+}
+
+.MPartSashContainer {
+ xmind-sash-width : 0px;
+}
+
+/**************************************************
+ * Main ToolBar
+ **************************************************/
+#org-eclipse-ui-main-toolbar {
+ xmind-margin-top:4pt;
+ xmind-margin-bottom:4pt;
+}
+
+/**
+ * Status Bar
+ */
+#org-eclipse-ui-trim-status,
+#org-eclipse-ui-trim-status *
+{
+ color : #ffffff;
+}
+
+/**
+ * Form
+ */
+.MPart Form {
+ text-background-color: #ecf0f1 #ecf0f1 100%;
+ color : #000000;
+ h-bottom-keyline-1-color: #ffffff;
+ h-bottom-keyline-2-color: #b1d1f3;
+}
+.MPart Section {
+ background-color-titlebar: #ffffff;
+ border-color-titlebar: #ffffff;
+ xmind-title-bar-text-color : #216592;
+ xmind-title-bar-active-text-color : #7b8fa5;
+}
+.MPart FormText {
+ xmind-hyperlink-color: #1949d9;
+ xmind-active-hyperlink-color: #11149b;
+}
+
diff --git a/bundles/org.xmind.cathy/css/default_gtk.css b/bundles/org.xmind.cathy/css/default_gtk.css
index 88b2b32d9..1caeb82f4 100644
--- a/bundles/org.xmind.cathy/css/default_gtk.css
+++ b/bundles/org.xmind.cathy/css/default_gtk.css
@@ -1,27 +1,27 @@
-@import url("platform:/plugin/org.xmind.cathy/css/default.css");
-
-.MPartStack{
- /*hover tab color */
- xmind-swt-hover-tab-color:#d9d9d9;
-}
-
-.MPartStack.active{
- /*hover tab color */
- xmind-swt-hover-tab-color:#d9d9d9;
- swt-selected-tab-fill:#35a6d9 100%;
-}
-
-#org-eclipse-ui-trim-status,
-#org-eclipse-ui-trim-status *
-{
- color : #000000;
-}
-
-Shell.MTrimmedWindow {
- background-color:#ffffff #e8e8e8 100%;
-}
-
-MTabFolder{
- xmind-tab-folder-bg:#5f5f5f;
-}
-
+@import url("platform:/plugin/org.xmind.cathy/css/default.css");
+
+.MPartStack{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#d9d9d9;
+}
+
+.MPartStack.active{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#d9d9d9;
+ swt-selected-tab-fill:#35a6d9 100%;
+}
+
+#org-eclipse-ui-trim-status,
+#org-eclipse-ui-trim-status *
+{
+ color : #000000;
+}
+
+Shell.MTrimmedWindow {
+ background-color:#ffffff #e8e8e8 100%;
+}
+
+MTabFolder{
+ xmind-tab-folder-bg:#5f5f5f;
+}
+
diff --git a/bundles/org.xmind.cathy/css/default_mac.css b/bundles/org.xmind.cathy/css/default_mac.css
index 31ddb5cfc..25b1526af 100644
--- a/bundles/org.xmind.cathy/css/default_mac.css
+++ b/bundles/org.xmind.cathy/css/default_mac.css
@@ -1,26 +1,26 @@
-@import url("platform:/plugin/org.xmind.cathy/css/default.css");
-
-.MPartStack{
- /*hover tab color */
- xmind-swt-hover-tab-color:#d9d9d7;
-}
-
-.MPartStack.active{
- /*hover tab color */
- xmind-swt-hover-tab-color:#d9d9d7;
- swt-selected-tab-fill:#35a6d9 100%;
-}
-
-#org-eclipse-ui-trim-status,
-#org-eclipse-ui-trim-status *
-{
- color : #000000;
-}
-
-Shell.MTrimmedWindow {
- background-color:#f7f7f7 #e5e5e5 100%;
-}
-
-MTabFolder{
- xmind-tab-folder-bg:#5f5f5f;
-}
+@import url("platform:/plugin/org.xmind.cathy/css/default.css");
+
+.MPartStack{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#d9d9d7;
+}
+
+.MPartStack.active{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#d9d9d7;
+ swt-selected-tab-fill:#35a6d9 100%;
+}
+
+#org-eclipse-ui-trim-status,
+#org-eclipse-ui-trim-status *
+{
+ color : #000000;
+}
+
+Shell.MTrimmedWindow {
+ background-color:#f7f7f7 #e5e5e5 100%;
+}
+
+MTabFolder{
+ xmind-tab-folder-bg:#5f5f5f;
+}
diff --git a/bundles/org.xmind.cathy/css/default_win.css b/bundles/org.xmind.cathy/css/default_win.css
index 88b2b32d9..1caeb82f4 100644
--- a/bundles/org.xmind.cathy/css/default_win.css
+++ b/bundles/org.xmind.cathy/css/default_win.css
@@ -1,27 +1,27 @@
-@import url("platform:/plugin/org.xmind.cathy/css/default.css");
-
-.MPartStack{
- /*hover tab color */
- xmind-swt-hover-tab-color:#d9d9d9;
-}
-
-.MPartStack.active{
- /*hover tab color */
- xmind-swt-hover-tab-color:#d9d9d9;
- swt-selected-tab-fill:#35a6d9 100%;
-}
-
-#org-eclipse-ui-trim-status,
-#org-eclipse-ui-trim-status *
-{
- color : #000000;
-}
-
-Shell.MTrimmedWindow {
- background-color:#ffffff #e8e8e8 100%;
-}
-
-MTabFolder{
- xmind-tab-folder-bg:#5f5f5f;
-}
-
+@import url("platform:/plugin/org.xmind.cathy/css/default.css");
+
+.MPartStack{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#d9d9d9;
+}
+
+.MPartStack.active{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#d9d9d9;
+ swt-selected-tab-fill:#35a6d9 100%;
+}
+
+#org-eclipse-ui-trim-status,
+#org-eclipse-ui-trim-status *
+{
+ color : #000000;
+}
+
+Shell.MTrimmedWindow {
+ background-color:#ffffff #e8e8e8 100%;
+}
+
+MTabFolder{
+ xmind-tab-folder-bg:#5f5f5f;
+}
+
diff --git a/bundles/org.xmind.cathy/css/default_win7.css b/bundles/org.xmind.cathy/css/default_win7.css
index d04b4993e..e1724f189 100644
--- a/bundles/org.xmind.cathy/css/default_win7.css
+++ b/bundles/org.xmind.cathy/css/default_win7.css
@@ -1,27 +1,27 @@
-@import url("platform:/plugin/org.xmind.cathy/css/default.css");
-
-.MPartStack{
- /*hover tab color */
- xmind-swt-hover-tab-color:#ffffff;
-}
-
-.MPartStack.active{
- /*hover tab color */
- xmind-swt-hover-tab-color:#ffffff;
- swt-selected-tab-fill:#35a6d9 100%;
-}
-
-#org-eclipse-ui-trim-status,
-#org-eclipse-ui-trim-status *
-{
- color : #000000;
-}
-
-Shell.MTrimmedWindow {
- background-color:#ffffff #e8e8e8 100%;
-}
-
-MTabFolder{
- xmind-tab-folder-bg:#5f5f5f;
-}
-
+@import url("platform:/plugin/org.xmind.cathy/css/default.css");
+
+.MPartStack{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#ffffff;
+}
+
+.MPartStack.active{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#ffffff;
+ swt-selected-tab-fill:#35a6d9 100%;
+}
+
+#org-eclipse-ui-trim-status,
+#org-eclipse-ui-trim-status *
+{
+ color : #000000;
+}
+
+Shell.MTrimmedWindow {
+ background-color:#ffffff #e8e8e8 100%;
+}
+
+MTabFolder{
+ xmind-tab-folder-bg:#5f5f5f;
+}
+
diff --git a/bundles/org.xmind.cathy/css/default_win8.css b/bundles/org.xmind.cathy/css/default_win8.css
index b9776f710..3213c25c5 100644
--- a/bundles/org.xmind.cathy/css/default_win8.css
+++ b/bundles/org.xmind.cathy/css/default_win8.css
@@ -1,27 +1,27 @@
-@import url("platform:/plugin/org.xmind.cathy/css/default.css");
-
-.MPartStack{
- /*hover tab color */
- xmind-swt-hover-tab-color:#e9e9e9;
-}
-
-.MPartStack.active{
- /*hover tab color */
- xmind-swt-hover-tab-color:#e9e9e9;
- swt-selected-tab-fill:#228edc 100%;
-}
-
-#org-eclipse-ui-trim-status,
-#org-eclipse-ui-trim-status *
-{
- color : #000000;
-}
-
-Shell.MTrimmedWindow {
- background-color:#ffffff #e8e8e8 100%;
-}
-
-MTabFolder{
- xmind-tab-folder-bg:#5f5f5f;
-}
-
+@import url("platform:/plugin/org.xmind.cathy/css/default.css");
+
+.MPartStack{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#e9e9e9;
+}
+
+.MPartStack.active{
+ /*hover tab color */
+ xmind-swt-hover-tab-color:#e9e9e9;
+ swt-selected-tab-fill:#228edc 100%;
+}
+
+#org-eclipse-ui-trim-status,
+#org-eclipse-ui-trim-status *
+{
+ color : #000000;
+}
+
+Shell.MTrimmedWindow {
+ background-color:#ffffff #e8e8e8 100%;
+}
+
+MTabFolder{
+ xmind-tab-folder-bg:#5f5f5f;
+}
+
diff --git a/bundles/org.xmind.cathy/dashboard/back.png b/bundles/org.xmind.cathy/dashboard/back.png
index 2b59437f8..5e6ffafe1 100644
Binary files a/bundles/org.xmind.cathy/dashboard/back.png and b/bundles/org.xmind.cathy/dashboard/back.png differ
diff --git a/bundles/org.xmind.cathy/dashboard/back@2x.png b/bundles/org.xmind.cathy/dashboard/back@2x.png
index 152f1c381..3943ebbbb 100644
Binary files a/bundles/org.xmind.cathy/dashboard/back@2x.png and b/bundles/org.xmind.cathy/dashboard/back@2x.png differ
diff --git a/bundles/org.xmind.cathy/dashboard/dashboard.properties b/bundles/org.xmind.cathy/dashboard/dashboard.properties
index a4db2ccf7..6e3307213 100644
--- a/bundles/org.xmind.cathy/dashboard/dashboard.properties
+++ b/bundles/org.xmind.cathy/dashboard/dashboard.properties
@@ -1,6 +1,7 @@
-new=New
-open=Open
-recent=Recent
-cloud=Cloud
-preferences=Preferences
-back=Workspace
+back_tooltip=Close home
+new=New
+open=Open
+recent=Recent
+cloud=Cloud
+preferences=Preferences
+back=Close
diff --git a/bundles/org.xmind.cathy/dashboard/dashboard.xml b/bundles/org.xmind.cathy/dashboard/dashboard.xml
index 0fabd475a..e3b819ef4 100644
--- a/bundles/org.xmind.cathy/dashboard/dashboard.xml
+++ b/bundles/org.xmind.cathy/dashboard/dashboard.xml
@@ -1,54 +1,40 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/dashboard/new/structures.properties b/bundles/org.xmind.cathy/dashboard/new/structures.properties
index 58158eb9d..bba7b80cf 100644
--- a/bundles/org.xmind.cathy/dashboard/new/structures.properties
+++ b/bundles/org.xmind.cathy/dashboard/new/structures.properties
@@ -1,16 +1,16 @@
-map=Map
-map_uptodown=Balanced Map (Up to down)
-map_clockwise=Balanced Map (Clockwise)
-map_anticlockwise=Balanced Map (Anticlockwise)
-orgchart_uptodown=Org Chart (Up to down)
-orgchart_downtoup=Org Chart (Down to up)
-treechart_right=Tree Chart (Right)
-treechart_left=Tree Chart (Left)
-logicchart_right=Logic Chart (Right)
-logicchart_left=Logic Chart (Left)
-timeline_horizontal=Timeline (Horizontal)
-timeline_vertical=Timeline (Vertical)
-fishbone_right=Fishbone (Right Headed)
-fishbone_left=Fishbone (Left Headed)
-matrix_row=Matrix (Row)
-matrix_column=Matrix (Column)
+map=Map
+map_uptodown=Balanced Map (Up to down)
+map_clockwise=Balanced Map (Clockwise)
+map_anticlockwise=Balanced Map (Anticlockwise)
+orgchart_uptodown=Org Chart (Up to down)
+orgchart_downtoup=Org Chart (Down to up)
+treechart_right=Tree Chart (Right)
+treechart_left=Tree Chart (Left)
+logicchart_right=Logic Chart (Right)
+logicchart_left=Logic Chart (Left)
+timeline_horizontal=Timeline (Horizontal)
+timeline_vertical=Timeline (Vertical)
+fishbone_right=Fishbone (Right Headed)
+fishbone_left=Fishbone (Left Headed)
+matrix_row=Matrix (Row)
+matrix_column=Matrix (Column)
diff --git a/bundles/org.xmind.cathy/dashboard/new/structures.xml b/bundles/org.xmind.cathy/dashboard/new/structures.xml
index 48c3d8c62..696e4a3e7 100644
--- a/bundles/org.xmind.cathy/dashboard/new/structures.xml
+++ b/bundles/org.xmind.cathy/dashboard/new/structures.xml
@@ -1,100 +1,100 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/dashboard.png b/bundles/org.xmind.cathy/icons/toolbar/d/dashboard.png
index 76a1b042b..d8503bc2f 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/dashboard.png and b/bundles/org.xmind.cathy/icons/toolbar/d/dashboard.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/dashboard@2x.png b/bundles/org.xmind.cathy/icons/toolbar/d/dashboard@2x.png
index c2d8fcd49..d226fd7cb 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/dashboard@2x.png and b/bundles/org.xmind.cathy/icons/toolbar/d/dashboard@2x.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/export.png b/bundles/org.xmind.cathy/icons/toolbar/d/export.png
index aa344887b..e6e790355 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/export.png and b/bundles/org.xmind.cathy/icons/toolbar/d/export.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/export@2x.png b/bundles/org.xmind.cathy/icons/toolbar/d/export@2x.png
index ce22fa243..ccb6bfd51 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/export@2x.png and b/bundles/org.xmind.cathy/icons/toolbar/d/export@2x.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/redo.png b/bundles/org.xmind.cathy/icons/toolbar/d/redo.png
index 460d5733b..93bdf9b7d 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/redo.png and b/bundles/org.xmind.cathy/icons/toolbar/d/redo.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/save.png b/bundles/org.xmind.cathy/icons/toolbar/d/save.png
index 809048eb2..445b1085d 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/save.png and b/bundles/org.xmind.cathy/icons/toolbar/d/save.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/save@2x.png b/bundles/org.xmind.cathy/icons/toolbar/d/save@2x.png
index ece332c83..4e84de01b 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/save@2x.png and b/bundles/org.xmind.cathy/icons/toolbar/d/save@2x.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/undo.png b/bundles/org.xmind.cathy/icons/toolbar/d/undo.png
index f7087abff..966767a41 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/undo.png and b/bundles/org.xmind.cathy/icons/toolbar/d/undo.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/d/undo@2x.png b/bundles/org.xmind.cathy/icons/toolbar/d/undo@2x.png
index 6bad1fe79..e36658677 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/d/undo@2x.png and b/bundles/org.xmind.cathy/icons/toolbar/d/undo@2x.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/e/dashboard.png b/bundles/org.xmind.cathy/icons/toolbar/e/dashboard.png
index 1c6fb9051..98271cb00 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/e/dashboard.png and b/bundles/org.xmind.cathy/icons/toolbar/e/dashboard.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/e/dashboard@2x.png b/bundles/org.xmind.cathy/icons/toolbar/e/dashboard@2x.png
index 236335a76..f90b0a77d 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/e/dashboard@2x.png and b/bundles/org.xmind.cathy/icons/toolbar/e/dashboard@2x.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/e/export.png b/bundles/org.xmind.cathy/icons/toolbar/e/export.png
index 48c7ee7f5..5ae5a4555 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/e/export.png and b/bundles/org.xmind.cathy/icons/toolbar/e/export.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/e/export@2x.png b/bundles/org.xmind.cathy/icons/toolbar/e/export@2x.png
index c17ef3f1e..322c213b9 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/e/export@2x.png and b/bundles/org.xmind.cathy/icons/toolbar/e/export@2x.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/e/redo.png b/bundles/org.xmind.cathy/icons/toolbar/e/redo.png
index f17a557e9..ca9e43251 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/e/redo.png and b/bundles/org.xmind.cathy/icons/toolbar/e/redo.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/e/save.png b/bundles/org.xmind.cathy/icons/toolbar/e/save.png
index 876734a2f..b87ae17fc 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/e/save.png and b/bundles/org.xmind.cathy/icons/toolbar/e/save.png differ
diff --git a/bundles/org.xmind.cathy/icons/toolbar/e/save@2x.png b/bundles/org.xmind.cathy/icons/toolbar/e/save@2x.png
index e135a031c..83e1fcf5c 100644
Binary files a/bundles/org.xmind.cathy/icons/toolbar/e/save@2x.png and b/bundles/org.xmind.cathy/icons/toolbar/e/save@2x.png differ
diff --git a/bundles/org.xmind.cathy/plugin.properties b/bundles/org.xmind.cathy/plugin.properties
index 405ff8d69..2ee1f4ce1 100644
--- a/bundles/org.xmind.cathy/plugin.properties
+++ b/bundles/org.xmind.cathy/plugin.properties
@@ -1,73 +1,73 @@
-productName = XMind
-providerName = XMind Ltd.
-pluginName = XMind Application
-prefPage.general.name = General
-prefPage.keys.name = Keys
-prefPage.language.name = Language
-prefPage.appearance.name = Appearance
-view.progress.name = Progress
-productBlurb=Version: XMind{0} ({1})\n\
-\n\
-{2}{3}{4}\n\
-{5}\n\
-\n\
-Official Website: {6}
-
-view.outline.name = Outline
-view.properties.name = Properties
-command.showHome.description = Show the Home UI
-command.showHome.name = Show Home UI
-commandParameter.homePage.name = Home Page Id
-command.toggleHome.description = Show/Hide the Home UI
-command.toggleHome.name = Toggle Home
-command.welcome.description = Show welcome information
-command.welcome.name = Welcome to XMind
-menu.file.new.label = &New...
-menu.file.close.label = &Close
-menu.file.closeAll.label = C&lose All
-menu.file.save.label = &Save
-menu.file.saveAs.label = Save &As...
-menu.file.saveall.label = Sa&ve All
-menu.file.print.label = &Print
-menu.file.import.label = &Import...
-menu.file.export.label = &Export...
-menu.file.share.label = S&hare
-menu.file.exit.label = E&xit
-menu.edit.undo.label = &Undo
-menu.edit.redo.label = &Redo
-menu.edit.cut.label = Cu&t
-menu.edit.copy.label = &Copy
-menu.edit.paste.label = &Paste
-menu.edit.delete.label = &Delete
-menu.edit.selectAll.label = Select &All
-menu.edit.find.label = &Find/Replace...
-menu.edit.preference.label = &Preferences...
-menu.help.welcome.label = &Welcome to XMind
-menu.help.xmindHelp.label = XMind &Help
-menu.help.keyAssist.label = &Key Assist
-menu.help.about.label = &About XMind
-context.showHome.name = Home UI Is Shown
-toolbar.dashboard.home.label = Home
-toolbar.dashboard.home.tooltip = Show Home
-toolbar.edit.save.label = Save
-toolbar.edit.save.tooltip = Save
-toolbar.edit.undo.label = Undo
-toolbar.edit.undo.tooltip = Undo
-toolbar.edit.redo.label = Redo
-toolbar.edit.redo.tooltip = Redo
-toolbar.export.label=Export
-toolbar.export.tooltip=Export
-toolbar.share.label=Share
-toolbar.share.tooltip=Share
-toolbar.export.more.label=More...
-toolbar.export.more.tooltip=Show all export options...
-
-command.showDashboard.label = More...
-command.pinRecent.name = Pin Recent File
-command.unpinRecent.name = Unpin Recent File
-command.clearRecent.name = Clear Recent File
-command.pinThis.label = Pin This Map
-command.unpinThis.label = Unpin This Map
-command.clearUnpinned.label = Clear Unpinned Maps
-command.home.label = Home
-command.openCloud.name = Open Cloud Page
+productName = XMind
+providerName = XMind Ltd.
+pluginName = XMind Application
+prefPage.general.name = General
+prefPage.keys.name = Keys
+prefPage.language.name = Language
+prefPage.appearance.name = Appearance
+view.progress.name = Progress
+productBlurb=Version: XMind{0} ({1})\n\
+\n\
+{2}{3}{4}\n\
+{5}\n\
+\n\
+Official Website: {6}
+
+view.outline.name = Outline
+view.properties.name = Properties
+command.showHome.description = Show the Home UI
+command.showHome.name = Show Home UI
+commandParameter.homePage.name = Home Page Id
+command.toggleHome.description = Show/Hide the Home UI
+command.toggleHome.name = Toggle Home
+command.welcome.description = Show welcome information
+command.welcome.name = Welcome to XMind
+menu.file.new.label = &New...
+menu.file.close.label = &Close
+menu.file.closeAll.label = C&lose All
+menu.file.save.label = &Save
+menu.file.saveAs.label = Save &As...
+menu.file.saveall.label = Sa&ve All
+menu.file.print.label = &Print
+menu.file.import.label = &Import...
+menu.file.export.label = &Export...
+menu.file.share.label = S&hare
+menu.file.exit.label = E&xit
+menu.edit.undo.label = &Undo
+menu.edit.redo.label = &Redo
+menu.edit.cut.label = Cu&t
+menu.edit.copy.label = &Copy
+menu.edit.paste.label = &Paste
+menu.edit.delete.label = &Delete
+menu.edit.selectAll.label = Select &All
+menu.edit.find.label = &Find/Replace...
+menu.edit.preference.label = &Preferences...
+menu.help.welcome.label = &Welcome to XMind
+menu.help.xmindHelp.label = XMind &Help
+menu.help.keyAssist.label = &Key Assist
+menu.help.about.label = &About XMind
+context.showHome.name = Home UI Is Shown
+toolbar.dashboard.home.label = Home
+toolbar.dashboard.home.tooltip = Show Home
+toolbar.edit.save.label = Save
+toolbar.edit.save.tooltip = Save
+toolbar.edit.undo.label = Undo
+toolbar.edit.undo.tooltip = Undo
+toolbar.edit.redo.label = Redo
+toolbar.edit.redo.tooltip = Redo
+toolbar.export.label=Export
+toolbar.export.tooltip=Export
+toolbar.share.label=Share
+toolbar.share.tooltip=Share
+toolbar.export.more.label=More...
+toolbar.export.more.tooltip=Show all export options...
+
+command.showDashboard.label = More...
+command.pinRecent.name = Pin Recent File
+command.unpinRecent.name = Unpin Recent File
+command.clearRecent.name = Clear Recent File
+command.pinThis.label = Pin This Map
+command.unpinThis.label = Unpin This Map
+command.clearUnpinned.label = Clear Unpinned Maps
+command.home.label = Home
+command.openCloud.name = Open Cloud Page
diff --git a/bundles/org.xmind.cathy/plugin.xml b/bundles/org.xmind.cathy/plugin.xml
index cb03ba797..47b0108cf 100644
--- a/bundles/org.xmind.cathy/plugin.xml
+++ b/bundles/org.xmind.cathy/plugin.xml
@@ -1,1312 +1,1303 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bundles/org.xmind.cathy/pom.xml b/bundles/org.xmind.cathy/pom.xml
index 07de990a9..7d5109505 100644
--- a/bundles/org.xmind.cathy/pom.xml
+++ b/bundles/org.xmind.cathy/pom.xml
@@ -1,16 +1,16 @@
-
-
- 4.0.0
- org.xmind.cathy.plugins
- org.xmind.cathy
- 3.7.0-SNAPSHOT
- eclipse-plugin
-
- org.xmind.releng
- org.xmind.cathy.releng
- 3.7.0-SNAPSHOT
- ../../
-
-
+
+
+ 4.0.0
+ org.xmind.cathy.plugins
+ org.xmind.cathy
+ 3.7.9-SNAPSHOT
+ eclipse-plugin
+
+ org.xmind.releng
+ org.xmind.cathy.releng
+ 3.7.9-SNAPSHOT
+ ../../
+
+
diff --git a/bundles/org.xmind.cathy/resource/langs.properties b/bundles/org.xmind.cathy/resource/langs.properties
index 27ccf3c60..81a7558a1 100644
--- a/bundles/org.xmind.cathy/resource/langs.properties
+++ b/bundles/org.xmind.cathy/resource/langs.properties
@@ -1,15 +1,15 @@
-en_US=English
-ar=\u0627\u0644\u0639\u0631\u0628\u064a\u0629
-da=Dansk
-de=Deutsch
-es=Espa\u00F1ol
-fr=Fran\u00e7ais
-it=Italiano
-ja=\u65e5\u672c\u8a9e
-ko=\ud55c\uad6d\uc758
-pt_BR=Portugu\u00eas (Brasil)
-ru=P\u0443\u0441\u0441\u043a\u0438\u0439
-sl=Sloven\u0161\u010dina
-zh_CN=\u7b80\u4f53\u4e2d\u6587
-zh_TW=\u7e41\u9ad4\u4e2d\u6587
-
+en_US=English
+ar=\u0627\u0644\u0639\u0631\u0628\u064a\u0629
+da=Dansk
+de=Deutsch
+es=Espa\u00F1ol
+fr=Fran\u00e7ais
+it=Italiano
+ja=\u65e5\u672c\u8a9e
+ko=\ud55c\uad6d\uc758
+pt_BR=Portugu\u00eas (Brasil)
+ru=P\u0443\u0441\u0441\u043a\u0438\u0439
+sl=Sloven\u0161\u010dina
+zh_CN=\u7b80\u4f53\u4e2d\u6587
+zh_TW=\u7e41\u9ad4\u4e2d\u6587
+
diff --git a/bundles/org.xmind.cathy/splash.bmp b/bundles/org.xmind.cathy/splash.bmp
index 3306764e9..a84948274 100644
Binary files a/bundles/org.xmind.cathy/splash.bmp and b/bundles/org.xmind.cathy/splash.bmp differ
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AbstractCheckFilesProcess.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AbstractCheckFilesProcess.java
index 9ff173b10..09233065d 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AbstractCheckFilesProcess.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AbstractCheckFilesProcess.java
@@ -1,95 +1,95 @@
-package org.xmind.cathy.internal;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class AbstractCheckFilesProcess {
-
- private final IWorkbench workbench;
-
- private List editorsToOpen;
-
- public AbstractCheckFilesProcess(IWorkbench workbench) {
- this.workbench = workbench;
- }
-
- public IWorkbench getWorkbench() {
- return workbench;
- }
-
- protected void addEditorToOpen(IEditorInput input) {
- if (editorsToOpen == null)
- editorsToOpen = new ArrayList();
- editorsToOpen.add(input);
- }
-
- protected void openEditors(boolean activate) {
- if (editorsToOpen != null && !editorsToOpen.isEmpty()) {
- openEditors(editorsToOpen, activate);
- }
- }
-
- protected void openEditors(List editorInputs,
- boolean activate) {
- for (final IEditorInput input : editorInputs) {
- IEditorPart editor = openEditor(input, activate);
- if (editor != null)
- activate = false;
- }
- }
-
- protected IEditorPart openEditor(final IEditorInput input,
- final boolean activate) {
- if (input == null)
- return null;
-
- Display display = workbench.getDisplay();
- if (display == null)
- return null;
-
- final IEditorPart[] result = new IEditorPart[1];
- display.syncExec(new Runnable() {
- public void run() {
- IWorkbenchWindow window = getPrimaryWindow();
- if (window == null)
- return;
- final IWorkbenchPage page = window.getActivePage();
- if (page != null) {
- SafeRunner.run(new SafeRunnable(NLS.bind(
- WorkbenchMessages.CheckOpenFilesJob_FailsToOpen_message,
- input.getName())) {
- public void run() throws Exception {
- result[0] = page.openEditor(input,
- MindMapUI.MINDMAP_EDITOR_ID, activate);
- }
- });
- }
- }
-
- });
- return result[0];
- }
-
- private IWorkbenchWindow getPrimaryWindow() {
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- if (window == null) {
- IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
- if (windows != null && windows.length > 0) {
- window = windows[0];
- }
- }
- return window;
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class AbstractCheckFilesProcess {
+
+ private final IWorkbench workbench;
+
+ private List editorsToOpen;
+
+ public AbstractCheckFilesProcess(IWorkbench workbench) {
+ this.workbench = workbench;
+ }
+
+ public IWorkbench getWorkbench() {
+ return workbench;
+ }
+
+ protected void addEditorToOpen(IEditorInput input) {
+ if (editorsToOpen == null)
+ editorsToOpen = new ArrayList();
+ editorsToOpen.add(input);
+ }
+
+ protected void openEditors(boolean activate) {
+ if (editorsToOpen != null && !editorsToOpen.isEmpty()) {
+ openEditors(editorsToOpen, activate);
+ }
+ }
+
+ protected void openEditors(List editorInputs,
+ boolean activate) {
+ for (final IEditorInput input : editorInputs) {
+ IEditorPart editor = openEditor(input, activate);
+ if (editor != null)
+ activate = false;
+ }
+ }
+
+ protected IEditorPart openEditor(final IEditorInput input,
+ final boolean activate) {
+ if (input == null)
+ return null;
+
+ Display display = workbench.getDisplay();
+ if (display == null)
+ return null;
+
+ final IEditorPart[] result = new IEditorPart[1];
+ display.syncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = getPrimaryWindow();
+ if (window == null)
+ return;
+ final IWorkbenchPage page = window.getActivePage();
+ if (page != null) {
+ SafeRunner.run(new SafeRunnable(NLS.bind(
+ WorkbenchMessages.CheckOpenFilesJob_FailsToOpen_message,
+ input.getName())) {
+ public void run() throws Exception {
+ result[0] = page.openEditor(input,
+ MindMapUI.MINDMAP_EDITOR_ID, activate);
+ }
+ });
+ }
+ }
+
+ });
+ return result[0];
+ }
+
+ private IWorkbenchWindow getPrimaryWindow() {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window == null) {
+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
+ if (windows != null && windows.length > 0) {
+ window = windows[0];
+ }
+ }
+ return window;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoBackupIndicator.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoBackupIndicator.java
index a49be4d75..ccd3f6b99 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoBackupIndicator.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoBackupIndicator.java
@@ -1,287 +1,287 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.ActionContributionItem;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IContributionItem;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.util.Util;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
-import org.xmind.ui.resources.FontUtils;
-import org.xmind.ui.util.PrefUtils;
-
-public class AutoBackupIndicator extends WorkbenchWindowControlContribution
- implements IPropertyChangeListener, Listener {
-
- private static final int DISABLED = 1;
-
- private static final int ENABLED = 2;
-
- private class ChangeAutoSavePrefAction extends Action {
- private IPreferenceStore ps;
- private int value;
-
- /**
- *
- */
- public ChangeAutoSavePrefAction(IPreferenceStore ps, String text,
- int value) {
- super(text);
- this.ps = ps;
- this.value = value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- if (ps == null)
- return;
-
- changeStatus(value);
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- private static class OpenPreferencePageAction extends Action {
-
- /**
- *
- */
- public OpenPreferencePageAction() {
- super(
- WorkbenchMessages.AutoBackupIndicator_OpenPreferenceAction_text);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- PrefUtils.openPrefDialog(null, PrefUtils.GENERAL_PREF_PAGE_ID);
- }
- }
-
- private Control control;
-
- private Label label;
-
- private MenuManager menu;
-
- private IPreferenceStore ps;
-
- public AutoBackupIndicator() {
- super("org.xmind.ui.status.AutoSaveIndicator"); //$NON-NLS-1$
- }
-
- protected Control createControl(Composite parent) {
- ps = CathyPlugin.getDefault().getPreferenceStore();
-
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(1, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- layout.verticalSpacing = 0;
- layout.horizontalSpacing = 4;
- composite.setLayout(layout);
-
-// Label sep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
-// sep.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, true));
-
- label = new Label(composite, SWT.CENTER);
- label.setText(WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_label);
- label.setFont(FontUtils.getRelativeHeight(JFaceResources.DEFAULT_FONT,
- Util.isMac() ? -2 : -1));
- label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
- label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
- label.addListener(SWT.MouseDown, this);
-
- menu = new MenuManager();
- menu.add(new ChangeAutoSavePrefAction(
- ps,
- WorkbenchMessages.AutoBackupIndicator_DisableAutoSaveAction_text,
- DISABLED));
- menu.add(new ChangeAutoSavePrefAction(
- ps,
- WorkbenchMessages.AutoBackupIndicator_EnableAutoSaveAction_text,
- ENABLED));
- menu.add(new Separator());
- menu.add(new OpenPreferencePageAction());
- menu.createContextMenu(label);
- label.setMenu(menu.getMenu());
-
- updateEnablement();
-
-// composite.setLayoutData(new StatusLineLayoutData());
-
- ps.removePropertyChangeListener(this);
- ps.addPropertyChangeListener(this);
-
- this.control = composite;
- return composite;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.ContributionItem#update()
- */
- @Override
- public void update() {
- update(null);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.ContributionItem#update(java.lang.String)
- */
- @Override
- public void update(String id) {
- super.update(id);
-
- if (label == null || label.isDisposed() || ps == null)
- return;
-
- if (id == null || CathyPlugin.AUTO_SAVE_ENABLED.equals(id)) {
- updateEnablement();
- updateSize();
- }
- }
-
- private void updateSize() {
- if (control == null || control.isDisposed())
- return;
-
- Point oldSize = control.getSize();
- control.pack(true);
- Point newSize = control.getSize();
- if (oldSize.equals(newSize))
- return;
-
- control.getParent().layout(true, true);
- }
-
- private void updateEnablement() {
- int value = getValue();
- if (value == ENABLED) {
- label.setText(WorkbenchMessages.AutoBackupIndicator_AutoSaveEnabled_label);
- int intervals = ps.getInt(CathyPlugin.AUTO_SAVE_INTERVALS);
- label.setToolTipText(NLS.bind(WorkbenchMessages.AutoSave_label2,
- intervals));
- } else {
- label.setText(WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_label);
- label.setToolTipText(WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_description);
- }
- if (menu != null) {
- for (IContributionItem item : menu.getItems()) {
- if (item instanceof ActionContributionItem) {
- IAction action = ((ActionContributionItem) item)
- .getAction();
- if (action instanceof ChangeAutoSavePrefAction) {
- action.setChecked(((ChangeAutoSavePrefAction) action)
- .getValue() == value);
- }
- }
- }
- }
- }
-
- private int getValue() {
- return ps.getBoolean(CathyPlugin.AUTO_SAVE_ENABLED) ? ENABLED
- : DISABLED;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.ContributionItem#dispose()
- */
- @Override
- public void dispose() {
- if (label != null) {
- label.dispose();
- label = null;
- }
- control = null;
- if (menu != null) {
- menu.dispose();
- menu = null;
- }
- if (ps != null) {
- ps.removePropertyChangeListener(this);
- ps = null;
- }
- super.dispose();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
- * .jface.util.PropertyChangeEvent)
- */
- public void propertyChange(final PropertyChangeEvent event) {
- if (control == null || control.isDisposed())
- return;
- control.getDisplay().asyncExec(new Runnable() {
- public void run() {
- update(event.getProperty());
- }
- });
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
- * Event)
- */
- public void handleEvent(final Event event) {
- if (event.widget == label) {
- if (event.button == 1) {
- event.display.timerExec(10, new Runnable() {
- public void run() {
- Point loc = label.getParent().toDisplay(event.x,
- event.y);
- updateEnablement();
- menu.getMenu().setLocation(loc);
- menu.getMenu().setVisible(true);
- }
- });
- }
- }
- }
-
- private void changeStatus(int value) {
- ps.setValue(CathyPlugin.AUTO_SAVE_ENABLED, value == ENABLED);
- }
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.util.Util;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
+import org.xmind.ui.resources.FontUtils;
+import org.xmind.ui.util.PrefUtils;
+
+public class AutoBackupIndicator extends WorkbenchWindowControlContribution
+ implements IPropertyChangeListener, Listener {
+
+ private static final int DISABLED = 1;
+
+ private static final int ENABLED = 2;
+
+ private class ChangeAutoSavePrefAction extends Action {
+ private IPreferenceStore ps;
+ private int value;
+
+ /**
+ *
+ */
+ public ChangeAutoSavePrefAction(IPreferenceStore ps, String text,
+ int value) {
+ super(text);
+ this.ps = ps;
+ this.value = value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ if (ps == null)
+ return;
+
+ changeStatus(value);
+ }
+
+ /**
+ * @return the value
+ */
+ public int getValue() {
+ return value;
+ }
+ }
+
+ private static class OpenPreferencePageAction extends Action {
+
+ /**
+ *
+ */
+ public OpenPreferencePageAction() {
+ super(
+ WorkbenchMessages.AutoBackupIndicator_OpenPreferenceAction_text);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ PrefUtils.openPrefDialog(null, PrefUtils.GENERAL_PREF_PAGE_ID);
+ }
+ }
+
+ private Control control;
+
+ private Label label;
+
+ private MenuManager menu;
+
+ private IPreferenceStore ps;
+
+ public AutoBackupIndicator() {
+ super("org.xmind.ui.status.AutoSaveIndicator"); //$NON-NLS-1$
+ }
+
+ protected Control createControl(Composite parent) {
+ ps = CathyPlugin.getDefault().getPreferenceStore();
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.verticalSpacing = 0;
+ layout.horizontalSpacing = 4;
+ composite.setLayout(layout);
+
+// Label sep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
+// sep.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, true));
+
+ label = new Label(composite, SWT.CENTER);
+ label.setText(WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_label);
+ label.setFont(FontUtils.getRelativeHeight(JFaceResources.DEFAULT_FONT,
+ Util.isMac() ? -2 : -1));
+ label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
+ label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
+ label.addListener(SWT.MouseDown, this);
+
+ menu = new MenuManager();
+ menu.add(new ChangeAutoSavePrefAction(
+ ps,
+ WorkbenchMessages.AutoBackupIndicator_DisableAutoSaveAction_text,
+ DISABLED));
+ menu.add(new ChangeAutoSavePrefAction(
+ ps,
+ WorkbenchMessages.AutoBackupIndicator_EnableAutoSaveAction_text,
+ ENABLED));
+ menu.add(new Separator());
+ menu.add(new OpenPreferencePageAction());
+ menu.createContextMenu(label);
+ label.setMenu(menu.getMenu());
+
+ updateEnablement();
+
+// composite.setLayoutData(new StatusLineLayoutData());
+
+ ps.removePropertyChangeListener(this);
+ ps.addPropertyChangeListener(this);
+
+ this.control = composite;
+ return composite;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.ContributionItem#update()
+ */
+ @Override
+ public void update() {
+ update(null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.ContributionItem#update(java.lang.String)
+ */
+ @Override
+ public void update(String id) {
+ super.update(id);
+
+ if (label == null || label.isDisposed() || ps == null)
+ return;
+
+ if (id == null || CathyPlugin.AUTO_SAVE_ENABLED.equals(id)) {
+ updateEnablement();
+ updateSize();
+ }
+ }
+
+ private void updateSize() {
+ if (control == null || control.isDisposed())
+ return;
+
+ Point oldSize = control.getSize();
+ control.pack(true);
+ Point newSize = control.getSize();
+ if (oldSize.equals(newSize))
+ return;
+
+ control.getParent().layout(true, true);
+ }
+
+ private void updateEnablement() {
+ int value = getValue();
+ if (value == ENABLED) {
+ label.setText(WorkbenchMessages.AutoBackupIndicator_AutoSaveEnabled_label);
+ int intervals = ps.getInt(CathyPlugin.AUTO_SAVE_INTERVALS);
+ label.setToolTipText(NLS.bind(WorkbenchMessages.AutoSave_label2,
+ intervals));
+ } else {
+ label.setText(WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_label);
+ label.setToolTipText(WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_description);
+ }
+ if (menu != null) {
+ for (IContributionItem item : menu.getItems()) {
+ if (item instanceof ActionContributionItem) {
+ IAction action = ((ActionContributionItem) item)
+ .getAction();
+ if (action instanceof ChangeAutoSavePrefAction) {
+ action.setChecked(((ChangeAutoSavePrefAction) action)
+ .getValue() == value);
+ }
+ }
+ }
+ }
+ }
+
+ private int getValue() {
+ return ps.getBoolean(CathyPlugin.AUTO_SAVE_ENABLED) ? ENABLED
+ : DISABLED;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.ContributionItem#dispose()
+ */
+ @Override
+ public void dispose() {
+ if (label != null) {
+ label.dispose();
+ label = null;
+ }
+ control = null;
+ if (menu != null) {
+ menu.dispose();
+ menu = null;
+ }
+ if (ps != null) {
+ ps.removePropertyChangeListener(this);
+ ps = null;
+ }
+ super.dispose();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
+ * .jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(final PropertyChangeEvent event) {
+ if (control == null || control.isDisposed())
+ return;
+ control.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ update(event.getProperty());
+ }
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
+ * Event)
+ */
+ public void handleEvent(final Event event) {
+ if (event.widget == label) {
+ if (event.button == 1) {
+ event.display.timerExec(10, new Runnable() {
+ public void run() {
+ Point loc = label.getParent().toDisplay(event.x,
+ event.y);
+ updateEnablement();
+ menu.getMenu().setLocation(loc);
+ menu.getMenu().setVisible(true);
+ }
+ });
+ }
+ }
+ }
+
+ private void changeStatus(int value) {
+ ps.setValue(CathyPlugin.AUTO_SAVE_ENABLED, value == ENABLED);
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoBackupIndicatorToolControl.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoBackupIndicatorToolControl.java
index b99689f49..301dcea91 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoBackupIndicatorToolControl.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoBackupIndicatorToolControl.java
@@ -1,242 +1,242 @@
-package org.xmind.cathy.internal;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.ActionContributionItem;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IContributionItem;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.util.Util;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.xmind.ui.resources.FontUtils;
-import org.xmind.ui.util.PrefUtils;
-
-public class AutoBackupIndicatorToolControl
- implements IPropertyChangeListener, Listener {
-
- private static final int DISABLED = 1;
-
- private static final int ENABLED = 2;
-
- private class ChangeAutoSavePrefAction extends Action {
- private IPreferenceStore ps;
- private int value;
-
- /**
- *
- */
- public ChangeAutoSavePrefAction(IPreferenceStore ps, String text,
- int value) {
- super(text);
- this.ps = ps;
- this.value = value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- if (ps == null)
- return;
-
- changeStatus(value);
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- private static class OpenPreferencePageAction extends Action {
-
- /**
- *
- */
- public OpenPreferencePageAction() {
- super(WorkbenchMessages.AutoBackupIndicator_OpenPreferenceAction_text);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- PrefUtils.openPrefDialog(null, PrefUtils.GENERAL_PREF_PAGE_ID);
- }
- }
-
- private IPreferenceStore ps;
-
- private Control control;
-
- private Label label;
-
- private MenuManager menu;
-
- @Inject
- public AutoBackupIndicatorToolControl() {
- ps = CathyPlugin.getDefault().getPreferenceStore();
- }
-
- @PostConstruct
- public void createGui(Composite parent) {
-
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(1, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- layout.verticalSpacing = 0;
- layout.horizontalSpacing = 4;
- composite.setLayout(layout);
-
- label = new Label(composite, SWT.CENTER);
- label.setText(
- WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_label);
- label.setFont(FontUtils.getRelativeHeight(JFaceResources.DEFAULT_FONT,
- Util.isMac() ? -2 : -1));
- label.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));
- label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
- label.addListener(SWT.MouseDown, this);
-
- menu = new MenuManager();
- menu.add(new ChangeAutoSavePrefAction(ps,
- WorkbenchMessages.AutoBackupIndicator_DisableAutoSaveAction_text,
- DISABLED));
- menu.add(new ChangeAutoSavePrefAction(ps,
- WorkbenchMessages.AutoBackupIndicator_EnableAutoSaveAction_text,
- ENABLED));
- menu.add(new Separator());
- menu.add(new OpenPreferencePageAction());
- menu.createContextMenu(label);
- label.setMenu(menu.getMenu());
-
- updateEnablement();
-
- ps.removePropertyChangeListener(this);
- ps.addPropertyChangeListener(this);
-
- this.control = composite;
-
- }
-
- private void updateEnablement() {
- int value = getValue();
- if (value == ENABLED) {
- label.setText(
- WorkbenchMessages.AutoBackupIndicator_AutoSaveEnabled_label);
- int intervals = ps.getInt(CathyPlugin.AUTO_SAVE_INTERVALS);
- label.setToolTipText(
- NLS.bind(WorkbenchMessages.AutoSave_label2, intervals));
- } else {
- label.setText(
- WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_label);
- label.setToolTipText(
- WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_description);
- }
- if (menu != null) {
- for (IContributionItem item : menu.getItems()) {
- if (item instanceof ActionContributionItem) {
- IAction action = ((ActionContributionItem) item)
- .getAction();
- if (action instanceof ChangeAutoSavePrefAction) {
- action.setChecked(((ChangeAutoSavePrefAction) action)
- .getValue() == value);
- }
- }
- }
- }
- }
-
- private int getValue() {
- return ps.getBoolean(CathyPlugin.AUTO_SAVE_ENABLED) ? ENABLED
- : DISABLED;
- }
-
- public void propertyChange(final PropertyChangeEvent event) {
- if (control == null || control.isDisposed())
- return;
- control.getDisplay().asyncExec(new Runnable() {
- public void run() {
- update(event.getProperty());
- }
- });
- }
-
- public void update(String id) {
- if (label == null || label.isDisposed() || ps == null)
- return;
-
- if (id == null || CathyPlugin.AUTO_SAVE_ENABLED.equals(id)) {
- updateEnablement();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
- * Event)
- */
- public void handleEvent(final Event event) {
- if (event.widget == label) {
- if (event.button == 1) {
- event.display.timerExec(10, new Runnable() {
- public void run() {
- Point loc = label.getParent().toDisplay(event.x,
- event.y);
- updateEnablement();
- menu.getMenu().setLocation(loc);
- menu.getMenu().setVisible(true);
- }
- });
- }
- }
- }
-
- private void changeStatus(int value) {
- ps.setValue(CathyPlugin.AUTO_SAVE_ENABLED, value == ENABLED);
- }
-
- @PreDestroy
- private void dispose() {
- if (label != null) {
- label.dispose();
- label = null;
- }
- control = null;
- if (menu != null) {
- menu.dispose();
- menu = null;
- }
- if (ps != null) {
- ps.removePropertyChangeListener(this);
- ps = null;
- }
- }
+package org.xmind.cathy.internal;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.util.Util;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.xmind.ui.resources.FontUtils;
+import org.xmind.ui.util.PrefUtils;
+
+public class AutoBackupIndicatorToolControl
+ implements IPropertyChangeListener, Listener {
+
+ private static final int DISABLED = 1;
+
+ private static final int ENABLED = 2;
+
+ private class ChangeAutoSavePrefAction extends Action {
+ private IPreferenceStore ps;
+ private int value;
+
+ /**
+ *
+ */
+ public ChangeAutoSavePrefAction(IPreferenceStore ps, String text,
+ int value) {
+ super(text);
+ this.ps = ps;
+ this.value = value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ if (ps == null)
+ return;
+
+ changeStatus(value);
+ }
+
+ /**
+ * @return the value
+ */
+ public int getValue() {
+ return value;
+ }
+ }
+
+ private static class OpenPreferencePageAction extends Action {
+
+ /**
+ *
+ */
+ public OpenPreferencePageAction() {
+ super(WorkbenchMessages.AutoBackupIndicator_OpenPreferenceAction_text);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ PrefUtils.openPrefDialog(null, PrefUtils.GENERAL_PREF_PAGE_ID);
+ }
+ }
+
+ private IPreferenceStore ps;
+
+ private Control control;
+
+ private Label label;
+
+ private MenuManager menu;
+
+ @Inject
+ public AutoBackupIndicatorToolControl() {
+ ps = CathyPlugin.getDefault().getPreferenceStore();
+ }
+
+ @PostConstruct
+ public void createGui(Composite parent) {
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.verticalSpacing = 0;
+ layout.horizontalSpacing = 4;
+ composite.setLayout(layout);
+
+ label = new Label(composite, SWT.CENTER);
+ label.setText(
+ WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_label);
+ label.setFont(FontUtils.getRelativeHeight(JFaceResources.DEFAULT_FONT,
+ Util.isMac() ? -2 : -1));
+ label.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));
+ label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
+ label.addListener(SWT.MouseDown, this);
+
+ menu = new MenuManager();
+ menu.add(new ChangeAutoSavePrefAction(ps,
+ WorkbenchMessages.AutoBackupIndicator_DisableAutoSaveAction_text,
+ DISABLED));
+ menu.add(new ChangeAutoSavePrefAction(ps,
+ WorkbenchMessages.AutoBackupIndicator_EnableAutoSaveAction_text,
+ ENABLED));
+ menu.add(new Separator());
+ menu.add(new OpenPreferencePageAction());
+ menu.createContextMenu(label);
+ label.setMenu(menu.getMenu());
+
+ updateEnablement();
+
+ ps.removePropertyChangeListener(this);
+ ps.addPropertyChangeListener(this);
+
+ this.control = composite;
+
+ }
+
+ private void updateEnablement() {
+ int value = getValue();
+ if (value == ENABLED) {
+ label.setText(
+ WorkbenchMessages.AutoBackupIndicator_AutoSaveEnabled_label);
+ int intervals = ps.getInt(CathyPlugin.AUTO_SAVE_INTERVALS);
+ label.setToolTipText(
+ NLS.bind(WorkbenchMessages.AutoSave_label2, intervals));
+ } else {
+ label.setText(
+ WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_label);
+ label.setToolTipText(
+ WorkbenchMessages.AutoBackupIndicator_AutoSaveDisabled_description);
+ }
+ if (menu != null) {
+ for (IContributionItem item : menu.getItems()) {
+ if (item instanceof ActionContributionItem) {
+ IAction action = ((ActionContributionItem) item)
+ .getAction();
+ if (action instanceof ChangeAutoSavePrefAction) {
+ action.setChecked(((ChangeAutoSavePrefAction) action)
+ .getValue() == value);
+ }
+ }
+ }
+ }
+ }
+
+ private int getValue() {
+ return ps.getBoolean(CathyPlugin.AUTO_SAVE_ENABLED) ? ENABLED
+ : DISABLED;
+ }
+
+ public void propertyChange(final PropertyChangeEvent event) {
+ if (control == null || control.isDisposed())
+ return;
+ control.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ update(event.getProperty());
+ }
+ });
+ }
+
+ public void update(String id) {
+ if (label == null || label.isDisposed() || ps == null)
+ return;
+
+ if (id == null || CathyPlugin.AUTO_SAVE_ENABLED.equals(id)) {
+ updateEnablement();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
+ * Event)
+ */
+ public void handleEvent(final Event event) {
+ if (event.widget == label) {
+ if (event.button == 1) {
+ event.display.timerExec(10, new Runnable() {
+ public void run() {
+ Point loc = label.getParent().toDisplay(event.x,
+ event.y);
+ updateEnablement();
+ menu.getMenu().setLocation(loc);
+ menu.getMenu().setVisible(true);
+ }
+ });
+ }
+ }
+ }
+
+ private void changeStatus(int value) {
+ ps.setValue(CathyPlugin.AUTO_SAVE_ENABLED, value == ENABLED);
+ }
+
+ @PreDestroy
+ private void dispose() {
+ if (label != null) {
+ label.dispose();
+ label = null;
+ }
+ control = null;
+ if (menu != null) {
+ menu.dispose();
+ menu = null;
+ }
+ if (ps != null) {
+ ps.removePropertyChangeListener(this);
+ ps = null;
+ }
+ }
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoSaveService.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoSaveService.java
index 349cb576d..bb9c375c6 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoSaveService.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/AutoSaveService.java
@@ -1,88 +1,88 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.ui.IStartup;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchListener;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.ui.internal.editor.BackgroundSaveWorkbook;
-
-/**
- * @author Frank Shaka
- *
- */
-public class AutoSaveService
- implements IStartup, IWorkbenchListener, IPropertyChangeListener {
-
- private IWorkbench workbench;
-
- /**
- *
- */
- public AutoSaveService() {
- }
-
- /**
- *
- */
- private void checkState() {
- IPreferenceStore ps = CathyPlugin.getDefault().getPreferenceStore();
- boolean enabled = ps.getBoolean(CathyPlugin.AUTO_SAVE_ENABLED);
- int intervals = ps.getInt(CathyPlugin.AUTO_SAVE_INTERVALS) * 60000;
- BackgroundSaveWorkbook.getInstance().reset(intervals, enabled);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
- * .jface.util.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- String property = event.getProperty();
- if (CathyPlugin.AUTO_SAVE_ENABLED.equals(property)
- || CathyPlugin.AUTO_SAVE_INTERVALS.equals(property)) {
- checkState();
- }
- }
-
- public void earlyStartup() {
- this.workbench = PlatformUI.getWorkbench();
- this.workbench.addWorkbenchListener(this);
- CathyPlugin.getDefault().getPreferenceStore()
- .addPropertyChangeListener(this);
- checkState();
- }
-
- public void postShutdown(IWorkbench workbench) {
- if (this.workbench == null)
- return;
- this.workbench.removeWorkbenchListener(this);
- this.workbench = null;
- CathyPlugin.getDefault().getPreferenceStore()
- .removePropertyChangeListener(this);
- BackgroundSaveWorkbook.getInstance().stopAll();
- }
-
- public boolean preShutdown(IWorkbench workbench, boolean forced) {
- return true;
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.IStartup;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchListener;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.ui.internal.editor.BackgroundSaveWorkbook;
+
+/**
+ * @author Frank Shaka
+ *
+ */
+public class AutoSaveService
+ implements IStartup, IWorkbenchListener, IPropertyChangeListener {
+
+ private IWorkbench workbench;
+
+ /**
+ *
+ */
+ public AutoSaveService() {
+ }
+
+ /**
+ *
+ */
+ private void checkState() {
+ IPreferenceStore ps = CathyPlugin.getDefault().getPreferenceStore();
+ boolean enabled = ps.getBoolean(CathyPlugin.AUTO_SAVE_ENABLED);
+ int intervals = ps.getInt(CathyPlugin.AUTO_SAVE_INTERVALS) * 60000;
+ BackgroundSaveWorkbook.getInstance().reset(intervals, enabled);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
+ * .jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ String property = event.getProperty();
+ if (CathyPlugin.AUTO_SAVE_ENABLED.equals(property)
+ || CathyPlugin.AUTO_SAVE_INTERVALS.equals(property)) {
+ checkState();
+ }
+ }
+
+ public void earlyStartup() {
+ this.workbench = PlatformUI.getWorkbench();
+ this.workbench.addWorkbenchListener(this);
+ CathyPlugin.getDefault().getPreferenceStore()
+ .addPropertyChangeListener(this);
+ checkState();
+ }
+
+ public void postShutdown(IWorkbench workbench) {
+ if (this.workbench == null)
+ return;
+ this.workbench.removeWorkbenchListener(this);
+ this.workbench = null;
+ CathyPlugin.getDefault().getPreferenceStore()
+ .removePropertyChangeListener(this);
+ BackgroundSaveWorkbook.getInstance().stopAll();
+ }
+
+ public boolean preShutdown(IWorkbench workbench, boolean forced) {
+ return true;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/BetaVerifier.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/BetaVerifier.java
index ade3ee731..ecab78223 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/BetaVerifier.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/BetaVerifier.java
@@ -1,122 +1,124 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import java.io.IOException;
-import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.program.Program;
-import org.eclipse.swt.widgets.Display;
-
-public class BetaVerifier {
-
- /**
- * The timestamp when the beta will expire. Beta releases will change this
- * value to a valid timestamp.
- */
- // Note: Not defined as 'final' to prevent compiling warning
- // at expression 'BETA_EXPIRE_TIME > 0'.
- private static long BETA_EXPIRY_TIME = 0L;
-
- private static long LAUNCH_TIME = System.currentTimeMillis();
-
- private final Display display;
-
- private final String brandingVersion;
-
- private final String buildId;
-
- public BetaVerifier(Display display) {
- this.display = display;
- this.brandingVersion = System
- .getProperty(CathyApplication.SYS_BRANDING_VERSION, ""); //$NON-NLS-1$
- this.buildId = System.getProperty(CathyApplication.SYS_BUILDID,
- "X.x.x"); //$NON-NLS-1$
- }
-
- public boolean shouldExitAfterBetaExpired() {
- if (isBeta() && isBetaExpired()) {
- promptBetaExpiry();
- return true;
- } else if (isBeta()) {
- String licenseRestrictions = System
- .getProperty("org.xmind.product.license.restrictions"); //$NON-NLS-1$
- if (licenseRestrictions == null || "".equals(licenseRestrictions)) { //$NON-NLS-1$
- licenseRestrictions = NLS.bind(
- WorkbenchMessages.About_BetaExpiryMessage_withExpiryTime,
- new SimpleDateFormat("MMM d, yyyy") //$NON-NLS-1$
- .format(new Date(BETA_EXPIRY_TIME)));
- System.setProperty("org.xmind.product.license.restrictions", //$NON-NLS-1$
- licenseRestrictions);
- }
- }
- return false;
- }
-
- private int openMessageDialog(String message, int dialogType,
- String[] buttonLabels) {
- URL titleIconURL = Platform.getBundle(CathyPlugin.PLUGIN_ID)
- .getResource("icons/xmind.16.png"); //$NON-NLS-1$
- Image titleIcon = null;
- try {
- titleIcon = new Image(display, titleIconURL.openStream());
- } catch (IOException e) {
- }
-
- try {
- MessageDialog dialog = new MessageDialog(null,
- WorkbenchMessages.BetaVerifier_BetaExpiredPromptDialog_windowTitle,
- titleIcon, message, dialogType, buttonLabels, 0);
- return dialog.open();
- } finally {
- if (titleIcon != null)
- titleIcon.dispose();
- }
-
- }
-
- private void promptBetaExpiry() {
- int selection = openMessageDialog(
- NLS.bind(
- WorkbenchMessages.BetaVerifier_BetaExpiredPromptDialog_message_withBrandingVersion_andBuildId,
- brandingVersion, buildId),
- MessageDialog.INFORMATION,
- new String[] {
- WorkbenchMessages.BetaVerifier_BetaExpiredPromptDialog_CheckAndInstallButton_text,
- WorkbenchMessages.BetaVerifier_BetaExpiredPromptDialog_ExitButton_text });
- if (selection == 0) {
- openDownloadSite();
- }
- }
-
- private void openDownloadSite() {
- Program.launch("http://www.xmind.net/xmind/beta-expired/" //$NON-NLS-1$
- + buildId.replace("qualifier", "000000000000")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public static boolean isBeta() {
- return BETA_EXPIRY_TIME > 0;
- }
-
- public static boolean isBetaExpired() {
- return LAUNCH_TIME > BETA_EXPIRY_TIME;
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import java.io.IOException;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.program.Program;
+import org.eclipse.swt.widgets.Display;
+import org.xmind.core.net.util.LinkUtils;
+
+public class BetaVerifier {
+
+ /**
+ * The timestamp when the beta will expire. Beta releases will change this
+ * value to a valid timestamp.
+ */
+ // Note: Not defined as 'final' to prevent compiling warning
+ // at expression 'BETA_EXPIRE_TIME > 0'.
+ private static long BETA_EXPIRY_TIME = 0L;
+
+ private static long LAUNCH_TIME = System.currentTimeMillis();
+
+ private final Display display;
+
+ private final String brandingVersion;
+
+ private final String buildId;
+
+ public BetaVerifier(Display display) {
+ this.display = display;
+ this.brandingVersion = System
+ .getProperty(CathyApplication.SYS_BRANDING_VERSION, ""); //$NON-NLS-1$
+ this.buildId = System.getProperty(CathyApplication.SYS_BUILDID,
+ "X.x.x"); //$NON-NLS-1$
+ }
+
+ public boolean shouldExitAfterBetaExpired() {
+ if (isBeta() && isBetaExpired()) {
+ promptBetaExpiry();
+ return true;
+ } else if (isBeta()) {
+ String licenseRestrictions = System
+ .getProperty("org.xmind.product.license.restrictions"); //$NON-NLS-1$
+ if (licenseRestrictions == null || "".equals(licenseRestrictions)) { //$NON-NLS-1$
+ licenseRestrictions = NLS.bind(
+ WorkbenchMessages.About_BetaExpiryMessage_withExpiryTime,
+ new SimpleDateFormat("MMM d, yyyy") //$NON-NLS-1$
+ .format(new Date(BETA_EXPIRY_TIME)));
+ System.setProperty("org.xmind.product.license.restrictions", //$NON-NLS-1$
+ licenseRestrictions);
+ }
+ }
+ return false;
+ }
+
+ private int openMessageDialog(String message, int dialogType,
+ String[] buttonLabels) {
+ URL titleIconURL = Platform.getBundle(CathyPlugin.PLUGIN_ID)
+ .getResource("icons/xmind.16.png"); //$NON-NLS-1$
+ Image titleIcon = null;
+ try {
+ titleIcon = new Image(display, titleIconURL.openStream());
+ } catch (IOException e) {
+ }
+
+ try {
+ MessageDialog dialog = new MessageDialog(null,
+ WorkbenchMessages.BetaVerifier_BetaExpiredPromptDialog_windowTitle,
+ titleIcon, message, dialogType, buttonLabels, 0);
+ return dialog.open();
+ } finally {
+ if (titleIcon != null)
+ titleIcon.dispose();
+ }
+
+ }
+
+ private void promptBetaExpiry() {
+ int selection = openMessageDialog(
+ NLS.bind(
+ WorkbenchMessages.BetaVerifier_BetaExpiredPromptDialog_message_withBrandingVersion_andBuildId,
+ brandingVersion, buildId),
+ MessageDialog.INFORMATION,
+ new String[] {
+ WorkbenchMessages.BetaVerifier_BetaExpiredPromptDialog_CheckAndInstallButton_text,
+ WorkbenchMessages.BetaVerifier_BetaExpiredPromptDialog_ExitButton_text });
+ if (selection == 0) {
+ openDownloadSite();
+ }
+ }
+
+ private void openDownloadSite() {
+ Program.launch(
+ LinkUtils.getLinkByLanguage(true, true, "/xmind/beta-expired/") //$NON-NLS-1$
+ + buildId.replace("qualifier", "000000000000")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public static boolean isBeta() {
+ return BETA_EXPIRY_TIME > 0;
+ }
+
+ public static boolean isBetaExpired() {
+ return LAUNCH_TIME > BETA_EXPIRY_TIME;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyApplication.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyApplication.java
index 0bd3431ce..c337e3cee 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyApplication.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyApplication.java
@@ -1,300 +1,257 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import java.awt.Toolkit;
-import java.io.File;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.equinox.app.IApplication;
-import org.eclipse.equinox.app.IApplicationContext;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.internal.IPreferenceConstants;
-import org.eclipse.ui.internal.WorkbenchPlugin;
-import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
-import org.xmind.core.Core;
-import org.xmind.core.internal.dom.DOMConstants;
-import org.xmind.core.usagedata.IUsageDataSampler;
-import org.xmind.ui.internal.MindMapUIPlugin;
-import org.xmind.ui.internal.app.IApplicationValidator;
-import org.xmind.ui.prefs.PrefConstants;
-
-/**
- * This class controls all aspects of the application's execution
- */
-public class CathyApplication implements IApplication {
-
- public static final String SYS_VERSION = "org.xmind.product.version"; //$NON-NLS-1$
-
- public static final String SYS_BUILDID = "org.xmind.product.buildid"; //$NON-NLS-1$
-
- public static final String SYS_BRANDING_VERSION = "org.xmind.product.brandingVersion"; //$NON-NLS-1$
-
- public static final String SYS_APP_STATUS = "org.xmind.cathy.app.status"; //$NON-NLS-1$
-
- /**
- * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
- */
- public Object start(IApplicationContext context) throws Exception {
- // Check product information.
- // Product build id and version may have been set in config.ini.
- // If not set, calculate them using runtime properties.
- String buildId = System.getProperty(SYS_BUILDID);
- if (buildId == null || "".equals(buildId)) { //$NON-NLS-1$
- buildId = calculateBuildId(context);
- System.setProperty(SYS_BUILDID, buildId);
- }
- String appVersion = System.getProperty(SYS_VERSION);
- if (appVersion == null || "".equals(appVersion)) { //$NON-NLS-1$
- appVersion = extractVersionNumber(buildId);
- System.setProperty(SYS_VERSION, appVersion);
- }
-
- System.setProperty("org.xmind.product.about.copyright", //$NON-NLS-1$
- WorkbenchMessages.About_Copyright);
- System.setProperty("org.xmind.product.about.homepage", //$NON-NLS-1$
- WorkbenchMessages.About_Homepage);
-
- IPreferenceStore pref = MindMapUIPlugin.getDefault()
- .getPreferenceStore();
-
- String name = pref.getString(PrefConstants.AUTHOR_INFO_NAME);
-
- if (name == null || "".equals(name)) //$NON-NLS-1$
- name = System.getProperty("user.name"); //$NON-NLS-1$
- if (name != null)
- System.setProperty(DOMConstants.AUTHOR_NAME, name);
-
- if (pref.getString(PrefConstants.AUTHOR_INFO_EMAIL) != null)
- System.setProperty(DOMConstants.AUTHOR_EMAIL,
- pref.getString(PrefConstants.AUTHOR_INFO_EMAIL));
-
- if (pref.getString(PrefConstants.AUTHOR_INFO_ORG) != null)
- System.setProperty(DOMConstants.AUTHOR_ORG,
- pref.getString(PrefConstants.AUTHOR_INFO_ORG));
-
- // Set Cathy product as the workbook creator.
- Core.getWorkbookBuilder().setCreator("XMind", buildId); //$NON-NLS-1$
-
- // Create the default display instance.
- Display display = PlatformUI.createDisplay();
-
- try {
- // Install global OpenDocument listener:
- OpenDocumentQueue.getInstance().hook(display);
-
- /// Activate network proxy settings. On Linux, we need a
- /// UI environment to show a dialog for retrieving the master
- /// password of the secure storage containing proxy server
- /// credentials.
- CathyPlugin.getDefault().activateNetworkSettings();
-
- // Check if we are in beta and should quit due to beta expiry.
- if (new BetaVerifier(display).shouldExitAfterBetaExpired())
- return EXIT_OK;
-
- // Check if this app session should exit early:
- if (shouldExitEarly(context)) {
- // Log all application arguments to local disk to exchange
- // between running XMind instances:
- logApplicationArgs();
- return EXIT_OK;
- }
-
- // Log all application arguments to local disk to exchange
- // between running XMind instances:
- logApplicationArgs();
-
- // Mark application status to 'starting':
- System.setProperty(SYS_APP_STATUS, "starting"); //$NON-NLS-1$
-
- // Set cookies to let web pages loaded within internal web browser
- // to recognize the environment:
- initializeInternalBrowserCookies();
-
- //Close model's auto-save to avoid repeated model elements
- //which application exits non-normally:
- WorkbenchPlugin.getDefault().getPreferenceStore()
- .setValue(IPreferenceConstants.WORKBENCH_SAVE_INTERVAL, 0);
-
- try {
- captureAppSessionInfo(
- CathyPlugin.getDefault().getUsageDataCollector(),
- context, buildId);
-
- // Launch workbench and get return code:
- int returnCode = PlatformUI.createAndRunWorkbench(display,
- new CathyWorkbenchAdvisor());
-
- if (returnCode == PlatformUI.RETURN_RESTART) {
- // Restart:
- return EXIT_RESTART;
- }
-
- // Quit:
- return EXIT_OK;
- } finally {
- CathyPlugin.getDefault().getUsageDataCollector().put(
- "ShutDownTime", //$NON-NLS-1$
- System.currentTimeMillis());
- }
- } finally {
- display.dispose();
- }
- }
-
- /**
- * @param sampler
- * @param context
- * @param buildId
- */
- private void captureAppSessionInfo(IUsageDataSampler sampler,
- IApplicationContext context, String buildId) {
- sampler.put("StartUpTime", //$NON-NLS-1$
- System.currentTimeMillis());
- sampler.put("AppId", //$NON-NLS-1$
- context.getBrandingApplication());
- sampler.put("BuildId", buildId); //$NON-NLS-1$
- sampler.put("DistributionId", //$NON-NLS-1$
- System.getProperty("org.xmind.product.distribution.id", //$NON-NLS-1$
- null));
- sampler.put("NL", Platform.getNL()); //$NON-NLS-1$
- sampler.put("OS", Platform.getOS()); //$NON-NLS-1$
- sampler.put("Arch", Platform.getOSArch()); //$NON-NLS-1$
- sampler.put("OSName", System.getProperty("os.name", null)); //$NON-NLS-1$ //$NON-NLS-2$
- sampler.put("OSVersion", System.getProperty("os.version", null)); //$NON-NLS-1$ //$NON-NLS-2$
- sampler.put("Country", System.getProperty("user.country", null)); //$NON-NLS-1$ //$NON-NLS-2$
- sampler.put("JavaVersion", System.getProperty("java.version", null)); //$NON-NLS-1$ //$NON-NLS-2$
- sampler.put("JavaVendor", System.getProperty("java.vendor", null)); //$NON-NLS-1$ //$NON-NLS-2$
- sampler.put("ScreenWidth", //$NON-NLS-1$
- Toolkit.getDefaultToolkit().getScreenSize().width);
- sampler.put("ScreenHeight", //$NON-NLS-1$
- Toolkit.getDefaultToolkit().getScreenSize().height);
- sampler.put("ScreenResolution", //$NON-NLS-1$
- Toolkit.getDefaultToolkit().getScreenResolution());
-
- }
-
- private static String calculateBuildId(IApplicationContext context) {
- String buildId = System.getProperty("eclipse.buildId"); //$NON-NLS-1$
- if (buildId != null && !"".equals(buildId)) //$NON-NLS-1$
- return buildId;
- return context.getBrandingBundle().getVersion().toString();
- }
-
- private static String extractVersionNumber(String buildId) {
- String[] numbers = buildId.split("\\."); //$NON-NLS-1$
- StringBuilder buffer = new StringBuilder(10);
- for (int i = 0; i < 3; i++) {
- if (i >= numbers.length)
- break;
- if (buffer.length() > 0) {
- buffer.append('.');
- }
- buffer.append(numbers[i]);
- }
- return buffer.toString();
- }
-
- private void initializeInternalBrowserCookies() {
- String appVersion = System.getProperty(SYS_VERSION);
- Browser.setCookie(
- "_env=xmind_" + appVersion //$NON-NLS-1$
- + "; path=/; domain=.xmind.net", //$NON-NLS-1$
- "http://www.xmind.net/"); //$NON-NLS-1$
- }
-
- private void logApplicationArgs() {
- final String[] args = Platform.getApplicationArgs();
- if (args == null || args.length == 0)
- return;
-
- Log openingLog = Log.get(Log.OPENING);
- for (String arg : args) {
- if ("-p".equals(arg)) {//$NON-NLS-1$
- // The "-p" argument is used to start Presentation Mode
- // immediately on startup:
- System.setProperty("org.xmind.cathy.startup.presentation", //$NON-NLS-1$
- "true"); //$NON-NLS-1$
- } else if (arg.startsWith("xmind:") || new File(arg).exists()) { //$NON-NLS-1$
- // Add xmind command or existing file path to '.opening' log:
- openingLog.append(arg);
- } else if (!arg.startsWith("-psn_0_")) { //$NON-NLS-1$
- // The "-psn_0_" argument is passed in by
- // Mac OS X for each GUI application. No need to log that.
- // Log any other unknown command line argument for debugging:
- CathyPlugin.log("Skip unrecognized command line argument: '" //$NON-NLS-1$
- + arg + "'"); //$NON-NLS-1$
- }
- }
- }
-
- private boolean shouldExitEarly(IApplicationContext appContext)
- throws Exception {
- IExtensionPoint extPoint = Platform.getExtensionRegistry()
- .getExtensionPoint(
- "org.xmind.ui.toolkit.applicationValidators"); //$NON-NLS-1$
- if (extPoint != null) {
- for (IExtension ext : extPoint.getExtensions()) {
- for (IConfigurationElement validatorElement : ext
- .getConfigurationElements()) {
- if ("applicationValidator" //$NON-NLS-1$
- .equals(validatorElement.getName())) {
- Object validator = validatorElement
- .createExecutableExtension(
- IWorkbenchRegistryConstants.ATT_CLASS);
- if (validator instanceof IApplicationValidator
- && ((IApplicationValidator) validator)
- .shouldApplicationExitEarly(
- appContext)) {
- return true;
- }
- }
- }
- }
- }
-
- return false;
- }
-
- /**
- * @see org.eclipse.equinox.app.IApplication#stop()
- */
- public void stop() {
- if (!PlatformUI.isWorkbenchRunning())
- return;
-
- final IWorkbench workbench = PlatformUI.getWorkbench();
- if (workbench == null)
- return;
-
- Display display = workbench.getDisplay();
- if (display == null || display.isDisposed())
- return;
-
- display.syncExec(new Runnable() {
- public void run() {
- workbench.close();
- }
- });
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.IPreferenceConstants;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
+import org.xmind.core.Core;
+import org.xmind.core.internal.dom.DOMConstants;
+import org.xmind.ui.internal.MindMapUIPlugin;
+import org.xmind.ui.internal.app.IApplicationValidator;
+import org.xmind.ui.prefs.PrefConstants;
+
+/**
+ * This class controls all aspects of the application's execution
+ */
+public class CathyApplication implements IApplication {
+
+ public static final String SYS_VERSION = "org.xmind.product.version"; //$NON-NLS-1$
+
+ public static final String SYS_BUILDID = "org.xmind.product.buildid"; //$NON-NLS-1$
+
+ public static final String SYS_BRANDING_VERSION = "org.xmind.product.brandingVersion"; //$NON-NLS-1$
+
+ public static final String SYS_APP_STATUS = "org.xmind.cathy.app.status"; //$NON-NLS-1$
+
+ /**
+ * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
+ */
+ public Object start(IApplicationContext context) throws Exception {
+ // Check product information.
+ // Product build id and version may have been set in config.ini.
+ // If not set, calculate them using runtime properties.
+ String buildId = System.getProperty(SYS_BUILDID);
+ if (buildId == null || "".equals(buildId)) { //$NON-NLS-1$
+ buildId = calculateBuildId(context);
+ System.setProperty(SYS_BUILDID, buildId);
+ }
+ String appVersion = System.getProperty(SYS_VERSION);
+ if (appVersion == null || "".equals(appVersion)) { //$NON-NLS-1$
+ appVersion = extractVersionNumber(buildId);
+ System.setProperty(SYS_VERSION, appVersion);
+ }
+
+ System.setProperty("org.xmind.product.about.copyright", //$NON-NLS-1$
+ WorkbenchMessages.About_Copyright);
+ System.setProperty("org.xmind.product.about.homepage", //$NON-NLS-1$
+ WorkbenchMessages.About_Homepage);
+
+ IPreferenceStore pref = MindMapUIPlugin.getDefault()
+ .getPreferenceStore();
+
+ String name = pref.getString(PrefConstants.AUTHOR_INFO_NAME);
+
+ if (name == null || "".equals(name)) //$NON-NLS-1$
+ name = System.getProperty("user.name"); //$NON-NLS-1$
+ if (name != null)
+ System.setProperty(DOMConstants.AUTHOR_NAME, name);
+
+ if (pref.getString(PrefConstants.AUTHOR_INFO_EMAIL) != null)
+ System.setProperty(DOMConstants.AUTHOR_EMAIL,
+ pref.getString(PrefConstants.AUTHOR_INFO_EMAIL));
+
+ if (pref.getString(PrefConstants.AUTHOR_INFO_ORG) != null)
+ System.setProperty(DOMConstants.AUTHOR_ORG,
+ pref.getString(PrefConstants.AUTHOR_INFO_ORG));
+
+ // Set Cathy product as the workbook creator.
+ Core.getWorkbookBuilder().setCreator("XMind", buildId); //$NON-NLS-1$
+
+ // Create the default display instance.
+ Display display = PlatformUI.createDisplay();
+
+ try {
+ // Install global OpenDocument listener:
+ OpenDocumentQueue.getInstance().hook(display);
+
+ /// Activate network proxy settings. On Linux, we need a
+ /// UI environment to show a dialog for retrieving the master
+ /// password of the secure storage containing proxy server
+ /// credentials.
+ CathyPlugin.getDefault().activateNetworkSettings();
+
+ // Check if we are in beta and should quit due to beta expiry.
+ if (new BetaVerifier(display).shouldExitAfterBetaExpired())
+ return EXIT_OK;
+
+ // Check if this app session should exit early:
+ if (shouldExitEarly(context)) {
+ // Log all application arguments to local disk to exchange
+ // between running XMind instances:
+ logApplicationArgs();
+ return EXIT_OK;
+ }
+
+ // Log all application arguments to local disk to exchange
+ // between running XMind instances:
+ logApplicationArgs();
+
+ // Mark application status to 'starting':
+ System.setProperty(SYS_APP_STATUS, "starting"); //$NON-NLS-1$
+
+ // Set cookies to let web pages loaded within internal web browser
+ // to recognize the environment:
+ initializeInternalBrowserCookies();
+
+ //Close model's auto-save to avoid repeated model elements
+ //which application exits non-normally:
+ WorkbenchPlugin.getDefault().getPreferenceStore()
+ .setValue(IPreferenceConstants.WORKBENCH_SAVE_INTERVAL, 0);
+
+ // Launch workbench and get return code:
+ int returnCode = PlatformUI.createAndRunWorkbench(display,
+ new CathyWorkbenchAdvisor());
+
+ if (returnCode == PlatformUI.RETURN_RESTART) {
+ // Restart:
+ return EXIT_RESTART;
+ }
+
+ // Quit:
+ return EXIT_OK;
+
+ } finally {
+ display.dispose();
+ }
+ }
+
+ private static String calculateBuildId(IApplicationContext context) {
+ String buildId = System.getProperty("eclipse.buildId"); //$NON-NLS-1$
+ if (buildId != null && !"".equals(buildId)) //$NON-NLS-1$
+ return buildId;
+ return context.getBrandingBundle().getVersion().toString();
+ }
+
+ private static String extractVersionNumber(String buildId) {
+ String[] numbers = buildId.split("\\."); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder(10);
+ for (int i = 0; i < 3; i++) {
+ if (i >= numbers.length)
+ break;
+ if (buffer.length() > 0) {
+ buffer.append('.');
+ }
+ buffer.append(numbers[i]);
+ }
+ return buffer.toString();
+ }
+
+ private void initializeInternalBrowserCookies() {
+ String appVersion = System.getProperty(SYS_VERSION);
+ Browser.setCookie(
+ "_env=xmind_" + appVersion //$NON-NLS-1$
+ + "; path=/; domain=.xmind.net", //$NON-NLS-1$
+ "https://www.xmind.net/"); //$NON-NLS-1$
+ }
+
+ private void logApplicationArgs() {
+ final String[] args = Platform.getApplicationArgs();
+ if (args == null || args.length == 0)
+ return;
+
+ Log openingLog = Log.get(Log.OPENING);
+ for (String arg : args) {
+ if ("-p".equals(arg)) {//$NON-NLS-1$
+ // The "-p" argument is used to start Presentation Mode
+ // immediately on startup:
+ System.setProperty("org.xmind.cathy.startup.presentation", //$NON-NLS-1$
+ "true"); //$NON-NLS-1$
+ } else if (arg.startsWith("xmind:") || new File(arg).exists()) { //$NON-NLS-1$
+ // Add xmind command or existing file path to '.opening' log:
+ openingLog.append(arg);
+ } else if (!arg.startsWith("-psn_0_")) { //$NON-NLS-1$
+ // The "-psn_0_" argument is passed in by
+ // Mac OS X for each GUI application. No need to log that.
+ // Log any other unknown command line argument for debugging:
+ CathyPlugin.log("Skip unrecognized command line argument: '" //$NON-NLS-1$
+ + arg + "'"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private boolean shouldExitEarly(IApplicationContext appContext)
+ throws Exception {
+ IExtensionPoint extPoint = Platform.getExtensionRegistry()
+ .getExtensionPoint(
+ "org.xmind.ui.toolkit.applicationValidators"); //$NON-NLS-1$
+ if (extPoint != null) {
+ for (IExtension ext : extPoint.getExtensions()) {
+ for (IConfigurationElement validatorElement : ext
+ .getConfigurationElements()) {
+ if ("applicationValidator" //$NON-NLS-1$
+ .equals(validatorElement.getName())) {
+ Object validator = validatorElement
+ .createExecutableExtension(
+ IWorkbenchRegistryConstants.ATT_CLASS);
+ if (validator instanceof IApplicationValidator
+ && ((IApplicationValidator) validator)
+ .shouldApplicationExitEarly(
+ appContext)) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.equinox.app.IApplication#stop()
+ */
+ public void stop() {
+ if (!PlatformUI.isWorkbenchRunning())
+ return;
+
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ if (workbench == null)
+ return;
+
+ Display display = workbench.getDisplay();
+ if (display == null || display.isDisposed())
+ return;
+
+ display.syncExec(new Runnable() {
+ public void run() {
+ workbench.close();
+ }
+ });
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyPlugin.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyPlugin.java
index d077c2e8a..304829dd9 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyPlugin.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyPlugin.java
@@ -1,530 +1,537 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.PlatformObject;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.service.debug.DebugOptions;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-import org.xmind.core.Core;
-import org.xmind.core.internal.runtime.WorkspaceConfigurer;
-import org.xmind.core.internal.runtime.WorkspaceSession;
-import org.xmind.core.licensing.ILicenseAgent;
-import org.xmind.core.usagedata.IUsageDataSampler;
-import org.xmind.ui.internal.app.ApplicationConstants;
-import org.xmind.ui.internal.statushandlers.DefaultErrorReporter;
-import org.xmind.ui.internal.statushandlers.IErrorReporter;
-
-/*---- BAD BOY HANDSOME DEBUT, DO NOT TOUCH ME ----*/
-/*---- BEGIN IMPORT ----*/
-/*---- END IMPORT ----*/
-/*---- BAD BOY PERFECT CURTAIN CALL, DO NOT TOUCH ME ----*/
-
-/**
- * The main plugin class to be used in the desktop.
- */
-public class CathyPlugin extends AbstractUIPlugin {
-
- public static final String PLUGIN_ID = "org.xmind.cathy"; //$NON-NLS-1$
-
- /**
- * Boolean value:
- *
- * true to enable auto saving service when there's opened
- * workbooks
- * false to disable this service
- *
- */
- public static final String AUTO_SAVE_ENABLED = "autoSaveEnabled"; //$NON-NLS-1$
-
- /**
- * Integer value:
- * the intervals (in minutes) between auto saving actions
- */
- public static final String AUTO_SAVE_INTERVALS = "autoSaveIntervals"; //$NON-NLS-1$
-
- /**
- * (Deprecated, use {@link #STARTUP_ACTION} instead) Boolean value:
- *
- * true to remember unclosed workbooks when XMind quits and
- * open them next time XMind starts
- * false to always open a bootstrap workbook when XMind
- * opens
- *
- */
- public static final String RESTORE_LAST_SESSION = "restoreLastSession"; //$NON-NLS-1$
-
- /**
- * Boolean value:
- *
- * true to check updates when XMind starts
- * false to skip update checking when XMind starts
- *
- */
- public static final String CHECK_UPDATES_ON_STARTUP = "checkUpdatesOnStartup"; //$NON-NLS-1$
-
- /**
- * Integer value (enumerated):
- *
- * 0({@link #STARTUP_ACTION_WIZARD}): opens a 'New
- * Workbook' wizard dialog on startup
- * 1({@link #STARTUP_ACTION_BLANK}): opens a blank map on
- * startup
- * 2({@link #STARTUP_ACTION_HOME}): opens the home map on
- * startup
- * 3({@link #STARTUP_ACTION_LAST}): opens last session on
- * startup
- *
- */
- public static final String STARTUP_ACTION = "startupAction2"; //$NON-NLS-1$
-
- /**
- * Integer preference store value for opening a 'New Workbook' wizard dialog
- * on startup. (value=0)
- *
- * @see #STARTUP_ACTION
- */
- public static final int STARTUP_ACTION_WIZARD = 0;
-
- /**
- * Integer preference store value for opening a blank map on startup.
- * (value=1)
- *
- * @see #STARTUP_ACTION
- */
- public static final int STARTUP_ACTION_BLANK = 1;
-
- /**
- * Integer preference store value for opening the home map on startup.
- * (value=2)
- *
- * @see #STARTUP_ACTION
- */
- public static final int STARTUP_ACTION_HOME = 2;
-
- /**
- * Integer preference store value for opening last session on startup.
- * (value=3)
- *
- * @see #STARTUP_ACTION
- */
- public static final int STARTUP_ACTION_LAST = 3;
-
- /**
- * Boolean value:
- *
- * true to hide system notifications (usually pushed to the
- * user by pop-up windows)
- * false to show system notifications
- *
- */
- //public static final String HIDE_NOTIFICATIONS = "hideNotifications"; //$NON-NLS-1$
-
- /**
- * String constants identifying the extension part of a XMind command file
- * name.
- */
- public static final String COMMAND_FILE_EXT = ".xmind-command"; //$NON-NLS-1$
-
- /**
- * Online help page.
- */
- public static final String ONLINE_HELP_URL = "https://www.xmind.net/xmind/help"; //$NON-NLS-1$
-
- /**
- * Boolean value:
- *
- * true to upload usage data to XMind server
- * false to skip uploading usage data
- *
- */
- public static final String USAGE_DATA_UPLOADING_ENABLED = "usageDataUploadingEnabled"; //$NON-NLS-1$
-
- /**
- * One minute delay between two auto save operations.
- */
- public static final int AUTO_SAVE_EDITOR_STATE_INTERVALS = 60000;
- public static final String OPTION_AUTO_SAVE_EDITOR_STATE_INTERVALS = "/debug/autoSaveEditorStateIntervals"; //$NON-NLS-1$
-
- // The shared instance.
- private static CathyPlugin plugin;
-
- private ServiceTracker debugTracker;
-
- private WorkspaceSession xmindWorkspaceSession;
-
- private IUsageDataSampler usageDataSampler;
-
- private IErrorReporter errorReporter;
-
- private LicenseAgentProxy licenseAgent;
-
- private ILogger logger;
-
- /**
- * The constructor.
- */
- public CathyPlugin() {
- plugin = this;
- }
-
- /**
- * This method is called upon plug-in activation
- */
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
-
- /*---- BAD BOY HANDSOME DEBUT, DO NOT TOUCH ME ----*/
- /*---- BEGIN INSERT ----*/
- /*---- END INSERT ----*/
- /*---- BAD BOY PERFECT CURTAIN CALL, DO NOT TOUCH ME ----*/
-
- usageDataSampler = IUsageDataSampler.NULL;
- errorReporter = DefaultErrorReporter.getInstance();
- licenseAgent = new LicenseAgentProxy();
-
- logger = new ILogger() {
-
- public void logWarning(String message, Throwable error) {
- getLog().log(toStatus(IStatus.ERROR, message, error));
- }
-
- public void logInfo(String message, Throwable error) {
- getLog().log(toStatus(IStatus.WARNING, message, error));
- }
-
- public void logError(String message, Throwable error) {
- getLog().log(toStatus(IStatus.INFO, message, error));
- }
-
- private IStatus toStatus(int severity, String message,
- Throwable error) {
- if (message == null) {
- message = error.getMessage();
- }
- return new Status(severity, PLUGIN_ID, message, error);
- }
- };
-
-// activateNetworkSettings();
-
- activateXMindCore();
-
- /*
- * We have to manually activate 'org.xmind.ui' plugin so that command
- * handler classes contributed by that plugin can be loaded upon
- * startup. This ensures that IElementUpdater implementations and
- * enablement updates to behave correctly. For example, the class
- * org.xmind.ui.internal.handlers.ClearWorkbookHistoryHandler should be
- * loaded on startup so that its enablement state can be correctly
- * updated, otherwise the command in menu will be shown as enabled even
- * when it should not be.
- */
- activateMindMapUIContributions();
-
- hackConstants();
-
- upgradeWorkspace();
-
- }
-
-// usageDataCollector.setUploadEnabled(getPreferenceStore()
-// .getBoolean(USAGE_DATA_UPLOADING_ENABLED));
-
- private void hackConstants() {
- ConstantsHacker.hack();
- }
-
- /**
- * This method is called when the plug-in is stopped
- */
- @Override
- public void stop(BundleContext context) throws Exception {
- if (xmindWorkspaceSession != null) {
- xmindWorkspaceSession.close();
- xmindWorkspaceSession = null;
- }
-
- licenseAgent = null;
-
- super.stop(context);
- plugin = null;
- }
-
- public void activateNetworkSettings() {
- Bundle networkPlugin = Platform.getBundle("org.eclipse.core.net"); //$NON-NLS-1$
- if (networkPlugin != null) {
- try {
- networkPlugin
- .loadClass("org.eclipse.core.internal.net.Activator"); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- getLog().log(new Status(IStatus.WARNING, PLUGIN_ID,
- "Failed to activate plugin 'org.eclipse.core.net'.", //$NON-NLS-1$
- e));
- }
- } else {
- getLog().log(new Status(IStatus.WARNING, PLUGIN_ID,
- "Plugin 'org.eclipse.core.net' not found. Network proxies may not be correct.")); //$NON-NLS-1$
- }
- }
-
- private void activateXMindCore() throws CoreException {
- WorkspaceConfigurer.setDefaultWorkspaceLocation(
- WorkspaceConfigurer.INSTANCE_LOCATION);
-
- xmindWorkspaceSession = WorkspaceSession
- .openSessionIn(new File(Core.getWorkspace().getTempDir()));
- }
-
- private void activateMindMapUIContributions() {
- Bundle uiPlugin = Platform.getBundle("org.xmind.ui"); //$NON-NLS-1$
- if (uiPlugin != null) {
- try {
- uiPlugin.loadClass("org.xmind.ui.internal.XmindUIPlugin"); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- getLog().log(new Status(IStatus.WARNING, PLUGIN_ID,
- "Failed to activate plugin 'org.xmind.ui'.", //$NON-NLS-1$
- e));
- }
- } else {
- getLog().log(new Status(IStatus.WARNING, PLUGIN_ID,
- "Plugin 'org.xmind.ui' is not found.")); //$NON-NLS-1$
- }
- }
-
- /**
- * @return the logger
- */
- public ILogger getLogger() {
- return logger;
- }
-
- /**
- * Returns the distribution identifier of this XMind product.
- *
- * @return the distribution identifier of this XMind product
- * @deprecated Use system property
- * "org.xmind.product.distribution.id"
- */
- public static String getDistributionId() {
- String distribId = System
- .getProperty(ApplicationConstants.PRODUCT_DISTRIBITION_ID);
- if (distribId == null || "".equals(distribId)) { //$NON-NLS-1$
- distribId = "cathy_portable"; //$NON-NLS-1$
- }
- return distribId;
- }
-
- public DebugOptions getDebugOptions() {
- if (debugTracker == null) {
- debugTracker = new ServiceTracker(
- getBundle().getBundleContext(),
- DebugOptions.class.getName(), null);
- debugTracker.open();
- }
- return debugTracker.getService();
- }
-
- public boolean isDebugging(String option) {
- DebugOptions debugOptions = getDebugOptions();
- return debugOptions != null && debugOptions.isDebugEnabled()
- && debugOptions.getBooleanOption(PLUGIN_ID + option, false);
- }
-
- public String getDebugValue(String option) {
- DebugOptions debugOptions = getDebugOptions();
- return debugOptions == null ? null
- : debugOptions.getOption(PLUGIN_ID + option, null);
- }
-
- public int getDebugValue(String option, int defaultValue) {
- DebugOptions debugOptions = getDebugOptions();
- return debugOptions == null ? defaultValue
- : debugOptions.getIntegerOption(PLUGIN_ID + option,
- defaultValue);
- }
-
- public Properties loadNLSProperties(String pathBase) {
- return doLoadNLSProperties(getBundle(), pathBase);
- }
-
- public IUsageDataSampler getUsageDataCollector() {
- return usageDataSampler;
- }
-
- void setUsageDataCollector(IUsageDataSampler sampler) {
- this.usageDataSampler = sampler == null ? IUsageDataSampler.NULL
- : sampler;
- }
-
- /**
- * @return
- */
- public IErrorReporter getErrorReporter() {
- return errorReporter;
- }
-
- void setErrorReporter(IErrorReporter reporter) {
- this.errorReporter = reporter == null
- ? DefaultErrorReporter.getInstance() : reporter;
- }
-
- public ILicenseAgent getLicenseAgent() {
- return licenseAgent;
- }
-
- void setLicenseAgent(ILicenseAgent agent) {
- this.licenseAgent.setDelegate(agent);
- }
-
- private void upgradeWorkspace() {
- IPath stateLocation;
- try {
- stateLocation = Platform.getStateLocation(getBundle());
- } catch (Exception e) {
- return;
- }
- String versionFileName = String.format("workspace-upgraded-v%s", //$NON-NLS-1$
- getBundle().getVersion().toString());
- File versionFile = stateLocation.append(versionFileName).toFile();
- if (versionFile.exists())
- return;
-
- /// delete old workbench state on first launch
- File workbenchFile = stateLocation.removeLastSegments(1)
- .append("org.eclipse.e4.workbench") //$NON-NLS-1$
- .append("workbench.xmi") //$NON-NLS-1$
- .toFile();
- if (workbenchFile.exists()) {
- workbenchFile.delete();
- }
-
- try {
- File parentDir = versionFile.getParentFile();
- if (parentDir != null)
- parentDir.mkdirs();
- OutputStream output = new FileOutputStream(versionFile);
- try {
- output.write("done".getBytes()); //$NON-NLS-1$
- } finally {
- output.close();
- }
- } catch (IOException e) {
- }
- }
-
- /**
- * Returns the shared instance.
- *
- * @return the shared instance.
- */
- public static CathyPlugin getDefault() {
- return plugin;
- }
-
- public static void log(Throwable e, String message) {
- if (message == null)
- message = ""; //$NON-NLS-1$
- getDefault().getLog()
- .log(new Status(IStatus.ERROR, PLUGIN_ID, message, e));
- }
-
- public static void log(String message) {
- if (message == null)
- message = ""; //$NON-NLS-1$
- getDefault().getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
- }
-
- private static Properties doLoadNLSProperties(Bundle bundle,
- String pathBase) {
- Properties properties = new Properties();
-
- String nl = Platform.getNL();
- String[] nlSegments = nl.split("_"); //$NON-NLS-1$
- URL entry;
- for (int i = 0; i <= nlSegments.length; i++) {
- StringBuilder nlsName = new StringBuilder(pathBase);
- for (int j = 0; j < i; j++) {
- nlsName.append('_');
- nlsName.append(nlSegments[j]);
- }
- nlsName.append(".properties"); //$NON-NLS-1$
- entry = findSingleEntry(bundle, nlsName.toString());
- if (entry != null) {
- try {
- InputStream stream = entry.openStream();
- try {
- properties.load(stream);
- } finally {
- stream.close();
- }
- } catch (IOException e) {
- // ignore
- }
- }
- }
-
- return properties;
- }
-
- private static URL findSingleEntry(Bundle bundle, String path) {
- int sepIndex = path.lastIndexOf('/');
- String dir, name;
- if (sepIndex < 0) {
- dir = "/"; //$NON-NLS-1$
- name = path;
- } else {
- dir = path.substring(0, sepIndex);
- name = path.substring(sepIndex + 1);
- }
- Enumeration entries = bundle.findEntries(dir, name, true);
- return entries != null && entries.hasMoreElements()
- ? entries.nextElement() : null;
- }
-
- public static T getAdapter(Object obj, Class adapter) {
- if (adapter.isInstance(obj))
- return adapter.cast(obj);
-
- if (obj instanceof IAdaptable) {
- T result = ((IAdaptable) obj).getAdapter(adapter);
- if (result != null)
- return result;
- }
-
- if (!(obj instanceof PlatformObject))
- return Platform.getAdapterManager().getAdapter(obj, adapter);
-
- return null;
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Authenticator;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.service.debug.DebugOptions;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+import org.xmind.core.Core;
+import org.xmind.core.internal.runtime.WorkspaceConfigurer;
+import org.xmind.core.internal.runtime.WorkspaceSession;
+import org.xmind.core.licensing.ILicenseAgent;
+import org.xmind.core.net.util.LinkUtils;
+import org.xmind.core.usagedata.IUsageDataSampler;
+import org.xmind.ui.internal.app.ApplicationConstants;
+import org.xmind.ui.internal.statushandlers.DefaultErrorReporter;
+import org.xmind.ui.internal.statushandlers.IErrorReporter;
+
+/*---- BAD BOY HANDSOME DEBUT, DO NOT TOUCH ME ----*/
+/*---- BEGIN IMPORT ----*/
+/*---- END IMPORT ----*/
+/*---- BAD BOY PERFECT CURTAIN CALL, DO NOT TOUCH ME ----*/
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class CathyPlugin extends AbstractUIPlugin {
+
+ public static final String PLUGIN_ID = "org.xmind.cathy"; //$NON-NLS-1$
+
+ /**
+ * Boolean value:
+ *
+ * true to enable auto saving service when there's opened
+ * workbooks
+ * false to disable this service
+ *
+ */
+ public static final String AUTO_SAVE_ENABLED = "autoSaveEnabled"; //$NON-NLS-1$
+
+ /**
+ * Integer value:
+ * the intervals (in minutes) between auto saving actions
+ */
+ public static final String AUTO_SAVE_INTERVALS = "autoSaveIntervals"; //$NON-NLS-1$
+
+ /**
+ * (Deprecated, use {@link #STARTUP_ACTION} instead) Boolean value:
+ *
+ * true to remember unclosed workbooks when XMind quits and
+ * open them next time XMind starts
+ * false to always open a bootstrap workbook when XMind
+ * opens
+ *
+ */
+ public static final String RESTORE_LAST_SESSION = "restoreLastSession"; //$NON-NLS-1$
+
+ /**
+ * Boolean value:
+ *
+ * true to check updates when XMind starts
+ * false to skip update checking when XMind starts
+ *
+ */
+ public static final String CHECK_UPDATES_ON_STARTUP = "checkUpdatesOnStartup"; //$NON-NLS-1$
+
+ /**
+ * Integer value (enumerated):
+ *
+ * 0({@link #STARTUP_ACTION_WIZARD}): opens a 'New
+ * Workbook' wizard dialog on startup
+ * 1({@link #STARTUP_ACTION_BLANK}): opens a blank map on
+ * startup
+ * 2({@link #STARTUP_ACTION_HOME}): opens the home map on
+ * startup
+ * 3({@link #STARTUP_ACTION_LAST}): opens last session on
+ * startup
+ *
+ */
+ public static final String STARTUP_ACTION = "startupAction2"; //$NON-NLS-1$
+
+ /**
+ * Integer preference store value for opening a 'New Workbook' wizard dialog
+ * on startup. (value=0)
+ *
+ * @see #STARTUP_ACTION
+ */
+ public static final int STARTUP_ACTION_WIZARD = 0;
+
+ /**
+ * Integer preference store value for opening a blank map on startup.
+ * (value=1)
+ *
+ * @see #STARTUP_ACTION
+ */
+ public static final int STARTUP_ACTION_BLANK = 1;
+
+ /**
+ * Integer preference store value for opening the home map on startup.
+ * (value=2)
+ *
+ * @see #STARTUP_ACTION
+ */
+ public static final int STARTUP_ACTION_HOME = 2;
+
+ /**
+ * Integer preference store value for opening last session on startup.
+ * (value=3)
+ *
+ * @see #STARTUP_ACTION
+ */
+ public static final int STARTUP_ACTION_LAST = 3;
+
+ /**
+ * Boolean value:
+ *
+ * true to hide system notifications (usually pushed to the
+ * user by pop-up windows)
+ * false to show system notifications
+ *
+ */
+ //public static final String HIDE_NOTIFICATIONS = "hideNotifications"; //$NON-NLS-1$
+
+ /**
+ * String constants identifying the extension part of a XMind command file
+ * name.
+ */
+ public static final String COMMAND_FILE_EXT = ".xmind-command"; //$NON-NLS-1$
+
+ /**
+ * Online help page.
+ */
+ public static final String ONLINE_HELP_URL = LinkUtils
+ .getLinkByLanguage(true, true, "/xmind/help"); //$NON-NLS-1$
+
+ /**
+ * Boolean value:
+ *
+ * true to upload usage data to XMind server
+ * false to skip uploading usage data
+ *
+ */
+ public static final String USAGE_DATA_UPLOADING_ENABLED = "usageDataUploadingEnabled"; //$NON-NLS-1$
+
+ /**
+ * One minute delay between two auto save operations.
+ */
+ public static final int AUTO_SAVE_EDITOR_STATE_INTERVALS = 60000;
+ public static final String OPTION_AUTO_SAVE_EDITOR_STATE_INTERVALS = "/debug/autoSaveEditorStateIntervals"; //$NON-NLS-1$
+
+ public static final String KEY_NOT_SHOW_UPLOAD_DATA_CHECK = "org.xmind.cathy.notShowUploadDataCheck"; //$NON-NLS-1$
+
+ // The shared instance.
+ private static CathyPlugin plugin;
+
+ private ServiceTracker debugTracker;
+
+ private WorkspaceSession xmindWorkspaceSession;
+
+ private IUsageDataSampler usageDataSampler;
+
+ private IErrorReporter errorReporter;
+
+ private LicenseAgentProxy licenseAgent;
+
+ private ILogger logger;
+
+ /**
+ * The constructor.
+ */
+ public CathyPlugin() {
+ plugin = this;
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+
+ /*---- BAD BOY HANDSOME DEBUT, DO NOT TOUCH ME ----*/
+ /*---- BEGIN INSERT ----*/
+ /*---- END INSERT ----*/
+ /*---- BAD BOY PERFECT CURTAIN CALL, DO NOT TOUCH ME ----*/
+
+ usageDataSampler = IUsageDataSampler.NULL;
+ errorReporter = DefaultErrorReporter.getInstance();
+ licenseAgent = new LicenseAgentProxy();
+
+ logger = new ILogger() {
+
+ public void logWarning(String message, Throwable error) {
+ getLog().log(toStatus(IStatus.ERROR, message, error));
+ }
+
+ public void logInfo(String message, Throwable error) {
+ getLog().log(toStatus(IStatus.WARNING, message, error));
+ }
+
+ public void logError(String message, Throwable error) {
+ getLog().log(toStatus(IStatus.INFO, message, error));
+ }
+
+ private IStatus toStatus(int severity, String message,
+ Throwable error) {
+ if (message == null) {
+ message = error.getMessage();
+ }
+ return new Status(severity, PLUGIN_ID, message, error);
+ }
+ };
+
+// activateNetworkSettings();
+
+ activateXMindCore();
+
+ /*
+ * We have to manually activate 'org.xmind.ui' plugin so that command
+ * handler classes contributed by that plugin can be loaded upon
+ * startup. This ensures that IElementUpdater implementations and
+ * enablement updates to behave correctly. For example, the class
+ * org.xmind.ui.internal.handlers.ClearWorkbookHistoryHandler should be
+ * loaded on startup so that its enablement state can be correctly
+ * updated, otherwise the command in menu will be shown as enabled even
+ * when it should not be.
+ */
+ activateMindMapUIContributions();
+
+ hackConstants();
+
+ upgradeWorkspace();
+
+ }
+
+// usageDataCollector.setUploadEnabled(getPreferenceStore()
+// .getBoolean(USAGE_DATA_UPLOADING_ENABLED));
+
+ private void hackConstants() {
+ ConstantsHacker.hack();
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ if (xmindWorkspaceSession != null) {
+ xmindWorkspaceSession.close();
+ xmindWorkspaceSession = null;
+ }
+
+ licenseAgent = null;
+
+ super.stop(context);
+ plugin = null;
+ }
+
+ public void activateNetworkSettings() {
+ Bundle networkPlugin = Platform.getBundle("org.eclipse.core.net"); //$NON-NLS-1$
+ if (networkPlugin != null) {
+ try {
+ networkPlugin
+ .loadClass("org.eclipse.core.internal.net.Activator"); //$NON-NLS-1$
+ /// cancel show AuthenticationDialog when return 401
+ Authenticator.setDefault(null);
+ } catch (ClassNotFoundException e) {
+ getLog().log(new Status(IStatus.WARNING, PLUGIN_ID,
+ "Failed to activate plugin 'org.eclipse.core.net'.", //$NON-NLS-1$
+ e));
+ }
+ } else {
+ getLog().log(new Status(IStatus.WARNING, PLUGIN_ID,
+ "Plugin 'org.eclipse.core.net' not found. Network proxies may not be correct.")); //$NON-NLS-1$
+ }
+ }
+
+ private void activateXMindCore() throws CoreException {
+ WorkspaceConfigurer.setDefaultWorkspaceLocation(
+ WorkspaceConfigurer.INSTANCE_LOCATION);
+
+ xmindWorkspaceSession = WorkspaceSession
+ .openSessionIn(new File(Core.getWorkspace().getTempDir()));
+ }
+
+ private void activateMindMapUIContributions() {
+ Bundle uiPlugin = Platform.getBundle("org.xmind.ui"); //$NON-NLS-1$
+ if (uiPlugin != null) {
+ try {
+ uiPlugin.loadClass("org.xmind.ui.internal.XmindUIPlugin"); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ getLog().log(new Status(IStatus.WARNING, PLUGIN_ID,
+ "Failed to activate plugin 'org.xmind.ui'.", //$NON-NLS-1$
+ e));
+ }
+ } else {
+ getLog().log(new Status(IStatus.WARNING, PLUGIN_ID,
+ "Plugin 'org.xmind.ui' is not found.")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @return the logger
+ */
+ public ILogger getLogger() {
+ return logger;
+ }
+
+ /**
+ * Returns the distribution identifier of this XMind product.
+ *
+ * @return the distribution identifier of this XMind product
+ * @deprecated Use system property
+ * "org.xmind.product.distribution.id"
+ */
+ public static String getDistributionId() {
+ String distribId = System
+ .getProperty(ApplicationConstants.PRODUCT_DISTRIBITION_ID);
+ if (distribId == null || "".equals(distribId)) { //$NON-NLS-1$
+ distribId = "cathy_portable"; //$NON-NLS-1$
+ }
+ return distribId;
+ }
+
+ public DebugOptions getDebugOptions() {
+ if (debugTracker == null) {
+ debugTracker = new ServiceTracker(
+ getBundle().getBundleContext(),
+ DebugOptions.class.getName(), null);
+ debugTracker.open();
+ }
+ return debugTracker.getService();
+ }
+
+ public boolean isDebugging(String option) {
+ DebugOptions debugOptions = getDebugOptions();
+ return debugOptions != null && debugOptions.isDebugEnabled()
+ && debugOptions.getBooleanOption(PLUGIN_ID + option, false);
+ }
+
+ public String getDebugValue(String option) {
+ DebugOptions debugOptions = getDebugOptions();
+ return debugOptions == null ? null
+ : debugOptions.getOption(PLUGIN_ID + option, null);
+ }
+
+ public int getDebugValue(String option, int defaultValue) {
+ DebugOptions debugOptions = getDebugOptions();
+ return debugOptions == null ? defaultValue
+ : debugOptions.getIntegerOption(PLUGIN_ID + option,
+ defaultValue);
+ }
+
+ public Properties loadNLSProperties(String pathBase) {
+ return doLoadNLSProperties(getBundle(), pathBase);
+ }
+
+ public IUsageDataSampler getUsageDataCollector() {
+ return usageDataSampler;
+ }
+
+ void setUsageDataCollector(IUsageDataSampler sampler) {
+ this.usageDataSampler = sampler == null ? IUsageDataSampler.NULL
+ : sampler;
+ }
+
+ /**
+ * @return
+ */
+ public IErrorReporter getErrorReporter() {
+ return errorReporter;
+ }
+
+ void setErrorReporter(IErrorReporter reporter) {
+ this.errorReporter = reporter == null
+ ? DefaultErrorReporter.getInstance() : reporter;
+ }
+
+ public ILicenseAgent getLicenseAgent() {
+ return licenseAgent;
+ }
+
+ void setLicenseAgent(ILicenseAgent agent) {
+ this.licenseAgent.setDelegate(agent);
+ }
+
+ private void upgradeWorkspace() {
+ IPath stateLocation;
+ try {
+ stateLocation = Platform.getStateLocation(getBundle());
+ } catch (Exception e) {
+ return;
+ }
+ String versionFileName = String.format("workspace-upgraded-v%s", //$NON-NLS-1$
+ getBundle().getVersion().toString());
+ File versionFile = stateLocation.append(versionFileName).toFile();
+ if (versionFile.exists())
+ return;
+
+ /// delete old workbench state on first launch
+ File workbenchFile = stateLocation.removeLastSegments(1)
+ .append("org.eclipse.e4.workbench") //$NON-NLS-1$
+ .append("workbench.xmi") //$NON-NLS-1$
+ .toFile();
+ if (workbenchFile.exists()) {
+ workbenchFile.delete();
+ }
+
+ try {
+ File parentDir = versionFile.getParentFile();
+ if (parentDir != null)
+ parentDir.mkdirs();
+ OutputStream output = new FileOutputStream(versionFile);
+ try {
+ output.write("done".getBytes()); //$NON-NLS-1$
+ } finally {
+ output.close();
+ }
+ } catch (IOException e) {
+ }
+ }
+
+ /**
+ * Returns the shared instance.
+ *
+ * @return the shared instance.
+ */
+ public static CathyPlugin getDefault() {
+ return plugin;
+ }
+
+ public static void log(Throwable e, String message) {
+ if (message == null)
+ message = ""; //$NON-NLS-1$
+ getDefault().getLog()
+ .log(new Status(IStatus.ERROR, PLUGIN_ID, message, e));
+ }
+
+ public static void log(String message) {
+ if (message == null)
+ message = ""; //$NON-NLS-1$
+ getDefault().getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
+ }
+
+ private static Properties doLoadNLSProperties(Bundle bundle,
+ String pathBase) {
+ Properties properties = new Properties();
+
+ String nl = Platform.getNL();
+ String[] nlSegments = nl.split("_"); //$NON-NLS-1$
+ URL entry;
+ for (int i = 0; i <= nlSegments.length; i++) {
+ StringBuilder nlsName = new StringBuilder(pathBase);
+ for (int j = 0; j < i; j++) {
+ nlsName.append('_');
+ nlsName.append(nlSegments[j]);
+ }
+ nlsName.append(".properties"); //$NON-NLS-1$
+ entry = findSingleEntry(bundle, nlsName.toString());
+ if (entry != null) {
+ try {
+ InputStream stream = entry.openStream();
+ try {
+ properties.load(stream);
+ } finally {
+ stream.close();
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ return properties;
+ }
+
+ private static URL findSingleEntry(Bundle bundle, String path) {
+ int sepIndex = path.lastIndexOf('/');
+ String dir, name;
+ if (sepIndex < 0) {
+ dir = "/"; //$NON-NLS-1$
+ name = path;
+ } else {
+ dir = path.substring(0, sepIndex);
+ name = path.substring(sepIndex + 1);
+ }
+ Enumeration entries = bundle.findEntries(dir, name, true);
+ return entries != null && entries.hasMoreElements()
+ ? entries.nextElement() : null;
+ }
+
+ public static T getAdapter(Object obj, Class adapter) {
+ if (adapter.isInstance(obj))
+ return adapter.cast(obj);
+
+ if (obj instanceof IAdaptable) {
+ T result = ((IAdaptable) obj).getAdapter(adapter);
+ if (result != null)
+ return result;
+ }
+
+ if (!(obj instanceof PlatformObject))
+ return Platform.getAdapterManager().getAdapter(obj, adapter);
+
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyPrefInitializer.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyPrefInitializer.java
index e84154b78..dcdb41b3f 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyPrefInitializer.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyPrefInitializer.java
@@ -1,55 +1,55 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
-import org.eclipse.core.runtime.preferences.DefaultScope;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.IScopeContext;
-
-public class CathyPrefInitializer extends AbstractPreferenceInitializer {
-
- public CathyPrefInitializer() {
- }
-
- public void initializeDefaultPreferences() {
- IScopeContext context = DefaultScope.INSTANCE;
- IEclipsePreferences node = context.getNode(
- CathyPlugin.getDefault().getBundle().getSymbolicName());
- node.putBoolean(CathyPlugin.AUTO_SAVE_ENABLED, false);
- node.putInt(CathyPlugin.AUTO_SAVE_INTERVALS, 5);
- node.putBoolean(CathyPlugin.RESTORE_LAST_SESSION, false);
- node.putBoolean(CathyPlugin.CHECK_UPDATES_ON_STARTUP, true);
- node.putInt(CathyPlugin.STARTUP_ACTION,
- CathyPlugin.STARTUP_ACTION_WIZARD);
-
-// ColorRegistry colorRegistry = PlatformUI.getWorkbench()
-// .getThemeManager().getCurrentTheme().getColorRegistry();
-// colorRegistry.put("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_END", //$NON-NLS-1$
-// new RGB(191, 205, 219));
-// colorRegistry.put(
-// "org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START", //$NON-NLS-1$
-// new RGB(191, 205, 219));
-// colorRegistry.put("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END", //$NON-NLS-1$
-// new RGB(153, 180, 209));
-// colorRegistry.put("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START", //$NON-NLS-1$
-// new RGB(153, 180, 209));
-// colorRegistry.put("org.eclipse.ui.workbench.INACTIVE_TAB_BG_END", //$NON-NLS-1$
-// new RGB(240, 240, 240));
-// colorRegistry.put("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START", //$NON-NLS-1$
-// new RGB(240, 240, 240));
-
- }
-
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+
+public class CathyPrefInitializer extends AbstractPreferenceInitializer {
+
+ public CathyPrefInitializer() {
+ }
+
+ public void initializeDefaultPreferences() {
+ IScopeContext context = DefaultScope.INSTANCE;
+ IEclipsePreferences node = context.getNode(
+ CathyPlugin.getDefault().getBundle().getSymbolicName());
+ node.putBoolean(CathyPlugin.AUTO_SAVE_ENABLED, false);
+ node.putInt(CathyPlugin.AUTO_SAVE_INTERVALS, 5);
+ node.putBoolean(CathyPlugin.RESTORE_LAST_SESSION, false);
+ node.putBoolean(CathyPlugin.CHECK_UPDATES_ON_STARTUP, true);
+ node.putInt(CathyPlugin.STARTUP_ACTION,
+ CathyPlugin.STARTUP_ACTION_WIZARD);
+
+// ColorRegistry colorRegistry = PlatformUI.getWorkbench()
+// .getThemeManager().getCurrentTheme().getColorRegistry();
+// colorRegistry.put("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_END", //$NON-NLS-1$
+// new RGB(191, 205, 219));
+// colorRegistry.put(
+// "org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START", //$NON-NLS-1$
+// new RGB(191, 205, 219));
+// colorRegistry.put("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END", //$NON-NLS-1$
+// new RGB(153, 180, 209));
+// colorRegistry.put("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START", //$NON-NLS-1$
+// new RGB(153, 180, 209));
+// colorRegistry.put("org.eclipse.ui.workbench.INACTIVE_TAB_BG_END", //$NON-NLS-1$
+// new RGB(240, 240, 240));
+// colorRegistry.put("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START", //$NON-NLS-1$
+// new RGB(240, 240, 240));
+
+ }
+
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathySplashHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathySplashHandler.java
index b15539afc..f5db31f42 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathySplashHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathySplashHandler.java
@@ -1,139 +1,139 @@
-package org.xmind.cathy.internal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.splash.AbstractSplashHandler;
-
-public class CathySplashHandler extends AbstractSplashHandler {
-
- private GC shellGC = null;
-
- private Image image = null;
-
- private Object resourceLock = new Object();
-
- public CathySplashHandler() {
- }
-
- public void init(final Shell splash) {
- super.init(splash);
- final ImageLoader loader = new ImageLoader();
- final ImageData[] imageDataArray = loadAnimationImageData(loader);
- if (imageDataArray == null)
- return;
-
- if (imageDataArray.length <= 1 || loader.repeatCount != 0) {
- CathyPlugin
- .log("Invalid GIF format of application loading indicator."); //$NON-NLS-1$
- return;
- }
-
- shellGC = new GC(splash);
-
- splash.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- releaseResources();
- }
- });
-
- final Display display = splash.getDisplay();
- Thread animateThread = new Thread(new Runnable() {
- public void run() {
- showLoadingAnimation(display, imageDataArray);
- }
- }, "LoadingIndicatorAnimation"); //$NON-NLS-1$
- animateThread.setDaemon(true);
- animateThread.start();
- }
-
- private ImageData[] loadAnimationImageData(ImageLoader loader) {
- URL url = FileLocator.find(Platform.getBundle(CathyPlugin.PLUGIN_ID),
- new Path("icons/progress.gif"), null); //$NON-NLS-1$
- if (url == null)
- return null;
- InputStream imageStream = null;
- try {
- imageStream = url.openStream();
- return loader.load(imageStream);
- } catch (IOException e) {
- CathyPlugin
- .log(e,
- "There was an error loading GIF from " + url.toExternalForm()); //$NON-NLS-1$
- return null;
- } finally {
- try {
- imageStream.close();
- } catch (IOException e) {
- }
- }
- }
-
- private void releaseResources() {
- synchronized (resourceLock) {
- // Dispose of the image
- if (image != null) {
- if (!image.isDisposed()) {
- image.dispose();
- }
- image = null;
- }
-
- // Dispose of the GC
- if (shellGC != null) {
- if (!shellGC.isDisposed()) {
- shellGC.dispose();
- }
- shellGC = null;
- }
- }
- }
-
- private void showLoadingAnimation(final Display display,
- final ImageData[] imageDataArray) {
- int imageDataIndex = -1;
- ImageData imageData;
-
- while (true) {
- imageDataIndex = (imageDataIndex + 1) % imageDataArray.length;
- imageData = imageDataArray[imageDataIndex];
-
- synchronized (resourceLock) {
- if (display.isDisposed() || shellGC == null
- || shellGC.isDisposed()) {
- return;
- }
-
- if (image != null && !image.isDisposed()) {
- image.dispose();
- image = null;
- }
- image = new Image(display, imageData);
- shellGC.drawImage(image, 233, 215);
- }
-
- try {
- int ms = imageData.delayTime * 10;
- if (ms < 20)
- ms += 30;
- if (ms < 30)
- ms += 10;
- Thread.sleep(ms);
- } catch (InterruptedException e) {
- }
- }
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageLoader;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.splash.AbstractSplashHandler;
+
+public class CathySplashHandler extends AbstractSplashHandler {
+
+ private GC shellGC = null;
+
+ private Image image = null;
+
+ private Object resourceLock = new Object();
+
+ public CathySplashHandler() {
+ }
+
+ public void init(final Shell splash) {
+ super.init(splash);
+ final ImageLoader loader = new ImageLoader();
+ final ImageData[] imageDataArray = loadAnimationImageData(loader);
+ if (imageDataArray == null)
+ return;
+
+ if (imageDataArray.length <= 1 || loader.repeatCount != 0) {
+ CathyPlugin
+ .log("Invalid GIF format of application loading indicator."); //$NON-NLS-1$
+ return;
+ }
+
+ shellGC = new GC(splash);
+
+ splash.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ releaseResources();
+ }
+ });
+
+ final Display display = splash.getDisplay();
+ Thread animateThread = new Thread(new Runnable() {
+ public void run() {
+ showLoadingAnimation(display, imageDataArray);
+ }
+ }, "LoadingIndicatorAnimation"); //$NON-NLS-1$
+ animateThread.setDaemon(true);
+ animateThread.start();
+ }
+
+ private ImageData[] loadAnimationImageData(ImageLoader loader) {
+ URL url = FileLocator.find(Platform.getBundle(CathyPlugin.PLUGIN_ID),
+ new Path("icons/progress.gif"), null); //$NON-NLS-1$
+ if (url == null)
+ return null;
+ InputStream imageStream = null;
+ try {
+ imageStream = url.openStream();
+ return loader.load(imageStream);
+ } catch (IOException e) {
+ CathyPlugin
+ .log(e,
+ "There was an error loading GIF from " + url.toExternalForm()); //$NON-NLS-1$
+ return null;
+ } finally {
+ try {
+ imageStream.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ private void releaseResources() {
+ synchronized (resourceLock) {
+ // Dispose of the image
+ if (image != null) {
+ if (!image.isDisposed()) {
+ image.dispose();
+ }
+ image = null;
+ }
+
+ // Dispose of the GC
+ if (shellGC != null) {
+ if (!shellGC.isDisposed()) {
+ shellGC.dispose();
+ }
+ shellGC = null;
+ }
+ }
+ }
+
+ private void showLoadingAnimation(final Display display,
+ final ImageData[] imageDataArray) {
+ int imageDataIndex = -1;
+ ImageData imageData;
+
+ while (true) {
+ imageDataIndex = (imageDataIndex + 1) % imageDataArray.length;
+ imageData = imageDataArray[imageDataIndex];
+
+ synchronized (resourceLock) {
+ if (display.isDisposed() || shellGC == null
+ || shellGC.isDisposed()) {
+ return;
+ }
+
+ if (image != null && !image.isDisposed()) {
+ image.dispose();
+ image = null;
+ }
+ image = new Image(display, imageData);
+ shellGC.drawImage(image, 233, 215);
+ }
+
+ try {
+ int ms = imageData.delayTime * 10;
+ if (ms < 20)
+ ms += 30;
+ if (ms < 30)
+ ms += 10;
+ Thread.sleep(ms);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyStatusHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyStatusHandler.java
index c91c20ac2..49521ef2a 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyStatusHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyStatusHandler.java
@@ -1,164 +1,173 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.statushandlers.AbstractStatusHandler;
-import org.eclipse.ui.statushandlers.IStatusAdapterConstants;
-import org.eclipse.ui.statushandlers.StatusAdapter;
-import org.eclipse.ui.statushandlers.StatusManager;
-import org.eclipse.ui.statushandlers.StatusManager.INotificationTypes;
-import org.xmind.ui.internal.ToolkitPlugin;
-import org.xmind.ui.internal.statushandlers.RuntimeErrorDialog;
-
-public class CathyStatusHandler extends AbstractStatusHandler {
-
- private static final String PROPERTY_PREFIX = "org.xmind.cathy.statusHandlers.adapters"; //$NON-NLS-1$
-
- private static final QualifiedName BLOCK = new QualifiedName(
- PROPERTY_PREFIX, "block"); //$NON-NLS-1$
-
- private List statusQueue = new ArrayList(4);
-
- private RuntimeErrorDialog currentDialog = null;
-
- public CathyStatusHandler() {
- }
-
- public boolean supportsNotification(int type) {
- if (type == INotificationTypes.HANDLED) {
- return true;
- }
- return super.supportsNotification(type);
- }
-
- public void handle(final StatusAdapter statusAdapter, final int style) {
- if (((style & StatusManager.SHOW) == StatusManager.SHOW)
- || ((style & StatusManager.BLOCK) == StatusManager.BLOCK)) {
-
- final boolean block = ((style
- & StatusManager.BLOCK) == StatusManager.BLOCK);
-
- addProperties(statusAdapter, block);
-
- if (Display.getCurrent() != null) {
- showStatusAdapter(statusAdapter);
- } else {
- if (block) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- showStatusAdapter(statusAdapter);
- }
- });
-
- } else {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- showStatusAdapter(statusAdapter);
- }
- });
- }
- }
- }
-
- if ((style & StatusManager.LOG) == StatusManager.LOG) {
- StatusManager.getManager()
- .addLoggedStatus(statusAdapter.getStatus());
- ToolkitPlugin.getDefault().getLog().log(statusAdapter.getStatus());
- }
- }
-
- private void addProperties(final StatusAdapter statusAdapter,
- boolean block) {
- // Add timestamp:
- if (statusAdapter.getProperty(
- IStatusAdapterConstants.TIMESTAMP_PROPERTY) == null) {
- statusAdapter.setProperty(
- IStatusAdapterConstants.TIMESTAMP_PROPERTY,
- Long.valueOf(System.currentTimeMillis()));
- }
-
- statusAdapter.setProperty(BLOCK, Boolean.valueOf(block));
- }
-
- /**
- * Shows the status adapter.
- *
- * @param statusAdapter
- * the status adapter to show
- * @param block
- * true to request a modal dialog and suspend the
- * calling thread till the dialog is closed, false
- * otherwise.
- */
- private void showStatusAdapter(final StatusAdapter statusAdapter) {
- if (!PlatformUI.isWorkbenchRunning()) {
- // we are shutting down, so just log
- ToolkitPlugin.getDefault().getLog().log(statusAdapter.getStatus());
- return;
- }
-
- statusQueue.add(statusAdapter);
-
- if (currentDialog == null) {
- currentDialog = showErrorDialogFor(statusAdapter);
- }
-
- if (((Boolean) statusAdapter.getProperty(BLOCK)).booleanValue()) {
- Display display = Display.getCurrent();
- if (display != null && !display.isDisposed()) {
- while (statusQueue.contains(statusAdapter)
- && !display.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- }
- }
- }
-
- private RuntimeErrorDialog showErrorDialogFor(
- final StatusAdapter statusAdapter) {
- StatusManager.getManager().fireNotification(INotificationTypes.HANDLED,
- new StatusAdapter[] { statusAdapter });
-
- int style = RuntimeErrorDialog.NONE;
- if (((Boolean) statusAdapter.getProperty(BLOCK)).booleanValue()) {
- style |= RuntimeErrorDialog.BLOCKED;
- }
- RuntimeErrorDialog dialog = new RuntimeErrorDialog(style, statusAdapter,
- null, CathyPlugin.getDefault().getErrorReporter());
- dialog.create();
- dialog.getShell().addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- statusQueue.remove(statusAdapter);
- if (statusQueue.size() > 0) {
- currentDialog = showErrorDialogFor(statusQueue.get(0));
- } else {
- currentDialog = null;
- }
- }
- });
- dialog.open();
- return dialog;
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.statushandlers.AbstractStatusHandler;
+import org.eclipse.ui.statushandlers.IStatusAdapterConstants;
+import org.eclipse.ui.statushandlers.StatusAdapter;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.eclipse.ui.statushandlers.StatusManager.INotificationTypes;
+import org.xmind.core.internal.UserDataConstants;
+import org.xmind.ui.internal.ToolkitPlugin;
+import org.xmind.ui.internal.statushandlers.RuntimeErrorDialog;
+
+public class CathyStatusHandler extends AbstractStatusHandler {
+
+ private static final String PROPERTY_PREFIX = "org.xmind.cathy.statusHandlers.adapters"; //$NON-NLS-1$
+
+ private static final QualifiedName BLOCK = new QualifiedName(
+ PROPERTY_PREFIX, "block"); //$NON-NLS-1$
+
+ private List statusQueue = new ArrayList(4);
+
+ private RuntimeErrorDialog currentDialog = null;
+
+ public CathyStatusHandler() {
+ }
+
+ public boolean supportsNotification(int type) {
+ if (type == INotificationTypes.HANDLED) {
+ return true;
+ }
+ return super.supportsNotification(type);
+ }
+
+ public void handle(final StatusAdapter statusAdapter, final int style) {
+ CathyPlugin.getDefault().getUsageDataCollector().trackEvent(
+ UserDataConstants.CATEGORY_ERROR,
+ UserDataConstants.ENCOUNTER_ERROR);
+
+ if (((style & StatusManager.SHOW) == StatusManager.SHOW)
+ || ((style & StatusManager.BLOCK) == StatusManager.BLOCK)) {
+
+ final boolean block = ((style
+ & StatusManager.BLOCK) == StatusManager.BLOCK);
+
+ addProperties(statusAdapter, block);
+
+ if (Display.getCurrent() != null) {
+ showStatusAdapter(statusAdapter);
+ } else {
+ if (block) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ showStatusAdapter(statusAdapter);
+ }
+ });
+
+ } else {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ showStatusAdapter(statusAdapter);
+ }
+ });
+ }
+ }
+ }
+
+ if ((style & StatusManager.LOG) == StatusManager.LOG) {
+ StatusManager.getManager()
+ .addLoggedStatus(statusAdapter.getStatus());
+ ToolkitPlugin.getDefault().getLog().log(statusAdapter.getStatus());
+ }
+ }
+
+ private void addProperties(final StatusAdapter statusAdapter,
+ boolean block) {
+ // Add timestamp:
+ if (statusAdapter.getProperty(
+ IStatusAdapterConstants.TIMESTAMP_PROPERTY) == null) {
+ statusAdapter.setProperty(
+ IStatusAdapterConstants.TIMESTAMP_PROPERTY,
+ Long.valueOf(System.currentTimeMillis()));
+ }
+
+ statusAdapter.setProperty(BLOCK, Boolean.valueOf(block));
+ }
+
+ /**
+ * Shows the status adapter.
+ *
+ * @param statusAdapter
+ * the status adapter to show
+ * @param block
+ * true to request a modal dialog and suspend the
+ * calling thread till the dialog is closed, false
+ * otherwise.
+ */
+ private void showStatusAdapter(final StatusAdapter statusAdapter) {
+ if (!PlatformUI.isWorkbenchRunning()) {
+ // we are shutting down, so just log
+ ToolkitPlugin.getDefault().getLog().log(statusAdapter.getStatus());
+ return;
+ }
+
+ statusQueue.add(statusAdapter);
+
+ if (currentDialog == null) {
+ currentDialog = showErrorDialogFor(statusAdapter);
+ }
+
+ if (((Boolean) statusAdapter.getProperty(BLOCK)).booleanValue()) {
+ Display display = Display.getCurrent();
+ if (display != null && !display.isDisposed()) {
+ while (statusQueue.contains(statusAdapter)
+ && !display.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ }
+ }
+ }
+
+ private RuntimeErrorDialog showErrorDialogFor(
+ final StatusAdapter statusAdapter) {
+ StatusManager.getManager().fireNotification(INotificationTypes.HANDLED,
+ new StatusAdapter[] { statusAdapter });
+
+ int style = RuntimeErrorDialog.NONE;
+ if (((Boolean) statusAdapter.getProperty(BLOCK)).booleanValue()) {
+ style |= RuntimeErrorDialog.BLOCKED;
+ }
+ RuntimeErrorDialog dialog = new RuntimeErrorDialog(style, statusAdapter,
+ null, CathyPlugin.getDefault().getErrorReporter());
+ dialog.create();
+ dialog.getShell().addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ statusQueue.remove(statusAdapter);
+ if (statusQueue.size() > 0) {
+ currentDialog = showErrorDialogFor(statusQueue.get(0));
+ } else {
+ currentDialog = null;
+ }
+ }
+ });
+ dialog.open();
+ CathyPlugin.getDefault().getUsageDataCollector().trackEvent(
+ UserDataConstants.CATEGORY_ERROR,
+ UserDataConstants.SHOW_ERROR_DIALOG);
+
+ return dialog;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchActionBuilder.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchActionBuilder.java
index 8729cc0eb..536e42c89 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchActionBuilder.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchActionBuilder.java
@@ -1,178 +1,178 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.action.GroupMarker;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.application.ActionBarAdvisor;
-import org.eclipse.ui.application.IActionBarConfigurer;
-
-/**
- * Make and contribute basic actions to menus and toolbars.
- *
- *
- * Main Menu Bar:
- *
- * File (file)
- *
- * (fileStart)
- * (new.ext)
- * ---- (open.group)
- * (open.ext)
- * ---- (close.group)
- * (close.ext)
- * ---- (save.group)
- * ---- (save.ext)
- * ---- (print.group)
- * (print.ext)
- * ---- (import.group)
- * (import.ext)
- * ---- (share.group)
- * ---- (additions)
- * (fileEnd)
- *
- *
- * Edit (edit)
- *
- * (editStart)
- * (undo.ext)
- * ---- (cut.group)
- * (cut.ext)
- * ---- (delete.group)
- * ---- (select.group)
- * ---- (additions)
- * ---- (find.group)
- * ---- (find.ext)
- * (editEnd)
- *
- *
- * (additions)
- * Help (help)
- *
- * ---- (group.intro)
- * (group.intro.ext)
- * ---- (group.main)
- * (group.assist)
- * ---- (helpStart)
- * (group.main.ext)
- * ---- (group.tutorials)
- * ---- (group.tools)
- * ---- (group.updates)
- * ---- (group.xmindnet)
- * (helpEnd)
- * ---- (additions)
- * ---- (group.about)
- * (about.ext)
- *
- *
- *
- *
- *
- *
- * Main Tool Bar and other trim bars are defined in 'Application.e4xmi'.
- *
- *
- *
- * NOTE: Up to now (4.5.0), we can't use Application.e4xmi to establish our main
- * menu model because workbench will delete main menu models from each window
- * model when persisting the workbench model. So we have to keep this class just
- * to fill in the main menu with our group markers each time the workbench
- * starts up.
- *
- *
- * @author Frank Shaka
- */
-public class CathyWorkbenchActionBuilder extends ActionBarAdvisor {
-
- public CathyWorkbenchActionBuilder(IActionBarConfigurer configurer) {
- super(configurer);
- }
-
- /**
- * Fill basic actions in the main menu.
- */
- protected void fillMenuBar(IMenuManager menuBar) {
- menuBar.add(createFileMenu());
- menuBar.add(createEditMenu());
- menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
- menuBar.add(createHelpMenu());
- }
-
- private MenuManager createFileMenu() {
- MenuManager menu = new MenuManager(WorkbenchMessages.File_menu_text,
- IWorkbenchActionConstants.M_FILE);
-
- menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
- menu.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
- menu.add(new Separator("open.group")); //$NON-NLS-1$
- menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
- menu.add(new Separator("close.group")); //$NON-NLS-1$
- menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));
- menu.add(new Separator(IWorkbenchActionConstants.SAVE_GROUP));
- menu.add(new Separator(IWorkbenchActionConstants.SAVE_EXT));
- menu.add(new Separator("print.group")); //$NON-NLS-1$
- menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
- menu.add(new Separator("import.group")); //$NON-NLS-1$
- menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));
- menu.add(new Separator("share.group")); //$NON-NLS-1$
- menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
-
- return menu;
- }
-
- private MenuManager createEditMenu() {
- MenuManager menu = new MenuManager(WorkbenchMessages.Edit_menu_text,
- IWorkbenchActionConstants.M_EDIT);
-
- menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
- menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));
- menu.add(new Separator("cut.group")); //$NON-NLS-1$
- menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));
- menu.add(new Separator("delete.group")); //$NON-NLS-1$
- menu.add(new Separator("select.group")); //$NON-NLS-1$
- menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- menu.add(new Separator("find.group")); //$NON-NLS-1$
- menu.add(new Separator(IWorkbenchActionConstants.FIND_EXT));
- menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
-
- return menu;
- }
-
- private MenuManager createHelpMenu() {
- MenuManager menu = new MenuManager(WorkbenchMessages.Help_menu_text,
- IWorkbenchActionConstants.M_HELP);
-
- menu.add(new Separator("group.intro")); //$NON-NLS-1$
- menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
- menu.add(new Separator("group.main")); //$NON-NLS-1$
- menu.add(new GroupMarker("group.assist")); //$NON-NLS-1$
- menu.add(new Separator(IWorkbenchActionConstants.HELP_START));
- menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
- menu.add(new Separator("group.tutorials")); //$NON-NLS-1$
- menu.add(new Separator("group.tools")); //$NON-NLS-1$
- menu.add(new Separator("group.updates")); //$NON-NLS-1$
- menu.add(new Separator("group.xmindnet")); //$NON-NLS-1$
- menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
- menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- menu.add(new Separator("group.about")); //$NON-NLS-1$
- menu.add(new GroupMarker("about.ext")); //$NON-NLS-1$
-
- return menu;
- }
-
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.application.ActionBarAdvisor;
+import org.eclipse.ui.application.IActionBarConfigurer;
+
+/**
+ * Make and contribute basic actions to menus and toolbars.
+ *
+ *
+ * Main Menu Bar:
+ *
+ * File (file)
+ *
+ * (fileStart)
+ * (new.ext)
+ * ---- (open.group)
+ * (open.ext)
+ * ---- (close.group)
+ * (close.ext)
+ * ---- (save.group)
+ * ---- (save.ext)
+ * ---- (print.group)
+ * (print.ext)
+ * ---- (import.group)
+ * (import.ext)
+ * ---- (share.group)
+ * ---- (additions)
+ * (fileEnd)
+ *
+ *
+ * Edit (edit)
+ *
+ * (editStart)
+ * (undo.ext)
+ * ---- (cut.group)
+ * (cut.ext)
+ * ---- (delete.group)
+ * ---- (select.group)
+ * ---- (additions)
+ * ---- (find.group)
+ * ---- (find.ext)
+ * (editEnd)
+ *
+ *
+ * (additions)
+ * Help (help)
+ *
+ * ---- (group.intro)
+ * (group.intro.ext)
+ * ---- (group.main)
+ * (group.assist)
+ * ---- (helpStart)
+ * (group.main.ext)
+ * ---- (group.tutorials)
+ * ---- (group.tools)
+ * ---- (group.updates)
+ * ---- (group.xmindnet)
+ * (helpEnd)
+ * ---- (additions)
+ * ---- (group.about)
+ * (about.ext)
+ *
+ *
+ *
+ *
+ *
+ *
+ * Main Tool Bar and other trim bars are defined in 'Application.e4xmi'.
+ *
+ *
+ *
+ * NOTE: Up to now (4.5.0), we can't use Application.e4xmi to establish our main
+ * menu model because workbench will delete main menu models from each window
+ * model when persisting the workbench model. So we have to keep this class just
+ * to fill in the main menu with our group markers each time the workbench
+ * starts up.
+ *
+ *
+ * @author Frank Shaka
+ */
+public class CathyWorkbenchActionBuilder extends ActionBarAdvisor {
+
+ public CathyWorkbenchActionBuilder(IActionBarConfigurer configurer) {
+ super(configurer);
+ }
+
+ /**
+ * Fill basic actions in the main menu.
+ */
+ protected void fillMenuBar(IMenuManager menuBar) {
+ menuBar.add(createFileMenu());
+ menuBar.add(createEditMenu());
+ menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ menuBar.add(createHelpMenu());
+ }
+
+ private MenuManager createFileMenu() {
+ MenuManager menu = new MenuManager(WorkbenchMessages.File_menu_text,
+ IWorkbenchActionConstants.M_FILE);
+
+ menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
+ menu.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
+ menu.add(new Separator("open.group")); //$NON-NLS-1$
+ menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
+ menu.add(new Separator("close.group")); //$NON-NLS-1$
+ menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));
+ menu.add(new Separator(IWorkbenchActionConstants.SAVE_GROUP));
+ menu.add(new Separator(IWorkbenchActionConstants.SAVE_EXT));
+ menu.add(new Separator("print.group")); //$NON-NLS-1$
+ menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
+ menu.add(new Separator("import.group")); //$NON-NLS-1$
+ menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));
+ menu.add(new Separator("share.group")); //$NON-NLS-1$
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
+
+ return menu;
+ }
+
+ private MenuManager createEditMenu() {
+ MenuManager menu = new MenuManager(WorkbenchMessages.Edit_menu_text,
+ IWorkbenchActionConstants.M_EDIT);
+
+ menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
+ menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));
+ menu.add(new Separator("cut.group")); //$NON-NLS-1$
+ menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));
+ menu.add(new Separator("delete.group")); //$NON-NLS-1$
+ menu.add(new Separator("select.group")); //$NON-NLS-1$
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ menu.add(new Separator("find.group")); //$NON-NLS-1$
+ menu.add(new Separator(IWorkbenchActionConstants.FIND_EXT));
+ menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
+
+ return menu;
+ }
+
+ private MenuManager createHelpMenu() {
+ MenuManager menu = new MenuManager(WorkbenchMessages.Help_menu_text,
+ IWorkbenchActionConstants.M_HELP);
+
+ menu.add(new Separator("group.intro")); //$NON-NLS-1$
+ menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
+ menu.add(new Separator("group.main")); //$NON-NLS-1$
+ menu.add(new GroupMarker("group.assist")); //$NON-NLS-1$
+ menu.add(new Separator(IWorkbenchActionConstants.HELP_START));
+ menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
+ menu.add(new Separator("group.tutorials")); //$NON-NLS-1$
+ menu.add(new Separator("group.tools")); //$NON-NLS-1$
+ menu.add(new Separator("group.updates")); //$NON-NLS-1$
+ menu.add(new Separator("group.xmindnet")); //$NON-NLS-1$
+ menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ menu.add(new Separator("group.about")); //$NON-NLS-1$
+ menu.add(new GroupMarker("about.ext")); //$NON-NLS-1$
+
+ return menu;
+ }
+
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchAdvisor.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchAdvisor.java
index 6c7588fbd..78af55826 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchAdvisor.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchAdvisor.java
@@ -1,417 +1,424 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorReference;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IPersistable;
-import org.eclipse.ui.IPersistableElement;
-import org.eclipse.ui.ISaveablePart2;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPreferenceConstants;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.XMLMemento;
-import org.eclipse.ui.application.IWorkbenchConfigurer;
-import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
-import org.eclipse.ui.application.WorkbenchAdvisor;
-import org.eclipse.ui.application.WorkbenchWindowAdvisor;
-import org.eclipse.ui.internal.IWorkbenchConstants;
-import org.eclipse.ui.internal.UIPlugin;
-import org.eclipse.ui.internal.WorkbenchPlugin;
-import org.xmind.cathy.internal.jobs.OpenFilesJob;
-import org.xmind.core.internal.InternalCore;
-import org.xmind.core.licensing.ILicenseAgent;
-import org.xmind.core.licensing.ILicenseChangedListener;
-import org.xmind.core.licensing.ILicenseKeyHeader;
-import org.xmind.gef.ui.editor.IEditingContext;
-import org.xmind.ui.internal.PasswordProvider;
-import org.xmind.ui.internal.dialogs.DialogMessages;
-import org.xmind.ui.internal.editor.AbstractWorkbookRef;
-import org.xmind.ui.internal.editor.DefaultMindMapPreviewGenerator;
-import org.xmind.ui.internal.editor.IMindMapPreviewGenerator;
-import org.xmind.ui.internal.editor.IPasswordProvider;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class CathyWorkbenchAdvisor extends WorkbenchAdvisor
- implements ILicenseChangedListener {
-
- public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
- IWorkbenchWindowConfigurer configurer) {
- return new CathyWorkbenchWindowAdvisor(configurer);
- }
-
- public String getInitialWindowPerspectiveId() {
- return MindMapUI.PERSPECTIVE_ID;
- }
-
- @Override
- public String getMainPreferencePageId() {
- return "org.xmind.ui.prefPage.General"; //$NON-NLS-1$
- }
-
- public void initialize(IWorkbenchConfigurer configurer) {
- super.initialize(configurer);
- configurer.setSaveAndRestore(true);
- configurer.setExitOnLastWindowClose(true);
- }
-
- @Override
- public void preStartup() {
- super.preStartup();
-
- CathyPlugin.getDefault().getLicenseAgent()
- .addLicenseChangedListener(this);
- licenseChanged(CathyPlugin.getDefault().getLicenseAgent());
-
- /**
- * This hack requires workbench to exist. See
- * {@link org.eclipse.ui.internal.PlatformUIPreferenceListener}.
- */
- UIPlugin.getDefault().getPreferenceStore().setValue(
- IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
- true);
- }
-
- @Override
- public void postStartup() {
- super.postStartup();
-
- IWorkbench workbench = getWorkbenchConfigurer().getWorkbench();
-
- AbstractWorkbookRef.setDefaultEditingContext(
- createDefaultEditingContext(workbench));
-
- new StartUpProcess(workbench).startUp();
- }
-
- private IEditingContext createDefaultEditingContext(
- final IWorkbench workbench) {
- final IMindMapPreviewGenerator previewGenerator = new DefaultMindMapPreviewGenerator(
- workbench.getDisplay());
-
- final IPasswordProvider passwordProvider = new PasswordProvider();
-
- return new IEditingContext() {
- public T getAdapter(Class adapter) {
-
- if (IMindMapPreviewGenerator.class.equals(adapter))
- return adapter.cast(previewGenerator);
-
- if (IPasswordProvider.class.equals(adapter))
- return adapter.cast(passwordProvider);
-
- T result;
-
- result = workbench.getService(adapter);
- if (result != null)
- return result;
-
- result = workbench.getAdapter(adapter);
- if (result != null)
- return result;
-
- return result;
- }
- };
- }
-
- @Override
- public void postShutdown() {
- CathyPlugin.getDefault().getLicenseAgent()
- .removeLicenseChangedListener(this);
-
- AbstractWorkbookRef.setDefaultEditingContext(null);
- super.postShutdown();
- }
-
- public boolean preShutdown() {
- boolean readyToShutdown = super.preShutdown();
- if (readyToShutdown) {
- readyToShutdown = saveAllEditorsOnClose();
- }
- return readyToShutdown;
- }
-
- private boolean saveAllEditorsOnClose() {
- IWorkbench workbench = getWorkbenchConfigurer().getWorkbench();
- final ArrayList unClosedEditorRefs = new ArrayList();
- IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
- for (IWorkbenchWindow window : windows) {
- IWorkbenchPage page = window.getActivePage();
- for (IEditorReference editorRef : page.getEditorReferences()) {
- unClosedEditorRefs.add(editorRef);
- final IEditorPart editor = editorRef.getEditor(false);
- if (editor != null && editor.isDirty()) {
- int answer = promptToSaveOnClose(window, page, editor);
- if (answer == ISaveablePart2.CANCEL)
- return false;
- if (answer == ISaveablePart2.YES) {
- if (!doSaveEditor(window, editor)) {
- return false;
- }
- }
- }
- }
- }
- SafeRunner.run(new SafeRunnable() {
- public void run() {
- XMLMemento mem = recordEditorsState(unClosedEditorRefs);
- saveMementoToFile(mem);
- }
- });
- return closeAllEditors();
- }
-
- private XMLMemento recordEditorsState(
- ArrayList editorRefs) {
- XMLMemento memento = XMLMemento.createWriteRoot("xmind"); //$NON-NLS-1$
- saveEditorsState(memento, editorRefs);
- return memento;
- }
-
- private void saveEditorsState(IMemento memento,
- ArrayList editorRefs) {
- IWorkbenchPage activePage = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- IEditorPart activeEditor = activePage.getActiveEditor();
-
- IMemento childrenMemento = memento
- .createChild(IWorkbenchConstants.TAG_EDITORS);
- if (!editorRefs.isEmpty())
- for (IEditorReference ref : editorRefs) {
- IEditorPart editor = ref.getEditor(false);
- IMemento editorMemento = childrenMemento
- .createChild(IWorkbenchConstants.TAG_EDITOR);
- editorMemento.putBoolean(IWorkbenchConstants.TAG_ACTIVE_PART,
- editor == activeEditor);
- IPersistable editorPersistable = CathyPlugin.getAdapter(editor,
- IPersistable.class);
- if (editorPersistable != null) {
- editorPersistable.saveState(editorMemento);
- }
-
- IEditorInput input = editor.getEditorInput();
- IMemento inputMemento = editorMemento
- .createChild(IWorkbenchConstants.TAG_INPUT);
- IPersistableElement inputPersistable = CathyPlugin
- .getAdapter(input, IPersistableElement.class);
- if (inputPersistable != null) {
- inputMemento.putString(IWorkbenchConstants.TAG_FACTORY_ID,
- inputPersistable.getFactoryId());
- inputPersistable.saveState(inputMemento);
- }
- }
- }
-
- private boolean saveMementoToFile(XMLMemento memento) {
- // Save it to a file.
- File stateFile = getEditorsStateFile();
- if (stateFile == null) {
- return false;
- }
- try {
- FileOutputStream stream = new FileOutputStream(stateFile);
- OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8"); //$NON-NLS-1$
- memento.save(writer);
- writer.close();
- } catch (IOException e) {
- stateFile.delete();
- return false;
- }
-
- // Success !
- return true;
- }
-
- private File getEditorsStateFile() {
- IPath path = WorkbenchPlugin.getDefault().getDataLocation();
- if (path == null) {
- return null;
- }
- path = path.append("XMind_Editors.xml"); //$NON-NLS-1$
- return path.toFile();
- }
-
- private int promptToSaveOnClose(IWorkbenchWindow window,
- IWorkbenchPage page, IEditorPart editor) {
- if (editor instanceof ISaveablePart2) {
- int answer = ((ISaveablePart2) editor).promptToSaveOnClose();
- if (answer != ISaveablePart2.DEFAULT)
- return answer;
- }
- page.activate(editor);
- MessageDialog dialog = new MessageDialog(window.getShell(),
- DialogMessages.Save_title, null,
- NLS.bind(WorkbenchMessages.PromptSaveEditorOnClosing_message,
- editor.getTitle()),
- MessageDialog.QUESTION,
- new String[] { IDialogConstants.YES_LABEL,
- IDialogConstants.NO_LABEL,
- IDialogConstants.CANCEL_LABEL },
- 0);
- int answerIndex = dialog.open();
- switch (answerIndex) {
- case 0:
- return ISaveablePart2.YES;
- case 1:
- return ISaveablePart2.NO;
- default:
- return ISaveablePart2.CANCEL;
- }
- }
-
- private boolean doSaveEditor(final IWorkbenchWindow window,
- final IEditorPart editor) {
- final boolean[] saved = new boolean[1];
- saved[0] = false;
- window.getShell().getDisplay().syncExec(new Runnable() {
- public void run() {
- SafeRunner.run(new SafeRunnable() {
- public void run() throws Exception {
- final IProgressMonitor monitor = new NullProgressMonitor();
- if (InternalCore.DEBUG_WORKBOOK_SAVE)
- CathyPlugin.log(
- "CathyWorkbenchAdvisor: About to save workbook on workbench close: " //$NON-NLS-1$
- + editor.getEditorInput()
- .toString());
- editor.doSave(monitor);
- if (!monitor.isCanceled()) {
- saved[0] = true;
- } else {
- if (InternalCore.DEBUG_WORKBOOK_SAVE)
- CathyPlugin.log(
- "CathyWorkbenchAdvisor: Finished saving workbook on workbench close: " //$NON-NLS-1$
- + editor.getEditorInput()
- .toString());
- }
- }
- });
- }
- });
- return saved[0];
- }
-
- private boolean closeAllEditors() {
- boolean closed = false;
- IWorkbench workbench = getWorkbenchConfigurer().getWorkbench();
- for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
- closed |= window.getActivePage().closeAllEditors(false);
- }
- return closed;
- }
-
- public void licenseChanged(ILicenseAgent agent) {
- int type = agent.getLicenseType();
- ILicenseKeyHeader header = agent.getLicenseKeyHeader();
- String brandingVersion = System
- .getProperty("org.xmind.product.brandingVersion", ""); //$NON-NLS-1$ //$NON-NLS-2$
- String licenseType;
- if ((type & ILicenseAgent.PRO_LICENSE_KEY) != 0) {
- licenseType = NLS.bind(WorkbenchMessages.About_ProTitle,
- brandingVersion);
- } else if ((type & ILicenseAgent.PLUS_LICENSE_KEY) != 0) {
- licenseType = NLS.bind(WorkbenchMessages.About_PlusTitle,
- brandingVersion);
- } else if ((type & ILicenseAgent.PRO_SUBSCRIPTION) != 0) {
- licenseType = WorkbenchMessages.About_ProSubscriptionTitle;
- } else {
- licenseType = null;
- }
-
- if (header != null && ((type & ILicenseAgent.PLUS_LICENSE_KEY) != 0
- || (type & ILicenseAgent.PRO_LICENSE_KEY) != 0)) {
- String licenseeType = header.getLicenseeType();
- if (ILicenseKeyHeader.LICENSEE_FAMILY.equals(licenseeType)) {
- licenseType = NLS.bind("{0} (Family License)", licenseType); //$NON-NLS-1$
- } else if (ILicenseKeyHeader.LICENSEE_EDU.equals(licenseeType)) {
- licenseType = NLS.bind("{0} (Academia License)", licenseType); //$NON-NLS-1$
- } else if (ILicenseKeyHeader.LICENSEE_GOV.equals(licenseeType)) {
- licenseType = NLS.bind("{0} (Gov/NPO License)", licenseType); //$NON-NLS-1$
- } else if (ILicenseKeyHeader.LICENSEE_TEAM_5U.equals(licenseeType)
- || ILicenseKeyHeader.LICENSEE_TEAM_10U.equals(licenseeType)
- || ILicenseKeyHeader.LICENSEE_TEAM_20U
- .equals(licenseeType)) {
- licenseType = NLS.bind("{0} (Team License)", licenseType); //$NON-NLS-1$
- } else if (ILicenseKeyHeader.LICENSEE_VLE.equals(licenseeType)) {
- licenseType = NLS.bind("{0} (Volume License)", licenseType); //$NON-NLS-1$
- }
- }
- if (licenseType == null) {
- licenseType = WorkbenchMessages.About_LicenseType_Unactivated;
- } else {
- licenseType = NLS.bind(WorkbenchMessages.About_LicenseTypePattern,
- licenseType);
- }
- System.setProperty("org.xmind.product.license.type", //$NON-NLS-1$
- licenseType);
-
- String name = agent.getLicenseeName();
- if (name != null && !"".equals(name)) { //$NON-NLS-1$
- name = NLS.bind(WorkbenchMessages.About_LicensedTo, name);
- } else {
- name = ""; //$NON-NLS-1$
- }
- System.setProperty("org.xmind.product.license.licensee", name); //$NON-NLS-1$
- }
-
- @Override
- public void eventLoopIdle(Display display) {
- String[] paths = OpenDocumentQueue.getInstance().drain();
- if (paths.length > 0) {
- CathyPlugin.log("Ready to open files: " + Arrays.toString(paths)); //$NON-NLS-1$
- openFiles(paths);
- IWorkbenchWindow window = getWorkbenchConfigurer().getWorkbench()
- .getActiveWorkbenchWindow();
- if (window != null) {
- Shell shell = window.getShell();
- if (shell != null && !shell.isDisposed()) {
- shell.forceActive();
- }
- }
- } else {
- super.eventLoopIdle(display);
- }
- }
-
- private void openFiles(String[] paths) {
- OpenFilesJob job = new OpenFilesJob(
- getWorkbenchConfigurer().getWorkbench(),
- WorkbenchMessages.CheckOpenFilesJob_CheckFiles_name,
- Arrays.asList(paths));
- job.setRule(Log.get(Log.OPENING));
- job.schedule();
- }
-
-}
\ No newline at end of file
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistable;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.ISaveablePart2;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPreferenceConstants;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.ui.application.IWorkbenchConfigurer;
+import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
+import org.eclipse.ui.application.WorkbenchAdvisor;
+import org.eclipse.ui.application.WorkbenchWindowAdvisor;
+import org.eclipse.ui.internal.IWorkbenchConstants;
+import org.eclipse.ui.internal.UIPlugin;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.xmind.cathy.internal.jobs.OpenFilesJob;
+import org.xmind.core.internal.InternalCore;
+import org.xmind.core.licensing.ILicenseAgent;
+import org.xmind.core.licensing.ILicenseChangedListener;
+import org.xmind.core.licensing.ILicenseKeyHeader;
+import org.xmind.gef.ui.editor.IEditingContext;
+import org.xmind.ui.internal.PasswordProvider;
+import org.xmind.ui.internal.dialogs.DialogMessages;
+import org.xmind.ui.internal.editor.AbstractWorkbookRef;
+import org.xmind.ui.internal.editor.DefaultMindMapPreviewGenerator;
+import org.xmind.ui.internal.editor.IMindMapPreviewGenerator;
+import org.xmind.ui.internal.editor.IPasswordProvider;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class CathyWorkbenchAdvisor extends WorkbenchAdvisor
+ implements ILicenseChangedListener {
+
+ public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
+ IWorkbenchWindowConfigurer configurer) {
+ return new CathyWorkbenchWindowAdvisor(configurer);
+ }
+
+ public String getInitialWindowPerspectiveId() {
+ return MindMapUI.PERSPECTIVE_ID;
+ }
+
+ @Override
+ public String getMainPreferencePageId() {
+ return "org.xmind.ui.prefPage.General"; //$NON-NLS-1$
+ }
+
+ public void initialize(IWorkbenchConfigurer configurer) {
+ super.initialize(configurer);
+ configurer.setSaveAndRestore(true);
+ configurer.setExitOnLastWindowClose(true);
+ }
+
+ @Override
+ public void preStartup() {
+ super.preStartup();
+
+ CathyPlugin.getDefault().getLicenseAgent()
+ .addLicenseChangedListener(this);
+ licenseChanged(CathyPlugin.getDefault().getLicenseAgent());
+
+ /**
+ * This hack requires workbench to exist. See
+ * {@link org.eclipse.ui.internal.PlatformUIPreferenceListener}.
+ */
+ UIPlugin.getDefault().getPreferenceStore().setValue(
+ IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
+ true);
+ }
+
+ @Override
+ public void postStartup() {
+ super.postStartup();
+
+ IWorkbench workbench = getWorkbenchConfigurer().getWorkbench();
+
+ AbstractWorkbookRef.setDefaultEditingContext(
+ createDefaultEditingContext(workbench));
+
+ new StartUpProcess(workbench).startUp();
+ }
+
+ private IEditingContext createDefaultEditingContext(
+ final IWorkbench workbench) {
+ final IMindMapPreviewGenerator previewGenerator = new DefaultMindMapPreviewGenerator(
+ workbench.getDisplay());
+
+ final IPasswordProvider passwordProvider = new PasswordProvider();
+
+ return new IEditingContext() {
+ public T getAdapter(Class adapter) {
+
+ if (IMindMapPreviewGenerator.class.equals(adapter))
+ return adapter.cast(previewGenerator);
+
+ if (IPasswordProvider.class.equals(adapter))
+ return adapter.cast(passwordProvider);
+
+ T result;
+
+ result = workbench.getService(adapter);
+ if (result != null)
+ return result;
+
+ result = workbench.getAdapter(adapter);
+ if (result != null)
+ return result;
+
+ return result;
+ }
+ };
+ }
+
+ @Override
+ public void postShutdown() {
+ CathyPlugin.getDefault().getLicenseAgent()
+ .removeLicenseChangedListener(this);
+
+ AbstractWorkbookRef.setDefaultEditingContext(null);
+ super.postShutdown();
+ }
+
+ public boolean preShutdown() {
+ boolean readyToShutdown = super.preShutdown();
+ if (readyToShutdown) {
+ readyToShutdown = saveAllEditorsOnClose();
+ }
+ return readyToShutdown;
+ }
+
+ private boolean saveAllEditorsOnClose() {
+ IWorkbench workbench = getWorkbenchConfigurer().getWorkbench();
+ final ArrayList unClosedEditorRefs = new ArrayList();
+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
+ for (IWorkbenchWindow window : windows) {
+ IWorkbenchPage page = window.getActivePage();
+ for (IEditorReference editorRef : page.getEditorReferences()) {
+ unClosedEditorRefs.add(editorRef);
+ final IEditorPart editor = editorRef.getEditor(false);
+ if (editor != null && editor.isDirty()) {
+ int answer = promptToSaveOnClose(window, page, editor);
+ if (answer == ISaveablePart2.CANCEL)
+ return false;
+ if (answer == ISaveablePart2.YES) {
+ if (!doSaveEditor(window, editor)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ SafeRunner.run(new SafeRunnable() {
+ public void run() {
+ XMLMemento mem = recordEditorsState(unClosedEditorRefs);
+ saveMementoToFile(mem);
+ }
+ });
+ return closeAllEditors();
+ }
+
+ private XMLMemento recordEditorsState(
+ ArrayList editorRefs) {
+ XMLMemento memento = XMLMemento.createWriteRoot("xmind"); //$NON-NLS-1$
+ saveEditorsState(memento, editorRefs);
+ return memento;
+ }
+
+ private void saveEditorsState(IMemento memento,
+ ArrayList editorRefs) {
+ IEditorPart activeEditor = null;
+
+ IWorkbenchWindow window = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (window != null && window.getActivePage() != null) {
+ activeEditor = window.getActivePage().getActiveEditor();
+ }
+
+ IMemento childrenMemento = memento
+ .createChild(IWorkbenchConstants.TAG_EDITORS);
+ if (!editorRefs.isEmpty())
+ for (IEditorReference ref : editorRefs) {
+ IEditorPart editor = ref.getEditor(false);
+ if (editor == null) {
+ continue;
+ }
+ IMemento editorMemento = childrenMemento
+ .createChild(IWorkbenchConstants.TAG_EDITOR);
+ editorMemento.putBoolean(IWorkbenchConstants.TAG_ACTIVE_PART,
+ editor == activeEditor);
+ IPersistable editorPersistable = CathyPlugin.getAdapter(editor,
+ IPersistable.class);
+ if (editorPersistable != null) {
+ editorPersistable.saveState(editorMemento);
+ }
+
+ IEditorInput input = editor.getEditorInput();
+ IMemento inputMemento = editorMemento
+ .createChild(IWorkbenchConstants.TAG_INPUT);
+ IPersistableElement inputPersistable = CathyPlugin
+ .getAdapter(input, IPersistableElement.class);
+ if (inputPersistable != null) {
+ inputMemento.putString(IWorkbenchConstants.TAG_FACTORY_ID,
+ inputPersistable.getFactoryId());
+ inputPersistable.saveState(inputMemento);
+ }
+ }
+ }
+
+ private boolean saveMementoToFile(XMLMemento memento) {
+ // Save it to a file.
+ File stateFile = getEditorsStateFile();
+ if (stateFile == null) {
+ return false;
+ }
+ try {
+ FileOutputStream stream = new FileOutputStream(stateFile);
+ OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8"); //$NON-NLS-1$
+ memento.save(writer);
+ writer.close();
+ } catch (IOException e) {
+ stateFile.delete();
+ return false;
+ }
+
+ // Success !
+ return true;
+ }
+
+ private File getEditorsStateFile() {
+ IPath path = WorkbenchPlugin.getDefault().getDataLocation();
+ if (path == null) {
+ return null;
+ }
+ path = path.append("XMind_Editors.xml"); //$NON-NLS-1$
+ return path.toFile();
+ }
+
+ private int promptToSaveOnClose(IWorkbenchWindow window,
+ IWorkbenchPage page, IEditorPart editor) {
+ if (editor instanceof ISaveablePart2) {
+ int answer = ((ISaveablePart2) editor).promptToSaveOnClose();
+ if (answer != ISaveablePart2.DEFAULT)
+ return answer;
+ }
+ page.activate(editor);
+ MessageDialog dialog = new MessageDialog(window.getShell(),
+ DialogMessages.Save_title, null,
+ NLS.bind(WorkbenchMessages.PromptSaveEditorOnClosing_message,
+ editor.getTitle()),
+ MessageDialog.QUESTION,
+ new String[] { IDialogConstants.YES_LABEL,
+ IDialogConstants.NO_LABEL,
+ IDialogConstants.CANCEL_LABEL },
+ 0);
+ int answerIndex = dialog.open();
+ switch (answerIndex) {
+ case 0:
+ return ISaveablePart2.YES;
+ case 1:
+ return ISaveablePart2.NO;
+ default:
+ return ISaveablePart2.CANCEL;
+ }
+ }
+
+ private boolean doSaveEditor(final IWorkbenchWindow window,
+ final IEditorPart editor) {
+ final boolean[] saved = new boolean[1];
+ saved[0] = false;
+ window.getShell().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ SafeRunner.run(new SafeRunnable() {
+ public void run() throws Exception {
+ final IProgressMonitor monitor = new NullProgressMonitor();
+ if (InternalCore.DEBUG_WORKBOOK_SAVE)
+ CathyPlugin.log(
+ "CathyWorkbenchAdvisor: About to save workbook on workbench close: " //$NON-NLS-1$
+ + editor.getEditorInput()
+ .toString());
+ editor.doSave(monitor);
+ if (!monitor.isCanceled()) {
+ saved[0] = true;
+ } else {
+ if (InternalCore.DEBUG_WORKBOOK_SAVE)
+ CathyPlugin.log(
+ "CathyWorkbenchAdvisor: Finished saving workbook on workbench close: " //$NON-NLS-1$
+ + editor.getEditorInput()
+ .toString());
+ }
+ }
+ });
+ }
+ });
+ return saved[0];
+ }
+
+ private boolean closeAllEditors() {
+ boolean closed = false;
+ IWorkbench workbench = getWorkbenchConfigurer().getWorkbench();
+ for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
+ closed |= window.getActivePage().closeAllEditors(false);
+ }
+ return closed;
+ }
+
+ public void licenseChanged(ILicenseAgent agent) {
+ int type = agent.getLicenseType();
+ ILicenseKeyHeader header = agent.getLicenseKeyHeader();
+ String brandingVersion = System
+ .getProperty("org.xmind.product.brandingVersion", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ String licenseType;
+ if ((type & ILicenseAgent.PRO_LICENSE_KEY) != 0) {
+ licenseType = NLS.bind(WorkbenchMessages.About_ProTitle,
+ brandingVersion);
+ } else if ((type & ILicenseAgent.PLUS_LICENSE_KEY) != 0) {
+ licenseType = NLS.bind(WorkbenchMessages.About_PlusTitle,
+ brandingVersion);
+ } else if ((type & ILicenseAgent.PRO_SUBSCRIPTION) != 0) {
+ licenseType = WorkbenchMessages.About_ProSubscriptionTitle;
+ } else {
+ licenseType = null;
+ }
+
+ if (header != null && ((type & ILicenseAgent.PLUS_LICENSE_KEY) != 0
+ || (type & ILicenseAgent.PRO_LICENSE_KEY) != 0)) {
+ String licenseeType = header.getLicenseeType();
+ if (ILicenseKeyHeader.LICENSEE_FAMILY.equals(licenseeType)) {
+ licenseType = NLS.bind("{0} (Family License)", licenseType); //$NON-NLS-1$
+ } else if (ILicenseKeyHeader.LICENSEE_EDU.equals(licenseeType)) {
+ licenseType = NLS.bind("{0} (Academia License)", licenseType); //$NON-NLS-1$
+ } else if (ILicenseKeyHeader.LICENSEE_GOV.equals(licenseeType)) {
+ licenseType = NLS.bind("{0} (Gov/NPO License)", licenseType); //$NON-NLS-1$
+ } else if (ILicenseKeyHeader.LICENSEE_TEAM_5U.equals(licenseeType)
+ || ILicenseKeyHeader.LICENSEE_TEAM_10U.equals(licenseeType)
+ || ILicenseKeyHeader.LICENSEE_TEAM_20U
+ .equals(licenseeType)) {
+ licenseType = NLS.bind("{0} (Team License)", licenseType); //$NON-NLS-1$
+ } else if (ILicenseKeyHeader.LICENSEE_VLE.equals(licenseeType)) {
+ licenseType = NLS.bind("{0} (Volume License)", licenseType); //$NON-NLS-1$
+ }
+ }
+ if (licenseType == null) {
+ licenseType = WorkbenchMessages.About_LicenseType_Unactivated;
+ } else {
+ licenseType = NLS.bind(WorkbenchMessages.About_LicenseTypePattern,
+ licenseType);
+ }
+ System.setProperty("org.xmind.product.license.type", //$NON-NLS-1$
+ licenseType);
+
+ String name = agent.getLicenseeName();
+ if (name != null && !"".equals(name)) { //$NON-NLS-1$
+ name = NLS.bind(WorkbenchMessages.About_LicensedTo, name);
+ } else {
+ name = ""; //$NON-NLS-1$
+ }
+ System.setProperty("org.xmind.product.license.licensee", name); //$NON-NLS-1$
+ }
+
+ @Override
+ public void eventLoopIdle(Display display) {
+ String[] paths = OpenDocumentQueue.getInstance().drain();
+ if (paths.length > 0) {
+ CathyPlugin.log("Ready to open files: " + Arrays.toString(paths)); //$NON-NLS-1$
+ openFiles(paths);
+ IWorkbenchWindow window = getWorkbenchConfigurer().getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (window != null) {
+ Shell shell = window.getShell();
+ if (shell != null && !shell.isDisposed()) {
+ shell.forceActive();
+ }
+ }
+ } else {
+ super.eventLoopIdle(display);
+ }
+ }
+
+ private void openFiles(String[] paths) {
+ OpenFilesJob job = new OpenFilesJob(
+ getWorkbenchConfigurer().getWorkbench(),
+ WorkbenchMessages.CheckOpenFilesJob_CheckFiles_name,
+ Arrays.asList(paths));
+ job.setRule(Log.get(Log.OPENING));
+ job.schedule();
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchWindowAdvisor.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchWindowAdvisor.java
index 2e884ba61..b70b84d1a 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchWindowAdvisor.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CathyWorkbenchWindowAdvisor.java
@@ -1,354 +1,360 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import java.io.File;
-import java.util.List;
-
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.e4.ui.workbench.modeling.EModelService;
-import org.eclipse.e4.ui.workbench.modeling.EPartService;
-import org.eclipse.e4.ui.workbench.modeling.IPartListener;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorReference;
-import org.eclipse.ui.IPartListener2;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPartReference;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.application.ActionBarAdvisor;
-import org.eclipse.ui.application.IActionBarConfigurer;
-import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
-import org.eclipse.ui.application.WorkbenchWindowAdvisor;
-import org.eclipse.ui.internal.Workbench;
-import org.eclipse.ui.internal.tweaklets.TitlePathUpdater;
-import org.eclipse.ui.internal.tweaklets.Tweaklets;
-import org.xmind.core.licensing.ILicenseAgent;
-import org.xmind.core.licensing.ILicenseChangedListener;
-import org.xmind.core.util.FileUtils;
-import org.xmind.ui.internal.editor.MME;
-import org.xmind.ui.internal.workbench.Util;
-
-public class CathyWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor
- implements IPartListener2, IPropertyListener, ILicenseChangedListener {
-
- private String licenseName = null;
-
- private IWorkbenchPartReference activePartRef = null;
-
-// private boolean checkingNewWorkbookEditor = false;
-
- private TitlePathUpdater titlePathUpdater;
-
- private boolean homeShowing = false;
-
- public CathyWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
- super(configurer);
- this.titlePathUpdater = (TitlePathUpdater) Tweaklets
- .get(TitlePathUpdater.KEY);
- }
-
- public ActionBarAdvisor createActionBarAdvisor(
- IActionBarConfigurer configurer) {
- return new CathyWorkbenchActionBuilder(configurer);
- }
-
- public void preWindowOpen() {
- IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
- configurer.setInitialSize(Util.getInitialWindowSize());
- configurer.setShowCoolBar(true);
- configurer.setShowStatusLine(true);
- configurer.setShowProgressIndicator(true);
- configurer.setTitle(WorkbenchMessages.AppWindowTitle);
-
- CathyPlugin.getDefault().getLicenseAgent()
- .addLicenseChangedListener(this);
- }
-
- public void postWindowOpen() {
- final IWorkbenchWindow window = getWindowConfigurer().getWindow();
- if (window != null) {
- window.getPartService().addPartListener(this);
-
- Shell shell = window.getShell();
- if (shell != null && !shell.isDisposed()) {
- shell.addShellListener(new ShellAdapter() {
- @Override
- public void shellActivated(ShellEvent e) {
- Display.getCurrent().asyncExec(new Runnable() {
- public void run() {
- SafeRunner.run(new SafeRunnable() {
- public void run() throws Exception {
- new CheckOpenFilesProcess(
- window.getWorkbench())
- .doCheckAndOpenFiles();
- }
- });
- }
- });
- }
- });
- }
- }
-
- addE4PartListener();
- }
-
- private void addE4PartListener() {
- IWorkbench workbench = getWindowConfigurer().getWorkbenchConfigurer()
- .getWorkbench();
- EModelService modelService = workbench.getService(EModelService.class);
- MApplication application = ((Workbench) workbench).getApplication();
-
- if (modelService == null || application == null) {
- return;
- }
-
- final List windows = modelService.findElements(application,
- ICathyConstants.ID_MAIN_WINDOW, MWindow.class, null);
- if (windows.isEmpty()) {
- return;
- }
- for (MWindow window : windows) {
- Shell shell = (Shell) window.getContext().get("localActiveShell"); //$NON-NLS-1$
- if (shell != null)
- shell.setMinimumSize(1000, 700);
- }
-
- EPartService partService = windows.get(0).getContext()
- .get(EPartService.class);
- if (partService == null) {
- return;
- }
-
- partService.addPartListener(new IPartListener() {
-
- public void partVisible(MPart part) {
- }
-
- public void partHidden(MPart part) {
- }
-
- public void partDeactivated(MPart part) {
- if (ICathyConstants.ID_DASHBOARD_PART
- .equals(part.getElementId())) {
- homeShowing = false;
- updateWindowTitle();
- }
- }
-
- public void partBroughtToTop(MPart part) {
- }
-
- public void partActivated(MPart part) {
- if (ICathyConstants.ID_DASHBOARD_PART
- .equals(part.getElementId())) {
- homeShowing = true;
- updateWindowTitle();
- }
- }
- });
- }
-
- @Override
- public void postWindowClose() {
- CathyPlugin.getDefault().getLicenseAgent()
- .removeLicenseChangedListener(this);
- }
-
- public void licenseChanged(ILicenseAgent agent) {
- int licenseType = agent.getLicenseType();
- if ((licenseType & ILicenseAgent.PRO_LICENSE_KEY) != 0) {
- licenseName = "Pro"; //$NON-NLS-1$
- } else if ((licenseType & ILicenseAgent.PLUS_LICENSE_KEY) != 0) {
- licenseName = "Plus"; //$NON-NLS-1$
- } else if ((licenseType & ILicenseAgent.PRO_SUBSCRIPTION) != 0) {
- licenseName = "Pro"; //$NON-NLS-1$
- } else {
- licenseName = null;
- }
- updateWindowTitle();
- }
-
- public void partActivated(IWorkbenchPartReference partRef) {
- if (partRef instanceof IEditorReference) {
- if (activePartRef != null) {
- activePartRef.removePropertyListener(this);
- }
- activePartRef = partRef;
- activePartRef.addPropertyListener(this);
- }
- updateWindowTitle();
- }
-
- public void partBroughtToTop(IWorkbenchPartReference partRef) {
- }
-
- public void partClosed(IWorkbenchPartReference partRef) {
- if (partRef == activePartRef) {
- activePartRef = null;
- partRef.removePropertyListener(this);
- }
- updateWindowTitle();
-// checkNewWorkbookEditor();
- }
-
- public void partDeactivated(IWorkbenchPartReference partRef) {
- }
-
- public void partHidden(IWorkbenchPartReference partRef) {
- updateWindowTitle();
- }
-
- public void partInputChanged(IWorkbenchPartReference partRef) {
- updateWindowTitle();
- }
-
- public void partOpened(IWorkbenchPartReference partRef) {
-// if (partRef instanceof IEditorReference
-// && !NewWorkbookEditor.EDITOR_ID.equals(partRef.getId())) {
-// checkNewWorkbookEditor();
-// }
- }
-
- public void partVisible(IWorkbenchPartReference partRef) {
- updateWindowTitle();
- }
-
- private void updateWindowTitle() {
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- public void run() {
- doUpdateWindowTitle();
- }
- });
- }
-
- private void doUpdateWindowTitle() {
- IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
- IWorkbenchWindow window = configurer.getWindow();
- if (window == null)
- return;
-
- Shell shell = window.getShell();
- if (shell == null || shell.isDisposed())
- return;
-
- StringBuffer sb = new StringBuffer(20);
-
- if (homeShowing) {
- sb.append(
- WorkbenchMessages.CathyWorkbenchWindowAdvisor_windowTitle_home_prefix);
- }
-
- IWorkbenchPage page = window.getActivePage();
- IEditorPart editor = null;
- if (page != null) {
- editor = page.getActiveEditor();
- }
-
- if (editor == null) {
- sb.append(WorkbenchMessages.AppWindowTitle);
- if (licenseName != null) {
- sb.append(' ');
- sb.append(licenseName);
- }
- } else {
- String text = editor.getClass().toString()
- .contains("org.xmind.ui.internal.browser") ? null //$NON-NLS-1$
- : editor.getTitleToolTip();
- if (text == null) {
- text = editor.getTitle();
- } else {
- text = FileUtils.getFileName(text);
- }
- sb.append(text);
- }
-
- configurer.setTitle(sb.toString());
-
- if (titlePathUpdater != null) {
- titlePathUpdater.updateTitlePath(shell, computeTitlePath(page));
- }
- }
-
- private String computeTitlePath(IWorkbenchPage page) {
- IEditorPart activeEditor = page.getActiveEditor();
- if (activeEditor != null) {
- IEditorInput editorInput = activeEditor.getEditorInput();
- if (editorInput != null) {
- File file = MME.getFile(editorInput);
- if (file != null)
- return file.getAbsolutePath();
- }
- }
- return null;
- }
-
- public void propertyChanged(Object source, int propId) {
- updateWindowTitle();
- }
-
-// private void checkNewWorkbookEditor() {
-// if (checkingNewWorkbookEditor)
-// return;
-// checkingNewWorkbookEditor = true;
-// Display.getCurrent().asyncExec(new Runnable() {
-// public void run() {
-// try {
-// IWorkbenchWindow window = getWindowConfigurer().getWindow();
-// Shell shell = window.getShell();
-// if (shell == null || shell.isDisposed())
-// return;
-//
-// IWorkbenchPage page = window.getActivePage();
-// if (page == null)
-// return;
-//
-// int numEditors = 0;
-// IEditorReference[] editors = page.getEditorReferences();
-// for (int i = 0; i < editors.length; i++) {
-// IEditorReference editor = editors[i];
-// if (!NewWorkbookEditor.EDITOR_ID
-// .equals(editor.getId())) {
-// numEditors++;
-// }
-// }
-//
-// if (numEditors > 0) {
-// // Has normal editors, hide NewWorkbookEditor:
-// NewWorkbookEditor.hideFrom(window);
-// } else {
-// // No normal editors, show NewWorkbookEditor:
-// NewWorkbookEditor.showIn(window);
-// }
-//
-// } finally {
-// checkingNewWorkbookEditor = false;
-// }
-// }
-// });
-// }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.e4.ui.workbench.modeling.IPartListener;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.swt.events.ShellAdapter;
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.application.ActionBarAdvisor;
+import org.eclipse.ui.application.IActionBarConfigurer;
+import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
+import org.eclipse.ui.application.WorkbenchWindowAdvisor;
+import org.eclipse.ui.internal.Workbench;
+import org.eclipse.ui.internal.tweaklets.TitlePathUpdater;
+import org.eclipse.ui.internal.tweaklets.Tweaklets;
+import org.xmind.core.licensing.ILicenseAgent;
+import org.xmind.core.licensing.ILicenseChangedListener;
+import org.xmind.core.util.FileUtils;
+import org.xmind.ui.internal.editor.MME;
+import org.xmind.ui.internal.workbench.Util;
+
+public class CathyWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor
+ implements IPartListener2, IPropertyListener, ILicenseChangedListener {
+
+ private String licenseName = null;
+
+ private IWorkbenchPartReference activePartRef = null;
+
+// private boolean checkingNewWorkbookEditor = false;
+
+ private TitlePathUpdater titlePathUpdater;
+
+ private boolean homeShowing = false;
+
+ public CathyWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
+ super(configurer);
+ this.titlePathUpdater = (TitlePathUpdater) Tweaklets
+ .get(TitlePathUpdater.KEY);
+ }
+
+ public ActionBarAdvisor createActionBarAdvisor(
+ IActionBarConfigurer configurer) {
+ return new CathyWorkbenchActionBuilder(configurer);
+ }
+
+ public void preWindowOpen() {
+ IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
+ configurer.setInitialSize(Util.getInitialWindowSize());
+ configurer.setShowCoolBar(true);
+ configurer.setShowStatusLine(true);
+ configurer.setShowProgressIndicator(true);
+ configurer.setTitle(WorkbenchMessages.AppWindowTitle);
+
+ CathyPlugin.getDefault().getLicenseAgent()
+ .addLicenseChangedListener(this);
+ }
+
+ public void postWindowOpen() {
+ final IWorkbenchWindow window = getWindowConfigurer().getWindow();
+ if (window != null) {
+ window.getPartService().addPartListener(this);
+
+ Shell shell = window.getShell();
+ if (shell != null && !shell.isDisposed()) {
+ shell.addShellListener(new ShellAdapter() {
+ @Override
+ public void shellActivated(ShellEvent e) {
+ Display display = Display.getCurrent();
+ if (display != null && !display.isDisposed()) {
+ display.asyncExec(new Runnable() {
+ public void run() {
+ SafeRunner.run(new SafeRunnable() {
+ public void run() throws Exception {
+ new CheckOpenFilesProcess(
+ window.getWorkbench())
+ .doCheckAndOpenFiles();
+ }
+ });
+ }
+ });
+ }
+ }
+ });
+ }
+ }
+
+ addE4PartListener();
+ }
+
+ private void addE4PartListener() {
+ IWorkbench workbench = getWindowConfigurer().getWorkbenchConfigurer()
+ .getWorkbench();
+ EModelService modelService = workbench.getService(EModelService.class);
+ MApplication application = ((Workbench) workbench).getApplication();
+
+ if (modelService == null || application == null) {
+ return;
+ }
+
+ final List windows = modelService.findElements(application,
+ ICathyConstants.ID_MAIN_WINDOW, MWindow.class, null);
+ if (windows.isEmpty()) {
+ return;
+ }
+ for (MWindow window : windows) {
+ Shell shell = (Shell) window.getContext().get("localActiveShell"); //$NON-NLS-1$
+ if (shell != null)
+ shell.setMinimumSize(1000, 700);
+ }
+
+ EPartService partService = windows.get(0).getContext()
+ .get(EPartService.class);
+ if (partService == null) {
+ return;
+ }
+
+ partService.addPartListener(new IPartListener() {
+
+ public void partVisible(MPart part) {
+ }
+
+ public void partHidden(MPart part) {
+ }
+
+ public void partDeactivated(MPart part) {
+ if (ICathyConstants.ID_DASHBOARD_PART
+ .equals(part.getElementId())) {
+ homeShowing = false;
+ updateWindowTitle();
+ }
+ }
+
+ public void partBroughtToTop(MPart part) {
+ }
+
+ public void partActivated(MPart part) {
+ if (ICathyConstants.ID_DASHBOARD_PART
+ .equals(part.getElementId())) {
+ homeShowing = true;
+ updateWindowTitle();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void postWindowClose() {
+ CathyPlugin.getDefault().getLicenseAgent()
+ .removeLicenseChangedListener(this);
+ }
+
+ public void licenseChanged(ILicenseAgent agent) {
+ int licenseType = agent.getLicenseType();
+ if ((licenseType & ILicenseAgent.PRO_LICENSE_KEY) != 0) {
+ licenseName = "Pro"; //$NON-NLS-1$
+ } else if ((licenseType & ILicenseAgent.PLUS_LICENSE_KEY) != 0) {
+ licenseName = "Plus"; //$NON-NLS-1$
+ } else if ((licenseType & ILicenseAgent.PRO_SUBSCRIPTION) != 0) {
+ licenseName = "Pro"; //$NON-NLS-1$
+ } else {
+ licenseName = null;
+ }
+ updateWindowTitle();
+ }
+
+ public void partActivated(IWorkbenchPartReference partRef) {
+ if (partRef instanceof IEditorReference) {
+ if (activePartRef != null) {
+ activePartRef.removePropertyListener(this);
+ }
+ activePartRef = partRef;
+ activePartRef.addPropertyListener(this);
+ }
+ updateWindowTitle();
+ }
+
+ public void partBroughtToTop(IWorkbenchPartReference partRef) {
+ }
+
+ public void partClosed(IWorkbenchPartReference partRef) {
+ if (partRef == activePartRef) {
+ activePartRef = null;
+ partRef.removePropertyListener(this);
+ }
+ updateWindowTitle();
+// checkNewWorkbookEditor();
+ }
+
+ public void partDeactivated(IWorkbenchPartReference partRef) {
+ }
+
+ public void partHidden(IWorkbenchPartReference partRef) {
+ updateWindowTitle();
+ }
+
+ public void partInputChanged(IWorkbenchPartReference partRef) {
+ updateWindowTitle();
+ }
+
+ public void partOpened(IWorkbenchPartReference partRef) {
+// if (partRef instanceof IEditorReference
+// && !NewWorkbookEditor.EDITOR_ID.equals(partRef.getId())) {
+// checkNewWorkbookEditor();
+// }
+ }
+
+ public void partVisible(IWorkbenchPartReference partRef) {
+ updateWindowTitle();
+ }
+
+ private void updateWindowTitle() {
+ Display display = PlatformUI.getWorkbench().getDisplay();
+ if (display != null && !display.isDisposed()) {
+ display.asyncExec(new Runnable() {
+ public void run() {
+ doUpdateWindowTitle();
+ }
+ });
+ }
+ }
+
+ private void doUpdateWindowTitle() {
+ IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
+ IWorkbenchWindow window = configurer.getWindow();
+ if (window == null)
+ return;
+
+ Shell shell = window.getShell();
+ if (shell == null || shell.isDisposed())
+ return;
+
+ StringBuffer sb = new StringBuffer(20);
+
+ if (homeShowing) {
+ sb.append(
+ WorkbenchMessages.CathyWorkbenchWindowAdvisor_windowTitle_home_prefix);
+ }
+
+ IWorkbenchPage page = window.getActivePage();
+ IEditorPart editor = null;
+ if (page != null) {
+ editor = page.getActiveEditor();
+ }
+
+ if (editor == null) {
+ sb.append(WorkbenchMessages.AppWindowTitle);
+ if (licenseName != null) {
+ sb.append(' ');
+ sb.append(licenseName);
+ }
+ } else {
+ String text = editor.getClass().toString()
+ .contains("org.xmind.ui.internal.browser") ? null //$NON-NLS-1$
+ : editor.getTitleToolTip();
+ if (text == null) {
+ text = editor.getTitle();
+ } else {
+ text = FileUtils.getFileName(text);
+ }
+ sb.append(text);
+ }
+
+ configurer.setTitle(sb.toString());
+
+ if (titlePathUpdater != null) {
+ titlePathUpdater.updateTitlePath(shell, computeTitlePath(page));
+ }
+ }
+
+ private String computeTitlePath(IWorkbenchPage page) {
+ IEditorPart activeEditor = page.getActiveEditor();
+ if (activeEditor != null) {
+ IEditorInput editorInput = activeEditor.getEditorInput();
+ if (editorInput != null) {
+ File file = MME.getFile(editorInput);
+ if (file != null)
+ return file.getAbsolutePath();
+ }
+ }
+ return null;
+ }
+
+ public void propertyChanged(Object source, int propId) {
+ updateWindowTitle();
+ }
+
+// private void checkNewWorkbookEditor() {
+// if (checkingNewWorkbookEditor)
+// return;
+// checkingNewWorkbookEditor = true;
+// Display.getCurrent().asyncExec(new Runnable() {
+// public void run() {
+// try {
+// IWorkbenchWindow window = getWindowConfigurer().getWindow();
+// Shell shell = window.getShell();
+// if (shell == null || shell.isDisposed())
+// return;
+//
+// IWorkbenchPage page = window.getActivePage();
+// if (page == null)
+// return;
+//
+// int numEditors = 0;
+// IEditorReference[] editors = page.getEditorReferences();
+// for (int i = 0; i < editors.length; i++) {
+// IEditorReference editor = editors[i];
+// if (!NewWorkbookEditor.EDITOR_ID
+// .equals(editor.getId())) {
+// numEditors++;
+// }
+// }
+//
+// if (numEditors > 0) {
+// // Has normal editors, hide NewWorkbookEditor:
+// NewWorkbookEditor.hideFrom(window);
+// } else {
+// // No normal editors, show NewWorkbookEditor:
+// NewWorkbookEditor.showIn(window);
+// }
+//
+// } finally {
+// checkingNewWorkbookEditor = false;
+// }
+// }
+// });
+// }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CheckOpenFilesProcess.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CheckOpenFilesProcess.java
index 8539206e2..8ce4fe06a 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CheckOpenFilesProcess.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CheckOpenFilesProcess.java
@@ -1,35 +1,35 @@
-package org.xmind.cathy.internal;
-
-import java.io.File;
-import java.util.List;
-
-import org.eclipse.ui.IWorkbench;
-
-public class CheckOpenFilesProcess extends OpenFilesProcess {
-
- public CheckOpenFilesProcess(IWorkbench workbench) {
- super(workbench);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.xmind.cathy.internal.jobs.OpenFilesJob#filterFilesToOpen(java.util
- * .List, org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- protected void filterFilesToOpen(List filesToOpen) {
- Log opening = Log.get(Log.OPENING);
- if (opening.exists()) {
- String[] contents = opening.getContents();
- for (String line : contents) {
- if (line.startsWith("xmind:") || new File(line).exists()) { //$NON-NLS-1$
- filesToOpen.add(line);
- }
- }
- opening.delete();
- }
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.ui.IWorkbench;
+
+public class CheckOpenFilesProcess extends OpenFilesProcess {
+
+ public CheckOpenFilesProcess(IWorkbench workbench) {
+ super(workbench);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.xmind.cathy.internal.jobs.OpenFilesJob#filterFilesToOpen(java.util
+ * .List, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected void filterFilesToOpen(List filesToOpen) {
+ Log opening = Log.get(Log.OPENING);
+ if (opening.exists()) {
+ String[] contents = opening.getContents();
+ for (String line : contents) {
+ if (line.startsWith("xmind:") || new File(line).exists()) { //$NON-NLS-1$
+ filesToOpen.add(line);
+ }
+ }
+ opening.delete();
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CommandLabelUpdater.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CommandLabelUpdater.java
index 7b1e2a525..1a8a5bac0 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CommandLabelUpdater.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/CommandLabelUpdater.java
@@ -1,218 +1,226 @@
-
-package org.xmind.cathy.internal;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.inject.Inject;
-
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.eclipse.e4.core.di.extensions.EventTopic;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.e4.ui.model.application.ui.menu.MItem;
-import org.eclipse.e4.ui.workbench.UIEvents;
-import org.eclipse.e4.ui.workbench.modeling.EModelService;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IViewSite;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchPartSite;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.SubActionBars;
-import org.eclipse.ui.actions.ActionFactory;
-import org.osgi.service.event.Event;
-
-public class CommandLabelUpdater implements IPropertyChangeListener {
-
- private static final int TEXT = 1 << 1;
- private static final int TOOLTIP = 1 << 2;
-
- private static final String DATA_ORIGINAL_TEXT = "CommandLabelUpdater:OriginalText"; //$NON-NLS-1$
- private static final String DATA_ORIGINAL_TOOLTIP = "CommandLabelUpdater:OriginalTooltip"; //$NON-NLS-1$
-
- @Inject
- private EModelService modelService;
-
- private MWindow activeWindow = null;
- private IActionBars activeActionBars = null;
- private Set trackedHandlers = null;
-
- @Inject
- @Optional
- public void applicationStarted(
- @EventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event) {
- }
-
- @Inject
- @Optional
- public void activePartChanged(
- @EventTopic(UIEvents.UILifeCycle.ACTIVATE) Event event) {
- Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
- if (!(element instanceof MPart))
- return;
-
- MPart part = (MPart) element;
- MWindow window = findWindowFor(part);
- if (window == null)
- return;
-
- partActivated(part, window);
- }
-
- private void partActivated(MPart part, MWindow window) {
- IWorkbenchWindow ww = window.getContext().get(IWorkbenchWindow.class);
- IActionBars actionBars = findActionBars(ww);
-
- this.activeWindow = window;
-
- if (actionBars != this.activeActionBars) {
- if (this.activeActionBars instanceof SubActionBars) {
- ((SubActionBars) this.activeActionBars)
- .removePropertyChangeListener(this);
- }
- this.activeActionBars = actionBars;
- if (this.activeActionBars instanceof SubActionBars) {
- ((SubActionBars) this.activeActionBars)
- .addPropertyChangeListener(this);
- }
-
- updateAllItemLabels();
- }
- }
-
- private void updateAllItemLabels() {
- if (activeWindow == null)
- return;
-
- Set oldTrackedHandlers = this.trackedHandlers;
- Set newTrackedHandlers = new HashSet();
-
- updateItemLabel(activeActionBars, activeWindow.getMainMenu(),
- ICathyConstants.ID_MENU_ITEM_UNDO, ActionFactory.UNDO.getId(),
- ActionFactory.UNDO.getCommandId(), TEXT, newTrackedHandlers);
- updateItemLabel(activeActionBars, activeWindow.getMainMenu(),
- ICathyConstants.ID_MENU_ITEM_REDO, ActionFactory.REDO.getId(),
- ActionFactory.REDO.getCommandId(), TEXT, newTrackedHandlers);
-
- updateItemLabel(activeActionBars, activeWindow,
- ICathyConstants.ID_TOOL_ITEM_UNDO, ActionFactory.UNDO.getId(),
- ActionFactory.UNDO.getCommandId(), TOOLTIP, newTrackedHandlers);
- updateItemLabel(activeActionBars, activeWindow,
- ICathyConstants.ID_TOOL_ITEM_REDO, ActionFactory.REDO.getId(),
- ActionFactory.REDO.getCommandId(), TOOLTIP, newTrackedHandlers);
-
- this.trackedHandlers = newTrackedHandlers;
-
- if (oldTrackedHandlers != null) {
- for (IAction handler : oldTrackedHandlers) {
- if (!newTrackedHandlers.contains(handler)) {
- handler.removePropertyChangeListener(this);
- }
- }
- }
- for (IAction handler : newTrackedHandlers) {
- if (oldTrackedHandlers == null
- || !oldTrackedHandlers.contains(handler)) {
- handler.addPropertyChangeListener(this);
- }
- }
- }
-
- private void updateItemLabel(IActionBars actionBars, MUIElement topElement,
- String itemId, String actionId, String commandId, int attributes,
- Set handlers) {
- if (modelService == null || topElement == null)
- return;
-
- MUIElement element = modelService.find(itemId, topElement);
- if (!(element instanceof MItem))
- return;
-
- MItem item = (MItem) element;
-
- IAction handler = actionBars == null ? null
- : actionBars.getGlobalActionHandler(actionId);
-
- if ((attributes & TEXT) != 0) {
- String text = handler == null ? null : handler.getText();
- if (text != null) {
- if (!item.getTransientData().containsKey(DATA_ORIGINAL_TEXT)) {
- item.getTransientData().put(DATA_ORIGINAL_TEXT,
- item.getLabel());
- }
- item.setLabel(text);
- } else {
- Object originalText = item.getTransientData()
- .get(DATA_ORIGINAL_TEXT);
- if (originalText != null && originalText instanceof String) {
- item.setLabel((String) originalText);
- }
- }
- }
- if ((attributes & TOOLTIP) != 0) {
- String tooltip = handler == null ? null : handler.getToolTipText();
- if (tooltip != null) {
- if (!item.getTransientData()
- .containsKey(DATA_ORIGINAL_TOOLTIP)) {
- item.getTransientData().put(DATA_ORIGINAL_TOOLTIP,
- item.getTooltip());
- }
- item.setTooltip(tooltip);
- } else {
- Object originalTooltip = item.getTransientData()
- .get(DATA_ORIGINAL_TOOLTIP);
- if (originalTooltip != null
- && originalTooltip instanceof String) {
- item.setTooltip((String) originalTooltip);
- }
- }
- }
-
- }
-
- private MWindow findWindowFor(MUIElement element) {
- if (element == null)
- return null;
- if (element instanceof MWindow)
- return (MWindow) element;
- MPlaceholder placeholder = element.getCurSharedRef();
- if (placeholder != null)
- return findWindowFor(placeholder);
- MUIElement parent = element.getParent();
- if (parent != null)
- return findWindowFor(parent);
- return null;
- }
-
- private IActionBars findActionBars(IWorkbenchWindow window) {
- if (window == null)
- return null;
-
- IWorkbenchPage page = window.getActivePage();
- if (page == null)
- return null;
-
- IWorkbenchPart activePart = page.getActivePart();
- if (activePart == null)
- return null;
-
- IWorkbenchPartSite site = activePart.getSite();
- if (site instanceof IEditorSite)
- return ((IEditorSite) site).getActionBars();
- if (site instanceof IViewSite)
- return ((IViewSite) site).getActionBars();
- return null;
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- updateAllItemLabels();
- }
-
-}
+
+package org.xmind.cathy.internal;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import javax.inject.Inject;
+
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.core.di.extensions.EventTopic;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.model.application.ui.menu.MItem;
+import org.eclipse.e4.ui.workbench.UIEvents;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.SubActionBars;
+import org.eclipse.ui.actions.ActionFactory;
+import org.osgi.service.event.Event;
+
+public class CommandLabelUpdater implements IPropertyChangeListener {
+
+ private static final int TEXT = 1 << 1;
+ private static final int TOOLTIP = 1 << 2;
+
+ private static final String DATA_ORIGINAL_TEXT = "CommandLabelUpdater:OriginalText"; //$NON-NLS-1$
+ private static final String DATA_ORIGINAL_TOOLTIP = "CommandLabelUpdater:OriginalTooltip"; //$NON-NLS-1$
+ private static final String WEAK_VALUE_PLACEHOLDER = "WeakValuePlaceHolder"; //$NON-NLS-1$
+
+ @Inject
+ private EModelService modelService;
+
+ private MWindow activeWindow = null;
+ private WeakHashMap activeActionBarsWeakRef = new WeakHashMap();
+ private Set trackedHandlers = null;
+
+ @Inject
+ @Optional
+ public void applicationStarted(
+ @EventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event) {
+ }
+
+ @Inject
+ @Optional
+ public void activePartChanged(
+ @EventTopic(UIEvents.UILifeCycle.ACTIVATE) Event event) {
+ Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
+ if (!(element instanceof MPart))
+ return;
+
+ MPart part = (MPart) element;
+ MWindow window = findWindowFor(part);
+ if (window == null)
+ return;
+
+ partActivated(part, window);
+ }
+
+ private void partActivated(MPart part, MWindow window) {
+ IWorkbenchWindow ww = window.getContext().get(IWorkbenchWindow.class);
+ IActionBars actionBars = findActionBars(ww);
+
+ this.activeWindow = window;
+ Object[] bars = activeActionBarsWeakRef.keySet().toArray();
+ IActionBars activeActionBars = bars.length > 0 ? (IActionBars) bars[0]
+ : null;
+
+ if (actionBars != activeActionBars) {
+ if (activeActionBars instanceof SubActionBars) {
+ ((SubActionBars) activeActionBars)
+ .removePropertyChangeListener(this);
+ }
+ activeActionBarsWeakRef.put(actionBars, WEAK_VALUE_PLACEHOLDER);
+ if (actionBars instanceof SubActionBars) {
+ ((SubActionBars) actionBars).addPropertyChangeListener(this);
+ }
+
+ updateAllItemLabels();
+ }
+ }
+
+ private void updateAllItemLabels() {
+ if (activeWindow == null)
+ return;
+
+ Set oldTrackedHandlers = this.trackedHandlers;
+ Set newTrackedHandlers = new HashSet();
+
+ Object[] bars = activeActionBarsWeakRef.keySet().toArray();
+ IActionBars activeActionBars = bars.length > 0 ? (IActionBars) bars[0]
+ : null;
+
+ updateItemLabel(activeActionBars, activeWindow.getMainMenu(),
+ ICathyConstants.ID_MENU_ITEM_UNDO, ActionFactory.UNDO.getId(),
+ ActionFactory.UNDO.getCommandId(), TEXT, newTrackedHandlers);
+ updateItemLabel(activeActionBars, activeWindow.getMainMenu(),
+ ICathyConstants.ID_MENU_ITEM_REDO, ActionFactory.REDO.getId(),
+ ActionFactory.REDO.getCommandId(), TEXT, newTrackedHandlers);
+
+ updateItemLabel(activeActionBars, activeWindow,
+ ICathyConstants.ID_TOOL_ITEM_UNDO, ActionFactory.UNDO.getId(),
+ ActionFactory.UNDO.getCommandId(), TOOLTIP, newTrackedHandlers);
+ updateItemLabel(activeActionBars, activeWindow,
+ ICathyConstants.ID_TOOL_ITEM_REDO, ActionFactory.REDO.getId(),
+ ActionFactory.REDO.getCommandId(), TOOLTIP, newTrackedHandlers);
+
+ this.trackedHandlers = newTrackedHandlers;
+
+ if (oldTrackedHandlers != null) {
+ for (IAction handler : oldTrackedHandlers) {
+ if (!newTrackedHandlers.contains(handler)) {
+ handler.removePropertyChangeListener(this);
+ }
+ }
+ }
+ for (IAction handler : newTrackedHandlers) {
+ if (oldTrackedHandlers == null
+ || !oldTrackedHandlers.contains(handler)) {
+ handler.addPropertyChangeListener(this);
+ }
+ }
+ }
+
+ private void updateItemLabel(IActionBars actionBars, MUIElement topElement,
+ String itemId, String actionId, String commandId, int attributes,
+ Set handlers) {
+ if (modelService == null || topElement == null)
+ return;
+
+ MUIElement element = modelService.find(itemId, topElement);
+ if (!(element instanceof MItem))
+ return;
+
+ MItem item = (MItem) element;
+
+ IAction handler = actionBars == null ? null
+ : actionBars.getGlobalActionHandler(actionId);
+
+ if ((attributes & TEXT) != 0) {
+ String text = handler == null ? null : handler.getText();
+ if (text != null) {
+ if (!item.getTransientData().containsKey(DATA_ORIGINAL_TEXT)) {
+ item.getTransientData().put(DATA_ORIGINAL_TEXT,
+ item.getLabel());
+ }
+ item.setLabel(text);
+ } else {
+ Object originalText = item.getTransientData()
+ .get(DATA_ORIGINAL_TEXT);
+ if (originalText != null && originalText instanceof String) {
+ item.setLabel((String) originalText);
+ }
+ }
+ }
+ if ((attributes & TOOLTIP) != 0) {
+ String tooltip = handler == null ? null : handler.getToolTipText();
+ if (tooltip != null) {
+ if (!item.getTransientData()
+ .containsKey(DATA_ORIGINAL_TOOLTIP)) {
+ item.getTransientData().put(DATA_ORIGINAL_TOOLTIP,
+ item.getTooltip());
+ }
+ item.setTooltip(tooltip);
+ } else {
+ Object originalTooltip = item.getTransientData()
+ .get(DATA_ORIGINAL_TOOLTIP);
+ if (originalTooltip != null
+ && originalTooltip instanceof String) {
+ item.setTooltip((String) originalTooltip);
+ }
+ }
+ }
+
+ }
+
+ private MWindow findWindowFor(MUIElement element) {
+ if (element == null)
+ return null;
+ if (element instanceof MWindow)
+ return (MWindow) element;
+ MPlaceholder placeholder = element.getCurSharedRef();
+ if (placeholder != null)
+ return findWindowFor(placeholder);
+ MUIElement parent = element.getParent();
+ if (parent != null)
+ return findWindowFor(parent);
+ return null;
+ }
+
+ private IActionBars findActionBars(IWorkbenchWindow window) {
+ if (window == null)
+ return null;
+
+ IWorkbenchPage page = window.getActivePage();
+ if (page == null)
+ return null;
+
+ IWorkbenchPart activePart = page.getActivePart();
+ if (activePart == null)
+ return null;
+
+ IWorkbenchPartSite site = activePart.getSite();
+ if (site instanceof IEditorSite)
+ return ((IEditorSite) site).getActionBars();
+ if (site instanceof IViewSite)
+ return ((IViewSite) site).getActionBars();
+ return null;
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ updateAllItemLabels();
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ConstantsHacker.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ConstantsHacker.java
index fa22baef4..a09afd83b 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ConstantsHacker.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ConstantsHacker.java
@@ -1,18 +1,18 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.internal.InternalPolicy;
-
-@SuppressWarnings("restriction")
-public class ConstantsHacker {
-
- private ConstantsHacker() {
- }
-
- public static void hack() {
- org.eclipse.ui.internal.WorkbenchMessages.WizardHandler_menuLabel = WorkbenchMessages.ConstantsHacker_WizardHandler_menuLabel;
-
- // Enable loading ***@2x.png by URLImageDescriptor
- InternalPolicy.DEBUG_LOAD_URL_IMAGE_DESCRIPTOR_2x = true;
- }
-
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.internal.InternalPolicy;
+
+@SuppressWarnings("restriction")
+public class ConstantsHacker {
+
+ private ConstantsHacker() {
+ }
+
+ public static void hack() {
+ org.eclipse.ui.internal.WorkbenchMessages.WizardHandler_menuLabel = WorkbenchMessages.ConstantsHacker_WizardHandler_menuLabel;
+
+ // Enable loading ***@2x.png by URLImageDescriptor
+ InternalPolicy.DEBUG_LOAD_URL_IMAGE_DESCRIPTOR_2x = true;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/EditorStatePersistance.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/EditorStatePersistance.java
index 6d0321f23..4378bf737 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/EditorStatePersistance.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/EditorStatePersistance.java
@@ -1,308 +1,310 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2016 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-/**
- *
- */
-package org.xmind.cathy.internal;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchListener;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.WorkbenchException;
-import org.eclipse.ui.XMLMemento;
-import org.eclipse.ui.dialogs.ListSelectionDialog;
-import org.eclipse.ui.internal.IWorkbenchConstants;
-import org.xmind.ui.util.Cancelable;
-import org.xmind.ui.util.ICancelable;
-
-/**
- * @author Frank Shaka
- *
- */
-public class EditorStatePersistance {
-
- private static final String PATH_SESSION = "editorstates.xml"; //$NON-NLS-1$
-
- private class EditorStateLabelProvider extends LabelProvider {
-
- private LocalResourceManager resources;
-
- /**
- *
- */
- public EditorStateLabelProvider() {
- this.resources = new LocalResourceManager(
- JFaceResources.getResources());
- }
-
- public String getText(Object element) {
- if (element instanceof IMemento) {
- IMemento state = (IMemento) element;
- String name = state.getString(IWorkbenchConstants.TAG_TITLE);
- if (name == null) {
- name = state.getString(IWorkbenchConstants.TAG_NAME);
- }
- if (name == null) {
- name = state.getString(IWorkbenchConstants.TAG_PART_NAME);
- }
- if (name == null) {
- String editorId = state
- .getString(IWorkbenchConstants.TAG_ID);
- if (editorId != null) {
- IEditorDescriptor editor = workbench.getEditorRegistry()
- .findEditor(editorId);
- if (editor != null) {
- name = editor.getLabel();
- }
- }
- }
- if (name == null) {
- name = ""; //$NON-NLS-1$
- }
- return name;
- }
- return super.getText(element);
- }
-
- public Image getImage(Object element) {
- if (element instanceof IMemento) {
- IMemento state = (IMemento) element;
- String editorId = state.getString(IWorkbenchConstants.TAG_ID);
- if (editorId != null) {
- IEditorDescriptor editor = workbench.getEditorRegistry()
- .findEditor(editorId);
- if (editor != null) {
- ImageDescriptor icon = editor.getImageDescriptor();
- if (icon != null)
- return (Image) resources.get(icon);
- }
- }
- }
- return super.getImage(element);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
- */
- @Override
- public void dispose() {
- resources.dispose();
- super.dispose();
- }
-
- }
-
- private final IWorkbench workbench;
- private final IPath basePath;
- private final ILogger logger;
- private final int autoSaveIntervals;
- private ICancelable autoSaveTask;
-
- /**
- *
- */
- public EditorStatePersistance(IWorkbench workbench, IPath basePath,
- ILogger logger, int autoSaveIntervals) {
- this.workbench = workbench;
- this.basePath = basePath;
- this.logger = logger == null ? ILogger.DEFAULT : logger;
- this.autoSaveIntervals = autoSaveIntervals;
- this.autoSaveTask = null;
- }
-
- /**
- * Must be called within the UI thread.
- *
- * @throws WorkbenchException
- */
- public void startUp() throws WorkbenchException {
- final Display display = workbench.getDisplay();
- Assert.isNotNull(display);
- Assert.isTrue(display == Display.getCurrent());
-
- try {
- recoverLastSession();
- } finally {
- schedule(display);
- workbench.addWorkbenchListener(new IWorkbenchListener() {
- public boolean preShutdown(IWorkbench workbench,
- boolean forced) {
- return true;
- }
-
- public void postShutdown(IWorkbench workbench) {
- shutDown();
- }
- });
- }
- }
-
- /**
- * @return
- */
- private File getSessionFile() {
- return basePath.append(PATH_SESSION).toFile();
- }
-
- /**
- * @throws WorkbenchException
- */
- private void recoverLastSession() throws WorkbenchException {
- File sessionFile = getSessionFile();
- if (sessionFile == null || !sessionFile.exists())
- return;
-
- XMLMemento root;
- try {
- Reader reader = new BufferedReader(new FileReader(sessionFile));
- root = XMLMemento.createReadRoot(reader);
- } catch (IOException e) {
- logger.logError(null, e);
- return;
- } finally {
- sessionFile.delete();
- }
-
- IMemento[] states = root.getChildren(IWorkbenchConstants.TAG_EDITOR);
- if (states.length == 0)
- return;
-
- ListSelectionDialog dialog = new ListSelectionDialog(null, states,
- new ArrayContentProvider(), new EditorStateLabelProvider(),
- WorkbenchMessages.appWindow_ListSelectionDialog_Text);
- dialog.setTitle(WorkbenchMessages.appWindow_ListSelectionDialog_Title);
- dialog.setInitialSelections(states);
- int ret = dialog.open();
- if (ret == ListSelectionDialog.CANCEL)
- return;
-
- Object[] result = dialog.getResult();
- if (result == null)
- return;
-
- states = new IMemento[result.length];
- System.arraycopy(result, 0, states, 0, result.length);
-
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- if (window == null) {
- window = workbench.openWorkbenchWindow(null);
- }
- IWorkbenchPage page = window.getActivePage();
- if (page == null) {
- page = window.openPage(null);
- }
- page.openEditors(null, null, states, 0, 0);
- }
-
- public void shutDown() {
- ICancelable task = this.autoSaveTask;
- this.autoSaveTask = null;
- if (task != null) {
- task.cancel();
- }
-
- File sessionFile = getSessionFile();
- if (sessionFile != null) {
- sessionFile.delete();
- }
- }
-
- private void schedule(final Display display) {
- ICancelable oldTask = this.autoSaveTask;
- ICancelable task = new Cancelable() {
- @Override
- protected void doJob() {
- autoSave(display);
- }
- };
- this.autoSaveTask = task;
- display.timerExec(autoSaveIntervals, task);
- if (oldTask != null) {
- oldTask.cancel();
- }
- }
-
- private void autoSave(final Display display) {
- try {
- save();
- } catch (Throwable e) {
- logger.logError(null, e);
- }
-
- schedule(display);
- }
-
- /**
- *
- */
- private void save() throws IOException {
- File sessionFile = getSessionFile();
- if (sessionFile == null)
- return;
-
- List states = new ArrayList();
- for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
- IWorkbenchPage page = window.getActivePage();
- if (page == null)
- continue;
- IMemento[] editorState = page
- .getEditorState(page.getEditorReferences(), true);
- states.addAll(Arrays.asList(editorState));
- }
-
- XMLMemento root = XMLMemento
- .createWriteRoot(IWorkbenchConstants.TAG_EDITORS);
- for (IMemento state : states) {
- IMemento st = root.createChild(state.getType());
- st.putMemento(state);
- }
-
- File dir = sessionFile.getParentFile();
- if (dir != null && !dir.exists()) {
- dir.mkdirs();
- }
- BufferedWriter writer = new BufferedWriter(new FileWriter(sessionFile));
- try {
- root.save(writer);
- } finally {
- writer.close();
- }
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2016 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+/**
+ *
+ */
+package org.xmind.cathy.internal;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchListener;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.ui.internal.IWorkbenchConstants;
+import org.xmind.ui.util.Cancelable;
+import org.xmind.ui.util.ICancelable;
+
+/**
+ * @author Frank Shaka
+ */
+public class EditorStatePersistance {
+
+ private static final String PATH_SESSION = "editorstates.xml"; //$NON-NLS-1$
+
+ private class EditorStateLabelProvider extends LabelProvider {
+
+ private LocalResourceManager resources;
+
+ /**
+ *
+ */
+ public EditorStateLabelProvider() {
+ this.resources = new LocalResourceManager(
+ JFaceResources.getResources());
+ }
+
+ public String getText(Object element) {
+ if (element instanceof IMemento) {
+ IMemento state = (IMemento) element;
+ String name = state.getString(IWorkbenchConstants.TAG_TITLE);
+ if (name == null) {
+ name = state.getString(IWorkbenchConstants.TAG_NAME);
+ }
+ if (name == null) {
+ name = state.getString(IWorkbenchConstants.TAG_PART_NAME);
+ }
+ if (name == null) {
+ String editorId = state
+ .getString(IWorkbenchConstants.TAG_ID);
+ if (editorId != null) {
+ IEditorDescriptor editor = workbench.getEditorRegistry()
+ .findEditor(editorId);
+ if (editor != null) {
+ name = editor.getLabel();
+ }
+ }
+ }
+ if (name == null) {
+ name = ""; //$NON-NLS-1$
+ }
+ return name;
+ }
+ return super.getText(element);
+ }
+
+ public Image getImage(Object element) {
+ if (element instanceof IMemento) {
+ IMemento state = (IMemento) element;
+ String editorId = state.getString(IWorkbenchConstants.TAG_ID);
+ if (editorId != null) {
+ IEditorDescriptor editor = workbench.getEditorRegistry()
+ .findEditor(editorId);
+ if (editor != null) {
+ ImageDescriptor icon = editor.getImageDescriptor();
+ if (icon != null)
+ return (Image) resources.get(icon);
+ }
+ }
+ }
+ return super.getImage(element);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+ resources.dispose();
+ super.dispose();
+ }
+
+ }
+
+ private final IWorkbench workbench;
+ private final IPath basePath;
+ private final ILogger logger;
+ private final int autoSaveIntervals;
+ private ICancelable autoSaveTask;
+
+ /**
+ *
+ */
+ public EditorStatePersistance(IWorkbench workbench, IPath basePath,
+ ILogger logger, int autoSaveIntervals) {
+ this.workbench = workbench;
+ this.basePath = basePath;
+ this.logger = logger == null ? ILogger.DEFAULT : logger;
+ this.autoSaveIntervals = autoSaveIntervals;
+ this.autoSaveTask = null;
+ }
+
+ /**
+ * Must be called within the UI thread.
+ *
+ * @throws WorkbenchException
+ */
+ public void startUp() throws WorkbenchException {
+ final Display display = workbench.getDisplay();
+ Assert.isNotNull(display);
+ Assert.isTrue(display == Display.getCurrent());
+
+ try {
+ recoverLastSession();
+ } finally {
+ schedule(display);
+ workbench.addWorkbenchListener(new IWorkbenchListener() {
+ public boolean preShutdown(IWorkbench workbench,
+ boolean forced) {
+ return true;
+ }
+
+ public void postShutdown(IWorkbench workbench) {
+ shutDown();
+ }
+ });
+ }
+ }
+
+ /**
+ * @return
+ */
+ private File getSessionFile() {
+ return basePath.append(PATH_SESSION).toFile();
+ }
+
+ /**
+ * @throws WorkbenchException
+ */
+ private void recoverLastSession() throws WorkbenchException {
+ File sessionFile = getSessionFile();
+ if (sessionFile == null || !sessionFile.exists())
+ return;
+
+ XMLMemento root;
+ try {
+ Reader reader = new BufferedReader(new FileReader(sessionFile));
+ root = XMLMemento.createReadRoot(reader);
+ } catch (IOException e) {
+ logger.logError(null, e);
+ return;
+ } finally {
+ sessionFile.delete();
+ }
+
+ IMemento[] states = root.getChildren(IWorkbenchConstants.TAG_EDITOR);
+ if (states.length == 0)
+ return;
+
+ ListSelectionDialog dialog = new ListSelectionDialog(null, states,
+ new ArrayContentProvider(), new EditorStateLabelProvider(),
+ WorkbenchMessages.appWindow_ListSelectionDialog_Text);
+ dialog.setTitle(WorkbenchMessages.appWindow_ListSelectionDialog_Title);
+ dialog.setInitialSelections(states);
+ int ret = dialog.open();
+ if (ret == ListSelectionDialog.CANCEL)
+ return;
+
+ Object[] result = dialog.getResult();
+ if (result == null || result.length == 0)
+ return;
+
+ states = new IMemento[result.length];
+ System.arraycopy(result, 0, states, 0, result.length);
+
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window == null) {
+ window = workbench.openWorkbenchWindow(null);
+ }
+ IWorkbenchPage page = window.getActivePage();
+ if (page == null) {
+ page = window.openPage(null);
+ }
+ page.openEditors(null, null, states, 0, 0);
+ }
+
+ public void shutDown() {
+ ICancelable task = this.autoSaveTask;
+ this.autoSaveTask = null;
+ if (task != null) {
+ task.cancel();
+ }
+
+ File sessionFile = getSessionFile();
+ if (sessionFile != null) {
+ sessionFile.delete();
+ }
+ }
+
+ private void schedule(final Display display) {
+ ICancelable oldTask = this.autoSaveTask;
+ ICancelable task = new Cancelable() {
+ @Override
+ protected void doJob() {
+ autoSave(display);
+ }
+ };
+ this.autoSaveTask = task;
+ display.timerExec(autoSaveIntervals, task);
+ if (oldTask != null) {
+ oldTask.cancel();
+ }
+ }
+
+ private void autoSave(final Display display) {
+ try {
+ save();
+ } catch (Throwable e) {
+ logger.logError(null, e);
+ }
+
+ schedule(display);
+ }
+
+ /**
+ *
+ */
+ private void save() throws IOException {
+ File sessionFile = getSessionFile();
+ if (sessionFile == null)
+ return;
+
+ List states = new ArrayList();
+ for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
+ IWorkbenchPage page = window.getActivePage();
+ if (page == null)
+ continue;
+ IMemento[] editorState = page
+ .getEditorState(page.getEditorReferences(), true);
+ states.addAll(Arrays.asList(editorState));
+ }
+
+ XMLMemento root = XMLMemento
+ .createWriteRoot(IWorkbenchConstants.TAG_EDITORS);
+ if (root == null) {
+ return;
+ }
+
+ for (IMemento state : states) {
+ IMemento st = root.createChild(state.getType());
+ st.putMemento(state);
+ }
+
+ File dir = sessionFile.getParentFile();
+ if (dir != null && !dir.exists()) {
+ dir.mkdirs();
+ }
+ BufferedWriter writer = new BufferedWriter(new FileWriter(sessionFile));
+ try {
+ root.save(writer);
+ } finally {
+ writer.close();
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/EmptyHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/EmptyHandler.java
new file mode 100644
index 000000000..6a5da698a
--- /dev/null
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/EmptyHandler.java
@@ -0,0 +1,14 @@
+package org.xmind.cathy.internal;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+public class EmptyHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/GeneralPrefPage.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/GeneralPrefPage.java
index a6b66802e..b729936e6 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/GeneralPrefPage.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/GeneralPrefPage.java
@@ -1,617 +1,619 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.preference.BooleanFieldEditor;
-import org.eclipse.jface.preference.FieldEditor;
-import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.IntegerFieldEditor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.program.Program;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.eclipse.ui.forms.events.HyperlinkAdapter;
-import org.eclipse.ui.forms.events.HyperlinkEvent;
-import org.eclipse.ui.forms.widgets.Hyperlink;
-import org.eclipse.ui.internal.IPreferenceConstants;
-import org.eclipse.ui.internal.WorkbenchPlugin;
-import org.xmind.core.usagedata.IUsageDataSampler;
-import org.xmind.core.usagedata.IUsageDataUploader;
-import org.xmind.ui.internal.MindMapUIPlugin;
-import org.xmind.ui.prefs.PrefConstants;
-import org.xmind.ui.resources.ColorUtils;
-import org.xmind.ui.util.NumberUtils;
-
-public class GeneralPrefPage extends FieldEditorPreferencePage
- implements IWorkbenchPreferencePage, Listener {
-
-// private static class SoftCheckFileFieldEditor
-// extends StringButtonFieldEditor {
-//
-// private String[] extensions = null;
-//
-// private String[] extensionNames = null;
-//
-// public SoftCheckFileFieldEditor(String name, String labelText,
-// Composite parent) {
-// init(name, labelText);
-// setChangeButtonText(JFaceResources.getString("openBrowse"));//$NON-NLS-1$
-// createControl(parent);
-// }
-//
-// @Override
-// public void setEmptyStringAllowed(boolean b) {
-// super.setEmptyStringAllowed(b);
-// refreshValidState();
-// }
-//
-// @Override
-// protected boolean checkState() {
-// Text text = getTextControl();
-// if (text == null)
-// return false;
-// boolean validFile;
-// String path = text.getText();
-// if ("".equals(path)) { //$NON-NLS-1$
-// validFile = isEmptyStringAllowed();
-// } else {
-// validFile = new File(path).isFile();
-// }
-// if (validFile) {
-// getPage().setMessage(null);
-// } else {
-// getPage().setMessage(getErrorMessage(),
-// IMessageProvider.WARNING);
-// }
-// return validFile;
-// }
-//
-// @Override
-// protected String changePressed() {
-// File f = new File(getTextControl().getText());
-// if (!f.exists()) {
-// f = null;
-// }
-// File d = getFile(f);
-// if (d == null) {
-// return null;
-// }
-// return d.getAbsolutePath();
-// }
-//
-// /**
-// * Helper to open the file chooser dialog.
-// *
-// * @param startingDirectory
-// * the directory to open the dialog on.
-// * @return File The File the user selected or null if they
-// * do not.
-// */
-// private File getFile(File startingDirectory) {
-// FileDialog dialog = new FileDialog(getShell(),
-// SWT.OPEN | SWT.SHEET);
-// if (extensions != null) {
-// dialog.setFilterExtensions(extensions);
-// if (extensionNames != null) {
-// dialog.setFilterNames(extensionNames);
-// }
-// }
-// if (startingDirectory != null) {
-// dialog.setFileName(startingDirectory.getPath());
-// }
-// String file = dialog.open();
-// if (file != null) {
-// file = file.trim();
-// if (file.length() > 0) {
-// return new File(file);
-// }
-// }
-//
-// return null;
-// }
-//
-// public void setExtensions(String[] extensions) {
-// this.extensions = extensions;
-// }
-//
-// public void setExtensionNames(String[] extensionNames) {
-// this.extensionNames = extensionNames;
-// }
-//
-// }
-
-// private IntegerFieldEditor autoSaveIntervalsField;
-//
-// private Composite autoSaveIntervalsParent;
-
- private Text autoSaveIntervalsInput;
-
- private boolean autoBackup = true;
-
- private BooleanFieldEditor autoBackupField;
-
- private IntegerFieldEditor recentFilesField;
-
-// private Combo startupActionCombo;
-//
-// private SoftCheckFileFieldEditor homeMapField;
-//
-// private Control homeMapControl;
-
- private Control recentFilesControl;
-
- private Button startupActionButton;
-
- private ResourceManager resources;
-
- public GeneralPrefPage() {
- super(WorkbenchMessages.GeneralPrefPage_title, FLAT);
- }
-
- @Override
- public void applyData(Object data) {
- if (IPreferenceConstants.RECENT_FILES.equals(data)) {
- if (recentFilesControl != null
- && !recentFilesControl.isDisposed()) {
- recentFilesControl.setFocus();
- highlight(recentFilesControl.getParent());
- }
- }
- }
-
- private void highlight(final Control control) {
- final Display display = control.getDisplay();
- final Color oldBackground = control.getBackground();
- final Color c1 = oldBackground == null
- ? display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)
- : oldBackground;
- final int r1 = c1.getRed(), g1 = c1.getGreen(), b1 = c1.getBlue();
- final int r0 = 255, g0 = 240, b0 = 180;
- final int total = 30;
- final int[] step = new int[] { 0 };
- final Color[] c = new Color[1];
- display.timerExec(500, new Runnable() {
- public void run() {
- if (control.isDisposed())
- return;
- c[0] = new Color(display, r0, g0, b0);
- control.setBackground(c[0]);
- display.timerExec(20, new Runnable() {
- public void run() {
- c[0].dispose();
-
- if (control.isDisposed())
- return;
-
- ++step[0];
- if (step[0] > total) {
- control.setBackground(null);
- return;
- }
-
- int x = step[0], y = total - step[0];
- int r = (r0 * y + r1 * x) / total;
- int g = (g0 * y + g1 * x) / total;
- int b = (b0 * y + b1 * x) / total;
- c[0] = new Color(display, r, g, b);
- control.setBackground(c[0]);
- display.timerExec(20, this);
- }
- });
- }
- });
- }
-
- protected IPreferenceStore doGetPreferenceStore() {
- return CathyPlugin.getDefault().getPreferenceStore();
- }
-
- @Override
- public void createControl(Composite parent) {
- resources = new LocalResourceManager(JFaceResources.getResources(),
- parent);
- super.createControl(parent);
- }
-
- protected Control createContents(Composite parent) {
- Composite composite = (Composite) super.createContents(parent);
- ((GridLayout) composite.getLayout()).verticalSpacing = 15;
- return composite;
- }
-
- protected void createFieldEditors() {
- addStartupGroup();
- addRecentFileCountField();
- addAutoSaveGroup();
- addAutoBackupGroup();
- //addRememberLastSessionField();
- //addCheckUpdatesField();
- addSendUsageDataGroup();
- }
-
- private void addStartupGroup() {
- Composite parent = createGroup(WorkbenchMessages.Startup_title);
- addStartupActionField(parent);
- addCheckUpdatesField(parent);
- }
-
- private void addStartupActionField(Composite parent) {
- startupActionButton = new Button(parent, SWT.CHECK);
- startupActionButton.setText(WorkbenchMessages.RestoreLastSession_label);
-// addField(new BooleanFieldEditor(CathyPlugin.RESTORE_LAST_SESSION,
-// WorkbenchMessages.StartupAction_LastSession,
-// createFieldContainer(parent, false)));
-// Composite line = new Composite(parent, SWT.NONE);
-// line.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-// GridLayout layout = new GridLayout(2, false);
-// layout.marginHeight = 0;
-// layout.marginWidth = 0;
-// line.setLayout(layout);
-// fillStartupActionFields(line);
- }
-
-// private void fillStartupActionFields(Composite parent) {
-// Label label = new Label(parent, SWT.NONE);
-// label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
-// label.setText(WorkbenchMessages.StartupAction_label);
-//
-// startupActionCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
-// startupActionCombo
-// .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-// startupActionCombo.add(WorkbenchMessages.StartupAction_OpenDialog);
-// startupActionCombo.add(WorkbenchMessages.StartupAction_BlankMap);
-// startupActionCombo.add(WorkbenchMessages.StartupAction_HomeMap);
-// startupActionCombo.add(WorkbenchMessages.StartupAction_LastSession);
-// startupActionCombo.addListener(SWT.Selection, this);
-// }
-
-// private void addHomeMapField(Composite parent) {
-// Composite line = new Composite(parent, SWT.NONE);
-// line.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-// GridLayout layout = new GridLayout(2, false);
-// layout.marginHeight = 0;
-// layout.marginWidth = 0;
-// line.setLayout(layout);
-// fillHomeMapFields(line);
-// }
-
-// private void fillHomeMapFields(Composite parent) {
-// Composite container = createFieldContainer(parent, true);
-// addField(homeMapField = new SoftCheckFileFieldEditor(
-// PrefConstants.HOME_MAP_LOCATION,
-// WorkbenchMessages.HomeMap_label, container));
-// homeMapControl = homeMapField.getTextControl(container);
-// homeMapField.setErrorMessage(WorkbenchMessages.HomeMap_NotFound_error);
-// String xmindExt = "*" + MindMapUI.FILE_EXT_XMIND; //$NON-NLS-1$
-// homeMapField.setExtensions(new String[] { xmindExt });
-// homeMapField.setExtensionNames(new String[] { NLS.bind("{0} ({1})", //$NON-NLS-1$
-// DialogMessages.WorkbookFilterName, xmindExt) });
-// }
-
- private void addCheckUpdatesField(Composite parent) {
- addField(new BooleanFieldEditor(CathyPlugin.CHECK_UPDATES_ON_STARTUP,
- WorkbenchMessages.CheckUpdates_label,
- createFieldContainer(parent, true)));
- }
-
- private void addRecentFileCountField() {
- Composite container = getFieldEditorParent();
- addField(recentFilesField = new IntegerFieldEditor(
- IPreferenceConstants.RECENT_FILES,
- WorkbenchMessages.RecentFiles_label, container));
- recentFilesControl = recentFilesField.getTextControl(container);
- }
-
-// private void addRememberLastSessionField() {
-// addField(new BooleanFieldEditor(CathyPlugin.RESTORE_LAST_SESSION,
-// WorkbenchMessages.RestoreLastSession_label,
-// getFieldEditorParent()));
-// }
-//
-// private void addCheckUpdatesField() {
-// addField(new BooleanFieldEditor(CathyPlugin.CHECK_UPDATES_ON_STARTUP,
-// WorkbenchMessages.CheckUpdates_label, getFieldEditorParent()));
-// }
-
- private void addAutoSaveGroup() {
- String message = WorkbenchMessages.AutoSave_label2;
- int index = message.indexOf("{0}"); //$NON-NLS-1$
- int cols = 3;
- String label1, label2;
- if (index >= 0) {
- label1 = message.substring(0, index);
- label2 = message.substring(index + 3);
- if ("".equals(label2)) { //$NON-NLS-1$
- label2 = null;
- cols--;
- }
- } else {
- label1 = message;
- label2 = null;
- cols--;
- if ("".equals(label1)) {//$NON-NLS-1$
- label1 = null;
- cols--;
- }
- }
-
- Composite parent = getFieldEditorParent();
- GridLayout gridLayout = new GridLayout(cols, false);
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.horizontalSpacing = 0;
- parent.setLayout(gridLayout);
-// parent.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
-// ((GridData) composite.getLayoutData()).horizontalIndent = 10;
-
- Composite booleanParent = new Composite(parent, SWT.NONE);
- booleanParent
- .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
- addField(new BooleanFieldEditor(CathyPlugin.AUTO_SAVE_ENABLED, label1,
- booleanParent));
-
- autoSaveIntervalsInput = new Text(parent,
- SWT.SINGLE | SWT.BORDER | SWT.CENTER);
- autoSaveIntervalsInput
- .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
- ((GridData) autoSaveIntervalsInput.getLayoutData()).widthHint = 40;
- autoSaveIntervalsInput.setEnabled(
- getPreferenceStore().getBoolean(CathyPlugin.AUTO_SAVE_ENABLED));
-
- if (label2 != null) {
- Label label = new Label(parent, SWT.NONE);
- label.setText(label2);
- label.setLayoutData(
- new GridData(SWT.FILL, SWT.CENTER, false, true));
- }
- }
-
-// private void addAutoSaveGroup() {
-// Composite parent = getFieldEditorParent();
-// GridLayout gridLayout = new GridLayout(2, false);
-// gridLayout.marginWidth = 0;
-// gridLayout.marginHeight = 0;
-// gridLayout.verticalSpacing = 0;
-// gridLayout.horizontalSpacing = 0;
-// parent.setLayout(gridLayout);
-//
-//// PreferenceLinkArea link = new PreferenceLinkArea(parent,
-//// SWT.NONE,
-//// "org.xmind.ui.BackupPrefPage", //$NON-NLS-1$
-//// "See ''{0}'' for auto saving and backup options.",
-//// (IWorkbenchPreferenceContainer) getContainer(), null);
-//// link.getControl().setLayoutData(
-//// new GridData(SWT.FILL, SWT.FILL, true, false));
-//
-//
-// addField(new BooleanFieldEditor(CathyPlugin.AUTO_SAVE_ENABLED,
-// WorkbenchMessages.AutoSave_label, createFieldContainer(parent,
-// false)));
-//
-// autoSaveIntervalsParent = createFieldContainer(parent, true);
-//
-// addField(autoSaveIntervalsField = new IntegerFieldEditor(
-// CathyPlugin.AUTO_SAVE_INTERVALS, "", //$NON-NLS-1$
-// autoSaveIntervalsParent));
-//
-// autoSaveIntervalsField.setEnabled(
-// getPreferenceStore().getBoolean(CathyPlugin.AUTO_SAVE_ENABLED),
-// autoSaveIntervalsParent);
-//
-// Label label = new Label(parent, SWT.NONE);
-// label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
-// false));
-// label.setText(WorkbenchMessages.AutoSave_Minutes);
-//
-// }
-
- private void addAutoBackupGroup() {
- Composite parent = getFieldEditorParent();
- GridLayout gridLayout = new GridLayout(1, false);
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.horizontalSpacing = 0;
- parent.setLayout(gridLayout);
- addField(autoBackupField = new BooleanFieldEditor(
- PrefConstants.AUTO_BACKUP_ENABLE,
- WorkbenchMessages.AutoBackup_label,
- createFieldContainer(parent, true)));
- }
-
- private void addSendUsageDataGroup() {
- Composite composite = getFieldEditorParent();
- GridLayout gridLayout = new GridLayout(2, false);
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.horizontalSpacing = 5;
- composite.setLayout(gridLayout);
-
- Composite composite2 = new Composite(composite, SWT.NONE);
- composite2.setLayoutData(
- new GridData(SWT.LEFT, SWT.CENTER, false, false));
-
- GridLayout gridLayout2 = new GridLayout(1, false);
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.horizontalSpacing = 0;
- composite2.setLayout(gridLayout2);
-
- addField(new BooleanFieldEditor(
- CathyPlugin.USAGE_DATA_UPLOADING_ENABLED,
- WorkbenchMessages.GeneralPrefPage_usageData_text, composite2));
-
- //
- Hyperlink privacyHyperlink = new Hyperlink(composite, SWT.NONE);
- privacyHyperlink.setBackground(composite.getBackground());
- privacyHyperlink.setLayoutData(
- new GridData(SWT.LEFT, SWT.CENTER, false, false));
- privacyHyperlink
- .setText(WorkbenchMessages.GeneralPrefPage_seePolicy_link);
- privacyHyperlink.setUnderlined(true);
- privacyHyperlink.setForeground(
- (Color) resources.get(ColorUtils.toDescriptor("#77afe0"))); //$NON-NLS-1$
- privacyHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
- public void linkActivated(HyperlinkEvent e) {
- Program.launch("http://www.xmind.net/privacy/usage/"); //$NON-NLS-1$
- }
- });
-
- if (CathyPlugin.getDefault()
- .isDebugging("/debug/udc/showUploadButton")) { //$NON-NLS-1$
- Button uploadButton = new Button(composite, SWT.PUSH);
- GridData layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false,
- false);
- layoutData.horizontalSpan = 2;
- layoutData.horizontalIndent = 10;
- layoutData.minimumWidth = 100;
- uploadButton.setLayoutData(layoutData);
- uploadButton.setBackground(composite.getBackground());
- uploadButton.setText("Upload Now"); //$NON-NLS-1$
- uploadButton.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- IUsageDataSampler sampler = CathyPlugin.getDefault()
- .getUsageDataCollector();
- if (sampler instanceof IUsageDataUploader) {
- ((IUsageDataUploader) sampler).forceUpload();
- }
- }
- });
- }
- }
-
- private Composite createFieldContainer(Composite parent,
- boolean grabHorizontal) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, grabHorizontal, true));
- composite.setLayout(new GridLayout(1, false));
- return composite;
- }
-
- private Composite createGroup(String groupTitle) {
- Composite parent = getFieldEditorParent();
- GridLayout gridLayout = new GridLayout(1, false);
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.horizontalSpacing = 0;
- parent.setLayout(gridLayout);
-
- Group group = new Group(parent, SWT.NONE);
- group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- group.setLayout(new GridLayout(1, false));
- group.setText(groupTitle);
- return group;
- }
-
- @Override
- protected void initialize() {
- super.initialize();
- int startupAction = getPreferenceStore()
- .getInt(CathyPlugin.STARTUP_ACTION);
- startupActionButton
- .setSelection(startupAction == CathyPlugin.STARTUP_ACTION_LAST);
-// startupActionCombo.select(startupAction);
-
-// homeMapField.setPreferenceStore(
-// MindMapUIPlugin.getDefault().getPreferenceStore());
-// homeMapField.setEmptyStringAllowed(
-// startupAction != CathyPlugin.STARTUP_ACTION_HOME);
-// homeMapField.load();
-
- recentFilesField.setPreferenceStore(
- WorkbenchPlugin.getDefault().getPreferenceStore());
- recentFilesField.load();
-
- autoSaveIntervalsInput.setText(String.valueOf(
- getPreferenceStore().getInt(CathyPlugin.AUTO_SAVE_INTERVALS)));
- autoBackupField.setPreferenceStore(
- MindMapUIPlugin.getDefault().getPreferenceStore());
- autoBackupField.load();
- }
-
- public void init(IWorkbench workbench) {
- }
-
- @Override
- public boolean performOk() {
- if (!super.performOk())
- return false;
-
- if (startupActionButton.getSelection()) {
- getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
- CathyPlugin.STARTUP_ACTION_LAST);
- } else {
- getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
- CathyPlugin.STARTUP_ACTION_WIZARD);
- }
-
- int autoSaveIntervals = NumberUtils
- .safeParseInt(autoSaveIntervalsInput.getText(), 0);
- getPreferenceStore().setValue(CathyPlugin.AUTO_SAVE_INTERVALS,
- autoSaveIntervals);
- MindMapUIPlugin.getDefault().getPreferenceStore()
- .setValue(PrefConstants.AUTO_BACKUP_ENABLE, autoBackup);
- return true;
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- super.propertyChange(event);
- if (event.getSource() instanceof FieldEditor) {
- FieldEditor fe = (FieldEditor) event.getSource();
- if (event.getProperty().equals(FieldEditor.VALUE)) {
- String prefName = fe.getPreferenceName();
- if (CathyPlugin.AUTO_SAVE_ENABLED.equals(prefName)) {
- autoSaveIntervalsInput.setEnabled(
- ((Boolean) event.getNewValue()).booleanValue());
-// autoSaveIntervalsField.setEnabled(
-// (Boolean) event.getNewValue(),
-// autoSaveIntervalsParent);
- } else if (PrefConstants.AUTO_BACKUP_ENABLE.equals(prefName)) {
- autoBackup = ((Boolean) event.getNewValue()).booleanValue();
- }
- }
- }
- }
-
- public void handleEvent(Event event) {
-// if (event.widget == startupActionCombo) {
-// int startupAction = startupActionCombo.getSelectionIndex();
-// homeMapField.setEmptyStringAllowed(
-// startupAction != CathyPlugin.STARTUP_ACTION_HOME);
-// checkState();
-// }
- }
-}
\ No newline at end of file
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.IntegerFieldEditor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.program.Program;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.widgets.Hyperlink;
+import org.eclipse.ui.internal.IPreferenceConstants;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.xmind.core.net.util.LinkUtils;
+import org.xmind.core.usagedata.IUsageDataSampler;
+import org.xmind.core.usagedata.IUsageDataUploader;
+import org.xmind.ui.internal.MindMapUIPlugin;
+import org.xmind.ui.prefs.PrefConstants;
+import org.xmind.ui.resources.ColorUtils;
+import org.xmind.ui.util.NumberUtils;
+
+public class GeneralPrefPage extends FieldEditorPreferencePage
+ implements IWorkbenchPreferencePage, Listener {
+
+// private static class SoftCheckFileFieldEditor
+// extends StringButtonFieldEditor {
+//
+// private String[] extensions = null;
+//
+// private String[] extensionNames = null;
+//
+// public SoftCheckFileFieldEditor(String name, String labelText,
+// Composite parent) {
+// init(name, labelText);
+// setChangeButtonText(JFaceResources.getString("openBrowse"));//$NON-NLS-1$
+// createControl(parent);
+// }
+//
+// @Override
+// public void setEmptyStringAllowed(boolean b) {
+// super.setEmptyStringAllowed(b);
+// refreshValidState();
+// }
+//
+// @Override
+// protected boolean checkState() {
+// Text text = getTextControl();
+// if (text == null)
+// return false;
+// boolean validFile;
+// String path = text.getText();
+// if ("".equals(path)) { //$NON-NLS-1$
+// validFile = isEmptyStringAllowed();
+// } else {
+// validFile = new File(path).isFile();
+// }
+// if (validFile) {
+// getPage().setMessage(null);
+// } else {
+// getPage().setMessage(getErrorMessage(),
+// IMessageProvider.WARNING);
+// }
+// return validFile;
+// }
+//
+// @Override
+// protected String changePressed() {
+// File f = new File(getTextControl().getText());
+// if (!f.exists()) {
+// f = null;
+// }
+// File d = getFile(f);
+// if (d == null) {
+// return null;
+// }
+// return d.getAbsolutePath();
+// }
+//
+// /**
+// * Helper to open the file chooser dialog.
+// *
+// * @param startingDirectory
+// * the directory to open the dialog on.
+// * @return File The File the user selected or null if they
+// * do not.
+// */
+// private File getFile(File startingDirectory) {
+// FileDialog dialog = new FileDialog(getShell(),
+// SWT.OPEN | SWT.SHEET);
+// if (extensions != null) {
+// dialog.setFilterExtensions(extensions);
+// if (extensionNames != null) {
+// dialog.setFilterNames(extensionNames);
+// }
+// }
+// if (startingDirectory != null) {
+// dialog.setFileName(startingDirectory.getPath());
+// }
+// String file = dialog.open();
+// if (file != null) {
+// file = file.trim();
+// if (file.length() > 0) {
+// return new File(file);
+// }
+// }
+//
+// return null;
+// }
+//
+// public void setExtensions(String[] extensions) {
+// this.extensions = extensions;
+// }
+//
+// public void setExtensionNames(String[] extensionNames) {
+// this.extensionNames = extensionNames;
+// }
+//
+// }
+
+// private IntegerFieldEditor autoSaveIntervalsField;
+//
+// private Composite autoSaveIntervalsParent;
+
+ private Text autoSaveIntervalsInput;
+
+ private boolean autoBackup = true;
+
+ private BooleanFieldEditor autoBackupField;
+
+ private IntegerFieldEditor recentFilesField;
+
+// private Combo startupActionCombo;
+//
+// private SoftCheckFileFieldEditor homeMapField;
+//
+// private Control homeMapControl;
+
+ private Control recentFilesControl;
+
+ private Button startupActionButton;
+
+ private ResourceManager resources;
+
+ public GeneralPrefPage() {
+ super(WorkbenchMessages.GeneralPrefPage_title, FLAT);
+ }
+
+ @Override
+ public void applyData(Object data) {
+ if (IPreferenceConstants.RECENT_FILES.equals(data)) {
+ if (recentFilesControl != null
+ && !recentFilesControl.isDisposed()) {
+ recentFilesControl.setFocus();
+ highlight(recentFilesControl.getParent());
+ }
+ }
+ }
+
+ private void highlight(final Control control) {
+ final Display display = control.getDisplay();
+ final Color oldBackground = control.getBackground();
+ final Color c1 = oldBackground == null
+ ? display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)
+ : oldBackground;
+ final int r1 = c1.getRed(), g1 = c1.getGreen(), b1 = c1.getBlue();
+ final int r0 = 255, g0 = 240, b0 = 180;
+ final int total = 30;
+ final int[] step = new int[] { 0 };
+ final Color[] c = new Color[1];
+ display.timerExec(500, new Runnable() {
+ public void run() {
+ if (control.isDisposed())
+ return;
+ c[0] = new Color(display, r0, g0, b0);
+ control.setBackground(c[0]);
+ display.timerExec(20, new Runnable() {
+ public void run() {
+ c[0].dispose();
+
+ if (control.isDisposed())
+ return;
+
+ ++step[0];
+ if (step[0] > total) {
+ control.setBackground(null);
+ return;
+ }
+
+ int x = step[0], y = total - step[0];
+ int r = (r0 * y + r1 * x) / total;
+ int g = (g0 * y + g1 * x) / total;
+ int b = (b0 * y + b1 * x) / total;
+ c[0] = new Color(display, r, g, b);
+ control.setBackground(c[0]);
+ display.timerExec(20, this);
+ }
+ });
+ }
+ });
+ }
+
+ protected IPreferenceStore doGetPreferenceStore() {
+ return CathyPlugin.getDefault().getPreferenceStore();
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ resources = new LocalResourceManager(JFaceResources.getResources(),
+ parent);
+ super.createControl(parent);
+ }
+
+ protected Control createContents(Composite parent) {
+ Composite composite = (Composite) super.createContents(parent);
+ ((GridLayout) composite.getLayout()).verticalSpacing = 15;
+ return composite;
+ }
+
+ protected void createFieldEditors() {
+ addStartupGroup();
+ addRecentFileCountField();
+ addAutoSaveGroup();
+ addAutoBackupGroup();
+ //addRememberLastSessionField();
+ //addCheckUpdatesField();
+ addSendUsageDataGroup();
+ }
+
+ private void addStartupGroup() {
+ Composite parent = createGroup(WorkbenchMessages.Startup_title);
+ addStartupActionField(parent);
+ addCheckUpdatesField(parent);
+ }
+
+ private void addStartupActionField(Composite parent) {
+ startupActionButton = new Button(parent, SWT.CHECK);
+ startupActionButton.setText(WorkbenchMessages.RestoreLastSession_label);
+// addField(new BooleanFieldEditor(CathyPlugin.RESTORE_LAST_SESSION,
+// WorkbenchMessages.StartupAction_LastSession,
+// createFieldContainer(parent, false)));
+// Composite line = new Composite(parent, SWT.NONE);
+// line.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+// GridLayout layout = new GridLayout(2, false);
+// layout.marginHeight = 0;
+// layout.marginWidth = 0;
+// line.setLayout(layout);
+// fillStartupActionFields(line);
+ }
+
+// private void fillStartupActionFields(Composite parent) {
+// Label label = new Label(parent, SWT.NONE);
+// label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
+// label.setText(WorkbenchMessages.StartupAction_label);
+//
+// startupActionCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
+// startupActionCombo
+// .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+// startupActionCombo.add(WorkbenchMessages.StartupAction_OpenDialog);
+// startupActionCombo.add(WorkbenchMessages.StartupAction_BlankMap);
+// startupActionCombo.add(WorkbenchMessages.StartupAction_HomeMap);
+// startupActionCombo.add(WorkbenchMessages.StartupAction_LastSession);
+// startupActionCombo.addListener(SWT.Selection, this);
+// }
+
+// private void addHomeMapField(Composite parent) {
+// Composite line = new Composite(parent, SWT.NONE);
+// line.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+// GridLayout layout = new GridLayout(2, false);
+// layout.marginHeight = 0;
+// layout.marginWidth = 0;
+// line.setLayout(layout);
+// fillHomeMapFields(line);
+// }
+
+// private void fillHomeMapFields(Composite parent) {
+// Composite container = createFieldContainer(parent, true);
+// addField(homeMapField = new SoftCheckFileFieldEditor(
+// PrefConstants.HOME_MAP_LOCATION,
+// WorkbenchMessages.HomeMap_label, container));
+// homeMapControl = homeMapField.getTextControl(container);
+// homeMapField.setErrorMessage(WorkbenchMessages.HomeMap_NotFound_error);
+// String xmindExt = "*" + MindMapUI.FILE_EXT_XMIND; //$NON-NLS-1$
+// homeMapField.setExtensions(new String[] { xmindExt });
+// homeMapField.setExtensionNames(new String[] { NLS.bind("{0} ({1})", //$NON-NLS-1$
+// DialogMessages.WorkbookFilterName, xmindExt) });
+// }
+
+ private void addCheckUpdatesField(Composite parent) {
+ addField(new BooleanFieldEditor(CathyPlugin.CHECK_UPDATES_ON_STARTUP,
+ WorkbenchMessages.CheckUpdates_label,
+ createFieldContainer(parent, true)));
+ }
+
+ private void addRecentFileCountField() {
+ Composite container = getFieldEditorParent();
+ addField(recentFilesField = new IntegerFieldEditor(
+ IPreferenceConstants.RECENT_FILES,
+ WorkbenchMessages.RecentFiles_label, container));
+ recentFilesControl = recentFilesField.getTextControl(container);
+ }
+
+// private void addRememberLastSessionField() {
+// addField(new BooleanFieldEditor(CathyPlugin.RESTORE_LAST_SESSION,
+// WorkbenchMessages.RestoreLastSession_label,
+// getFieldEditorParent()));
+// }
+//
+// private void addCheckUpdatesField() {
+// addField(new BooleanFieldEditor(CathyPlugin.CHECK_UPDATES_ON_STARTUP,
+// WorkbenchMessages.CheckUpdates_label, getFieldEditorParent()));
+// }
+
+ private void addAutoSaveGroup() {
+ String message = WorkbenchMessages.AutoSave_label2;
+ int index = message.indexOf("{0}"); //$NON-NLS-1$
+ int cols = 3;
+ String label1, label2;
+ if (index >= 0) {
+ label1 = message.substring(0, index);
+ label2 = message.substring(index + 3);
+ if ("".equals(label2)) { //$NON-NLS-1$
+ label2 = null;
+ cols--;
+ }
+ } else {
+ label1 = message;
+ label2 = null;
+ cols--;
+ if ("".equals(label1)) {//$NON-NLS-1$
+ label1 = null;
+ cols--;
+ }
+ }
+
+ Composite parent = getFieldEditorParent();
+ GridLayout gridLayout = new GridLayout(cols, false);
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.verticalSpacing = 0;
+ gridLayout.horizontalSpacing = 0;
+ parent.setLayout(gridLayout);
+// parent.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
+// ((GridData) composite.getLayoutData()).horizontalIndent = 10;
+
+ Composite booleanParent = new Composite(parent, SWT.NONE);
+ booleanParent
+ .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
+ addField(new BooleanFieldEditor(CathyPlugin.AUTO_SAVE_ENABLED, label1,
+ booleanParent));
+
+ autoSaveIntervalsInput = new Text(parent,
+ SWT.SINGLE | SWT.BORDER | SWT.CENTER);
+ autoSaveIntervalsInput
+ .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
+ ((GridData) autoSaveIntervalsInput.getLayoutData()).widthHint = 40;
+ autoSaveIntervalsInput.setEnabled(
+ getPreferenceStore().getBoolean(CathyPlugin.AUTO_SAVE_ENABLED));
+
+ if (label2 != null) {
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(label2);
+ label.setLayoutData(
+ new GridData(SWT.FILL, SWT.CENTER, false, true));
+ }
+ }
+
+// private void addAutoSaveGroup() {
+// Composite parent = getFieldEditorParent();
+// GridLayout gridLayout = new GridLayout(2, false);
+// gridLayout.marginWidth = 0;
+// gridLayout.marginHeight = 0;
+// gridLayout.verticalSpacing = 0;
+// gridLayout.horizontalSpacing = 0;
+// parent.setLayout(gridLayout);
+//
+//// PreferenceLinkArea link = new PreferenceLinkArea(parent,
+//// SWT.NONE,
+//// "org.xmind.ui.BackupPrefPage", //$NON-NLS-1$
+//// "See ''{0}'' for auto saving and backup options.",
+//// (IWorkbenchPreferenceContainer) getContainer(), null);
+//// link.getControl().setLayoutData(
+//// new GridData(SWT.FILL, SWT.FILL, true, false));
+//
+//
+// addField(new BooleanFieldEditor(CathyPlugin.AUTO_SAVE_ENABLED,
+// WorkbenchMessages.AutoSave_label, createFieldContainer(parent,
+// false)));
+//
+// autoSaveIntervalsParent = createFieldContainer(parent, true);
+//
+// addField(autoSaveIntervalsField = new IntegerFieldEditor(
+// CathyPlugin.AUTO_SAVE_INTERVALS, "", //$NON-NLS-1$
+// autoSaveIntervalsParent));
+//
+// autoSaveIntervalsField.setEnabled(
+// getPreferenceStore().getBoolean(CathyPlugin.AUTO_SAVE_ENABLED),
+// autoSaveIntervalsParent);
+//
+// Label label = new Label(parent, SWT.NONE);
+// label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
+// false));
+// label.setText(WorkbenchMessages.AutoSave_Minutes);
+//
+// }
+
+ private void addAutoBackupGroup() {
+ Composite parent = getFieldEditorParent();
+ GridLayout gridLayout = new GridLayout(1, false);
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.verticalSpacing = 0;
+ gridLayout.horizontalSpacing = 0;
+ parent.setLayout(gridLayout);
+ addField(autoBackupField = new BooleanFieldEditor(
+ PrefConstants.AUTO_BACKUP_ENABLE,
+ WorkbenchMessages.AutoBackup_label,
+ createFieldContainer(parent, true)));
+ }
+
+ private void addSendUsageDataGroup() {
+ Composite composite = getFieldEditorParent();
+ GridLayout gridLayout = new GridLayout(2, false);
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.verticalSpacing = 0;
+ gridLayout.horizontalSpacing = 5;
+ composite.setLayout(gridLayout);
+
+ Composite composite2 = new Composite(composite, SWT.NONE);
+ composite2.setLayoutData(
+ new GridData(SWT.LEFT, SWT.CENTER, false, false));
+
+ GridLayout gridLayout2 = new GridLayout(1, false);
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.verticalSpacing = 0;
+ gridLayout.horizontalSpacing = 0;
+ composite2.setLayout(gridLayout2);
+
+ addField(new BooleanFieldEditor(
+ CathyPlugin.USAGE_DATA_UPLOADING_ENABLED,
+ WorkbenchMessages.GeneralPrefPage_usageData_text, composite2));
+
+ //
+ Hyperlink privacyHyperlink = new Hyperlink(composite, SWT.NONE);
+ privacyHyperlink.setBackground(composite.getBackground());
+ privacyHyperlink.setLayoutData(
+ new GridData(SWT.LEFT, SWT.CENTER, false, false));
+ privacyHyperlink
+ .setText(WorkbenchMessages.GeneralPrefPage_seePolicy_link);
+ privacyHyperlink.setUnderlined(true);
+ privacyHyperlink.setForeground(
+ (Color) resources.get(ColorUtils.toDescriptor("#77afe0"))); //$NON-NLS-1$
+ privacyHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
+ public void linkActivated(HyperlinkEvent e) {
+ Program.launch(
+ LinkUtils.getLinkByLanguage(true, true, "/privacy/")); //$NON-NLS-1$
+ }
+ });
+
+ if (CathyPlugin.getDefault()
+ .isDebugging("/debug/udc/showUploadButton")) { //$NON-NLS-1$
+ Button uploadButton = new Button(composite, SWT.PUSH);
+ GridData layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false,
+ false);
+ layoutData.horizontalSpan = 2;
+ layoutData.horizontalIndent = 10;
+ layoutData.minimumWidth = 100;
+ uploadButton.setLayoutData(layoutData);
+ uploadButton.setBackground(composite.getBackground());
+ uploadButton.setText("Upload Now"); //$NON-NLS-1$
+ uploadButton.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ IUsageDataSampler sampler = CathyPlugin.getDefault()
+ .getUsageDataCollector();
+ if (sampler instanceof IUsageDataUploader) {
+ ((IUsageDataUploader) sampler).forceUpload();
+ }
+ }
+ });
+ }
+ }
+
+ private Composite createFieldContainer(Composite parent,
+ boolean grabHorizontal) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayoutData(
+ new GridData(SWT.FILL, SWT.FILL, grabHorizontal, true));
+ composite.setLayout(new GridLayout(1, false));
+ return composite;
+ }
+
+ private Composite createGroup(String groupTitle) {
+ Composite parent = getFieldEditorParent();
+ GridLayout gridLayout = new GridLayout(1, false);
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.verticalSpacing = 0;
+ gridLayout.horizontalSpacing = 0;
+ parent.setLayout(gridLayout);
+
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ group.setLayout(new GridLayout(1, false));
+ group.setText(groupTitle);
+ return group;
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ int startupAction = getPreferenceStore()
+ .getInt(CathyPlugin.STARTUP_ACTION);
+ startupActionButton
+ .setSelection(startupAction == CathyPlugin.STARTUP_ACTION_LAST);
+// startupActionCombo.select(startupAction);
+
+// homeMapField.setPreferenceStore(
+// MindMapUIPlugin.getDefault().getPreferenceStore());
+// homeMapField.setEmptyStringAllowed(
+// startupAction != CathyPlugin.STARTUP_ACTION_HOME);
+// homeMapField.load();
+
+ recentFilesField.setPreferenceStore(
+ WorkbenchPlugin.getDefault().getPreferenceStore());
+ recentFilesField.load();
+
+ autoSaveIntervalsInput.setText(String.valueOf(
+ getPreferenceStore().getInt(CathyPlugin.AUTO_SAVE_INTERVALS)));
+ autoBackupField.setPreferenceStore(
+ MindMapUIPlugin.getDefault().getPreferenceStore());
+ autoBackupField.load();
+ }
+
+ public void init(IWorkbench workbench) {
+ }
+
+ @Override
+ public boolean performOk() {
+ if (!super.performOk())
+ return false;
+
+ if (startupActionButton.getSelection()) {
+ getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
+ CathyPlugin.STARTUP_ACTION_LAST);
+ } else {
+ getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
+ CathyPlugin.STARTUP_ACTION_WIZARD);
+ }
+
+ int autoSaveIntervals = NumberUtils
+ .safeParseInt(autoSaveIntervalsInput.getText(), 0);
+ getPreferenceStore().setValue(CathyPlugin.AUTO_SAVE_INTERVALS,
+ autoSaveIntervals);
+ MindMapUIPlugin.getDefault().getPreferenceStore()
+ .setValue(PrefConstants.AUTO_BACKUP_ENABLE, autoBackup);
+ return true;
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ super.propertyChange(event);
+ if (event.getSource() instanceof FieldEditor) {
+ FieldEditor fe = (FieldEditor) event.getSource();
+ if (event.getProperty().equals(FieldEditor.VALUE)) {
+ String prefName = fe.getPreferenceName();
+ if (CathyPlugin.AUTO_SAVE_ENABLED.equals(prefName)) {
+ autoSaveIntervalsInput.setEnabled(
+ ((Boolean) event.getNewValue()).booleanValue());
+// autoSaveIntervalsField.setEnabled(
+// (Boolean) event.getNewValue(),
+// autoSaveIntervalsParent);
+ } else if (PrefConstants.AUTO_BACKUP_ENABLE.equals(prefName)) {
+ autoBackup = ((Boolean) event.getNewValue()).booleanValue();
+ }
+ }
+ }
+ }
+
+ public void handleEvent(Event event) {
+// if (event.widget == startupActionCombo) {
+// int startupAction = startupActionCombo.getSelectionIndex();
+// homeMapField.setEmptyStringAllowed(
+// startupAction != CathyPlugin.STARTUP_ACTION_HOME);
+// checkState();
+// }
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/GeneralPreferencePageSection.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/GeneralPreferencePageSection.java
index d3a69477a..b873f536c 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/GeneralPreferencePageSection.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/GeneralPreferencePageSection.java
@@ -1,218 +1,218 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.preference.BooleanFieldEditor;
-import org.eclipse.jface.preference.ComboFieldEditor;
-import org.eclipse.jface.preference.FieldEditor;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.eclipse.ui.internal.IPreferenceConstants;
-import org.xmind.ui.internal.MindMapUIPlugin;
-import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
-import org.xmind.ui.prefs.PrefConstants;
-
-public class GeneralPreferencePageSection extends
- PreferenceFieldEditorPageSection implements IWorkbenchPreferencePage {
-
- private FieldEditor autoSaveInterval;
-
- private String[][] saveIntervals = new String[][] { { "5", "5" }, //$NON-NLS-1$//$NON-NLS-2$
- { "10", "10" }, //$NON-NLS-1$//$NON-NLS-2$
- { "30", "30" }, { "60", "60" } }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
-
- private String[][] filesList = new String[][] { { "4", "4" }, { "5", "5" }, //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- { "10", "10" }, { "20", "20" }, //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- { "50", "50" } }; //$NON-NLS-1$//$NON-NLS-2$
-
- private boolean autoBackup = true;
-
- private BooleanFieldEditor autoBackupField;
-
- private Composite autoSaveIntervalsParent;
-
- private Button startupActionButton;
-
- private Composite container;
-
- public void init(IWorkbench workbench) {
- }
-
- protected IPreferenceStore doGetPreferenceStore() {
- return CathyPlugin.getDefault().getPreferenceStore();
- }
-
- @Override
- protected void createFieldEditors() {
-
- addStartupGroup(container);
- new Label(container, SWT.NONE);
-
- addRecentFileCountSection(container);
- addAutoSaveGroup(container);
-
- this.initialize();
- }
-
- private void addStartupGroup(Composite parent) {
- Label label = new Label(parent, SWT.NONE);
- label.setText(WorkbenchMessages.Startup_title);
-
- Composite container = new Composite(parent, SWT.NONE);
- GridLayoutFactory.fillDefaults().applyTo(container);
- GridData data = new GridData();
- data.horizontalIndent = 25;
- data.minimumHeight = 0;
- container.setLayoutData(data);
-
- startupActionButton = new Button(container, SWT.CHECK);
- startupActionButton.setText(WorkbenchMessages.RestoreLastSession_label);
- addField(new BooleanFieldEditor(CathyPlugin.CHECK_UPDATES_ON_STARTUP,
- WorkbenchMessages.CheckUpdates_label, container));
- }
-
- private void addRecentFileCountSection(Composite parent) {
- Label label = new Label(parent, SWT.NONE);
- label.setText(
- WorkbenchMessages.GeneralPrefPageSection_RecentFileCountSection_title);
-
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 15)
- .applyTo(composite);
-
- Composite container = new Composite(composite, SWT.NONE);
- GridData data = new GridData();
- data.horizontalIndent = 25;
- container.setLayoutData(data);
- GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
-
- addField(new ComboFieldEditor(IPreferenceConstants.RECENT_FILES,
- WorkbenchMessages.RecentFiles_label, filesList, container));
- }
-
- private void addAutoSaveGroup(Composite parent) {
- String message = WorkbenchMessages.AutoSave_label2;
- int index = message.indexOf("{0}"); //$NON-NLS-1$
- String label1, label2;
- label1 = message.substring(0, index);
- label2 = message.substring(index + 3, index + 7);
- if (null != saveIntervals) {
- for (String[] interval : saveIntervals) {
- interval[0] += " " + label2; //$NON-NLS-1$
- }
- }
-
- Label label = new Label(parent, SWT.NONE);
- label.setText(
- WorkbenchMessages.GeneralPrefPageSection_AutoSaveGroup_title);
- Composite container = new Composite(parent, SWT.NONE);
-
- GridLayoutFactory.fillDefaults().extendedMargins(23, 0, 0, 0)
- .numColumns(1).applyTo(container);
-
- Composite saveParent = createContainer(container, 2);
- Composite enableParent = createContainer(saveParent, 1);
- addField(new BooleanFieldEditor(CathyPlugin.AUTO_SAVE_ENABLED, label1,
- enableParent));
-
- autoSaveIntervalsParent = createContainer(saveParent, 1);
- autoSaveInterval = new ComboFieldEditor(CathyPlugin.AUTO_SAVE_INTERVALS,
- "", saveIntervals, autoSaveIntervalsParent); //$NON-NLS-1$
- addField(autoSaveInterval);
-
- autoSaveInterval.setEnabled(
- getPreferenceStore().getBoolean(CathyPlugin.AUTO_SAVE_ENABLED),
- autoSaveIntervalsParent);
-
- Composite boolParent = createContainer(container, 1);
- autoBackupField = new BooleanFieldEditor(
- PrefConstants.AUTO_BACKUP_ENABLE,
- WorkbenchMessages.AutoBackup_label, boolParent);
- autoBackupField.setPropertyChangeListener(this);
-
- }
-
- private Composite createContainer(Composite parent, int cols) {
- Composite container = new Composite(parent, SWT.NONE);
- GridLayoutFactory.fillDefaults().numColumns(cols).applyTo(container);
-
- return container;
- }
-
- @Override
- protected Control createContents(Composite parent) {
- if (null == container)
- this.container = parent;
- return super.createContents(parent);
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- if (event.getSource() instanceof FieldEditor) {
- FieldEditor fe = (FieldEditor) event.getSource();
- if (event.getProperty().equals(FieldEditor.VALUE)) {
- String prefName = fe.getPreferenceName();
- if (CathyPlugin.AUTO_SAVE_ENABLED.equals(prefName)) {
- autoSaveInterval.setEnabled(
- ((Boolean) event.getNewValue()).booleanValue(),
- autoSaveIntervalsParent);
- } else if (PrefConstants.AUTO_BACKUP_ENABLE.equals(prefName)) {
- autoBackup = ((Boolean) event.getNewValue()).booleanValue();
- }
- }
- }
- }
-
- @Override
- public boolean performOk() {
- if (!super.performOk())
- return false;
-
- if (startupActionButton.getSelection()) {
- getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
- CathyPlugin.STARTUP_ACTION_LAST);
- } else {
- getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
- CathyPlugin.STARTUP_ACTION_WIZARD);
- }
-
- MindMapUIPlugin.getDefault().getPreferenceStore()
- .setValue(PrefConstants.AUTO_BACKUP_ENABLE, autoBackup);
- return true;
- }
-
- @Override
- protected void initialize() {
- super.initialize();
- int startupAction = getPreferenceStore()
- .getInt(CathyPlugin.STARTUP_ACTION);
- startupActionButton
- .setSelection(startupAction == CathyPlugin.STARTUP_ACTION_LAST);
- autoBackupField.setPreferenceStore(
- MindMapUIPlugin.getDefault().getPreferenceStore());
- autoBackupField.load();
- }
-
- public void apply() {
- this.performApply();
- }
-
- public boolean ok() {
- return this.performOk();
- }
-
- public void excuteDefault() {
- this.performDefaults();
- }
-
- public boolean cancel() {
- return this.performCancel();
- }
-
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.internal.IPreferenceConstants;
+import org.xmind.ui.internal.MindMapUIPlugin;
+import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
+import org.xmind.ui.prefs.PrefConstants;
+
+public class GeneralPreferencePageSection extends
+ PreferenceFieldEditorPageSection implements IWorkbenchPreferencePage {
+
+ private FieldEditor autoSaveInterval;
+
+ private String[][] saveIntervals = new String[][] { { "5", "5" }, //$NON-NLS-1$//$NON-NLS-2$
+ { "10", "10" }, //$NON-NLS-1$//$NON-NLS-2$
+ { "30", "30" }, { "60", "60" } }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
+
+ private String[][] filesList = new String[][] { { "4", "4" }, { "5", "5" }, //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ { "10", "10" }, { "20", "20" }, //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ { "50", "50" } }; //$NON-NLS-1$//$NON-NLS-2$
+
+ private boolean autoBackup = true;
+
+ private BooleanFieldEditor autoBackupField;
+
+ private Composite autoSaveIntervalsParent;
+
+ private Button startupActionButton;
+
+ private Composite container;
+
+ public void init(IWorkbench workbench) {
+ }
+
+ protected IPreferenceStore doGetPreferenceStore() {
+ return CathyPlugin.getDefault().getPreferenceStore();
+ }
+
+ @Override
+ protected void createFieldEditors() {
+
+ addStartupGroup(container);
+ new Label(container, SWT.NONE);
+
+ addRecentFileCountSection(container);
+ addAutoSaveGroup(container);
+
+ this.initialize();
+ }
+
+ private void addStartupGroup(Composite parent) {
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(WorkbenchMessages.Startup_title);
+
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().applyTo(container);
+ GridData data = new GridData();
+ data.horizontalIndent = 25;
+ data.minimumHeight = 0;
+ container.setLayoutData(data);
+
+ startupActionButton = new Button(container, SWT.CHECK);
+ startupActionButton.setText(WorkbenchMessages.RestoreLastSession_label);
+ addField(new BooleanFieldEditor(CathyPlugin.CHECK_UPDATES_ON_STARTUP,
+ WorkbenchMessages.CheckUpdates_label, container));
+ }
+
+ private void addRecentFileCountSection(Composite parent) {
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(
+ WorkbenchMessages.GeneralPrefPageSection_RecentFileCountSection_title);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 15)
+ .applyTo(composite);
+
+ Composite container = new Composite(composite, SWT.NONE);
+ GridData data = new GridData();
+ data.horizontalIndent = 25;
+ container.setLayoutData(data);
+ GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
+
+ addField(new ComboFieldEditor(IPreferenceConstants.RECENT_FILES,
+ WorkbenchMessages.RecentFiles_label, filesList, container));
+ }
+
+ private void addAutoSaveGroup(Composite parent) {
+ String message = WorkbenchMessages.AutoSave_label2;
+ int index = message.indexOf("{0}"); //$NON-NLS-1$
+ String label1, label2;
+ label1 = message.substring(0, index);
+ label2 = message.substring(index + 3, index + 7);
+ if (null != saveIntervals) {
+ for (String[] interval : saveIntervals) {
+ interval[0] += " " + label2; //$NON-NLS-1$
+ }
+ }
+
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(
+ WorkbenchMessages.GeneralPrefPageSection_AutoSaveGroup_title);
+ Composite container = new Composite(parent, SWT.NONE);
+
+ GridLayoutFactory.fillDefaults().extendedMargins(23, 0, 0, 0)
+ .numColumns(1).applyTo(container);
+
+ Composite saveParent = createContainer(container, 2);
+ Composite enableParent = createContainer(saveParent, 1);
+ addField(new BooleanFieldEditor(CathyPlugin.AUTO_SAVE_ENABLED, label1,
+ enableParent));
+
+ autoSaveIntervalsParent = createContainer(saveParent, 1);
+ autoSaveInterval = new ComboFieldEditor(CathyPlugin.AUTO_SAVE_INTERVALS,
+ "", saveIntervals, autoSaveIntervalsParent); //$NON-NLS-1$
+ addField(autoSaveInterval);
+
+ autoSaveInterval.setEnabled(
+ getPreferenceStore().getBoolean(CathyPlugin.AUTO_SAVE_ENABLED),
+ autoSaveIntervalsParent);
+
+ Composite boolParent = createContainer(container, 1);
+ autoBackupField = new BooleanFieldEditor(
+ PrefConstants.AUTO_BACKUP_ENABLE,
+ WorkbenchMessages.AutoBackup_label, boolParent);
+ autoBackupField.setPropertyChangeListener(this);
+
+ }
+
+ private Composite createContainer(Composite parent, int cols) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().numColumns(cols).applyTo(container);
+
+ return container;
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ if (null == container)
+ this.container = parent;
+ return super.createContents(parent);
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getSource() instanceof FieldEditor) {
+ FieldEditor fe = (FieldEditor) event.getSource();
+ if (event.getProperty().equals(FieldEditor.VALUE)) {
+ String prefName = fe.getPreferenceName();
+ if (CathyPlugin.AUTO_SAVE_ENABLED.equals(prefName)) {
+ autoSaveInterval.setEnabled(
+ ((Boolean) event.getNewValue()).booleanValue(),
+ autoSaveIntervalsParent);
+ } else if (PrefConstants.AUTO_BACKUP_ENABLE.equals(prefName)) {
+ autoBackup = ((Boolean) event.getNewValue()).booleanValue();
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean performOk() {
+ if (!super.performOk())
+ return false;
+
+ if (startupActionButton.getSelection()) {
+ getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
+ CathyPlugin.STARTUP_ACTION_LAST);
+ } else {
+ getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
+ CathyPlugin.STARTUP_ACTION_WIZARD);
+ }
+
+ MindMapUIPlugin.getDefault().getPreferenceStore()
+ .setValue(PrefConstants.AUTO_BACKUP_ENABLE, autoBackup);
+ return true;
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ int startupAction = getPreferenceStore()
+ .getInt(CathyPlugin.STARTUP_ACTION);
+ startupActionButton
+ .setSelection(startupAction == CathyPlugin.STARTUP_ACTION_LAST);
+ autoBackupField.setPreferenceStore(
+ MindMapUIPlugin.getDefault().getPreferenceStore());
+ autoBackupField.load();
+ }
+
+ public void apply() {
+ this.performApply();
+ }
+
+ public boolean ok() {
+ return this.performOk();
+ }
+
+ public void excuteDefault() {
+ this.performDefaults();
+ }
+
+ public boolean cancel() {
+ return this.performCancel();
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/HandledItemMatcher.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/HandledItemMatcher.java
index 2c14c2ef7..f2fa91a17 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/HandledItemMatcher.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/HandledItemMatcher.java
@@ -1,27 +1,27 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.e4.ui.model.application.MApplicationElement;
-import org.eclipse.e4.ui.model.application.commands.MCommand;
-import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
-import org.eclipse.e4.ui.workbench.Selector;
-
-public class HandledItemMatcher implements Selector {
-
- private String commandId;
-
- public HandledItemMatcher(String commandId) {
- this.commandId = commandId;
- }
-
- public boolean select(MApplicationElement element) {
- if (!(element instanceof MHandledItem))
- return false;
-
- MHandledItem handledItem = (MHandledItem) element;
- MCommand command = handledItem.getCommand();
- if (command == null)
- return false;
-
- return this.commandId.equals(command.getElementId());
- }
+package org.xmind.cathy.internal;
+
+import org.eclipse.e4.ui.model.application.MApplicationElement;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
+import org.eclipse.e4.ui.workbench.Selector;
+
+public class HandledItemMatcher implements Selector {
+
+ private String commandId;
+
+ public HandledItemMatcher(String commandId) {
+ this.commandId = commandId;
+ }
+
+ public boolean select(MApplicationElement element) {
+ if (!(element instanceof MHandledItem))
+ return false;
+
+ MHandledItem handledItem = (MHandledItem) element;
+ MCommand command = handledItem.getCommand();
+ if (command == null)
+ return false;
+
+ return this.commandId.equals(command.getElementId());
+ }
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/IApplicationValidator.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/IApplicationValidator.java
index bb86d66c5..4a26557c1 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/IApplicationValidator.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/IApplicationValidator.java
@@ -1,20 +1,20 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-public interface IApplicationValidator {
-
- boolean shouldApplicationExitEarly();
-
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+public interface IApplicationValidator {
+
+ boolean shouldApplicationExitEarly();
+
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ICathyConstants.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ICathyConstants.java
index fc1cc5a5e..d4f7af414 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ICathyConstants.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ICathyConstants.java
@@ -1,128 +1,128 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
-
-public interface ICathyConstants {
-
- /*
- * Element Tag Names
- */
- public static final String TAG_SHOW_IMAGE = "CathyShowImage"; //$NON-NLS-1$
- public static final String TAG_SHOW_DASHBOARD = "CathyShowDashboard"; //$NON-NLS-1$
- public static final String TAG_EDITOR = "Editor"; //$NON-NLS-1$
- public static final String TAG_FORCE_TEXT = "FORCE_TEXT"; //$NON-NLS-1$
-
- public static final String TAG_TRIMBAR_LAYOUT_BEGINING = "TrimBarLayout:begining"; //$NON-NLS-1$
- public static final String TAG_TRIMBAR_LAYOUT_CENTER = "TrimBarLayout:center"; //$NON-NLS-1$
- public static final String TAG_TRIMBAR_LAYOUT_END = "TrimBarLayout:end"; //$NON-NLS-1$
-
- /*
- * Element Ids
- */
- public static final String ID_APPLICATION = "org.xmind.cathy.application"; //$NON-NLS-1$
- public static final String ID_MAIN_WINDOW = "org.xmind.cathy.window.main"; //$NON-NLS-1$
- public static final String ID_PERSPECTIVE_STACK = "org.eclipse.ui.ide.perspectivestack"; //$NON-NLS-1$
- public static final String ID_EDITOR_AREA = "org.eclipse.ui.editorss"; //$NON-NLS-1$
- public static final String ID_PRIMARY_EDITOR_STACK = "org.eclipse.e4.primaryDataStack"; //$NON-NLS-1$
- public static final String ID_MAIN_TOOLBAR = "org.eclipse.ui.main.toolbar"; //$NON-NLS-1$
- public static final String ID_STATUS_BAR = "org.eclipse.ui.trim.status"; //$NON-NLS-1$
- public static final String ID_TRIMBAR_RIGHT = "org.xmind.ui.trimbar.right"; //$NON-NLS-1$
- public static final String ID_PARTSTACK_RIGHT = "org.xmind.ui.stack.right"; //$NON-NLS-1$
- public static final String ID_DASHBOARD_PART = "org.xmind.cathy.part.dashboard"; //$NON-NLS-1$
- public static final String ID_TOOL_ITEM_TOGGLE_DASHBOARD = "org.xmind.ui.toolbar.dashboard.toggle"; //$NON-NLS-1$
-
- public static final String ID_MENU_ITEM_UNDO = "undo"; //$NON-NLS-1$
- public static final String ID_MENU_ITEM_REDO = "redo"; //$NON-NLS-1$
- public static final String ID_MENU_ITEM_SAVE = "save"; //$NON-NLS-1$
- public static final String ID_TOOL_ITEM_UNDO = "org.xmind.ui.toolbar.edit.undo"; //$NON-NLS-1$
- public static final String ID_TOOL_ITEM_REDO = "org.xmind.ui.toolbar.edit.redo"; //$NON-NLS-1$
- public static final String ID_TOOL_ITEM_SAVE = "org.xmind.ui.toolbar.edit.save"; //$NON-NLS-1$
-
- public static final String MB_XADDITIONS = "xadditions"; //$NON-NLS-1$
-
- /*
- * CSS Property Names
- */
- public static final String PROPERTY_UNSELECTED_TABS_BG_VISIBLE = "xmind-swt-unselected-tabs-bg-visible"; //$NON-NLS-1$
- public static final String PROPERTY_MAXIMIZE_IMAGE = "xmind-swt-maximize-image"; //$NON-NLS-1$
- public static final String PROPERTY_MINIMIZE_IMAGE = "xmind-swt-minimize-image"; //$NON-NLS-1$
- public static final String PROPERTY_CHEVRON_VISIBLE = "xmind-swt-chevron-visible"; //$NON-NLS-1$
- public static final String PROPERTY_CLOSE_IMAGE = "xmind-swt-close-image"; //$NON-NLS-1$
- public static final String PROPERTY_CLOSE_HOVER_IMAGE = "xmind-swt-close-hover-image"; //$NON-NLS-1$
- public static final String PROPERTY_XTEXT_BACKGROUND = "xmind-text-background"; //$NON-NLS-1$
- public static final String PROPERTY_XBOTTOM_KEYLINE_1_COLOR = "xmind-bottom-keyline-1-color"; //$NON-NLS-1$
- public static final String PROPERTY_XBOTTOM_KEYLINE_2_COLOR = "xmind-bottom-keyline-2-color"; //$NON-NLS-1$
- public static final String PROPERTY_HYPERLINK_COLOR = "xmind-hyperlink-color"; //$NON-NLS-1$
- public static final String PROPERTY_ACTIVE_HYPERLINK_COLOR = "xmind-active-hyperlink-color"; //$NON-NLS-1$
- public static final String PROPERTY_MARGIN = "xmind-margin"; //$NON-NLS-1$
- public static final String PROPERTY_MARGIN_TOP = "xmind-margin-top"; //$NON-NLS-1$
- public static final String PROPERTY_MARGIN_BOTTOM = "xmind-margin-bottom"; //$NON-NLS-1$
- public static final String PROPERTY_MARGIN_LEFT = "xmind-margin-left"; //$NON-NLS-1$
- public static final String PROPERTY_MARGIN_RIGHT = "xmind-margin-right"; //$NON-NLS-1$
- public static final String PROPERTY_MINIMIZE_VISIBLE = "xmind-swt-minimize-visible"; //$NON-NLS-1$
- public static final String PROPERTY_MAXIMIZE_VISIBLE = "xmind-swt-maximize-visible"; //$NON-NLS-1$
- public static final String PROPERTY_CTABFOLDER_RENDER_NONE = "xmind-ctabfolder-render-none"; //$NON-NLS-1$
- public static final String PROPERTY_BG_COLOR = "xmind-background-color"; //$NON-NLS-1$
- public static final String PROPERTY_FG_COLOR = "xmind-foreground-color"; //$NON-NLS-1$
- public static final String PROPERTY_TITLE_BAR_TEXT_COLOR = "xmind-title-bar-text-color"; //$NON-NLS-1$
- public static final String PROPERTY_TITLE_BAR_ACTIVE_TEXT_COLOR = "xmind-title-bar-active-text-color"; //$NON-NLS-1$
- public static final String PROPERTY_OUTER_BORDER_VISIBLE = "xmind-swt-outer-border-visible"; //$NON-NLS-1$
- public static final String PROPERTY_INNER_BORDER_VISIBLE = "xmind-swt-inner-border-visible"; //$NON-NLS-1$
- public static final String PROPERTY_IMAGE_VISIBLE = "xmind-swt-image-visible"; //$NON-NLS-1$
- public static final String PROPERTY_TEXT_VISIBLE = "xmind-swt-text-visible"; //$NON-NLS-1$
- public static final String PROPERTY_TOOL_ITEM_COLOR = "xmind-swt-tool-item-color"; //$NON-NLS-1$
- public static final String PROPERTY_VIEW_MENU = "xmind-swt-view-menu-image"; //$NON-NLS-1$
- public static final String PROPERTY_UNSELECTED_TABS_COLOR = "xmind-swt-unselected-tabs-color"; //$NON-NLS-1$
- public static final String PROPERTY_SHOW_CLOSE = "xmind-swt-show-close"; //$NON-NLS-1$
- public static final String PROPERTY_TABFOLDER_BACKGROUND = "xmind-tab-folder-bg"; //$NON-NLS-1$
- public static final String PROPERTY_TABBAR_BACKGROUND = "xmind-tab-bar-bg"; //$NON-NLS-1$
-
- /*
- * Commmand Ids
- */
- public static final String COMMAND_TOGGLE_DASHBOARD = "org.xmind.ui.command.toggleDashboard"; //$NON-NLS-1$
- public static final String COMMAND_SHOW_DASHBOARD = "org.xmind.ui.command.showDashboard"; //$NON-NLS-1$
- public static final String COMMAND_RECENTFILE_PIN = "org.xmind.ui.command.pinRecentFile"; //$NON-NLS-1$
- public static final String COMMAND_RECENTFILE_UNPIN = "org.xmind.ui.command.unpinRecentFile"; //$NON-NLS-1$
- public static final String COMMAND_RECENTFILE_CLEAR = "org.xmind.ui.command.clearRecentFile"; //$NON-NLS-1$
-
- public static final String COMMAND_TEMPLATE_DUPLICATE = "org.xmind.ui.command.template.duplicate"; //$NON-NLS-1$
- public static final String COMMAND_TEMPLATE_RENAME = "org.xmind.ui.command.template.rename"; //$NON-NLS-1$
- public static final String COMMAND_TEMPLATE_DELETE = "org.xmind.ui.command.template.delete"; //$NON-NLS-1$
-
- /*
- * Command Parameter Ids
- */
- public static final String PARAMETER_DASHBOARD_PAGE_ID = "org.xmind.ui.command.showDashboard.pageId"; //$NON-NLS-1$
-
- /*
- * Data Keys
- */
- public static final String DATA_PART_OF_WIDGET = AbstractPartRenderer.OWNING_ME;
- public static final String DATA_DASHBOARD_SELECTED_PAGE_ID = "org.xmind.ui.part.dashboard.selectedPageId"; //$NON-NLS-1$
-
- /*
- * Dashboard Pages
- */
- public static final String DASHBOARD_PAGE_NEW = "org.xmind.ui.part.dashboard.new"; //$NON-NLS-1$
- public static final String DASHBOARD_PAGE_RECENT = "org.xmind.ui.part.dashboard.recent"; //$NON-NLS-1$
-
- /*
- * Popup Menu Ids
- */
- public static final String POPUP_RECENTFILE = "org.xmind.ui.popup.recentFile"; //$NON-NLS-1$
-
- /*
- * Popup Menu Ids
- */
- public static final String POPUP_TEMPLATE = "org.xmind.ui.popup.template"; //$NON-NLS-1$
-
- /*
- * Helper Ids
- */
- public static final String HELPER_RECENTFILE_PIN = "org.xmind.ui.helper.recentFile.pin"; //$NON-NLS-1$
- public static final String HELPER_RECENTFILE_DELETE = "org.xmind.ui.helper.recentFile.delete"; //$NON-NLS-1$
- public static final String HELPER_RECENTFILE_CLEAR = "org.xmind.ui.helper.recentFile.clear"; //$NON-NLS-1$
-
- public static final String HELPER_TEMPLATE_RENAME = "org.xmind.ui.helper.template.rename"; //$NON-NLS-1$
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
+
+public interface ICathyConstants {
+
+ /*
+ * Element Tag Names
+ */
+ public static final String TAG_SHOW_IMAGE = "CathyShowImage"; //$NON-NLS-1$
+ public static final String TAG_SHOW_DASHBOARD = "CathyShowDashboard"; //$NON-NLS-1$
+ public static final String TAG_EDITOR = "Editor"; //$NON-NLS-1$
+ public static final String TAG_FORCE_TEXT = "FORCE_TEXT"; //$NON-NLS-1$
+
+ public static final String TAG_TRIMBAR_LAYOUT_BEGINING = "TrimBarLayout:begining"; //$NON-NLS-1$
+ public static final String TAG_TRIMBAR_LAYOUT_CENTER = "TrimBarLayout:center"; //$NON-NLS-1$
+ public static final String TAG_TRIMBAR_LAYOUT_END = "TrimBarLayout:end"; //$NON-NLS-1$
+
+ /*
+ * Element Ids
+ */
+ public static final String ID_APPLICATION = "org.xmind.cathy.application"; //$NON-NLS-1$
+ public static final String ID_MAIN_WINDOW = "org.xmind.cathy.window.main"; //$NON-NLS-1$
+ public static final String ID_PERSPECTIVE_STACK = "org.eclipse.ui.ide.perspectivestack"; //$NON-NLS-1$
+ public static final String ID_EDITOR_AREA = "org.eclipse.ui.editorss"; //$NON-NLS-1$
+ public static final String ID_PRIMARY_EDITOR_STACK = "org.eclipse.e4.primaryDataStack"; //$NON-NLS-1$
+ public static final String ID_MAIN_TOOLBAR = "org.eclipse.ui.main.toolbar"; //$NON-NLS-1$
+ public static final String ID_STATUS_BAR = "org.eclipse.ui.trim.status"; //$NON-NLS-1$
+ public static final String ID_TRIMBAR_RIGHT = "org.xmind.ui.trimbar.right"; //$NON-NLS-1$
+ public static final String ID_PARTSTACK_RIGHT = "org.xmind.ui.stack.right"; //$NON-NLS-1$
+ public static final String ID_DASHBOARD_PART = "org.xmind.cathy.part.dashboard"; //$NON-NLS-1$
+ public static final String ID_TOOL_ITEM_TOGGLE_DASHBOARD = "org.xmind.ui.toolbar.dashboard.toggle"; //$NON-NLS-1$
+
+ public static final String ID_MENU_ITEM_UNDO = "undo"; //$NON-NLS-1$
+ public static final String ID_MENU_ITEM_REDO = "redo"; //$NON-NLS-1$
+ public static final String ID_MENU_ITEM_SAVE = "save"; //$NON-NLS-1$
+ public static final String ID_TOOL_ITEM_UNDO = "org.xmind.ui.toolbar.edit.undo"; //$NON-NLS-1$
+ public static final String ID_TOOL_ITEM_REDO = "org.xmind.ui.toolbar.edit.redo"; //$NON-NLS-1$
+ public static final String ID_TOOL_ITEM_SAVE = "org.xmind.ui.toolbar.edit.save"; //$NON-NLS-1$
+
+ public static final String MB_XADDITIONS = "xadditions"; //$NON-NLS-1$
+
+ /*
+ * CSS Property Names
+ */
+ public static final String PROPERTY_UNSELECTED_TABS_BG_VISIBLE = "xmind-swt-unselected-tabs-bg-visible"; //$NON-NLS-1$
+ public static final String PROPERTY_MAXIMIZE_IMAGE = "xmind-swt-maximize-image"; //$NON-NLS-1$
+ public static final String PROPERTY_MINIMIZE_IMAGE = "xmind-swt-minimize-image"; //$NON-NLS-1$
+ public static final String PROPERTY_CHEVRON_VISIBLE = "xmind-swt-chevron-visible"; //$NON-NLS-1$
+ public static final String PROPERTY_CLOSE_IMAGE = "xmind-swt-close-image"; //$NON-NLS-1$
+ public static final String PROPERTY_CLOSE_HOVER_IMAGE = "xmind-swt-close-hover-image"; //$NON-NLS-1$
+ public static final String PROPERTY_XTEXT_BACKGROUND = "xmind-text-background"; //$NON-NLS-1$
+ public static final String PROPERTY_XBOTTOM_KEYLINE_1_COLOR = "xmind-bottom-keyline-1-color"; //$NON-NLS-1$
+ public static final String PROPERTY_XBOTTOM_KEYLINE_2_COLOR = "xmind-bottom-keyline-2-color"; //$NON-NLS-1$
+ public static final String PROPERTY_HYPERLINK_COLOR = "xmind-hyperlink-color"; //$NON-NLS-1$
+ public static final String PROPERTY_ACTIVE_HYPERLINK_COLOR = "xmind-active-hyperlink-color"; //$NON-NLS-1$
+ public static final String PROPERTY_MARGIN = "xmind-margin"; //$NON-NLS-1$
+ public static final String PROPERTY_MARGIN_TOP = "xmind-margin-top"; //$NON-NLS-1$
+ public static final String PROPERTY_MARGIN_BOTTOM = "xmind-margin-bottom"; //$NON-NLS-1$
+ public static final String PROPERTY_MARGIN_LEFT = "xmind-margin-left"; //$NON-NLS-1$
+ public static final String PROPERTY_MARGIN_RIGHT = "xmind-margin-right"; //$NON-NLS-1$
+ public static final String PROPERTY_MINIMIZE_VISIBLE = "xmind-swt-minimize-visible"; //$NON-NLS-1$
+ public static final String PROPERTY_MAXIMIZE_VISIBLE = "xmind-swt-maximize-visible"; //$NON-NLS-1$
+ public static final String PROPERTY_CTABFOLDER_RENDER_NONE = "xmind-ctabfolder-render-none"; //$NON-NLS-1$
+ public static final String PROPERTY_BG_COLOR = "xmind-background-color"; //$NON-NLS-1$
+ public static final String PROPERTY_FG_COLOR = "xmind-foreground-color"; //$NON-NLS-1$
+ public static final String PROPERTY_TITLE_BAR_TEXT_COLOR = "xmind-title-bar-text-color"; //$NON-NLS-1$
+ public static final String PROPERTY_TITLE_BAR_ACTIVE_TEXT_COLOR = "xmind-title-bar-active-text-color"; //$NON-NLS-1$
+ public static final String PROPERTY_OUTER_BORDER_VISIBLE = "xmind-swt-outer-border-visible"; //$NON-NLS-1$
+ public static final String PROPERTY_INNER_BORDER_VISIBLE = "xmind-swt-inner-border-visible"; //$NON-NLS-1$
+ public static final String PROPERTY_IMAGE_VISIBLE = "xmind-swt-image-visible"; //$NON-NLS-1$
+ public static final String PROPERTY_TEXT_VISIBLE = "xmind-swt-text-visible"; //$NON-NLS-1$
+ public static final String PROPERTY_TOOL_ITEM_COLOR = "xmind-swt-tool-item-color"; //$NON-NLS-1$
+ public static final String PROPERTY_VIEW_MENU = "xmind-swt-view-menu-image"; //$NON-NLS-1$
+ public static final String PROPERTY_UNSELECTED_TABS_COLOR = "xmind-swt-unselected-tabs-color"; //$NON-NLS-1$
+ public static final String PROPERTY_SHOW_CLOSE = "xmind-swt-show-close"; //$NON-NLS-1$
+ public static final String PROPERTY_TABFOLDER_BACKGROUND = "xmind-tab-folder-bg"; //$NON-NLS-1$
+ public static final String PROPERTY_TABBAR_BACKGROUND = "xmind-tab-bar-bg"; //$NON-NLS-1$
+
+ /*
+ * Commmand Ids
+ */
+ public static final String COMMAND_TOGGLE_DASHBOARD = "org.xmind.ui.command.toggleDashboard"; //$NON-NLS-1$
+ public static final String COMMAND_SHOW_DASHBOARD = "org.xmind.ui.command.showDashboard"; //$NON-NLS-1$
+ public static final String COMMAND_RECENTFILE_PIN = "org.xmind.ui.command.pinRecentFile"; //$NON-NLS-1$
+ public static final String COMMAND_RECENTFILE_UNPIN = "org.xmind.ui.command.unpinRecentFile"; //$NON-NLS-1$
+ public static final String COMMAND_RECENTFILE_CLEAR = "org.xmind.ui.command.clearRecentFile"; //$NON-NLS-1$
+
+ public static final String COMMAND_TEMPLATE_DUPLICATE = "org.xmind.ui.command.template.duplicate"; //$NON-NLS-1$
+ public static final String COMMAND_TEMPLATE_RENAME = "org.xmind.ui.command.template.rename"; //$NON-NLS-1$
+ public static final String COMMAND_TEMPLATE_DELETE = "org.xmind.ui.command.template.delete"; //$NON-NLS-1$
+
+ /*
+ * Command Parameter Ids
+ */
+ public static final String PARAMETER_DASHBOARD_PAGE_ID = "org.xmind.ui.command.showDashboard.pageId"; //$NON-NLS-1$
+
+ /*
+ * Data Keys
+ */
+ public static final String DATA_PART_OF_WIDGET = AbstractPartRenderer.OWNING_ME;
+ public static final String DATA_DASHBOARD_SELECTED_PAGE_ID = "org.xmind.ui.part.dashboard.selectedPageId"; //$NON-NLS-1$
+
+ /*
+ * Dashboard Pages
+ */
+ public static final String DASHBOARD_PAGE_NEW = "org.xmind.ui.part.dashboard.new"; //$NON-NLS-1$
+ public static final String DASHBOARD_PAGE_RECENT = "org.xmind.ui.part.dashboard.recent"; //$NON-NLS-1$
+
+ /*
+ * Popup Menu Ids
+ */
+ public static final String POPUP_RECENTFILE = "org.xmind.ui.popup.recentFile"; //$NON-NLS-1$
+
+ /*
+ * Popup Menu Ids
+ */
+ public static final String POPUP_TEMPLATE = "org.xmind.ui.popup.template"; //$NON-NLS-1$
+
+ /*
+ * Helper Ids
+ */
+ public static final String HELPER_RECENTFILE_PIN = "org.xmind.ui.helper.recentFile.pin"; //$NON-NLS-1$
+ public static final String HELPER_RECENTFILE_DELETE = "org.xmind.ui.helper.recentFile.delete"; //$NON-NLS-1$
+ public static final String HELPER_RECENTFILE_CLEAR = "org.xmind.ui.helper.recentFile.clear"; //$NON-NLS-1$
+
+ public static final String HELPER_TEMPLATE_RENAME = "org.xmind.ui.helper.template.rename"; //$NON-NLS-1$
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ILogger.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ILogger.java
index 9523af42c..49bfca1a2 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ILogger.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ILogger.java
@@ -1,62 +1,62 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2016 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-/**
- *
- */
-package org.xmind.cathy.internal;
-
-/**
- * @author Frank Shaka
- *
- */
-public interface ILogger {
-
- ILogger DEFAULT = new ILogger() {
-
- public void logError(String message, Throwable error) {
- if (message != null) {
- System.err.println(message);
- }
- if (error != null) {
- error.printStackTrace(System.err);
- }
- }
-
- public void logWarning(String message, Throwable error) {
- if (message != null) {
- System.out.println(message);
- }
- if (error != null) {
- error.printStackTrace(System.out);
- }
- }
-
- public void logInfo(String message, Throwable error) {
- if (message != null) {
- System.out.println(message);
- }
- if (error != null) {
- error.printStackTrace(System.out);
- }
- }
-
- };
-
- void logError(String message, Throwable error);
-
- void logWarning(String message, Throwable error);
-
- void logInfo(String message, Throwable error);
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2016 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+/**
+ *
+ */
+package org.xmind.cathy.internal;
+
+/**
+ * @author Frank Shaka
+ *
+ */
+public interface ILogger {
+
+ ILogger DEFAULT = new ILogger() {
+
+ public void logError(String message, Throwable error) {
+ if (message != null) {
+ System.err.println(message);
+ }
+ if (error != null) {
+ error.printStackTrace(System.err);
+ }
+ }
+
+ public void logWarning(String message, Throwable error) {
+ if (message != null) {
+ System.out.println(message);
+ }
+ if (error != null) {
+ error.printStackTrace(System.out);
+ }
+ }
+
+ public void logInfo(String message, Throwable error) {
+ if (message != null) {
+ System.out.println(message);
+ }
+ if (error != null) {
+ error.printStackTrace(System.out);
+ }
+ }
+
+ };
+
+ void logError(String message, Throwable error);
+
+ void logWarning(String message, Throwable error);
+
+ void logInfo(String message, Throwable error);
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LanguagePrefPage.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LanguagePrefPage.java
index 93fac3415..e1ce0e2bd 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LanguagePrefPage.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LanguagePrefPage.java
@@ -1,374 +1,374 @@
-package org.xmind.cathy.internal;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.ListViewer;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.eclipse.ui.PlatformUI;
-
-public class LanguagePrefPage extends FieldEditorPreferencePage implements
- IWorkbenchPreferencePage {
-
- private static final String LANGUAGE_OSGI_NL_KEY = "osgi.nl"; //$NON-NLS-1$
- private static final String LOADED_LANGUAGES_URL = "platform:/plugin/org.xmind.cathy/resource/langs.properties"; //$NON-NLS-1$
- @SuppressWarnings("nls")
- private static final String[] supportedLangsKey = { "en_US", "de", "fr",
- "zh_CN", "zh_TW", "ja", "ko", "da", "ru", "it", "sl", "ar", "es",
- "pt_BR" };
-
- private class LanguageLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- if (element instanceof String) {
- StringBuffer buffer = new StringBuffer(3);
-
- String langKey = (String) element;
- String supportLang = supportLanguageProperties
- .getProperty(langKey);
- buffer.append(supportLang);
- buffer.append(" - "); //$NON-NLS-1$
- buffer.append(supportLangsMap.get(langKey));
- return buffer.toString();
- }
- return super.getText(element);
- }
- }
-
- private static String oldLangKey = null;
-
- private Properties configIniProperties;
-
- private Properties supportLanguageProperties;
-
- private HashMap supportLangsMap;
-
- private ListViewer langsViewer;
-
- private Label changingToLangText;
-
- private Button changeButton;
-
- public LanguagePrefPage() {
- super(WorkbenchMessages.LanguagePrefPage_title, FLAT);
- configIniProperties = loadProperties(getConfigFile());
- supportLanguageProperties = loadProperties(getSupportLanguageFile());
- initSupportLanguageMap();
- if (oldLangKey == null) {
- String languageKey = configIniProperties
- .getProperty(LANGUAGE_OSGI_NL_KEY);
- oldLangKey = languageKey != null ? languageKey : System
- .getProperty(LANGUAGE_OSGI_NL_KEY);
- }
- }
-
- private void initSupportLanguageMap() {
- if (supportLangsMap != null)
- return;
- supportLangsMap = new HashMap();
- supportLangsMap.put(
- "en_US", WorkbenchMessages.SupportLanguageName_English); //$NON-NLS-1$
- supportLangsMap.put("ar", WorkbenchMessages.SupportLanguageName_Arabic); //$NON-NLS-1$
- supportLangsMap.put("da", WorkbenchMessages.SupportLanguageName_Danish); //$NON-NLS-1$
- supportLangsMap.put("de", WorkbenchMessages.SupportLanguageName_German); //$NON-NLS-1$
- supportLangsMap.put(
- "es", WorkbenchMessages.SupportLanguageName_Spanish); //$NON-NLS-1$
- supportLangsMap.put("fr", WorkbenchMessages.SupportLanguageName_French); //$NON-NLS-1$
- supportLangsMap
- .put("it", WorkbenchMessages.SupportLanguageName_Italian); //$NON-NLS-1$
- supportLangsMap.put(
- "ja", WorkbenchMessages.SupportLanguageName_Japanese); //$NON-NLS-1$
- supportLangsMap.put("ko", WorkbenchMessages.SupportLanguageName_Korean); //$NON-NLS-1$
- supportLangsMap
- .put("pt_BR", WorkbenchMessages.SupportLanguageName_Portuguese_Brazilian); //$NON-NLS-1$
- supportLangsMap
- .put("ru", WorkbenchMessages.SupportLanguageName_Russian); //$NON-NLS-1$
- supportLangsMap.put(
- "sl", WorkbenchMessages.SupportLanguageName_Slovenian); //$NON-NLS-1$
- supportLangsMap.put(
- "zh_CN", WorkbenchMessages.SupportLanguageName_SimplifiedCN); //$NON-NLS-1$
- supportLangsMap.put(
- "zh_TW", WorkbenchMessages.SupportLanguageName_TraditionalCN); //$NON-NLS-1$
- }
-
- private Properties loadProperties(File file) {
- if (file != null && file.exists() && file.canRead()) {
- try {
- InputStream stream = new BufferedInputStream(
- new FileInputStream(file), 1024);
- try {
- Properties properties = new Properties();
- properties.load(stream);
- return properties;
- } finally {
- try {
- stream.close();
- } catch (IOException e) {
- }
- }
- } catch (IOException e) {
- }
- }
- return null;
- }
-
- private void storeProperties(Properties properties, File file) {
- if (file != null && file.exists() && file.canWrite()) {
- try {
- OutputStream stream = new BufferedOutputStream(
- new FileOutputStream(file), 1024);
- try {
- properties.store(stream, "Store properties into file."); //$NON-NLS-1$
- } finally {
- try {
- stream.close();
- } catch (IOException e) {
- }
- }
- } catch (IOException e) {
- }
- }
- }
-
- private File getConfigFile() {
- URL configDir = Platform.getConfigurationLocation().getURL();
- try {
- URL configIni = new URL(configDir, "config.ini"); //$NON-NLS-1$
- File file = new File(configIni.getFile());
- return file;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private File getSupportLanguageFile() {
- try {
- URL url = FileLocator.find(new URL(LOADED_LANGUAGES_URL));
- File supportLanguageFile = new File(FileLocator.toFileURL(url)
- .getPath());
- return supportLanguageFile;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public void init(IWorkbench workbench) {
- }
-
- @Override
- protected void createFieldEditors() {
- addLanguageGroup();
- }
-
- private void addLanguageGroup() {
- Composite parent = getFieldEditorParent();
- GridLayout gridLayout = new GridLayout(1, false);
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.horizontalSpacing = 0;
- parent.setLayout(gridLayout);
- addChangeLanguageField(parent);
- }
-
- private void addChangeLanguageField(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- composite.setLayout(new GridLayout());
-
- createLangsDescription(composite);
- createChangeLanguageControl(parent);
- }
-
- private void createChangeLanguageControl(Composite parent) {
- Composite line = new Composite(parent, SWT.NONE);
- line.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- line.setLayout(new GridLayout(2, false));
-
- int flags = SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE;
- langsViewer = new ListViewer(line, flags);
- GridData layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
- langsViewer.getControl().setLayoutData(layoutData);
- langsViewer.setContentProvider(new ArrayContentProvider());
- langsViewer.setLabelProvider(new LanguageLabelProvider());
- langsViewer.setInput(supportedLangsKey);
-
- String languageKey = configIniProperties
- .getProperty(LANGUAGE_OSGI_NL_KEY);
- String currentLanguageKey = languageKey != null ? languageKey
- : oldLangKey;
-
- langsViewer.setSelection(new StructuredSelection(currentLanguageKey));
- langsViewer
- .addSelectionChangedListener(new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection langElementSelection = event.getSelection();
- if (langElementSelection instanceof StructuredSelection) {
- Object langKey = ((StructuredSelection) langElementSelection)
- .getFirstElement();
-
- boolean isChanged = !oldLangKey.equals(langKey);
- if (isChanged) {
- String langSelected = ((LanguageLabelProvider) langsViewer
- .getLabelProvider()).getText(langKey);
- changingToLangText.setText(langSelected);
- } else {
- changingToLangText.setText(""); //$NON-NLS-1$
- }
- changeButton.setEnabled(isChanged);
- }
- }
- });
-
- changeButton = new Button(line, SWT.NONE);
- changeButton.setText(WorkbenchMessages.ChangeLanguage_button);
- changeButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
- false));
- changeButton.setEnabled(!currentLanguageKey.equals(oldLangKey));
- changeButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- ISelection langElementSelection = langsViewer.getSelection();
- if (langElementSelection instanceof StructuredSelection) {
- Object langKey = ((StructuredSelection) langElementSelection)
- .getFirstElement();
- String langSelected = ((LanguageLabelProvider) langsViewer
- .getLabelProvider()).getText(langKey);
- String message = NLS.bind(
- WorkbenchMessages.ConfirmToRestart_description,
- langSelected);
- MessageDialog confirmDialog = new MessageDialog(
- getShell(),
- WorkbenchMessages.ConfirmToRestart_title,
- null,
- message,
- MessageDialog.CONFIRM,
- new String[] {
- WorkbenchMessages.ConfirmToRestart_defaultButton,
- WorkbenchMessages.ConfirmToRestart_cancelButton },
- IDialogConstants.OK_ID);
- int restart = confirmDialog.open();
- configIniProperties.put(LANGUAGE_OSGI_NL_KEY, langKey);
- storeProperties(configIniProperties, getConfigFile());
- if (restart == 0) {
- PlatformUI.getWorkbench().restart();
- }
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- });
- }
-
- private void createLangsDescription(Composite composite) {
- Composite descriptionComposite = new Composite(composite, SWT.NONE);
- descriptionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
- true, false));
- GridLayout descriptionLayout = new GridLayout(2, false);
- descriptionLayout.marginHeight = 0;
- descriptionLayout.marginWidth = 0;
- descriptionComposite.setLayout(descriptionLayout);
-
- Label langToChangeDescription = new Label(descriptionComposite,
- SWT.NONE);
- langToChangeDescription
- .setText(WorkbenchMessages.ChangeLanguageTo_description);
- langToChangeDescription.setLayoutData(new GridData(SWT.FILL));
-
- changingToLangText = new Label(descriptionComposite, SWT.READ_ONLY
- | SWT.SINGLE | SWT.BORDER | SWT.SHADOW_IN | SWT.LEFT);
- changingToLangText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
- true, true));
-
- String languageKey = configIniProperties
- .getProperty(LANGUAGE_OSGI_NL_KEY);
- String supportLang = supportLangsMap.get(languageKey);
- if (supportLang != null)
- changingToLangText.setText(supportLang);
- }
-
- @Override
- protected void performDefaults() {
- configIniProperties.put(LANGUAGE_OSGI_NL_KEY,
- System.getProperty(LANGUAGE_OSGI_NL_KEY));
- langsViewer.setSelection(
- new StructuredSelection(System
- .getProperty(LANGUAGE_OSGI_NL_KEY)), true);
- storeProperties(configIniProperties, getConfigFile());
- super.performDefaults();
- }
-
- @Override
- public boolean performOk() {
- if (!super.performOk())
- return false;
-
- ISelection langElementSelection = langsViewer.getSelection();
- if (langElementSelection instanceof StructuredSelection) {
- Object langKey = ((StructuredSelection) langElementSelection)
- .getFirstElement();
- if (!oldLangKey.equals(langKey)) {
- String message = WorkbenchMessages.LanguagePrefPage_ConfirmToRestart2_description;
- MessageDialog confirmDialog = new MessageDialog(
- getShell(),
- WorkbenchMessages.ConfirmToRestart_title,
- null,
- message,
- MessageDialog.CONFIRM,
- new String[] {
- WorkbenchMessages.LanguagePrefPage_ConfirmToRestart2_defaultButton,
- WorkbenchMessages.LanguagePrefPage_ConfirmToRestart_laterButton },
- IDialogConstants.OK_ID);
- int restart = confirmDialog.open();
- if (restart == -1)
- return false;
-
- configIniProperties.put(LANGUAGE_OSGI_NL_KEY, langKey);
- storeProperties(configIniProperties, getConfigFile());
- if (restart == IDialogConstants.OK_ID) {
- PlatformUI.getWorkbench().restart();
- }
- }
- }
-
- return true;
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.PlatformUI;
+
+public class LanguagePrefPage extends FieldEditorPreferencePage implements
+ IWorkbenchPreferencePage {
+
+ private static final String LANGUAGE_OSGI_NL_KEY = "osgi.nl"; //$NON-NLS-1$
+ private static final String LOADED_LANGUAGES_URL = "platform:/plugin/org.xmind.cathy/resource/langs.properties"; //$NON-NLS-1$
+ @SuppressWarnings("nls")
+ private static final String[] supportedLangsKey = { "en_US", "de", "fr",
+ "zh_CN", "zh_TW", "ja", "ko", "da", "ru", "it", "sl", "ar", "es",
+ "pt_BR" };
+
+ private class LanguageLabelProvider extends LabelProvider {
+ @Override
+ public String getText(Object element) {
+ if (element instanceof String) {
+ StringBuffer buffer = new StringBuffer(3);
+
+ String langKey = (String) element;
+ String supportLang = supportLanguageProperties
+ .getProperty(langKey);
+ buffer.append(supportLang);
+ buffer.append(" - "); //$NON-NLS-1$
+ buffer.append(supportLangsMap.get(langKey));
+ return buffer.toString();
+ }
+ return super.getText(element);
+ }
+ }
+
+ private static String oldLangKey = null;
+
+ private Properties configIniProperties;
+
+ private Properties supportLanguageProperties;
+
+ private HashMap supportLangsMap;
+
+ private ListViewer langsViewer;
+
+ private Label changingToLangText;
+
+ private Button changeButton;
+
+ public LanguagePrefPage() {
+ super(WorkbenchMessages.LanguagePrefPage_title, FLAT);
+ configIniProperties = loadProperties(getConfigFile());
+ supportLanguageProperties = loadProperties(getSupportLanguageFile());
+ initSupportLanguageMap();
+ if (oldLangKey == null) {
+ String languageKey = configIniProperties
+ .getProperty(LANGUAGE_OSGI_NL_KEY);
+ oldLangKey = languageKey != null ? languageKey : System
+ .getProperty(LANGUAGE_OSGI_NL_KEY);
+ }
+ }
+
+ private void initSupportLanguageMap() {
+ if (supportLangsMap != null)
+ return;
+ supportLangsMap = new HashMap();
+ supportLangsMap.put(
+ "en_US", WorkbenchMessages.SupportLanguageName_English); //$NON-NLS-1$
+ supportLangsMap.put("ar", WorkbenchMessages.SupportLanguageName_Arabic); //$NON-NLS-1$
+ supportLangsMap.put("da", WorkbenchMessages.SupportLanguageName_Danish); //$NON-NLS-1$
+ supportLangsMap.put("de", WorkbenchMessages.SupportLanguageName_German); //$NON-NLS-1$
+ supportLangsMap.put(
+ "es", WorkbenchMessages.SupportLanguageName_Spanish); //$NON-NLS-1$
+ supportLangsMap.put("fr", WorkbenchMessages.SupportLanguageName_French); //$NON-NLS-1$
+ supportLangsMap
+ .put("it", WorkbenchMessages.SupportLanguageName_Italian); //$NON-NLS-1$
+ supportLangsMap.put(
+ "ja", WorkbenchMessages.SupportLanguageName_Japanese); //$NON-NLS-1$
+ supportLangsMap.put("ko", WorkbenchMessages.SupportLanguageName_Korean); //$NON-NLS-1$
+ supportLangsMap
+ .put("pt_BR", WorkbenchMessages.SupportLanguageName_Portuguese_Brazilian); //$NON-NLS-1$
+ supportLangsMap
+ .put("ru", WorkbenchMessages.SupportLanguageName_Russian); //$NON-NLS-1$
+ supportLangsMap.put(
+ "sl", WorkbenchMessages.SupportLanguageName_Slovenian); //$NON-NLS-1$
+ supportLangsMap.put(
+ "zh_CN", WorkbenchMessages.SupportLanguageName_SimplifiedCN); //$NON-NLS-1$
+ supportLangsMap.put(
+ "zh_TW", WorkbenchMessages.SupportLanguageName_TraditionalCN); //$NON-NLS-1$
+ }
+
+ private Properties loadProperties(File file) {
+ if (file != null && file.exists() && file.canRead()) {
+ try {
+ InputStream stream = new BufferedInputStream(
+ new FileInputStream(file), 1024);
+ try {
+ Properties properties = new Properties();
+ properties.load(stream);
+ return properties;
+ } finally {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ }
+ }
+ } catch (IOException e) {
+ }
+ }
+ return null;
+ }
+
+ private void storeProperties(Properties properties, File file) {
+ if (file != null && file.exists() && file.canWrite()) {
+ try {
+ OutputStream stream = new BufferedOutputStream(
+ new FileOutputStream(file), 1024);
+ try {
+ properties.store(stream, "Store properties into file."); //$NON-NLS-1$
+ } finally {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ }
+ }
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ private File getConfigFile() {
+ URL configDir = Platform.getConfigurationLocation().getURL();
+ try {
+ URL configIni = new URL(configDir, "config.ini"); //$NON-NLS-1$
+ File file = new File(configIni.getFile());
+ return file;
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private File getSupportLanguageFile() {
+ try {
+ URL url = FileLocator.find(new URL(LOADED_LANGUAGES_URL));
+ File supportLanguageFile = new File(FileLocator.toFileURL(url)
+ .getPath());
+ return supportLanguageFile;
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public void init(IWorkbench workbench) {
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ addLanguageGroup();
+ }
+
+ private void addLanguageGroup() {
+ Composite parent = getFieldEditorParent();
+ GridLayout gridLayout = new GridLayout(1, false);
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.verticalSpacing = 0;
+ gridLayout.horizontalSpacing = 0;
+ parent.setLayout(gridLayout);
+ addChangeLanguageField(parent);
+ }
+
+ private void addChangeLanguageField(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ composite.setLayout(new GridLayout());
+
+ createLangsDescription(composite);
+ createChangeLanguageControl(parent);
+ }
+
+ private void createChangeLanguageControl(Composite parent) {
+ Composite line = new Composite(parent, SWT.NONE);
+ line.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ line.setLayout(new GridLayout(2, false));
+
+ int flags = SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE;
+ langsViewer = new ListViewer(line, flags);
+ GridData layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
+ langsViewer.getControl().setLayoutData(layoutData);
+ langsViewer.setContentProvider(new ArrayContentProvider());
+ langsViewer.setLabelProvider(new LanguageLabelProvider());
+ langsViewer.setInput(supportedLangsKey);
+
+ String languageKey = configIniProperties
+ .getProperty(LANGUAGE_OSGI_NL_KEY);
+ String currentLanguageKey = languageKey != null ? languageKey
+ : oldLangKey;
+
+ langsViewer.setSelection(new StructuredSelection(currentLanguageKey));
+ langsViewer
+ .addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection langElementSelection = event.getSelection();
+ if (langElementSelection instanceof StructuredSelection) {
+ Object langKey = ((StructuredSelection) langElementSelection)
+ .getFirstElement();
+
+ boolean isChanged = !oldLangKey.equals(langKey);
+ if (isChanged) {
+ String langSelected = ((LanguageLabelProvider) langsViewer
+ .getLabelProvider()).getText(langKey);
+ changingToLangText.setText(langSelected);
+ } else {
+ changingToLangText.setText(""); //$NON-NLS-1$
+ }
+ changeButton.setEnabled(isChanged);
+ }
+ }
+ });
+
+ changeButton = new Button(line, SWT.NONE);
+ changeButton.setText(WorkbenchMessages.ChangeLanguage_button);
+ changeButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
+ false));
+ changeButton.setEnabled(!currentLanguageKey.equals(oldLangKey));
+ changeButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ ISelection langElementSelection = langsViewer.getSelection();
+ if (langElementSelection instanceof StructuredSelection) {
+ Object langKey = ((StructuredSelection) langElementSelection)
+ .getFirstElement();
+ String langSelected = ((LanguageLabelProvider) langsViewer
+ .getLabelProvider()).getText(langKey);
+ String message = NLS.bind(
+ WorkbenchMessages.ConfirmToRestart_description,
+ langSelected);
+ MessageDialog confirmDialog = new MessageDialog(
+ getShell(),
+ WorkbenchMessages.ConfirmToRestart_title,
+ null,
+ message,
+ MessageDialog.CONFIRM,
+ new String[] {
+ WorkbenchMessages.ConfirmToRestart_defaultButton,
+ WorkbenchMessages.ConfirmToRestart_cancelButton },
+ IDialogConstants.OK_ID);
+ int restart = confirmDialog.open();
+ configIniProperties.put(LANGUAGE_OSGI_NL_KEY, langKey);
+ storeProperties(configIniProperties, getConfigFile());
+ if (restart == 0) {
+ PlatformUI.getWorkbench().restart();
+ }
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+ }
+
+ private void createLangsDescription(Composite composite) {
+ Composite descriptionComposite = new Composite(composite, SWT.NONE);
+ descriptionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
+ true, false));
+ GridLayout descriptionLayout = new GridLayout(2, false);
+ descriptionLayout.marginHeight = 0;
+ descriptionLayout.marginWidth = 0;
+ descriptionComposite.setLayout(descriptionLayout);
+
+ Label langToChangeDescription = new Label(descriptionComposite,
+ SWT.NONE);
+ langToChangeDescription
+ .setText(WorkbenchMessages.ChangeLanguageTo_description);
+ langToChangeDescription.setLayoutData(new GridData(SWT.FILL));
+
+ changingToLangText = new Label(descriptionComposite, SWT.READ_ONLY
+ | SWT.SINGLE | SWT.BORDER | SWT.SHADOW_IN | SWT.LEFT);
+ changingToLangText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
+ true, true));
+
+ String languageKey = configIniProperties
+ .getProperty(LANGUAGE_OSGI_NL_KEY);
+ String supportLang = supportLangsMap.get(languageKey);
+ if (supportLang != null)
+ changingToLangText.setText(supportLang);
+ }
+
+ @Override
+ protected void performDefaults() {
+ configIniProperties.put(LANGUAGE_OSGI_NL_KEY,
+ System.getProperty(LANGUAGE_OSGI_NL_KEY));
+ langsViewer.setSelection(
+ new StructuredSelection(System
+ .getProperty(LANGUAGE_OSGI_NL_KEY)), true);
+ storeProperties(configIniProperties, getConfigFile());
+ super.performDefaults();
+ }
+
+ @Override
+ public boolean performOk() {
+ if (!super.performOk())
+ return false;
+
+ ISelection langElementSelection = langsViewer.getSelection();
+ if (langElementSelection instanceof StructuredSelection) {
+ Object langKey = ((StructuredSelection) langElementSelection)
+ .getFirstElement();
+ if (!oldLangKey.equals(langKey)) {
+ String message = WorkbenchMessages.LanguagePrefPage_ConfirmToRestart2_description;
+ MessageDialog confirmDialog = new MessageDialog(
+ getShell(),
+ WorkbenchMessages.ConfirmToRestart_title,
+ null,
+ message,
+ MessageDialog.CONFIRM,
+ new String[] {
+ WorkbenchMessages.LanguagePrefPage_ConfirmToRestart2_defaultButton,
+ WorkbenchMessages.LanguagePrefPage_ConfirmToRestart_laterButton },
+ IDialogConstants.OK_ID);
+ int restart = confirmDialog.open();
+ if (restart == -1)
+ return false;
+
+ configIniProperties.put(LANGUAGE_OSGI_NL_KEY, langKey);
+ storeProperties(configIniProperties, getConfigFile());
+ if (restart == IDialogConstants.OK_ID) {
+ PlatformUI.getWorkbench().restart();
+ }
+ }
+ }
+
+ return true;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LanguagePreferencePageSection.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LanguagePreferencePageSection.java
index 016f311ed..6fdf03c35 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LanguagePreferencePageSection.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LanguagePreferencePageSection.java
@@ -1,348 +1,348 @@
-package org.xmind.cathy.internal;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
-import org.xmind.ui.resources.ColorUtils;
-
-public class LanguagePreferencePageSection
- extends PreferenceFieldEditorPageSection
- implements IWorkbenchPreferencePage, MouseListener {
-
- private static final String LANGUAGE_OSGI_NL_KEY = "osgi.nl"; //$NON-NLS-1$
-
- private static final String LOADED_LANGUAGES_URL = "platform:/plugin/org.xmind.cathy/resource/langs.properties"; //$NON-NLS-1$
-
- private Properties supportLanguageProperties;
-
- private String oldLangKey = null;
-
- private String newLangKey = null;
-
- private Properties configIniProperties;
-
- private Label langLabel;
-
- private LocalResourceManager resource;
-
- private static final String blue = "#0070D8"; //$NON-NLS-1$
-
- private static final String[] supportedLangsKey = { "en_US", "de", "fr", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- "zh_CN", "zh_TW", "ja", "ko", "da", "es" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-
- private Map langMap = null;
-
- public void init(IWorkbench workbench) {
- configIniProperties = loadProperties(getConfigFile());
- supportLanguageProperties = loadProperties(getSupportLanguageFile());
- if (oldLangKey == null) {
- String languageKey = configIniProperties
- .getProperty(LANGUAGE_OSGI_NL_KEY);
- oldLangKey = languageKey != null ? languageKey
- : System.getProperty(LANGUAGE_OSGI_NL_KEY);
- }
- }
-
-// @Override
-// public void createControl(Composite parent) {
-// Control body = createContents(parent);
-// setControl(body);
-// }
-
- @Override
- protected Control createContents(Composite parent) {
-
- if (null == resource)
- resource = new LocalResourceManager(JFaceResources.getResources(),
- parent);
-
- Composite topContainer = new Composite(parent, SWT.NONE);
- GridDataFactory.fillDefaults().grab(true, false).applyTo(topContainer);
- GridLayoutFactory.fillDefaults().numColumns(2).applyTo(topContainer);
-
- Label describe = new Label(topContainer, SWT.NONE);
- describe.setText(WorkbenchMessages.ChangeLanguageTo_description);
-
- langLabel = new Label(topContainer, SWT.NONE);
- langLabel.setText(supportLanguageProperties.getProperty(oldLangKey));
- GridDataFactory.fillDefaults().grab(true, false).applyTo(langLabel);
-
- GridLayout parentLayout = (GridLayout) parent.getLayout();
- if (parentLayout != null) {
- parentLayout.verticalSpacing = 10;
- }
-
- Composite container = createLangContainer(parent, 3);
-
- //firstly init language map, and init langMap by OldLangKey.
- initLangMap(container);
- initByOldLangKey();
-
- return container;
- }
-
- private void initLangMap(Composite container) {
- if (null == langMap)
- langMap = new HashMap();
- for (String lang : supportedLangsKey) {
- Composite langComposite = createLang(container,
- supportLanguageProperties.getProperty(lang));
- langComposite.addMouseListener(this);
- Control[] children = langComposite.getChildren();
- for (Control child : children) {
- child.addMouseListener(this);
- }
- langMap.put(langComposite, lang);
- }
- }
-
- private void initByOldLangKey() {
- if (null != langMap && langMap.containsValue(oldLangKey)) {
- Iterator iterator = langMap.entrySet().iterator();
- while (iterator.hasNext()) {
- @SuppressWarnings("unchecked")
- Map.Entry item = (Entry) iterator
- .next();
- if (oldLangKey.equals(item.getValue())) {
- Composite composite = item.getKey();
- changeControlBack(composite,
- (Color) resource.get(ColorUtils.toDescriptor(blue)),
- ColorConstants.white);
- }
- }
- }
- }
-
- private Composite createLangContainer(Composite parent, int cols) {
- Composite container = new Composite(parent, SWT.NONE);
- GridDataFactory.fillDefaults().grab(true, false).applyTo(container);
- GridLayoutFactory.fillDefaults().equalWidth(true).spacing(8, 10)
- .numColumns(cols).applyTo(container);
- return container;
- }
-
- private Composite createLang(Composite parent, String lang) {
- Composite panel = new Composite(parent, SWT.BORDER);
- panel.setBackground(ColorConstants.white);
- GridLayoutFactory.fillDefaults().margins(5, 5).spacing(5, 5)
- .applyTo(panel);
- GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
-
- Label langLabel = new Label(panel, SWT.NONE);
- langLabel.setText(lang);
- langLabel.setBackground(ColorConstants.white);
- return panel;
- }
-
- private File getSupportLanguageFile() {
- try {
- URL url = FileLocator.find(new URL(LOADED_LANGUAGES_URL));
- File supportLanguageFile = new File(
- FileLocator.toFileURL(url).getPath());
- return supportLanguageFile;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private Properties loadProperties(File file) {
- if (file != null && file.exists() && file.canRead()) {
- try {
- InputStream stream = new BufferedInputStream(
- new FileInputStream(file), 1024);
- try {
- Properties properties = new Properties();
- properties.load(stream);
- return properties;
- } finally {
- try {
- stream.close();
- } catch (IOException e) {
- }
- }
- } catch (IOException e) {
- }
- }
- return null;
- }
-
- private File getConfigFile() {
- URL configDir = Platform.getConfigurationLocation().getURL();
- try {
- URL configIni = new URL(configDir, "config.ini"); //$NON-NLS-1$
- File file = new File(configIni.getFile());
- return file;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private void storeProperties(Properties properties, File file) {
- if (file != null && file.exists() && file.canWrite()) {
- try {
- OutputStream stream = new BufferedOutputStream(
- new FileOutputStream(file), 1024);
- try {
- properties.store(stream, "Store properties into file."); //$NON-NLS-1$
- } finally {
- try {
- stream.close();
- } catch (IOException e) {
- }
- }
- } catch (IOException e) {
- }
- }
- }
-
- @Override
- protected void performDefaults() {
- configIniProperties.put(LANGUAGE_OSGI_NL_KEY,
- System.getProperty(LANGUAGE_OSGI_NL_KEY));
- String lang = System.getProperty(LANGUAGE_OSGI_NL_KEY);
- if (null != langMap && langMap.containsValue(lang)) {
- clearLangSelection();
- newLangKey = lang;
- Iterator iterator = langMap.entrySet().iterator();
- while (iterator.hasNext()) {
- @SuppressWarnings("unchecked")
- Map.Entry item = (Entry) iterator
- .next();
- if (lang.equals(item.getValue())) {
- Composite composite = item.getKey();
- changeControlBack(composite,
- (Color) resource.get(ColorUtils.toDescriptor(blue)),
- ColorConstants.white);
- }
- }
- }
- storeProperties(configIniProperties, getConfigFile());
- super.performDefaults();
- }
-
- @Override
- public boolean performOk() {
- if (!super.performOk())
- return false;
- if (null != newLangKey && !oldLangKey.equals(newLangKey)) {
- String message = WorkbenchMessages.LanguagePrefPage_ConfirmToRestart2_description;
- MessageDialog confirmDialog = new MessageDialog(getShell(),
- WorkbenchMessages.ConfirmToRestart_title, null, message,
- MessageDialog.CONFIRM,
- new String[] {
- WorkbenchMessages.LanguagePrefPage_ConfirmToRestart2_defaultButton,
- WorkbenchMessages.LanguagePrefPage_ConfirmToRestart_laterButton },
- IDialogConstants.OK_ID);
- int restart = confirmDialog.open();
- if (restart == -1)
- return false;
-
- configIniProperties.put(LANGUAGE_OSGI_NL_KEY, newLangKey);
- storeProperties(configIniProperties, getConfigFile());
-
- if (restart == IDialogConstants.OK_ID) {
- PlatformUI.getWorkbench().restart();
- }
- }
- return true;
- }
-
- public void mouseDoubleClick(MouseEvent e) {
- mouseDown(e);
- this.performOk();
- }
-
- public void mouseDown(MouseEvent e) {
- Composite composite = null;
- Object object = e.getSource();
- if (null != object && object instanceof Control) {
- if (object instanceof Composite)
- composite = (Composite) object;
- else if (object instanceof Label)
- composite = ((Label) object).getParent();
- }
- changeLangSelection(composite);
- }
-
- public void mouseUp(MouseEvent e) {
- }
-
- private void changeLangSelection(Composite composite) {
- if (null != composite) {
- clearLangSelection();
- newLangKey = null;
- changeControlBack(composite,
- (Color) resource.get(ColorUtils.toDescriptor(blue)),
- ColorConstants.white);
- if (langMap.containsKey(composite)) {
- newLangKey = langMap.get(composite);
- langLabel.setText(
- supportLanguageProperties.getProperty(newLangKey));
- }
- }
- }
-
- private void clearLangSelection() {
- Iterator iterator = langMap.entrySet().iterator();
- while (iterator.hasNext()) {
- @SuppressWarnings("unchecked")
- Map.Entry it = (Entry) iterator
- .next();
- changeControlBack(it.getKey(), ColorConstants.white,
- ColorConstants.black);
- }
- }
-
- private void changeControlBack(Composite composite, Color color,
- Color fontColor) {
- composite.setBackground(color);
- Control[] children = composite.getChildren();
- for (Control child : children) {
- child.setBackground(color);
- child.setForeground(fontColor);
- }
- }
-
- @Override
- protected void createFieldEditors() {
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
+import org.xmind.ui.resources.ColorUtils;
+
+public class LanguagePreferencePageSection
+ extends PreferenceFieldEditorPageSection
+ implements IWorkbenchPreferencePage, MouseListener {
+
+ private static final String LANGUAGE_OSGI_NL_KEY = "osgi.nl"; //$NON-NLS-1$
+
+ private static final String LOADED_LANGUAGES_URL = "platform:/plugin/org.xmind.cathy/resource/langs.properties"; //$NON-NLS-1$
+
+ private Properties supportLanguageProperties;
+
+ private String oldLangKey = null;
+
+ private String newLangKey = null;
+
+ private Properties configIniProperties;
+
+ private Label langLabel;
+
+ private LocalResourceManager resource;
+
+ private static final String blue = "#0070D8"; //$NON-NLS-1$
+
+ private static final String[] supportedLangsKey = { "en_US", "de", "fr", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "zh_CN", "zh_TW", "ja", "ko", "da", "es", "sl", "it" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
+
+ private Map langMap = null;
+
+ public void init(IWorkbench workbench) {
+ configIniProperties = loadProperties(getConfigFile());
+ supportLanguageProperties = loadProperties(getSupportLanguageFile());
+ if (oldLangKey == null) {
+ String languageKey = configIniProperties
+ .getProperty(LANGUAGE_OSGI_NL_KEY);
+ oldLangKey = languageKey != null ? languageKey
+ : System.getProperty(LANGUAGE_OSGI_NL_KEY);
+ }
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+
+ if (null == resource)
+ resource = new LocalResourceManager(JFaceResources.getResources(),
+ parent);
+
+ Composite topContainer = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(topContainer);
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(topContainer);
+
+ Label describe = new Label(topContainer, SWT.NONE);
+ describe.setText(WorkbenchMessages.ChangeLanguageTo_description);
+
+ langLabel = new Label(topContainer, SWT.NONE);
+ if (supportLanguageProperties == null)
+ supportLanguageProperties = loadProperties(
+ getSupportLanguageFile());
+ String langString = supportLanguageProperties.getProperty(oldLangKey);
+ langString = langString != null ? langString : " "; //$NON-NLS-1$
+
+ langLabel.setText(langString);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(langLabel);
+ GridLayout parentLayout = (GridLayout) parent.getLayout();
+
+ if (parentLayout != null) {
+ parentLayout.verticalSpacing = 10;
+ }
+
+ Composite container = createLangContainer(parent, 3);
+
+ //firstly init language map, and init langMap by OldLangKey.
+ initLangMap(container);
+ initByOldLangKey();
+
+ return container;
+ }
+
+ private void initLangMap(Composite container) {
+ if (null == langMap)
+ langMap = new HashMap();
+ for (String lang : supportedLangsKey) {
+ Composite langComposite = createLang(container,
+ supportLanguageProperties.getProperty(lang));
+ langComposite.addMouseListener(this);
+ Control[] children = langComposite.getChildren();
+ for (Control child : children) {
+ child.addMouseListener(this);
+ }
+ langMap.put(langComposite, lang);
+ }
+ }
+
+ private void initByOldLangKey() {
+ if (null != langMap && langMap.containsValue(oldLangKey)) {
+ Iterator iterator = langMap.entrySet().iterator();
+ while (iterator.hasNext()) {
+ @SuppressWarnings("unchecked")
+ Map.Entry item = (Entry) iterator
+ .next();
+ if (oldLangKey.equals(item.getValue())) {
+ Composite composite = item.getKey();
+ changeControlBack(composite,
+ (Color) resource.get(ColorUtils.toDescriptor(blue)),
+ ColorConstants.white);
+ }
+ }
+ }
+ }
+
+ private Composite createLangContainer(Composite parent, int cols) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(container);
+ GridLayoutFactory.fillDefaults().equalWidth(true).spacing(8, 10)
+ .numColumns(cols).applyTo(container);
+ return container;
+ }
+
+ private Composite createLang(Composite parent, String lang) {
+ Composite panel = new Composite(parent, SWT.BORDER);
+ panel.setBackground(ColorConstants.white);
+ GridLayoutFactory.fillDefaults().margins(5, 5).spacing(5, 5)
+ .applyTo(panel);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
+
+ Label langLabel = new Label(panel, SWT.NONE);
+ langLabel.setText(lang);
+ langLabel.setBackground(ColorConstants.white);
+ return panel;
+ }
+
+ private File getSupportLanguageFile() {
+ try {
+ URL url = FileLocator.find(new URL(LOADED_LANGUAGES_URL));
+ File supportLanguageFile = new File(
+ FileLocator.toFileURL(url).getPath());
+ return supportLanguageFile;
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private Properties loadProperties(File file) {
+ if (file != null && file.exists() && file.canRead()) {
+ try {
+ InputStream stream = new BufferedInputStream(
+ new FileInputStream(file), 1024);
+ try {
+ Properties properties = new Properties();
+ properties.load(stream);
+ return properties;
+ } finally {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ }
+ }
+ } catch (IOException e) {
+ }
+ }
+ return null;
+ }
+
+ private File getConfigFile() {
+ URL configDir = Platform.getConfigurationLocation().getURL();
+ try {
+ URL configIni = new URL(configDir, "config.ini"); //$NON-NLS-1$
+ File file = new File(configIni.getFile());
+ return file;
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void storeProperties(Properties properties, File file) {
+ if (file != null && file.exists() && file.canWrite()) {
+ try {
+ OutputStream stream = new BufferedOutputStream(
+ new FileOutputStream(file), 1024);
+ try {
+ properties.store(stream, "Store properties into file."); //$NON-NLS-1$
+ } finally {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ }
+ }
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ @Override
+ protected void performDefaults() {
+ configIniProperties.put(LANGUAGE_OSGI_NL_KEY,
+ System.getProperty(LANGUAGE_OSGI_NL_KEY));
+ String lang = System.getProperty(LANGUAGE_OSGI_NL_KEY);
+ if (null != langMap && langMap.containsValue(lang)) {
+ clearLangSelection();
+ newLangKey = lang;
+ Iterator iterator = langMap.entrySet().iterator();
+ while (iterator.hasNext()) {
+ @SuppressWarnings("unchecked")
+ Map.Entry item = (Entry) iterator
+ .next();
+ if (lang.equals(item.getValue())) {
+ Composite composite = item.getKey();
+ changeControlBack(composite,
+ (Color) resource.get(ColorUtils.toDescriptor(blue)),
+ ColorConstants.white);
+ }
+ }
+ }
+ storeProperties(configIniProperties, getConfigFile());
+ super.performDefaults();
+ }
+
+ @Override
+ public boolean performOk() {
+ if (!super.performOk())
+ return false;
+ if (null != newLangKey && !oldLangKey.equals(newLangKey)) {
+ String message = WorkbenchMessages.LanguagePrefPage_ConfirmToRestart2_description;
+ MessageDialog confirmDialog = new MessageDialog(getShell(),
+ WorkbenchMessages.ConfirmToRestart_title, null, message,
+ MessageDialog.CONFIRM,
+ new String[] {
+ WorkbenchMessages.LanguagePrefPage_ConfirmToRestart2_defaultButton,
+ WorkbenchMessages.LanguagePrefPage_ConfirmToRestart_laterButton },
+ IDialogConstants.OK_ID);
+ int restart = confirmDialog.open();
+ if (restart == -1)
+ return false;
+
+ configIniProperties.put(LANGUAGE_OSGI_NL_KEY, newLangKey);
+ storeProperties(configIniProperties, getConfigFile());
+
+ if (restart == IDialogConstants.OK_ID) {
+ PlatformUI.getWorkbench().restart();
+ }
+ }
+ return true;
+ }
+
+ public void mouseDoubleClick(MouseEvent e) {
+ mouseDown(e);
+ this.performOk();
+ }
+
+ public void mouseDown(MouseEvent e) {
+ Composite composite = null;
+ Object object = e.getSource();
+ if (null != object && object instanceof Control) {
+ if (object instanceof Composite)
+ composite = (Composite) object;
+ else if (object instanceof Label)
+ composite = ((Label) object).getParent();
+ }
+ changeLangSelection(composite);
+ }
+
+ public void mouseUp(MouseEvent e) {
+ }
+
+ private void changeLangSelection(Composite composite) {
+ if (null != composite) {
+ clearLangSelection();
+ newLangKey = null;
+ changeControlBack(composite,
+ (Color) resource.get(ColorUtils.toDescriptor(blue)),
+ ColorConstants.white);
+ if (langMap.containsKey(composite)) {
+ newLangKey = langMap.get(composite);
+ langLabel.setText(
+ supportLanguageProperties.getProperty(newLangKey));
+ }
+ }
+ }
+
+ private void clearLangSelection() {
+ Iterator iterator = langMap.entrySet().iterator();
+ while (iterator.hasNext()) {
+ @SuppressWarnings("unchecked")
+ Map.Entry it = (Entry) iterator
+ .next();
+ changeControlBack(it.getKey(), ColorConstants.white,
+ ColorConstants.black);
+ }
+ }
+
+ private void changeControlBack(Composite composite, Color color,
+ Color fontColor) {
+ composite.setBackground(color);
+ Control[] children = composite.getChildren();
+ for (Control child : children) {
+ child.setBackground(color);
+ child.setForeground(fontColor);
+ }
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LicenseAgentProxy.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LicenseAgentProxy.java
index f022c5de2..b17d19517 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LicenseAgentProxy.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/LicenseAgentProxy.java
@@ -1,130 +1,130 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2016 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-/**
- *
- */
-package org.xmind.cathy.internal;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.xmind.core.licensing.ILicenseAgent;
-import org.xmind.core.licensing.ILicenseChangedListener;
-import org.xmind.core.licensing.ILicenseKeyHeader;
-
-/**
- * @author Frank Shaka
- *
- */
-public class LicenseAgentProxy implements ILicenseAgent {
-
- private ILicenseAgent delegate;
-
- private final List listeners;
-
- /**
- *
- */
- public LicenseAgentProxy() {
- this.delegate = null;
- this.listeners = new ArrayList(1);
- }
-
- /**
- * @param delegate
- * the delegate to set
- */
- public void setDelegate(ILicenseAgent delegate) {
- ILicenseAgent oldDelegate = this.delegate;
- if (delegate == oldDelegate)
- return;
-
- if (oldDelegate != null) {
- for (ILicenseChangedListener listener : listeners) {
- oldDelegate.removeLicenseChangedListener(listener);
- }
- }
- this.delegate = delegate;
- if (delegate != null) {
- for (ILicenseChangedListener listener : listeners) {
- delegate.addLicenseChangedListener(listener);
- }
- }
-
- for (ILicenseChangedListener listener : listeners) {
- listener.licenseChanged(this);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.xmind.core.licensing.ILicenseAgent#getLicenseType()
- */
- @Override
- public int getLicenseType() {
- return delegate == null ? NOT_LICENSED : delegate.getLicenseType();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.xmind.core.licensing.ILicenseAgent#getLicenseeName()
- */
- @Override
- public String getLicenseeName() {
- return delegate == null ? null : delegate.getLicenseeName();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.xmind.core.licensing.ILicenseAgent#getLicenseKeyHeader()
- */
- @Override
- public ILicenseKeyHeader getLicenseKeyHeader() {
- return delegate == null ? null : delegate.getLicenseKeyHeader();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.xmind.core.licensing.ILicenseAgent#addLicenseChangedListener(org.
- * xmind.core.licensing.ILicenseChangedListener)
- */
- @Override
- public void addLicenseChangedListener(ILicenseChangedListener listener) {
- listeners.add(listener);
- if (delegate != null) {
- delegate.addLicenseChangedListener(listener);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.xmind.core.licensing.ILicenseAgent#removeLicenseChangedListener(org.
- * xmind.core.licensing.ILicenseChangedListener)
- */
- @Override
- public void removeLicenseChangedListener(ILicenseChangedListener listener) {
- listeners.remove(listener);
- if (delegate != null) {
- delegate.removeLicenseChangedListener(listener);
- }
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2016 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+/**
+ *
+ */
+package org.xmind.cathy.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xmind.core.licensing.ILicenseAgent;
+import org.xmind.core.licensing.ILicenseChangedListener;
+import org.xmind.core.licensing.ILicenseKeyHeader;
+
+/**
+ * @author Frank Shaka
+ *
+ */
+public class LicenseAgentProxy implements ILicenseAgent {
+
+ private ILicenseAgent delegate;
+
+ private final List listeners;
+
+ /**
+ *
+ */
+ public LicenseAgentProxy() {
+ this.delegate = null;
+ this.listeners = new ArrayList(1);
+ }
+
+ /**
+ * @param delegate
+ * the delegate to set
+ */
+ public void setDelegate(ILicenseAgent delegate) {
+ ILicenseAgent oldDelegate = this.delegate;
+ if (delegate == oldDelegate)
+ return;
+
+ if (oldDelegate != null) {
+ for (ILicenseChangedListener listener : listeners) {
+ oldDelegate.removeLicenseChangedListener(listener);
+ }
+ }
+ this.delegate = delegate;
+ if (delegate != null) {
+ for (ILicenseChangedListener listener : listeners) {
+ delegate.addLicenseChangedListener(listener);
+ }
+ }
+
+ for (ILicenseChangedListener listener : listeners) {
+ listener.licenseChanged(this);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xmind.core.licensing.ILicenseAgent#getLicenseType()
+ */
+ @Override
+ public int getLicenseType() {
+ return delegate == null ? NOT_LICENSED : delegate.getLicenseType();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xmind.core.licensing.ILicenseAgent#getLicenseeName()
+ */
+ @Override
+ public String getLicenseeName() {
+ return delegate == null ? null : delegate.getLicenseeName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xmind.core.licensing.ILicenseAgent#getLicenseKeyHeader()
+ */
+ @Override
+ public ILicenseKeyHeader getLicenseKeyHeader() {
+ return delegate == null ? null : delegate.getLicenseKeyHeader();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.xmind.core.licensing.ILicenseAgent#addLicenseChangedListener(org.
+ * xmind.core.licensing.ILicenseChangedListener)
+ */
+ @Override
+ public void addLicenseChangedListener(ILicenseChangedListener listener) {
+ listeners.add(listener);
+ if (delegate != null) {
+ delegate.addLicenseChangedListener(listener);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.xmind.core.licensing.ILicenseAgent#removeLicenseChangedListener(org.
+ * xmind.core.licensing.ILicenseChangedListener)
+ */
+ @Override
+ public void removeLicenseChangedListener(ILicenseChangedListener listener) {
+ listeners.remove(listener);
+ if (delegate != null) {
+ delegate.removeLicenseChangedListener(listener);
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/Log.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/Log.java
index 0653930e3..bd3537314 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/Log.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/Log.java
@@ -1,209 +1,209 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.xmind.core.util.FileUtils;
-
-public class Log implements ISchedulingRule {
-
- public static final String SINGLETON = ".singleton"; //$NON-NLS-1$
-
- public static final String OPENING = ".opening"; //$NON-NLS-1$
-
- public static final String K_PRIMARY_WINDOW = "PRIMARY_WINDOW"; //$NON-NLS-1$
-
- private static String lineSeparator = null;
-
- /*
- * This is a former workaround. No use after SWT has OpenDocument event.
- * ========================================================================
- * On Mac OS X, we use AppleScript to open .xmind file on double click.
- * AppleScript supports only UTF-16. So we should do writing and reading log
- * files using UTF-16 format on Mac OS X.
- */
- // private static boolean ON_MAC = "macosx".equals(Platform.getOS()); //$NON-NLS-1$
-
- private File file;
-
- private Properties properties = null;
-
- public Log(File file) {
- this.file = file;
- }
-
- public Properties getProperties() {
- if (properties == null) {
- loadProperties();
- }
- return properties;
- }
-
- private void loadProperties() {
- properties = new Properties();
-
- if (file.isFile() && file.canRead()) {
- try {
- FileInputStream is = new FileInputStream(file);
- try {
- properties.load(is);
- } finally {
- is.close();
- }
- } catch (IOException e) {
- CathyPlugin
- .log(e,
- "Failed to load properties from log file: " + file.getAbsolutePath()); //$NON-NLS-1$
- }
- }
- }
-
- public void saveProperties() {
- if (properties == null)
- return;
-
- FileUtils.ensureFileParent(file);
- try {
- FileOutputStream out = new FileOutputStream(file);
- try {
- properties.store(out, null);
- } finally {
- out.close();
- }
- } catch (IOException e) {
- CathyPlugin
- .log(e,
- "Failed to save properties to log file: " + file.getAbsolutePath()); //$NON-NLS-1$
- }
- }
-
- public String[] getContents() {
- if (!file.isFile() || !file.canRead())
- return new String[0];
- List lines = new ArrayList();
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(
- new FileInputStream(file), "UTF-8")); //$NON-NLS-1$
- try {
- String line;
- while ((line = reader.readLine()) != null) {
- line = line.trim();
- if (!"".equals(line)) //$NON-NLS-1$
- lines.add(line);
- }
- } finally {
- reader.close();
- }
- } catch (IOException e) {
- CathyPlugin.log(e,
- "Failed to read log file: " + file.getAbsolutePath()); //$NON-NLS-1$
- }
- return lines.toArray(new String[lines.size()]);
- }
-
- public void setContents(String... contents) {
- write(false, contents);
- }
-
- public void append(String... lines) {
- if (lines.length == 0)
- return;
- write(true, lines);
- }
-
- private void write(boolean append, String... contents) {
- FileUtils.ensureFileParent(file);
- try {
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(file, append), "UTF-8")); //$NON-NLS-1$
- try {
- for (String line : contents) {
- writer.write(line);
- writer.newLine();
- }
- } finally {
- writer.close();
- }
- } catch (IOException e) {
- CathyPlugin.log(e,
- "Failed to write log file: " + file.getAbsolutePath()); //$NON-NLS-1$
- }
- }
-
- public void delete() {
- file.delete();
- properties = null;
- }
-
- public boolean exists() {
- return file.exists();
- }
-
- public static Log get(String name) {
- URL url = Platform.getInstanceLocation().getURL();
- try {
- url = FileLocator.toFileURL(url);
- } catch (IOException e) {
- //ignore this exception
- }
- File file = new File(url.getFile(), name);
- Log log = new Log(file);
- return log;
- }
-
- public static String getLineSeparator() {
- if (lineSeparator == null)
- lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$
- return lineSeparator;
- }
-
- public boolean contains(ISchedulingRule rule) {
- if (rule == this)
- return true;
- if (rule instanceof Log) {
- Log log = (Log) rule;
- if (log.file == null || file == null)
- return false;
- return log.file.getAbsolutePath().equals(file.getAbsolutePath());
- }
- return false;
- }
-
- public boolean isConflicting(ISchedulingRule rule) {
- if (rule == this)
- return true;
- if (rule instanceof Log) {
- Log log = (Log) rule;
- if (log.file == null || file == null)
- return false;
- return log.file.getAbsolutePath().equals(file.getAbsolutePath());
- }
- return false;
- }
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.xmind.core.util.FileUtils;
+
+public class Log implements ISchedulingRule {
+
+ public static final String SINGLETON = ".singleton"; //$NON-NLS-1$
+
+ public static final String OPENING = ".opening"; //$NON-NLS-1$
+
+ public static final String K_PRIMARY_WINDOW = "PRIMARY_WINDOW"; //$NON-NLS-1$
+
+ private static String lineSeparator = null;
+
+ /*
+ * This is a former workaround. No use after SWT has OpenDocument event.
+ * ========================================================================
+ * On Mac OS X, we use AppleScript to open .xmind file on double click.
+ * AppleScript supports only UTF-16. So we should do writing and reading log
+ * files using UTF-16 format on Mac OS X.
+ */
+ // private static boolean ON_MAC = "macosx".equals(Platform.getOS()); //$NON-NLS-1$
+
+ private File file;
+
+ private Properties properties = null;
+
+ public Log(File file) {
+ this.file = file;
+ }
+
+ public Properties getProperties() {
+ if (properties == null) {
+ loadProperties();
+ }
+ return properties;
+ }
+
+ private void loadProperties() {
+ properties = new Properties();
+
+ if (file.isFile() && file.canRead()) {
+ try {
+ FileInputStream is = new FileInputStream(file);
+ try {
+ properties.load(is);
+ } finally {
+ is.close();
+ }
+ } catch (IOException e) {
+ CathyPlugin
+ .log(e,
+ "Failed to load properties from log file: " + file.getAbsolutePath()); //$NON-NLS-1$
+ }
+ }
+ }
+
+ public void saveProperties() {
+ if (properties == null)
+ return;
+
+ FileUtils.ensureFileParent(file);
+ try {
+ FileOutputStream out = new FileOutputStream(file);
+ try {
+ properties.store(out, null);
+ } finally {
+ out.close();
+ }
+ } catch (IOException e) {
+ CathyPlugin
+ .log(e,
+ "Failed to save properties to log file: " + file.getAbsolutePath()); //$NON-NLS-1$
+ }
+ }
+
+ public String[] getContents() {
+ if (!file.isFile() || !file.canRead())
+ return new String[0];
+ List lines = new ArrayList();
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ new FileInputStream(file), "UTF-8")); //$NON-NLS-1$
+ try {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ line = line.trim();
+ if (!"".equals(line)) //$NON-NLS-1$
+ lines.add(line);
+ }
+ } finally {
+ reader.close();
+ }
+ } catch (IOException e) {
+ CathyPlugin.log(e,
+ "Failed to read log file: " + file.getAbsolutePath()); //$NON-NLS-1$
+ }
+ return lines.toArray(new String[lines.size()]);
+ }
+
+ public void setContents(String... contents) {
+ write(false, contents);
+ }
+
+ public void append(String... lines) {
+ if (lines.length == 0)
+ return;
+ write(true, lines);
+ }
+
+ private void write(boolean append, String... contents) {
+ FileUtils.ensureFileParent(file);
+ try {
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(file, append), "UTF-8")); //$NON-NLS-1$
+ try {
+ for (String line : contents) {
+ writer.write(line);
+ writer.newLine();
+ }
+ } finally {
+ writer.close();
+ }
+ } catch (IOException e) {
+ CathyPlugin.log(e,
+ "Failed to write log file: " + file.getAbsolutePath()); //$NON-NLS-1$
+ }
+ }
+
+ public void delete() {
+ file.delete();
+ properties = null;
+ }
+
+ public boolean exists() {
+ return file.exists();
+ }
+
+ public static Log get(String name) {
+ URL url = Platform.getInstanceLocation().getURL();
+ try {
+ url = FileLocator.toFileURL(url);
+ } catch (IOException e) {
+ //ignore this exception
+ }
+ File file = new File(url.getFile(), name);
+ Log log = new Log(file);
+ return log;
+ }
+
+ public static String getLineSeparator() {
+ if (lineSeparator == null)
+ lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$
+ return lineSeparator;
+ }
+
+ public boolean contains(ISchedulingRule rule) {
+ if (rule == this)
+ return true;
+ if (rule instanceof Log) {
+ Log log = (Log) rule;
+ if (log.file == null || file == null)
+ return false;
+ return log.file.getAbsolutePath().equals(file.getAbsolutePath());
+ }
+ return false;
+ }
+
+ public boolean isConflicting(ISchedulingRule rule) {
+ if (rule == this)
+ return true;
+ if (rule instanceof Log) {
+ Log log = (Log) rule;
+ if (log.file == null || file == null)
+ return false;
+ return log.file.getAbsolutePath().equals(file.getAbsolutePath());
+ }
+ return false;
+ }
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenDocumentQueue.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenDocumentQueue.java
index e2752b4bc..ef3296b9a 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenDocumentQueue.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenDocumentQueue.java
@@ -1,84 +1,84 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-
-public class OpenDocumentQueue {
-
- private static final String[] EMPTY_QUEUE = new String[0];
-
- private class OpenDocumentHook implements Listener {
-
- public void handleEvent(Event event) {
- if (event.text != null && !"".equals(event.text)) //$NON-NLS-1$
- enqueue(event.text);
- }
-
- }
-
- private static final OpenDocumentQueue instance = new OpenDocumentQueue();
-
- private List files = new ArrayList();
-
- private Listener hook = null;
-
- private OpenDocumentQueue() {
- }
-
- public void hook(Display display) {
- if (hook == null) {
- hook = new OpenDocumentHook();
- }
- display.addListener(SWT.OpenDocument, hook);
- }
-
- public void unhook(Display display) {
- if (hook != null)
- display.removeListener(SWT.OpenDocument, hook);
- }
-
- public void enqueue(String path) {
- if (new File(path).exists()) {
- synchronized (this) {
- files.add(path);
- }
- CathyPlugin.log("Path queued to be opened: " + path); //$NON-NLS-1$
- } else {
- CathyPlugin.log("Non-existing path skipped: " + path); //$NON-NLS-1$
- }
- }
-
- public String[] drain() {
- synchronized (this) {
- if (files.isEmpty())
- return EMPTY_QUEUE;
- String[] array = files.toArray(new String[files.size()]);
- files.clear();
- return array;
- }
- }
-
- public static OpenDocumentQueue getInstance() {
- return instance;
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+
+public class OpenDocumentQueue {
+
+ private static final String[] EMPTY_QUEUE = new String[0];
+
+ private class OpenDocumentHook implements Listener {
+
+ public void handleEvent(Event event) {
+ if (event.text != null && !"".equals(event.text)) //$NON-NLS-1$
+ enqueue(event.text);
+ }
+
+ }
+
+ private static final OpenDocumentQueue instance = new OpenDocumentQueue();
+
+ private List files = new ArrayList();
+
+ private Listener hook = null;
+
+ private OpenDocumentQueue() {
+ }
+
+ public void hook(Display display) {
+ if (hook == null) {
+ hook = new OpenDocumentHook();
+ }
+ display.addListener(SWT.OpenDocument, hook);
+ }
+
+ public void unhook(Display display) {
+ if (hook != null)
+ display.removeListener(SWT.OpenDocument, hook);
+ }
+
+ public void enqueue(String path) {
+ if (new File(path).exists()) {
+ synchronized (this) {
+ files.add(path);
+ }
+ CathyPlugin.log("Path queued to be opened: " + path); //$NON-NLS-1$
+ } else {
+ CathyPlugin.log("Non-existing path skipped: " + path); //$NON-NLS-1$
+ }
+ }
+
+ public String[] drain() {
+ synchronized (this) {
+ if (files.isEmpty())
+ return EMPTY_QUEUE;
+ String[] array = files.toArray(new String[files.size()]);
+ files.clear();
+ return array;
+ }
+ }
+
+ public static OpenDocumentQueue getInstance() {
+ return instance;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenFileCommandHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenFileCommandHandler.java
index 75b3bbcf9..efb93d2bd 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenFileCommandHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenFileCommandHandler.java
@@ -1,53 +1,53 @@
-package org.xmind.cathy.internal;
-
-import java.util.Collections;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.cathy.internal.jobs.DownloadAndOpenFileJob;
-import org.xmind.cathy.internal.jobs.OpenFilesJob;
-import org.xmind.core.command.ICommand;
-import org.xmind.core.command.ICommandHandler;
-
-public class OpenFileCommandHandler implements ICommandHandler {
-
- public OpenFileCommandHandler() {
- }
-
- public IStatus execute(IProgressMonitor monitor, ICommand command,
- String[] matches) {
- IWorkbench workbench = PlatformUI.getWorkbench();
- if (workbench == null)
- return null;
-
- String file = command.getArgument("file"); //$NON-NLS-1$
- if (file != null)
- return openFile(workbench, file);
-
- String url = command.getArgument("url"); //$NON-NLS-1$
- if (url != null)
- return openURL(workbench, url, command.getArgument("name")); //$NON-NLS-1$
-
- return null;
- }
-
- private IStatus openFile(IWorkbench workbench, String filePath) {
- CathyPlugin.log("Opening file through 'xmind:' protocol: " + filePath); //$NON-NLS-1$
- OpenFilesJob openFilesJob = new OpenFilesJob(workbench,
- WorkbenchMessages.CheckOpenFilesJob_CheckFiles_name,
- Collections.singletonList(filePath));
- openFilesJob.setRule(Log.get(Log.OPENING));
- openFilesJob.schedule();
- return Status.OK_STATUS;
- }
-
- private IStatus openURL(IWorkbench workbench, String url, String name) {
- CathyPlugin.log("Opening URL through 'xmind:' protocol: " + url); //$NON-NLS-1$
- new DownloadAndOpenFileJob(workbench, url, name).schedule();
- return Status.OK_STATUS;
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.util.Collections;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.cathy.internal.jobs.DownloadAndOpenFileJob;
+import org.xmind.cathy.internal.jobs.OpenFilesJob;
+import org.xmind.core.command.ICommand;
+import org.xmind.core.command.ICommandHandler;
+
+public class OpenFileCommandHandler implements ICommandHandler {
+
+ public OpenFileCommandHandler() {
+ }
+
+ public IStatus execute(IProgressMonitor monitor, ICommand command,
+ String[] matches) {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ if (workbench == null)
+ return null;
+
+ String file = command.getArgument("file"); //$NON-NLS-1$
+ if (file != null)
+ return openFile(workbench, file);
+
+ String url = command.getArgument("url"); //$NON-NLS-1$
+ if (url != null)
+ return openURL(workbench, url, command.getArgument("name")); //$NON-NLS-1$
+
+ return null;
+ }
+
+ private IStatus openFile(IWorkbench workbench, String filePath) {
+ CathyPlugin.log("Opening file through 'xmind:' protocol: " + filePath); //$NON-NLS-1$
+ OpenFilesJob openFilesJob = new OpenFilesJob(workbench,
+ WorkbenchMessages.CheckOpenFilesJob_CheckFiles_name,
+ Collections.singletonList(filePath));
+ openFilesJob.setRule(Log.get(Log.OPENING));
+ openFilesJob.schedule();
+ return Status.OK_STATUS;
+ }
+
+ private IStatus openURL(IWorkbench workbench, String url, String name) {
+ CathyPlugin.log("Opening URL through 'xmind:' protocol: " + url); //$NON-NLS-1$
+ new DownloadAndOpenFileJob(workbench, url, name).schedule();
+ return Status.OK_STATUS;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenFilesProcess.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenFilesProcess.java
index 1a6d0f9ae..9d2823b8a 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenFilesProcess.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/OpenFilesProcess.java
@@ -1,198 +1,198 @@
-package org.xmind.cathy.internal;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.xmind.cathy.internal.jobs.OpenXMindCommandFileJob;
-import org.xmind.core.IWorkbook;
-import org.xmind.core.command.Command;
-import org.xmind.core.command.CommandJob;
-import org.xmind.core.command.ICommand;
-import org.xmind.core.util.FileUtils;
-import org.xmind.ui.internal.MarkerImpExpUtils;
-import org.xmind.ui.internal.editor.ClonedWorkbookRef;
-import org.xmind.ui.internal.imports.freemind.FreeMindImporter;
-import org.xmind.ui.internal.imports.mm.MindManagerImporter;
-import org.xmind.ui.internal.prefs.MarkerManagerPrefPage;
-import org.xmind.ui.mindmap.IWorkbookRef;
-import org.xmind.ui.mindmap.MindMapUI;
-import org.xmind.ui.util.PrefUtils;
-import org.xmind.ui.wizards.MindMapImporter;
-
-public class OpenFilesProcess extends AbstractCheckFilesProcess {
-
- private List filesToOpen;
-
- private boolean markersImported = false;
-
- private List commandFilesToOpen = new ArrayList(1);
-
- public OpenFilesProcess(IWorkbench workbench) {
- super(workbench);
- this.filesToOpen = new ArrayList();
- }
-
- /**
- *
- */
- public OpenFilesProcess(IWorkbench workbench, Collection files) {
- super(workbench);
- this.filesToOpen = new ArrayList(files);
- }
-
- public void doCheckAndOpenFiles() {
- filterFilesToOpen(filesToOpen);
-
- if (filesToOpen.isEmpty()) {
-
- } else {
- addEditors();
- openEditors(true);
- }
-
- onFilsOpened();
- }
-
- /**
- *
- */
- protected void onFilsOpened() {
- if (markersImported)
- showMarkersPrefPage();
- if (!commandFilesToOpen.isEmpty()) {
- openXMindCommandFiles();
- }
- }
-
- /**
- * Filters the files to open. Subclasses may add/remove files to/from the
- * `filesToOpen` list.
- *
- * @param monitor
- */
- protected void filterFilesToOpen(List filesToOpen) {
- }
-
- /**
- * Add editors to open.
- *
- * @param monitor
- */
- protected void addEditors() {
- for (final String fileName : filesToOpen) {
- SafeRunner.run(new SafeRunnable(NLS.bind(
- WorkbenchMessages.CheckOpenFilesJob_FailsToOpen_message,
- fileName)) {
- public void run() throws Exception {
- IEditorInput input = createEditorInput(fileName);
- if (input != null) {
- addEditorToOpen(input);
- }
- }
- });
- }
- }
-
- /**
- * Create an editor input from the file, or do anything to open the file.
- *
- * @param fileName
- * @param monitor
- * @return
- * @throws Exception
- */
- protected IEditorInput createEditorInput(String fileName) throws Exception {
- final ICommand command = Command.parseURI(fileName);
- if (command != null) {
- new CommandJob(command, null).schedule();
- return null;
- }
-
- final String path = fileName;
- String extension = FileUtils.getExtension(path);
-
- if (CathyPlugin.COMMAND_FILE_EXT.equalsIgnoreCase(extension)) {
- return openXMindCommandFile(path);
- } else if (MindMapUI.FILE_EXT_TEMPLATE.equalsIgnoreCase(extension)) {
- return newFromTemplate(path, fileName);
- } else if (".mmap".equalsIgnoreCase(extension)) { //$NON-NLS-1$
- return importMindManagerFile(path, fileName);
- } else if (".mm".equalsIgnoreCase(extension)) { //$NON-NLS-1$
- return importFreeMindFile(path, fileName);
- } else if (MindMapUI.FILE_EXT_MARKER_PACKAGE
- .equalsIgnoreCase(extension)) {
- return importMarkers(path);
- } else {
- // assumes we're opening xmind files
- return MindMapUI.getEditorInputFactory()
- .createEditorInputForFile(new File(path));
- }
- }
-
- protected IEditorInput newFromTemplate(String path, String fileName)
- throws Exception {
- IWorkbookRef ref = ClonedWorkbookRef
- .createFromSourceWorkbookURI(new File(path).toURI());
- return MindMapUI.getEditorInputFactory().createEditorInput(ref);
- }
-
- protected IEditorInput importMindManagerFile(String path, String fileName)
- throws Exception {
- MindMapImporter importer = new MindManagerImporter(path);
- importer.build();
- IWorkbook workbook = importer.getTargetWorkbook();
- return workbook == null ? null
- : MindMapUI.getEditorInputFactory()
- .createEditorInputForPreLoadedWorkbook(workbook,
- fileName);
- }
-
- protected IEditorInput importFreeMindFile(String path, String fileName)
- throws Exception {
- FreeMindImporter importer = new FreeMindImporter(path);
- importer.build();
- IWorkbook workbook = importer.getTargetWorkbook();
- return workbook == null ? null
- : MindMapUI.getEditorInputFactory()
- .createEditorInputForPreLoadedWorkbook(workbook,
- fileName);
- }
-
- protected IEditorInput importMarkers(String path) throws Exception {
- MarkerImpExpUtils.importMarkerPackage(path);
- markersImported = true;
- return null;
- }
-
- private void showMarkersPrefPage() {
- Display display = getWorkbench().getDisplay();
- if (display == null || display.isDisposed())
- return;
-
- display.asyncExec(new Runnable() {
- public void run() {
- PrefUtils.openPrefDialog(null, MarkerManagerPrefPage.ID);
- }
- });
- }
-
- private IEditorInput openXMindCommandFile(String path) {
- commandFilesToOpen.add(path);
- return null;
- }
-
- private void openXMindCommandFiles() {
- for (String path : commandFilesToOpen) {
- new OpenXMindCommandFileJob(path).schedule(500);
- }
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.xmind.cathy.internal.jobs.OpenXMindCommandFileJob;
+import org.xmind.core.IWorkbook;
+import org.xmind.core.command.Command;
+import org.xmind.core.command.CommandJob;
+import org.xmind.core.command.ICommand;
+import org.xmind.core.util.FileUtils;
+import org.xmind.ui.internal.MarkerImpExpUtils;
+import org.xmind.ui.internal.editor.ClonedWorkbookRef;
+import org.xmind.ui.internal.imports.freemind.FreeMindImporter;
+import org.xmind.ui.internal.imports.mm.MindManagerImporter;
+import org.xmind.ui.internal.prefs.MarkerManagerPrefPage;
+import org.xmind.ui.mindmap.IWorkbookRef;
+import org.xmind.ui.mindmap.MindMapUI;
+import org.xmind.ui.util.PrefUtils;
+import org.xmind.ui.wizards.MindMapImporter;
+
+public class OpenFilesProcess extends AbstractCheckFilesProcess {
+
+ private List filesToOpen;
+
+ private boolean markersImported = false;
+
+ private List commandFilesToOpen = new ArrayList(1);
+
+ public OpenFilesProcess(IWorkbench workbench) {
+ super(workbench);
+ this.filesToOpen = new ArrayList();
+ }
+
+ /**
+ *
+ */
+ public OpenFilesProcess(IWorkbench workbench, Collection files) {
+ super(workbench);
+ this.filesToOpen = new ArrayList(files);
+ }
+
+ public void doCheckAndOpenFiles() {
+ filterFilesToOpen(filesToOpen);
+
+ if (filesToOpen.isEmpty()) {
+
+ } else {
+ addEditors();
+ openEditors(true);
+ }
+
+ onFilsOpened();
+ }
+
+ /**
+ *
+ */
+ protected void onFilsOpened() {
+ if (markersImported)
+ showMarkersPrefPage();
+ if (!commandFilesToOpen.isEmpty()) {
+ openXMindCommandFiles();
+ }
+ }
+
+ /**
+ * Filters the files to open. Subclasses may add/remove files to/from the
+ * `filesToOpen` list.
+ *
+ * @param monitor
+ */
+ protected void filterFilesToOpen(List filesToOpen) {
+ }
+
+ /**
+ * Add editors to open.
+ *
+ * @param monitor
+ */
+ protected void addEditors() {
+ for (final String fileName : filesToOpen) {
+ SafeRunner.run(new SafeRunnable(NLS.bind(
+ WorkbenchMessages.CheckOpenFilesJob_FailsToOpen_message,
+ fileName)) {
+ public void run() throws Exception {
+ IEditorInput input = createEditorInput(fileName);
+ if (input != null) {
+ addEditorToOpen(input);
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * Create an editor input from the file, or do anything to open the file.
+ *
+ * @param fileName
+ * @param monitor
+ * @return
+ * @throws Exception
+ */
+ protected IEditorInput createEditorInput(String fileName) throws Exception {
+ final ICommand command = Command.parseURI(fileName);
+ if (command != null) {
+ new CommandJob(command, null).schedule();
+ return null;
+ }
+
+ final String path = fileName;
+ String extension = FileUtils.getExtension(path);
+
+ if (CathyPlugin.COMMAND_FILE_EXT.equalsIgnoreCase(extension)) {
+ return openXMindCommandFile(path);
+ } else if (MindMapUI.FILE_EXT_TEMPLATE.equalsIgnoreCase(extension)) {
+ return newFromTemplate(path, fileName);
+ } else if (".mmap".equalsIgnoreCase(extension)) { //$NON-NLS-1$
+ return importMindManagerFile(path, fileName);
+ } else if (".mm".equalsIgnoreCase(extension)) { //$NON-NLS-1$
+ return importFreeMindFile(path, fileName);
+ } else if (MindMapUI.FILE_EXT_MARKER_PACKAGE
+ .equalsIgnoreCase(extension)) {
+ return importMarkers(path);
+ } else {
+ // assumes we're opening xmind files
+ return MindMapUI.getEditorInputFactory()
+ .createEditorInputForFile(new File(path));
+ }
+ }
+
+ protected IEditorInput newFromTemplate(String path, String fileName)
+ throws Exception {
+ IWorkbookRef ref = ClonedWorkbookRef
+ .createFromSourceWorkbookURI(new File(path).toURI(), fileName);
+ return MindMapUI.getEditorInputFactory().createEditorInput(ref);
+ }
+
+ protected IEditorInput importMindManagerFile(String path, String fileName)
+ throws Exception {
+ MindMapImporter importer = new MindManagerImporter(path);
+ importer.build();
+ IWorkbook workbook = importer.getTargetWorkbook();
+ return workbook == null ? null
+ : MindMapUI.getEditorInputFactory()
+ .createEditorInputForPreLoadedWorkbook(workbook,
+ fileName);
+ }
+
+ protected IEditorInput importFreeMindFile(String path, String fileName)
+ throws Exception {
+ FreeMindImporter importer = new FreeMindImporter(path);
+ importer.build();
+ IWorkbook workbook = importer.getTargetWorkbook();
+ return workbook == null ? null
+ : MindMapUI.getEditorInputFactory()
+ .createEditorInputForPreLoadedWorkbook(workbook,
+ fileName);
+ }
+
+ protected IEditorInput importMarkers(String path) throws Exception {
+ MarkerImpExpUtils.importMarkerPackage(path);
+ markersImported = true;
+ return null;
+ }
+
+ private void showMarkersPrefPage() {
+ Display display = getWorkbench().getDisplay();
+ if (display == null || display.isDisposed())
+ return;
+
+ display.asyncExec(new Runnable() {
+ public void run() {
+ PrefUtils.openPrefDialog(null, MarkerManagerPrefPage.ID);
+ }
+ });
+ }
+
+ private IEditorInput openXMindCommandFile(String path) {
+ commandFilesToOpen.add(path);
+ return null;
+ }
+
+ private void openXMindCommandFiles() {
+ for (String path : commandFilesToOpen) {
+ new OpenXMindCommandFileJob(path).schedule(500);
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/RecentFilePropertyTester.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/RecentFilePropertyTester.java
index c0c8803e5..a609e91b2 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/RecentFilePropertyTester.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/RecentFilePropertyTester.java
@@ -1,40 +1,40 @@
-package org.xmind.cathy.internal;
-
-import java.net.URI;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.ui.editor.IEditorHistory;
-
-public class RecentFilePropertyTester extends PropertyTester {
-
- private static final String P_ISPINNED = "isPinned"; //$NON-NLS-1$
-
- public boolean test(Object receiver, String property, Object[] args,
- Object expectedValue) {
- Assert.isLegal(receiver instanceof URI);
- IEditorHistory editorHistory = PlatformUI.getWorkbench()
- .getService(IEditorHistory.class);
- Assert.isLegal(editorHistory != null);
- return testTag(editorHistory, (URI) receiver, property, expectedValue);
- }
-
- private boolean testTag(IEditorHistory editorHistory, URI receiver,
- String property, Object expectedValue) {
- if (P_ISPINNED.equals(property)) {
- boolean actualValue = editorHistory.isPinned(receiver);
- if (expectedValue == null || "".equals(expectedValue)) { //$NON-NLS-1$
- return actualValue;
- } else if (expectedValue instanceof Boolean) {
- return ((Boolean) expectedValue) == actualValue;
- } else if (expectedValue instanceof String) {
- return Boolean
- .parseBoolean((String) expectedValue) == actualValue;
- }
- }
- Assert.isLegal(false, "Unrecognized value: " + expectedValue); //$NON-NLS-1$
- return false;
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.net.URI;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.ui.editor.IEditorHistory;
+
+public class RecentFilePropertyTester extends PropertyTester {
+
+ private static final String P_ISPINNED = "isPinned"; //$NON-NLS-1$
+
+ public boolean test(Object receiver, String property, Object[] args,
+ Object expectedValue) {
+ Assert.isLegal(receiver instanceof URI);
+ IEditorHistory editorHistory = PlatformUI.getWorkbench()
+ .getService(IEditorHistory.class);
+ Assert.isLegal(editorHistory != null);
+ return testTag(editorHistory, (URI) receiver, property, expectedValue);
+ }
+
+ private boolean testTag(IEditorHistory editorHistory, URI receiver,
+ String property, Object expectedValue) {
+ if (P_ISPINNED.equals(property)) {
+ boolean actualValue = editorHistory.isPinned(receiver);
+ if (expectedValue == null || "".equals(expectedValue)) { //$NON-NLS-1$
+ return actualValue;
+ } else if (expectedValue instanceof Boolean) {
+ return ((Boolean) expectedValue) == actualValue;
+ } else if (expectedValue instanceof String) {
+ return Boolean
+ .parseBoolean((String) expectedValue) == actualValue;
+ }
+ }
+ Assert.isLegal(false, "Unrecognized value: " + expectedValue); //$NON-NLS-1$
+ return false;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/RecentFilesPreferencePageSection.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/RecentFilesPreferencePageSection.java
index ace785d33..8484a9a91 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/RecentFilesPreferencePageSection.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/RecentFilesPreferencePageSection.java
@@ -1,68 +1,68 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.preference.ComboFieldEditor;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.eclipse.ui.internal.IPreferenceConstants;
-import org.eclipse.ui.internal.WorkbenchPlugin;
-import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
-
-public class RecentFilesPreferencePageSection extends
- PreferenceFieldEditorPageSection implements IWorkbenchPreferencePage {
-
- private String[][] filesList = new String[][] { { "10", "10" }, //$NON-NLS-1$//$NON-NLS-2$
- { "20", "20" }, //$NON-NLS-1$ //$NON-NLS-2$
- { "50", "50" } }; //$NON-NLS-1$//$NON-NLS-2$
-
- private Composite container;
- private ComboFieldEditor recentFilesField;
-
- @Override
- protected Control createContents(Composite parent) {
- if (null == container)
- this.container = parent;
- return super.createContents(parent);
- }
-
- @Override
- protected void createFieldEditors() {
- addRecentFileCountSection(container);
- this.initialize();
- }
-
- protected IPreferenceStore doGetPreferenceStore() {
- return CathyPlugin.getDefault().getPreferenceStore();
- }
-
- private void addRecentFileCountSection(Composite parent) {
-
- Composite container = new Composite(parent, SWT.NONE);
- GridDataFactory.fillDefaults().indent(25, 0).applyTo(container);
- GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
-
- addField(recentFilesField = new ComboFieldEditor(
- IPreferenceConstants.RECENT_FILES,
- WorkbenchMessages.RecentFiles_label, filesList, container));
- }
-
- @Override
- protected void initialize() {
- recentFilesField.setPreferenceStore(
- WorkbenchPlugin.getDefault().getPreferenceStore());
- recentFilesField.load();
- }
-
- @Override
- public void init(IWorkbench workbench) {
-// WorkbenchPlugin.getDefault().getPreferenceStore().setDefault(
-// IPreferenceConstants.RECENT_FILES, DEFAULT_RECENT_VALUE);
- super.init(workbench);
- }
-
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.internal.IPreferenceConstants;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
+
+public class RecentFilesPreferencePageSection extends
+ PreferenceFieldEditorPageSection implements IWorkbenchPreferencePage {
+
+ private String[][] filesList = new String[][] { { "10", "10" }, //$NON-NLS-1$//$NON-NLS-2$
+ { "20", "20" }, //$NON-NLS-1$ //$NON-NLS-2$
+ { "50", "50" } }; //$NON-NLS-1$//$NON-NLS-2$
+
+ private Composite container;
+ private ComboFieldEditor recentFilesField;
+
+ @Override
+ protected Control createContents(Composite parent) {
+ if (null == container)
+ this.container = parent;
+ return super.createContents(parent);
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ addRecentFileCountSection(container);
+ this.initialize();
+ }
+
+ protected IPreferenceStore doGetPreferenceStore() {
+ return CathyPlugin.getDefault().getPreferenceStore();
+ }
+
+ private void addRecentFileCountSection(Composite parent) {
+
+ Composite container = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().indent(25, 0).applyTo(container);
+ GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
+
+ addField(recentFilesField = new ComboFieldEditor(
+ IPreferenceConstants.RECENT_FILES,
+ WorkbenchMessages.RecentFiles_label, filesList, container));
+ }
+
+ @Override
+ protected void initialize() {
+ recentFilesField.setPreferenceStore(
+ WorkbenchPlugin.getDefault().getPreferenceStore());
+ recentFilesField.load();
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+// WorkbenchPlugin.getDefault().getPreferenceStore().setDefault(
+// IPreferenceConstants.RECENT_FILES, DEFAULT_RECENT_VALUE);
+ super.init(workbench);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/SaveBackupPreferencePageSection.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/SaveBackupPreferencePageSection.java
index 8940d08f1..4559ae49c 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/SaveBackupPreferencePageSection.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/SaveBackupPreferencePageSection.java
@@ -1,131 +1,131 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.preference.BooleanFieldEditor;
-import org.eclipse.jface.preference.ComboFieldEditor;
-import org.eclipse.jface.preference.FieldEditor;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.xmind.ui.internal.MindMapUIPlugin;
-import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
-import org.xmind.ui.prefs.PrefConstants;
-
-public class SaveBackupPreferencePageSection extends
- PreferenceFieldEditorPageSection implements IWorkbenchPreferencePage {
-
- private String[][] saveIntervals = new String[][] { { "5", "5" }, //$NON-NLS-1$//$NON-NLS-2$
- { "10", "10" }, //$NON-NLS-1$//$NON-NLS-2$
- { "30", "30" }, { "60", "60" } }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
-
- private Composite container;
-
- private FieldEditor autoSaveInterval;
-
- private boolean autoBackup = true;
-
- private BooleanFieldEditor autoBackupField;
-
- private Composite autoSaveIntervalsParent;
-
- @Override
- protected Control createContents(Composite parent) {
- if (null == container)
- this.container = parent;
- return super.createContents(parent);
- }
-
- protected IPreferenceStore doGetPreferenceStore() {
- return CathyPlugin.getDefault().getPreferenceStore();
- }
-
- @Override
- protected void initialize() {
- super.initialize();
- autoBackupField.setPreferenceStore(
- MindMapUIPlugin.getDefault().getPreferenceStore());
- autoBackupField.load();
- }
-
- @Override
- protected void createFieldEditors() {
- addAutoSaveGroup(container);
- this.initialize();
- }
-
- private void addAutoSaveGroup(Composite parent) {
- String message = WorkbenchMessages.AutoSave_label2;
- int index = message.indexOf("{0}"); //$NON-NLS-1$
- String label1, label2;
- label1 = message.substring(0, index);
- label2 = message.substring(index + 3);
- if (null != saveIntervals) {
- for (String[] interval : saveIntervals) {
- interval[0] += " " + label2; //$NON-NLS-1$
- }
- }
-
- Composite container = new Composite(parent, SWT.NONE);
- GridDataFactory.fillDefaults().applyTo(container);
- GridLayoutFactory.fillDefaults().extendedMargins(23, 0, 0, 0)
- .applyTo(container);
-
- Composite saveParent = createContainer(container, 2);
- Composite enableParent = createContainer(saveParent, 1);
- addField(new BooleanFieldEditor(CathyPlugin.AUTO_SAVE_ENABLED, label1,
- enableParent));
-
- autoSaveIntervalsParent = createContainer(saveParent, 1);
- autoSaveInterval = new ComboFieldEditor(CathyPlugin.AUTO_SAVE_INTERVALS,
- "", saveIntervals, autoSaveIntervalsParent); //$NON-NLS-1$
- addField(autoSaveInterval);
-
- autoSaveInterval.setEnabled(
- getPreferenceStore().getBoolean(CathyPlugin.AUTO_SAVE_ENABLED),
- autoSaveIntervalsParent);
-
- Composite boolParent = createContainer(container, 1);
- autoBackupField = new BooleanFieldEditor(
- PrefConstants.AUTO_BACKUP_ENABLE,
- WorkbenchMessages.AutoBackup_label, boolParent);
- autoBackupField.setPropertyChangeListener(this);
-
- }
-
- private Composite createContainer(Composite parent, int cols) {
- Composite container = new Composite(parent, SWT.NONE);
- GridDataFactory.fillDefaults().applyTo(container);
- GridLayoutFactory.fillDefaults().numColumns(cols).applyTo(container);
-
- return container;
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- if (event.getSource() instanceof FieldEditor) {
- FieldEditor fe = (FieldEditor) event.getSource();
- if (event.getProperty().equals(FieldEditor.VALUE)) {
- String prefName = fe.getPreferenceName();
- if (CathyPlugin.AUTO_SAVE_ENABLED.equals(prefName)) {
- autoSaveInterval.setEnabled(
- ((Boolean) event.getNewValue()).booleanValue(),
- autoSaveIntervalsParent);
- } else if (PrefConstants.AUTO_BACKUP_ENABLE.equals(prefName)) {
- autoBackup = ((Boolean) event.getNewValue()).booleanValue();
- }
- }
- }
- }
-
- @Override
- public boolean performOk() {
- if (!super.performOk())
- return false;
- MindMapUIPlugin.getDefault().getPreferenceStore()
- .setValue(PrefConstants.AUTO_BACKUP_ENABLE, autoBackup);
- return true;
- }
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.xmind.ui.internal.MindMapUIPlugin;
+import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
+import org.xmind.ui.prefs.PrefConstants;
+
+public class SaveBackupPreferencePageSection extends
+ PreferenceFieldEditorPageSection implements IWorkbenchPreferencePage {
+
+ private String[][] saveIntervals = new String[][] { { "5", "5" }, //$NON-NLS-1$//$NON-NLS-2$
+ { "10", "10" }, //$NON-NLS-1$//$NON-NLS-2$
+ { "30", "30" }, { "60", "60" } }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
+
+ private Composite container;
+
+ private FieldEditor autoSaveInterval;
+
+ private boolean autoBackup = true;
+
+ private BooleanFieldEditor autoBackupField;
+
+ private Composite autoSaveIntervalsParent;
+
+ @Override
+ protected Control createContents(Composite parent) {
+ if (null == container)
+ this.container = parent;
+ return super.createContents(parent);
+ }
+
+ protected IPreferenceStore doGetPreferenceStore() {
+ return CathyPlugin.getDefault().getPreferenceStore();
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ autoBackupField.setPreferenceStore(
+ MindMapUIPlugin.getDefault().getPreferenceStore());
+ autoBackupField.load();
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ addAutoSaveGroup(container);
+ this.initialize();
+ }
+
+ private void addAutoSaveGroup(Composite parent) {
+ String message = WorkbenchMessages.AutoSave_label2;
+ int index = message.indexOf("{0}"); //$NON-NLS-1$
+ String label1, label2;
+ label1 = message.substring(0, index);
+ label2 = message.substring(index + 3);
+ if (null != saveIntervals) {
+ for (String[] interval : saveIntervals) {
+ interval[0] += " " + label2; //$NON-NLS-1$
+ }
+ }
+
+ Composite container = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().applyTo(container);
+ GridLayoutFactory.fillDefaults().extendedMargins(23, 0, 0, 0)
+ .applyTo(container);
+
+ Composite saveParent = createContainer(container, 2);
+ Composite enableParent = createContainer(saveParent, 1);
+ addField(new BooleanFieldEditor(CathyPlugin.AUTO_SAVE_ENABLED, label1,
+ enableParent));
+
+ autoSaveIntervalsParent = createContainer(saveParent, 1);
+ autoSaveInterval = new ComboFieldEditor(CathyPlugin.AUTO_SAVE_INTERVALS,
+ "", saveIntervals, autoSaveIntervalsParent); //$NON-NLS-1$
+ addField(autoSaveInterval);
+
+ autoSaveInterval.setEnabled(
+ getPreferenceStore().getBoolean(CathyPlugin.AUTO_SAVE_ENABLED),
+ autoSaveIntervalsParent);
+
+ Composite boolParent = createContainer(container, 1);
+ autoBackupField = new BooleanFieldEditor(
+ PrefConstants.AUTO_BACKUP_ENABLE,
+ WorkbenchMessages.AutoBackup_label, boolParent);
+ autoBackupField.setPropertyChangeListener(this);
+
+ }
+
+ private Composite createContainer(Composite parent, int cols) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().applyTo(container);
+ GridLayoutFactory.fillDefaults().numColumns(cols).applyTo(container);
+
+ return container;
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getSource() instanceof FieldEditor) {
+ FieldEditor fe = (FieldEditor) event.getSource();
+ if (event.getProperty().equals(FieldEditor.VALUE)) {
+ String prefName = fe.getPreferenceName();
+ if (CathyPlugin.AUTO_SAVE_ENABLED.equals(prefName)) {
+ autoSaveInterval.setEnabled(
+ ((Boolean) event.getNewValue()).booleanValue(),
+ autoSaveIntervalsParent);
+ } else if (PrefConstants.AUTO_BACKUP_ENABLE.equals(prefName)) {
+ autoBackup = ((Boolean) event.getNewValue()).booleanValue();
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean performOk() {
+ if (!super.performOk())
+ return false;
+ MindMapUIPlugin.getDefault().getPreferenceStore()
+ .setValue(PrefConstants.AUTO_BACKUP_ENABLE, autoBackup);
+ return true;
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/SaveCommandLabelUpdater.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/SaveCommandLabelUpdater.java
index 3a821a1f8..b26cd53c7 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/SaveCommandLabelUpdater.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/SaveCommandLabelUpdater.java
@@ -1,262 +1,262 @@
-
-package org.xmind.cathy.internal;
-
-import javax.inject.Inject;
-
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.eclipse.e4.core.di.extensions.EventTopic;
-import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.e4.ui.model.application.ui.menu.MItem;
-import org.eclipse.e4.ui.workbench.UIEvents;
-import org.eclipse.e4.ui.workbench.modeling.EModelService;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IPartListener;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.osgi.service.event.Event;
-import org.xmind.core.Core;
-import org.xmind.core.IMeta;
-import org.xmind.core.IWorkbook;
-import org.xmind.core.event.CoreEvent;
-import org.xmind.core.event.ICoreEventListener;
-import org.xmind.core.event.ICoreEventRegistration;
-import org.xmind.core.event.ICoreEventSource;
-import org.xmind.ui.internal.MindMapMessages;
-
-public class SaveCommandLabelUpdater
- implements IPartListener, IPropertyListener, ICoreEventListener {
-
- private static final String DATA_ORIGINAL_TEXT = "SaveCommandLabelUpdater:OriginalText"; //$NON-NLS-1$
- private static final String DATA_ORIGINAL_TOOLTIP = "SaveCommandLabelUpdater:OriginalTooltip"; //$NON-NLS-1$
-
- @Inject
- private EModelService modelService;
-
- @Inject
- private Display display;
-
- private MWindow activeWindow = null;
- private IEditorPart activeEditor = null;
- private IWorkbook editingWorkbook = null;
- private ICoreEventRegistration metadataEventRegistration = null;
-
- private void updateSaveCommandLabel() {
- if (this.activeWindow == null)
- return;
-
- String text;
- String tooltip;
- if (this.editingWorkbook != null
- && isAutoGeneratingRevision(this.editingWorkbook)) {
- text = MindMapMessages.SaveNewRevision_text;
- tooltip = MindMapMessages.SaveNewRevision_tooltip;
- } else {
- text = null;
- tooltip = null;
- }
-
- MItem item = findItem(this.activeWindow.getMainMenu(),
- ICathyConstants.ID_MENU_ITEM_SAVE);
- if (item != null) {
- if (text == null) {
- if (item.getTransientData().containsKey(DATA_ORIGINAL_TEXT)) {
- item.setLabel((String) item.getTransientData()
- .get(DATA_ORIGINAL_TEXT));
- }
- } else {
- if (!item.getTransientData().containsKey(DATA_ORIGINAL_TEXT)) {
- item.getTransientData().put(DATA_ORIGINAL_TEXT,
- item.getLabel());
- }
- item.setLabel(text);
- }
- }
-
- item = findItem(this.activeWindow, ICathyConstants.ID_TOOL_ITEM_SAVE);
- if (item != null) {
- if (tooltip == null) {
- if (item.getTransientData()
- .containsKey(DATA_ORIGINAL_TOOLTIP)) {
- item.setTooltip((String) item.getTransientData()
- .get(DATA_ORIGINAL_TOOLTIP));
- }
- } else {
- if (!item.getTransientData()
- .containsKey(DATA_ORIGINAL_TOOLTIP)) {
- item.getTransientData().put(DATA_ORIGINAL_TOOLTIP,
- item.getTooltip());
- }
- item.setTooltip(tooltip);
- }
- }
- }
-
- @Inject
- @Optional
- public void applicationStarted(
- @EventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event,
- @Optional final MApplication app) {
- if (app == null)
- return;
-
- if (display == null || display.isDisposed())
- return;
-
- display.syncExec(new Runnable() {
- public void run() {
- MWindow window = app.getSelectedElement();
- setActiveWindow(window);
- updateSaveCommandLabel();
- }
- });
- }
-
- @Inject
- @Optional
- public void windowChanged(
- @EventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) Event event) {
- Object selectedElement = event
- .getProperty(UIEvents.ElementContainer.SELECTEDELEMENT);
- if (!(selectedElement instanceof MWindow))
- return;
-
- setActiveWindow((MWindow) selectedElement);
- updateSaveCommandLabel();
- }
-
- public void partActivated(IWorkbenchPart part) {
- setActiveEditor(findActiveEditorFrom(part));
- updateSaveCommandLabel();
- }
-
- public void partBroughtToTop(IWorkbenchPart part) {
- }
-
- public void partClosed(IWorkbenchPart part) {
- setActiveEditor(findActiveEditorFrom(part));
- updateSaveCommandLabel();
- }
-
- public void partDeactivated(IWorkbenchPart part) {
- }
-
- public void partOpened(IWorkbenchPart part) {
- }
-
- public void propertyChanged(Object source, int propId) {
- if (propId == IEditorPart.PROP_INPUT) {
- setEditingWorkbook(findWorkbookIn(this.activeEditor));
- updateSaveCommandLabel();
- }
- }
-
- public void handleCoreEvent(CoreEvent event) {
- if (IMeta.CONFIG_AUTO_REVISION_GENERATION.equals(event.getTarget())) {
- if (display != null) {
- display.syncExec(new Runnable() {
- public void run() {
- updateSaveCommandLabel();
- }
- });
- }
- }
- }
-
- private void setActiveWindow(MWindow window) {
- if (window != this.activeWindow) {
- if (this.activeWindow != null) {
- IWorkbenchWindow wbWindow = this.activeWindow.getContext()
- .get(IWorkbenchWindow.class);
- if (wbWindow != null)
- wbWindow.getPartService().removePartListener(this);
- }
- this.activeWindow = window;
- if (this.activeWindow != null) {
- IWorkbenchWindow wbWindow = this.activeWindow.getContext()
- .get(IWorkbenchWindow.class);
- if (wbWindow != null)
- wbWindow.getPartService().addPartListener(this);
- }
- }
- setActiveEditor(findActiveEditorIn(this.activeWindow));
- }
-
- private void setActiveEditor(IEditorPart editor) {
- if (editor != this.activeEditor) {
- if (this.activeEditor != null)
- this.activeEditor.removePropertyListener(this);
- this.activeEditor = editor;
- if (this.activeEditor != null)
- this.activeEditor.addPropertyListener(this);
- }
- setEditingWorkbook(findWorkbookIn(editor));
- }
-
- private void setEditingWorkbook(IWorkbook workbook) {
- if (workbook != this.editingWorkbook) {
- if (this.metadataEventRegistration != null) {
- this.metadataEventRegistration.unregister();
- this.metadataEventRegistration = null;
- }
- this.editingWorkbook = workbook;
- if (this.editingWorkbook != null && this.editingWorkbook
- .getMeta() instanceof ICoreEventSource) {
- this.metadataEventRegistration = ((ICoreEventSource) this.editingWorkbook
- .getMeta()).registerCoreEventListener(Core.Metadata,
- this);
- }
- }
- }
-
- private IEditorPart findActiveEditorFrom(IWorkbenchPart referencePart) {
- if (referencePart == null)
- return null;
-
- IWorkbenchWindow window = referencePart.getSite().getWorkbenchWindow();
- return findActiveEditorIn(window);
- }
-
- private IEditorPart findActiveEditorIn(MWindow window) {
- if (window == null)
- return null;
- IWorkbenchWindow wbWindow = window.getContext()
- .get(IWorkbenchWindow.class);
- return findActiveEditorIn(wbWindow);
- }
-
- private IEditorPart findActiveEditorIn(IWorkbenchWindow window) {
- if (window == null)
- return null;
- IWorkbenchPage page = window.getActivePage();
- if (page == null)
- return null;
- return page.getActiveEditor();
- }
-
- private IWorkbook findWorkbookIn(IEditorPart editor) {
- if (editor == null)
- return null;
- return editor.getAdapter(IWorkbook.class);
- }
-
- private MItem findItem(MUIElement rootElement, String id) {
- if (this.modelService == null || rootElement == null)
- return null;
- MUIElement element = this.modelService.find(id, rootElement);
- if (!(element instanceof MItem))
- return null;
- return (MItem) element;
- }
-
- private static final boolean isAutoGeneratingRevision(IWorkbook workbook) {
- String value = workbook.getMeta()
- .getValue(IMeta.CONFIG_AUTO_REVISION_GENERATION);
- return value == null || IMeta.V_YES.equalsIgnoreCase(value);
- }
-
-}
+
+package org.xmind.cathy.internal;
+
+import javax.inject.Inject;
+
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.core.di.extensions.EventTopic;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.model.application.ui.menu.MItem;
+import org.eclipse.e4.ui.workbench.UIEvents;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.osgi.service.event.Event;
+import org.xmind.core.Core;
+import org.xmind.core.IMeta;
+import org.xmind.core.IWorkbook;
+import org.xmind.core.event.CoreEvent;
+import org.xmind.core.event.ICoreEventListener;
+import org.xmind.core.event.ICoreEventRegistration;
+import org.xmind.core.event.ICoreEventSource;
+import org.xmind.ui.internal.MindMapMessages;
+
+public class SaveCommandLabelUpdater
+ implements IPartListener, IPropertyListener, ICoreEventListener {
+
+ private static final String DATA_ORIGINAL_TEXT = "SaveCommandLabelUpdater:OriginalText"; //$NON-NLS-1$
+ private static final String DATA_ORIGINAL_TOOLTIP = "SaveCommandLabelUpdater:OriginalTooltip"; //$NON-NLS-1$
+
+ @Inject
+ private EModelService modelService;
+
+ @Inject
+ private Display display;
+
+ private MWindow activeWindow = null;
+ private IEditorPart activeEditor = null;
+ private IWorkbook editingWorkbook = null;
+ private ICoreEventRegistration metadataEventRegistration = null;
+
+ private void updateSaveCommandLabel() {
+ if (this.activeWindow == null)
+ return;
+
+ String text;
+ String tooltip;
+ if (this.editingWorkbook != null
+ && isAutoGeneratingRevision(this.editingWorkbook)) {
+ text = MindMapMessages.SaveNewRevision_text;
+ tooltip = MindMapMessages.SaveNewRevision_tooltip;
+ } else {
+ text = null;
+ tooltip = null;
+ }
+
+ MItem item = findItem(this.activeWindow.getMainMenu(),
+ ICathyConstants.ID_MENU_ITEM_SAVE);
+ if (item != null) {
+ if (text == null) {
+ if (item.getTransientData().containsKey(DATA_ORIGINAL_TEXT)) {
+ item.setLabel((String) item.getTransientData()
+ .get(DATA_ORIGINAL_TEXT));
+ }
+ } else {
+ if (!item.getTransientData().containsKey(DATA_ORIGINAL_TEXT)) {
+ item.getTransientData().put(DATA_ORIGINAL_TEXT,
+ item.getLabel());
+ }
+ item.setLabel(text);
+ }
+ }
+
+ item = findItem(this.activeWindow, ICathyConstants.ID_TOOL_ITEM_SAVE);
+ if (item != null) {
+ if (tooltip == null) {
+ if (item.getTransientData()
+ .containsKey(DATA_ORIGINAL_TOOLTIP)) {
+ item.setTooltip((String) item.getTransientData()
+ .get(DATA_ORIGINAL_TOOLTIP));
+ }
+ } else {
+ if (!item.getTransientData()
+ .containsKey(DATA_ORIGINAL_TOOLTIP)) {
+ item.getTransientData().put(DATA_ORIGINAL_TOOLTIP,
+ item.getTooltip());
+ }
+ item.setTooltip(tooltip);
+ }
+ }
+ }
+
+ @Inject
+ @Optional
+ public void applicationStarted(
+ @EventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event,
+ @Optional final MApplication app) {
+ if (app == null)
+ return;
+
+ if (display == null || display.isDisposed())
+ return;
+
+ display.syncExec(new Runnable() {
+ public void run() {
+ MWindow window = app.getSelectedElement();
+ setActiveWindow(window);
+ updateSaveCommandLabel();
+ }
+ });
+ }
+
+ @Inject
+ @Optional
+ public void windowChanged(
+ @EventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) Event event) {
+ Object selectedElement = event
+ .getProperty(UIEvents.ElementContainer.SELECTEDELEMENT);
+ if (!(selectedElement instanceof MWindow))
+ return;
+
+ setActiveWindow((MWindow) selectedElement);
+ updateSaveCommandLabel();
+ }
+
+ public void partActivated(IWorkbenchPart part) {
+ setActiveEditor(findActiveEditorFrom(part));
+ updateSaveCommandLabel();
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part) {
+ }
+
+ public void partClosed(IWorkbenchPart part) {
+ setActiveEditor(findActiveEditorFrom(part));
+ updateSaveCommandLabel();
+ }
+
+ public void partDeactivated(IWorkbenchPart part) {
+ }
+
+ public void partOpened(IWorkbenchPart part) {
+ }
+
+ public void propertyChanged(Object source, int propId) {
+ if (propId == IEditorPart.PROP_INPUT) {
+ setEditingWorkbook(findWorkbookIn(this.activeEditor));
+ updateSaveCommandLabel();
+ }
+ }
+
+ public void handleCoreEvent(CoreEvent event) {
+ if (IMeta.CONFIG_AUTO_REVISION_GENERATION.equals(event.getTarget())) {
+ if (display != null) {
+ display.syncExec(new Runnable() {
+ public void run() {
+ updateSaveCommandLabel();
+ }
+ });
+ }
+ }
+ }
+
+ private void setActiveWindow(MWindow window) {
+ if (window != this.activeWindow) {
+ if (this.activeWindow != null) {
+ IWorkbenchWindow wbWindow = this.activeWindow.getContext()
+ .get(IWorkbenchWindow.class);
+ if (wbWindow != null)
+ wbWindow.getPartService().removePartListener(this);
+ }
+ this.activeWindow = window;
+ if (this.activeWindow != null) {
+ IWorkbenchWindow wbWindow = this.activeWindow.getContext()
+ .get(IWorkbenchWindow.class);
+ if (wbWindow != null)
+ wbWindow.getPartService().addPartListener(this);
+ }
+ }
+ setActiveEditor(findActiveEditorIn(this.activeWindow));
+ }
+
+ private void setActiveEditor(IEditorPart editor) {
+ if (editor != this.activeEditor) {
+ if (this.activeEditor != null)
+ this.activeEditor.removePropertyListener(this);
+ this.activeEditor = editor;
+ if (this.activeEditor != null)
+ this.activeEditor.addPropertyListener(this);
+ }
+ setEditingWorkbook(findWorkbookIn(editor));
+ }
+
+ private void setEditingWorkbook(IWorkbook workbook) {
+ if (workbook != this.editingWorkbook) {
+ if (this.metadataEventRegistration != null) {
+ this.metadataEventRegistration.unregister();
+ this.metadataEventRegistration = null;
+ }
+ this.editingWorkbook = workbook;
+ if (this.editingWorkbook != null && this.editingWorkbook
+ .getMeta() instanceof ICoreEventSource) {
+ this.metadataEventRegistration = ((ICoreEventSource) this.editingWorkbook
+ .getMeta()).registerCoreEventListener(Core.Metadata,
+ this);
+ }
+ }
+ }
+
+ private IEditorPart findActiveEditorFrom(IWorkbenchPart referencePart) {
+ if (referencePart == null)
+ return null;
+
+ IWorkbenchWindow window = referencePart.getSite().getWorkbenchWindow();
+ return findActiveEditorIn(window);
+ }
+
+ private IEditorPart findActiveEditorIn(MWindow window) {
+ if (window == null)
+ return null;
+ IWorkbenchWindow wbWindow = window.getContext()
+ .get(IWorkbenchWindow.class);
+ return findActiveEditorIn(wbWindow);
+ }
+
+ private IEditorPart findActiveEditorIn(IWorkbenchWindow window) {
+ if (window == null)
+ return null;
+ IWorkbenchPage page = window.getActivePage();
+ if (page == null)
+ return null;
+ return page.getActiveEditor();
+ }
+
+ private IWorkbook findWorkbookIn(IEditorPart editor) {
+ if (editor == null)
+ return null;
+ return editor.getAdapter(IWorkbook.class);
+ }
+
+ private MItem findItem(MUIElement rootElement, String id) {
+ if (this.modelService == null || rootElement == null)
+ return null;
+ MUIElement element = this.modelService.find(id, rootElement);
+ if (!(element instanceof MItem))
+ return null;
+ return (MItem) element;
+ }
+
+ private static final boolean isAutoGeneratingRevision(IWorkbook workbook) {
+ String value = workbook.getMeta()
+ .getValue(IMeta.CONFIG_AUTO_REVISION_GENERATION);
+ return value == null || IMeta.V_YES.equalsIgnoreCase(value);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ServiceManager.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ServiceManager.java
index e90271e22..7b3abd20a 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ServiceManager.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ServiceManager.java
@@ -1,125 +1,125 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2016 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-/**
- *
- */
-package org.xmind.cathy.internal;
-
-import org.xmind.core.licensing.ILicenseAgent;
-import org.xmind.core.usagedata.IUsageDataSampler;
-import org.xmind.ui.internal.statushandlers.IErrorReporter;
-
-/**
- * @author Frank Shaka
- *
- */
-public class ServiceManager {
-
- private boolean active;
-
- private IErrorReporter errorReporter;
-
- private IUsageDataSampler usageDataSampler;
-
- private ILicenseAgent licenseAgent;
-
- private CathyPlugin plugin;
-
- /**
- *
- */
- public ServiceManager() {
- this.active = false;
- this.errorReporter = null;
- this.usageDataSampler = null;
- this.licenseAgent = null;
- this.plugin = CathyPlugin.getDefault();
- }
-
- public void activate() {
- if (active)
- return;
-
- plugin.setUsageDataCollector(usageDataSampler);
- plugin.setErrorReporter(errorReporter);
- plugin.setLicenseAgent(licenseAgent);
-
- active = true;
- }
-
- public void deactivate() {
- if (!active)
- return;
-
- plugin.setUsageDataCollector(null);
- plugin.setErrorReporter(null);
- plugin.setLicenseAgent(null);
-
- active = false;
- }
-
- public void setErrorReporter(IErrorReporter reporter) {
- this.errorReporter = reporter;
-
- if (active) {
- plugin.setErrorReporter(reporter);
- }
- }
-
- public void unsetErrorReporter(IErrorReporter reporter) {
- if (reporter != this.errorReporter)
- return;
- this.errorReporter = null;
- if (active) {
- plugin.setErrorReporter(null);
- }
- }
-
- /**
- * @param sampler
- * the usageDataSampler to set
- */
- public void setUsageDataSampler(IUsageDataSampler sampler) {
- this.usageDataSampler = sampler;
- if (active) {
- plugin.setUsageDataCollector(sampler);
- }
- }
-
- public void unsetUsageDataSampler(IUsageDataSampler sampler) {
- if (sampler == this.usageDataSampler)
- return;
- this.usageDataSampler = null;
- if (active) {
- plugin.setUsageDataCollector(null);
- }
- }
-
- public void setLicenseAgent(ILicenseAgent agent) {
- this.licenseAgent = agent;
- if (active) {
- plugin.setLicenseAgent(agent);
- }
- }
-
- public void unsetLicenseAgent(ILicenseAgent agent) {
- if (agent == this.licenseAgent)
- return;
- this.licenseAgent = null;
- if (active) {
- plugin.setLicenseAgent(null);
- }
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2016 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+/**
+ *
+ */
+package org.xmind.cathy.internal;
+
+import org.xmind.core.licensing.ILicenseAgent;
+import org.xmind.core.usagedata.IUsageDataSampler;
+import org.xmind.ui.internal.statushandlers.IErrorReporter;
+
+/**
+ * @author Frank Shaka
+ *
+ */
+public class ServiceManager {
+
+ private boolean active;
+
+ private IErrorReporter errorReporter;
+
+ private IUsageDataSampler usageDataSampler;
+
+ private ILicenseAgent licenseAgent;
+
+ private CathyPlugin plugin;
+
+ /**
+ *
+ */
+ public ServiceManager() {
+ this.active = false;
+ this.errorReporter = null;
+ this.usageDataSampler = null;
+ this.licenseAgent = null;
+ this.plugin = CathyPlugin.getDefault();
+ }
+
+ public void activate() {
+ if (active)
+ return;
+
+ plugin.setUsageDataCollector(usageDataSampler);
+ plugin.setErrorReporter(errorReporter);
+ plugin.setLicenseAgent(licenseAgent);
+
+ active = true;
+ }
+
+ public void deactivate() {
+ if (!active)
+ return;
+
+ plugin.setUsageDataCollector(null);
+ plugin.setErrorReporter(null);
+ plugin.setLicenseAgent(null);
+
+ active = false;
+ }
+
+ public void setErrorReporter(IErrorReporter reporter) {
+ this.errorReporter = reporter;
+
+ if (active) {
+ plugin.setErrorReporter(reporter);
+ }
+ }
+
+ public void unsetErrorReporter(IErrorReporter reporter) {
+ if (reporter != this.errorReporter)
+ return;
+ this.errorReporter = null;
+ if (active) {
+ plugin.setErrorReporter(null);
+ }
+ }
+
+ /**
+ * @param sampler
+ * the usageDataSampler to set
+ */
+ public void setUsageDataSampler(IUsageDataSampler sampler) {
+ this.usageDataSampler = sampler;
+ if (active) {
+ plugin.setUsageDataCollector(sampler);
+ }
+ }
+
+ public void unsetUsageDataSampler(IUsageDataSampler sampler) {
+ if (sampler == this.usageDataSampler)
+ return;
+ this.usageDataSampler = null;
+ if (active) {
+ plugin.setUsageDataCollector(null);
+ }
+ }
+
+ public void setLicenseAgent(ILicenseAgent agent) {
+ this.licenseAgent = agent;
+ if (active) {
+ plugin.setLicenseAgent(agent);
+ }
+ }
+
+ public void unsetLicenseAgent(ILicenseAgent agent) {
+ if (agent == this.licenseAgent)
+ return;
+ this.licenseAgent = null;
+ if (active) {
+ plugin.setLicenseAgent(null);
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ShowWelcomeService.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ShowWelcomeService.java
index 17e38ab5c..4d5b8f4ce 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ShowWelcomeService.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/ShowWelcomeService.java
@@ -1,87 +1,87 @@
-package org.xmind.cathy.internal;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-import org.eclipse.ui.IStartup;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.core.util.FileUtils;
-
-/**
- *
- * @author Shawn Liu
- * @since 3.6.50
- */
-public class ShowWelcomeService implements IStartup {
-
- private static final boolean DEBUG_NOT_SHOW_WELCOME = CathyPlugin
- .getDefault().isDebugging("/debug/notshowwelcome"); //$NON-NLS-1$
-
- private static final String NO_FIRST_START = System
- .getProperty("org.xmind.product.buildid") //$NON-NLS-1$
- + ".noFirstStart"; //$NON-NLS-1$
-
- public void earlyStartup() {
- if (DEBUG_NOT_SHOW_WELCOME) {
- return;
- }
-
- final File propertiesFile = new File(getPropertiesFilePath());
- if (!propertiesFile.exists()) {
- FileUtils.ensureFileParent(propertiesFile);
- try {
- propertiesFile.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- final Properties properties = new Properties();
- try {
- properties.load(new FileInputStream(propertiesFile));
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- boolean isNotFirstStart = Boolean
- .valueOf(properties.getProperty(NO_FIRST_START));
-
- if (!isNotFirstStart) {
- final IWorkbench workbench = PlatformUI.getWorkbench();
- workbench.getDisplay().asyncExec(new Runnable() {
- public void run() {
- IWorkbenchWindow window = workbench
- .getActiveWorkbenchWindow();
- if (window != null) {
- new WelcomeDialog(window.getShell()).open();
-
- //set value to properties file.
- properties.setProperty(NO_FIRST_START,
- Boolean.toString(true));
- try {
- properties.store(
- new FileOutputStream(propertiesFile), null);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- });
- }
- }
-
- private String getPropertiesFilePath() {
- return CathyPlugin.getDefault().getStateLocation()
- .append("start.properties").toString(); //$NON-NLS-1$
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.eclipse.ui.IStartup;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.core.util.FileUtils;
+
+/**
+ *
+ * @author Shawn Liu
+ * @since 3.6.50
+ */
+public class ShowWelcomeService implements IStartup {
+
+ private static final boolean DEBUG_NOT_SHOW_WELCOME = CathyPlugin
+ .getDefault().isDebugging("/debug/notshowwelcome"); //$NON-NLS-1$
+
+ private static final String NO_FIRST_START = System
+ .getProperty("org.xmind.product.buildid") //$NON-NLS-1$
+ + ".noFirstStart"; //$NON-NLS-1$
+
+ public void earlyStartup() {
+ if (DEBUG_NOT_SHOW_WELCOME) {
+ return;
+ }
+
+ final File propertiesFile = new File(getPropertiesFilePath());
+ if (!propertiesFile.exists()) {
+ FileUtils.ensureFileParent(propertiesFile);
+ try {
+ propertiesFile.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ final Properties properties = new Properties();
+ try {
+ properties.load(new FileInputStream(propertiesFile));
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ boolean isNotFirstStart = Boolean
+ .valueOf(properties.getProperty(NO_FIRST_START));
+
+ if (!isNotFirstStart) {
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ workbench.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = workbench
+ .getActiveWorkbenchWindow();
+ if (window != null) {
+ new WelcomeDialog(window.getShell()).open();
+
+ //set value to properties file.
+ properties.setProperty(NO_FIRST_START,
+ Boolean.toString(true));
+ try {
+ properties.store(
+ new FileOutputStream(propertiesFile), null);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ });
+ }
+ }
+
+ private String getPropertiesFilePath() {
+ return CathyPlugin.getDefault().getStateLocation()
+ .append("start.properties").toString(); //$NON-NLS-1$
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/StartUpProcess.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/StartUpProcess.java
index 8aea5b567..d73111f0f 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/StartUpProcess.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/StartUpProcess.java
@@ -1,210 +1,240 @@
-package org.xmind.cathy.internal;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.e4.ui.workbench.modeling.EModelService;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.WorkbenchException;
-import org.eclipse.ui.XMLMemento;
-import org.eclipse.ui.internal.IWorkbenchConstants;
-import org.eclipse.ui.internal.WorkbenchPlugin;
-import org.xmind.cathy.internal.dashboard.DashboardAutomationAddon;
-import org.xmind.ui.internal.MindMapUIPlugin;
-import org.xmind.ui.mindmap.IWorkbookRef;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class StartUpProcess {
-
- private static final boolean DEBUG_CHECK_OPEN_FILE = CathyPlugin
- .getDefault().isDebugging("/debug/checkopenfile"); //$NON-NLS-1$
-
- private IWorkbench workbench;
-
- public StartUpProcess(IWorkbench workbench) {
- this.workbench = workbench;
- }
-
- public void startUp() {
- checkAndRecoverFiles();
-
- if (DEBUG_CHECK_OPEN_FILE) {
- checkAndOpenFiles();
- } else {
- //delete file paths which need to open from command line
- Log openFile = Log.get(Log.OPENING);
- if (openFile.exists())
- openFile.delete();
- }
- openStartupMap();
-
- Display display = workbench.getDisplay();
- if (display != null && !display.isDisposed()) {
- display.asyncExec(new Runnable() {
- public void run() {
- System.setProperty("org.xmind.cathy.app.status", //$NON-NLS-1$
- "workbenchReady"); //$NON-NLS-1$
- }
- });
- }
- }
-
- private void checkAndOpenFiles() {
- new CheckOpenFilesProcess(workbench).doCheckAndOpenFiles();
- }
-
- private void checkAndRecoverFiles() {
- SafeRunner.run(new SafeRunnable() {
- public void run() throws Exception {
- new EditorStatePersistance(workbench,
- CathyPlugin.getDefault().getStateLocation(),
- CathyPlugin.getDefault().getLogger(),
- CathyPlugin.getDefault().getDebugValue(
- CathyPlugin.OPTION_AUTO_SAVE_EDITOR_STATE_INTERVALS,
- CathyPlugin.AUTO_SAVE_EDITOR_STATE_INTERVALS))
- .startUp();
- }
- });
- }
-
- private void openStartupMap() {
- if (!hasOpenedEditors()) {
- int action = CathyPlugin.getDefault().getPreferenceStore()
- .getInt(CathyPlugin.STARTUP_ACTION);
- if (action == CathyPlugin.STARTUP_ACTION_LAST) {
- doOpenLastSession();
- }
- if (!hasOpenedEditors()) {
- doOpenDashboard();
- }
- }
- }
-
- private void doOpenDashboard() {
- final EModelService modelService = workbench
- .getService(EModelService.class);
- final MApplication application = workbench
- .getService(MApplication.class);
- if (modelService == null || application == null)
- return;
-
- final DashboardAutomationAddon automator = new DashboardAutomationAddon();
- automator.setModelService(modelService);
- automator.setApplication(application);
- workbench.getDisplay().asyncExec(new Runnable() {
- public void run() {
- for (MWindow window : application.getChildren()) {
- automator.showDashboard(window);
- }
- }
- });
- }
-
- private void doOpenLastSession() {
- IPath editorStatusPath = WorkbenchPlugin.getDefault().getDataLocation()
- .append("XMind_Editors.xml"); //$NON-NLS-1$
- //open unclosed editors in the last session.
- final File stateFile = editorStatusPath.toFile();
- if (stateFile.exists())
- workbench.getDisplay().syncExec(new Runnable() {
- public void run() {
- SafeRunner.run(new SafeRunnable() {
- public void run() throws Exception {
- IWorkbenchWindow window = workbench
- .getActiveWorkbenchWindow();
- if (window != null) {
- IWorkbenchPage page = window.getActivePage();
- if (page != null) {
- openUnclosedMapLastSession(stateFile, page);
- }
- }
- }
- });
- }
- });
- }
-
- private void openUnclosedMapLastSession(File statusFile,
- final IWorkbenchPage page)
- throws FileNotFoundException, UnsupportedEncodingException,
- WorkbenchException, CoreException, PartInitException {
- FileInputStream input = new FileInputStream(statusFile);
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(input, "utf-8")); //$NON-NLS-1$
- IMemento memento = XMLMemento.createReadRoot(reader);
- IMemento childMem = memento.getChild(IWorkbenchConstants.TAG_EDITORS);
- IMemento[] childrenEditor = childMem
- .getChildren(IWorkbenchConstants.TAG_EDITOR);
- IEditorPart activeEditorPart = null;
- for (IMemento childEditor : childrenEditor) {
- IMemento inputMemeto = childEditor.getChild("input"); //$NON-NLS-1$
- if (inputMemeto == null)
- continue;
-
- String uri = inputMemeto.getString("uri"); //$NON-NLS-1$
- if (uri != null) {
- IWorkbookRef workbookRef = null;
- try {
- workbookRef = MindMapUIPlugin.getDefault()
- .getWorkbookRefFactory()
- .createWorkbookRef(new URI(uri), null);
- } catch (URISyntaxException e) {
- e.printStackTrace();
- }
- if (workbookRef != null) {
- IEditorInput editorInput = MindMapUI.getEditorInputFactory()
- .createEditorInput(workbookRef);
- IEditorPart editorPart = page.openEditor(editorInput,
- MindMapUI.MINDMAP_EDITOR_ID);
- if ("true".equals(childEditor //$NON-NLS-1$
- .getString(IWorkbenchConstants.TAG_ACTIVE_PART))) {
- activeEditorPart = editorPart;
- }
- }
- }
- }
- if (activeEditorPart != null) {
- page.activate(activeEditorPart);
- }
- }
-
- private boolean hasOpenedEditors() {
- final boolean[] ret = new boolean[1];
- ret[0] = false;
- workbench.getDisplay().syncExec(new Runnable() {
- public void run() {
- for (IWorkbenchWindow window : workbench
- .getWorkbenchWindows()) {
- IWorkbenchPage page = window.getActivePage();
- if (page != null) {
- if (page.getEditorReferences().length > 0) {
- ret[0] = true;
- return;
- }
- }
- }
- }
- });
- return ret[0];
- }
-
-}
+package org.xmind.cathy.internal;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.ui.internal.IWorkbenchConstants;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.xmind.cathy.internal.dashboard.DashboardAutomationAddon;
+import org.xmind.ui.internal.MindMapUIPlugin;
+import org.xmind.ui.mindmap.IWorkbookRef;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class StartUpProcess {
+
+ private static final boolean DEBUG_CHECK_OPEN_FILE = CathyPlugin
+ .getDefault().isDebugging("/debug/checkopenfile"); //$NON-NLS-1$
+
+ private IWorkbench workbench;
+
+ public StartUpProcess(IWorkbench workbench) {
+ this.workbench = workbench;
+ }
+
+ public void startUp() {
+ hideRightStack();
+ checkAndRecoverFiles();
+
+ if (DEBUG_CHECK_OPEN_FILE) {
+ checkAndOpenFiles();
+ } else {
+ //delete file paths which need to open from command line
+ Log openFile = Log.get(Log.OPENING);
+ if (openFile.exists())
+ openFile.delete();
+ }
+ openStartupMap();
+
+ Display display = workbench.getDisplay();
+ if (display != null && !display.isDisposed()) {
+ display.asyncExec(new Runnable() {
+ public void run() {
+ System.setProperty("org.xmind.cathy.app.status", //$NON-NLS-1$
+ "workbenchReady"); //$NON-NLS-1$
+ }
+ });
+ }
+ }
+
+ private void hideRightStack() {
+ MApplication application = workbench.getService(MApplication.class);
+ for (MWindow window : application.getChildren()) {
+ DashboardAutomationAddon.hideVisiblePart(window,
+ "org.xmind.ui.stack.right"); //$NON-NLS-1$
+ }
+ }
+
+ private void checkAndOpenFiles() {
+ new CheckOpenFilesProcess(workbench).doCheckAndOpenFiles();
+ }
+
+ private void checkAndRecoverFiles() {
+ SafeRunner.run(new SafeRunnable() {
+ public void run() throws Exception {
+ new EditorStatePersistance(workbench,
+ CathyPlugin.getDefault().getStateLocation(),
+ CathyPlugin.getDefault().getLogger(),
+ CathyPlugin.getDefault().getDebugValue(
+ CathyPlugin.OPTION_AUTO_SAVE_EDITOR_STATE_INTERVALS,
+ CathyPlugin.AUTO_SAVE_EDITOR_STATE_INTERVALS))
+ .startUp();
+ }
+ });
+ }
+
+ private void openStartupMap() {
+ if (!hasOpenedEditors()) {
+ int action = CathyPlugin.getDefault().getPreferenceStore()
+ .getInt(CathyPlugin.STARTUP_ACTION);
+ if (action == CathyPlugin.STARTUP_ACTION_LAST) {
+ doOpenLastSession();
+ }
+ if (!hasOpenedEditors()) {
+ closeOpenedDashboard();
+ }
+ }
+ }
+
+ private void doOpenDashboard() {
+ final EModelService modelService = workbench
+ .getService(EModelService.class);
+ final MApplication application = workbench
+ .getService(MApplication.class);
+ if (modelService == null || application == null)
+ return;
+
+ final DashboardAutomationAddon automator = new DashboardAutomationAddon();
+ automator.setModelService(modelService);
+ automator.setApplication(application);
+ workbench.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ for (MWindow window : application.getChildren()) {
+ automator.showDashboard(window);
+ }
+ }
+ });
+ }
+
+ private void closeOpenedDashboard() {
+ final EModelService modelService = workbench
+ .getService(EModelService.class);
+ final MApplication application = workbench
+ .getService(MApplication.class);
+ if (modelService == null || application == null)
+ return;
+
+ workbench.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ for (MWindow window : application.getChildren()) {
+ if (window.getTags()
+ .contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
+ window.getTags()
+ .remove(ICathyConstants.TAG_SHOW_DASHBOARD);
+ }
+ }
+ }
+ });
+ }
+
+ private void doOpenLastSession() {
+ IPath editorStatusPath = WorkbenchPlugin.getDefault().getDataLocation()
+ .append("XMind_Editors.xml"); //$NON-NLS-1$
+ //open unclosed editors in the last session.
+ final File stateFile = editorStatusPath.toFile();
+ if (stateFile.exists())
+ workbench.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ SafeRunner.run(new SafeRunnable() {
+ public void run() throws Exception {
+ IWorkbenchWindow window = workbench
+ .getActiveWorkbenchWindow();
+ if (window != null) {
+ IWorkbenchPage page = window.getActivePage();
+ if (page != null) {
+ openUnclosedMapLastSession(stateFile, page);
+ }
+ }
+ }
+ });
+ }
+ });
+ }
+
+ private void openUnclosedMapLastSession(File statusFile,
+ final IWorkbenchPage page)
+ throws FileNotFoundException, UnsupportedEncodingException,
+ WorkbenchException, CoreException, PartInitException {
+ FileInputStream input = new FileInputStream(statusFile);
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(input, "utf-8")); //$NON-NLS-1$
+ IMemento memento = XMLMemento.createReadRoot(reader);
+ IMemento childMem = memento.getChild(IWorkbenchConstants.TAG_EDITORS);
+ IMemento[] childrenEditor = childMem
+ .getChildren(IWorkbenchConstants.TAG_EDITOR);
+ IEditorPart activeEditorPart = null;
+ for (IMemento childEditor : childrenEditor) {
+ IMemento inputMemeto = childEditor.getChild("input"); //$NON-NLS-1$
+ if (inputMemeto == null)
+ continue;
+
+ String uri = inputMemeto.getString("uri"); //$NON-NLS-1$
+ if (uri != null) {
+ IWorkbookRef workbookRef = null;
+ try {
+ workbookRef = MindMapUIPlugin.getDefault()
+ .getWorkbookRefFactory()
+ .createWorkbookRef(new URI(uri), null);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ if (workbookRef != null) {
+ IEditorInput editorInput = MindMapUI.getEditorInputFactory()
+ .createEditorInput(workbookRef);
+ IEditorPart editorPart = page.openEditor(editorInput,
+ MindMapUI.MINDMAP_EDITOR_ID);
+ if ("true".equals(childEditor //$NON-NLS-1$
+ .getString(IWorkbenchConstants.TAG_ACTIVE_PART))) {
+ activeEditorPart = editorPart;
+ }
+ }
+ }
+ }
+ if (activeEditorPart != null) {
+ page.activate(activeEditorPart);
+ }
+ }
+
+ private boolean hasOpenedEditors() {
+ final boolean[] ret = new boolean[1];
+ ret[0] = false;
+ workbench.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ for (IWorkbenchWindow window : workbench
+ .getWorkbenchWindows()) {
+ IWorkbenchPage page = window.getActivePage();
+ if (page != null) {
+ if (page.getEditorReferences().length > 0) {
+ ret[0] = true;
+ return;
+ }
+ }
+ }
+ }
+ });
+ return ret[0];
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/StartupPreferencePageSection.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/StartupPreferencePageSection.java
index 124015a71..1c54dcc65 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/StartupPreferencePageSection.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/StartupPreferencePageSection.java
@@ -1,149 +1,82 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.preference.BooleanFieldEditor;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.program.Program;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.eclipse.ui.forms.events.HyperlinkAdapter;
-import org.eclipse.ui.forms.events.HyperlinkEvent;
-import org.eclipse.ui.forms.widgets.Hyperlink;
-import org.xmind.core.usagedata.IUsageDataSampler;
-import org.xmind.core.usagedata.IUsageDataUploader;
-import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
-import org.xmind.ui.resources.ColorUtils;
-
-public class StartupPreferencePageSection extends
- PreferenceFieldEditorPageSection implements IWorkbenchPreferencePage {
-
- private Composite container;
- private Button startupActionButton;
-
- private LocalResourceManager resources;
-
- @Override
- protected Control createContents(Composite parent) {
- if (null == container)
- this.container = parent;
- return super.createContents(parent);
- }
-
- protected IPreferenceStore doGetPreferenceStore() {
- return CathyPlugin.getDefault().getPreferenceStore();
- }
-
- @Override
- protected void initialize() {
- super.initialize();
- int startupAction = getPreferenceStore()
- .getInt(CathyPlugin.STARTUP_ACTION);
- startupActionButton
- .setSelection(startupAction == CathyPlugin.STARTUP_ACTION_LAST);
- }
-
- @Override
- public void createControl(Composite parent) {
- resources = new LocalResourceManager(JFaceResources.getResources(),
- parent);
- super.createControl(parent);
- }
-
- @Override
- protected void createFieldEditors() {
- addStartupGroup(container);
- addSendUsageDataGroup(container);
- this.initialize();
- }
-
- private void addStartupGroup(Composite parent) {
-
- Composite container = new Composite(parent, SWT.NONE);
- GridLayoutFactory.fillDefaults().applyTo(container);
- GridDataFactory.fillDefaults().indent(25, 0).applyTo(container);
-
- startupActionButton = new Button(container, SWT.CHECK);
- startupActionButton.setText(WorkbenchMessages.RestoreLastSession_label);
- addField(new BooleanFieldEditor(CathyPlugin.CHECK_UPDATES_ON_STARTUP,
- WorkbenchMessages.CheckUpdates_label, container));
- }
-
- private void addSendUsageDataGroup(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- GridDataFactory.fillDefaults().indent(25, 0).applyTo(composite);
- GridLayoutFactory.fillDefaults().numColumns(2).spacing(5, 0)
- .applyTo(composite);
-
- Composite composite2 = new Composite(composite, SWT.NONE);
- composite2.setLayoutData(
- new GridData(SWT.LEFT, SWT.CENTER, false, false));
- GridLayoutFactory.fillDefaults().applyTo(composite2);
-
- addField(new BooleanFieldEditor(
- CathyPlugin.USAGE_DATA_UPLOADING_ENABLED,
- WorkbenchMessages.GeneralPrefPage_usageData_text, composite2));
-
- //
- Hyperlink privacyHyperlink = new Hyperlink(composite, SWT.NONE);
- privacyHyperlink.setBackground(composite.getBackground());
- privacyHyperlink.setLayoutData(
- new GridData(SWT.LEFT, SWT.CENTER, false, false));
- privacyHyperlink
- .setText(WorkbenchMessages.GeneralPrefPage_seePolicy_link);
- privacyHyperlink.setUnderlined(true);
- privacyHyperlink.setForeground(
- (Color) resources.get(ColorUtils.toDescriptor("#006CF9"))); //$NON-NLS-1$
- privacyHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
- public void linkActivated(HyperlinkEvent e) {
- Program.launch("http://www.xmind.net/privacy/usage/"); //$NON-NLS-1$
- }
- });
-
- composite.setFocus();
-
- if (CathyPlugin.getDefault()
- .isDebugging("/debug/udc/showUploadButton")) { //$NON-NLS-1$
- Button uploadButton = new Button(composite, SWT.PUSH);
- GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER)
- .span(2, 0).indent(10, 0).minSize(100, 0)
- .applyTo(uploadButton);
- uploadButton.setBackground(composite.getBackground());
- uploadButton.setText("Upload Now"); //$NON-NLS-1$
- uploadButton.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- IUsageDataSampler sampler = CathyPlugin.getDefault()
- .getUsageDataCollector();
- if (sampler instanceof IUsageDataUploader) {
- ((IUsageDataUploader) sampler).forceUpload();
- }
- }
- });
- }
- }
-
- @Override
- public boolean performOk() {
- if (!super.performOk())
- return false;
-
- if (startupActionButton.getSelection()) {
- getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
- CathyPlugin.STARTUP_ACTION_LAST);
- } else {
- getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
- CathyPlugin.STARTUP_ACTION_WIZARD);
- }
-
- return true;
- }
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.xmind.ui.preference.PreferenceFieldEditorPageSection;
+
+public class StartupPreferencePageSection extends
+ PreferenceFieldEditorPageSection implements IWorkbenchPreferencePage {
+
+ private Composite container;
+
+ private Button startupActionButton;
+
+ @Override
+ protected Control createContents(Composite parent) {
+ if (null == container)
+ this.container = parent;
+ return super.createContents(parent);
+ }
+
+ protected IPreferenceStore doGetPreferenceStore() {
+ return CathyPlugin.getDefault().getPreferenceStore();
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ int startupAction = getPreferenceStore()
+ .getInt(CathyPlugin.STARTUP_ACTION);
+ startupActionButton
+ .setSelection(startupAction == CathyPlugin.STARTUP_ACTION_LAST);
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ addStartupGroup(container);
+ this.initialize();
+ }
+
+ private void addStartupGroup(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().applyTo(container);
+ GridDataFactory.fillDefaults().indent(25, 0).applyTo(container);
+
+ startupActionButton = new Button(container, SWT.CHECK);
+ startupActionButton.setText(WorkbenchMessages.RestoreLastSession_label);
+
+ if (isShowUploadDataCheck()) {
+ addField(
+ new BooleanFieldEditor(CathyPlugin.CHECK_UPDATES_ON_STARTUP,
+ WorkbenchMessages.CheckUpdates_label, container));
+ }
+ }
+
+ private boolean isShowUploadDataCheck() {
+ return !Boolean.getBoolean(CathyPlugin.KEY_NOT_SHOW_UPLOAD_DATA_CHECK);
+ }
+
+ @Override
+ public boolean performOk() {
+ if (!super.performOk())
+ return false;
+
+ if (startupActionButton.getSelection()) {
+ getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
+ CathyPlugin.STARTUP_ACTION_LAST);
+ } else {
+ getPreferenceStore().setValue(CathyPlugin.STARTUP_ACTION,
+ CathyPlugin.STARTUP_ACTION_WIZARD);
+ }
+
+ return true;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/UndoRedoActionToolControl.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/UndoRedoActionToolControl.java
index 10a476026..a12ca57d4 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/UndoRedoActionToolControl.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/UndoRedoActionToolControl.java
@@ -1,128 +1,128 @@
-package org.xmind.cathy.internal;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.annotation.PostConstruct;
-
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.SideValue;
-import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.ActionContributionItem;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.actions.ActionFactory;
-
-public class UndoRedoActionToolControl {
-
- private static class HandledAction extends Action
- implements IPropertyChangeListener {
-
- private IAction handler;
-
- public HandledAction(IAction handler) {
- super(handler.getText(), handler.getStyle());
- this.handler = handler;
- setId(handler.getId());
- setEnabled(handler.isEnabled());
- handler.addPropertyChangeListener(this);
- }
-
- @Override
- public void runWithEvent(Event event) {
- handler.runWithEvent(event);
- }
-
- @Override
- public void run() {
- handler.run();
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- if (event.getProperty().equals(IAction.ENABLED)) {
- Boolean bool = (Boolean) event.getNewValue();
- setEnabled(bool.booleanValue());
- } else if (event.getProperty().equals(IAction.CHECKED)) {
- Boolean bool = (Boolean) event.getNewValue();
- setChecked(bool.booleanValue());
- } else if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
- String str = (String) event.getNewValue();
- setToolTipText(str);
- }
- }
-
- }
-
- @PostConstruct
- public void createWidget(Composite parent, MToolControl toolControl,
- MWindow window) {
- int orientation = getOrientation(toolControl.getParent());
- int contributionItemMode = toolControl.getTags()
- .contains(ICathyConstants.TAG_FORCE_TEXT)
- ? ActionContributionItem.MODE_FORCE_TEXT : 0;
-
- ToolBarManager toolBarManager = new ToolBarManager(
- orientation | SWT.RIGHT | SWT.WRAP | SWT.FLAT);
-
- IWorkbenchWindow ww = window.getContext().get(IWorkbenchWindow.class);
- if (ww != null) {
- IAction undoAction = new HandledAction(
- ActionFactory.UNDO.create(ww));
- undoAction.setImageDescriptor(imageDescriptorFor("undo.png")); //$NON-NLS-1$
- ActionContributionItem undoItem = new ActionContributionItem(
- undoAction);
- undoItem.setMode(contributionItemMode);
- toolBarManager.add(undoItem);
-
- IAction redoAction = new HandledAction(
- ActionFactory.REDO.create(ww));
- redoAction.setImageDescriptor(imageDescriptorFor("redo.png")); //$NON-NLS-1$
- ActionContributionItem redoItem = new ActionContributionItem(
- redoAction);
- redoItem.setMode(contributionItemMode);
- toolBarManager.add(redoItem);
- }
-
- toolBarManager.createControl(parent);
- }
-
- private ImageDescriptor imageDescriptorFor(String iconName) {
- try {
- return ImageDescriptor.createFromURL(
- new URL("platform:/plugin/org.xmind.cathy/icons/toolbar/e/" //$NON-NLS-1$
- + iconName));
- } catch (MalformedURLException e) {
- return null;
- }
- }
-
- private int getOrientation(final MUIElement element) {
- MTrimBar trimContainer = findTrimBar(element);
- if (trimContainer != null) {
- SideValue side = trimContainer.getSide();
- if (side.getValue() == SideValue.LEFT_VALUE
- || side.getValue() == SideValue.RIGHT_VALUE) {
- return SWT.VERTICAL;
- }
- }
- return SWT.HORIZONTAL;
- }
-
- private MTrimBar findTrimBar(MUIElement element) {
- if (element == null)
- return null;
- if (element instanceof MTrimBar)
- return (MTrimBar) element;
- return findTrimBar(element.getParent());
- }
+package org.xmind.cathy.internal;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.annotation.PostConstruct;
+
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.model.application.ui.SideValue;
+import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.ActionFactory;
+
+public class UndoRedoActionToolControl {
+
+ private static class HandledAction extends Action
+ implements IPropertyChangeListener {
+
+ private IAction handler;
+
+ public HandledAction(IAction handler) {
+ super(handler.getText(), handler.getStyle());
+ this.handler = handler;
+ setId(handler.getId());
+ setEnabled(handler.isEnabled());
+ handler.addPropertyChangeListener(this);
+ }
+
+ @Override
+ public void runWithEvent(Event event) {
+ handler.runWithEvent(event);
+ }
+
+ @Override
+ public void run() {
+ handler.run();
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event.getProperty().equals(IAction.ENABLED)) {
+ Boolean bool = (Boolean) event.getNewValue();
+ setEnabled(bool.booleanValue());
+ } else if (event.getProperty().equals(IAction.CHECKED)) {
+ Boolean bool = (Boolean) event.getNewValue();
+ setChecked(bool.booleanValue());
+ } else if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
+ String str = (String) event.getNewValue();
+ setToolTipText(str);
+ }
+ }
+
+ }
+
+ @PostConstruct
+ public void createWidget(Composite parent, MToolControl toolControl,
+ MWindow window) {
+ int orientation = getOrientation(toolControl.getParent());
+ int contributionItemMode = toolControl.getTags()
+ .contains(ICathyConstants.TAG_FORCE_TEXT)
+ ? ActionContributionItem.MODE_FORCE_TEXT : 0;
+
+ ToolBarManager toolBarManager = new ToolBarManager(
+ orientation | SWT.RIGHT | SWT.WRAP | SWT.FLAT);
+
+ IWorkbenchWindow ww = window.getContext().get(IWorkbenchWindow.class);
+ if (ww != null) {
+ IAction undoAction = new HandledAction(
+ ActionFactory.UNDO.create(ww));
+ undoAction.setImageDescriptor(imageDescriptorFor("undo.png")); //$NON-NLS-1$
+ ActionContributionItem undoItem = new ActionContributionItem(
+ undoAction);
+ undoItem.setMode(contributionItemMode);
+ toolBarManager.add(undoItem);
+
+ IAction redoAction = new HandledAction(
+ ActionFactory.REDO.create(ww));
+ redoAction.setImageDescriptor(imageDescriptorFor("redo.png")); //$NON-NLS-1$
+ ActionContributionItem redoItem = new ActionContributionItem(
+ redoAction);
+ redoItem.setMode(contributionItemMode);
+ toolBarManager.add(redoItem);
+ }
+
+ toolBarManager.createControl(parent);
+ }
+
+ private ImageDescriptor imageDescriptorFor(String iconName) {
+ try {
+ return ImageDescriptor.createFromURL(
+ new URL("platform:/plugin/org.xmind.cathy/icons/toolbar/e/" //$NON-NLS-1$
+ + iconName));
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ private int getOrientation(final MUIElement element) {
+ MTrimBar trimContainer = findTrimBar(element);
+ if (trimContainer != null) {
+ SideValue side = trimContainer.getSide();
+ if (side.getValue() == SideValue.LEFT_VALUE
+ || side.getValue() == SideValue.RIGHT_VALUE) {
+ return SWT.VERTICAL;
+ }
+ }
+ return SWT.HORIZONTAL;
+ }
+
+ private MTrimBar findTrimBar(MUIElement element) {
+ if (element == null)
+ return null;
+ if (element instanceof MTrimBar)
+ return (MTrimBar) element;
+ return findTrimBar(element.getParent());
+ }
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WelcomeDialog.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WelcomeDialog.java
index 8b3698502..29d7949dc 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WelcomeDialog.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WelcomeDialog.java
@@ -1,553 +1,454 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.resource.FontDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseTrackListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.program.Program;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.forms.events.HyperlinkEvent;
-import org.eclipse.ui.forms.events.IHyperlinkListener;
-import org.eclipse.ui.forms.widgets.Hyperlink;
-import org.xmind.ui.resources.ColorUtils;
-import org.xmind.ui.resources.FontUtils;
-
-/**
- * @author Shawn Liu
- * @since 3.6.50
- */
-public class WelcomeDialog extends Dialog {
-
- private Button uploadDataCheck;
-
- private ResourceManager resources;
-
- public WelcomeDialog(Shell parent) {
- super(parent);
- setShellStyle(SWT.NO_TRIM | SWT.TOOL | SWT.APPLICATION_MODAL
- | SWT.NO_REDRAW_RESIZE);
- setBlockOnOpen(false);
- }
-
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- resources = new LocalResourceManager(JFaceResources.getResources(),
- newShell);
- }
-
- @Override
- protected Control createContents(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(
- (Color) resources.get(ColorUtils.toDescriptor("#cccccc"))); //$NON-NLS-1$
- GridData gridData = new GridData(GridData.FILL_BOTH);
- gridData.widthHint = 743;
- gridData.heightHint = 432;
- composite.setLayoutData(gridData);
-
- GridLayout gridLayout = new GridLayout(1, false);
- gridLayout.marginWidth = 1;
- gridLayout.marginHeight = 1;
- composite.setLayout(gridLayout);
-
- Composite composite2 = new Composite(composite, SWT.NONE);
- composite2.setBackground(
- (Color) resources.get(ColorUtils.toDescriptor("#ffffff"))); //$NON-NLS-1$
- GridData gridData2 = new GridData(GridData.FILL_BOTH);
- composite2.setLayoutData(gridData2);
-
- GridLayout gridLayout2 = new GridLayout(1, false);
- gridLayout2.marginWidth = 0;
- gridLayout2.marginHeight = 0;
- gridLayout2.verticalSpacing = 0;
- composite2.setLayout(gridLayout2);
-
- createTopSection(composite2);
-// createSeperator(composite2);
- createBottomSection(composite2);
-
- return composite;
- }
-
- private void createTopSection(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
- layoutData.widthHint = 740;
- layoutData.heightHint = 120;
- composite.setLayoutData(layoutData);
-
- GridLayout layout = new GridLayout(1, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- layout.verticalSpacing = 0;
- composite.setLayout(layout);
-
- createHeaderSection(composite);
- createTitleSection(composite);
- createPlaceholderComposite(composite);
- }
-
- private void createPlaceholderComposite(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
- layoutData.heightHint = 33;
- composite.setLayoutData(layoutData);
-
- GridLayout layout = new GridLayout(1, false);
- composite.setLayout(layout);
- }
-
- private void createHeaderSection(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
- composite.setLayoutData(layoutData);
-
- GridLayout layout = new GridLayout(1, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- layout.marginTop = 10;
- layout.marginRight = 10;
- composite.setLayout(layout);
-
- createCloseButtonSection(composite);
-
- //add drag function
- Listener controlMovedListener = createControlMovedListener(composite);
- composite.addListener(SWT.MouseDown, controlMovedListener);
- composite.addListener(SWT.MouseMove, controlMovedListener);
- composite.addListener(SWT.MouseUp, controlMovedListener);
- }
-
- private void createCloseButtonSection(Composite parent) {
- Composite composite2 = new Composite(parent, SWT.NONE);
- composite2.setBackground(composite2.getParent().getBackground());
- GridData layoutData2 = new GridData(SWT.RIGHT, SWT.TOP, true, true);
- composite2.setLayoutData(layoutData2);
-
- GridLayout layout2 = new GridLayout(1, false);
- layout2.marginWidth = 5;
- layout2.marginHeight = 5;
- composite2.setLayout(layout2);
-
- final Label close = new Label(composite2, SWT.RIGHT);
- close.setBackground(composite2.getBackground());
- close.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
-
- final Image focusedImage = (Image) resources.get(
- CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
- "icons/welcome/close.png")); //$NON-NLS-1$
- final Image noFocusedImage = (Image) resources.get(
- CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
- "icons/welcome/close-d.png")) //$NON-NLS-1$
- ;
-
- close.setImage(noFocusedImage);
-
- MouseTrackListener mouseTrackListener = new MouseTrackListener() {
-
- public void mouseHover(MouseEvent e) {
- }
-
- public void mouseExit(MouseEvent e) {
- close.setImage(noFocusedImage);
- }
-
- public void mouseEnter(MouseEvent e) {
- close.setImage(focusedImage);
- }
- };
-
- composite2.addMouseTrackListener(mouseTrackListener);
- close.addMouseTrackListener(mouseTrackListener);
-
- MouseListener mouseListener = new MouseListener() {
-
- public void mouseUp(MouseEvent e) {
- }
-
- public void mouseDown(MouseEvent e) {
- close(true);
- }
-
- public void mouseDoubleClick(MouseEvent e) {
- }
- };
-
- composite2.addMouseListener(mouseListener);
- close.addMouseListener(mouseListener);
- }
-
- private Listener createControlMovedListener(final Control header) {
- Listener listener = new Listener() {
- Point point = null;
- Point startLocation = null;
-
- public void handleEvent(Event event) {
- Shell shell = getShell();
-
- switch (event.type) {
- case SWT.MouseDown:
- if (getShell().isDisposed()) {
- return;
- }
- point = header.toDisplay(event.x, event.y);
- startLocation = shell.getLocation();
- break;
- case SWT.MouseMove:
- if (point == null)
- return;
- Point p2 = header.toDisplay(event.x, event.y);
- int deltaX = p2.x - point.x;
- int deltaY = p2.y - point.y;
- Rectangle rect = shell.getBounds();
- rect.x = startLocation.x + deltaX;
- rect.y = startLocation.y + deltaY;
- shell.setLocation(rect.x, rect.y);
- break;
- case SWT.MouseUp:
- point = null;
- break;
- }
- }
- };
- return listener;
- }
-
- private void createTitleSection(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, true);
- composite.setLayoutData(gridData);
-
- GridLayout layout = new GridLayout(2, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- layout.horizontalSpacing = 31;
- layout.marginLeft = 47;
- composite.setLayout(layout);
-
- Label titleLabel = new Label(composite, SWT.CENTER);
- titleLabel.setBackground(composite.getBackground());
- titleLabel.setForeground(
- (Color) resources.get(ColorUtils.toDescriptor("#4a4a4a"))); //$NON-NLS-1$
- titleLabel.setLayoutData(
- new GridData(SWT.CENTER, SWT.CENTER, false, true));
-
- FontData[] fontData = Display.getDefault().getSystemFont()
- .getFontData();
- titleLabel.setFont((Font) resources.get(FontDescriptor.createFrom(
- FontUtils.bold((FontUtils.newHeight(fontData, 30)), true))));
- titleLabel.setText(WorkbenchMessages.WelcomDialog_Welcom_title);
-
- Label title2 = new Label(composite, SWT.BOTTOM);
- title2.setBackground(composite.getBackground());
- title2.setForeground(
- (Color) resources.get(ColorUtils.toDescriptor("#4a4a4a"))); //$NON-NLS-1$
- GridData layoutData = new GridData(SWT.CENTER, SWT.BOTTOM, false, true);
- title2.setLayoutData(layoutData);
-
- title2.setFont((Font) resources.get(
- FontDescriptor.createFrom(FontUtils.newHeight(fontData, 15))));
- title2.setText(WorkbenchMessages.WelcomDialog_WhatIsNew_title);
-
-// Label imageLabel = new Label(composite, SWT.CENTER);
-// imageLabel.setBackground(composite.getBackground());
-// GridData gridData2 = new GridData(SWT.CENTER, SWT.CENTER, true, true);
-// imageLabel.setLayoutData(gridData2);
-// imageLabel.setImage((Image) resources.get(
-// CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
-// "icons/welcome/welcome-xmind-logo.png")) //$NON-NLS-1$
-// );
- }
-
-// private void createSeperator(Composite parent) {
-// Composite composite = new Composite(parent, SWT.NONE);
-// composite.setBackground(parent.getBackground());
-// GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
-// composite.setLayoutData(layoutData);
-//
-// GridLayout layout = new GridLayout(1, false);
-// layout.marginWidth = 20;
-// layout.marginHeight = 0;
-// composite.setLayout(layout);
-//
-// Composite seperator = new Composite(composite, SWT.NONE);
-// seperator.setBackground(
-// (Color) resources.get(ColorUtils.toDescriptor("#cccccc"))); //$NON-NLS-1$
-// GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
-// gridData.heightHint = 1;
-// seperator.setLayoutData(gridData);
-// seperator.setLayout(new GridLayout());
-// }
-
- private void createBottomSection(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- GridData gridData = new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(gridData);
-
- GridLayoutFactory.fillDefaults().applyTo(composite);
-
- createNewFeatureItems(composite);
- createButtonSection(composite);
- }
-
- private void createNewFeatureItems(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
- composite.setLayoutData(layoutData);
-
- GridLayout layout = new GridLayout(4, true);
- layout.marginWidth = 50;
- layout.marginHeight = 0;
- layout.horizontalSpacing = 10;
- composite.setLayout(layout);
-
- createImageItem(composite,
- (Image) resources.get(CathyPlugin.imageDescriptorFromPlugin(
- CathyPlugin.PLUGIN_ID, "icons/welcome/slide.png")) //$NON-NLS-1$
- , WorkbenchMessages.WelcomeDialog_item_slide_title,
- WorkbenchMessages.WelcomeDialog_item_slide_description,
- new Runnable() {
-
- public void run() {
- // TODO launch permalink
- }
- });
-
- createImageItem(composite,
- (Image) resources.get(CathyPlugin.imageDescriptorFromPlugin(
- CathyPlugin.PLUGIN_ID, "icons/welcome/cloud.png")) //$NON-NLS-1$
- , WorkbenchMessages.WelcomeDialog_item_cloud_title,
- WorkbenchMessages.WelcomeDialog_item_cloud_description,
- new Runnable() {
-
- public void run() {
- // TODO launch permalink
- }
- });
-
- createImageItem(composite,
- (Image) resources.get(CathyPlugin.imageDescriptorFromPlugin(
- CathyPlugin.PLUGIN_ID,
- "icons/welcome/new_workspace.png")) //$NON-NLS-1$
- , WorkbenchMessages.WelcomeDialog_item_workspace_title,
- WorkbenchMessages.WelcomeDialog_item_workspace_description,
- new Runnable() {
-
- public void run() {
- // TODO launch permalink
- }
- });
-
- createImageItem(composite,
- (Image) resources.get(CathyPlugin.imageDescriptorFromPlugin(
- CathyPlugin.PLUGIN_ID, "icons/welcome/high_dpi.png")) //$NON-NLS-1$
- , WorkbenchMessages.WelcomeDialog_item_high_dpi_title,
- WorkbenchMessages.WelcomeDialog_item_high_dpi_description,
-
- new Runnable() {
-
- public void run() {
- // TODO launch permalink
- }
- });
- }
-
- private void createImageItem(Composite parent, Image image, String title,
- String description, final Runnable action) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
- composite.setLayoutData(layoutData);
-
- GridLayoutFactory.fillDefaults().spacing(0, 20).applyTo(composite);
-
- Label imageLabel = new Label(composite, SWT.CENTER);
- imageLabel.setBackground(composite.getBackground());
- GridData gridData2 = new GridData(SWT.CENTER, SWT.TOP, true, false);
- imageLabel.setLayoutData(gridData2);
- imageLabel.setImage(image);
-// imageLabel.setCursor(
-// parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
-
- imageLabel.addMouseListener(new MouseAdapter() {
-
- @Override
- public void mouseDown(MouseEvent e) {
- action.run();
- }
- });
-
- //
- Composite composite2 = new Composite(composite, SWT.NONE);
- composite2.setBackground(composite.getBackground());
- GridData layoutData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
- composite2.setLayoutData(layoutData2);
-
- GridLayout layout2 = new GridLayout(1, false);
- layout2.marginWidth = 0;
- layout2.marginHeight = 0;
- layout2.verticalSpacing = 10;
- composite2.setLayout(layout2);
-
- FontData[] fontData = Display.getDefault().getSystemFont()
- .getFontData();
-
- Label titleLabel = new Label(composite2, SWT.NONE);
- titleLabel.setBackground(composite2.getBackground());
- titleLabel.setForeground(
- (Color) resources.get(ColorUtils.toDescriptor("#4a4a4a"))); //$NON-NLS-1$
- titleLabel.setLayoutData(
- new GridData(SWT.CENTER, SWT.CENTER, true, false));
- titleLabel.setText(title);
- titleLabel.setFont((Font) resources.get(FontDescriptor.createFrom(
- FontUtils.bold(FontUtils.newHeight(fontData, 11), true))));
-
- Label descriptionLabel = new Label(composite2, SWT.WRAP);
- descriptionLabel.setBackground(composite2.getBackground());
- descriptionLabel.setForeground(
- (Color) resources.get(ColorUtils.toDescriptor("#4a4a4a"))); //$NON-NLS-1$
- descriptionLabel
- .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- descriptionLabel.setAlignment(SWT.CENTER);
- descriptionLabel.setText(description);
- descriptionLabel.setFont((Font) resources
- .get(FontDescriptor.createFrom(FontUtils.relativeHeight(
- descriptionLabel.getFont().getFontData(), 0))));
- }
-
- private void createButtonSection(Composite parent) {
- Composite container = new Composite(parent, SWT.NONE);
- GridDataFactory.fillDefaults().applyTo(container);
- GridLayoutFactory.fillDefaults().margins(1, 1).applyTo(container);
- container.setBackground(
- (Color) resources.get(ColorUtils.toDescriptor("#e8e8e8"))); //$NON-NLS-1$
-
- Composite composite = new Composite(container, SWT.NONE);
- composite.setBackground(
- (Color) resources.get(ColorUtils.toDescriptor("#fcfcfc"))); //$NON-NLS-1$
- GridData layoutData = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
- composite.setLayoutData(layoutData);
-
- GridLayout layout = new GridLayout(2, false);
- layout.marginWidth = 27;
- layout.marginHeight = 10;
- composite.setLayout(layout);
-
- createUploadDataCheck(composite);
- createOkButton(composite);
- }
-
- private void createUploadDataCheck(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
- composite.setLayoutData(layoutData);
-
- GridLayout layout = new GridLayout(2, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- layout.horizontalSpacing = 5;
- composite.setLayout(layout);
-
- uploadDataCheck = new Button(composite, SWT.CHECK);
- uploadDataCheck.setBackground(composite.getBackground());
- GridData gridData2 = new GridData(SWT.LEFT, SWT.CENTER, false, false);
- uploadDataCheck.setLayoutData(gridData2);
- uploadDataCheck
- .setText(WorkbenchMessages.WelcomeDialog_uploadDataCheck_text);
- uploadDataCheck.setSelection(true);
-
- //
- Hyperlink privacyHyperlink = new Hyperlink(composite, SWT.NONE);
- privacyHyperlink.setBackground(composite.getBackground());
- privacyHyperlink.setLayoutData(
- new GridData(SWT.LEFT, SWT.CENTER, false, false));
- privacyHyperlink
- .setText(WorkbenchMessages.WelcomeDialog_seePolicy_link);
- privacyHyperlink.setUnderlined(true);
- privacyHyperlink.setForeground(
- (Color) resources.get(ColorUtils.toDescriptor("#006CF9"))); //$NON-NLS-1$
-
- composite.setFocus();
-
- privacyHyperlink.addHyperlinkListener(new IHyperlinkListener() {
-
- public void linkExited(HyperlinkEvent e) {
- }
-
- public void linkEntered(HyperlinkEvent e) {
- }
-
- public void linkActivated(HyperlinkEvent e) {
- Program.launch("http://www.xmind.net/privacy/usage/"); //$NON-NLS-1$
- }
- });
- }
-
- private void createOkButton(Composite parent) {
- final Button okButton = new Button(parent, SWT.PUSH);
- okButton.setBackground(parent.getBackground());
- GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, false, true);
- gridData.widthHint = 92;
- okButton.setLayoutData(gridData);
- okButton.setText(WorkbenchMessages.WelcomeDialog_okButton_text);
- okButton.setFont(
- (Font) resources.get(FontDescriptor.createFrom(FontUtils
- .relativeHeight(okButton.getFont().getFontData(), 1))));
-
- okButton.addMouseListener(new MouseListener() {
-
- public void mouseUp(MouseEvent e) {
- }
-
- public void mouseDown(MouseEvent e) {
- close(false);
- }
-
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
- }
-
- private void close(boolean restoreDefaults) {
- boolean isUploadData = true;
- if (!restoreDefaults) {
- isUploadData = uploadDataCheck.getSelection();
- }
- CathyPlugin.getDefault().getPreferenceStore().setValue(
- CathyPlugin.USAGE_DATA_UPLOADING_ENABLED, isUploadData);
-
- super.close();
- }
-
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.FontDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.xmind.ui.resources.ColorUtils;
+import org.xmind.ui.resources.FontUtils;
+
+/**
+ * @author Shawn Liu
+ * @since 3.6.50
+ */
+public class WelcomeDialog extends Dialog {
+
+ private ResourceManager resources;
+
+ public WelcomeDialog(Shell parent) {
+ super(parent);
+ setShellStyle(SWT.NO_TRIM | SWT.TOOL | SWT.APPLICATION_MODAL
+ | SWT.NO_REDRAW_RESIZE);
+ setBlockOnOpen(false);
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ resources = new LocalResourceManager(JFaceResources.getResources(),
+ newShell);
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(
+ (Color) resources.get(ColorUtils.toDescriptor("#cccccc"))); //$NON-NLS-1$
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.widthHint = 640;
+ gridData.heightHint = 410;
+ composite.setLayoutData(gridData);
+
+ GridLayout gridLayout = new GridLayout(1, false);
+ gridLayout.marginWidth = 1;
+ gridLayout.marginHeight = 1;
+ composite.setLayout(gridLayout);
+
+ Composite composite2 = new Composite(composite, SWT.NONE);
+ composite2.setBackground(
+ (Color) resources.get(ColorUtils.toDescriptor("#ffffff"))); //$NON-NLS-1$
+ GridData gridData2 = new GridData(GridData.FILL_BOTH);
+ composite2.setLayoutData(gridData2);
+
+ GridLayout gridLayout2 = new GridLayout(1, false);
+ gridLayout2.marginWidth = 0;
+ gridLayout2.marginHeight = 0;
+ gridLayout2.verticalSpacing = 0;
+ composite2.setLayout(gridLayout2);
+
+ createTopSection(composite2);
+ createBottomSection(composite2);
+
+ return composite;
+ }
+
+ private void createTopSection(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+ layoutData.widthHint = 637;
+ composite.setLayoutData(layoutData);
+
+ GridLayout layout = new GridLayout(1, false);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.verticalSpacing = 0;
+ composite.setLayout(layout);
+
+ createHeaderSection(composite);
+ createTitleSection(composite);
+ createPlaceholderComposite(composite);
+ }
+
+ private void createPlaceholderComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+ layoutData.heightHint = 33;
+ composite.setLayoutData(layoutData);
+
+ GridLayout layout = new GridLayout(1, false);
+ composite.setLayout(layout);
+ }
+
+ private void createHeaderSection(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+ composite.setLayoutData(layoutData);
+
+ GridLayout layout = new GridLayout(1, false);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.marginTop = 10;
+ layout.marginRight = 10;
+ composite.setLayout(layout);
+
+ createCloseButtonSection(composite);
+
+ //add drag function
+ Listener controlMovedListener = createControlMovedListener(composite);
+ composite.addListener(SWT.MouseDown, controlMovedListener);
+ composite.addListener(SWT.MouseMove, controlMovedListener);
+ composite.addListener(SWT.MouseUp, controlMovedListener);
+ }
+
+ private void createCloseButtonSection(Composite parent) {
+ Composite composite2 = new Composite(parent, SWT.NONE);
+ composite2.setBackground(composite2.getParent().getBackground());
+ GridData layoutData2 = new GridData(SWT.RIGHT, SWT.TOP, true, true);
+ composite2.setLayoutData(layoutData2);
+
+ GridLayout layout2 = new GridLayout(1, false);
+ layout2.marginWidth = 5;
+ layout2.marginHeight = 5;
+ composite2.setLayout(layout2);
+
+ final Label close = new Label(composite2, SWT.RIGHT);
+ close.setBackground(composite2.getBackground());
+ close.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
+
+ final Image focusedImage = (Image) resources.get(
+ CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
+ "icons/welcome/close.png")); //$NON-NLS-1$
+ final Image noFocusedImage = (Image) resources.get(
+ CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
+ "icons/welcome/close-d.png")) //$NON-NLS-1$
+ ;
+
+ close.setImage(noFocusedImage);
+
+ MouseTrackListener mouseTrackListener = new MouseTrackListener() {
+
+ public void mouseHover(MouseEvent e) {
+ }
+
+ public void mouseExit(MouseEvent e) {
+ close.setImage(noFocusedImage);
+ }
+
+ public void mouseEnter(MouseEvent e) {
+ close.setImage(focusedImage);
+ }
+ };
+
+ composite2.addMouseTrackListener(mouseTrackListener);
+ close.addMouseTrackListener(mouseTrackListener);
+
+ MouseListener mouseListener = new MouseListener() {
+
+ public void mouseUp(MouseEvent e) {
+ }
+
+ public void mouseDown(MouseEvent e) {
+ close();
+ }
+
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+ };
+
+ composite2.addMouseListener(mouseListener);
+ close.addMouseListener(mouseListener);
+ }
+
+ private Listener createControlMovedListener(final Control header) {
+ Listener listener = new Listener() {
+ Point point = null;
+ Point startLocation = null;
+
+ public void handleEvent(Event event) {
+ Shell shell = getShell();
+
+ switch (event.type) {
+ case SWT.MouseDown:
+ if (getShell().isDisposed()) {
+ return;
+ }
+ point = header.toDisplay(event.x, event.y);
+ startLocation = shell.getLocation();
+ break;
+ case SWT.MouseMove:
+ if (point == null)
+ return;
+ Point p2 = header.toDisplay(event.x, event.y);
+ int deltaX = p2.x - point.x;
+ int deltaY = p2.y - point.y;
+ Rectangle rect = shell.getBounds();
+ rect.x = startLocation.x + deltaX;
+ rect.y = startLocation.y + deltaY;
+ shell.setLocation(rect.x, rect.y);
+ break;
+ case SWT.MouseUp:
+ point = null;
+ break;
+ }
+ }
+ };
+ return listener;
+ }
+
+ private void createTitleSection(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite.setLayoutData(gridData);
+
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.horizontalSpacing = 31;
+ layout.marginLeft = 47;
+ composite.setLayout(layout);
+
+ Label titleLabel = new Label(composite, SWT.CENTER);
+ titleLabel.setBackground(composite.getBackground());
+ titleLabel.setForeground(
+ (Color) resources.get(ColorUtils.toDescriptor("#4a4a4a"))); //$NON-NLS-1$
+ titleLabel.setLayoutData(
+ new GridData(SWT.CENTER, SWT.CENTER, false, true));
+
+ FontData[] fontData = Display.getDefault().getSystemFont()
+ .getFontData();
+ titleLabel.setFont(
+ (Font) resources.get(FontDescriptor.createFrom(FontUtils.bold(
+ (FontUtils.relativeHeight(fontData, 18)), true))));
+ titleLabel.setText(WorkbenchMessages.WelcomDialog_Welcom_title);
+
+ Label title2 = new Label(composite, SWT.BOTTOM);
+ title2.setBackground(composite.getBackground());
+ title2.setForeground(
+ (Color) resources.get(ColorUtils.toDescriptor("#4a4a4a"))); //$NON-NLS-1$
+ GridData layoutData = new GridData(SWT.CENTER, SWT.BOTTOM, false, true);
+ title2.setLayoutData(layoutData);
+
+ title2.setFont((Font) resources.get(FontDescriptor
+ .createFrom(FontUtils.relativeHeight(fontData, 4))));
+ title2.setText(WorkbenchMessages.WelcomDialog_WhatIsNew_title);
+ }
+
+ private void createBottomSection(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ composite.setLayoutData(gridData);
+
+ GridLayoutFactory.fillDefaults().applyTo(composite);
+
+ createNewFeatureItems(composite);
+ createButtonSection(composite);
+ }
+
+ private void createNewFeatureItems(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite.setLayoutData(layoutData);
+
+ GridLayout layout = new GridLayout(3, true);
+ layout.marginWidth = 50;
+ layout.marginHeight = 0;
+ layout.horizontalSpacing = 10;
+ composite.setLayout(layout);
+
+ createImageItem(composite,
+ (Image) resources.get(CathyPlugin.imageDescriptorFromPlugin(
+ CathyPlugin.PLUGIN_ID, "icons/welcome/slide.png")) //$NON-NLS-1$
+ , WorkbenchMessages.WelcomeDialog_item_slide_title,
+ WorkbenchMessages.WelcomeDialog_item_slide_description,
+ new Runnable() {
+
+ public void run() {
+ // TODO launch permalink
+ }
+ });
+
+ createImageItem(composite,
+ (Image) resources.get(CathyPlugin.imageDescriptorFromPlugin(
+ CathyPlugin.PLUGIN_ID,
+ "icons/welcome/new_workspace.png")) //$NON-NLS-1$
+ , WorkbenchMessages.WelcomeDialog_item_workspace_title,
+ WorkbenchMessages.WelcomeDialog_item_workspace_description,
+ new Runnable() {
+
+ public void run() {
+ // TODO launch permalink
+ }
+ });
+
+ createImageItem(composite,
+ (Image) resources.get(CathyPlugin.imageDescriptorFromPlugin(
+ CathyPlugin.PLUGIN_ID, "icons/welcome/high_dpi.png")) //$NON-NLS-1$
+ , WorkbenchMessages.WelcomeDialog_item_high_dpi_title,
+ WorkbenchMessages.WelcomeDialog_item_high_dpi_description,
+
+ new Runnable() {
+
+ public void run() {
+ // TODO launch permalink
+ }
+ });
+ }
+
+ private void createImageItem(Composite parent, Image image, String title,
+ String description, final Runnable action) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite.setLayoutData(layoutData);
+
+ GridLayoutFactory.fillDefaults().spacing(0, 10).applyTo(composite);
+
+ Label imageLabel = new Label(composite, SWT.CENTER);
+ imageLabel.setBackground(composite.getBackground());
+ GridData gridData2 = new GridData(SWT.CENTER, SWT.TOP, true, false);
+ imageLabel.setLayoutData(gridData2);
+ imageLabel.setImage(image);
+// imageLabel.setCursor(
+// parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
+
+ imageLabel.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ action.run();
+ }
+ });
+
+ //
+ Composite composite2 = new Composite(composite, SWT.NONE);
+ composite2.setBackground(composite.getBackground());
+ GridData layoutData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite2.setLayoutData(layoutData2);
+
+ GridLayout layout2 = new GridLayout(1, false);
+ layout2.marginWidth = 0;
+ layout2.marginHeight = 0;
+ layout2.verticalSpacing = 10;
+ composite2.setLayout(layout2);
+
+ FontData[] fontData = Display.getDefault().getSystemFont()
+ .getFontData();
+
+ Label titleLabel = new Label(composite2, SWT.NONE);
+ titleLabel.setBackground(composite2.getBackground());
+ titleLabel.setForeground(
+ (Color) resources.get(ColorUtils.toDescriptor("#4a4a4a"))); //$NON-NLS-1$
+ titleLabel.setLayoutData(
+ new GridData(SWT.CENTER, SWT.CENTER, true, false));
+ titleLabel.setText(title);
+ titleLabel.setFont((Font) resources.get(FontDescriptor.createFrom(
+ FontUtils.bold(FontUtils.relativeHeight(fontData, 2), true))));
+
+ Label descriptionLabel = new Label(composite2, SWT.WRAP);
+ descriptionLabel.setBackground(composite2.getBackground());
+ descriptionLabel.setForeground(
+ (Color) resources.get(ColorUtils.toDescriptor("#4a4a4a"))); //$NON-NLS-1$
+ descriptionLabel
+ .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ descriptionLabel.setAlignment(SWT.CENTER);
+ descriptionLabel.setText(description);
+ descriptionLabel.setFont((Font) resources
+ .get(FontDescriptor.createFrom(FontUtils.relativeHeight(
+ descriptionLabel.getFont().getFontData(), 0))));
+ }
+
+ private void createButtonSection(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().applyTo(container);
+ GridLayoutFactory.fillDefaults().margins(1, 1).applyTo(container);
+ container.setBackground(
+ (Color) resources.get(ColorUtils.toDescriptor("#e8e8e8"))); //$NON-NLS-1$
+
+ Composite composite = new Composite(container, SWT.NONE);
+ composite.setBackground(
+ (Color) resources.get(ColorUtils.toDescriptor("#fcfcfc"))); //$NON-NLS-1$
+ GridData layoutData = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
+ composite.setLayoutData(layoutData);
+
+ GridLayout layout = new GridLayout(0, false);
+ layout.marginWidth = 27;
+ layout.marginHeight = 10;
+ composite.setLayout(layout);
+
+ createOkButton(composite);
+ }
+
+ private void createOkButton(Composite parent) {
+ ((GridLayout) parent.getLayout()).numColumns++;
+
+ final Button okButton = new Button(parent, SWT.PUSH);
+ okButton.setBackground(parent.getBackground());
+
+ GridData gridData = null;
+ if (((GridLayout) parent.getLayout()).numColumns > 1) {
+ gridData = new GridData(SWT.CENTER, SWT.CENTER, false, true);
+ } else {
+ gridData = new GridData(SWT.RIGHT, SWT.CENTER, true, true);
+ }
+ gridData.widthHint = 92;
+ okButton.setLayoutData(gridData);
+ okButton.setText(WorkbenchMessages.WelcomeDialog_okButton_text);
+ okButton.setFont(
+ (Font) resources.get(FontDescriptor.createFrom(FontUtils
+ .relativeHeight(okButton.getFont().getFontData(), 1))));
+
+ okButton.addMouseListener(new MouseListener() {
+
+ public void mouseUp(MouseEvent e) {
+ }
+
+ public void mouseDown(MouseEvent e) {
+ close();
+ }
+
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+ });
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WindowPropertyTester.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WindowPropertyTester.java
index 5c9e6fbe5..bff1f536f 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WindowPropertyTester.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WindowPropertyTester.java
@@ -1,44 +1,44 @@
-package org.xmind.cathy.internal;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.ui.IWorkbenchWindow;
-
-public class WindowPropertyTester extends PropertyTester {
-
- private static final String P_SHOWING_DASHBOARD = "showingDashboard"; //$NON-NLS-1$
-
- public boolean test(Object receiver, String property, Object[] args,
- Object expectedValue) {
- Assert.isLegal(receiver instanceof IWorkbenchWindow);
-
- IWorkbenchWindow window = (IWorkbenchWindow) receiver;
- MWindow windowModel = window.getService(MWindow.class);
- Assert.isLegal(windowModel != null);
-
- if (P_SHOWING_DASHBOARD.equals(property)) {
- return testTag(windowModel, ICathyConstants.TAG_SHOW_DASHBOARD,
- expectedValue);
- }
-
- Assert.isLegal(false, "Unrecognized property: " + property); //$NON-NLS-1$
-
- return false;
- }
-
- private boolean testTag(MWindow windowModel, String tag,
- Object expectedValue) {
- boolean actualValue = windowModel.getTags().contains(tag);
- if (expectedValue == null || "".equals(expectedValue)) { //$NON-NLS-1$
- return actualValue;
- } else if (expectedValue instanceof Boolean) {
- return ((Boolean) expectedValue) == actualValue;
- } else if (expectedValue instanceof String) {
- return Boolean.parseBoolean((String) expectedValue) == actualValue;
- }
- Assert.isLegal(false, "Unrecognized value: " + expectedValue); //$NON-NLS-1$
- return false;
- }
-
-}
+package org.xmind.cathy.internal;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.ui.IWorkbenchWindow;
+
+public class WindowPropertyTester extends PropertyTester {
+
+ private static final String P_SHOWING_DASHBOARD = "showingDashboard"; //$NON-NLS-1$
+
+ public boolean test(Object receiver, String property, Object[] args,
+ Object expectedValue) {
+ Assert.isLegal(receiver instanceof IWorkbenchWindow);
+
+ IWorkbenchWindow window = (IWorkbenchWindow) receiver;
+ MWindow windowModel = window.getService(MWindow.class);
+ Assert.isLegal(windowModel != null);
+
+ if (P_SHOWING_DASHBOARD.equals(property)) {
+ return testTag(windowModel, ICathyConstants.TAG_SHOW_DASHBOARD,
+ expectedValue);
+ }
+
+ Assert.isLegal(false, "Unrecognized property: " + property); //$NON-NLS-1$
+
+ return false;
+ }
+
+ private boolean testTag(MWindow windowModel, String tag,
+ Object expectedValue) {
+ boolean actualValue = windowModel.getTags().contains(tag);
+ if (expectedValue == null || "".equals(expectedValue)) { //$NON-NLS-1$
+ return actualValue;
+ } else if (expectedValue instanceof Boolean) {
+ return ((Boolean) expectedValue) == actualValue;
+ } else if (expectedValue instanceof String) {
+ return Boolean.parseBoolean((String) expectedValue) == actualValue;
+ }
+ Assert.isLegal(false, "Unrecognized value: " + expectedValue); //$NON-NLS-1$
+ return false;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WorkbenchMessages.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WorkbenchMessages.java
index 1a2402d4c..b8f127722 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WorkbenchMessages.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WorkbenchMessages.java
@@ -1,221 +1,225 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal;
-
-import org.eclipse.osgi.util.NLS;
-
-public class WorkbenchMessages extends NLS {
-
- private static final String BUNDLE_NAME = "org.xmind.cathy.internal.messages"; //$NON-NLS-1$
-
- public static String AppWindowTitle;
- public static String ProWindowTitle;
-
- public static String File_menu_text;
- public static String Edit_menu_text;
- public static String Help_menu_text;
- public static String SaveAction_text;
-
- public static String GeneralPrefPage_seePolicy_link;
- public static String GeneralPrefPage_title;
- public static String GeneralPrefPage_usageData_text;
-
- public static String GeneralPrefPageSection_RecentFileCountSection_title;
- public static String GeneralPrefPageSection_AutoSaveGroup_title;
-
- public static String RecentFiles_label;
- public static String RecentFileViewer_PinThisMapAction_label;
- public static String RecentFileViewer_UnpinThisMap_label;
- public static String RestoreLastSession_label;
- public static String CathyWorkbenchWindowAdvisor_menu_lockAction_text;
-
- public static String CathyWorkbenchWindowAdvisor_menu_resetAction_text;
-
- public static String CathyWorkbenchWindowAdvisor_windowTitle_home_prefix;
-
- public static String ChangeLanguage_button;
-
- public static String ChangeLanguageTo_description;
-
- public static String CheckUpdates_label;
- public static String AutoBackup_label;
-
- public static String AutoBackupIndicator_AutoSaveDisabled_description;
- public static String AutoBackupIndicator_AutoSaveDisabled_label;
- public static String AutoBackupIndicator_AutoSaveEnabled_label;
- public static String AutoBackupIndicator_DisableAutoSaveAction_text;
- public static String AutoBackupIndicator_EnableAutoSaveAction_text;
- public static String AutoBackupIndicator_OpenPreferenceAction_text;
-
- public static String AutoSave_label;
- public static String AutoSave_Minutes;
- public static String AutoSave_label2;
- public static String Startup_title;
- public static String StartupAction_label;
- public static String StartupAction_OpenDialog;
- public static String StartupAction_BlankMap;
- public static String StartupAction_HomeMap;
- public static String StartupAction_LastSession;
- public static String HomeMap_label;
- public static String HomeMap_NotFound_error;
-
- public static String appWindow_ListSelectionDialog_Text;
- public static String appWindow_ListSelectionDialog_Title;
-
- public static String KeyAssist_text;
-
- public static String Help_text;
- public static String Help_toolTip;
- public static String Update_text;
- public static String Update_toolTip;
-
- public static String CheckOpenFilesJob_CheckFiles_name;
- public static String CheckOpenFilesJob_OpenFiles_name;
- public static String CheckOpenFilesJob_FailsToOpen_message;
- public static String CheckOpenFilesJob_ShowPresentation_name;
-
- public static String CheckRecoverFilesJob_jobName;
- public static String CheckRecoverFilesJob_LoadFiles_name;
- public static String CheckRecoverFilesJob_FilterFiles_name;
- public static String CheckRecoverFilesJob_RecoverFiles_name;
-
- public static String CheckUpdatesJob_jobName;
- public static String CheckUpdatesJob_Fail_message;
- public static String CheckUpdatesJob_NoUpdate_message;
- public static String CheckUpdatesJob_NewUpdate_message;
- public static String CheckUpdatesJob_NewUpdate_info_message;
- public static String CheckUpdatesJob_NewUpdate_moreDownloads_text;
-
- public static String ConfirmDeleteTemplateDialog_message_withTemplateName;
- public static String ConfirmDeleteTemplateDialog_title;
- public static String ConfirmToRestart_cancelButton;
- public static String ConfirmToRestart_defaultButton;
- public static String ConfirmToRestart_description;
- public static String ConfirmToRestart_title;
-
- public static String ConstantsHacker_WizardHandler_menuLabel;
-
- public static String StartupJob_jobName;
- public static String StartupJob_OpenBootstrapEditor_name;
- public static String StartupJob_OpenBlankMap;
- public static String StartupJob_OpenHomeMap;
- public static String StartupJob_OpenLastSession;
-
- public static String SupportLanguageName_Arabic;
- public static String SupportLanguageName_Danish;
- public static String SupportLanguageName_English;
- public static String SupportLanguageName_Spanish;
- public static String SupportLanguageName_French;
- public static String SupportLanguageName_German;
- public static String SupportLanguageName_Italian;
- public static String SupportLanguageName_Japanese;
- public static String SupportLanguageName_Korean;
- public static String SupportLanguageName_Portuguese_Brazilian;
- public static String SupportLanguageName_Russian;
- public static String SupportLanguageName_SimplifiedCN;
- public static String SupportLanguageName_Slovenian;
- public static String SupportLanguageName_TraditionalCN;
-
- public static String PromptSaveEditorOnClosing_message;
-
- public static String About_LicensedTo;
- public static String About_ProTitle;
- public static String About_PlusTitle;
- public static String About_ProSubscriptionTitle;
- public static String About_LicenseTypePattern;
- public static String About_LicenseType_Unactivated;
-
- public static String DownloadAndOpenFileJob_jobName;
- public static String DownloadAndOpenFileJob_Task_Download_with_url;
- public static String DownloadAndOpenFileJob_Task_OpenDownloadedFile_with_url;
- public static String DownloadAndOpenFileJob_Error_FailedToCreateTempFile;
- public static String DownloadAndOpenFileJob_Error_FailedToLoadWorkbook_with_url;
- public static String DownloadAndOpenFileJob_DownloadJob_jobName;
-
- public static String OpenXMindCommandFileJob_failed_fileIsNotReadable;
- public static String OpenXMindCommandFileJob_failed_noCommandFilePath_text;
- public static String OpenXMindCommandFileJob_failed_openXMindCommandFile;
- public static String OpenXMindCommandFileJob_name;
-
- public static String WelcomeDialog_item_slide_title;
- public static String WelcomeDialog_item_slide_description;
- public static String WelcomeDialog_item_cloud_description;
- public static String WelcomeDialog_item_cloud_title;
- public static String WelcomeDialog_item_high_dpi_description;
- public static String WelcomeDialog_item_high_dpi_title;
- public static String WelcomeDialog_item_workspace_description;
- public static String WelcomeDialog_item_workspace_title;
- public static String WelcomeDialog_okButton_text;
- public static String WelcomeDialog_seePolicy_link;
- public static String WelcomeDialog_uploadDataCheck_text;
- public static String WelcomDialog_WhatIsNew_title;
- public static String WelcomDialog_Welcom_title;
-
- public static String WelcomeToXMindHandler_welcomeToXMind_templatedName;
-
- public static String WizardHandler_menuLabel;
-
- public static String BetaVerifier_BetaExpiredPromptDialog_windowTitle;
- public static String BetaVerifier_BetaExpiredPromptDialog_message_withBrandingVersion_andBuildId;
- public static String BetaVerifier_BetaExpiredPromptDialog_CheckAndInstallButton_text;
- public static String BetaVerifier_BetaExpiredPromptDialog_ExitButton_text;
- public static String BetaVerifier_BetaExpiredPromptDialog_DownloadFailure_message;
-
- public static String About_Copyright;
- public static String About_Homepage;
- public static String About_BetaExpiryMessage_withExpiryTime;
-
- public static String LanguagePrefPage_ConfirmToRestart_laterButton;
- public static String LanguagePrefPage_ConfirmToRestart2_defaultButton;
- public static String LanguagePrefPage_ConfirmToRestart2_description;
- public static String LanguagePrefPage_title;
- public static String DashboardHideHome_tooltip;
- public static String DashboardShowHome_tooltip;
- public static String DashboardBlankPage_name;
- public static String DashboardTemplatesPage_name;
- public static String DashboardBlankPage_message;
- public static String DashboardTemplatesPage_message;
-
- public static String DashboardRecentFiles_message;
-
- public static String DashboardThemeChoose_message;
- public static String DashboardThemeCreate_label;
-
- public static String NewFileDashboardPage_AddTemplates_tooltip;
- public static String NewFileDashboardPage_AddTemplates_label;
- public static String NewFileDashboardPage_DeleteTemplate_tooltip;
- public static String NewFileDashboardPage_DeleteTemplate_label;
- public static String NewFileDashboardPage_ExitEditMode_tooltip;
- public static String NewFileDashboardPage_ExitEditTemplatesMode_label;
- public static String NewFileDashboardPage_GoIntoTemplatesManagerMode_tooltip;
- public static String NewFileDashboardPage_GoToEditTemplateMode_label;
- public static String NewFileDashboardPage_leftTitleBar_text;
- public static String NewFileDashboardPage_TemplateFilterName_label;
- public static String NewFileDashboardPage_Import_button;
-
- public static String TemplateViewer_SystemGroup_title;
- public static String TemplateViewer_UserGroup_title;
-
- public static String RecentFileBlankPage_description;
-
- public static String RecentFilesLabelProvider_Cloud_text;
-
- public static String XStackRenderer_TopArea_tipLabel;
- public static String XStackRenderer_BottomArea_Add_button;
-
- static {
- NLS.initializeMessages(BUNDLE_NAME, WorkbenchMessages.class);
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+public class WorkbenchMessages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.xmind.cathy.internal.messages"; //$NON-NLS-1$
+
+ public static String AppWindowTitle;
+ public static String ProWindowTitle;
+
+ public static String File_menu_text;
+ public static String Edit_menu_text;
+ public static String Help_menu_text;
+ public static String SaveAction_text;
+
+ public static String GeneralPrefPage_seePolicy_link;
+ public static String GeneralPrefPage_title;
+ public static String GeneralPrefPage_usageData_text;
+
+ public static String GeneralPrefPageSection_RecentFileCountSection_title;
+ public static String GeneralPrefPageSection_AutoSaveGroup_title;
+
+ public static String RecentFiles_label;
+ public static String RecentFileViewer_PinThisMapAction_label;
+ public static String RecentFileViewer_UnpinThisMap_label;
+ public static String RestoreLastSession_label;
+ public static String CategorizedTemplateViewer_group_untitiledName;
+
+ public static String CategorizedTemplateViewer_template_untitiledName;
+
+ public static String CathyWorkbenchWindowAdvisor_menu_lockAction_text;
+
+ public static String CathyWorkbenchWindowAdvisor_menu_resetAction_text;
+
+ public static String CathyWorkbenchWindowAdvisor_windowTitle_home_prefix;
+
+ public static String ChangeLanguage_button;
+
+ public static String ChangeLanguageTo_description;
+
+ public static String CheckUpdates_label;
+ public static String AutoBackup_label;
+
+ public static String AutoBackupIndicator_AutoSaveDisabled_description;
+ public static String AutoBackupIndicator_AutoSaveDisabled_label;
+ public static String AutoBackupIndicator_AutoSaveEnabled_label;
+ public static String AutoBackupIndicator_DisableAutoSaveAction_text;
+ public static String AutoBackupIndicator_EnableAutoSaveAction_text;
+ public static String AutoBackupIndicator_OpenPreferenceAction_text;
+
+ public static String AutoSave_label;
+ public static String AutoSave_Minutes;
+ public static String AutoSave_label2;
+ public static String Startup_title;
+ public static String StartupAction_label;
+ public static String StartupAction_OpenDialog;
+ public static String StartupAction_BlankMap;
+ public static String StartupAction_HomeMap;
+ public static String StartupAction_LastSession;
+ public static String HomeMap_label;
+ public static String HomeMap_NotFound_error;
+
+ public static String appWindow_ListSelectionDialog_Text;
+ public static String appWindow_ListSelectionDialog_Title;
+
+ public static String KeyAssist_text;
+
+ public static String Help_text;
+ public static String Help_toolTip;
+ public static String Update_text;
+ public static String Update_toolTip;
+
+ public static String CheckOpenFilesJob_CheckFiles_name;
+ public static String CheckOpenFilesJob_OpenFiles_name;
+ public static String CheckOpenFilesJob_FailsToOpen_message;
+ public static String CheckOpenFilesJob_ShowPresentation_name;
+
+ public static String CheckRecoverFilesJob_jobName;
+ public static String CheckRecoverFilesJob_LoadFiles_name;
+ public static String CheckRecoverFilesJob_FilterFiles_name;
+ public static String CheckRecoverFilesJob_RecoverFiles_name;
+
+ public static String CheckUpdatesJob_jobName;
+ public static String CheckUpdatesJob_Fail_message;
+ public static String CheckUpdatesJob_NoUpdate_message;
+ public static String CheckUpdatesJob_NewUpdate_message;
+ public static String CheckUpdatesJob_NewUpdate_info_message;
+ public static String CheckUpdatesJob_NewUpdate_moreDownloads_text;
+
+ public static String ConfirmDeleteTemplateDialog_message_withTemplateName;
+ public static String ConfirmDeleteTemplateDialog_title;
+ public static String ConfirmToRestart_cancelButton;
+ public static String ConfirmToRestart_defaultButton;
+ public static String ConfirmToRestart_description;
+ public static String ConfirmToRestart_title;
+
+ public static String ConstantsHacker_WizardHandler_menuLabel;
+
+ public static String StartupJob_jobName;
+ public static String StartupJob_OpenBootstrapEditor_name;
+ public static String StartupJob_OpenBlankMap;
+ public static String StartupJob_OpenHomeMap;
+ public static String StartupJob_OpenLastSession;
+
+ public static String SupportLanguageName_Arabic;
+ public static String SupportLanguageName_Danish;
+ public static String SupportLanguageName_English;
+ public static String SupportLanguageName_Spanish;
+ public static String SupportLanguageName_French;
+ public static String SupportLanguageName_German;
+ public static String SupportLanguageName_Italian;
+ public static String SupportLanguageName_Japanese;
+ public static String SupportLanguageName_Korean;
+ public static String SupportLanguageName_Portuguese_Brazilian;
+ public static String SupportLanguageName_Russian;
+ public static String SupportLanguageName_SimplifiedCN;
+ public static String SupportLanguageName_Slovenian;
+ public static String SupportLanguageName_TraditionalCN;
+
+ public static String PromptSaveEditorOnClosing_message;
+
+ public static String About_LicensedTo;
+ public static String About_ProTitle;
+ public static String About_PlusTitle;
+ public static String About_ProSubscriptionTitle;
+ public static String About_LicenseTypePattern;
+ public static String About_LicenseType_Unactivated;
+
+ public static String DownloadAndOpenFileJob_jobName;
+ public static String DownloadAndOpenFileJob_Task_Download_with_url;
+ public static String DownloadAndOpenFileJob_Task_OpenDownloadedFile_with_url;
+ public static String DownloadAndOpenFileJob_Error_FailedToCreateTempFile;
+ public static String DownloadAndOpenFileJob_Error_FailedToLoadWorkbook_with_url;
+ public static String DownloadAndOpenFileJob_DownloadJob_jobName;
+
+ public static String OpenXMindCommandFileJob_failed_fileIsNotReadable;
+ public static String OpenXMindCommandFileJob_failed_noCommandFilePath_text;
+ public static String OpenXMindCommandFileJob_failed_openXMindCommandFile;
+ public static String OpenXMindCommandFileJob_name;
+
+ public static String WelcomeDialog_item_slide_title;
+ public static String WelcomeDialog_item_slide_description;
+ public static String WelcomeDialog_item_cloud_description;
+ public static String WelcomeDialog_item_cloud_title;
+ public static String WelcomeDialog_item_high_dpi_description;
+ public static String WelcomeDialog_item_high_dpi_title;
+ public static String WelcomeDialog_item_workspace_description;
+ public static String WelcomeDialog_item_workspace_title;
+ public static String WelcomeDialog_okButton_text;
+ public static String WelcomeDialog_seePolicy_link;
+ public static String WelcomeDialog_uploadDataCheck_text;
+ public static String WelcomDialog_WhatIsNew_title;
+ public static String WelcomDialog_Welcom_title;
+
+ public static String WelcomeToXMindHandler_welcomeToXMind_templatedName;
+
+ public static String WizardHandler_menuLabel;
+
+ public static String BetaVerifier_BetaExpiredPromptDialog_windowTitle;
+ public static String BetaVerifier_BetaExpiredPromptDialog_message_withBrandingVersion_andBuildId;
+ public static String BetaVerifier_BetaExpiredPromptDialog_CheckAndInstallButton_text;
+ public static String BetaVerifier_BetaExpiredPromptDialog_ExitButton_text;
+ public static String BetaVerifier_BetaExpiredPromptDialog_DownloadFailure_message;
+
+ public static String About_Copyright;
+ public static String About_Homepage;
+ public static String About_BetaExpiryMessage_withExpiryTime;
+
+ public static String LanguagePrefPage_ConfirmToRestart_laterButton;
+ public static String LanguagePrefPage_ConfirmToRestart2_defaultButton;
+ public static String LanguagePrefPage_ConfirmToRestart2_description;
+ public static String LanguagePrefPage_title;
+ public static String DashboardHideHome_tooltip;
+ public static String DashboardShowHome_tooltip;
+ public static String DashboardBlankPage_name;
+ public static String DashboardTemplatesPage_name;
+ public static String DashboardBlankPage_message;
+ public static String DashboardTemplatesPage_message;
+
+ public static String DashboardRecentFiles_message;
+
+ public static String DashboardThemeChoose_message;
+ public static String DashboardThemeCreate_label;
+
+ public static String NewFileDashboardPage_AddTemplates_tooltip;
+ public static String NewFileDashboardPage_AddTemplates_label;
+ public static String NewFileDashboardPage_DeleteTemplate_tooltip;
+ public static String NewFileDashboardPage_DeleteTemplate_label;
+ public static String NewFileDashboardPage_ExitEditMode_tooltip;
+ public static String NewFileDashboardPage_ExitEditTemplatesMode_label;
+ public static String NewFileDashboardPage_GoIntoTemplatesManagerMode_tooltip;
+ public static String NewFileDashboardPage_GoToEditTemplateMode_label;
+ public static String NewFileDashboardPage_leftTitleBar_text;
+ public static String NewFileDashboardPage_TemplateFilterName_label;
+ public static String NewFileDashboardPage_Import_button;
+
+ public static String TemplateViewer_SystemGroup_title;
+ public static String TemplateViewer_UserGroup_title;
+
+ public static String RecentFileBlankPage_description;
+
+ public static String RecentFilesLabelProvider_Cloud_text;
+
+ public static String XStackRenderer_TopArea_tipLabel;
+ public static String XStackRenderer_BottomArea_Add_button;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, WorkbenchMessages.class);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WorkspaceFile.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WorkspaceFile.java
index 8062e7108..f6d78be87 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WorkspaceFile.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/WorkspaceFile.java
@@ -6,7 +6,7 @@
* which is available at http://www.eclipse.org/legal/epl-v10.html
* and the GNU Lesser General Public License (LGPL),
* which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
+ * See https://www.xmind.net/license.html for details.
*
* Contributors:
* XMind Ltd. - initial API and implementation
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyCTabFolderRenderNoneHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyCTabFolderRenderNoneHandler.java
index 573d84907..78676e192 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyCTabFolderRenderNoneHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyCTabFolderRenderNoneHandler.java
@@ -1,42 +1,42 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyCTabFolderRenderNoneHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final ICSSPropertyHandler INSTANCE = new CSSPropertyCTabFolderRenderNoneHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder)) {
- return;
- }
- CTabFolder folder = (CTabFolder) control;
- CTabFolderRenderer renderer = folder.getRenderer();
- if (!(renderer instanceof ICTabFolderRendering))
- return;
-
- boolean isNoneRender = (Boolean) engine.convert(value, Boolean.class,
- null);
- if (ICathyConstants.PROPERTY_CTABFOLDER_RENDER_NONE.equals(property)) {
- ((ICTabFolderRendering) renderer).setNoneRender(isNoneRender);
- }
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyCTabFolderRenderNoneHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final ICSSPropertyHandler INSTANCE = new CSSPropertyCTabFolderRenderNoneHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder)) {
+ return;
+ }
+ CTabFolder folder = (CTabFolder) control;
+ CTabFolderRenderer renderer = folder.getRenderer();
+ if (!(renderer instanceof ICTabFolderRendering))
+ return;
+
+ boolean isNoneRender = (Boolean) engine.convert(value, Boolean.class,
+ null);
+ if (ICathyConstants.PROPERTY_CTABFOLDER_RENDER_NONE.equals(property)) {
+ ((ICTabFolderRendering) renderer).setNoneRender(isNoneRender);
+ }
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyCTabFolderToolBarSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyCTabFolderToolBarSWTHandler.java
index f78f2ad6a..6767ea493 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyCTabFolderToolBarSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyCTabFolderToolBarSWTHandler.java
@@ -1,81 +1,81 @@
-package org.xmind.cathy.internal.css;
-
-import java.lang.reflect.Method;
-import java.net.URL;
-
-import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSPrimitiveValue;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyCTabFolderToolBarSWTHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final ICSSPropertyHandler INSTANCE = new CSSPropertyCTabFolderToolBarSWTHandler();
-
- private static final String METHOD_SET_CHEVRON_VISIBLE = "setChevronVisible"; //$NON-NLS-1$
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder)) {
- return;
- }
- CTabFolder folder = (CTabFolder) control;
- CTabFolderRenderer renderer = folder.getRenderer();
- if (!(renderer instanceof ICTabFolderRendering))
- return;
-
- ICTabFolderRendering tabFolderRendering = (ICTabFolderRendering) renderer;
-
- Image image = null;
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- if (((CSSPrimitiveValue) value)
- .getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
- String imageUrl = ((CSSPrimitiveValue) value).getStringValue();
- ImageDescriptor imageDescriptor = ImageDescriptor
- .createFromURL(new URL(imageUrl.toString()));
- image = JFaceResources.getResources()
- .createImage(imageDescriptor);
- }
- }
-
- if (ICathyConstants.PROPERTY_MAXIMIZE_IMAGE.equals(property)) {
- tabFolderRendering.setMaximizeImage(image);
- } else if (ICathyConstants.PROPERTY_MINIMIZE_IMAGE.equals(property)) {
- tabFolderRendering.setMinimizeImage(image);
- } else if (ICathyConstants.PROPERTY_CLOSE_IMAGE.equals(property)) {
- tabFolderRendering.setCloseImage(image);
- } else
- if (ICathyConstants.PROPERTY_CLOSE_HOVER_IMAGE.equals(property)) {
- tabFolderRendering.setClsoeHoverImage(image);
- } else if (ICathyConstants.PROPERTY_CHEVRON_VISIBLE.equals(property)) {
- ReflectionSupport reflect = new ReflectionSupport(
- CTabFolder.class);
- boolean chevronVisible = (Boolean) engine.convert(value,
- Boolean.class, null);
- Method setChevronVisible = reflect.getMethod(
- METHOD_SET_CHEVRON_VISIBLE,
- new Class>[] { boolean.class });
- reflect.executeMethod(setChevronVisible, folder,
- new Object[] { chevronVisible });
- }
-
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSPrimitiveValue;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyCTabFolderToolBarSWTHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final ICSSPropertyHandler INSTANCE = new CSSPropertyCTabFolderToolBarSWTHandler();
+
+ private static final String METHOD_SET_CHEVRON_VISIBLE = "setChevronVisible"; //$NON-NLS-1$
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder)) {
+ return;
+ }
+ CTabFolder folder = (CTabFolder) control;
+ CTabFolderRenderer renderer = folder.getRenderer();
+ if (!(renderer instanceof ICTabFolderRendering))
+ return;
+
+ ICTabFolderRendering tabFolderRendering = (ICTabFolderRendering) renderer;
+
+ Image image = null;
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ if (((CSSPrimitiveValue) value)
+ .getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
+ String imageUrl = ((CSSPrimitiveValue) value).getStringValue();
+ ImageDescriptor imageDescriptor = ImageDescriptor
+ .createFromURL(new URL(imageUrl.toString()));
+ image = JFaceResources.getResources()
+ .createImage(imageDescriptor);
+ }
+ }
+
+ if (ICathyConstants.PROPERTY_MAXIMIZE_IMAGE.equals(property)) {
+ tabFolderRendering.setMaximizeImage(image);
+ } else if (ICathyConstants.PROPERTY_MINIMIZE_IMAGE.equals(property)) {
+ tabFolderRendering.setMinimizeImage(image);
+ } else if (ICathyConstants.PROPERTY_CLOSE_IMAGE.equals(property)) {
+ tabFolderRendering.setCloseImage(image);
+ } else
+ if (ICathyConstants.PROPERTY_CLOSE_HOVER_IMAGE.equals(property)) {
+ tabFolderRendering.setClsoeHoverImage(image);
+ } else if (ICathyConstants.PROPERTY_CHEVRON_VISIBLE.equals(property)) {
+ ReflectionSupport reflect = new ReflectionSupport(
+ CTabFolder.class);
+ boolean chevronVisible = (Boolean) engine.convert(value,
+ Boolean.class, null);
+ Method setChevronVisible = reflect.getMethod(
+ METHOD_SET_CHEVRON_VISIBLE,
+ new Class>[] { boolean.class });
+ reflect.executeMethod(setChevronVisible, folder,
+ new Object[] { chevronVisible });
+ }
+
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyFormHeadingHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyFormHeadingHandler.java
index e86175651..04a8a7579 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyFormHeadingHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyFormHeadingHandler.java
@@ -1,86 +1,86 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.forms.IFormColors;
-import org.eclipse.ui.internal.forms.widgets.FormHeading;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyFormHeadingHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyFormHeadingHandler INSTANCE = new CSSPropertyFormHeadingHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof FormHeading))
- return;
-
- FormHeading formHeading = (FormHeading) control;
- if (ICathyConstants.PROPERTY_XTEXT_BACKGROUND.equals(property)) {
- applyCSSPropertyTextBackgroud(formHeading, value, engine);
- } else if (ICathyConstants.PROPERTY_XBOTTOM_KEYLINE_1_COLOR
- .equals(property)) {
- Color keyline1Color = (Color) engine.convert(value, Color.class,
- formHeading.getDisplay());
- formHeading.putColor(IFormColors.H_BOTTOM_KEYLINE1, keyline1Color);
-
- } else if (ICathyConstants.PROPERTY_XBOTTOM_KEYLINE_2_COLOR
- .equals(property)) {
- Color keyline2Color = (Color) engine.convert(value, Color.class,
- formHeading.getDisplay());
- formHeading.putColor(IFormColors.H_BOTTOM_KEYLINE2, keyline2Color);
- }
-
- }
-
- private void applyCSSPropertyTextBackgroud(FormHeading formHeading,
- CSSValue value, CSSEngine engine) throws Exception {
- if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
- Gradient grad = (Gradient) engine.convert(value, Gradient.class,
- formHeading.getDisplay());
- if (grad == null) {
- return;
- }
- Color[] colors = null;
- int[] percents = null;
- if (!grad.getValues().isEmpty()) {
- colors = CSSSWTColorHelper.getSWTColors(grad,
- formHeading.getDisplay(), engine);
- percents = CSSSWTColorHelper.getPercents(grad);
- }
- formHeading.setTextBackground(colors, percents, true);
- } else if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color color = (Color) engine.convert(value, Color.class,
- formHeading.getDisplay());
- formHeading.setTextBackground(new Color[] { color, color },
- new int[] { 100 }, true);
- }
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- if (control instanceof FormHeading) {
- if (ICathyConstants.PROPERTY_XBOTTOM_KEYLINE_1_COLOR
- .equals(property)) {
- Color keyline1Color = ((FormHeading) control)
- .getColor(IFormColors.H_BOTTOM_KEYLINE1);
- return engine.convert(keyline1Color, Color.class, null);
- } else if (ICathyConstants.PROPERTY_XBOTTOM_KEYLINE_2_COLOR
- .equals(property)) {
- Color keyline2Color = ((FormHeading) control)
- .getColor(IFormColors.H_BOTTOM_KEYLINE2);
- return engine.convert(keyline2Color, Color.class, null);
- }
- }
- return null;
- }
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.IFormColors;
+import org.eclipse.ui.internal.forms.widgets.FormHeading;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyFormHeadingHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyFormHeadingHandler INSTANCE = new CSSPropertyFormHeadingHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof FormHeading))
+ return;
+
+ FormHeading formHeading = (FormHeading) control;
+ if (ICathyConstants.PROPERTY_XTEXT_BACKGROUND.equals(property)) {
+ applyCSSPropertyTextBackgroud(formHeading, value, engine);
+ } else if (ICathyConstants.PROPERTY_XBOTTOM_KEYLINE_1_COLOR
+ .equals(property)) {
+ Color keyline1Color = (Color) engine.convert(value, Color.class,
+ formHeading.getDisplay());
+ formHeading.putColor(IFormColors.H_BOTTOM_KEYLINE1, keyline1Color);
+
+ } else if (ICathyConstants.PROPERTY_XBOTTOM_KEYLINE_2_COLOR
+ .equals(property)) {
+ Color keyline2Color = (Color) engine.convert(value, Color.class,
+ formHeading.getDisplay());
+ formHeading.putColor(IFormColors.H_BOTTOM_KEYLINE2, keyline2Color);
+ }
+
+ }
+
+ private void applyCSSPropertyTextBackgroud(FormHeading formHeading,
+ CSSValue value, CSSEngine engine) throws Exception {
+ if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
+ Gradient grad = (Gradient) engine.convert(value, Gradient.class,
+ formHeading.getDisplay());
+ if (grad == null) {
+ return;
+ }
+ Color[] colors = null;
+ int[] percents = null;
+ if (!grad.getValues().isEmpty()) {
+ colors = CSSSWTColorHelper.getSWTColors(grad,
+ formHeading.getDisplay(), engine);
+ percents = CSSSWTColorHelper.getPercents(grad);
+ }
+ formHeading.setTextBackground(colors, percents, true);
+ } else if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color color = (Color) engine.convert(value, Color.class,
+ formHeading.getDisplay());
+ formHeading.setTextBackground(new Color[] { color, color },
+ new int[] { 100 }, true);
+ }
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ if (control instanceof FormHeading) {
+ if (ICathyConstants.PROPERTY_XBOTTOM_KEYLINE_1_COLOR
+ .equals(property)) {
+ Color keyline1Color = ((FormHeading) control)
+ .getColor(IFormColors.H_BOTTOM_KEYLINE1);
+ return engine.convert(keyline1Color, Color.class, null);
+ } else if (ICathyConstants.PROPERTY_XBOTTOM_KEYLINE_2_COLOR
+ .equals(property)) {
+ Color keyline2Color = ((FormHeading) control)
+ .getColor(IFormColors.H_BOTTOM_KEYLINE2);
+ return engine.convert(keyline2Color, Color.class, null);
+ }
+ }
+ return null;
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyFormTextHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyFormTextHandler.java
index f8b0c05b0..3cafbeed8 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyFormTextHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyFormTextHandler.java
@@ -1,48 +1,48 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.forms.HyperlinkSettings;
-import org.eclipse.ui.forms.widgets.FormText;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyFormTextHandler extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyFormTextHandler INSTANCE = new CSSPropertyFormTextHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof FormText))
- return;
-
- FormText formText = (FormText) control;
- if (ICathyConstants.PROPERTY_HYPERLINK_COLOR.equals(property)) {
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color hyperlinkColor = (Color) engine.convert(value,
- Color.class, formText.getDisplay());
- HyperlinkSettings hyperlinkSettings = formText
- .getHyperlinkSettings();
- hyperlinkSettings.setForeground(hyperlinkColor);
- }
- } else if (ICathyConstants.PROPERTY_ACTIVE_HYPERLINK_COLOR
- .equals(property)) {
- Color activeHyperlinkColor = (Color) engine.convert(value,
- Color.class, formText.getDisplay());
- formText.getHyperlinkSettings()
- .setActiveForeground(activeHyperlinkColor);
- }
-
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.HyperlinkSettings;
+import org.eclipse.ui.forms.widgets.FormText;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyFormTextHandler extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyFormTextHandler INSTANCE = new CSSPropertyFormTextHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof FormText))
+ return;
+
+ FormText formText = (FormText) control;
+ if (ICathyConstants.PROPERTY_HYPERLINK_COLOR.equals(property)) {
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color hyperlinkColor = (Color) engine.convert(value,
+ Color.class, formText.getDisplay());
+ HyperlinkSettings hyperlinkSettings = formText
+ .getHyperlinkSettings();
+ hyperlinkSettings.setForeground(hyperlinkColor);
+ }
+ } else if (ICathyConstants.PROPERTY_ACTIVE_HYPERLINK_COLOR
+ .equals(property)) {
+ Color activeHyperlinkColor = (Color) engine.convert(value,
+ Color.class, formText.getDisplay());
+ formText.getHyperlinkSettings()
+ .setActiveForeground(activeHyperlinkColor);
+ }
+
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyHoverTabSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyHoverTabSWTHandler.java
index 9c145429f..b46f7a67a 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyHoverTabSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyHoverTabSWTHandler.java
@@ -1,63 +1,63 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSValue;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyHoverTabSWTHandler extends
- AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyHoverTabSWTHandler INSTANCE = new CSSPropertyHoverTabSWTHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder)) {
- return;
- }
-
- CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
- if (!(renderer instanceof ICTabFolderRendering))
- return;
-
- ICTabFolderRendering tabFolderRendering = (ICTabFolderRendering) renderer;
-
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color color = (Color) engine.convert(value, Color.class,
- control.getDisplay());
- tabFolderRendering.setHoverTabColor(color);
- return;
- }
-
- if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
- Gradient grad = (Gradient) engine.convert(value, Gradient.class,
- control.getDisplay());
- if (grad == null) {
- return;
- }
- Color[] colors = null;
- int[] percents = null;
- if (!grad.getValues().isEmpty()) {
- colors = CSSSWTColorHelper.getSWTColors(grad,
- control.getDisplay(), engine);
- percents = CSSSWTColorHelper.getPercents(grad);
- }
- tabFolderRendering.setHoverTabColor(colors, percents);
- }
-
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSValue;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyHoverTabSWTHandler extends
+ AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyHoverTabSWTHandler INSTANCE = new CSSPropertyHoverTabSWTHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder)) {
+ return;
+ }
+
+ CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
+ if (!(renderer instanceof ICTabFolderRendering))
+ return;
+
+ ICTabFolderRendering tabFolderRendering = (ICTabFolderRendering) renderer;
+
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color color = (Color) engine.convert(value, Color.class,
+ control.getDisplay());
+ tabFolderRendering.setHoverTabColor(color);
+ return;
+ }
+
+ if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
+ Gradient grad = (Gradient) engine.convert(value, Gradient.class,
+ control.getDisplay());
+ if (grad == null) {
+ return;
+ }
+ Color[] colors = null;
+ int[] percents = null;
+ if (!grad.getValues().isEmpty()) {
+ colors = CSSSWTColorHelper.getSWTColors(grad,
+ control.getDisplay(), engine);
+ percents = CSSSWTColorHelper.getPercents(grad);
+ }
+ tabFolderRendering.setHoverTabColor(colors, percents);
+ }
+
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMTabBarHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMTabBarHandler.java
index 5b5c1349d..5f8313526 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMTabBarHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMTabBarHandler.java
@@ -1,40 +1,40 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-import org.xmind.ui.tabfolder.MTabBar;
-import org.xmind.ui.tabfolder.MTabFolder;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyMTabBarHandler extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyMTabBarHandler INSTANCE = new CSSPropertyMTabBarHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof MTabBar))
- return;
-
- MTabBar tabBar = (MTabBar) control;
- if (ICathyConstants.PROPERTY_TABFOLDER_BACKGROUND.equals(property)) {
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color color = (Color) engine.convert(value, Color.class,
- tabBar.getDisplay());
- tabBar.getStyleProvider().setColor(MTabFolder.TAB_BAR,
- color.getRGB());
- }
- }
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+import org.xmind.ui.tabfolder.MTabBar;
+import org.xmind.ui.tabfolder.MTabFolder;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyMTabBarHandler extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyMTabBarHandler INSTANCE = new CSSPropertyMTabBarHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof MTabBar))
+ return;
+
+ MTabBar tabBar = (MTabBar) control;
+ if (ICathyConstants.PROPERTY_TABFOLDER_BACKGROUND.equals(property)) {
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color color = (Color) engine.convert(value, Color.class,
+ tabBar.getDisplay());
+ tabBar.getStyleProvider().setColor(MTabFolder.TAB_BAR,
+ color.getRGB());
+ }
+ }
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMTabFolderHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMTabFolderHandler.java
index 26d2c1d5c..f63d757c4 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMTabFolderHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMTabFolderHandler.java
@@ -1,40 +1,40 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-import org.xmind.ui.tabfolder.MTabFolder;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyMTabFolderHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyMTabBarHandler INSTANCE = new CSSPropertyMTabBarHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof MTabFolder))
- return;
-
- MTabFolder tabFolder = (MTabFolder) control;
- if (ICathyConstants.PROPERTY_TABFOLDER_BACKGROUND.equals(property)) {
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color color = (Color) engine.convert(value, Color.class,
- tabFolder.getDisplay());
- tabFolder.getStyleProvider().setColor(MTabFolder.TAB_BAR,
- color.getRGB());
- }
- }
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+import org.xmind.ui.tabfolder.MTabFolder;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyMTabFolderHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyMTabBarHandler INSTANCE = new CSSPropertyMTabBarHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof MTabFolder))
+ return;
+
+ MTabFolder tabFolder = (MTabFolder) control;
+ if (ICathyConstants.PROPERTY_TABFOLDER_BACKGROUND.equals(property)) {
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color color = (Color) engine.convert(value, Color.class,
+ tabFolder.getDisplay());
+ tabFolder.getStyleProvider().setColor(MTabFolder.TAB_BAR,
+ color.getRGB());
+ }
+ }
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMarginXHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMarginXHandler.java
index d39d4f6c3..cd84e0be8 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMarginXHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMarginXHandler.java
@@ -1,142 +1,142 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.e4.ui.workbench.renderers.swt.TrimBarLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Layout;
-import org.w3c.dom.css.CSSPrimitiveValue;
-import org.w3c.dom.css.CSSValue;
-import org.w3c.dom.css.CSSValueList;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyMarginXHandler extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyMarginXHandler INSTANCE = new CSSPropertyMarginXHandler();
-
- private final static int TOP = 0;
- private final static int RIGHT = 1;
- private final static int BOTTOM = 2;
- private final static int LEFT = 3;
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof Composite))
- return;
-
- Composite composite = (Composite) control;
-
- if (ICathyConstants.PROPERTY_MARGIN.equals(property))
- applyCSSPropertyMargin(composite, value, pseudo, engine);
- else if (ICathyConstants.PROPERTY_MARGIN_TOP.equals(property))
- applyCSSPropertyMarginTop(composite, value, pseudo, engine);
- else if (ICathyConstants.PROPERTY_MARGIN_RIGHT.equals(property))
- applyCSSPropertyMarginRight(composite, value, pseudo, engine);
- else if (ICathyConstants.PROPERTY_MARGIN_BOTTOM.equals(property))
- applyCSSPropertyMarginBottom(composite, value, pseudo, engine);
- else if (ICathyConstants.PROPERTY_MARGIN_LEFT.equals(property))
- applyCSSPropertyMarginLeft(composite, value, pseudo, engine);
-
- }
-
- public void applyCSSPropertyMargin(Composite element, CSSValue value,
- String pseudo, CSSEngine engine) throws Exception {
-
- // If single value then assigned to all four margins
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- setMargin(element, TOP, value, pseudo);
- setMargin(element, RIGHT, value, pseudo);
- setMargin(element, BOTTOM, value, pseudo);
- setMargin(element, LEFT, value, pseudo);
- return;
- }
-
- if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
- CSSValueList valueList = (CSSValueList) value;
- int length = valueList.getLength();
-
- if (length < 2 || length > 4)
- return;
-
- switch (length) {
- case 4:
- // If four values then assigned top/right/bottom/left
- setMargin(element, TOP, valueList.item(0), pseudo);
- setMargin(element, RIGHT, valueList.item(1), pseudo);
- setMargin(element, BOTTOM, valueList.item(2), pseudo);
- setMargin(element, LEFT, valueList.item(3), pseudo);
- break;
- case 3:
- // If three values then assigned top=v1, left=v2, right=v2, bottom=v3
- setMargin(element, TOP, valueList.item(0), pseudo);
- setMargin(element, RIGHT, valueList.item(1), pseudo);
- setMargin(element, BOTTOM, valueList.item(2), pseudo);
- setMargin(element, LEFT, valueList.item(1), pseudo);
- case 2:
- // If two values then assigned top/bottom=v1, left/right=v2
- setMargin(element, TOP, valueList.item(0), pseudo);
- setMargin(element, RIGHT, valueList.item(1), pseudo);
- setMargin(element, BOTTOM, valueList.item(0), pseudo);
- setMargin(element, LEFT, valueList.item(1), pseudo);
- }
- }
- }
-
- private void applyCSSPropertyMarginTop(Composite element, CSSValue value,
- String pseudo, CSSEngine engine) throws Exception {
- setMargin(element, TOP, value, pseudo);
- }
-
- private void applyCSSPropertyMarginRight(Composite element, CSSValue value,
- String pseudo, CSSEngine engine) throws Exception {
- setMargin(element, RIGHT, value, pseudo);
- }
-
- private void applyCSSPropertyMarginBottom(Composite element, CSSValue value,
- String pseudo, CSSEngine engine) throws Exception {
- setMargin(element, BOTTOM, value, pseudo);
- }
-
- private void applyCSSPropertyMarginLeft(Composite element, CSSValue value,
- String pseudo, CSSEngine engine) throws Exception {
- setMargin(element, LEFT, value, pseudo);
- }
-
- private void setMargin(Composite composite, int side, CSSValue value,
- String pseudo) {
- if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE)
- return;
- int pixelValue = (int) ((CSSPrimitiveValue) value)
- .getFloatValue(CSSPrimitiveValue.CSS_PX);
-
- Layout layout = composite.getLayout();
- if (layout == null || !(layout instanceof TrimBarLayout))
- return;
-
- TrimBarLayout trimBarLayout = (TrimBarLayout) layout;
- switch (side) {
- case TOP:
- trimBarLayout.marginTop = pixelValue;
- break;
- case RIGHT:
- trimBarLayout.marginRight = pixelValue;
- break;
- case BOTTOM:
- trimBarLayout.marginBottom = pixelValue;
- break;
- case LEFT:
- trimBarLayout.marginLeft = pixelValue;
- break;
- }
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.e4.ui.workbench.renderers.swt.TrimBarLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Layout;
+import org.w3c.dom.css.CSSPrimitiveValue;
+import org.w3c.dom.css.CSSValue;
+import org.w3c.dom.css.CSSValueList;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyMarginXHandler extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyMarginXHandler INSTANCE = new CSSPropertyMarginXHandler();
+
+ private final static int TOP = 0;
+ private final static int RIGHT = 1;
+ private final static int BOTTOM = 2;
+ private final static int LEFT = 3;
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof Composite))
+ return;
+
+ Composite composite = (Composite) control;
+
+ if (ICathyConstants.PROPERTY_MARGIN.equals(property))
+ applyCSSPropertyMargin(composite, value, pseudo, engine);
+ else if (ICathyConstants.PROPERTY_MARGIN_TOP.equals(property))
+ applyCSSPropertyMarginTop(composite, value, pseudo, engine);
+ else if (ICathyConstants.PROPERTY_MARGIN_RIGHT.equals(property))
+ applyCSSPropertyMarginRight(composite, value, pseudo, engine);
+ else if (ICathyConstants.PROPERTY_MARGIN_BOTTOM.equals(property))
+ applyCSSPropertyMarginBottom(composite, value, pseudo, engine);
+ else if (ICathyConstants.PROPERTY_MARGIN_LEFT.equals(property))
+ applyCSSPropertyMarginLeft(composite, value, pseudo, engine);
+
+ }
+
+ public void applyCSSPropertyMargin(Composite element, CSSValue value,
+ String pseudo, CSSEngine engine) throws Exception {
+
+ // If single value then assigned to all four margins
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ setMargin(element, TOP, value, pseudo);
+ setMargin(element, RIGHT, value, pseudo);
+ setMargin(element, BOTTOM, value, pseudo);
+ setMargin(element, LEFT, value, pseudo);
+ return;
+ }
+
+ if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
+ CSSValueList valueList = (CSSValueList) value;
+ int length = valueList.getLength();
+
+ if (length < 2 || length > 4)
+ return;
+
+ switch (length) {
+ case 4:
+ // If four values then assigned top/right/bottom/left
+ setMargin(element, TOP, valueList.item(0), pseudo);
+ setMargin(element, RIGHT, valueList.item(1), pseudo);
+ setMargin(element, BOTTOM, valueList.item(2), pseudo);
+ setMargin(element, LEFT, valueList.item(3), pseudo);
+ break;
+ case 3:
+ // If three values then assigned top=v1, left=v2, right=v2, bottom=v3
+ setMargin(element, TOP, valueList.item(0), pseudo);
+ setMargin(element, RIGHT, valueList.item(1), pseudo);
+ setMargin(element, BOTTOM, valueList.item(2), pseudo);
+ setMargin(element, LEFT, valueList.item(1), pseudo);
+ case 2:
+ // If two values then assigned top/bottom=v1, left/right=v2
+ setMargin(element, TOP, valueList.item(0), pseudo);
+ setMargin(element, RIGHT, valueList.item(1), pseudo);
+ setMargin(element, BOTTOM, valueList.item(0), pseudo);
+ setMargin(element, LEFT, valueList.item(1), pseudo);
+ }
+ }
+ }
+
+ private void applyCSSPropertyMarginTop(Composite element, CSSValue value,
+ String pseudo, CSSEngine engine) throws Exception {
+ setMargin(element, TOP, value, pseudo);
+ }
+
+ private void applyCSSPropertyMarginRight(Composite element, CSSValue value,
+ String pseudo, CSSEngine engine) throws Exception {
+ setMargin(element, RIGHT, value, pseudo);
+ }
+
+ private void applyCSSPropertyMarginBottom(Composite element, CSSValue value,
+ String pseudo, CSSEngine engine) throws Exception {
+ setMargin(element, BOTTOM, value, pseudo);
+ }
+
+ private void applyCSSPropertyMarginLeft(Composite element, CSSValue value,
+ String pseudo, CSSEngine engine) throws Exception {
+ setMargin(element, LEFT, value, pseudo);
+ }
+
+ private void setMargin(Composite composite, int side, CSSValue value,
+ String pseudo) {
+ if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE)
+ return;
+ int pixelValue = (int) ((CSSPrimitiveValue) value)
+ .getFloatValue(CSSPrimitiveValue.CSS_PX);
+
+ Layout layout = composite.getLayout();
+ if (layout == null || !(layout instanceof TrimBarLayout))
+ return;
+
+ TrimBarLayout trimBarLayout = (TrimBarLayout) layout;
+ switch (side) {
+ case TOP:
+ trimBarLayout.marginTop = pixelValue;
+ break;
+ case RIGHT:
+ trimBarLayout.marginRight = pixelValue;
+ break;
+ case BOTTOM:
+ trimBarLayout.marginBottom = pixelValue;
+ break;
+ case LEFT:
+ trimBarLayout.marginLeft = pixelValue;
+ break;
+ }
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMaxMinVisibleSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMaxMinVisibleSWTHandler.java
index e4dd60ab4..c87b445fb 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMaxMinVisibleSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyMaxMinVisibleSWTHandler.java
@@ -1,108 +1,108 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.w3c.dom.Element;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyMaxMinVisibleSWTHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final ICSSPropertyHandler INSTANCE = new CSSPropertyMaxMinVisibleSWTHandler();
-
- private static final String CSS_CTABFOLDER_MAXMIN_VISIBLE_LISTENER_KEY = "CSS_CTABFOLDER_MAXMIN_VISIBLE_LISTENER_KEY"; //$NON-NLS-1$
-
- @Override
- public void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder))
- return;
-
- CTabFolder folder = (CTabFolder) control;
- boolean visible = (Boolean) engine.convert(value, Boolean.class, null);
-
- ShowMaxMinVisibleListener listener = (ShowMaxMinVisibleListener) folder
- .getData(CSS_CTABFOLDER_MAXMIN_VISIBLE_LISTENER_KEY);
- if (listener == null) {
- listener = new ShowMaxMinVisibleListener(engine);
- folder.addListener(SWT.Paint, listener);
- folder.setData(CSS_CTABFOLDER_MAXMIN_VISIBLE_LISTENER_KEY,
- listener);
- } else {
- listener.setEngine(engine);
- }
-
- if (ICathyConstants.PROPERTY_MAXIMIZE_VISIBLE.equals(property)) {
- folder.setMaximizeVisible(visible);
- } else if (ICathyConstants.PROPERTY_MINIMIZE_VISIBLE.equals(property)) {
- folder.setMinimizeVisible(visible);
- }
- }
-
- @Override
- public String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- if (control instanceof CTabFolder) {
- CTabFolder folder = (CTabFolder) control;
- if (ICathyConstants.PROPERTY_MAXIMIZE_VISIBLE.equals(property)) {
- return Boolean.toString(folder.getMaximizeVisible());
- } else if (ICathyConstants.PROPERTY_MINIMIZE_VISIBLE
- .equals(property)) {
- return Boolean.toString(folder.getMinimizeVisible());
- }
- }
- return null;
- }
-
- private class ShowMaxMinVisibleListener implements Listener {
-
- private CSSEngine engine;
-
- public ShowMaxMinVisibleListener(CSSEngine engine) {
- this.engine = engine;
- }
-
- public void setEngine(CSSEngine engine) {
- this.engine = engine;
- }
-
- public void handleEvent(Event e) {
-
- CTabFolder folder = (CTabFolder) e.widget;
- if (folder == null || folder.isDisposed()) {
- return;
- }
-
- Element element = engine.getElement(folder);
- CSSStyleDeclaration style = engine.getViewCSS()
- .getComputedStyle(element, null);
- if (style != null) {
- CSSValue maximizeVisible = style.getPropertyCSSValue(
- ICathyConstants.PROPERTY_MAXIMIZE_VISIBLE);
- CSSValue minimizeVisible = style.getPropertyCSSValue(
- ICathyConstants.PROPERTY_MINIMIZE_VISIBLE);
- if (maximizeVisible != null) {
- boolean maxVisible = Boolean
- .parseBoolean(maximizeVisible.getCssText());
- if (maxVisible != folder.getMaximizeVisible())
- folder.setMaximizeVisible(maxVisible);
- }
- if (minimizeVisible != null) {
- boolean miniVisible = Boolean
- .parseBoolean(minimizeVisible.getCssText());
- if (miniVisible != folder.getMinimizeVisible())
- folder.setMinimizeVisible(miniVisible);
- }
- }
- }
- }
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.w3c.dom.Element;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyMaxMinVisibleSWTHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final ICSSPropertyHandler INSTANCE = new CSSPropertyMaxMinVisibleSWTHandler();
+
+ private static final String CSS_CTABFOLDER_MAXMIN_VISIBLE_LISTENER_KEY = "CSS_CTABFOLDER_MAXMIN_VISIBLE_LISTENER_KEY"; //$NON-NLS-1$
+
+ @Override
+ public void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder))
+ return;
+
+ CTabFolder folder = (CTabFolder) control;
+ boolean visible = (Boolean) engine.convert(value, Boolean.class, null);
+
+ ShowMaxMinVisibleListener listener = (ShowMaxMinVisibleListener) folder
+ .getData(CSS_CTABFOLDER_MAXMIN_VISIBLE_LISTENER_KEY);
+ if (listener == null) {
+ listener = new ShowMaxMinVisibleListener(engine);
+ folder.addListener(SWT.Paint, listener);
+ folder.setData(CSS_CTABFOLDER_MAXMIN_VISIBLE_LISTENER_KEY,
+ listener);
+ } else {
+ listener.setEngine(engine);
+ }
+
+ if (ICathyConstants.PROPERTY_MAXIMIZE_VISIBLE.equals(property)) {
+ folder.setMaximizeVisible(visible);
+ } else if (ICathyConstants.PROPERTY_MINIMIZE_VISIBLE.equals(property)) {
+ folder.setMinimizeVisible(visible);
+ }
+ }
+
+ @Override
+ public String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ if (control instanceof CTabFolder) {
+ CTabFolder folder = (CTabFolder) control;
+ if (ICathyConstants.PROPERTY_MAXIMIZE_VISIBLE.equals(property)) {
+ return Boolean.toString(folder.getMaximizeVisible());
+ } else if (ICathyConstants.PROPERTY_MINIMIZE_VISIBLE
+ .equals(property)) {
+ return Boolean.toString(folder.getMinimizeVisible());
+ }
+ }
+ return null;
+ }
+
+ private class ShowMaxMinVisibleListener implements Listener {
+
+ private CSSEngine engine;
+
+ public ShowMaxMinVisibleListener(CSSEngine engine) {
+ this.engine = engine;
+ }
+
+ public void setEngine(CSSEngine engine) {
+ this.engine = engine;
+ }
+
+ public void handleEvent(Event e) {
+
+ CTabFolder folder = (CTabFolder) e.widget;
+ if (folder == null || folder.isDisposed()) {
+ return;
+ }
+
+ Element element = engine.getElement(folder);
+ CSSStyleDeclaration style = engine.getViewCSS()
+ .getComputedStyle(element, null);
+ if (style != null) {
+ CSSValue maximizeVisible = style.getPropertyCSSValue(
+ ICathyConstants.PROPERTY_MAXIMIZE_VISIBLE);
+ CSSValue minimizeVisible = style.getPropertyCSSValue(
+ ICathyConstants.PROPERTY_MINIMIZE_VISIBLE);
+ if (maximizeVisible != null) {
+ boolean maxVisible = Boolean
+ .parseBoolean(maximizeVisible.getCssText());
+ if (maxVisible != folder.getMaximizeVisible())
+ folder.setMaximizeVisible(maxVisible);
+ }
+ if (minimizeVisible != null) {
+ boolean miniVisible = Boolean
+ .parseBoolean(minimizeVisible.getCssText());
+ if (miniVisible != folder.getMinimizeVisible())
+ folder.setMinimizeVisible(miniVisible);
+ }
+ }
+ }
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyScrolledFormHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyScrolledFormHandler.java
index cbe8215f5..81c557d31 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyScrolledFormHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyScrolledFormHandler.java
@@ -1,44 +1,44 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyScrolledFormHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyScrolledFormHandler INSTANCE = new CSSPropertyScrolledFormHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof ScrolledForm))
- return;
-
- ScrolledForm form = (ScrolledForm) control;
- if (ICathyConstants.PROPERTY_FG_COLOR.equals(property)) {
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color fgColor = (Color) engine.convert(value, Color.class,
- form.getDisplay());
- form.setForeground(fgColor);
- }
- } else if (ICathyConstants.PROPERTY_BG_COLOR.equals(property)) {
- Color bgColor = (Color) engine.convert(value, Color.class,
- form.getDisplay());
- form.setBackground(bgColor);
- }
-
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyScrolledFormHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyScrolledFormHandler INSTANCE = new CSSPropertyScrolledFormHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof ScrolledForm))
+ return;
+
+ ScrolledForm form = (ScrolledForm) control;
+ if (ICathyConstants.PROPERTY_FG_COLOR.equals(property)) {
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color fgColor = (Color) engine.convert(value, Color.class,
+ form.getDisplay());
+ form.setForeground(fgColor);
+ }
+ } else if (ICathyConstants.PROPERTY_BG_COLOR.equals(property)) {
+ Color bgColor = (Color) engine.convert(value, Color.class,
+ form.getDisplay());
+ form.setBackground(bgColor);
+ }
+
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertySectionHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertySectionHandler.java
index 45ee76415..2f381997c 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertySectionHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertySectionHandler.java
@@ -1,54 +1,54 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.forms.widgets.Section;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertySectionHandler extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertySectionHandler INSTANCE = new CSSPropertySectionHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof Section))
- return;
-
- Section section = (Section) control;
- if (ICathyConstants.PROPERTY_TITLE_BAR_TEXT_COLOR.equals(property)) {
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color textColor = (Color) engine.convert(value, Color.class,
- section.getDisplay());
- section.setTitleBarForeground(textColor);
- section.setToggleColor(textColor);
- }
- } else if (ICathyConstants.PROPERTY_TITLE_BAR_ACTIVE_TEXT_COLOR
- .equals(property)) {
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color activeTextColor = (Color) engine.convert(value,
- Color.class, section.getDisplay());
- section.setActiveToggleColor(activeTextColor);
- }
- }
-
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- if (control instanceof Section) {
- Section section = (Section) control;
- if (ICathyConstants.PROPERTY_TITLE_BAR_TEXT_COLOR
- .equals(property)) {
- Color textColor = section.getTitleBarForeground();
- return engine.convert(textColor, Color.class, null);
- }
- }
- return null;
- }
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.widgets.Section;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertySectionHandler extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertySectionHandler INSTANCE = new CSSPropertySectionHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof Section))
+ return;
+
+ Section section = (Section) control;
+ if (ICathyConstants.PROPERTY_TITLE_BAR_TEXT_COLOR.equals(property)) {
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color textColor = (Color) engine.convert(value, Color.class,
+ section.getDisplay());
+ section.setTitleBarForeground(textColor);
+ section.setToggleColor(textColor);
+ }
+ } else if (ICathyConstants.PROPERTY_TITLE_BAR_ACTIVE_TEXT_COLOR
+ .equals(property)) {
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color activeTextColor = (Color) engine.convert(value,
+ Color.class, section.getDisplay());
+ section.setActiveToggleColor(activeTextColor);
+ }
+ }
+
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ if (control instanceof Section) {
+ Section section = (Section) control;
+ if (ICathyConstants.PROPERTY_TITLE_BAR_TEXT_COLOR
+ .equals(property)) {
+ Color textColor = section.getTitleBarForeground();
+ return engine.convert(textColor, Color.class, null);
+ }
+ }
+ return null;
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertySelectedTabAreaSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertySelectedTabAreaSWTHandler.java
index d99e5d022..0c37a5b44 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertySelectedTabAreaSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertySelectedTabAreaSWTHandler.java
@@ -1,63 +1,63 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSValue;
-
-@SuppressWarnings("restriction")
-public class CSSPropertySelectedTabAreaSWTHandler extends
- AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertySelectedTabAreaSWTHandler INSTANCE = new CSSPropertySelectedTabAreaSWTHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder)) {
- return;
- }
-
- CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
- if (!(renderer instanceof ICTabFolderRendering))
- return;
-
- ICTabFolderRendering tabFolderRendering = (ICTabFolderRendering) renderer;
-
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color color = (Color) engine.convert(value, Color.class,
- control.getDisplay());
- tabFolderRendering.setSelectedTabAreaColor(color);
- return;
- }
-
- if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
- Gradient grad = (Gradient) engine.convert(value, Gradient.class,
- control.getDisplay());
- if (grad == null) {
- return;
- }
- Color[] colors = null;
- int[] percents = null;
- if (!grad.getValues().isEmpty()) {
- colors = CSSSWTColorHelper.getSWTColors(grad,
- control.getDisplay(), engine);
- percents = CSSSWTColorHelper.getPercents(grad);
- }
- tabFolderRendering.setSelectedTabAreaColor(colors, percents);
- }
-
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSValue;
+
+@SuppressWarnings("restriction")
+public class CSSPropertySelectedTabAreaSWTHandler extends
+ AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertySelectedTabAreaSWTHandler INSTANCE = new CSSPropertySelectedTabAreaSWTHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder)) {
+ return;
+ }
+
+ CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
+ if (!(renderer instanceof ICTabFolderRendering))
+ return;
+
+ ICTabFolderRendering tabFolderRendering = (ICTabFolderRendering) renderer;
+
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color color = (Color) engine.convert(value, Color.class,
+ control.getDisplay());
+ tabFolderRendering.setSelectedTabAreaColor(color);
+ return;
+ }
+
+ if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
+ Gradient grad = (Gradient) engine.convert(value, Gradient.class,
+ control.getDisplay());
+ if (grad == null) {
+ return;
+ }
+ Color[] colors = null;
+ int[] percents = null;
+ if (!grad.getValues().isEmpty()) {
+ colors = CSSSWTColorHelper.getSWTColors(grad,
+ control.getDisplay(), engine);
+ percents = CSSSWTColorHelper.getPercents(grad);
+ }
+ tabFolderRendering.setSelectedTabAreaColor(colors, percents);
+ }
+
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyTabBorderVisibleSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyTabBorderVisibleSWTHandler.java
index 95fcad352..b488c052f 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyTabBorderVisibleSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyTabBorderVisibleSWTHandler.java
@@ -1,47 +1,47 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyTabBorderVisibleSWTHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final ICSSPropertyHandler INSTANCE = new CSSPropertyTabBorderVisibleSWTHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder)) {
- return;
- }
- boolean borderVisible = (Boolean) engine.convert(value, Boolean.class,
- null);
- CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
- if (renderer instanceof ICTabFolderRendering) {
- if (ICathyConstants.PROPERTY_OUTER_BORDER_VISIBLE
- .equals(property)) {
- ((ICTabFolderRendering) renderer)
- .setOuterBorderVisible(borderVisible);
- } else if (ICathyConstants.PROPERTY_INNER_BORDER_VISIBLE
- .equals(property)) {
- ((ICTabFolderRendering) renderer)
- .setInnerBorderVisible(borderVisible);
- }
- }
-
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyTabBorderVisibleSWTHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final ICSSPropertyHandler INSTANCE = new CSSPropertyTabBorderVisibleSWTHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder)) {
+ return;
+ }
+ boolean borderVisible = (Boolean) engine.convert(value, Boolean.class,
+ null);
+ CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
+ if (renderer instanceof ICTabFolderRendering) {
+ if (ICathyConstants.PROPERTY_OUTER_BORDER_VISIBLE
+ .equals(property)) {
+ ((ICTabFolderRendering) renderer)
+ .setOuterBorderVisible(borderVisible);
+ } else if (ICathyConstants.PROPERTY_INNER_BORDER_VISIBLE
+ .equals(property)) {
+ ((ICTabFolderRendering) renderer)
+ .setInnerBorderVisible(borderVisible);
+ }
+ }
+
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyTabIconTextVisibleSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyTabIconTextVisibleSWTHandler.java
index e2dd8cd22..df52fd81b 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyTabIconTextVisibleSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyTabIconTextVisibleSWTHandler.java
@@ -1,41 +1,41 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyTabIconTextVisibleSWTHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyTabIconTextVisibleSWTHandler INSTANCE = new CSSPropertyTabIconTextVisibleSWTHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder)) {
- return;
- }
- boolean visible = (Boolean) engine.convert(value, Boolean.class, null);
- CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
- if (renderer instanceof ICTabFolderRendering) {
- if (ICathyConstants.PROPERTY_IMAGE_VISIBLE.equals(property)) {
- ((ICTabFolderRendering) renderer).setImageVisible(visible);
- } else if (ICathyConstants.PROPERTY_TEXT_VISIBLE.equals(property)) {
- ((ICTabFolderRendering) renderer).setTextVisible(visible);
- }
- }
-
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyTabIconTextVisibleSWTHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyTabIconTextVisibleSWTHandler INSTANCE = new CSSPropertyTabIconTextVisibleSWTHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder)) {
+ return;
+ }
+ boolean visible = (Boolean) engine.convert(value, Boolean.class, null);
+ CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
+ if (renderer instanceof ICTabFolderRendering) {
+ if (ICathyConstants.PROPERTY_IMAGE_VISIBLE.equals(property)) {
+ ((ICTabFolderRendering) renderer).setImageVisible(visible);
+ } else if (ICathyConstants.PROPERTY_TEXT_VISIBLE.equals(property)) {
+ ((ICTabFolderRendering) renderer).setTextVisible(visible);
+ }
+ }
+
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyToolBarSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyToolBarSWTHandler.java
index 18ace44bf..1ad346acc 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyToolBarSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyToolBarSWTHandler.java
@@ -1,87 +1,87 @@
-package org.xmind.cathy.internal.css;
-
-import java.net.URL;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.ToolBar;
-import org.eclipse.swt.widgets.ToolItem;
-import org.w3c.dom.css.CSSPrimitiveValue;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyToolBarSWTHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final CSSPropertyToolBarSWTHandler INSTANCE = new CSSPropertyToolBarSWTHandler();
-
- private static final String TOOLBAR_TAG_VIEW_MENU = "ViewMenu"; //$NON-NLS-1$
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof ToolBar))
- return;
-
- ToolBar toolBar = (ToolBar) control;
- if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
- Color color = (Color) engine.convert(value, Color.class,
- toolBar.getDisplay());
- toolBar.setForeground(color);
-
- ToolItem[] items = toolBar.getItems();
- for (ToolItem each : items) {
- String text = each.getText();
- each.setText(text);
- }
- } else if (ICathyConstants.PROPERTY_VIEW_MENU.equals(property)) {
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- if (((CSSPrimitiveValue) value)
- .getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
- String imageUrl = ((CSSPrimitiveValue) value)
- .getStringValue();
- ImageDescriptor imageDescriptor = ImageDescriptor
- .createFromURL(new URL(imageUrl.toString()));
- Image image = JFaceResources.getResources()
- .createImage(imageDescriptor);
- if (TOOLBAR_TAG_VIEW_MENU.equals(toolBar.getData())) {
- toolBar.getItem(0).setImage(image);
- }
-
- }
- }
- }
-// else if ("xswt-view-properties-pin".equals(property)) {
-// ToolItem[] items = toolBar.getItems();
-// for (ToolItem each : items) {
-// Object data = each.getData();
-// if (data instanceof ActionContributionItem) {
-// String id = ((ActionContributionItem) data).getId();
-// if (id.contains("org.eclipse.ui.views.properties.PinPropertySheetAction")) {
-//
-// }
-// }
-// }
-// }
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- if (control instanceof ToolBar) {
- if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
- Color fgColor = ((ToolBar) control).getForeground();
- return engine.convert(fgColor, Color.class, null);
- }
-
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import java.net.URL;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.w3c.dom.css.CSSPrimitiveValue;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyToolBarSWTHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final CSSPropertyToolBarSWTHandler INSTANCE = new CSSPropertyToolBarSWTHandler();
+
+ private static final String TOOLBAR_TAG_VIEW_MENU = "ViewMenu"; //$NON-NLS-1$
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof ToolBar))
+ return;
+
+ ToolBar toolBar = (ToolBar) control;
+ if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
+ Color color = (Color) engine.convert(value, Color.class,
+ toolBar.getDisplay());
+ toolBar.setForeground(color);
+
+ ToolItem[] items = toolBar.getItems();
+ for (ToolItem each : items) {
+ String text = each.getText();
+ each.setText(text);
+ }
+ } else if (ICathyConstants.PROPERTY_VIEW_MENU.equals(property)) {
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ if (((CSSPrimitiveValue) value)
+ .getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
+ String imageUrl = ((CSSPrimitiveValue) value)
+ .getStringValue();
+ ImageDescriptor imageDescriptor = ImageDescriptor
+ .createFromURL(new URL(imageUrl.toString()));
+ Image image = JFaceResources.getResources()
+ .createImage(imageDescriptor);
+ if (TOOLBAR_TAG_VIEW_MENU.equals(toolBar.getData())) {
+ toolBar.getItem(0).setImage(image);
+ }
+
+ }
+ }
+ }
+// else if ("xswt-view-properties-pin".equals(property)) {
+// ToolItem[] items = toolBar.getItems();
+// for (ToolItem each : items) {
+// Object data = each.getData();
+// if (data instanceof ActionContributionItem) {
+// String id = ((ActionContributionItem) data).getId();
+// if (id.contains("org.eclipse.ui.views.properties.PinPropertySheetAction")) {
+//
+// }
+// }
+// }
+// }
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ if (control instanceof ToolBar) {
+ if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
+ Color fgColor = ((ToolBar) control).getForeground();
+ return engine.convert(fgColor, Color.class, null);
+ }
+
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyUnselectedTabsColorSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyUnselectedTabsColorSWTHandler.java
index fc7aa2ac5..41d5d59b9 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyUnselectedTabsColorSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyUnselectedTabsColorSWTHandler.java
@@ -1,126 +1,126 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
-import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.e4.ui.internal.css.swt.ICTabRendering;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyUnselectedTabsColorSWTHandler
- extends AbstractCSSPropertySWTHandler {
-
- private static final String RESIZE_LISTENER = "CSSPropertyUnselectedTabsColorSWTHandler.resizeListener"; //$NON-NLS-1$
-
- public static final ICSSPropertyHandler INSTANCE = new CSSPropertyUnselectedTabsColorSWTHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder)
- || !isUnselectedTabsColorProp(property)) {
- return;
- }
- CTabFolder folder = ((CTabFolder) control);
- CTabFolderRenderer renderer = folder.getRenderer();
- if (!(renderer instanceof ICTabRendering)) {
- return;
- }
-
- if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
- Color color = (Color) engine.convert(value, Color.class,
- control.getDisplay());
- ((ICTabRendering) renderer).setUnselectedTabsColor(color);
- folder.setBackground(null);
- removeResizeEventListener(folder);
- return;
- }
- if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
- Gradient grad = (Gradient) engine.convert(value, Gradient.class,
- control.getDisplay());
- if (grad == null) {
- return;
- }
- Color[] colors = null;
- int[] percents = null;
- if (!grad.getValues().isEmpty()) {
- colors = CSSSWTColorHelper.getSWTColors(grad,
- control.getDisplay(), engine);
- percents = CSSSWTColorHelper.getPercents(grad);
- }
- ((ICTabRendering) renderer).setUnselectedTabsColor(colors,
- percents);
- folder.setBackground(null, null, false);
- appendResizeEventListener(folder);
- }
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
- private boolean isUnselectedTabsColorProp(String property) {
- return ICathyConstants.PROPERTY_UNSELECTED_TABS_COLOR.equals(property);
- }
-
- // TODO: It needs to be refactored when the Bug 33276 gets fixed
- private void appendResizeEventListener(CTabFolder folder) {
- if (hasResizeEventListener(folder)) {
- return;
- }
-
- final Listener resizeListener = new Listener() {
- public void handleEvent(Event event) {
- CTabFolder folder = (CTabFolder) event.widget;
- for (Control child : folder.getChildren()) {
- if (isReskinRequired(child)) {
- child.reskin(SWT.NONE);
- }
- }
- }
- };
-
- folder.addListener(SWT.Resize, resizeListener);
- folder.setData(RESIZE_LISTENER, resizeListener);
- folder.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- e.widget.removeListener(SWT.Resize, resizeListener);
- }
- });
- }
-
- private void removeResizeEventListener(CTabFolder folder) {
- Object obj = folder.getData(RESIZE_LISTENER);
- if (obj instanceof Listener) {
- folder.removeListener(SWT.Resize, (Listener) obj);
- folder.setData(RESIZE_LISTENER, null);
- }
- }
-
- private boolean hasResizeEventListener(CTabFolder folder) {
- return folder.getData(RESIZE_LISTENER) instanceof Listener;
- }
-
- private boolean isReskinRequired(Control control) {
- if (control instanceof Composite) {
- Composite composite = (Composite) control;
- return composite.isVisible() && composite.getChildren().length > 0;
- }
- return false;
- }
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.e4.ui.internal.css.swt.ICTabRendering;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyUnselectedTabsColorSWTHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ private static final String RESIZE_LISTENER = "CSSPropertyUnselectedTabsColorSWTHandler.resizeListener"; //$NON-NLS-1$
+
+ public static final ICSSPropertyHandler INSTANCE = new CSSPropertyUnselectedTabsColorSWTHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder)
+ || !isUnselectedTabsColorProp(property)) {
+ return;
+ }
+ CTabFolder folder = ((CTabFolder) control);
+ CTabFolderRenderer renderer = folder.getRenderer();
+ if (!(renderer instanceof ICTabRendering)) {
+ return;
+ }
+
+ if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
+ Color color = (Color) engine.convert(value, Color.class,
+ control.getDisplay());
+ ((ICTabRendering) renderer).setUnselectedTabsColor(color);
+ folder.setBackground(null);
+ removeResizeEventListener(folder);
+ return;
+ }
+ if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
+ Gradient grad = (Gradient) engine.convert(value, Gradient.class,
+ control.getDisplay());
+ if (grad == null) {
+ return;
+ }
+ Color[] colors = null;
+ int[] percents = null;
+ if (!grad.getValues().isEmpty()) {
+ colors = CSSSWTColorHelper.getSWTColors(grad,
+ control.getDisplay(), engine);
+ percents = CSSSWTColorHelper.getPercents(grad);
+ }
+ ((ICTabRendering) renderer).setUnselectedTabsColor(colors,
+ percents);
+ folder.setBackground(null, null, false);
+ appendResizeEventListener(folder);
+ }
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+ private boolean isUnselectedTabsColorProp(String property) {
+ return ICathyConstants.PROPERTY_UNSELECTED_TABS_COLOR.equals(property);
+ }
+
+ // TODO: It needs to be refactored when the Bug 33276 gets fixed
+ private void appendResizeEventListener(CTabFolder folder) {
+ if (hasResizeEventListener(folder)) {
+ return;
+ }
+
+ final Listener resizeListener = new Listener() {
+ public void handleEvent(Event event) {
+ CTabFolder folder = (CTabFolder) event.widget;
+ for (Control child : folder.getChildren()) {
+ if (isReskinRequired(child)) {
+ child.reskin(SWT.NONE);
+ }
+ }
+ }
+ };
+
+ folder.addListener(SWT.Resize, resizeListener);
+ folder.setData(RESIZE_LISTENER, resizeListener);
+ folder.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ e.widget.removeListener(SWT.Resize, resizeListener);
+ }
+ });
+ }
+
+ private void removeResizeEventListener(CTabFolder folder) {
+ Object obj = folder.getData(RESIZE_LISTENER);
+ if (obj instanceof Listener) {
+ folder.removeListener(SWT.Resize, (Listener) obj);
+ folder.setData(RESIZE_LISTENER, null);
+ }
+ }
+
+ private boolean hasResizeEventListener(CTabFolder folder) {
+ return folder.getData(RESIZE_LISTENER) instanceof Listener;
+ }
+
+ private boolean isReskinRequired(Control control) {
+ if (control instanceof Composite) {
+ Composite composite = (Composite) control;
+ return composite.isVisible() && composite.getChildren().length > 0;
+ }
+ return false;
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyUnselectedTabsFillVisibleSWTHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyUnselectedTabsFillVisibleSWTHandler.java
index 432c14aff..317e78c0b 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyUnselectedTabsFillVisibleSWTHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyUnselectedTabsFillVisibleSWTHandler.java
@@ -1,43 +1,43 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.widgets.Control;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyUnselectedTabsFillVisibleSWTHandler
- extends AbstractCSSPropertySWTHandler {
-
- public static final ICSSPropertyHandler INSTANCE = new CSSPropertyUnselectedTabsFillVisibleSWTHandler();
-
- @Override
- protected void applyCSSProperty(Control control, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(control instanceof CTabFolder)) {
- return;
- }
- boolean unselectedTabsBackgroundVisible = (Boolean) engine
- .convert(value, Boolean.class, null);
- CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
- if (renderer instanceof ICTabFolderRendering) {
- if (ICathyConstants.PROPERTY_UNSELECTED_TABS_BG_VISIBLE
- .equals(property)) {
- ((ICTabFolderRendering) renderer)
- .setUnselectedTabsBackgroundVisible(
- unselectedTabsBackgroundVisible);
- }
- }
- }
-
- @Override
- protected String retrieveCSSProperty(Control control, String property,
- String pseudo, CSSEngine engine) throws Exception {
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyUnselectedTabsFillVisibleSWTHandler
+ extends AbstractCSSPropertySWTHandler {
+
+ public static final ICSSPropertyHandler INSTANCE = new CSSPropertyUnselectedTabsFillVisibleSWTHandler();
+
+ @Override
+ protected void applyCSSProperty(Control control, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(control instanceof CTabFolder)) {
+ return;
+ }
+ boolean unselectedTabsBackgroundVisible = (Boolean) engine
+ .convert(value, Boolean.class, null);
+ CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
+ if (renderer instanceof ICTabFolderRendering) {
+ if (ICathyConstants.PROPERTY_UNSELECTED_TABS_BG_VISIBLE
+ .equals(property)) {
+ ((ICTabFolderRendering) renderer)
+ .setUnselectedTabsBackgroundVisible(
+ unselectedTabsBackgroundVisible);
+ }
+ }
+ }
+
+ @Override
+ protected String retrieveCSSProperty(Control control, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyXShowCloseHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyXShowCloseHandler.java
index 9f0194e54..9ed11430d 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyXShowCloseHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CSSPropertyXShowCloseHandler.java
@@ -1,149 +1,149 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers;
-import org.eclipse.e4.ui.css.swt.properties.custom.CTabETabHelper;
-import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CTabItem;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Item;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Widget;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.CSSValue;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CSSPropertyXShowCloseHandler extends CTabETabHelper
- implements ICSSPropertyHandler {
-
- public static final ICSSPropertyHandler INSTANCE = new CSSPropertyXShowCloseHandler();
-
- private static final String CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY = "CSS_CTABFOLDER_SELECTED_SHOW_CLOSE_LISTENER_KEY"; //$NON-NLS-1$
-
- private static final String SUPPORTED_PSEUDO = "selected"; //$NON-NLS-1$
-
- private static final String TAG_NOCLOSE = "NoClose"; //$NON-NLS-1$
-
- public boolean applyCSSProperty(Object element, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- Widget widget = SWTElementHelpers.getWidget(element);
- if (widget instanceof CTabItem) {
- Item item = (Item) widget;
- boolean showClose = ((Boolean) engine.convert(value, Boolean.class,
- null)).booleanValue();
-
- if (SUPPORTED_PSEUDO.equals(pseudo)) {
- Control parent = getParent(widget);
-
- ShowCloseSelectionListener listener = (ShowCloseSelectionListener) parent
- .getData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY);
- if (listener == null) {
- listener = new ShowCloseSelectionListener(engine);
- parent.addListener(SWT.Paint, listener);
- parent.setData(
- CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY,
- listener);
- } else {
- listener.setEngine(engine);
- }
- item = getSelection(getParent(widget));
-
- if (item != null) {
- internalSetShowClose(item, showClose);
- }
- } else {
- internalSetShowClose(item, showClose);
- }
- return true;
- }
- return false;
- }
-
- public String retrieveCSSProperty(Object element, String property,
- String pseudo, CSSEngine engine) throws Exception {
- Widget widget = SWTElementHelpers.getWidget(element);
- if (widget instanceof CTabItem) {
- CTabItem item = (CTabItem) widget;
- return Boolean.toString(item.getShowClose());
- }
- return null;
- }
-
- private class ShowCloseSelectionListener implements Listener {
-
- private CSSEngine engine;
-
- public ShowCloseSelectionListener(CSSEngine engine) {
- this.engine = engine;
- }
-
- public void setEngine(CSSEngine engine) {
- this.engine = engine;
- }
-
- public void handleEvent(Event e) {
-
- Item selection = getSelection(e.widget);
-
- if (selection == null || selection.isDisposed()) {
- return;
- }
-
- Item[] items = getItems(e.widget);
- int selectionIndex = getSelectionIndex(e.widget);
-
- boolean selectionSet = false;
-
- CSSStyleDeclaration selectedStyle = engine.getViewCSS()
- .getComputedStyle(engine.getElement(selection),
- SUPPORTED_PSEUDO);
- if (selectedStyle != null) {
- CSSValue value = selectedStyle.getPropertyCSSValue(
- ICathyConstants.PROPERTY_SHOW_CLOSE);
- if (value != null) {
- internalSetShowClose(selection,
- Boolean.parseBoolean(value.getCssText()));
- selectionSet = true;
- }
- }
-
- CSSStyleDeclaration unselectedStyle = engine.getViewCSS()
- .getComputedStyle(engine.getElement(selection), null);
- if (unselectedStyle == null) {
- for (int i = 0; i < items.length; i++) {
- if (selectionSet && i != selectionIndex) {
- internalSetShowClose(items[i], false);
- }
- }
- } else {
- CSSValue value = unselectedStyle.getPropertyCSSValue(
- ICathyConstants.PROPERTY_SHOW_CLOSE);
- boolean unselectedShowClose = value == null ? false
- : Boolean.parseBoolean(value.getCssText());
- for (int i = 0; i < items.length; i++) {
- if (selectionSet && i != selectionIndex) {
- internalSetShowClose(items[i], unselectedShowClose);
- }
- }
- }
-
- }
- }
-
- private void internalSetShowClose(Item item, boolean showClose) {
- Object data = item.getData(AbstractPartRenderer.OWNING_ME);
- if (data instanceof MUIElement) {
- boolean noClose = ((MUIElement) data).getTags()
- .contains(TAG_NOCLOSE);
- if (noClose)
- showClose = !noClose;
- }
- if (item instanceof CTabItem)
- ((CTabItem) item).setShowClose(showClose);
- }
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers;
+import org.eclipse.e4.ui.css.swt.properties.custom.CTabETabHelper;
+import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Widget;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.CSSValue;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CSSPropertyXShowCloseHandler extends CTabETabHelper
+ implements ICSSPropertyHandler {
+
+ public static final ICSSPropertyHandler INSTANCE = new CSSPropertyXShowCloseHandler();
+
+ private static final String CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY = "CSS_CTABFOLDER_SELECTED_SHOW_CLOSE_LISTENER_KEY"; //$NON-NLS-1$
+
+ private static final String SUPPORTED_PSEUDO = "selected"; //$NON-NLS-1$
+
+ private static final String TAG_NOCLOSE = "NoClose"; //$NON-NLS-1$
+
+ public boolean applyCSSProperty(Object element, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ Widget widget = SWTElementHelpers.getWidget(element);
+ if (widget instanceof CTabItem) {
+ Item item = (Item) widget;
+ boolean showClose = ((Boolean) engine.convert(value, Boolean.class,
+ null)).booleanValue();
+
+ if (SUPPORTED_PSEUDO.equals(pseudo)) {
+ Control parent = getParent(widget);
+
+ ShowCloseSelectionListener listener = (ShowCloseSelectionListener) parent
+ .getData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY);
+ if (listener == null) {
+ listener = new ShowCloseSelectionListener(engine);
+ parent.addListener(SWT.Paint, listener);
+ parent.setData(
+ CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY,
+ listener);
+ } else {
+ listener.setEngine(engine);
+ }
+ item = getSelection(getParent(widget));
+
+ if (item != null) {
+ internalSetShowClose(item, showClose);
+ }
+ } else {
+ internalSetShowClose(item, showClose);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public String retrieveCSSProperty(Object element, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ Widget widget = SWTElementHelpers.getWidget(element);
+ if (widget instanceof CTabItem) {
+ CTabItem item = (CTabItem) widget;
+ return Boolean.toString(item.getShowClose());
+ }
+ return null;
+ }
+
+ private class ShowCloseSelectionListener implements Listener {
+
+ private CSSEngine engine;
+
+ public ShowCloseSelectionListener(CSSEngine engine) {
+ this.engine = engine;
+ }
+
+ public void setEngine(CSSEngine engine) {
+ this.engine = engine;
+ }
+
+ public void handleEvent(Event e) {
+
+ Item selection = getSelection(e.widget);
+
+ if (selection == null || selection.isDisposed()) {
+ return;
+ }
+
+ Item[] items = getItems(e.widget);
+ int selectionIndex = getSelectionIndex(e.widget);
+
+ boolean selectionSet = false;
+
+ CSSStyleDeclaration selectedStyle = engine.getViewCSS()
+ .getComputedStyle(engine.getElement(selection),
+ SUPPORTED_PSEUDO);
+ if (selectedStyle != null) {
+ CSSValue value = selectedStyle.getPropertyCSSValue(
+ ICathyConstants.PROPERTY_SHOW_CLOSE);
+ if (value != null) {
+ internalSetShowClose(selection,
+ Boolean.parseBoolean(value.getCssText()));
+ selectionSet = true;
+ }
+ }
+
+ CSSStyleDeclaration unselectedStyle = engine.getViewCSS()
+ .getComputedStyle(engine.getElement(selection), null);
+ if (unselectedStyle == null) {
+ for (int i = 0; i < items.length; i++) {
+ if (selectionSet && i != selectionIndex) {
+ internalSetShowClose(items[i], false);
+ }
+ }
+ } else {
+ CSSValue value = unselectedStyle.getPropertyCSSValue(
+ ICathyConstants.PROPERTY_SHOW_CLOSE);
+ boolean unselectedShowClose = value == null ? false
+ : Boolean.parseBoolean(value.getCssText());
+ for (int i = 0; i < items.length; i++) {
+ if (selectionSet && i != selectionIndex) {
+ internalSetShowClose(items[i], unselectedShowClose);
+ }
+ }
+ }
+
+ }
+ }
+
+ private void internalSetShowClose(Item item, boolean showClose) {
+ Object data = item.getData(AbstractPartRenderer.OWNING_ME);
+ if (data instanceof MUIElement) {
+ boolean noClose = ((MUIElement) data).getTags()
+ .contains(TAG_NOCLOSE);
+ if (noClose)
+ showClose = !noClose;
+ }
+ if (item instanceof CTabItem)
+ ((CTabItem) item).setShowClose(showClose);
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CathyCTabFolderRendering.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CathyCTabFolderRendering.java
index 5c180f592..61e542bf6 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CathyCTabFolderRendering.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/CathyCTabFolderRendering.java
@@ -1,1951 +1,1952 @@
-package org.xmind.cathy.internal.css;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import javax.inject.Inject;
-
-import org.eclipse.e4.ui.css.swt.dom.CTabFolderElement;
-import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
-import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
-import org.eclipse.swt.custom.CTabItem;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.PaletteData;
-import org.eclipse.swt.graphics.Pattern;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.graphics.Region;
-import org.eclipse.swt.graphics.TextLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.ToolBar;
-import org.xmind.cathy.internal.ICathyConstants;
-
-@SuppressWarnings("restriction")
-public class CathyCTabFolderRendering extends CTabFolderRenderer
- implements ICTabFolderRendering {
- private static final String CONTAINS_TOOLBAR = "CathyCTabFolderRendering.containsToolbar"; //$NON-NLS-1$
-
- // Constants for circle drawing
- final static int LEFT_TOP = 0;
- final static int LEFT_BOTTOM = 1;
- final static int RIGHT_TOP = 2;
- final static int RIGHT_BOTTOM = 3;
-
- // drop shadow constants
- final static int SIDE_DROP_WIDTH = 3;
- final static int BOTTOM_DROP_WIDTH = 4;
-
- // keylines
- final static int OUTER_KEYLINE = 1;
- final static int INNER_KEYLINE = 0;
- final static int TOP_KEYLINE = 0;
-
- // Item Constants
- static final int ITEM_TOP_MARGIN = 2;
- static final int ITEM_BOTTOM_MARGIN = 6;
- static final int ITEM_LEFT_MARGIN = 8;
- static final int ITEM_RIGHT_MARGIN = 4;
- static final int INTERNAL_SPACING = 4;
-
- static final int FLAGS = SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC;
- static final String ELLIPSIS = "..."; //$NON-NLS-1$
- static final String E4_TOOLBAR_ACTIVE_IMAGE = "org.eclipse.e4.renderer.toolbar_background_active_image"; //$NON-NLS-1$
- static final String E4_TOOLBAR_INACTIVE_IMAGE = "org.eclipse.e4.renderer.toolbar_background_inactive_image"; //$NON-NLS-1$
-
- static final int BUTTON_BORDER = SWT.COLOR_WIDGET_DARK_SHADOW;
- static final int BUTTON_SIZE = 16;
-
- static final RGB CLOSE_FILL = new RGB(252, 160, 160);
-
- private Color closeFillColor;
-
- int[] shape;
-
- Image shadowImage, toolbarActiveImage, toolbarInactiveImage;
-
- int cornerSize = 14;
-
- //The best value
- boolean shadowEnabled = true;
- Color shadowColor;
- Color outerKeyline, innerKeyline;
- Color[] activeToolbar;
- int[] activePercents;
- Color[] inactiveToolbar;
- int[] inactivePercents;
- boolean active;
-
- Color[] selectedTabFillColors;
- int[] selectedTabFillPercents;
-
- Color[] selectedTabAreaColors;
- int[] selectedTabAreaPercents;
-
- Color[] unselectedTabsColors;
- int[] unselectedTabsPercents;
-
- Color[] hoverTabColors;
- int[] hoverTabPercents;
-
- Color tabOutlineColor;
-
- int paddingLeft = 2, paddingRight = 2, paddingTop = 2, paddingBottom = 2;
-
- private CTabFolderRendererWrapper rendererWrapper;
- private CTabFolderWrapper parentWrapper;
-
- private boolean textVisible = true;
-
- private boolean imageVisible = true;
-
- private boolean outerBorderVisible = true;
- private boolean innerBorderVisible = true;
-
- private boolean unselectedTabsBackgroundVisible = true;
-
- private Image maxImage;
-
- private Image minImage;
-
- private Image closeImage;
-
- private Image closeHoverImage;
-
- private int[] tabArea;
-
- //temp
- private boolean hoverBorderVisible = false;
-
- private boolean nothingToRender = false;
-
- @Inject
- public CathyCTabFolderRendering(CTabFolder parent) {
- super(parent);
- parentWrapper = new CTabFolderWrapper(parent);
- rendererWrapper = new CTabFolderRendererWrapper(this);
- }
-
- @Override
- protected Rectangle computeTrim(int part, int state, int x, int y,
- int width, int height) {
- if (!nothingToRender) {
- boolean onBottom = isTabOnBottom();
- int borderTop = onBottom ? INNER_KEYLINE + OUTER_KEYLINE
- : TOP_KEYLINE + OUTER_KEYLINE;
- int borderBottom = onBottom ? TOP_KEYLINE + OUTER_KEYLINE
- : INNER_KEYLINE + OUTER_KEYLINE;
- int marginWidth = parent.marginWidth;
- int marginHeight = parent.marginHeight;
- int sideDropWidth = shadowEnabled ? SIDE_DROP_WIDTH : 0;
- int bottomDropWidth = shadowEnabled ? BOTTOM_DROP_WIDTH : 0;
- int headerBorderBottom = outerBorderVisible ? OUTER_KEYLINE : 0;
- switch (part) {
- //body trimmed + body client area
- case PART_BODY:
- if (state == SWT.FILL) {
- x = x - paddingLeft - sideDropWidth
- - (INNER_KEYLINE + OUTER_KEYLINE) - marginWidth;
- int tabHeight = parent.getTabHeight() + 1;
- y = onBottom
- ? y - paddingTop - marginHeight - borderTop
- - bottomDropWidth
- : y - paddingTop - marginHeight - tabHeight
- - borderTop - headerBorderBottom
- - bottomDropWidth;
- width = 2 * (INNER_KEYLINE + OUTER_KEYLINE) + paddingLeft
- + paddingRight + 2 * sideDropWidth
- + 2 * marginWidth;
- height += paddingTop + paddingBottom + bottomDropWidth;
- height += tabHeight + headerBorderBottom + borderBottom
- + borderTop;
- } else {
- x = x - marginWidth - OUTER_KEYLINE - INNER_KEYLINE
- - sideDropWidth - (cornerSize / 2) - paddingLeft;
- width = width + 2 * OUTER_KEYLINE + 2 * INNER_KEYLINE
- + 2 * marginWidth + 2 * sideDropWidth + cornerSize
- + paddingRight + paddingLeft;
- int tabHeight = parent.getTabHeight() + 1;
- if (parent.getMinimized()) {
- y = onBottom ? y - borderTop - 5
- : y - tabHeight - borderTop - 5;
- height = borderTop + borderBottom + tabHeight;
- } else {
- y = onBottom
- ? y - marginHeight - borderTop - paddingTop
- - bottomDropWidth
- : y - marginHeight - tabHeight - borderTop
- - paddingTop - headerBorderBottom
- - bottomDropWidth;
- height = height + borderBottom + borderTop
- + 2 * marginHeight + tabHeight
- + headerBorderBottom + bottomDropWidth
- + paddingTop + paddingBottom;
- }
- }
- break;
- case PART_HEADER:
- x = x - (INNER_KEYLINE + OUTER_KEYLINE) - marginWidth
- - sideDropWidth;
- width = width + 2 * (INNER_KEYLINE + OUTER_KEYLINE)
- + 2 * marginWidth + 2 * sideDropWidth;
- y = y - borderTop - marginHeight;
- break;
- case PART_BORDER:
- x = x - INNER_KEYLINE - OUTER_KEYLINE - sideDropWidth
- - (cornerSize / 4);
- width = width + 2 * (INNER_KEYLINE + OUTER_KEYLINE)
- + 2 * sideDropWidth + cornerSize / 2;
- height = height + borderTop + borderBottom;
- y = y - borderTop;
- if (onBottom) {
- if (shadowEnabled) {
- height += 3;
- }
- }
- break;
- default:
- if (0 <= part && part < parent.getItemCount()) {
- x = x - ITEM_LEFT_MARGIN;// - (CORNER_SIZE/2);
- width = width + ITEM_LEFT_MARGIN + ITEM_RIGHT_MARGIN + 1;
- y = y - ITEM_TOP_MARGIN;
- height = height + ITEM_TOP_MARGIN + ITEM_BOTTOM_MARGIN;
- }
- break;
- }
- }
- return new Rectangle(x, y, width, height);
- }
-
- @Override
- protected Point computeSize(int part, int state, GC gc, int wHint,
- int hHint) {
- int width = 0, height = 0;
- switch (part) {
- case PART_HEADER:
- int fixedTabHeight = parentWrapper.getFixedTabHeight();
- if (fixedTabHeight != SWT.DEFAULT) {
- //TODO use field variable instead of 1
- height = fixedTabHeight == 0 ? 0 : fixedTabHeight + 1; // +1 for line drawn across top of tab
- } else {
- CTabItem[] items = parent.getItems();
- if (items.length == 0) {
- height = gc.textExtent("Default", FLAGS).y + ITEM_TOP_MARGIN //$NON-NLS-1$
- + ITEM_BOTTOM_MARGIN;
- } else {
- for (int i = 0; i < items.length; i++) {
- height = Math.max(height,
- computeSize(i, SWT.NONE, gc, wHint, hHint).y);
- }
- }
- height = Math.max(height, parent.getTabHeight() + 1);
-// gc.dispose();
- }
- break;
- case PART_MAX_BUTTON:
- case PART_MIN_BUTTON:
- case PART_CLOSE_BUTTON:
- width = height = BUTTON_SIZE;
- break;
- case PART_CHEVRON_BUTTON:
- width = 3 * BUTTON_SIZE / 2;
- height = BUTTON_SIZE;
- break;
- default:
- if (0 <= part && part < parent.getItemCount()) {
- gc.setAdvanced(true);
-
- CTabItem item = parent.getItem(part);
- if (item.isDisposed())
- return new Point(0, 0);
-
- if (imageVisible || shouldDrawImage(item)) {
- Image image = item.getImage();
- if (image != null && !image.isDisposed()) {
- Rectangle bounds = image.getBounds();
- if ((state & SWT.SELECTED) != 0
- || parent.getUnselectedImageVisible()) {
- width += bounds.width;
- }
- height = bounds.height;
- }
- }
-
- if (textVisible) {
- String text = null;
- if ((state & MINIMUM_SIZE) != 0) {
- int minChars = parent.getMinimumCharacters();
- text = minChars == 0 ? null : item.getText();
- if (text != null && text.length() > minChars) {
- if (useEllipse()) {
- int end = minChars < ELLIPSIS.length() + 1
- ? minChars
- : minChars - ELLIPSIS.length();
- text = text.substring(0, end);
- if (minChars > ELLIPSIS.length() + 1)
- text += ELLIPSIS;
- } else {
- int end = minChars;
- text = text.substring(0, end);
- }
- }
- } else {
- text = item.getText();
- }
- if (text != null) {
- if (width > 0)
- width += INTERNAL_SPACING;
- if (item.getFont() == null) {
- Point size = gc.textExtent(text, FLAGS);
- width += size.x;
- height = Math.max(height, size.y);
- } else {
- Font gcFont = gc.getFont();
- gc.setFont(item.getFont());
- Point size = gc.textExtent(text, FLAGS);
- width += size.x;
- height = Math.max(height, size.y);
- gc.setFont(gcFont);
- }
- }
- }
-
- if (parentWrapper.isShowClose() || item.getShowClose()) {
- if ((state & SWT.SELECTED) != 0
- || parent.getUnselectedCloseVisible()) {
- if (width > 0)
- width += INTERNAL_SPACING;
- width += computeSize(PART_CLOSE_BUTTON, SWT.NONE, gc,
- SWT.DEFAULT, SWT.DEFAULT).x;
- }
- }
- }
- break;
- }
- Rectangle trim = computeTrim(part, state, 0, 0, width, height);
- width = trim.width;
- height = trim.height;
- return new Point(width, height);
- }
-
- private boolean useEllipse() {
- return parent.getSimple();
- }
-
- private Color getCloseFillColor() {
- if (closeFillColor == null) {
- closeFillColor = new Color(parent.getDisplay(), CLOSE_FILL);
- }
- return closeFillColor;
- }
-
- @Override
- protected void dispose() {
- if (shadowImage != null && !shadowImage.isDisposed()) {
- shadowImage.dispose();
- shadowImage = null;
- }
- if (closeFillColor != null) {
- closeFillColor.dispose();
- closeFillColor = null;
- }
- super.dispose();
- }
-
- @Override
- protected void draw(int part, int state, Rectangle bounds, GC gc) {
- if (nothingToRender) {
- return;
- }
-
- switch (part) {
- case PART_BACKGROUND:
- this.drawCustomBackground(gc, bounds, state);
- return;
- case PART_BODY:
- this.drawTabBody(gc, bounds, state);
- return;
- case PART_HEADER:
- this.drawTabHeader(gc, bounds, state);
- return;
- case PART_MAX_BUTTON:
- if (maxImage != null) {
- this.drawMaximizeButton(gc, bounds, state);
- return;
- }
- break;
- case PART_MIN_BUTTON:
- if (minImage != null) {
- this.drawMinimizeButton(gc, bounds, state);
- return;
- }
- break;
- case PART_CLOSE_BUTTON:
- if (closeImage != null) {
- this.drawCloseButton(gc, bounds, state);
- return;
- }
- break;
- default:
- if (0 <= part && part < parent.getItemCount()) {
- gc.setAdvanced(true);
- if (bounds.width == 0 || bounds.height == 0)
- return;
- if ((state & SWT.SELECTED) != 0) {
- drawSelectedTab(part, gc, bounds, state);
- state &= ~SWT.BACKGROUND;
- if ((state & SWT.SELECTED) != 0)
- toDrawTab(true, part, gc, bounds, state);
- } else {
- drawUnselectedTab(part, gc, bounds, state);
- if ((state & SWT.HOT) == 0 && !active) {
- gc.setAlpha(0x7f);
- state &= ~SWT.BACKGROUND;
- toDrawTab(false, part, gc, bounds, state);
- gc.setAlpha(0xff);
- } else {
- state &= ~SWT.BACKGROUND;
- toDrawTab(false, part, gc, bounds, state);
- }
- }
- return;
- }
- }
- super.draw(part, state, bounds, gc);
- }
-
- private void drawCloseButton(GC gc, Rectangle bounds, int state) {
- Image hoverImage = closeHoverImage == null ? closeImage
- : closeHoverImage;
- switch (state & (SWT.HOT | SWT.SELECTED | SWT.BACKGROUND)) {
- case SWT.NONE:
- gc.drawImage(closeImage, bounds.x, bounds.y);
- break;
- case SWT.HOT:
- gc.drawImage(hoverImage, bounds.x, bounds.y);
- break;
- case SWT.SELECTED:
- gc.drawImage(hoverImage, bounds.x + 1, bounds.y + 1);
- break;
- case SWT.BACKGROUND:
- break;
- }
- }
-
- private void drawMinimizeButton(GC gc, Rectangle bounds, int state) {
- gc.drawImage(minImage, bounds.x, bounds.y);
- }
-
- private void drawMaximizeButton(GC gc, Rectangle bounds, int state) {
- gc.drawImage(maxImage, bounds.x, bounds.y);
- }
-
- void drawTabHeader(GC gc, Rectangle bounds, int state) {
- boolean onBottom = parent.getTabPosition() == SWT.BOTTOM;
-
- // Fill in background
- Region clipping = new Region();
- gc.getClipping(clipping);
- Region region = new Region();
- region.add(shape);
- region.intersect(clipping);
- gc.setClipping(region);
-
- int header = shadowEnabled ? onBottom ? 6 : 3 : 1;
- Rectangle trim = computeTrim(PART_HEADER, state, 0, 0, 0, 0);
- trim.width = bounds.width - trim.width;
- trim.height = computeSize(PART_HEADER, state, gc, 0, 0).y;
- trim.x = -trim.x;
- trim.y = onBottom ? bounds.height - parent.getTabHeight() - 1 - header
- : -trim.y;
- draw(PART_BACKGROUND, SWT.NONE, trim, gc);
-
- gc.setClipping(clipping);
- clipping.dispose();
- region.dispose();
-
- if (outerKeyline == null)
- outerKeyline = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(outerKeyline);
- if (outerBorderVisible) {
- gc.drawPolyline(tabArea);
- gc.drawLine(trim.x, trim.y + trim.height, trim.x + trim.width,
- trim.y + trim.height);
- }
- }
-
- void generateTabArea(Rectangle bounds) {
- int[] points = new int[1024];
- int index = 0;
- int radius = cornerSize / 2;
- int marginWidth = parent.marginWidth;
- int marginHeight = parent.marginHeight;
- int delta = (INNER_KEYLINE + OUTER_KEYLINE) * 2 + marginWidth * 2;
- int width = bounds.width - delta;
- int height = Math.max(
- parent.getTabHeight() + INNER_KEYLINE + OUTER_KEYLINE,
- bounds.height
- - (INNER_KEYLINE + OUTER_KEYLINE + marginHeight * 2));
-
- int circX = bounds.x + radius + delta / 2;
- int circY = bounds.y + radius;
-
- // Body
- index = 0;
- int[] ltt = { bounds.x + delta / 2,
- bounds.y + parent.getTabHeight() + delta };
- System.arraycopy(ltt, 0, points, index, ltt.length);
- index += ltt.length;
-
- int[] lbb = drawCircle(circX, circY + height - (radius * 2), radius,
- LEFT_BOTTOM);
- System.arraycopy(lbb, 0, points, index, lbb.length);
- index += lbb.length;
-
- int[] rb = drawCircle(circX + width - (radius * 2),
- circY + height - (radius * 2), radius, RIGHT_BOTTOM);
- System.arraycopy(rb, 0, points, index, rb.length);
- index += rb.length;
-
- int[] rt = { bounds.x + delta / 2 + width,
- bounds.y + parent.getTabHeight() + delta };
- System.arraycopy(rt, 0, points, index, rt.length);
- index += rt.length;
-
-// points[index++] = bounds.x + delta / 2;
-// points[index++] = bounds.y + parent.getTabHeight() + 1;
-
- int[] tempPoints = new int[index];
- System.arraycopy(points, 0, tempPoints, 0, index);
-
- tabArea = tempPoints;
-
- }
-
- void drawTabBody(GC gc, Rectangle bounds, int state) {
- generateTabArea(bounds);
-
- int[] points = new int[1024];
- int index = 0;
- int radius = cornerSize / 2;
- int marginWidth = parent.marginWidth;
- int marginHeight = parent.marginHeight;
- int delta = (INNER_KEYLINE + OUTER_KEYLINE) * 2 + marginWidth * 2;
- int width = bounds.width - delta;
- int height = Math.max(
- parent.getTabHeight() + INNER_KEYLINE + OUTER_KEYLINE,
- bounds.height
- - (INNER_KEYLINE + OUTER_KEYLINE + marginHeight * 2));
-
- int circX = bounds.x + radius + delta / 2;
- int circY = bounds.y + radius;
-
- // Body
- index = 0;
- int[] ltt = drawCircle(circX, circY, radius, LEFT_TOP);
- System.arraycopy(ltt, 0, points, index, ltt.length);
- index += ltt.length;
-
- int[] lbb = drawCircle(circX, circY + height - (radius * 2), radius,
- LEFT_BOTTOM);
- System.arraycopy(lbb, 0, points, index, lbb.length);
- index += lbb.length;
-
- int[] rb = drawCircle(circX + width - (radius * 2),
- circY + height - (radius * 2), radius, RIGHT_BOTTOM);
- System.arraycopy(rb, 0, points, index, rb.length);
- index += rb.length;
-
- int[] rt = drawCircle(circX + width - (radius * 2), circY, radius,
- RIGHT_TOP);
- System.arraycopy(rt, 0, points, index, rt.length);
- index += rt.length;
- points[index++] = circX;
- points[index++] = circY - radius;
-
- int[] tempPoints = new int[index];
- System.arraycopy(points, 0, tempPoints, 0, index);
-
- // Fill in parent background for non-rectangular shape
- Region r = new Region();
- r.add(bounds);
- r.subtract(tempPoints);
- gc.setBackground(parent.getParent().getBackground());
- Display display = parent.getDisplay();
- Region clipping = new Region();
- gc.getClipping(clipping);
- r.intersect(clipping);
- gc.setClipping(r);
- Rectangle mappedBounds = display.map(parent, parent.getParent(),
- bounds);
- parent.getParent().drawBackground(gc, bounds.x, bounds.y, bounds.width,
- bounds.height, mappedBounds.x, mappedBounds.y);
-
- // Shadow
- if (shadowEnabled)
- drawShadow(display, bounds, gc);
-
- gc.setClipping(clipping);
- clipping.dispose();
- r.dispose();
-
- // Remember for use in header drawing
- shape = tempPoints;
- }
-
- /*
- * Draw active and unactive selected tab item
- */
- void drawSelectedTab(int itemIndex, GC gc, Rectangle bounds, int state) {
- if (parent.getSingle() && parent.getItem(itemIndex).isShowing())
- return;
-
- boolean onBottom = parent.getTabPosition() == SWT.BOTTOM;
- int header = shadowEnabled ? 2 : 0;
- int width = bounds.width;
- int[] points = new int[1024];
- int index = 0;
- int radius = cornerSize / 2;
- int circX = bounds.x + radius;
- int circY = onBottom ? bounds.y + bounds.height - header - radius
- : bounds.y + radius;
- int selectionX1, selectionY1, selectionX2, selectionY2;
- int bottomY = onBottom ? bounds.y - header : bounds.y + bounds.height;
- if (itemIndex == 0
- && bounds.x == -computeTrim(CTabFolderRenderer.PART_HEADER,
- SWT.NONE, 0, 0, 0, 0).x) {
-// circX -= 1;
-// points[index++] = circX - radius;
-// points[index++] = bottomY;
-
- points[index++] = selectionX1 = circX - radius;
- points[index++] = selectionY1 = bottomY;
- } else {
- if (active) {
- points[index++] = shadowEnabled ? SIDE_DROP_WIDTH
- : 0 + INNER_KEYLINE + OUTER_KEYLINE;
- points[index++] = bottomY;
- }
- points[index++] = selectionX1 = bounds.x;
- points[index++] = selectionY1 = bottomY;
- }
-
- int startX = -1, endX = -1;
- if (!onBottom) {
- int[] ltt = drawCircle(circX, circY, radius, LEFT_TOP);
- startX = ltt[6];
- for (int i = 0; i < ltt.length / 2; i += 2) {
- int tmp = ltt[i];
- ltt[i] = ltt[ltt.length - i - 2];
- ltt[ltt.length - i - 2] = tmp;
- tmp = ltt[i + 1];
- ltt[i + 1] = ltt[ltt.length - i - 1];
- ltt[ltt.length - i - 1] = tmp;
- }
- System.arraycopy(ltt, 0, points, index, ltt.length);
- index += ltt.length;
-
- int[] rt = drawCircle(circX + width - (radius * 2), circY, radius,
- RIGHT_TOP);
- endX = rt[rt.length - 4];
- for (int i = 0; i < rt.length / 2; i += 2) {
- int tmp = rt[i];
- rt[i] = rt[rt.length - i - 2];
- rt[rt.length - i - 2] = tmp;
- tmp = rt[i + 1];
- rt[i + 1] = rt[rt.length - i - 1];
- rt[rt.length - i - 1] = tmp;
- }
- System.arraycopy(rt, 0, points, index, rt.length);
- index += rt.length;
-
- points[index++] = selectionX2 = bounds.width + circX - radius;
- points[index++] = selectionY2 = bottomY;
- } else {
- int[] ltt = drawCircle(circX, circY, radius, LEFT_BOTTOM);
- startX = ltt[6];
- System.arraycopy(ltt, 0, points, index, ltt.length);
- index += ltt.length;
-
- int[] rt = drawCircle(circX + width - (radius * 2), circY, radius,
- RIGHT_BOTTOM);
- endX = rt[rt.length - 4];
- System.arraycopy(rt, 0, points, index, rt.length);
- index += rt.length;
-
- points[index++] = selectionX2 = bounds.width + circX - radius;
- points[index++] = selectionY2 = bottomY;
- }
-
- if (active) {
- points[index++] = parent.getSize().x - (shadowEnabled
- ? SIDE_DROP_WIDTH : 0 + INNER_KEYLINE + OUTER_KEYLINE);
- points[index++] = bottomY;
- }
- gc.setClipping(bounds.x, onBottom ? bounds.y - header : bounds.y,
- parent.getSize().x - (shadowEnabled ? SIDE_DROP_WIDTH
- : 0 + INNER_KEYLINE + OUTER_KEYLINE),
- bounds.y + bounds.height);
-
- Pattern backgroundPattern = null;
- if (selectedTabFillColors == null) {
- setSelectedTabFill(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
- }
- if (selectedTabFillColors.length == 1) {
- gc.setBackground(selectedTabFillColors[0]);
- gc.setForeground(selectedTabFillColors[0]);
- } else if (!onBottom && selectedTabFillColors.length == 2) {
- // for now we support the 2-colors gradient for selected tab
- backgroundPattern = new Pattern(gc.getDevice(), 0, 0, 0,
- bounds.height + 1, selectedTabFillColors[0],
- selectedTabFillColors[1]);
- gc.setBackgroundPattern(backgroundPattern);
- gc.setForeground(selectedTabFillColors[1]);
- }
-
- int[] tmpPoints = new int[index];
- System.arraycopy(points, 0, tmpPoints, 0, index);
- gc.fillPolygon(tmpPoints);
-
- //cover item bottom border using background color
- gc.drawLine(selectionX1, selectionY1, selectionX2, selectionY2);
-
- gc.setClipping(bounds.x - 1,
- onBottom ? bounds.y - header : bounds.y - 1,
- parent.getSize().x - (shadowEnabled ? SIDE_DROP_WIDTH
- : 0 + INNER_KEYLINE + OUTER_KEYLINE),
- bounds.y + bounds.height);
- if (innerBorderVisible) {
- if (innerKeyline == null)
- innerKeyline = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(innerKeyline);
- gc.drawPolyline(tmpPoints);
- }
- Rectangle rect = null;
- gc.setClipping(rect);
-
- if (outerBorderVisible) {
- if (!onBottom) {
- if (outerKeyline == null)
- outerKeyline = gc.getDevice()
- .getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(outerKeyline);
- gc.drawLine(startX + 2, 1, endX - 1, 1);
- }
- }
-
- if (backgroundPattern != null) {
- backgroundPattern.dispose();
- }
- }
-
- private boolean isTabOnBottom() {
- return parent.getTabPosition() == SWT.BOTTOM;
- }
-
- private String getShortenedText(GC gc, String text, int width) {
- return useEllipse() ? getShortenedText(gc, text, width, ELLIPSIS)
- : getShortenedText(gc, text, width, ""); //$NON-NLS-1$
- }
-
- private String getShortenedText(GC gc, String text, int width,
- String ellipses) {
- if (gc.textExtent(text, FLAGS).x <= width)
- return text;
- int ellipseWidth = gc.textExtent(ellipses, FLAGS).x;
- int length = text.length();
- TextLayout layout = new TextLayout(parent.getDisplay());
- layout.setText(text);
- int end = layout.getPreviousOffset(length, SWT.MOVEMENT_CLUSTER);
- while (end > 0) {
- text = text.substring(0, end);
- int l = gc.textExtent(text, FLAGS).x;
- if (l + ellipseWidth <= width) {
- break;
- }
- end = layout.getPreviousOffset(end, SWT.MOVEMENT_CLUSTER);
- }
- layout.dispose();
- return end == 0 ? text.substring(0, 1) : text + ellipses;
- }
-
- private void toDrawTab(boolean selected, int itemIndex, GC gc,
- Rectangle bounds, int state) {
- CTabItem item = parent.getItem(itemIndex);
- int x = bounds.x;
- int y = bounds.y;
- int height = bounds.height;
- int width = bounds.width;
-
- int rightEdge = Math.min(x + width, parentWrapper.getRightItemEdge(gc));
-
- if ((state & SWT.FOREGROUND) != 0) {
- CTabItemWrapper itemWrapper = new CTabItemWrapper(item);
- Rectangle itemCloseRect = itemWrapper.getCloseRect();
- itemCloseRect = new Rectangle(itemCloseRect.x, itemCloseRect.y,
- itemCloseRect.width, itemCloseRect.height);
-
- // draw Image
- Rectangle trim = computeTrim(itemIndex, SWT.NONE, 0, 0, 0, 0);
- int xDraw = x - trim.x;
- if (parent.getSingle()
- && (parentWrapper.isShowClose() || item.getShowClose()))
- xDraw += itemWrapper.getCloseRect().width;
- if (imageVisible || shouldDrawImage(item)) {
- Image image = item.getImage();
- if (image != null && !image.isDisposed()) {
- Rectangle imageBounds = image.getBounds();
- // only draw image if it won't overlap with close button
- int maxImageWidth = rightEdge - xDraw
- - (trim.width + trim.x);
- if (!parent.getSingle() && itemCloseRect.width > 0)
- maxImageWidth -= itemCloseRect.width + INTERNAL_SPACING;
- if (imageBounds.width < maxImageWidth) {
- int imageX = xDraw;
- int imageY = y + (height - imageBounds.height) / 2;
- imageY += isTabOnBottom() ? -1 : 1;
- gc.drawImage(image, imageX, imageY);
- xDraw += imageBounds.width + INTERNAL_SPACING;
- }
- }
- }
-
- if (textVisible) {
- // draw Text
- int textWidth = rightEdge - xDraw - (trim.width + trim.x);
- if (!parent.getSingle() && itemCloseRect.width > 0)
- textWidth -= itemCloseRect.width + INTERNAL_SPACING;
- if (textWidth > 0) {
- Font gcFont = gc.getFont();
- gc.setFont(item.getFont() == null ? parent.getFont()
- : item.getFont());
-
- if (itemWrapper.getShortenedText() == null || itemWrapper
- .getShortenedTextWidth() != textWidth) {
- itemWrapper.setShortenedText(getShortenedText(gc,
- item.getText(), textWidth));
- itemWrapper.setShortenedTextWidth(textWidth);
- }
- Point extent = gc.textExtent(itemWrapper.getShortenedText(),
- FLAGS);
- int textY = y + (height - extent.y) / 2;
- textY += isTabOnBottom() ? -1 : 1;
-
- gc.setForeground(selected ? parent.getSelectionForeground()
- : parent.getForeground());
- gc.drawText(itemWrapper.getShortenedText(), xDraw, textY,
- FLAGS);
- gc.setFont(gcFont);
-
- if (selected) {
- // draw a Focus rectangle
- if (parent.isFocusControl()) {
- Display display = parent.getDisplay();
- if (parent.getSimple() || parent.getSingle()) {
- gc.setBackground(display
- .getSystemColor(SWT.COLOR_BLACK));
- gc.setForeground(display
- .getSystemColor(SWT.COLOR_WHITE));
- gc.drawFocus(xDraw - 1, textY - 1, extent.x + 2,
- extent.y + 2);
- } else {
- gc.setForeground(
- display.getSystemColor(BUTTON_BORDER));
- gc.drawLine(xDraw, textY + extent.y + 1,
- xDraw + extent.x + 1,
- textY + extent.y + 1);
- }
- }
- }
-
- }
- }
-
- if (parentWrapper.isShowClose() || item.getShowClose()) {
- if (closeImage != null) {
- drawCloseButton(gc, itemCloseRect,
- itemWrapper.getCloseImageState());
- } else {
- drawClose2(gc, itemCloseRect,
- itemWrapper.getCloseImageState());
- }
- }
- }
- }
-
- void drawClose2(GC gc, Rectangle closeRect, int closeImageState) {
- if (closeRect.width == 0 || closeRect.height == 0)
- return;
- Display display = parent.getDisplay();
-
- // draw X 9x9
- int x = closeRect.x + Math.max(1, (closeRect.width - 9) / 2);
- int y = closeRect.y + Math.max(1, (closeRect.height - 9) / 2);
-
- Color closeBorder = display.getSystemColor(BUTTON_BORDER);
- int[] fillShape = new int[] { x + 1, y + 1, x + 3, y + 1, x + 5, y + 3,
- x + 6, y + 3, x + 8, y + 1, x + 10, y + 1, x + 10, y + 3, x + 8,
- y + 5, x + 8, y + 6, x + 10, y + 8, x + 10, y + 10, x + 8,
- y + 10, x + 6, y + 8, x + 5, y + 8, x + 3, y + 10, x + 1,
- y + 10, x + 1, y + 8, x + 3, y + 6, x + 3, y + 5, x + 1,
- y + 3 };
- int[] drawShape = new int[] { x, y, x + 2, y, x + 4, y + 2, x + 5,
- y + 2, x + 7, y, x + 9, y, x + 9, y + 2, x + 7, y + 4, x + 7,
- y + 5, x + 9, y + 7, x + 9, y + 9, x + 7, y + 9, x + 5, y + 7,
- x + 4, y + 7, x + 2, y + 9, x, y + 9, x, y + 7, x + 2, y + 5,
- x + 2, y + 4, x, y + 2 };
- switch (closeImageState & (SWT.HOT | SWT.SELECTED | SWT.BACKGROUND)) {
- case SWT.NONE: {
- gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
- gc.fillPolygon(fillShape);
- gc.setForeground(closeBorder);
- gc.drawPolygon(drawShape);
- break;
- }
- case SWT.HOT: {
- gc.setBackground(getCloseFillColor());
- gc.fillPolygon(fillShape);
- gc.setForeground(closeBorder);
- gc.drawPolygon(drawShape);
- break;
- }
- case SWT.SELECTED: {
- gc.setBackground(getCloseFillColor());
- gc.fillPolygon(fillShape);
- gc.setForeground(closeBorder);
- gc.drawPolygon(drawShape);
- break;
- }
- case SWT.BACKGROUND: {
- rendererWrapper.drawClose(gc, closeRect, closeImageState);
- break;
- }
- }
- }
-
- private boolean shouldDrawImage(CTabItem item) {
- Object model = item.getData(AbstractPartRenderer.OWNING_ME);
- if (model != null && model instanceof MUIElement) {
- MUIElement element = (MUIElement) model;
- if (element.getTags().contains(ICathyConstants.TAG_SHOW_IMAGE)) {
- return true;
- }
- }
- return false;
- }
-
- void drawUnselectedTab(int itemIndex, GC gc, Rectangle bounds, int state) {
- if ((state & SWT.HOT) != 0) {
- int header = shadowEnabled ? 2 : 0;
- int width = bounds.width;
- boolean onBottom = parent.getTabPosition() == SWT.BOTTOM;
- int[] points = new int[1024];
- int[] inactive = new int[8];
- int index = 0, inactive_index = 0;
- int radius = cornerSize / 2;
- int circX = bounds.x + radius;
- int circY = onBottom
- ? bounds.y + bounds.height + 1 - header - radius
- : bounds.y - 1 + radius;
- int bottomY = onBottom ? bounds.y - header
- : bounds.y + bounds.height;
-
- int leftIndex = circX;
- if (itemIndex == 0) {
-// if (parent.getSelectionIndex() != 0)
-// leftIndex -= 1;
- points[index++] = leftIndex - radius;
- points[index++] = bottomY;
-
- } else {
- points[index++] = bounds.x;
- points[index++] = bottomY;
- }
-
- if (!active) {
- System.arraycopy(points, 0, inactive, 0, index);
- inactive_index += 2;
- }
-
- int rightIndex = circX - 1;
- int startX = -1, endX = -1;
- if (!onBottom) {
- int[] ltt = drawCircle(leftIndex, circY, radius, LEFT_TOP);
- startX = ltt[6];
- for (int i = 0; i < ltt.length / 2; i += 2) {
- int tmp = ltt[i];
- ltt[i] = ltt[ltt.length - i - 2];
- ltt[ltt.length - i - 2] = tmp;
- tmp = ltt[i + 1];
- ltt[i + 1] = ltt[ltt.length - i - 1];
- ltt[ltt.length - i - 1] = tmp;
- }
- System.arraycopy(ltt, 0, points, index, ltt.length);
- index += ltt.length;
-
- if (!active) {
- System.arraycopy(ltt, 0, inactive, inactive_index, 2);
- inactive_index += 2;
- }
-
- int[] rt = drawCircle(rightIndex + width - (radius * 2), circY,
- radius, RIGHT_TOP);
- endX = rt[rt.length - 4];
- for (int i = 0; i < rt.length / 2; i += 2) {
- int tmp = rt[i];
- rt[i] = rt[rt.length - i - 2];
- rt[rt.length - i - 2] = tmp;
- tmp = rt[i + 1];
- rt[i + 1] = rt[rt.length - i - 1];
- rt[rt.length - i - 1] = tmp;
- }
- System.arraycopy(rt, 0, points, index, rt.length);
- index += rt.length;
- if (!active) {
- System.arraycopy(rt, rt.length - 4, inactive,
- inactive_index, 2);
- inactive[inactive_index] -= 1;
- inactive_index += 2;
- }
- } else {
- int[] ltt = drawCircle(leftIndex, circY, radius, LEFT_BOTTOM);
- startX = ltt[6];
- System.arraycopy(ltt, 0, points, index, ltt.length);
- index += ltt.length;
-
- if (!active) {
- System.arraycopy(ltt, 0, inactive, inactive_index, 2);
- inactive_index += 2;
- }
-
- int[] rt = drawCircle(rightIndex + width - (radius * 2), circY,
- radius, RIGHT_BOTTOM);
- endX = rt[rt.length - 4];
- System.arraycopy(rt, 0, points, index, rt.length);
- index += rt.length;
- if (!active) {
- System.arraycopy(rt, rt.length - 4, inactive,
- inactive_index, 2);
- inactive[inactive_index] -= 1;
- inactive_index += 2;
- }
-
- }
-
- points[index++] = bounds.width + rightIndex - radius;
- points[index++] = bottomY;
-
- if (!active) {
- System.arraycopy(points, index - 2, inactive, inactive_index,
- 2);
- inactive[inactive_index] -= 1;
- inactive_index += 2;
- }
-
- gc.setClipping(points[0],
- onBottom ? bounds.y - header : bounds.y - 1,
- parent.getSize().x - (shadowEnabled ? SIDE_DROP_WIDTH
- : 0 + INNER_KEYLINE + OUTER_KEYLINE),
- bounds.y + bounds.height);
-
- if (hoverTabColors == null) {
- hoverTabColors = new Color[] {
- gc.getDevice().getSystemColor(SWT.COLOR_WHITE) };
- hoverTabPercents = new int[] { 100 };
- }
-
- gc.setBackground(hoverTabColors[0]);
- int[] tmpPoints = new int[index];
- System.arraycopy(points, 0, tmpPoints, 0, index);
- gc.fillPolygon(tmpPoints);
- Color tempBorder = new Color(gc.getDevice(), 182, 188, 204);
- gc.setForeground(tempBorder);
- tempBorder.dispose();
-
- if (hoverBorderVisible) {
- if (outerBorderVisible) {
- if (outerKeyline == null)
- outerKeyline = gc.getDevice()
- .getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(outerKeyline);
- if (active) {
- gc.drawLine(startX, 1, endX, 1);
- } else {
- gc.drawLine(inactive[0], inactive[1], inactive[2],
- inactive[3]);
- gc.drawLine(inactive[4], inactive[5], inactive[6],
- inactive[7]);
- }
- }
-
- if (innerBorderVisible) {
- if (innerKeyline == null)
- innerKeyline = gc.getDevice()
- .getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(innerKeyline);
- gc.drawPolyline(tmpPoints);
- }
- }
-
- Rectangle rect = null;
- gc.setClipping(rect);
-
- // gc.setForeground(outerKeyline);
- // gc.drawPolyline(shape);
- }
- }
-
- static int[] drawCircle(int xC, int yC, int r, int circlePart) {
- int x = 0, y = r, u = 1, v = 2 * r - 1, e = 0;
- int[] points = new int[1024];
- int[] pointsMirror = new int[1024];
- int loop = 0;
- int loopMirror = 0;
- if (r == 0) {
- for (int i = 0; i < 4; i++) {
- points[loop++] = xC;
- points[loop++] = yC;
- }
- }
- while (x < y) {
- if (circlePart == RIGHT_BOTTOM) {
- points[loop++] = xC + x;
- points[loop++] = yC + y;
- }
- if (circlePart == RIGHT_TOP) {
- points[loop++] = xC + y;
- points[loop++] = yC - x;
- }
- if (circlePart == LEFT_TOP) {
- points[loop++] = xC - x;
- points[loop++] = yC - y;
- }
- if (circlePart == LEFT_BOTTOM) {
- points[loop++] = xC - y;
- points[loop++] = yC + x;
- }
- x++;
- e += u;
- u += 2;
- if (v < 2 * e) {
- y--;
- e -= v;
- v -= 2;
- }
- if (x > y)
- break;
- if (circlePart == RIGHT_BOTTOM) {
- pointsMirror[loopMirror++] = xC + y;
- pointsMirror[loopMirror++] = yC + x;
- }
- if (circlePart == RIGHT_TOP) {
- pointsMirror[loopMirror++] = xC + x;
- pointsMirror[loopMirror++] = yC - y;
- }
- if (circlePart == LEFT_TOP) {
- pointsMirror[loopMirror++] = xC - y;
- pointsMirror[loopMirror++] = yC - x;
- }
- if (circlePart == LEFT_BOTTOM) {
- pointsMirror[loopMirror++] = xC - x;
- pointsMirror[loopMirror++] = yC + y;
- }
- // grow?
- if ((loop + 1) > points.length) {
- int length = points.length * 2;
- int[] newPointTable = new int[length];
- int[] newPointTableMirror = new int[length];
- System.arraycopy(points, 0, newPointTable, 0, points.length);
- points = newPointTable;
- System.arraycopy(pointsMirror, 0, newPointTableMirror, 0,
- pointsMirror.length);
- pointsMirror = newPointTableMirror;
- }
- }
- int[] finalArray = new int[loop + loopMirror];
- System.arraycopy(points, 0, finalArray, 0, loop);
- for (int i = loopMirror - 1, j = loop; i > 0; i = i - 2, j = j + 2) {
- int tempY = pointsMirror[i];
- int tempX = pointsMirror[i - 1];
- finalArray[j] = tempX;
- finalArray[j + 1] = tempY;
- }
- return finalArray;
- }
-
- static RGB blend(RGB c1, RGB c2, int ratio) {
- int r = blend(c1.red, c2.red, ratio);
- int g = blend(c1.green, c2.green, ratio);
- int b = blend(c1.blue, c2.blue, ratio);
- return new RGB(r, g, b);
- }
-
- static int blend(int v1, int v2, int ratio) {
- int b = (ratio * v1 + (100 - ratio) * v2) / 100;
- return Math.min(255, b);
- }
-
- void drawShadow(final Display display, Rectangle bounds, GC gc) {
- if (shadowImage == null) {
- createShadow(display);
- }
- int x = bounds.x;
- int y = bounds.y;
- int SIZE = shadowImage.getBounds().width / 3;
-
- int height = Math.max(bounds.height, SIZE * 2);
- int width = Math.max(bounds.width, SIZE * 2);
- // top left
- gc.drawImage(shadowImage, 0, 0, SIZE, SIZE, 2, 10, SIZE, 20);
- int fillHeight = height - SIZE * 2;
- int fillWidth = width + 5 - SIZE * 2;
-
- int xFill = 0;
- for (int i = SIZE; i < fillHeight; i += SIZE) {
- xFill = i;
- gc.drawImage(shadowImage, 0, SIZE, SIZE, SIZE, 2, i, SIZE, SIZE);
- }
-
- // Pad the rest of the shadow
- gc.drawImage(shadowImage, 0, SIZE, SIZE, fillHeight - xFill, 2,
- xFill + SIZE, SIZE, fillHeight - xFill);
-
- // bl
- gc.drawImage(shadowImage, 0, 40, 20, 20, 2, y + height - SIZE, 20, 20);
-
- int yFill = 0;
- for (int i = SIZE; i <= fillWidth; i += SIZE) {
- yFill = i;
- gc.drawImage(shadowImage, SIZE, SIZE * 2, SIZE, SIZE, i,
- y + height - SIZE, SIZE, SIZE);
- }
- // Pad the rest of the shadow
- gc.drawImage(shadowImage, SIZE, SIZE * 2, fillWidth - yFill, SIZE,
- yFill + SIZE, y + height - SIZE, fillWidth - yFill, SIZE);
-
- // br
- gc.drawImage(shadowImage, SIZE * 2, SIZE * 2, SIZE, SIZE,
- x + width - SIZE - 1, y + height - SIZE, SIZE, SIZE);
-
- // tr
- gc.drawImage(shadowImage, (SIZE * 2), 0, SIZE, SIZE,
- x + width - SIZE - 1, 10, SIZE, SIZE);
-
- xFill = 0;
- for (int i = SIZE; i < fillHeight; i += SIZE) {
- xFill = i;
- gc.drawImage(shadowImage, SIZE * 2, SIZE, SIZE, SIZE,
- x + width - SIZE - 1, i, SIZE, SIZE);
- }
-
- // Pad the rest of the shadow
- gc.drawImage(shadowImage, SIZE * 2, SIZE, SIZE, fillHeight - xFill,
- x + width - SIZE - 1, xFill + SIZE, SIZE, fillHeight - xFill);
- }
-
- void createShadow(final Display display) {
- if (shadowImage != null) {
- shadowImage.dispose();
- shadowImage = null;
- }
- ImageData data = new ImageData(60, 60, 32,
- new PaletteData(0xFF0000, 0xFF00, 0xFF));
- Image tmpImage = shadowImage = new Image(display, data);
- GC gc = new GC(tmpImage);
- if (shadowColor == null)
- shadowColor = gc.getDevice().getSystemColor(SWT.COLOR_GRAY);
- gc.setBackground(shadowColor);
- drawTabBody(gc, new Rectangle(0, 0, 60, 60), SWT.None);
- ImageData blured = blur(tmpImage, 5, 25);
- shadowImage = new Image(display, blured);
- tmpImage.dispose();
- }
-
- public ImageData blur(Image src, int radius, int sigma) {
- float[] kernel = create1DKernel(radius, sigma);
-
- ImageData imgPixels = src.getImageData();
- int width = imgPixels.width;
- int height = imgPixels.height;
-
- int[] inPixels = new int[width * height];
- int[] outPixels = new int[width * height];
- int offset = 0;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- RGB rgb = imgPixels.palette.getRGB(imgPixels.getPixel(x, y));
- if (rgb.red == 255 && rgb.green == 255 && rgb.blue == 255) {
- inPixels[offset] = (rgb.red << 16) | (rgb.green << 8)
- | rgb.blue;
- } else {
- inPixels[offset] = (imgPixels.getAlpha(x, y) << 24)
- | (rgb.red << 16) | (rgb.green << 8) | rgb.blue;
- }
- offset++;
- }
- }
-
- convolve(kernel, inPixels, outPixels, width, height, true);
- convolve(kernel, outPixels, inPixels, height, width, true);
-
- ImageData dst = new ImageData(imgPixels.width, imgPixels.height, 24,
- new PaletteData(0xff0000, 0xff00, 0xff));
-
- dst.setPixels(0, 0, inPixels.length, inPixels, 0);
- offset = 0;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- if (inPixels[offset] == -1) {
- dst.setAlpha(x, y, 0);
- } else {
- int a = (inPixels[offset] >> 24) & 0xff;
- // if (a < 150) a = 0;
- dst.setAlpha(x, y, a);
- }
- offset++;
- }
- }
- return dst;
- }
-
- private void convolve(float[] kernel, int[] inPixels, int[] outPixels,
- int width, int height, boolean alpha) {
- int kernelWidth = kernel.length;
- int kernelMid = kernelWidth / 2;
- for (int y = 0; y < height; y++) {
- int index = y;
- int currentLine = y * width;
- for (int x = 0; x < width; x++) {
- // do point
- float a = 0, r = 0, g = 0, b = 0;
- for (int k = -kernelMid; k <= kernelMid; k++) {
- float val = kernel[k + kernelMid];
- int xcoord = x + k;
- if (xcoord < 0)
- xcoord = 0;
- if (xcoord >= width)
- xcoord = width - 1;
- int pixel = inPixels[currentLine + xcoord];
- // float alp = ((pixel >> 24) & 0xff);
- a += val * ((pixel >> 24) & 0xff);
- r += val * (((pixel >> 16) & 0xff));
- g += val * (((pixel >> 8) & 0xff));
- b += val * (((pixel) & 0xff));
- }
- int ia = alpha ? clamp((int) (a + 0.5)) : 0xff;
- int ir = clamp((int) (r + 0.5));
- int ig = clamp((int) (g + 0.5));
- int ib = clamp((int) (b + 0.5));
- outPixels[index] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
- index += height;
- }
- }
-
- }
-
- private int clamp(int value) {
- if (value > 255)
- return 255;
- if (value < 0)
- return 0;
- return value;
- }
-
- private float[] create1DKernel(int radius, int sigma) {
- // guideline: 3*sigma should be the radius
- int size = radius * 2 + 1;
- float[] kernel = new float[size];
- int radiusSquare = radius * radius;
- float sigmaSquare = 2 * sigma * sigma;
- float piSigma = 2 * (float) Math.PI * sigma;
- float sqrtSigmaPi2 = (float) Math.sqrt(piSigma);
- int start = size / 2;
- int index = 0;
- float total = 0;
- for (int i = -start; i <= start; i++) {
- float d = i * i;
- if (d > radiusSquare) {
- kernel[index] = 0;
- } else {
- kernel[index] = (float) Math.exp(-(d) / sigmaSquare)
- / sqrtSigmaPi2;
- }
- total += kernel[index];
- index++;
- }
- for (int i = 0; i < size; i++) {
- kernel[i] /= total;
- }
- return kernel;
- }
-
- public Rectangle getPadding() {
- return new Rectangle(paddingTop, paddingRight, paddingBottom,
- paddingLeft);
- }
-
- public void setPadding(int paddingLeft, int paddingRight, int paddingTop,
- int paddingBottom) {
- this.paddingLeft = paddingLeft;
- this.paddingRight = paddingRight;
- this.paddingTop = paddingTop;
- this.paddingBottom = paddingBottom;
- parent.redraw();
- }
-
- public void setCornerRadius(int radius) {
- cornerSize = radius;
- parent.redraw();
- }
-
- public void setShadowVisible(boolean visible) {
- this.shadowEnabled = visible;
- parent.redraw();
- }
-
- public void setShadowColor(Color color) {
- this.shadowColor = color;
- createShadow(parent.getDisplay());
- parent.redraw();
- }
-
- public void setOuterKeyline(Color color) {
- this.outerKeyline = color;
- // TODO: HACK! Should be set based on pseudo-state.
- if (color != null) {
- setActive(!(color.getRed() == 255 && color.getGreen() == 255
- && color.getBlue() == 255));
- }
- parent.redraw();
- }
-
- public void setSelectedTabFill(Color color) {
- setSelectedTabFill(new Color[] { color }, new int[] { 100 });
- }
-
- public void setSelectedTabFill(Color[] colors, int[] percents) {
- selectedTabFillColors = colors;
- selectedTabFillPercents = percents;
- parent.redraw();
- }
-
- public void setSelectedTabAreaColor(Color color) {
- setSelectedTabAreaColor(new Color[] { color }, new int[] { 100 });
- }
-
- public void setSelectedTabAreaColor(Color[] colors, int[] percents) {
- selectedTabAreaColors = colors;
- selectedTabAreaPercents = percents;
- parent.redraw();
- }
-
- public void setUnselectedTabsColor(Color color) {
- setUnselectedTabsColor(new Color[] { color }, new int[] { 100 });
- }
-
- public void setUnselectedTabsColor(Color[] colors, int[] percents) {
- unselectedTabsColors = colors;
- unselectedTabsPercents = percents;
-
- parent.redraw();
- }
-
- public void setUnselectedTabsBackgroundVisible(boolean visible) {
- unselectedTabsBackgroundVisible = visible;
- parent.redraw();
- }
-
- public void setUnselectedHotTabsColorBackground(Color color) {
- setHoverTabColor(new Color[] { color }, new int[] { 100 });
- }
-
- public void setHoverTabColor(Color color) {
- setHoverTabColor(new Color[] { color }, new int[] { 100 });
-
- }
-
- public void setHoverTabColor(Color[] colors, int[] percents) {
- hoverTabColors = colors;
- hoverTabPercents = percents;
- parent.redraw();
- }
-
- public void setTabOutline(Color color) {
- this.tabOutlineColor = color;
- parent.redraw();
- }
-
- public void setInnerKeyline(Color color) {
- this.innerKeyline = color;
- parent.redraw();
- }
-
- public void setTextVisible(boolean visible) {
- this.textVisible = visible;
- parent.redraw();
- }
-
- public void setImageVisible(boolean visible) {
- this.imageVisible = visible;
- parent.redraw();
- }
-
- public void setOuterBorderVisible(boolean visible) {
- this.outerBorderVisible = visible;
- parent.redraw();
- }
-
- public void setInnerBorderVisible(boolean visible) {
- this.innerBorderVisible = visible;
- parent.redraw();
- }
-
- public void setActiveToolbarGradient(Color[] color, int[] percents) {
- activeToolbar = color;
- activePercents = percents;
- }
-
- public void setInactiveToolbarGradient(Color[] color, int[] percents) {
- inactiveToolbar = color;
- inactivePercents = percents;
- }
-
- public void setActive(boolean active) {
- this.active = active;
- }
-
- public void setMaximizeImage(Image maxImage) {
- this.maxImage = maxImage;
- }
-
- public void setMinimizeImage(Image minImage) {
- this.minImage = minImage;
- }
-
- public void setCloseImage(Image closeImage) {
- this.closeImage = closeImage;
- }
-
- public void setClsoeHoverImage(Image closeHoverImage) {
- this.closeHoverImage = closeHoverImage;
- }
-
- public void setNoneRender(boolean nothingToRender) {
- this.nothingToRender = nothingToRender;
- }
-
- private void drawCustomBackground(GC gc, Rectangle bounds, int state) {
- boolean selected = (state & SWT.SELECTED) != 0;
- Color defaultBackground = selected ? parent.getSelectionBackground()
- : parent.getBackground();
- boolean vertical = selected
- ? parentWrapper.isSelectionGradientVertical()
- : parentWrapper.isGradientVertical();
- Rectangle partHeaderBounds = bounds;
-
- if (unselectedTabsBackgroundVisible) {
- drawUnselectedTabBackground(gc, partHeaderBounds, state, vertical,
- defaultBackground);
- }
- drawTabAreaBackground(gc, partHeaderBounds, state, vertical,
- defaultBackground);
-
- int borderTop = isTabOnBottom() ? INNER_KEYLINE + OUTER_KEYLINE
- : TOP_KEYLINE + OUTER_KEYLINE;
- int borderBottom = isTabOnBottom() ? TOP_KEYLINE + OUTER_KEYLINE
- : INNER_KEYLINE + OUTER_KEYLINE;
- int bottomDropWidth = shadowEnabled ? BOTTOM_DROP_WIDTH : 0;
- int sideDropWidth = shadowEnabled ? SIDE_DROP_WIDTH : 0;
- int headerBorderBottom = outerBorderVisible ? OUTER_KEYLINE : 0;
- Rectangle underTabAreaBounds = new Rectangle(
- partHeaderBounds.x + paddingLeft + sideDropWidth,
- partHeaderBounds.y + partHeaderBounds.height + bottomDropWidth
- + paddingTop + headerBorderBottom,
- bounds.width - paddingLeft - paddingRight - 2 * sideDropWidth,
- parent.getBounds().height - partHeaderBounds.height - paddingTop
- - paddingBottom - headerBorderBottom
- - ((cornerSize / 4) + borderBottom + borderTop)
- - bottomDropWidth * 2);
- drawUnderTabAreaBackground(gc, underTabAreaBounds, state, vertical,
- defaultBackground);
- drawChildrenBackground(partHeaderBounds);
- }
-
- private void drawUnderTabAreaBackground(GC gc, Rectangle tabAreaBounds,
- int state, boolean vertical, Color defaultBackground) {
- Color[] underTabAreaColors = new Color[] {
- gc.getDevice().getSystemColor(SWT.COLOR_WHITE) };
- int[] underTabAreaPercents = new int[] { 100 };
- rendererWrapper.drawBackground(gc, tabAreaBounds.x, tabAreaBounds.y,
- tabAreaBounds.width, tabAreaBounds.height, defaultBackground,
- underTabAreaColors, underTabAreaPercents, vertical);
- }
-
- private void drawUnselectedTabBackground(GC gc, Rectangle partHeaderBounds,
- int state, boolean vertical, Color defaultBackground) {
- if (unselectedTabsColors == null) {
- boolean selected = (state & SWT.SELECTED) != 0;
- unselectedTabsColors = selected
- ? parentWrapper.getSelectionGradientColors()
- : parentWrapper.getGradientColors();
- unselectedTabsPercents = selected
- ? parentWrapper.getSelectionGradientPercents()
- : parentWrapper.getGradientPercents();
- }
- if (unselectedTabsColors == null) {
- unselectedTabsColors = new Color[] {
- gc.getDevice().getSystemColor(SWT.COLOR_WHITE) };
- unselectedTabsPercents = new int[] { 100 };
- }
-
- rendererWrapper.drawBackground(gc, partHeaderBounds.x,
- partHeaderBounds.y, partHeaderBounds.width,
- partHeaderBounds.height, defaultBackground,
- unselectedTabsColors, unselectedTabsPercents, vertical);
- }
-
- private void drawTabAreaBackground(GC gc, Rectangle partHeaderBounds,
- int state, boolean vertical, Color defaultBackground) {
- Color[] colors = selectedTabAreaColors;
- int[] percents = selectedTabAreaPercents;
-
- if (colors != null && colors.length == 2) {
- colors = new Color[] { colors[1], colors[1] };
- }
- if (colors == null) {
- boolean selected = (state & SWT.SELECTED) != 0;
- colors = selected ? parentWrapper.getSelectionGradientColors()
- : parentWrapper.getGradientColors();
- percents = selected ? parentWrapper.getSelectionGradientPercents()
- : parentWrapper.getGradientPercents();
- }
- if (colors == null) {
- colors = new Color[] {
- gc.getDevice().getSystemColor(SWT.COLOR_WHITE) };
- percents = new int[] { 100 };
- }
-
- rendererWrapper.drawBackground(gc, partHeaderBounds.x,
- partHeaderBounds.y + partHeaderBounds.height,
- partHeaderBounds.width, parent.getBounds().height,
- defaultBackground, colors, percents, vertical);
- }
-
- // Workaround for the bug 433276. Remove it when the bug gets fixed
- private void drawChildrenBackground(Rectangle partHeaderBounds) {
- for (Control control : parent.getChildren()) {
- if (!CompositeElement.hasBackgroundOverriddenByCSS(control)
- && containsToolbar(control)) {
- drawChildBackground((Composite) control, partHeaderBounds);
- }
- }
- }
-
- private boolean containsToolbar(Control control) {
- if (control.getData(CONTAINS_TOOLBAR) != null) {
- return true;
- }
-
- if (control instanceof ToolBar) {
- control.setData(CONTAINS_TOOLBAR, true);
- return true;
- }
-
- if (control instanceof Composite) {
- for (Control child : ((Composite) control).getChildren()) {
- if (child instanceof ToolBar) {
- control.setData(CONTAINS_TOOLBAR, true);
- return true;
- }
- }
- }
- return false;
- }
-
- private void drawChildBackground(Composite composite,
- Rectangle partHeaderBounds) {
- Rectangle rec = composite.getBounds();
- Color background = null;
- boolean partOfHeader = rec.y >= partHeaderBounds.y
- && rec.y < partHeaderBounds.height;
-
- if (!partOfHeader) {
- background = composite.getDisplay().getSystemColor(SWT.COLOR_WHITE);
- }
- CTabFolderElement.setBackgroundOverriddenDuringRenderering(composite,
- background);
- }
-
- private static class CTabFolderRendererWrapper
- extends ReflectionSupport {
- private Method drawBackgroundMethod;
-
- private Method drawCloseMethod;
-
- public CTabFolderRendererWrapper(CTabFolderRenderer instance) {
- super(instance);
- }
-
- public void drawBackground(GC gc, int x, int y, int width, int height,
- Color defaultBackground, Color[] colors, int[] percents,
- boolean vertical) {
- if (drawBackgroundMethod == null) {
- drawBackgroundMethod = getMethod("drawBackground", //$NON-NLS-1$
- new Class>[] { GC.class, int[].class, int.class,
- int.class, int.class, int.class, Color.class,
- Image.class, Color[].class, int[].class,
- boolean.class });
- }
- executeMethod(drawBackgroundMethod,
- new Object[] { gc, null, x, y, width, height,
- defaultBackground, null, colors, percents,
- vertical });
- }
-
- public void drawClose(GC gc, Rectangle closeRect, int closeImageState) {
- if (drawCloseMethod == null) {
- drawCloseMethod = getMethod("drawClose", new Class>[] { //$NON-NLS-1$
- GC.class, Rectangle.class, int.class });
- }
- executeMethod(drawCloseMethod,
- new Object[] { gc, closeRect, closeImageState });
- }
- }
-
- private static class CTabItemWrapper extends ReflectionSupport {
-
- private Field shortenedTextField;
-
- private Field shortenedTextWidthField;
-
- private Field closeRectField;
-
- private Field closeImageStateField;
-
- public CTabItemWrapper(CTabItem instance) {
- super(instance);
- }
-
- public String getShortenedText() {
- if (shortenedTextField == null) {
- shortenedTextField = getField("shortenedText"); //$NON-NLS-1$
- }
- return (String) getFieldValue(shortenedTextField);
- }
-
- public void setShortenedText(String value) {
- set("shortenedText", value); //$NON-NLS-1$
- }
-
- public Integer getShortenedTextWidth() {
- if (shortenedTextWidthField == null) {
- shortenedTextWidthField = getField("shortenedTextWidth"); //$NON-NLS-1$
- }
- return (Integer) getFieldValue(shortenedTextWidthField);
- }
-
- public void setShortenedTextWidth(int value) {
- set("shortenedTextWidth", value); //$NON-NLS-1$
- }
-
- public Rectangle getCloseRect() {
- if (closeRectField == null) {
- closeRectField = getField("closeRect"); //$NON-NLS-1$
- }
- return (Rectangle) getFieldValue(closeRectField);
- }
-
- public int getCloseImageState() {
- if (closeImageStateField == null) {
- closeImageStateField = getField("closeImageState"); //$NON-NLS-1$
- }
- return (Integer) getFieldValue(closeImageStateField);
- }
-
- }
-
- private static class CTabFolderWrapper
- extends ReflectionSupport {
- private Field selectionGradientVerticalField;
-
- private Field gradientVerticalField;
-
- private Field selectionGradientColorsField;
-
- private Field selectionGradientPercentsField;
-
- private Field gradientColorsField;
-
- private Field gradientPercentsField;
-
- private Field showCloseField;
-
- private Field fixedTabHeightField;
-
- private Method getRightItemEdgeMethod;
-
- public CTabFolderWrapper(CTabFolder instance) {
- super(instance);
- }
-
- public boolean isShowClose() {
- if (showCloseField == null) {
- showCloseField = getField("showClose"); //$NON-NLS-1$
- }
- Boolean result = (Boolean) getFieldValue(showCloseField);
- return result != null ? result : true;
- }
-
- public boolean isSelectionGradientVertical() {
- if (selectionGradientVerticalField == null) {
- selectionGradientVerticalField = getField(
- "selectionGradientVertical"); //$NON-NLS-1$
- }
- Boolean result = (Boolean) getFieldValue(
- selectionGradientVerticalField);
- return result != null ? result : true;
- }
-
- public boolean isGradientVertical() {
- if (gradientVerticalField == null) {
- gradientVerticalField = getField("gradientVertical"); //$NON-NLS-1$
- }
- Boolean result = (Boolean) getFieldValue(gradientVerticalField);
- return result != null ? result : true;
- }
-
- public Color[] getSelectionGradientColors() {
- if (selectionGradientColorsField == null) {
- selectionGradientColorsField = getField(
- "selectionGradientColorsField"); //$NON-NLS-1$
- }
- return (Color[]) getFieldValue(selectionGradientColorsField);
- }
-
- public int[] getSelectionGradientPercents() {
- if (selectionGradientPercentsField == null) {
- selectionGradientPercentsField = getField(
- "selectionGradientPercents"); //$NON-NLS-1$
- }
- return (int[]) getFieldValue(selectionGradientPercentsField);
- }
-
- public Color[] getGradientColors() {
- if (gradientColorsField == null) {
- gradientColorsField = getField("gradientColors"); //$NON-NLS-1$
- }
- return (Color[]) getFieldValue(gradientColorsField);
- }
-
- public int[] getGradientPercents() {
- if (gradientPercentsField == null) {
- gradientPercentsField = getField("gradientPercents"); //$NON-NLS-1$
- }
- return (int[]) getFieldValue(gradientPercentsField);
- }
-
- public int getRightItemEdge(GC gc) {
- if (getRightItemEdgeMethod == null) {
- getRightItemEdgeMethod = getMethod("getRightItemEdge", //$NON-NLS-1$
- new Class>[] { GC.class });
- }
- return (Integer) executeMethod(getRightItemEdgeMethod,
- new Object[] { gc });
- }
-
- public int getFixedTabHeight() {
- if (fixedTabHeightField == null) {
- fixedTabHeightField = getField("fixedTabHeight"); //$NON-NLS-1$
- }
- return (Integer) getFieldValue(fixedTabHeightField);
- }
- }
-
- private static class ReflectionSupport {
- private T instance;
-
- public ReflectionSupport(T instance) {
- this.instance = instance;
- }
-
- protected Object getFieldValue(Field field) {
- Object value = null;
- if (field != null) {
- boolean accessible = field.isAccessible();
- try {
- field.setAccessible(true);
- value = field.get(instance);
- } catch (Exception exc) {
- // do nothing
- } finally {
- field.setAccessible(accessible);
- }
- }
- return value;
- }
-
- protected Field getField(String name) {
- Class> cls = instance.getClass();
- while (!cls.equals(Object.class)) {
- try {
- return cls.getDeclaredField(name);
- } catch (Exception exc) {
- cls = cls.getSuperclass();
- }
- }
- return null;
- }
-
- public Object set(String name, Object value) {
- try {
- Field field = getField(name);
- boolean accessible = field.isAccessible();
- field.setAccessible(true);
- field.set(instance, value);
- field.setAccessible(accessible);
- return value;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- protected Object executeMethod(Method method, Object... params) {
- Object value = null;
- if (method != null) {
- boolean accessible = method.isAccessible();
- try {
- method.setAccessible(true);
- value = method.invoke(instance, params);
- } catch (Exception exc) {
- // do nothing
- } finally {
- method.setAccessible(accessible);
- }
- }
- return value;
- }
-
- protected Method getMethod(String name, Class>... params) {
- Class> cls = instance.getClass();
- while (!cls.equals(Object.class)) {
- try {
- return cls.getDeclaredMethod(name, params);
- } catch (Exception exc) {
- cls = cls.getSuperclass();
- }
- }
- return null;
- }
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.inject.Inject;
+
+import org.eclipse.e4.ui.css.swt.dom.CTabFolderElement;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.graphics.Pattern;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.Region;
+import org.eclipse.swt.graphics.TextLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.ToolBar;
+import org.xmind.cathy.internal.ICathyConstants;
+
+@SuppressWarnings("restriction")
+public class CathyCTabFolderRendering extends CTabFolderRenderer
+ implements ICTabFolderRendering {
+ private static final String CONTAINS_TOOLBAR = "CathyCTabFolderRendering.containsToolbar"; //$NON-NLS-1$
+
+ // Constants for circle drawing
+ final static int LEFT_TOP = 0;
+ final static int LEFT_BOTTOM = 1;
+ final static int RIGHT_TOP = 2;
+ final static int RIGHT_BOTTOM = 3;
+
+ // drop shadow constants
+ final static int SIDE_DROP_WIDTH = 3;
+ final static int BOTTOM_DROP_WIDTH = 4;
+
+ // keylines
+ final static int OUTER_KEYLINE = 1;
+ final static int INNER_KEYLINE = 0;
+ final static int TOP_KEYLINE = 0;
+
+ // Item Constants
+ static final int ITEM_TOP_MARGIN = 2;
+ static final int ITEM_BOTTOM_MARGIN = 6;
+ static final int ITEM_LEFT_MARGIN = 8;
+ static final int ITEM_RIGHT_MARGIN = 4;
+ static final int INTERNAL_SPACING = 4;
+
+ static final int FLAGS = SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC;
+ static final String ELLIPSIS = "..."; //$NON-NLS-1$
+ static final String E4_TOOLBAR_ACTIVE_IMAGE = "org.eclipse.e4.renderer.toolbar_background_active_image"; //$NON-NLS-1$
+ static final String E4_TOOLBAR_INACTIVE_IMAGE = "org.eclipse.e4.renderer.toolbar_background_inactive_image"; //$NON-NLS-1$
+
+ static final int BUTTON_BORDER = SWT.COLOR_WIDGET_DARK_SHADOW;
+ static final int BUTTON_SIZE = 16;
+
+ static final RGB CLOSE_FILL = new RGB(252, 160, 160);
+
+ private Color closeFillColor;
+
+ int[] shape;
+
+ Image shadowImage, toolbarActiveImage, toolbarInactiveImage;
+
+ int cornerSize = 14;
+
+ //The best value
+ boolean shadowEnabled = true;
+ Color shadowColor;
+ Color outerKeyline, innerKeyline;
+ Color[] activeToolbar;
+ int[] activePercents;
+ Color[] inactiveToolbar;
+ int[] inactivePercents;
+ boolean active;
+
+ Color[] selectedTabFillColors;
+ int[] selectedTabFillPercents;
+
+ Color[] selectedTabAreaColors;
+ int[] selectedTabAreaPercents;
+
+ Color[] unselectedTabsColors;
+ int[] unselectedTabsPercents;
+
+ Color[] hoverTabColors;
+ int[] hoverTabPercents;
+
+ Color tabOutlineColor;
+
+ int paddingLeft = 2, paddingRight = 2, paddingTop = 2, paddingBottom = 2;
+
+ private CTabFolderRendererWrapper rendererWrapper;
+ private CTabFolderWrapper parentWrapper;
+
+ private boolean textVisible = true;
+
+ private boolean imageVisible = true;
+
+ private boolean outerBorderVisible = true;
+ private boolean innerBorderVisible = true;
+
+ private boolean unselectedTabsBackgroundVisible = true;
+
+ private Image maxImage;
+
+ private Image minImage;
+
+ private Image closeImage;
+
+ private Image closeHoverImage;
+
+ private int[] tabArea;
+
+ //temp
+ private boolean hoverBorderVisible = false;
+
+ private boolean nothingToRender = false;
+
+ @Inject
+ public CathyCTabFolderRendering(CTabFolder parent) {
+ super(parent);
+ parentWrapper = new CTabFolderWrapper(parent);
+ rendererWrapper = new CTabFolderRendererWrapper(this);
+ }
+
+ @Override
+ protected Rectangle computeTrim(int part, int state, int x, int y,
+ int width, int height) {
+ if (!nothingToRender) {
+ boolean onBottom = isTabOnBottom();
+ int borderTop = onBottom ? INNER_KEYLINE + OUTER_KEYLINE
+ : TOP_KEYLINE + OUTER_KEYLINE;
+ int borderBottom = onBottom ? TOP_KEYLINE + OUTER_KEYLINE
+ : INNER_KEYLINE + OUTER_KEYLINE;
+ int marginWidth = parent.marginWidth;
+ int marginHeight = parent.marginHeight;
+ int sideDropWidth = shadowEnabled ? SIDE_DROP_WIDTH : 0;
+ int bottomDropWidth = shadowEnabled ? BOTTOM_DROP_WIDTH : 0;
+ int headerBorderBottom = outerBorderVisible ? OUTER_KEYLINE : 0;
+ switch (part) {
+ //body trimmed + body client area
+ case PART_BODY:
+ if (state == SWT.FILL) {
+ x = x - paddingLeft - sideDropWidth
+ - (INNER_KEYLINE + OUTER_KEYLINE) - marginWidth;
+ int tabHeight = parent.getTabHeight() + 1;
+ y = onBottom
+ ? y - paddingTop - marginHeight - borderTop
+ - bottomDropWidth
+ : y - paddingTop - marginHeight - tabHeight
+ - borderTop - headerBorderBottom
+ - bottomDropWidth;
+ width = 2 * (INNER_KEYLINE + OUTER_KEYLINE) + paddingLeft
+ + paddingRight + 2 * sideDropWidth
+ + 2 * marginWidth;
+ height += paddingTop + paddingBottom + bottomDropWidth;
+ height += tabHeight + headerBorderBottom + borderBottom
+ + borderTop;
+ } else {
+ x = x - marginWidth - OUTER_KEYLINE - INNER_KEYLINE
+ - sideDropWidth - (cornerSize / 2) - paddingLeft;
+ width = width + 2 * OUTER_KEYLINE + 2 * INNER_KEYLINE
+ + 2 * marginWidth + 2 * sideDropWidth + cornerSize
+ + paddingRight + paddingLeft;
+ int tabHeight = parent.getTabHeight() + 1;
+ if (parent.getMinimized()) {
+ y = onBottom ? y - borderTop - 5
+ : y - tabHeight - borderTop - 5;
+ height = borderTop + borderBottom + tabHeight;
+ } else {
+ y = onBottom
+ ? y - marginHeight - borderTop - paddingTop
+ - bottomDropWidth
+ : y - marginHeight - tabHeight - borderTop
+ - paddingTop - headerBorderBottom
+ - bottomDropWidth;
+ height = height + borderBottom + borderTop
+ + 2 * marginHeight + tabHeight
+ + headerBorderBottom + bottomDropWidth
+ + paddingTop + paddingBottom;
+ }
+ }
+ break;
+ case PART_HEADER:
+ x = x - (INNER_KEYLINE + OUTER_KEYLINE) - marginWidth
+ - sideDropWidth;
+ width = width + 2 * (INNER_KEYLINE + OUTER_KEYLINE)
+ + 2 * marginWidth + 2 * sideDropWidth;
+ y = y - borderTop - marginHeight;
+ break;
+ case PART_BORDER:
+ x = x - INNER_KEYLINE - OUTER_KEYLINE - sideDropWidth
+ - (cornerSize / 4);
+ width = width + 2 * (INNER_KEYLINE + OUTER_KEYLINE)
+ + 2 * sideDropWidth + cornerSize / 2;
+ height = height + borderTop + borderBottom;
+ y = y - borderTop;
+ if (onBottom) {
+ if (shadowEnabled) {
+ height += 3;
+ }
+ }
+ break;
+ default:
+ if (0 <= part && part < parent.getItemCount()) {
+ x = x - ITEM_LEFT_MARGIN;// - (CORNER_SIZE/2);
+ width = width + ITEM_LEFT_MARGIN + ITEM_RIGHT_MARGIN + 1;
+ y = y - ITEM_TOP_MARGIN;
+ height = height + ITEM_TOP_MARGIN + ITEM_BOTTOM_MARGIN;
+ }
+ break;
+ }
+ }
+ return new Rectangle(x, y, width, height);
+ }
+
+ @Override
+ protected Point computeSize(int part, int state, GC gc, int wHint,
+ int hHint) {
+ int width = 0, height = 0;
+ switch (part) {
+ case PART_HEADER:
+ int fixedTabHeight = parentWrapper.getFixedTabHeight();
+ if (fixedTabHeight != SWT.DEFAULT) {
+ //TODO use field variable instead of 1
+ height = fixedTabHeight == 0 ? 0 : fixedTabHeight + 1; // +1 for line drawn across top of tab
+ } else {
+ CTabItem[] items = parent.getItems();
+ if (items.length == 0) {
+ height = gc.textExtent("Default", FLAGS).y + ITEM_TOP_MARGIN //$NON-NLS-1$
+ + ITEM_BOTTOM_MARGIN;
+ } else {
+ for (int i = 0; i < items.length; i++) {
+ height = Math.max(height,
+ computeSize(i, SWT.NONE, gc, wHint, hHint).y);
+ }
+ }
+ height = Math.max(height, parent.getTabHeight() + 1);
+ gc.dispose();
+ }
+ break;
+ case PART_MAX_BUTTON:
+ case PART_MIN_BUTTON:
+ case PART_CLOSE_BUTTON:
+ width = height = BUTTON_SIZE;
+ break;
+ case PART_CHEVRON_BUTTON:
+ width = 3 * BUTTON_SIZE / 2;
+ height = BUTTON_SIZE;
+ break;
+ default:
+ if (0 <= part && part < parent.getItemCount()) {
+ gc.setAdvanced(true);
+
+ CTabItem item = parent.getItem(part);
+ if (item.isDisposed())
+ return new Point(0, 0);
+
+ if (imageVisible || shouldDrawImage(item)) {
+ Image image = item.getImage();
+ if (image != null && !image.isDisposed()) {
+ Rectangle bounds = image.getBounds();
+ if ((state & SWT.SELECTED) != 0
+ || parent.getUnselectedImageVisible()) {
+ width += bounds.width;
+ }
+ height = bounds.height;
+ }
+ }
+
+ if (textVisible) {
+ String text = null;
+ if ((state & MINIMUM_SIZE) != 0) {
+ int minChars = parent.getMinimumCharacters();
+ text = minChars == 0 ? null : item.getText();
+ if (text != null && text.length() > minChars) {
+ if (useEllipse()) {
+ int end = minChars < ELLIPSIS.length() + 1
+ ? minChars
+ : minChars - ELLIPSIS.length();
+ text = text.substring(0, end);
+ if (minChars > ELLIPSIS.length() + 1)
+ text += ELLIPSIS;
+ } else {
+ int end = minChars;
+ text = text.substring(0, end);
+ }
+ }
+ } else {
+ text = item.getText();
+ }
+ if (text != null) {
+ if (width > 0)
+ width += INTERNAL_SPACING;
+ if (item.getFont() == null) {
+ Point size = gc.textExtent(text, FLAGS);
+ width += size.x;
+ height = Math.max(height, size.y);
+ } else {
+ Font gcFont = gc.getFont();
+ gc.setFont(item.getFont());
+ Point size = gc.textExtent(text, FLAGS);
+ width += size.x;
+ height = Math.max(height, size.y);
+ gc.setFont(gcFont);
+ }
+ }
+ }
+
+ if (parentWrapper.isShowClose() || item.getShowClose()) {
+ if ((state & SWT.SELECTED) != 0
+ || parent.getUnselectedCloseVisible()) {
+ if (width > 0)
+ width += INTERNAL_SPACING;
+ width += computeSize(PART_CLOSE_BUTTON, SWT.NONE, gc,
+ SWT.DEFAULT, SWT.DEFAULT).x;
+ }
+ }
+ }
+ break;
+ }
+ Rectangle trim = computeTrim(part, state, 0, 0, width, height);
+ width = trim.width;
+ height = trim.height;
+ return new Point(width, height);
+ }
+
+ private boolean useEllipse() {
+ return parent.getSimple();
+ }
+
+ private Color getCloseFillColor() {
+ if (closeFillColor == null) {
+ closeFillColor = new Color(parent.getDisplay(), CLOSE_FILL);
+ }
+ return closeFillColor;
+ }
+
+ @Override
+ protected void dispose() {
+ if (shadowImage != null && !shadowImage.isDisposed()) {
+ shadowImage.dispose();
+ shadowImage = null;
+ }
+ if (closeFillColor != null) {
+ closeFillColor.dispose();
+ closeFillColor = null;
+ }
+ super.dispose();
+ }
+
+ @Override
+ protected void draw(int part, int state, Rectangle bounds, GC gc) {
+ if (nothingToRender) {
+ return;
+ }
+
+ switch (part) {
+ case PART_BACKGROUND:
+ this.drawCustomBackground(gc, bounds, state);
+ return;
+ case PART_BODY:
+ this.drawTabBody(gc, bounds, state);
+ return;
+ case PART_HEADER:
+ this.drawTabHeader(gc, bounds, state);
+ return;
+ case PART_MAX_BUTTON:
+ if (maxImage != null) {
+ this.drawMaximizeButton(gc, bounds, state);
+ return;
+ }
+ break;
+ case PART_MIN_BUTTON:
+ if (minImage != null) {
+ this.drawMinimizeButton(gc, bounds, state);
+ return;
+ }
+ break;
+ case PART_CLOSE_BUTTON:
+ if (closeImage != null) {
+ this.drawCloseButton(gc, bounds, state);
+ return;
+ }
+ break;
+ default:
+ if (0 <= part && part < parent.getItemCount()) {
+ gc.setAdvanced(true);
+ if (bounds.width == 0 || bounds.height == 0)
+ return;
+ if ((state & SWT.SELECTED) != 0) {
+ drawSelectedTab(part, gc, bounds, state);
+ state &= ~SWT.BACKGROUND;
+ if ((state & SWT.SELECTED) != 0)
+ toDrawTab(true, part, gc, bounds, state);
+ } else {
+ drawUnselectedTab(part, gc, bounds, state);
+ if ((state & SWT.HOT) == 0 && !active) {
+ gc.setAlpha(0x7f);
+ state &= ~SWT.BACKGROUND;
+ toDrawTab(false, part, gc, bounds, state);
+ gc.setAlpha(0xff);
+ } else {
+ state &= ~SWT.BACKGROUND;
+ toDrawTab(false, part, gc, bounds, state);
+ }
+ }
+ return;
+ }
+ }
+ super.draw(part, state, bounds, gc);
+ }
+
+ private void drawCloseButton(GC gc, Rectangle bounds, int state) {
+ Image hoverImage = closeHoverImage == null ? closeImage
+ : closeHoverImage;
+ switch (state & (SWT.HOT | SWT.SELECTED | SWT.BACKGROUND)) {
+ case SWT.NONE:
+ gc.drawImage(closeImage, bounds.x, bounds.y);
+ break;
+ case SWT.HOT:
+ gc.drawImage(hoverImage, bounds.x, bounds.y);
+ break;
+ case SWT.SELECTED:
+ gc.drawImage(hoverImage, bounds.x + 1, bounds.y + 1);
+ break;
+ case SWT.BACKGROUND:
+ break;
+ }
+ }
+
+ private void drawMinimizeButton(GC gc, Rectangle bounds, int state) {
+ gc.drawImage(minImage, bounds.x, bounds.y);
+ }
+
+ private void drawMaximizeButton(GC gc, Rectangle bounds, int state) {
+ gc.drawImage(maxImage, bounds.x, bounds.y);
+ }
+
+ void drawTabHeader(GC gc, Rectangle bounds, int state) {
+ boolean onBottom = parent.getTabPosition() == SWT.BOTTOM;
+
+ // Fill in background
+ Region clipping = new Region();
+ gc.getClipping(clipping);
+ Region region = new Region();
+ region.add(shape);
+ region.intersect(clipping);
+ gc.setClipping(region);
+
+ int header = shadowEnabled ? onBottom ? 6 : 3 : 1;
+ Rectangle trim = computeTrim(PART_HEADER, state, 0, 0, 0, 0);
+ trim.width = bounds.width - trim.width;
+ trim.height = computeSize(PART_HEADER, state, gc, 0, 0).y;
+ trim.x = -trim.x;
+ trim.y = onBottom ? bounds.height - parent.getTabHeight() - 1 - header
+ : -trim.y;
+ draw(PART_BACKGROUND, SWT.NONE, trim, gc);
+
+ gc.setClipping(clipping);
+ clipping.dispose();
+ region.dispose();
+
+ if (outerKeyline == null)
+ outerKeyline = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
+ gc.setForeground(outerKeyline);
+ if (outerBorderVisible) {
+ gc.drawPolyline(tabArea);
+ gc.drawLine(trim.x, trim.y + trim.height, trim.x + trim.width,
+ trim.y + trim.height);
+ }
+ }
+
+ void generateTabArea(Rectangle bounds) {
+ int[] points = new int[1024];
+ int index = 0;
+ int radius = cornerSize / 2;
+ int marginWidth = parent.marginWidth;
+ int marginHeight = parent.marginHeight;
+ int delta = (INNER_KEYLINE + OUTER_KEYLINE) * 2 + marginWidth * 2;
+ int width = bounds.width - delta;
+ int height = Math.max(
+ parent.getTabHeight() + INNER_KEYLINE + OUTER_KEYLINE,
+ bounds.height
+ - (INNER_KEYLINE + OUTER_KEYLINE + marginHeight * 2));
+
+ int circX = bounds.x + radius + delta / 2;
+ int circY = bounds.y + radius;
+
+ // Body
+ index = 0;
+ int[] ltt = { bounds.x + delta / 2,
+ bounds.y + parent.getTabHeight() + delta };
+ System.arraycopy(ltt, 0, points, index, ltt.length);
+ index += ltt.length;
+
+ int[] lbb = drawCircle(circX, circY + height - (radius * 2), radius,
+ LEFT_BOTTOM);
+ System.arraycopy(lbb, 0, points, index, lbb.length);
+ index += lbb.length;
+
+ int[] rb = drawCircle(circX + width - (radius * 2),
+ circY + height - (radius * 2), radius, RIGHT_BOTTOM);
+ System.arraycopy(rb, 0, points, index, rb.length);
+ index += rb.length;
+
+ int[] rt = { bounds.x + delta / 2 + width,
+ bounds.y + parent.getTabHeight() + delta };
+ System.arraycopy(rt, 0, points, index, rt.length);
+ index += rt.length;
+
+// points[index++] = bounds.x + delta / 2;
+// points[index++] = bounds.y + parent.getTabHeight() + 1;
+
+ int[] tempPoints = new int[index];
+ System.arraycopy(points, 0, tempPoints, 0, index);
+
+ tabArea = tempPoints;
+
+ }
+
+ void drawTabBody(GC gc, Rectangle bounds, int state) {
+ generateTabArea(bounds);
+
+ int[] points = new int[1024];
+ int index = 0;
+ int radius = cornerSize / 2;
+ int marginWidth = parent.marginWidth;
+ int marginHeight = parent.marginHeight;
+ int delta = (INNER_KEYLINE + OUTER_KEYLINE) * 2 + marginWidth * 2;
+ int width = bounds.width - delta;
+ int height = Math.max(
+ parent.getTabHeight() + INNER_KEYLINE + OUTER_KEYLINE,
+ bounds.height
+ - (INNER_KEYLINE + OUTER_KEYLINE + marginHeight * 2));
+
+ int circX = bounds.x + radius + delta / 2;
+ int circY = bounds.y + radius;
+
+ // Body
+ index = 0;
+ int[] ltt = drawCircle(circX, circY, radius, LEFT_TOP);
+ System.arraycopy(ltt, 0, points, index, ltt.length);
+ index += ltt.length;
+
+ int[] lbb = drawCircle(circX, circY + height - (radius * 2), radius,
+ LEFT_BOTTOM);
+ System.arraycopy(lbb, 0, points, index, lbb.length);
+ index += lbb.length;
+
+ int[] rb = drawCircle(circX + width - (radius * 2),
+ circY + height - (radius * 2), radius, RIGHT_BOTTOM);
+ System.arraycopy(rb, 0, points, index, rb.length);
+ index += rb.length;
+
+ int[] rt = drawCircle(circX + width - (radius * 2), circY, radius,
+ RIGHT_TOP);
+ System.arraycopy(rt, 0, points, index, rt.length);
+ index += rt.length;
+ points[index++] = circX;
+ points[index++] = circY - radius;
+
+ int[] tempPoints = new int[index];
+ System.arraycopy(points, 0, tempPoints, 0, index);
+
+ // Fill in parent background for non-rectangular shape
+ Region r = new Region();
+ r.add(bounds);
+ r.subtract(tempPoints);
+ gc.setBackground(parent.getParent().getBackground());
+ Display display = parent.getDisplay();
+ Region clipping = new Region();
+ gc.getClipping(clipping);
+ r.intersect(clipping);
+ gc.setClipping(r);
+ Rectangle mappedBounds = display.map(parent, parent.getParent(),
+ bounds);
+ parent.getParent().drawBackground(gc, bounds.x, bounds.y, bounds.width,
+ bounds.height, mappedBounds.x, mappedBounds.y);
+
+ // Shadow
+ if (shadowEnabled)
+ drawShadow(display, bounds, gc);
+
+ gc.setClipping(clipping);
+ clipping.dispose();
+ r.dispose();
+
+ // Remember for use in header drawing
+ shape = tempPoints;
+ }
+
+ /*
+ * Draw active and unactive selected tab item
+ */
+ void drawSelectedTab(int itemIndex, GC gc, Rectangle bounds, int state) {
+ if (parent.getSingle() && parent.getItem(itemIndex).isShowing())
+ return;
+
+ boolean onBottom = parent.getTabPosition() == SWT.BOTTOM;
+ int header = shadowEnabled ? 2 : 0;
+ int width = bounds.width;
+ int[] points = new int[1024];
+ int index = 0;
+ int radius = cornerSize / 2;
+ int circX = bounds.x + radius;
+ int circY = onBottom ? bounds.y + bounds.height - header - radius
+ : bounds.y + radius;
+ int selectionX1, selectionY1, selectionX2, selectionY2;
+ int bottomY = onBottom ? bounds.y - header : bounds.y + bounds.height;
+ if (itemIndex == 0
+ && bounds.x == -computeTrim(CTabFolderRenderer.PART_HEADER,
+ SWT.NONE, 0, 0, 0, 0).x) {
+// circX -= 1;
+// points[index++] = circX - radius;
+// points[index++] = bottomY;
+
+ points[index++] = selectionX1 = circX - radius;
+ points[index++] = selectionY1 = bottomY;
+ } else {
+ if (active) {
+ points[index++] = shadowEnabled ? SIDE_DROP_WIDTH
+ : 0 + INNER_KEYLINE + OUTER_KEYLINE;
+ points[index++] = bottomY;
+ }
+ points[index++] = selectionX1 = bounds.x;
+ points[index++] = selectionY1 = bottomY;
+ }
+
+ int startX = -1, endX = -1;
+ if (!onBottom) {
+ int[] ltt = drawCircle(circX, circY, radius, LEFT_TOP);
+ startX = ltt[6];
+ for (int i = 0; i < ltt.length / 2; i += 2) {
+ int tmp = ltt[i];
+ ltt[i] = ltt[ltt.length - i - 2];
+ ltt[ltt.length - i - 2] = tmp;
+ tmp = ltt[i + 1];
+ ltt[i + 1] = ltt[ltt.length - i - 1];
+ ltt[ltt.length - i - 1] = tmp;
+ }
+ System.arraycopy(ltt, 0, points, index, ltt.length);
+ index += ltt.length;
+
+ int[] rt = drawCircle(circX + width - (radius * 2), circY, radius,
+ RIGHT_TOP);
+ endX = rt[rt.length - 4];
+ for (int i = 0; i < rt.length / 2; i += 2) {
+ int tmp = rt[i];
+ rt[i] = rt[rt.length - i - 2];
+ rt[rt.length - i - 2] = tmp;
+ tmp = rt[i + 1];
+ rt[i + 1] = rt[rt.length - i - 1];
+ rt[rt.length - i - 1] = tmp;
+ }
+ System.arraycopy(rt, 0, points, index, rt.length);
+ index += rt.length;
+
+ points[index++] = selectionX2 = bounds.width + circX - radius;
+ points[index++] = selectionY2 = bottomY;
+ } else {
+ int[] ltt = drawCircle(circX, circY, radius, LEFT_BOTTOM);
+ startX = ltt[6];
+ System.arraycopy(ltt, 0, points, index, ltt.length);
+ index += ltt.length;
+
+ int[] rt = drawCircle(circX + width - (radius * 2), circY, radius,
+ RIGHT_BOTTOM);
+ endX = rt[rt.length - 4];
+ System.arraycopy(rt, 0, points, index, rt.length);
+ index += rt.length;
+
+ points[index++] = selectionX2 = bounds.width + circX - radius;
+ points[index++] = selectionY2 = bottomY;
+ }
+
+ if (active) {
+ points[index++] = parent.getSize().x - (shadowEnabled
+ ? SIDE_DROP_WIDTH : 0 + INNER_KEYLINE + OUTER_KEYLINE);
+ points[index++] = bottomY;
+ }
+ gc.setClipping(bounds.x, onBottom ? bounds.y - header : bounds.y,
+ parent.getSize().x - (shadowEnabled ? SIDE_DROP_WIDTH
+ : 0 + INNER_KEYLINE + OUTER_KEYLINE),
+ bounds.y + bounds.height);
+
+ Pattern backgroundPattern = null;
+ if (selectedTabFillColors == null) {
+ setSelectedTabFill(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+ }
+ if (selectedTabFillColors.length == 1) {
+ gc.setBackground(selectedTabFillColors[0]);
+ gc.setForeground(selectedTabFillColors[0]);
+ } else if (!onBottom && selectedTabFillColors.length == 2) {
+ // for now we support the 2-colors gradient for selected tab
+ backgroundPattern = new Pattern(gc.getDevice(), 0, 0, 0,
+ bounds.height + 1, selectedTabFillColors[0],
+ selectedTabFillColors[1]);
+ gc.setBackgroundPattern(backgroundPattern);
+ gc.setForeground(selectedTabFillColors[1]);
+ }
+
+ int[] tmpPoints = new int[index];
+ System.arraycopy(points, 0, tmpPoints, 0, index);
+ gc.fillPolygon(tmpPoints);
+
+ //cover item bottom border using background color
+ gc.drawLine(selectionX1, selectionY1, selectionX2, selectionY2);
+
+ gc.setClipping(bounds.x - 1,
+ onBottom ? bounds.y - header : bounds.y - 1,
+ parent.getSize().x - (shadowEnabled ? SIDE_DROP_WIDTH
+ : 0 + INNER_KEYLINE + OUTER_KEYLINE),
+ bounds.y + bounds.height);
+ if (innerBorderVisible) {
+ if (innerKeyline == null)
+ innerKeyline = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
+ gc.setForeground(innerKeyline);
+ gc.drawPolyline(tmpPoints);
+ }
+ Rectangle rect = null;
+ gc.setClipping(rect);
+
+ if (outerBorderVisible) {
+ if (!onBottom) {
+ if (outerKeyline == null)
+ outerKeyline = gc.getDevice()
+ .getSystemColor(SWT.COLOR_BLACK);
+ gc.setForeground(outerKeyline);
+ gc.drawLine(startX + 2, 1, endX - 1, 1);
+ }
+ }
+
+ if (backgroundPattern != null) {
+ backgroundPattern.dispose();
+ }
+ }
+
+ private boolean isTabOnBottom() {
+ return parent.getTabPosition() == SWT.BOTTOM;
+ }
+
+ private String getShortenedText(GC gc, String text, int width) {
+ return useEllipse() ? getShortenedText(gc, text, width, ELLIPSIS)
+ : getShortenedText(gc, text, width, ""); //$NON-NLS-1$
+ }
+
+ private String getShortenedText(GC gc, String text, int width,
+ String ellipses) {
+ if (gc.textExtent(text, FLAGS).x <= width)
+ return text;
+ int ellipseWidth = gc.textExtent(ellipses, FLAGS).x;
+ int length = text.length();
+ TextLayout layout = new TextLayout(parent.getDisplay());
+ layout.setText(text);
+ int end = layout.getPreviousOffset(length, SWT.MOVEMENT_CLUSTER);
+ while (end > 0) {
+ text = text.substring(0, end);
+ int l = gc.textExtent(text, FLAGS).x;
+ if (l + ellipseWidth <= width) {
+ break;
+ }
+ end = layout.getPreviousOffset(end, SWT.MOVEMENT_CLUSTER);
+ }
+ layout.dispose();
+ return end == 0 ? text.substring(0, 1) : text + ellipses;
+ }
+
+ private void toDrawTab(boolean selected, int itemIndex, GC gc,
+ Rectangle bounds, int state) {
+ CTabItem item = parent.getItem(itemIndex);
+ int x = bounds.x;
+ int y = bounds.y;
+ int height = bounds.height;
+ int width = bounds.width;
+
+ int rightEdge = Math.min(x + width, parentWrapper.getRightItemEdge(gc));
+
+ if ((state & SWT.FOREGROUND) != 0) {
+ CTabItemWrapper itemWrapper = new CTabItemWrapper(item);
+ Rectangle itemCloseRect = itemWrapper.getCloseRect();
+ itemCloseRect = new Rectangle(itemCloseRect.x, itemCloseRect.y,
+ itemCloseRect.width, itemCloseRect.height);
+
+ // draw Image
+ Rectangle trim = computeTrim(itemIndex, SWT.NONE, 0, 0, 0, 0);
+ int xDraw = x - trim.x;
+ if (parent.getSingle()
+ && (parentWrapper.isShowClose() || item.getShowClose()))
+ xDraw += itemWrapper.getCloseRect().width;
+ if (imageVisible || shouldDrawImage(item)) {
+ Image image = item.getImage();
+ if (image != null && !image.isDisposed()) {
+ Rectangle imageBounds = image.getBounds();
+ // only draw image if it won't overlap with close button
+ int maxImageWidth = rightEdge - xDraw
+ - (trim.width + trim.x);
+ if (!parent.getSingle() && itemCloseRect.width > 0)
+ maxImageWidth -= itemCloseRect.width + INTERNAL_SPACING;
+ if (imageBounds.width < maxImageWidth) {
+ int imageX = xDraw;
+ int imageY = y + (height - imageBounds.height) / 2;
+ imageY += isTabOnBottom() ? -1 : 1;
+ gc.drawImage(image, imageX, imageY);
+ xDraw += imageBounds.width + INTERNAL_SPACING;
+ }
+ }
+ }
+
+ if (textVisible) {
+ // draw Text
+ int textWidth = rightEdge - xDraw - (trim.width + trim.x);
+ if (!parent.getSingle() && itemCloseRect.width > 0)
+ textWidth -= itemCloseRect.width + INTERNAL_SPACING;
+ if (textWidth > 0) {
+ Font gcFont = gc.getFont();
+ gc.setFont(item.getFont() == null ? parent.getFont()
+ : item.getFont());
+
+ if (itemWrapper.getShortenedText() == null || itemWrapper
+ .getShortenedTextWidth() != textWidth) {
+ itemWrapper.setShortenedText(getShortenedText(gc,
+ item.getText(), textWidth));
+ itemWrapper.setShortenedTextWidth(textWidth);
+ }
+ Point extent = gc.textExtent(itemWrapper.getShortenedText(),
+ FLAGS);
+ int textY = y + (height - extent.y) / 2;
+ textY += isTabOnBottom() ? -1 : 1;
+
+ gc.setForeground(selected ? parent.getSelectionForeground()
+ : parent.getForeground());
+ gc.drawText(itemWrapper.getShortenedText(), xDraw, textY,
+ FLAGS);
+ gc.setFont(gcFont);
+
+ if (selected) {
+ // draw a Focus rectangle
+ if (parent.isFocusControl()) {
+ Display display = parent.getDisplay();
+ if (parent.getSimple() || parent.getSingle()) {
+ gc.setBackground(display
+ .getSystemColor(SWT.COLOR_BLACK));
+ gc.setForeground(display
+ .getSystemColor(SWT.COLOR_WHITE));
+ gc.drawFocus(xDraw - 1, textY - 1, extent.x + 2,
+ extent.y + 2);
+ } else {
+ gc.setForeground(
+ display.getSystemColor(BUTTON_BORDER));
+ gc.drawLine(xDraw, textY + extent.y + 1,
+ xDraw + extent.x + 1,
+ textY + extent.y + 1);
+ }
+ }
+ }
+
+ }
+ }
+
+ if (parentWrapper.isShowClose() || item.getShowClose()) {
+ if (closeImage != null) {
+ drawCloseButton(gc, itemCloseRect,
+ itemWrapper.getCloseImageState());
+ } else {
+ drawClose2(gc, itemCloseRect,
+ itemWrapper.getCloseImageState());
+ }
+ }
+ }
+ }
+
+ void drawClose2(GC gc, Rectangle closeRect, int closeImageState) {
+ if (closeRect.width == 0 || closeRect.height == 0)
+ return;
+ Display display = parent.getDisplay();
+
+ // draw X 9x9
+ int x = closeRect.x + Math.max(1, (closeRect.width - 9) / 2);
+ int y = closeRect.y + Math.max(1, (closeRect.height - 9) / 2);
+
+ Color closeBorder = display.getSystemColor(BUTTON_BORDER);
+ int[] fillShape = new int[] { x + 1, y + 1, x + 3, y + 1, x + 5, y + 3,
+ x + 6, y + 3, x + 8, y + 1, x + 10, y + 1, x + 10, y + 3, x + 8,
+ y + 5, x + 8, y + 6, x + 10, y + 8, x + 10, y + 10, x + 8,
+ y + 10, x + 6, y + 8, x + 5, y + 8, x + 3, y + 10, x + 1,
+ y + 10, x + 1, y + 8, x + 3, y + 6, x + 3, y + 5, x + 1,
+ y + 3 };
+ int[] drawShape = new int[] { x, y, x + 2, y, x + 4, y + 2, x + 5,
+ y + 2, x + 7, y, x + 9, y, x + 9, y + 2, x + 7, y + 4, x + 7,
+ y + 5, x + 9, y + 7, x + 9, y + 9, x + 7, y + 9, x + 5, y + 7,
+ x + 4, y + 7, x + 2, y + 9, x, y + 9, x, y + 7, x + 2, y + 5,
+ x + 2, y + 4, x, y + 2 };
+ switch (closeImageState & (SWT.HOT | SWT.SELECTED | SWT.BACKGROUND)) {
+ case SWT.NONE: {
+ gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
+ gc.fillPolygon(fillShape);
+ gc.setForeground(closeBorder);
+ gc.drawPolygon(drawShape);
+ break;
+ }
+ case SWT.HOT: {
+ gc.setBackground(getCloseFillColor());
+ gc.fillPolygon(fillShape);
+ gc.setForeground(closeBorder);
+ gc.drawPolygon(drawShape);
+ break;
+ }
+ case SWT.SELECTED: {
+ gc.setBackground(getCloseFillColor());
+ gc.fillPolygon(fillShape);
+ gc.setForeground(closeBorder);
+ gc.drawPolygon(drawShape);
+ break;
+ }
+ case SWT.BACKGROUND: {
+ rendererWrapper.drawClose(gc, closeRect, closeImageState);
+ break;
+ }
+ }
+ }
+
+ private boolean shouldDrawImage(CTabItem item) {
+ Object model = item.getData(AbstractPartRenderer.OWNING_ME);
+ if (model != null && model instanceof MUIElement) {
+ MUIElement element = (MUIElement) model;
+ if (element.getTags().contains(ICathyConstants.TAG_SHOW_IMAGE)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void drawUnselectedTab(int itemIndex, GC gc, Rectangle bounds, int state) {
+ if ((state & SWT.HOT) != 0) {
+ int header = shadowEnabled ? 2 : 0;
+ int width = bounds.width;
+ boolean onBottom = parent.getTabPosition() == SWT.BOTTOM;
+ int[] points = new int[1024];
+ int[] inactive = new int[8];
+ int index = 0, inactive_index = 0;
+ int radius = cornerSize / 2;
+ int circX = bounds.x + radius;
+ int circY = onBottom
+ ? bounds.y + bounds.height + 1 - header - radius
+ : bounds.y - 1 + radius;
+ int bottomY = onBottom ? bounds.y - header
+ : bounds.y + bounds.height;
+
+ int leftIndex = circX;
+ if (itemIndex == 0) {
+// if (parent.getSelectionIndex() != 0)
+// leftIndex -= 1;
+ points[index++] = leftIndex - radius;
+ points[index++] = bottomY;
+
+ } else {
+ points[index++] = bounds.x;
+ points[index++] = bottomY;
+ }
+
+ if (!active) {
+ System.arraycopy(points, 0, inactive, 0, index);
+ inactive_index += 2;
+ }
+
+ int rightIndex = circX - 1;
+ int startX = -1, endX = -1;
+ if (!onBottom) {
+ int[] ltt = drawCircle(leftIndex, circY, radius, LEFT_TOP);
+ startX = ltt[6];
+ for (int i = 0; i < ltt.length / 2; i += 2) {
+ int tmp = ltt[i];
+ ltt[i] = ltt[ltt.length - i - 2];
+ ltt[ltt.length - i - 2] = tmp;
+ tmp = ltt[i + 1];
+ ltt[i + 1] = ltt[ltt.length - i - 1];
+ ltt[ltt.length - i - 1] = tmp;
+ }
+ System.arraycopy(ltt, 0, points, index, ltt.length);
+ index += ltt.length;
+
+ if (!active) {
+ System.arraycopy(ltt, 0, inactive, inactive_index, 2);
+ inactive_index += 2;
+ }
+
+ int[] rt = drawCircle(rightIndex + width - (radius * 2), circY,
+ radius, RIGHT_TOP);
+ endX = rt[rt.length - 4];
+ for (int i = 0; i < rt.length / 2; i += 2) {
+ int tmp = rt[i];
+ rt[i] = rt[rt.length - i - 2];
+ rt[rt.length - i - 2] = tmp;
+ tmp = rt[i + 1];
+ rt[i + 1] = rt[rt.length - i - 1];
+ rt[rt.length - i - 1] = tmp;
+ }
+ System.arraycopy(rt, 0, points, index, rt.length);
+ index += rt.length;
+ if (!active) {
+ System.arraycopy(rt, rt.length - 4, inactive,
+ inactive_index, 2);
+ inactive[inactive_index] -= 1;
+ inactive_index += 2;
+ }
+ } else {
+ int[] ltt = drawCircle(leftIndex, circY, radius, LEFT_BOTTOM);
+ startX = ltt[6];
+ System.arraycopy(ltt, 0, points, index, ltt.length);
+ index += ltt.length;
+
+ if (!active) {
+ System.arraycopy(ltt, 0, inactive, inactive_index, 2);
+ inactive_index += 2;
+ }
+
+ int[] rt = drawCircle(rightIndex + width - (radius * 2), circY,
+ radius, RIGHT_BOTTOM);
+ endX = rt[rt.length - 4];
+ System.arraycopy(rt, 0, points, index, rt.length);
+ index += rt.length;
+ if (!active) {
+ System.arraycopy(rt, rt.length - 4, inactive,
+ inactive_index, 2);
+ inactive[inactive_index] -= 1;
+ inactive_index += 2;
+ }
+
+ }
+
+ points[index++] = bounds.width + rightIndex - radius;
+ points[index++] = bottomY;
+
+ if (!active) {
+ System.arraycopy(points, index - 2, inactive, inactive_index,
+ 2);
+ inactive[inactive_index] -= 1;
+ inactive_index += 2;
+ }
+
+ gc.setClipping(points[0],
+ onBottom ? bounds.y - header : bounds.y - 1,
+ parent.getSize().x - (shadowEnabled ? SIDE_DROP_WIDTH
+ : 0 + INNER_KEYLINE + OUTER_KEYLINE),
+ bounds.y + bounds.height);
+
+ if (hoverTabColors == null) {
+ hoverTabColors = new Color[] {
+ gc.getDevice().getSystemColor(SWT.COLOR_WHITE) };
+ hoverTabPercents = new int[] { 100 };
+ }
+
+ gc.setBackground(hoverTabColors[0]);
+ int[] tmpPoints = new int[index];
+ System.arraycopy(points, 0, tmpPoints, 0, index);
+ gc.fillPolygon(tmpPoints);
+ Color tempBorder = new Color(gc.getDevice(), 182, 188, 204);
+ gc.setForeground(tempBorder);
+ tempBorder.dispose();
+
+ if (hoverBorderVisible) {
+ if (outerBorderVisible) {
+ if (outerKeyline == null)
+ outerKeyline = gc.getDevice()
+ .getSystemColor(SWT.COLOR_BLACK);
+ gc.setForeground(outerKeyline);
+ if (active) {
+ gc.drawLine(startX, 1, endX, 1);
+ } else {
+ gc.drawLine(inactive[0], inactive[1], inactive[2],
+ inactive[3]);
+ gc.drawLine(inactive[4], inactive[5], inactive[6],
+ inactive[7]);
+ }
+ }
+
+ if (innerBorderVisible) {
+ if (innerKeyline == null)
+ innerKeyline = gc.getDevice()
+ .getSystemColor(SWT.COLOR_BLACK);
+ gc.setForeground(innerKeyline);
+ gc.drawPolyline(tmpPoints);
+ }
+ }
+
+ Rectangle rect = null;
+ gc.setClipping(rect);
+
+ // gc.setForeground(outerKeyline);
+ // gc.drawPolyline(shape);
+ }
+ }
+
+ static int[] drawCircle(int xC, int yC, int r, int circlePart) {
+ int x = 0, y = r, u = 1, v = 2 * r - 1, e = 0;
+ int[] points = new int[1024];
+ int[] pointsMirror = new int[1024];
+ int loop = 0;
+ int loopMirror = 0;
+ if (r == 0) {
+ for (int i = 0; i < 4; i++) {
+ points[loop++] = xC;
+ points[loop++] = yC;
+ }
+ }
+ while (x < y) {
+ if (circlePart == RIGHT_BOTTOM) {
+ points[loop++] = xC + x;
+ points[loop++] = yC + y;
+ }
+ if (circlePart == RIGHT_TOP) {
+ points[loop++] = xC + y;
+ points[loop++] = yC - x;
+ }
+ if (circlePart == LEFT_TOP) {
+ points[loop++] = xC - x;
+ points[loop++] = yC - y;
+ }
+ if (circlePart == LEFT_BOTTOM) {
+ points[loop++] = xC - y;
+ points[loop++] = yC + x;
+ }
+ x++;
+ e += u;
+ u += 2;
+ if (v < 2 * e) {
+ y--;
+ e -= v;
+ v -= 2;
+ }
+ if (x > y)
+ break;
+ if (circlePart == RIGHT_BOTTOM) {
+ pointsMirror[loopMirror++] = xC + y;
+ pointsMirror[loopMirror++] = yC + x;
+ }
+ if (circlePart == RIGHT_TOP) {
+ pointsMirror[loopMirror++] = xC + x;
+ pointsMirror[loopMirror++] = yC - y;
+ }
+ if (circlePart == LEFT_TOP) {
+ pointsMirror[loopMirror++] = xC - y;
+ pointsMirror[loopMirror++] = yC - x;
+ }
+ if (circlePart == LEFT_BOTTOM) {
+ pointsMirror[loopMirror++] = xC - x;
+ pointsMirror[loopMirror++] = yC + y;
+ }
+ // grow?
+ if ((loop + 1) > points.length) {
+ int length = points.length * 2;
+ int[] newPointTable = new int[length];
+ int[] newPointTableMirror = new int[length];
+ System.arraycopy(points, 0, newPointTable, 0, points.length);
+ points = newPointTable;
+ System.arraycopy(pointsMirror, 0, newPointTableMirror, 0,
+ pointsMirror.length);
+ pointsMirror = newPointTableMirror;
+ }
+ }
+ int[] finalArray = new int[loop + loopMirror];
+ System.arraycopy(points, 0, finalArray, 0, loop);
+ for (int i = loopMirror - 1, j = loop; i > 0; i = i - 2, j = j + 2) {
+ int tempY = pointsMirror[i];
+ int tempX = pointsMirror[i - 1];
+ finalArray[j] = tempX;
+ finalArray[j + 1] = tempY;
+ }
+ return finalArray;
+ }
+
+ static RGB blend(RGB c1, RGB c2, int ratio) {
+ int r = blend(c1.red, c2.red, ratio);
+ int g = blend(c1.green, c2.green, ratio);
+ int b = blend(c1.blue, c2.blue, ratio);
+ return new RGB(r, g, b);
+ }
+
+ static int blend(int v1, int v2, int ratio) {
+ int b = (ratio * v1 + (100 - ratio) * v2) / 100;
+ return Math.min(255, b);
+ }
+
+ void drawShadow(final Display display, Rectangle bounds, GC gc) {
+ if (shadowImage == null) {
+ createShadow(display);
+ }
+ int x = bounds.x;
+ int y = bounds.y;
+ int SIZE = shadowImage.getBounds().width / 3;
+
+ int height = Math.max(bounds.height, SIZE * 2);
+ int width = Math.max(bounds.width, SIZE * 2);
+ // top left
+ gc.drawImage(shadowImage, 0, 0, SIZE, SIZE, 2, 10, SIZE, 20);
+ int fillHeight = height - SIZE * 2;
+ int fillWidth = width + 5 - SIZE * 2;
+
+ int xFill = 0;
+ for (int i = SIZE; i < fillHeight; i += SIZE) {
+ xFill = i;
+ gc.drawImage(shadowImage, 0, SIZE, SIZE, SIZE, 2, i, SIZE, SIZE);
+ }
+
+ // Pad the rest of the shadow
+ gc.drawImage(shadowImage, 0, SIZE, SIZE, fillHeight - xFill, 2,
+ xFill + SIZE, SIZE, fillHeight - xFill);
+
+ // bl
+ gc.drawImage(shadowImage, 0, 40, 20, 20, 2, y + height - SIZE, 20, 20);
+
+ int yFill = 0;
+ for (int i = SIZE; i <= fillWidth; i += SIZE) {
+ yFill = i;
+ gc.drawImage(shadowImage, SIZE, SIZE * 2, SIZE, SIZE, i,
+ y + height - SIZE, SIZE, SIZE);
+ }
+ // Pad the rest of the shadow
+ gc.drawImage(shadowImage, SIZE, SIZE * 2, fillWidth - yFill, SIZE,
+ yFill + SIZE, y + height - SIZE, fillWidth - yFill, SIZE);
+
+ // br
+ gc.drawImage(shadowImage, SIZE * 2, SIZE * 2, SIZE, SIZE,
+ x + width - SIZE - 1, y + height - SIZE, SIZE, SIZE);
+
+ // tr
+ gc.drawImage(shadowImage, (SIZE * 2), 0, SIZE, SIZE,
+ x + width - SIZE - 1, 10, SIZE, SIZE);
+
+ xFill = 0;
+ for (int i = SIZE; i < fillHeight; i += SIZE) {
+ xFill = i;
+ gc.drawImage(shadowImage, SIZE * 2, SIZE, SIZE, SIZE,
+ x + width - SIZE - 1, i, SIZE, SIZE);
+ }
+
+ // Pad the rest of the shadow
+ gc.drawImage(shadowImage, SIZE * 2, SIZE, SIZE, fillHeight - xFill,
+ x + width - SIZE - 1, xFill + SIZE, SIZE, fillHeight - xFill);
+ }
+
+ void createShadow(final Display display) {
+ if (shadowImage != null) {
+ shadowImage.dispose();
+ shadowImage = null;
+ }
+ ImageData data = new ImageData(60, 60, 32,
+ new PaletteData(0xFF0000, 0xFF00, 0xFF));
+ Image tmpImage = shadowImage = new Image(display, data);
+ GC gc = new GC(tmpImage);
+ if (shadowColor == null)
+ shadowColor = gc.getDevice().getSystemColor(SWT.COLOR_GRAY);
+ gc.setBackground(shadowColor);
+ drawTabBody(gc, new Rectangle(0, 0, 60, 60), SWT.None);
+ ImageData blured = blur(tmpImage, 5, 25);
+ shadowImage = new Image(display, blured);
+ tmpImage.dispose();
+ gc.dispose();
+ }
+
+ public ImageData blur(Image src, int radius, int sigma) {
+ float[] kernel = create1DKernel(radius, sigma);
+
+ ImageData imgPixels = src.getImageData();
+ int width = imgPixels.width;
+ int height = imgPixels.height;
+
+ int[] inPixels = new int[width * height];
+ int[] outPixels = new int[width * height];
+ int offset = 0;
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ RGB rgb = imgPixels.palette.getRGB(imgPixels.getPixel(x, y));
+ if (rgb.red == 255 && rgb.green == 255 && rgb.blue == 255) {
+ inPixels[offset] = (rgb.red << 16) | (rgb.green << 8)
+ | rgb.blue;
+ } else {
+ inPixels[offset] = (imgPixels.getAlpha(x, y) << 24)
+ | (rgb.red << 16) | (rgb.green << 8) | rgb.blue;
+ }
+ offset++;
+ }
+ }
+
+ convolve(kernel, inPixels, outPixels, width, height, true);
+ convolve(kernel, outPixels, inPixels, height, width, true);
+
+ ImageData dst = new ImageData(imgPixels.width, imgPixels.height, 24,
+ new PaletteData(0xff0000, 0xff00, 0xff));
+
+ dst.setPixels(0, 0, inPixels.length, inPixels, 0);
+ offset = 0;
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ if (inPixels[offset] == -1) {
+ dst.setAlpha(x, y, 0);
+ } else {
+ int a = (inPixels[offset] >> 24) & 0xff;
+ // if (a < 150) a = 0;
+ dst.setAlpha(x, y, a);
+ }
+ offset++;
+ }
+ }
+ return dst;
+ }
+
+ private void convolve(float[] kernel, int[] inPixels, int[] outPixels,
+ int width, int height, boolean alpha) {
+ int kernelWidth = kernel.length;
+ int kernelMid = kernelWidth / 2;
+ for (int y = 0; y < height; y++) {
+ int index = y;
+ int currentLine = y * width;
+ for (int x = 0; x < width; x++) {
+ // do point
+ float a = 0, r = 0, g = 0, b = 0;
+ for (int k = -kernelMid; k <= kernelMid; k++) {
+ float val = kernel[k + kernelMid];
+ int xcoord = x + k;
+ if (xcoord < 0)
+ xcoord = 0;
+ if (xcoord >= width)
+ xcoord = width - 1;
+ int pixel = inPixels[currentLine + xcoord];
+ // float alp = ((pixel >> 24) & 0xff);
+ a += val * ((pixel >> 24) & 0xff);
+ r += val * (((pixel >> 16) & 0xff));
+ g += val * (((pixel >> 8) & 0xff));
+ b += val * (((pixel) & 0xff));
+ }
+ int ia = alpha ? clamp((int) (a + 0.5)) : 0xff;
+ int ir = clamp((int) (r + 0.5));
+ int ig = clamp((int) (g + 0.5));
+ int ib = clamp((int) (b + 0.5));
+ outPixels[index] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
+ index += height;
+ }
+ }
+
+ }
+
+ private int clamp(int value) {
+ if (value > 255)
+ return 255;
+ if (value < 0)
+ return 0;
+ return value;
+ }
+
+ private float[] create1DKernel(int radius, int sigma) {
+ // guideline: 3*sigma should be the radius
+ int size = radius * 2 + 1;
+ float[] kernel = new float[size];
+ int radiusSquare = radius * radius;
+ float sigmaSquare = 2 * sigma * sigma;
+ float piSigma = 2 * (float) Math.PI * sigma;
+ float sqrtSigmaPi2 = (float) Math.sqrt(piSigma);
+ int start = size / 2;
+ int index = 0;
+ float total = 0;
+ for (int i = -start; i <= start; i++) {
+ float d = i * i;
+ if (d > radiusSquare) {
+ kernel[index] = 0;
+ } else {
+ kernel[index] = (float) Math.exp(-(d) / sigmaSquare)
+ / sqrtSigmaPi2;
+ }
+ total += kernel[index];
+ index++;
+ }
+ for (int i = 0; i < size; i++) {
+ kernel[i] /= total;
+ }
+ return kernel;
+ }
+
+ public Rectangle getPadding() {
+ return new Rectangle(paddingTop, paddingRight, paddingBottom,
+ paddingLeft);
+ }
+
+ public void setPadding(int paddingLeft, int paddingRight, int paddingTop,
+ int paddingBottom) {
+ this.paddingLeft = paddingLeft;
+ this.paddingRight = paddingRight;
+ this.paddingTop = paddingTop;
+ this.paddingBottom = paddingBottom;
+ parent.redraw();
+ }
+
+ public void setCornerRadius(int radius) {
+ cornerSize = radius;
+ parent.redraw();
+ }
+
+ public void setShadowVisible(boolean visible) {
+ this.shadowEnabled = visible;
+ parent.redraw();
+ }
+
+ public void setShadowColor(Color color) {
+ this.shadowColor = color;
+ createShadow(parent.getDisplay());
+ parent.redraw();
+ }
+
+ public void setOuterKeyline(Color color) {
+ this.outerKeyline = color;
+ // TODO: HACK! Should be set based on pseudo-state.
+ if (color != null) {
+ setActive(!(color.getRed() == 255 && color.getGreen() == 255
+ && color.getBlue() == 255));
+ }
+ parent.redraw();
+ }
+
+ public void setSelectedTabFill(Color color) {
+ setSelectedTabFill(new Color[] { color }, new int[] { 100 });
+ }
+
+ public void setSelectedTabFill(Color[] colors, int[] percents) {
+ selectedTabFillColors = colors;
+ selectedTabFillPercents = percents;
+ parent.redraw();
+ }
+
+ public void setSelectedTabAreaColor(Color color) {
+ setSelectedTabAreaColor(new Color[] { color }, new int[] { 100 });
+ }
+
+ public void setSelectedTabAreaColor(Color[] colors, int[] percents) {
+ selectedTabAreaColors = colors;
+ selectedTabAreaPercents = percents;
+ parent.redraw();
+ }
+
+ public void setUnselectedTabsColor(Color color) {
+ setUnselectedTabsColor(new Color[] { color }, new int[] { 100 });
+ }
+
+ public void setUnselectedTabsColor(Color[] colors, int[] percents) {
+ unselectedTabsColors = colors;
+ unselectedTabsPercents = percents;
+
+ parent.redraw();
+ }
+
+ public void setUnselectedTabsBackgroundVisible(boolean visible) {
+ unselectedTabsBackgroundVisible = visible;
+ parent.redraw();
+ }
+
+ public void setUnselectedHotTabsColorBackground(Color color) {
+ setHoverTabColor(new Color[] { color }, new int[] { 100 });
+ }
+
+ public void setHoverTabColor(Color color) {
+ setHoverTabColor(new Color[] { color }, new int[] { 100 });
+
+ }
+
+ public void setHoverTabColor(Color[] colors, int[] percents) {
+ hoverTabColors = colors;
+ hoverTabPercents = percents;
+ parent.redraw();
+ }
+
+ public void setTabOutline(Color color) {
+ this.tabOutlineColor = color;
+ parent.redraw();
+ }
+
+ public void setInnerKeyline(Color color) {
+ this.innerKeyline = color;
+ parent.redraw();
+ }
+
+ public void setTextVisible(boolean visible) {
+ this.textVisible = visible;
+ parent.redraw();
+ }
+
+ public void setImageVisible(boolean visible) {
+ this.imageVisible = visible;
+ parent.redraw();
+ }
+
+ public void setOuterBorderVisible(boolean visible) {
+ this.outerBorderVisible = visible;
+ parent.redraw();
+ }
+
+ public void setInnerBorderVisible(boolean visible) {
+ this.innerBorderVisible = visible;
+ parent.redraw();
+ }
+
+ public void setActiveToolbarGradient(Color[] color, int[] percents) {
+ activeToolbar = color;
+ activePercents = percents;
+ }
+
+ public void setInactiveToolbarGradient(Color[] color, int[] percents) {
+ inactiveToolbar = color;
+ inactivePercents = percents;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public void setMaximizeImage(Image maxImage) {
+ this.maxImage = maxImage;
+ }
+
+ public void setMinimizeImage(Image minImage) {
+ this.minImage = minImage;
+ }
+
+ public void setCloseImage(Image closeImage) {
+ this.closeImage = closeImage;
+ }
+
+ public void setClsoeHoverImage(Image closeHoverImage) {
+ this.closeHoverImage = closeHoverImage;
+ }
+
+ public void setNoneRender(boolean nothingToRender) {
+ this.nothingToRender = nothingToRender;
+ }
+
+ private void drawCustomBackground(GC gc, Rectangle bounds, int state) {
+ boolean selected = (state & SWT.SELECTED) != 0;
+ Color defaultBackground = selected ? parent.getSelectionBackground()
+ : parent.getBackground();
+ boolean vertical = selected
+ ? parentWrapper.isSelectionGradientVertical()
+ : parentWrapper.isGradientVertical();
+ Rectangle partHeaderBounds = bounds;
+
+ if (unselectedTabsBackgroundVisible) {
+ drawUnselectedTabBackground(gc, partHeaderBounds, state, vertical,
+ defaultBackground);
+ }
+ drawTabAreaBackground(gc, partHeaderBounds, state, vertical,
+ defaultBackground);
+
+ int borderTop = isTabOnBottom() ? INNER_KEYLINE + OUTER_KEYLINE
+ : TOP_KEYLINE + OUTER_KEYLINE;
+ int borderBottom = isTabOnBottom() ? TOP_KEYLINE + OUTER_KEYLINE
+ : INNER_KEYLINE + OUTER_KEYLINE;
+ int bottomDropWidth = shadowEnabled ? BOTTOM_DROP_WIDTH : 0;
+ int sideDropWidth = shadowEnabled ? SIDE_DROP_WIDTH : 0;
+ int headerBorderBottom = outerBorderVisible ? OUTER_KEYLINE : 0;
+ Rectangle underTabAreaBounds = new Rectangle(
+ partHeaderBounds.x + paddingLeft + sideDropWidth,
+ partHeaderBounds.y + partHeaderBounds.height + bottomDropWidth
+ + paddingTop + headerBorderBottom,
+ bounds.width - paddingLeft - paddingRight - 2 * sideDropWidth,
+ parent.getBounds().height - partHeaderBounds.height - paddingTop
+ - paddingBottom - headerBorderBottom
+ - ((cornerSize / 4) + borderBottom + borderTop)
+ - bottomDropWidth * 2);
+ drawUnderTabAreaBackground(gc, underTabAreaBounds, state, vertical,
+ defaultBackground);
+ drawChildrenBackground(partHeaderBounds);
+ }
+
+ private void drawUnderTabAreaBackground(GC gc, Rectangle tabAreaBounds,
+ int state, boolean vertical, Color defaultBackground) {
+ Color[] underTabAreaColors = new Color[] {
+ gc.getDevice().getSystemColor(SWT.COLOR_WHITE) };
+ int[] underTabAreaPercents = new int[] { 100 };
+ rendererWrapper.drawBackground(gc, tabAreaBounds.x, tabAreaBounds.y,
+ tabAreaBounds.width, tabAreaBounds.height, defaultBackground,
+ underTabAreaColors, underTabAreaPercents, vertical);
+ }
+
+ private void drawUnselectedTabBackground(GC gc, Rectangle partHeaderBounds,
+ int state, boolean vertical, Color defaultBackground) {
+ if (unselectedTabsColors == null) {
+ boolean selected = (state & SWT.SELECTED) != 0;
+ unselectedTabsColors = selected
+ ? parentWrapper.getSelectionGradientColors()
+ : parentWrapper.getGradientColors();
+ unselectedTabsPercents = selected
+ ? parentWrapper.getSelectionGradientPercents()
+ : parentWrapper.getGradientPercents();
+ }
+ if (unselectedTabsColors == null) {
+ unselectedTabsColors = new Color[] {
+ gc.getDevice().getSystemColor(SWT.COLOR_WHITE) };
+ unselectedTabsPercents = new int[] { 100 };
+ }
+
+ rendererWrapper.drawBackground(gc, partHeaderBounds.x,
+ partHeaderBounds.y, partHeaderBounds.width,
+ partHeaderBounds.height, defaultBackground,
+ unselectedTabsColors, unselectedTabsPercents, vertical);
+ }
+
+ private void drawTabAreaBackground(GC gc, Rectangle partHeaderBounds,
+ int state, boolean vertical, Color defaultBackground) {
+ Color[] colors = selectedTabAreaColors;
+ int[] percents = selectedTabAreaPercents;
+
+ if (colors != null && colors.length == 2) {
+ colors = new Color[] { colors[1], colors[1] };
+ }
+ if (colors == null) {
+ boolean selected = (state & SWT.SELECTED) != 0;
+ colors = selected ? parentWrapper.getSelectionGradientColors()
+ : parentWrapper.getGradientColors();
+ percents = selected ? parentWrapper.getSelectionGradientPercents()
+ : parentWrapper.getGradientPercents();
+ }
+ if (colors == null) {
+ colors = new Color[] {
+ gc.getDevice().getSystemColor(SWT.COLOR_WHITE) };
+ percents = new int[] { 100 };
+ }
+
+ rendererWrapper.drawBackground(gc, partHeaderBounds.x,
+ partHeaderBounds.y + partHeaderBounds.height,
+ partHeaderBounds.width, parent.getBounds().height,
+ defaultBackground, colors, percents, vertical);
+ }
+
+ // Workaround for the bug 433276. Remove it when the bug gets fixed
+ private void drawChildrenBackground(Rectangle partHeaderBounds) {
+ for (Control control : parent.getChildren()) {
+ if (!CompositeElement.hasBackgroundOverriddenByCSS(control)
+ && containsToolbar(control)) {
+ drawChildBackground((Composite) control, partHeaderBounds);
+ }
+ }
+ }
+
+ private boolean containsToolbar(Control control) {
+ if (control.getData(CONTAINS_TOOLBAR) != null) {
+ return true;
+ }
+
+ if (control instanceof ToolBar) {
+ control.setData(CONTAINS_TOOLBAR, true);
+ return true;
+ }
+
+ if (control instanceof Composite) {
+ for (Control child : ((Composite) control).getChildren()) {
+ if (child instanceof ToolBar) {
+ control.setData(CONTAINS_TOOLBAR, true);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void drawChildBackground(Composite composite,
+ Rectangle partHeaderBounds) {
+ Rectangle rec = composite.getBounds();
+ Color background = null;
+ boolean partOfHeader = rec.y >= partHeaderBounds.y
+ && rec.y < partHeaderBounds.height;
+
+ if (!partOfHeader) {
+ background = composite.getDisplay().getSystemColor(SWT.COLOR_WHITE);
+ }
+ CTabFolderElement.setBackgroundOverriddenDuringRenderering(composite,
+ background);
+ }
+
+ private static class CTabFolderRendererWrapper
+ extends ReflectionSupport {
+ private Method drawBackgroundMethod;
+
+ private Method drawCloseMethod;
+
+ public CTabFolderRendererWrapper(CTabFolderRenderer instance) {
+ super(instance);
+ }
+
+ public void drawBackground(GC gc, int x, int y, int width, int height,
+ Color defaultBackground, Color[] colors, int[] percents,
+ boolean vertical) {
+ if (drawBackgroundMethod == null) {
+ drawBackgroundMethod = getMethod("drawBackground", //$NON-NLS-1$
+ new Class>[] { GC.class, int[].class, int.class,
+ int.class, int.class, int.class, Color.class,
+ Image.class, Color[].class, int[].class,
+ boolean.class });
+ }
+ executeMethod(drawBackgroundMethod,
+ new Object[] { gc, null, x, y, width, height,
+ defaultBackground, null, colors, percents,
+ vertical });
+ }
+
+ public void drawClose(GC gc, Rectangle closeRect, int closeImageState) {
+ if (drawCloseMethod == null) {
+ drawCloseMethod = getMethod("drawClose", new Class>[] { //$NON-NLS-1$
+ GC.class, Rectangle.class, int.class });
+ }
+ executeMethod(drawCloseMethod,
+ new Object[] { gc, closeRect, closeImageState });
+ }
+ }
+
+ private static class CTabItemWrapper extends ReflectionSupport {
+
+ private Field shortenedTextField;
+
+ private Field shortenedTextWidthField;
+
+ private Field closeRectField;
+
+ private Field closeImageStateField;
+
+ public CTabItemWrapper(CTabItem instance) {
+ super(instance);
+ }
+
+ public String getShortenedText() {
+ if (shortenedTextField == null) {
+ shortenedTextField = getField("shortenedText"); //$NON-NLS-1$
+ }
+ return (String) getFieldValue(shortenedTextField);
+ }
+
+ public void setShortenedText(String value) {
+ set("shortenedText", value); //$NON-NLS-1$
+ }
+
+ public Integer getShortenedTextWidth() {
+ if (shortenedTextWidthField == null) {
+ shortenedTextWidthField = getField("shortenedTextWidth"); //$NON-NLS-1$
+ }
+ return (Integer) getFieldValue(shortenedTextWidthField);
+ }
+
+ public void setShortenedTextWidth(int value) {
+ set("shortenedTextWidth", value); //$NON-NLS-1$
+ }
+
+ public Rectangle getCloseRect() {
+ if (closeRectField == null) {
+ closeRectField = getField("closeRect"); //$NON-NLS-1$
+ }
+ return (Rectangle) getFieldValue(closeRectField);
+ }
+
+ public int getCloseImageState() {
+ if (closeImageStateField == null) {
+ closeImageStateField = getField("closeImageState"); //$NON-NLS-1$
+ }
+ return (Integer) getFieldValue(closeImageStateField);
+ }
+
+ }
+
+ private static class CTabFolderWrapper
+ extends ReflectionSupport {
+ private Field selectionGradientVerticalField;
+
+ private Field gradientVerticalField;
+
+ private Field selectionGradientColorsField;
+
+ private Field selectionGradientPercentsField;
+
+ private Field gradientColorsField;
+
+ private Field gradientPercentsField;
+
+ private Field showCloseField;
+
+ private Field fixedTabHeightField;
+
+ private Method getRightItemEdgeMethod;
+
+ public CTabFolderWrapper(CTabFolder instance) {
+ super(instance);
+ }
+
+ public boolean isShowClose() {
+ if (showCloseField == null) {
+ showCloseField = getField("showClose"); //$NON-NLS-1$
+ }
+ Boolean result = (Boolean) getFieldValue(showCloseField);
+ return result != null ? result : true;
+ }
+
+ public boolean isSelectionGradientVertical() {
+ if (selectionGradientVerticalField == null) {
+ selectionGradientVerticalField = getField(
+ "selectionGradientVertical"); //$NON-NLS-1$
+ }
+ Boolean result = (Boolean) getFieldValue(
+ selectionGradientVerticalField);
+ return result != null ? result : true;
+ }
+
+ public boolean isGradientVertical() {
+ if (gradientVerticalField == null) {
+ gradientVerticalField = getField("gradientVertical"); //$NON-NLS-1$
+ }
+ Boolean result = (Boolean) getFieldValue(gradientVerticalField);
+ return result != null ? result : true;
+ }
+
+ public Color[] getSelectionGradientColors() {
+ if (selectionGradientColorsField == null) {
+ selectionGradientColorsField = getField(
+ "selectionGradientColorsField"); //$NON-NLS-1$
+ }
+ return (Color[]) getFieldValue(selectionGradientColorsField);
+ }
+
+ public int[] getSelectionGradientPercents() {
+ if (selectionGradientPercentsField == null) {
+ selectionGradientPercentsField = getField(
+ "selectionGradientPercents"); //$NON-NLS-1$
+ }
+ return (int[]) getFieldValue(selectionGradientPercentsField);
+ }
+
+ public Color[] getGradientColors() {
+ if (gradientColorsField == null) {
+ gradientColorsField = getField("gradientColors"); //$NON-NLS-1$
+ }
+ return (Color[]) getFieldValue(gradientColorsField);
+ }
+
+ public int[] getGradientPercents() {
+ if (gradientPercentsField == null) {
+ gradientPercentsField = getField("gradientPercents"); //$NON-NLS-1$
+ }
+ return (int[]) getFieldValue(gradientPercentsField);
+ }
+
+ public int getRightItemEdge(GC gc) {
+ if (getRightItemEdgeMethod == null) {
+ getRightItemEdgeMethod = getMethod("getRightItemEdge", //$NON-NLS-1$
+ new Class>[] { GC.class });
+ }
+ return (Integer) executeMethod(getRightItemEdgeMethod,
+ new Object[] { gc });
+ }
+
+ public int getFixedTabHeight() {
+ if (fixedTabHeightField == null) {
+ fixedTabHeightField = getField("fixedTabHeight"); //$NON-NLS-1$
+ }
+ return (Integer) getFieldValue(fixedTabHeightField);
+ }
+ }
+
+ private static class ReflectionSupport {
+ private T instance;
+
+ public ReflectionSupport(T instance) {
+ this.instance = instance;
+ }
+
+ protected Object getFieldValue(Field field) {
+ Object value = null;
+ if (field != null) {
+ boolean accessible = field.isAccessible();
+ try {
+ field.setAccessible(true);
+ value = field.get(instance);
+ } catch (Exception exc) {
+ // do nothing
+ } finally {
+ field.setAccessible(accessible);
+ }
+ }
+ return value;
+ }
+
+ protected Field getField(String name) {
+ Class> cls = instance.getClass();
+ while (!cls.equals(Object.class)) {
+ try {
+ return cls.getDeclaredField(name);
+ } catch (Exception exc) {
+ cls = cls.getSuperclass();
+ }
+ }
+ return null;
+ }
+
+ public Object set(String name, Object value) {
+ try {
+ Field field = getField(name);
+ boolean accessible = field.isAccessible();
+ field.setAccessible(true);
+ field.set(instance, value);
+ field.setAccessible(accessible);
+ return value;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected Object executeMethod(Method method, Object... params) {
+ Object value = null;
+ if (method != null) {
+ boolean accessible = method.isAccessible();
+ try {
+ method.setAccessible(true);
+ value = method.invoke(instance, params);
+ } catch (Exception exc) {
+ // do nothing
+ } finally {
+ method.setAccessible(accessible);
+ }
+ }
+ return value;
+ }
+
+ protected Method getMethod(String name, Class>... params) {
+ Class> cls = instance.getClass();
+ while (!cls.equals(Object.class)) {
+ try {
+ return cls.getDeclaredMethod(name, params);
+ } catch (Exception exc) {
+ cls = cls.getSuperclass();
+ }
+ }
+ return null;
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/FormHeadingElement.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/FormHeadingElement.java
index 84bfbc60d..e11061043 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/FormHeadingElement.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/FormHeadingElement.java
@@ -1,14 +1,14 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
-import org.eclipse.ui.internal.forms.widgets.FormHeading;
-
-@SuppressWarnings("restriction")
-public class FormHeadingElement extends CompositeElement {
-
- public FormHeadingElement(FormHeading formHeading, CSSEngine engine) {
- super(formHeading, engine);
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.eclipse.ui.internal.forms.widgets.FormHeading;
+
+@SuppressWarnings("restriction")
+public class FormHeadingElement extends CompositeElement {
+
+ public FormHeadingElement(FormHeading formHeading, CSSEngine engine) {
+ super(formHeading, engine);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/FormTextElement.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/FormTextElement.java
index 44fe47159..c98c1a5d0 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/FormTextElement.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/FormTextElement.java
@@ -1,14 +1,14 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
-import org.eclipse.ui.forms.widgets.FormText;
-
-@SuppressWarnings("restriction")
-public class FormTextElement extends CompositeElement {
-
- public FormTextElement(FormText formText, CSSEngine engine) {
- super(formText, engine);
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.eclipse.ui.forms.widgets.FormText;
+
+@SuppressWarnings("restriction")
+public class FormTextElement extends CompositeElement {
+
+ public FormTextElement(FormText formText, CSSEngine engine) {
+ super(formText, engine);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ICTabFolderRendering.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ICTabFolderRendering.java
index 899dbedef..bcdb9bb24 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ICTabFolderRendering.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ICTabFolderRendering.java
@@ -1,38 +1,38 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.internal.css.swt.ICTabRendering;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-
-@SuppressWarnings("restriction")
-public interface ICTabFolderRendering extends ICTabRendering {
-
- void setTextVisible(boolean visible);
-
- void setImageVisible(boolean visible);
-
- void setOuterBorderVisible(boolean visible);
-
- void setInnerBorderVisible(boolean visible);
-
- void setHoverTabColor(Color color);
-
- void setHoverTabColor(Color[] colors, int[] percents);
-
- void setSelectedTabAreaColor(Color color);
-
- void setSelectedTabAreaColor(Color[] colors, int[] percents);
-
- void setUnselectedTabsBackgroundVisible(boolean visible);
-
- void setMaximizeImage(Image maxImage);
-
- void setMinimizeImage(Image minImage);
-
- void setCloseImage(Image closeImage);
-
- void setClsoeHoverImage(Image closeHoverImage);
-
- void setNoneRender(boolean nothingToRender);
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.internal.css.swt.ICTabRendering;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+
+@SuppressWarnings("restriction")
+public interface ICTabFolderRendering extends ICTabRendering {
+
+ void setTextVisible(boolean visible);
+
+ void setImageVisible(boolean visible);
+
+ void setOuterBorderVisible(boolean visible);
+
+ void setInnerBorderVisible(boolean visible);
+
+ void setHoverTabColor(Color color);
+
+ void setHoverTabColor(Color[] colors, int[] percents);
+
+ void setSelectedTabAreaColor(Color color);
+
+ void setSelectedTabAreaColor(Color[] colors, int[] percents);
+
+ void setUnselectedTabsBackgroundVisible(boolean visible);
+
+ void setMaximizeImage(Image maxImage);
+
+ void setMinimizeImage(Image minImage);
+
+ void setCloseImage(Image closeImage);
+
+ void setClsoeHoverImage(Image closeHoverImage);
+
+ void setNoneRender(boolean nothingToRender);
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/MTabBarElement.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/MTabBarElement.java
index 538d43741..f49e31ef0 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/MTabBarElement.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/MTabBarElement.java
@@ -1,14 +1,14 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
-import org.xmind.ui.tabfolder.MTabBar;
-
-@SuppressWarnings("restriction")
-public class MTabBarElement extends CompositeElement {
-
- public MTabBarElement(MTabBar tabBar, CSSEngine engine) {
- super(tabBar, engine);
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.xmind.ui.tabfolder.MTabBar;
+
+@SuppressWarnings("restriction")
+public class MTabBarElement extends CompositeElement {
+
+ public MTabBarElement(MTabBar tabBar, CSSEngine engine) {
+ super(tabBar, engine);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/MTabFolderElement.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/MTabFolderElement.java
index 53a5eb252..7ce8f29be 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/MTabFolderElement.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/MTabFolderElement.java
@@ -1,14 +1,14 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
-import org.xmind.ui.tabfolder.MTabFolder;
-
-@SuppressWarnings("restriction")
-public class MTabFolderElement extends CompositeElement {
-
- public MTabFolderElement(MTabFolder tabFolder, CSSEngine engine) {
- super(tabFolder, engine);
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.xmind.ui.tabfolder.MTabFolder;
+
+@SuppressWarnings("restriction")
+public class MTabFolderElement extends CompositeElement {
+
+ public MTabFolderElement(MTabFolder tabFolder, CSSEngine engine) {
+ super(tabFolder, engine);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ReflectionSupport.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ReflectionSupport.java
index d6ff43a35..1ae1133b7 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ReflectionSupport.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ReflectionSupport.java
@@ -1,86 +1,86 @@
-package org.xmind.cathy.internal.css;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-public class ReflectionSupport {
-
- private Class> type;
-
- public ReflectionSupport(Class type) {
- this.type = type;
- }
-
- public Object getFieldValue(Field field, T instance) {
- Object value = null;
- if (field != null) {
- boolean accessible = field.isAccessible();
- try {
- field.setAccessible(true);
- value = field.get(instance);
- } catch (Exception exc) {
- // do nothing
- } finally {
- field.setAccessible(accessible);
- }
- }
- return value;
- }
-
- public Object getFieldValue(String name, T instance) {
- Field field = getField(name);
- return getFieldValue(field, instance);
- }
-
- public Field getField(String name) {
- while (!type.equals(Object.class)) {
- try {
- return type.getDeclaredField(name);
- } catch (Exception exc) {
- type = type.getSuperclass();
- }
- }
- return null;
- }
-
- public Object set(Object obj, String name, Object value) {
- try {
- Field field = getField(name);
- boolean accessible = field.isAccessible();
- field.setAccessible(true);
- field.set(obj, value);
- field.setAccessible(accessible);
- return value;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public Object executeMethod(Method method, T instance, Object... params) {
- Object value = null;
- if (method != null) {
- boolean accessible = method.isAccessible();
- try {
- method.setAccessible(true);
- value = method.invoke(instance, params);
- } catch (Exception exc) {
- // do nothing
- } finally {
- method.setAccessible(accessible);
- }
- }
- return value;
- }
-
- public Method getMethod(String name, Class>... params) {
- while (!type.equals(Object.class)) {
- try {
- return type.getDeclaredMethod(name, params);
- } catch (Exception exc) {
- type = type.getSuperclass();
- }
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+public class ReflectionSupport {
+
+ private Class> type;
+
+ public ReflectionSupport(Class type) {
+ this.type = type;
+ }
+
+ public Object getFieldValue(Field field, T instance) {
+ Object value = null;
+ if (field != null) {
+ boolean accessible = field.isAccessible();
+ try {
+ field.setAccessible(true);
+ value = field.get(instance);
+ } catch (Exception exc) {
+ // do nothing
+ } finally {
+ field.setAccessible(accessible);
+ }
+ }
+ return value;
+ }
+
+ public Object getFieldValue(String name, T instance) {
+ Field field = getField(name);
+ return getFieldValue(field, instance);
+ }
+
+ public Field getField(String name) {
+ while (!type.equals(Object.class)) {
+ try {
+ return type.getDeclaredField(name);
+ } catch (Exception exc) {
+ type = type.getSuperclass();
+ }
+ }
+ return null;
+ }
+
+ public Object set(Object obj, String name, Object value) {
+ try {
+ Field field = getField(name);
+ boolean accessible = field.isAccessible();
+ field.setAccessible(true);
+ field.set(obj, value);
+ field.setAccessible(accessible);
+ return value;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Object executeMethod(Method method, T instance, Object... params) {
+ Object value = null;
+ if (method != null) {
+ boolean accessible = method.isAccessible();
+ try {
+ method.setAccessible(true);
+ value = method.invoke(instance, params);
+ } catch (Exception exc) {
+ // do nothing
+ } finally {
+ method.setAccessible(accessible);
+ }
+ }
+ return value;
+ }
+
+ public Method getMethod(String name, Class>... params) {
+ while (!type.equals(Object.class)) {
+ try {
+ return type.getDeclaredMethod(name, params);
+ } catch (Exception exc) {
+ type = type.getSuperclass();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/SashWidthHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/SashWidthHandler.java
index 35d666330..dda1ca53d 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/SashWidthHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/SashWidthHandler.java
@@ -1,71 +1,71 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
-import org.eclipse.e4.ui.workbench.renderers.swt.SashLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Layout;
-import org.w3c.dom.css.CSSPrimitiveValue;
-import org.w3c.dom.css.CSSValue;
-
-@SuppressWarnings("restriction")
-public class SashWidthHandler implements ICSSPropertyHandler {
-
- private static final String FIELD_SASH_WIDTH = "sashWidth"; //$NON-NLS-1$
-
- private ReflectionSupport sashLayout = new ReflectionSupport(
- SashLayout.class);
-
- public boolean applyCSSProperty(Object element, String property,
- CSSValue value, String pseudo, CSSEngine engine) throws Exception {
- if (!(element instanceof CompositeElement)) {
- return false;
- }
- CompositeElement compositeElement = (CompositeElement) element;
- Object nativeWidget = compositeElement.getNativeWidget();
- if (!(nativeWidget instanceof Composite)) {
- return false;
- }
-
- Composite composite = (Composite) nativeWidget;
- Layout layout = composite.getLayout();
- if (!(layout instanceof SashLayout)) {
- return false;
- }
-
- if (!(value instanceof CSSPrimitiveValue)) {
- return false;
- }
-
- int newWidth = (int) ((CSSPrimitiveValue) value)
- .getFloatValue(CSSPrimitiveValue.CSS_PX);
- sashLayout.set(layout, FIELD_SASH_WIDTH, newWidth);
-
- composite.layout(true, true);
- return true;
- }
-
- public String retrieveCSSProperty(Object element, String property,
- String pseudo, CSSEngine engine) throws Exception {
- if (!(element instanceof CompositeElement)) {
- return null;
- }
- CompositeElement compositeElement = (CompositeElement) element;
- Object nativeWidget = compositeElement.getNativeWidget();
- if (!(nativeWidget instanceof Composite)) {
- return null;
- }
-
- Composite composite = (Composite) nativeWidget;
- Layout layout = composite.getLayout();
- if (!(layout instanceof SashLayout)) {
- return null;
- }
-
- Integer width = (Integer) sashLayout.getFieldValue(FIELD_SASH_WIDTH,
- (SashLayout) layout);
- return Integer.toString(width);
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.eclipse.e4.ui.workbench.renderers.swt.SashLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Layout;
+import org.w3c.dom.css.CSSPrimitiveValue;
+import org.w3c.dom.css.CSSValue;
+
+@SuppressWarnings("restriction")
+public class SashWidthHandler implements ICSSPropertyHandler {
+
+ private static final String FIELD_SASH_WIDTH = "sashWidth"; //$NON-NLS-1$
+
+ private ReflectionSupport sashLayout = new ReflectionSupport(
+ SashLayout.class);
+
+ public boolean applyCSSProperty(Object element, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ if (!(element instanceof CompositeElement)) {
+ return false;
+ }
+ CompositeElement compositeElement = (CompositeElement) element;
+ Object nativeWidget = compositeElement.getNativeWidget();
+ if (!(nativeWidget instanceof Composite)) {
+ return false;
+ }
+
+ Composite composite = (Composite) nativeWidget;
+ Layout layout = composite.getLayout();
+ if (!(layout instanceof SashLayout)) {
+ return false;
+ }
+
+ if (!(value instanceof CSSPrimitiveValue)) {
+ return false;
+ }
+
+ int newWidth = (int) ((CSSPrimitiveValue) value)
+ .getFloatValue(CSSPrimitiveValue.CSS_PX);
+ sashLayout.set(layout, FIELD_SASH_WIDTH, newWidth);
+
+ composite.layout(true, true);
+ return true;
+ }
+
+ public String retrieveCSSProperty(Object element, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ if (!(element instanceof CompositeElement)) {
+ return null;
+ }
+ CompositeElement compositeElement = (CompositeElement) element;
+ Object nativeWidget = compositeElement.getNativeWidget();
+ if (!(nativeWidget instanceof Composite)) {
+ return null;
+ }
+
+ Composite composite = (Composite) nativeWidget;
+ Layout layout = composite.getLayout();
+ if (!(layout instanceof SashLayout)) {
+ return null;
+ }
+
+ Integer width = (Integer) sashLayout.getFieldValue(FIELD_SASH_WIDTH,
+ (SashLayout) layout);
+ return Integer.toString(width);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ScrolledFormElement.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ScrolledFormElement.java
index d4dfa6bc4..846f53215 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ScrolledFormElement.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/ScrolledFormElement.java
@@ -1,14 +1,14 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-
-@SuppressWarnings("restriction")
-public class ScrolledFormElement extends CompositeElement {
-
- public ScrolledFormElement(ScrolledForm scrolledForm, CSSEngine engine) {
- super(scrolledForm, engine);
- }
-
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+@SuppressWarnings("restriction")
+public class ScrolledFormElement extends CompositeElement {
+
+ public ScrolledFormElement(ScrolledForm scrolledForm, CSSEngine engine) {
+ super(scrolledForm, engine);
+ }
+
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/SectionElement.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/SectionElement.java
index 3b085f365..1fd0a19e3 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/SectionElement.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/SectionElement.java
@@ -1,14 +1,14 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
-import org.eclipse.ui.forms.widgets.Section;
-
-@SuppressWarnings("restriction")
-public class SectionElement extends CompositeElement {
-
- public SectionElement(Section section, CSSEngine engine) {
- super(section, engine);
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.eclipse.ui.forms.widgets.Section;
+
+@SuppressWarnings("restriction")
+public class SectionElement extends CompositeElement {
+
+ public SectionElement(Section section, CSSEngine engine) {
+ super(section, engine);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/XSWTElementProvider.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/XSWTElementProvider.java
index b13d496fa..4481a0bab 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/XSWTElementProvider.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/css/XSWTElementProvider.java
@@ -1,29 +1,29 @@
-package org.xmind.cathy.internal.css;
-
-import org.eclipse.e4.ui.css.core.dom.IElementProvider;
-import org.eclipse.e4.ui.css.core.engine.CSSEngine;
-import org.eclipse.ui.forms.widgets.FormText;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.w3c.dom.Element;
-import org.xmind.ui.tabfolder.MTabBar;
-import org.xmind.ui.tabfolder.MTabFolder;
-
-@SuppressWarnings("restriction")
-public class XSWTElementProvider implements IElementProvider {
-
- public static final IElementProvider INSTANCE = new XSWTElementProvider();
-
- public Element getElement(Object element, CSSEngine engine) {
- if (element instanceof FormText) {
- return new FormTextElement((FormText) element, engine);
- } else if (element instanceof ScrolledForm) {
- return new ScrolledFormElement((ScrolledForm) element, engine);
- } else if (element instanceof MTabBar) {
- return new MTabBarElement((MTabBar) element, engine);
- } else if (element instanceof MTabFolder) {
- return new MTabFolderElement((MTabFolder) element, engine);
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.css;
+
+import org.eclipse.e4.ui.css.core.dom.IElementProvider;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.ui.forms.widgets.FormText;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.w3c.dom.Element;
+import org.xmind.ui.tabfolder.MTabBar;
+import org.xmind.ui.tabfolder.MTabFolder;
+
+@SuppressWarnings("restriction")
+public class XSWTElementProvider implements IElementProvider {
+
+ public static final IElementProvider INSTANCE = new XSWTElementProvider();
+
+ public Element getElement(Object element, CSSEngine engine) {
+ if (element instanceof FormText) {
+ return new FormTextElement((FormText) element, engine);
+ } else if (element instanceof ScrolledForm) {
+ return new ScrolledFormElement((ScrolledForm) element, engine);
+ } else if (element instanceof MTabBar) {
+ return new MTabBarElement((MTabBar) element, engine);
+ } else if (element instanceof MTabFolder) {
+ return new MTabFolderElement((MTabFolder) element, engine);
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/CategorizedTemplateViewer.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/CategorizedTemplateViewer.java
index 0f5efac2d..9e2dbacd7 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/CategorizedTemplateViewer.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/CategorizedTemplateViewer.java
@@ -1,379 +1,403 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.io.File;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.URIUtil;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Insets;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.forms.widgets.Section;
-import org.xmind.cathy.internal.ICathyConstants;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.core.util.FileUtils;
-import org.xmind.gef.EditDomain;
-import org.xmind.gef.GEF;
-import org.xmind.gef.IViewer;
-import org.xmind.gef.event.KeyEvent;
-import org.xmind.gef.part.IPart;
-import org.xmind.gef.tool.ITool;
-import org.xmind.gef.ui.internal.SpaceCollaborativeEngine;
-import org.xmind.gef.util.Properties;
-import org.xmind.ui.gallery.CategorizedGalleryViewer;
-import org.xmind.ui.gallery.GalleryEditTool;
-import org.xmind.ui.gallery.GalleryLayout;
-import org.xmind.ui.gallery.GallerySelectTool;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.internal.ClonedTemplate;
-import org.xmind.ui.internal.TemplateGroup;
-import org.xmind.ui.internal.wizards.TemplateLabelProvider;
-import org.xmind.ui.mindmap.ITemplate;
-import org.xmind.ui.mindmap.ITemplateGroup;
-import org.xmind.ui.mindmap.MindMapUI;
-import org.xmind.ui.resources.ColorUtils;
-import org.xmind.ui.texteditor.FloatingTextEditor;
-
-@SuppressWarnings("restriction")
-public class CategorizedTemplateViewer extends CategorizedGalleryViewer
- implements IAdaptable {
-
- private static final int FRAME_WIDTH = 215;
-
- private static final int FRAME_HEIGHT = 130;
-
- private class CategorizedTemplateContentProvider
- implements ITreeContentProvider {
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput,
- Object newInput) {
- }
-
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof ITemplateGroup[]) {
- return (ITemplateGroup[]) inputElement;
- }
-
- return null;
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof ITemplateGroup) {
- return ((ITemplateGroup) parentElement).getTemplates()
- .toArray();
- }
- return null;
- }
-
- public Object getParent(Object element) {
- if (element instanceof ITemplate) {
- Object input = getInput();
- if (input instanceof ITemplateGroup[]) {
- ITemplateGroup[] groups = (ITemplateGroup[]) input;
- for (ITemplateGroup group : groups) {
- for (ITemplate template : group.getTemplates()) {
- if (template.equals(element)) {
- return group;
- }
- }
- }
- }
- }
-
- return null;
- }
-
- public boolean hasChildren(Object element) {
- return (element instanceof ITemplateGroup
- && ((ITemplateGroup) element).getTemplates().size() > 0);
- }
- }
-
- private static class CategorizedTemplateLabelProvider
- extends TemplateLabelProvider {
-
- public String getText(Object element) {
- if (element instanceof ITemplateGroup) {
- return ((ITemplateGroup) element).getName();
- } else if (element instanceof ITemplate) {
- return ((ITemplate) element).getName();
- }
-
- return super.getText(element);
- }
- }
-
- private class TemplateGallerySelectTool extends GallerySelectTool {
- @Override
- protected boolean handleKeyUp(KeyEvent ke) {
- int state = ke.getState();
- int key = ke.keyCode;
- if (state == 0 && key == SWT.DEL) {
- ISelection selection = getSelection();
- if (selection instanceof IStructuredSelection) {
- Object element = ((IStructuredSelection) selection)
- .getFirstElement();
- if (element instanceof ITemplate) {
- ITemplate template = (ITemplate) element;
- if (MindMapUI.getResourceManager()
- .isUserTemplate(template)) {
- if (MessageDialog.openConfirm(
- getControl().getShell(),
- WorkbenchMessages.ConfirmDeleteTemplateDialog_title,
- NLS.bind(
- WorkbenchMessages.ConfirmDeleteTemplateDialog_message_withTemplateName,
- template.getName()))) {
- MindMapUI.getResourceManager()
- .removeUserTemplate(template);
- }
- }
- }
- }
- }
- return super.handleKeyUp(ke);
- }
- }
-
- private class TemplateNameEditTool extends GalleryEditTool {
-
- protected IDocument getTextContents(IPart source) {
- return new org.eclipse.jface.text.Document(
- ((ITemplate) source.getModel()).getName());
- }
-
- protected void handleTextModified(IPart source, IDocument document) {
- ITemplate template = (ITemplate) source.getModel();
- if (template != null) {
- modifyTemplateName(template, document.get());
- }
- }
-
- protected void hookEditor(FloatingTextEditor editor) {
- super.hookEditor(editor);
- getHelper().setPrefWidth(130);
- }
- }
-
- private List sysTemplateGroups;
-
- private ResourceManager localResourceManager;
-
- public CategorizedTemplateViewer(Composite container) {
- super();
- setSectionStyle(Section.COMPACT | Section.TWISTIE | Section.EXPANDED
- | Section.NO_TITLE_FOCUS_BOX);
- create(container);
- }
-
- private void create(Composite parent) {
- localResourceManager = new LocalResourceManager(
- JFaceResources.getResources(), parent);
-
- setContentProvider(new CategorizedTemplateContentProvider());
- setLabelProvider(new CategorizedTemplateLabelProvider());
-
- EditDomain domain = new EditDomain();
- domain.installTool(GEF.TOOL_SELECT, new TemplateGallerySelectTool());
- domain.installTool(GEF.TOOL_EDIT, new TemplateNameEditTool());
- setEditDomain(domain);
-
- initProperties();
- createControl(parent, SWT.WRAP);
-
- setInput(getViewerInput());
-
- registerHelper(parent.getShell());
- }
-
- private void initProperties() {
- Properties properties = getProperties();
-
- properties.set(GalleryViewer.Horizontal, Boolean.TRUE);
- properties.set(GalleryViewer.Wrap, Boolean.TRUE);
- properties.set(GalleryViewer.TitlePlacement,
- GalleryViewer.TITLE_BOTTOM);
-
- properties.set(GalleryViewer.SingleClickToOpen, Boolean.TRUE);
- properties.set(GalleryViewer.SolidFrames, true);
- properties.set(GalleryViewer.FlatFrames, true);
-
- properties.set(GalleryViewer.ImageConstrained, true);
- properties.set(GalleryViewer.ImageStretched, true);
-
- properties.set(GalleryViewer.Layout,
- new GalleryLayout(GalleryLayout.ALIGN_TOPLEFT,
- GalleryLayout.ALIGN_TOPLEFT, 30, 0,
- new Insets(10, 0, 20, 65)));
- properties.set(GalleryViewer.ContentPaneBorderWidth, 1);
- properties.set(GalleryViewer.ContentPaneBorderColor,
- (Color) localResourceManager
- .get(ColorUtils.toDescriptor("#cccccc"))); //$NON-NLS-1$
- properties.set(GalleryViewer.FrameContentSize,
- new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
-
- properties.set(GalleryViewer.ContentPaneSpaceCollaborativeEngine,
- new SpaceCollaborativeEngine());
- }
-
- @Override
- protected void configureContainer(ScrolledForm container) {
- super.configureContainer(container);
- container.setBackground(container.getParent().getBackground());
- }
-
- private Object[] getViewerInput() {
- List groups = new ArrayList();
- if (sysTemplateGroups == null || sysTemplateGroups.isEmpty())
- sysTemplateGroups = MindMapUI.getResourceManager()
- .getSystemTemplateGroups();
-
- groups.addAll(sysTemplateGroups);
-
- List userTemplates = MindMapUI.getResourceManager()
- .getUserTemplates();
- if (userTemplates.size() != 0) {
- ITemplateGroup userGroup = new TemplateGroup(
- WorkbenchMessages.TemplateViewer_UserGroup_title,
- userTemplates);
- groups.add(userGroup);
- }
-
- return groups.toArray(new ITemplateGroup[groups.size()]);
- }
-
- @Override
- protected Control createSectionContent(Composite parent, Object category) {
- parent.setBackground(parent.getParent().getBackground());
- getWidgetFactory().setBackground(parent.getBackground());
-
- return super.createSectionContent(parent, category);
- }
-
- protected GalleryViewer createNestedViewer() {
- return new GalleryViewer();
- }
-
- private void registerHelper(Shell shell) {
- shell.setData(ICathyConstants.HELPER_TEMPLATE_RENAME, new Runnable() {
-
- public void run() {
- ISelection selection = getSelection();
- if (selection instanceof IStructuredSelection) {
- Object obj = ((IStructuredSelection) selection)
- .getFirstElement();
- if (obj instanceof ITemplate) {
- ITemplate template = (ITemplate) obj;
- startEditing(template);
- }
- }
- }
- });
- }
-
- public void userTemplateAdded(ITemplate template) {
- if (template == null || getControl() == null
- || getControl().isDisposed()) {
- return;
- }
-
- setInput(getViewerInput());
- refresh();
- reveal(new ClonedTemplate(template.getSourceWorkbookURI(), null));
- }
-
- public void userTemplateRemoved(ITemplate template) {
- if (template == null || getControl() == null
- || getControl().isDisposed()) {
- return;
- }
- setInput(getViewerInput());
- }
-
- private void startEditing(ITemplate template) {
- Object input = getInput();
- if (input instanceof ITemplateGroup[]) {
- ITemplateGroup[] groups = (ITemplateGroup[]) input;
- for (ITemplateGroup group : groups) {
- if (group.getTemplates().contains(template)) {
-
- GalleryViewer galleryViewer = getNestedViewer(group);
- EditDomain domain = galleryViewer.getEditDomain();
- ITool tool = domain.getDefaultTool();
-
- ((GallerySelectTool) tool).getStatus()
- .setStatus(GEF.ST_ACTIVE, true);
- domain.handleRequest(GEF.REQ_EDIT, (IViewer) galleryViewer);
- break;
- }
- }
- }
- }
-
- private boolean modifyTemplateName(ITemplate template, String newName) {
- if (template == null || newName == null || newName.equals("") //$NON-NLS-1$
- || newName.equals(template.getName())) {
- return false;
- }
-
- List userTemplates = MindMapUI.getResourceManager()
- .getUserTemplates();
- for (ITemplate t : userTemplates) {
- if (newName.equals(t.getName())) {
- return false;
- }
- }
-
- URI uri = template.getSourceWorkbookURI();
- File sourceFile = URIUtil.toFile(uri);
-
- File targetFile = new File(sourceFile.getParent(),
- newName + FileUtils.getExtension(sourceFile.getAbsolutePath()));
- boolean renameSuccess = sourceFile.renameTo(targetFile);
- if (!renameSuccess) {
- //TODO
- }
-
- Object[] input = getViewerInput();
- setInput(input);
-
- setSelection(new StructuredSelection(
- new ClonedTemplate(targetFile.toURI(), null)), true);
-
- return true;
- }
-
- public T getAdapter(Class adapter) {
- if (ISelectionProvider.class.equals(adapter)) {
- return adapter.cast(this);
- }
-
- return null;
- }
-
- @Override
- protected void unmapAllElements() {
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.io.File;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Insets;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+import org.xmind.cathy.internal.ICathyConstants;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.core.util.FileUtils;
+import org.xmind.gef.EditDomain;
+import org.xmind.gef.GEF;
+import org.xmind.gef.IViewer;
+import org.xmind.gef.event.KeyEvent;
+import org.xmind.gef.part.IPart;
+import org.xmind.gef.tool.ITool;
+import org.xmind.gef.ui.internal.SpaceCollaborativeEngine;
+import org.xmind.gef.util.Properties;
+import org.xmind.ui.gallery.CategorizedGalleryViewer;
+import org.xmind.ui.gallery.GalleryEditTool;
+import org.xmind.ui.gallery.GalleryLayout;
+import org.xmind.ui.gallery.GallerySelectTool;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.internal.ClonedTemplate;
+import org.xmind.ui.internal.TemplateGroup;
+import org.xmind.ui.internal.wizards.TemplateLabelProvider;
+import org.xmind.ui.mindmap.ITemplate;
+import org.xmind.ui.mindmap.ITemplateGroup;
+import org.xmind.ui.mindmap.MindMapUI;
+import org.xmind.ui.resources.ColorUtils;
+import org.xmind.ui.texteditor.FloatingTextEditor;
+
+@SuppressWarnings("restriction")
+public class CategorizedTemplateViewer extends CategorizedGalleryViewer
+ implements IAdaptable {
+
+ private static final int FRAME_WIDTH = 210;
+
+ private static final int FRAME_HEIGHT = 130;
+
+ private class CategorizedTemplateContentProvider
+ implements ITreeContentProvider {
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof ITemplateGroup[]) {
+ return (ITemplateGroup[]) inputElement;
+ }
+
+ return null;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof ITemplateGroup) {
+ return ((ITemplateGroup) parentElement).getTemplates()
+ .toArray();
+ }
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ if (element instanceof ITemplate) {
+ Object input = getInput();
+ if (input instanceof ITemplateGroup[]) {
+ ITemplateGroup[] groups = (ITemplateGroup[]) input;
+ for (ITemplateGroup group : groups) {
+ for (ITemplate template : group.getTemplates()) {
+ if (template.equals(element)) {
+ return group;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return (element instanceof ITemplateGroup
+ && ((ITemplateGroup) element).getTemplates().size() > 0);
+ }
+ }
+
+ private static class CategorizedTemplateLabelProvider
+ extends TemplateLabelProvider {
+
+ public String getText(Object element) {
+ if (element instanceof ITemplateGroup) {
+ String name = ((ITemplateGroup) element).getName();
+ if (name == null)
+ name = WorkbenchMessages.CategorizedTemplateViewer_group_untitiledName;
+ return name.length() <= 20 ? name
+ : name.substring(0, 20) + "..."; //$NON-NLS-1$
+ } else if (element instanceof ITemplate) {
+ String name = ((ITemplate) element).getName();
+ if (name == null)
+ name = WorkbenchMessages.CategorizedTemplateViewer_template_untitiledName;
+ return name.length() <= 20 ? name
+ : name.substring(0, 20) + "..."; //$NON-NLS-1$
+ }
+
+ return super.getText(element);
+ }
+ }
+
+ private class TemplateGallerySelectTool extends GallerySelectTool {
+ @Override
+ protected boolean handleKeyUp(KeyEvent ke) {
+ int state = ke.getState();
+ int key = ke.keyCode;
+ if (state == 0 && key == SWT.DEL) {
+ ISelection selection = getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Object element = ((IStructuredSelection) selection)
+ .getFirstElement();
+ if (element instanceof ITemplate) {
+ ITemplate template = (ITemplate) element;
+ if (MindMapUI.getResourceManager()
+ .isUserTemplate(template)) {
+ if (MessageDialog.openConfirm(
+ getControl().getShell(),
+ WorkbenchMessages.ConfirmDeleteTemplateDialog_title,
+ NLS.bind(
+ WorkbenchMessages.ConfirmDeleteTemplateDialog_message_withTemplateName,
+ template.getName()))) {
+ MindMapUI.getResourceManager()
+ .removeUserTemplate(template);
+ }
+ }
+ }
+ }
+ }
+ return super.handleKeyUp(ke);
+ }
+ }
+
+ private class TemplateNameEditTool extends GalleryEditTool {
+
+ protected IDocument getTextContents(IPart source) {
+ return new org.eclipse.jface.text.Document(
+ ((ITemplate) source.getModel()).getName());
+ }
+
+ protected void handleTextModified(IPart source, IDocument document) {
+ ITemplate template = (ITemplate) source.getModel();
+ if (template != null) {
+ modifyTemplateName(template, document.get());
+ }
+ }
+
+ protected void hookEditor(FloatingTextEditor editor) {
+ super.hookEditor(editor);
+ getHelper().setPrefWidth(130);
+ }
+ }
+
+ private List sysTemplateGroups;
+
+ private ResourceManager localResourceManager;
+
+ public CategorizedTemplateViewer(Composite container) {
+ super();
+ setSectionStyle(Section.COMPACT | Section.TWISTIE | Section.EXPANDED
+ | Section.NO_TITLE_FOCUS_BOX);
+ create(container);
+ }
+
+ private void create(Composite parent) {
+ localResourceManager = new LocalResourceManager(
+ JFaceResources.getResources(), parent);
+ setContentProvider(new CategorizedTemplateContentProvider());
+ setLabelProvider(new CategorizedTemplateLabelProvider());
+
+ EditDomain domain = new EditDomain();
+ domain.installTool(GEF.TOOL_SELECT, new TemplateGallerySelectTool());
+ domain.installTool(GEF.TOOL_EDIT, new TemplateNameEditTool());
+ setEditDomain(domain);
+
+ initProperties();
+ createControl(parent, SWT.WRAP);
+
+ getControl().addDisposeListener(new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ handleDispose();
+ }
+ });
+
+ setInput(getViewerInput());
+
+ registerHelper(parent.getShell());
+ }
+
+ private void handleDispose() {
+ unregisterHelper(getControl().getShell());
+ }
+
+ private void initProperties() {
+ Properties properties = getProperties();
+
+ properties.set(GalleryViewer.Horizontal, Boolean.TRUE);
+ properties.set(GalleryViewer.Wrap, Boolean.TRUE);
+ properties.set(GalleryViewer.TitlePlacement,
+ GalleryViewer.TITLE_BOTTOM);
+
+ properties.set(GalleryViewer.SingleClickToOpen, Boolean.TRUE);
+ properties.set(GalleryViewer.SolidFrames, true);
+ properties.set(GalleryViewer.FlatFrames, true);
+
+ properties.set(GalleryViewer.ImageConstrained, true);
+ properties.set(GalleryViewer.ImageStretched, true);
+
+ properties.set(GalleryViewer.Layout,
+ new GalleryLayout(GalleryLayout.ALIGN_TOPLEFT,
+ GalleryLayout.ALIGN_TOPLEFT, 30, 0,
+ new Insets(10, 0, 20, 65)));
+ properties.set(GalleryViewer.ContentPaneBorderWidth, 1);
+ properties.set(GalleryViewer.ContentPaneBorderColor,
+ (Color) localResourceManager
+ .get(ColorUtils.toDescriptor("#cccccc"))); //$NON-NLS-1$
+ properties.set(GalleryViewer.FrameContentSize,
+ new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
+
+ properties.set(GalleryViewer.ContentPaneSpaceCollaborativeEngine,
+ new SpaceCollaborativeEngine());
+ }
+
+ @Override
+ protected void configureContainer(ScrolledForm container) {
+ super.configureContainer(container);
+ container.setBackground(container.getParent().getBackground());
+ }
+
+ private Object[] getViewerInput() {
+ List groups = new ArrayList();
+ if (sysTemplateGroups == null || sysTemplateGroups.isEmpty())
+ sysTemplateGroups = MindMapUI.getResourceManager()
+ .getSystemTemplateGroups();
+
+ groups.addAll(sysTemplateGroups);
+
+ List userTemplates = MindMapUI.getResourceManager()
+ .getUserTemplates();
+ if (userTemplates.size() != 0) {
+ ITemplateGroup userGroup = new TemplateGroup(
+ WorkbenchMessages.TemplateViewer_UserGroup_title,
+ userTemplates);
+ groups.add(userGroup);
+ }
+
+ return groups.toArray(new ITemplateGroup[groups.size()]);
+ }
+
+ @Override
+ protected Control createSectionContent(Composite parent, Object category) {
+ parent.setBackground(parent.getParent().getBackground());
+ getWidgetFactory().setBackground(parent.getBackground());
+
+ return super.createSectionContent(parent, category);
+ }
+
+ protected GalleryViewer createNestedViewer() {
+ return new GalleryViewer();
+ }
+
+ private void registerHelper(Shell shell) {
+ shell.setData(ICathyConstants.HELPER_TEMPLATE_RENAME, new Runnable() {
+
+ public void run() {
+ ISelection selection = getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection) selection)
+ .getFirstElement();
+ if (obj instanceof ITemplate) {
+ ITemplate template = (ITemplate) obj;
+ startEditing(template);
+ }
+ }
+ }
+ });
+ }
+
+ private void unregisterHelper(Shell shell) {
+ shell.setData(ICathyConstants.HELPER_TEMPLATE_RENAME, null);
+ }
+
+ public void userTemplateAdded(ITemplate template) {
+ if (template == null || getControl() == null
+ || getControl().isDisposed()) {
+ return;
+ }
+
+ setInput(getViewerInput());
+ refresh();
+ reveal(new ClonedTemplate(template.getSourceWorkbookURI(), null));
+ }
+
+ public void userTemplateRemoved(ITemplate template) {
+ if (template == null || getControl() == null
+ || getControl().isDisposed()) {
+ return;
+ }
+ setInput(getViewerInput());
+ }
+
+ private void startEditing(ITemplate template) {
+ Object input = getInput();
+ if (input instanceof ITemplateGroup[]) {
+ ITemplateGroup[] groups = (ITemplateGroup[]) input;
+ for (ITemplateGroup group : groups) {
+ if (group.getTemplates().contains(template)) {
+
+ GalleryViewer galleryViewer = getNestedViewer(group);
+ EditDomain domain = galleryViewer.getEditDomain();
+ ITool tool = domain.getDefaultTool();
+
+ ((GallerySelectTool) tool).getStatus()
+ .setStatus(GEF.ST_ACTIVE, true);
+ domain.handleRequest(GEF.REQ_EDIT, (IViewer) galleryViewer);
+ break;
+ }
+ }
+ }
+ }
+
+ private boolean modifyTemplateName(ITemplate template, String newName) {
+ if (template == null || newName == null || newName.equals("") //$NON-NLS-1$
+ || newName.equals(template.getName())) {
+ return false;
+ }
+
+ List userTemplates = MindMapUI.getResourceManager()
+ .getUserTemplates();
+ for (ITemplate t : userTemplates) {
+ if (newName.equals(t.getName())) {
+ return false;
+ }
+ }
+
+ URI uri = template.getSourceWorkbookURI();
+ File sourceFile = URIUtil.toFile(uri);
+
+ File targetFile = new File(sourceFile.getParent(),
+ newName + FileUtils.getExtension(sourceFile.getAbsolutePath()));
+ boolean renameSuccess = sourceFile.renameTo(targetFile);
+ if (!renameSuccess) {
+ //TODO
+ }
+
+ Object[] input = getViewerInput();
+ setInput(input);
+
+ setSelection(new StructuredSelection(
+ new ClonedTemplate(targetFile.toURI(), null)), true);
+
+ return true;
+ }
+
+ public T getAdapter(Class adapter) {
+ if (ISelectionProvider.class.equals(adapter)) {
+ return adapter.cast(this);
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void unmapAllElements() {
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardAutomationAddon.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardAutomationAddon.java
index 7bc219ab1..01a46d040 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardAutomationAddon.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardAutomationAddon.java
@@ -1,310 +1,327 @@
-
-package org.xmind.cathy.internal.dashboard;
-
-import java.util.Arrays;
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.eclipse.e4.core.di.extensions.EventTopic;
-import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.ui.MElementContainer;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
-import org.eclipse.e4.ui.model.application.ui.basic.MStackElement;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
-import org.eclipse.e4.ui.workbench.Selector;
-import org.eclipse.e4.ui.workbench.UIEvents;
-import org.eclipse.e4.ui.workbench.modeling.EModelService;
-import org.eclipse.e4.ui.workbench.modeling.EPartService;
-import org.osgi.service.event.Event;
-import org.xmind.cathy.internal.HandledItemMatcher;
-import org.xmind.cathy.internal.ICathyConstants;
-import org.xmind.cathy.internal.WorkbenchMessages;
-
-public class DashboardAutomationAddon {
-
- @Inject
- private EModelService modelService;
-
- @Inject
- private MApplication application;
-
- private Selector itemMatcher = new HandledItemMatcher(
- ICathyConstants.COMMAND_TOGGLE_DASHBOARD);
-
- /**
- * @param modelService
- * the modelService to set
- */
- public void setModelService(EModelService modelService) {
- this.modelService = modelService;
- }
-
- /**
- * @param application
- * the application to set
- */
- public void setApplication(MApplication application) {
- this.application = application;
- }
-
- public void showDashboard(MWindow window) {
- if (doShowDashboard(window)) {
- updateDashboardToolItems(window);
- }
-
- //hide right parts.
- hideVisiblePart(window, "org.xmind.ui.stack.right"); //$NON-NLS-1$
- }
-
- @Inject
- @Optional
- public void updateDashboardVisibilityWhenWindowTagsChanged(
- @EventTopic(UIEvents.ApplicationElement.TOPIC_TAGS) Event event) {
- Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
- if (!(element instanceof MWindow) || !ICathyConstants.ID_MAIN_WINDOW
- .equals(((MWindow) element).getElementId()))
- return;
-
- MWindow window = (MWindow) element;
- if (UIEvents.EventTypes.ADD
- .equals(event.getProperty(UIEvents.EventTags.TYPE))
- && ICathyConstants.TAG_SHOW_DASHBOARD.equals(
- event.getProperty(UIEvents.EventTags.NEW_VALUE))) {
- if (!doShowDashboard(window)) {
- window.getTags().remove(ICathyConstants.TAG_SHOW_DASHBOARD);
- return;
- }
- } else if (UIEvents.EventTypes.REMOVE
- .equals(event.getProperty(UIEvents.EventTags.TYPE))
- && ICathyConstants.TAG_SHOW_DASHBOARD.equals(
- event.getProperty(UIEvents.EventTags.OLD_VALUE))) {
- if (!doHideDashboard(window)) {
- window.getTags().add(ICathyConstants.TAG_SHOW_DASHBOARD);
- return;
- }
- }
-
- updateDashboardToolItems(window);
- }
-
- private boolean doShowDashboard(MWindow window) {
- MPart dashboardPart = findReferencedDashboardPartIn(window, true);
- if (dashboardPart == null)
- return false;
-
- EPartService partService = window.getContext().get(EPartService.class);
- if (partService == null)
- return false;
-
- partService.activate(dashboardPart, true);
- return partService.getActivePart() == dashboardPart;
- }
-
- private boolean doHideDashboard(MWindow window) {
- MPart dashboardPart = findReferencedDashboardPartIn(window, false);
- if (dashboardPart == null)
- return true;
-
- EPartService partService = window.getContext().get(EPartService.class);
- if (partService == null)
- return false;
-
- partService.hidePart(dashboardPart);
- return partService.getActivePart() != dashboardPart;
- }
-
- @Inject
- @Optional
- public void updateWindowTagsWhenDashboardVisibilityChanged(
- @EventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) Event event) {
- Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
- if (!(element instanceof MElementContainer))
- return;
-
- MElementContainer container = (MElementContainer) element;
- final MWindow window = modelService.getTopLevelWindowFor(container);
- if (window == null || !ICathyConstants.ID_MAIN_WINDOW
- .equals(window.getElementId()))
- return;
-
- MPart activePart = findSelectedElementIn(window, MPart.class);
- if (activePart != null && ICathyConstants.ID_DASHBOARD_PART
- .equals(activePart.getElementId())) {
- /*
- * The Dashboard is shown, we must ensure that the
- * CathyShowDashboard tag is added to window.
- */
- if (!window.getTags()
- .contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
- window.getTags().add(ICathyConstants.TAG_SHOW_DASHBOARD);
- }
- } else {
- /*
- * The Dashboard is about to be hidden, we must ensure that the
- * CathyShowDashboard tag is removed from the window.
- */
- if (window.getTags().contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
- window.getTags().remove(ICathyConstants.TAG_SHOW_DASHBOARD);
- }
- }
- }
-
- @Inject
- @Optional
- public void showDashboardWhenAllEditorsAreRemoved(
- @EventTopic(UIEvents.ElementContainer.TOPIC_CHILDREN) Event event) {
- if (!UIEvents.isREMOVE(event))
- return;
-
- Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
- if (!(element instanceof MElementContainer))
- return;
-
- boolean partRemoved = false;
- for (Object removed : UIEvents.asIterable(event,
- UIEvents.EventTags.OLD_VALUE)) {
- if (removed instanceof MPart) {
- partRemoved = true;
- break;
- }
- }
-
- if (!partRemoved)
- return;
-
- MWindow window = modelService
- .getTopLevelWindowFor((MUIElement) element);
- if (window == null || !ICathyConstants.ID_MAIN_WINDOW
- .equals(window.getElementId()))
- return;
-
- List editors = modelService.findElements(window, null,
- MPart.class, Arrays.asList(ICathyConstants.TAG_EDITOR));
- if (!editors.isEmpty())
- return;
-
- //hide right parts.
- hideVisiblePart(window, "org.xmind.ui.stack.right"); //$NON-NLS-1$
-
- if (!window.getTags().contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
- window.getTags().add(ICathyConstants.TAG_SHOW_DASHBOARD);
- }
- }
-
- private MPart findReferencedDashboardPartIn(MWindow window,
- boolean createIfMissing) {
- MPart dashboardPart = null;
-
- /*
- * Find Dashboard instance in window model tree.
- */
- List dashboardParts = modelService.findElements(window,
- ICathyConstants.ID_DASHBOARD_PART, MPart.class, null);
- if (!dashboardParts.isEmpty()) {
- dashboardPart = dashboardParts.get(0);
- } else {
- /*
- * Find Dashboard instance in shared elements.
- */
- for (MUIElement p : window.getChildren()) {
- if (p instanceof MPart && ICathyConstants.ID_DASHBOARD_PART
- .equals(p.getElementId())) {
- dashboardPart = (MPart) p;
- break;
- }
- }
- }
-
- if (dashboardPart == null && createIfMissing) {
- /*
- * Create Dashboard part from snippet.
- */
- MUIElement part = modelService.cloneSnippet(application,
- ICathyConstants.ID_DASHBOARD_PART, window);
- if (part != null && part instanceof MPart
- && ICathyConstants.ID_DASHBOARD_PART
- .equals(part.getElementId())) {
- dashboardPart = (MPart) part;
- window.getChildren().add(dashboardPart);
- }
- }
-
- return dashboardPart;
- }
-
- private T findSelectedElementIn(MUIElement root,
- Class type) {
- if (type.isInstance(root))
- return type.cast(root);
-
- if (root instanceof MPlaceholder)
- return findSelectedElementIn(((MPlaceholder) root).getRef(), type);
-
- if (root instanceof MElementContainer)
- return findSelectedElementIn(
- ((MElementContainer) root).getSelectedElement(), type);
-
- return null;
- }
-
- private void updateDashboardToolItems(MWindow window) {
- String tooltip;
- boolean selected;
- if (window.getTags().contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
- tooltip = WorkbenchMessages.DashboardHideHome_tooltip;
- selected = true;
- } else {
- tooltip = WorkbenchMessages.DashboardShowHome_tooltip;
- selected = false;
- }
-
- List items = modelService.findElements(window,
- MHandledItem.class, EModelService.ANYWHERE, itemMatcher);
- for (MHandledItem item : items) {
- item.setTooltip(tooltip);
- item.setSelected(selected);
- }
- }
-
- private static final String hideVisiblePart(MWindow window,
- String partStackId) {
- if (window == null || partStackId == null) {
- return null;
- }
-
- EModelService modelService = window.getContext()
- .get(EModelService.class);
- EPartService partService = window.getContext().get(EPartService.class);
-
- List partStacks = modelService.findElements(window,
- partStackId, MPartStack.class, null);
- if (partStacks.isEmpty()) {
- return null;
- }
- MPartStack partStack = partStacks.get(0);
-
- MPart visiblePart = null;
- MStackElement selectedElement = partStack.getSelectedElement();
- if (selectedElement instanceof MPlaceholder) {
- MPlaceholder placeholder = (MPlaceholder) selectedElement;
- visiblePart = partService.findPart(placeholder.getElementId());
- } else if (selectedElement instanceof MPart) {
- visiblePart = (MPart) selectedElement;
- }
-
- if (visiblePart != null) {
- visiblePart.setVisible(false);
- partService.hidePart(visiblePart);
- return visiblePart.getElementId();
- }
-
- return null;
- }
-
-}
+
+package org.xmind.cathy.internal.dashboard;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.core.di.extensions.EventTopic;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.MElementContainer;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
+import org.eclipse.e4.ui.model.application.ui.basic.MStackElement;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
+import org.eclipse.e4.ui.workbench.Selector;
+import org.eclipse.e4.ui.workbench.UIEvents;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.osgi.service.event.Event;
+import org.xmind.cathy.internal.HandledItemMatcher;
+import org.xmind.cathy.internal.ICathyConstants;
+import org.xmind.cathy.internal.WorkbenchMessages;
+
+public class DashboardAutomationAddon {
+
+ @Inject
+ private EModelService modelService;
+
+ @Inject
+ private MApplication application;
+
+ private Selector itemMatcher = new HandledItemMatcher(
+ ICathyConstants.COMMAND_TOGGLE_DASHBOARD);
+
+ /**
+ * @param modelService
+ * the modelService to set
+ */
+ public void setModelService(EModelService modelService) {
+ this.modelService = modelService;
+ }
+
+ /**
+ * @param application
+ * the application to set
+ */
+ public void setApplication(MApplication application) {
+ this.application = application;
+ }
+
+ public void showDashboard(MWindow window) {
+ if (doShowDashboard(window)) {
+ updateDashboardToolItems(window);
+ }
+
+ //hide right parts.
+ hideVisiblePart(window, "org.xmind.ui.stack.right"); //$NON-NLS-1$
+ }
+
+ @Inject
+ @Optional
+ public void updateDashboardVisibilityWhenWindowTagsChanged(
+ @EventTopic(UIEvents.ApplicationElement.TOPIC_TAGS) Event event) {
+ Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
+ if (!(element instanceof MWindow) || !ICathyConstants.ID_MAIN_WINDOW
+ .equals(((MWindow) element).getElementId()))
+ return;
+
+ MWindow window = (MWindow) element;
+ if (UIEvents.EventTypes.ADD
+ .equals(event.getProperty(UIEvents.EventTags.TYPE))
+ && ICathyConstants.TAG_SHOW_DASHBOARD.equals(
+ event.getProperty(UIEvents.EventTags.NEW_VALUE))) {
+ if (!doShowDashboard(window)) {
+ window.getTags().remove(ICathyConstants.TAG_SHOW_DASHBOARD);
+ return;
+ }
+ } else if (UIEvents.EventTypes.REMOVE
+ .equals(event.getProperty(UIEvents.EventTags.TYPE))
+ && ICathyConstants.TAG_SHOW_DASHBOARD.equals(
+ event.getProperty(UIEvents.EventTags.OLD_VALUE))) {
+ if (!doHideDashboard(window)) {
+ window.getTags().add(ICathyConstants.TAG_SHOW_DASHBOARD);
+ return;
+ }
+ }
+
+ updateDashboardToolItems(window);
+ }
+
+ private boolean doShowDashboard(MWindow window) {
+ MPart dashboardPart = findReferencedDashboardPartIn(window, true);
+ if (dashboardPart == null)
+ return false;
+
+ EPartService partService = window.getContext().get(EPartService.class);
+ if (partService == null)
+ return false;
+
+ partService.activate(dashboardPart, true);
+ return partService.getActivePart() == dashboardPart;
+ }
+
+ private boolean doHideDashboard(MWindow window) {
+ MPart dashboardPart = findReferencedDashboardPartIn(window, false);
+ if (dashboardPart == null)
+ return true;
+
+ EPartService partService = window.getContext().get(EPartService.class);
+ if (partService == null)
+ return false;
+
+ partService.hidePart(dashboardPart);
+ return partService.getActivePart() != dashboardPart;
+ }
+
+ @Inject
+ @Optional
+ public void updateWindowTagsWhenDashboardVisibilityChanged(
+ @EventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) Event event) {
+ Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
+ if (!(element instanceof MElementContainer))
+ return;
+
+ MElementContainer container = (MElementContainer) element;
+ final MWindow window = modelService.getTopLevelWindowFor(container);
+ if (window == null || !ICathyConstants.ID_MAIN_WINDOW
+ .equals(window.getElementId()))
+ return;
+
+ MPart activePart = findSelectedElementIn(window, MPart.class);
+ if (activePart != null && ICathyConstants.ID_DASHBOARD_PART
+ .equals(activePart.getElementId())) {
+ /*
+ * The Dashboard is shown, we must ensure that the
+ * CathyShowDashboard tag is added to window.
+ */
+ if (!window.getTags()
+ .contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
+ window.getTags().add(ICathyConstants.TAG_SHOW_DASHBOARD);
+ }
+ } else {
+ /*
+ * The Dashboard is about to be hidden, we must ensure that the
+ * CathyShowDashboard tag is removed from the window.
+ */
+ if (window.getTags().contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
+ window.getTags().remove(ICathyConstants.TAG_SHOW_DASHBOARD);
+ }
+ }
+ }
+
+ @Inject
+ @Optional
+ public void showDashboardWhenAllEditorsAreRemoved(
+ @EventTopic(UIEvents.ElementContainer.TOPIC_CHILDREN) Event event) {
+ if (!UIEvents.isREMOVE(event))
+ return;
+
+ Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
+ if (!(element instanceof MElementContainer))
+ return;
+
+ boolean partRemoved = false;
+ for (Object removed : UIEvents.asIterable(event,
+ UIEvents.EventTags.OLD_VALUE)) {
+ if (removed instanceof MPart) {
+ partRemoved = true;
+ break;
+ }
+ }
+
+ if (!partRemoved)
+ return;
+
+ MWindow window = modelService
+ .getTopLevelWindowFor((MUIElement) element);
+ if (window == null || !ICathyConstants.ID_MAIN_WINDOW
+ .equals(window.getElementId()))
+ return;
+
+ List editors = modelService.findElements(window, null,
+ MPart.class, Arrays.asList(ICathyConstants.TAG_EDITOR));
+ if (!editors.isEmpty())
+ return;
+
+ //hide right parts.
+ hideVisiblePart(window, "org.xmind.ui.stack.right"); //$NON-NLS-1$
+
+// if (!window.getTags().contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
+// window.getTags().add(ICathyConstants.TAG_SHOW_DASHBOARD);
+// }
+ }
+
+ private MPart findReferencedDashboardPartIn(MWindow window,
+ boolean createIfMissing) {
+ MPart dashboardPart = null;
+
+ /*
+ * Find Dashboard instance in window model tree.
+ */
+ List dashboardParts = modelService.findElements(window,
+ ICathyConstants.ID_DASHBOARD_PART, MPart.class, null);
+ if (!dashboardParts.isEmpty()) {
+ dashboardPart = dashboardParts.get(0);
+ } else {
+ /*
+ * Find Dashboard instance in shared elements.
+ */
+ for (MUIElement p : window.getChildren()) {
+ if (p instanceof MPart && ICathyConstants.ID_DASHBOARD_PART
+ .equals(p.getElementId())) {
+ dashboardPart = (MPart) p;
+ break;
+ }
+ }
+ }
+
+ if (dashboardPart == null && createIfMissing) {
+ /*
+ * Create Dashboard part from snippet.
+ */
+ MUIElement part = modelService.cloneSnippet(application,
+ ICathyConstants.ID_DASHBOARD_PART, window);
+ if (part != null && part instanceof MPart
+ && ICathyConstants.ID_DASHBOARD_PART
+ .equals(part.getElementId())) {
+ dashboardPart = (MPart) part;
+ window.getChildren().add(dashboardPart);
+ }
+ }
+
+ return dashboardPart;
+ }
+
+ private T findSelectedElementIn(MUIElement root,
+ Class type) {
+ if (type.isInstance(root))
+ return type.cast(root);
+
+ if (root instanceof MPlaceholder)
+ return findSelectedElementIn(((MPlaceholder) root).getRef(), type);
+
+ if (root instanceof MElementContainer)
+ return findSelectedElementIn(
+ ((MElementContainer) root).getSelectedElement(), type);
+
+ return null;
+ }
+
+ private void updateDashboardToolItems(MWindow window) {
+ String tooltip;
+ boolean selected;
+ if (window.getTags().contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
+ tooltip = WorkbenchMessages.DashboardHideHome_tooltip;
+ selected = true;
+ } else {
+ tooltip = WorkbenchMessages.DashboardShowHome_tooltip;
+ selected = false;
+ }
+
+ List items = modelService.findElements(window,
+ MHandledItem.class, EModelService.ANYWHERE, itemMatcher);
+ for (MHandledItem item : items) {
+ item.setTooltip(tooltip);
+ item.setSelected(selected);
+ }
+ }
+
+ public static final String hideVisiblePart(MWindow window,
+ String partStackId) {
+ if (window == null || window.getContext() == null
+ || partStackId == null) {
+ return null;
+ }
+
+ EModelService modelService = window.getContext()
+ .get(EModelService.class);
+ EPartService partService = window.getContext().get(EPartService.class);
+
+ List partStacks = modelService.findElements(window,
+ partStackId, MPartStack.class, null);
+ if (partStacks.isEmpty()) {
+ return null;
+ }
+ MPartStack partStack = partStacks.get(0);
+
+ MStackElement selectedElement = partStack.getSelectedElement();
+ String hidePartId = hidePart(partService, selectedElement);
+ if (hidePartId != null) {
+ return hidePartId;
+ }
+
+ //fix: part may not be hiden
+ List children = partStack.getChildren();
+ for (MStackElement child : children) {
+ hidePart(partService, child);
+ }
+
+ return null;
+ }
+
+ private static String hidePart(EPartService partService,
+ MStackElement element) {
+ MPart visiblePart = null;
+ if (element instanceof MPlaceholder) {
+ MPlaceholder placeholder = (MPlaceholder) element;
+ visiblePart = partService.findPart(placeholder.getElementId());
+ } else if (element instanceof MPart) {
+ visiblePart = (MPart) element;
+ }
+
+ if (visiblePart != null) {
+ visiblePart.setVisible(false);
+ partService.hidePart(visiblePart);
+ return visiblePart.getElementId();
+ }
+
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardContent.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardContent.java
index a5050ef48..089738366 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardContent.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardContent.java
@@ -1,409 +1,441 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.osgi.framework.Bundle;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.ui.internal.dashboard.pages.IDashboardPage;
-import org.xmind.ui.tabfolder.MTabFolder;
-import org.xmind.ui.tabfolder.MTabItem;
-
-public class DashboardContent {
-
- private static final String CONTENT_URI = "platform:/plugin/org.xmind.cathy/dashboard/dashboard.xml"; //$NON-NLS-1$
- private static final String NLS_PATH_BASE = "dashboard/dashboard"; //$NON-NLS-1$
-
- private static final String TAG_DASHBOARD = "dashboard"; //$NON-NLS-1$
- private static final String TAG_PAGE = "page"; //$NON-NLS-1$
- private static final String TAG_SPACE = "space"; //$NON-NLS-1$
- private static final String TAG_COMMAND = "command"; //$NON-NLS-1$
- private static final String TAG_PARAMETER = "parameter"; //$NON-NLS-1$
- private static final String TAG_ITEM = "item"; //$NON-NLS-1$
- private static final String ATTR_ID = "id"; //$NON-NLS-1$
- private static final String ATTR_LABEL = "label"; //$NON-NLS-1$
- private static final String ATTR_ICON_URI = "iconURI"; //$NON-NLS-1$
- private static final String ATTR_CONTRIBUTION_URI = "contributionURI"; //$NON-NLS-1$
- private static final String ATTR_COMMAND_ID = "commandId"; //$NON-NLS-1$
- private static final String ATTR_NAME = "name"; //$NON-NLS-1$
- private static final String ATTR_VALUE = "value"; //$NON-NLS-1$
- private static final String ATTR_WIDTH = "width"; //$NON-NLS-1$
-
- private static final String VAL_FILL = "fill"; //$NON-NLS-1$
-
- private static final String DATA_ID = "org.xmind.ui.dashboard.itemId"; //$NON-NLS-1$
- private static final String DATA_PARAMETERS = "org.xmind.ui.dashboard.commandParameters"; //$NON-NLS-1$
-
- private static final String STATE_SELECTED_PAGE_ID = "selectedPageId"; //$NON-NLS-1$
-
- private final DashboardPart part;
-
- private final MTabFolder tabFolder;
-
- private Properties nlsProperties = new Properties();
-
- public DashboardContent(final DashboardPart part,
- final MTabFolder tabFolder) {
- this.part = part;
- this.tabFolder = tabFolder;
- loadFromDefaultLocation();
- tabFolder.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- Object page = event.item.getData();
- if (page instanceof IDashboardPage) {
- handlePageSelected((IDashboardPage) page);
- }
- }
- });
- tabFolder.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- MTabItem item = tabFolder.getSelection();
- String pageId = (String) item.getData(DATA_ID);
- if (pageId != null) {
- part.setPersistedState(STATE_SELECTED_PAGE_ID, pageId);
- }
- }
- });
- }
-
- private void loadFromDefaultLocation() {
- // load NLS properties
- nlsProperties = CathyPlugin.getDefault()
- .loadNLSProperties(NLS_PATH_BASE);
-
- // load content xml
- try {
- URL docURL = new URL(CONTENT_URI);
- loadFromURL(docURL);
- } catch (Exception e) {
- CathyPlugin.log(e,
- "Failed to load dashboard content from " + CONTENT_URI); //$NON-NLS-1$
- }
-
- // set primary selection
- MTabItem primarySelection = findPrimarySelection();
- tabFolder.setSelection(primarySelection);
-
- IDashboardPage page = getDashboardPage(primarySelection);
- if (page != null) {
- if (page.getControl() == null || page.getControl().isDisposed()) {
- page.createControl(this.tabFolder.getBody());
- primarySelection.setControl(page.getControl());
- }
- handlePageSelected(page);
- }
- }
-
- private void loadFromURL(URL docURL) throws Exception {
- InputStream docStream = docURL.openStream();
- try {
- Document doc = DocumentBuilderFactory.newInstance()
- .newDocumentBuilder().parse(docStream);
-
- Element rootElement = doc.getDocumentElement();
- if (rootElement == null
- || !TAG_DASHBOARD.equals(rootElement.getNodeName()))
- throw new IllegalArgumentException(
- "No 'dashboard' element in " + CONTENT_URI); //$NON-NLS-1$
-
- readElement(rootElement, tabFolder);
- } finally {
- docStream.close();
- }
- }
-
- private void readElement(Element element, Object parent) throws Exception {
- String tagName = element.getTagName();
- Object item = parent;
- if (parent instanceof MTabFolder) {
- if (TAG_PAGE.equals(tagName)) {
- item = readPage(element, (MTabFolder) parent);
- } else if (TAG_COMMAND.equals(tagName)) {
- item = readCommand(element, (MTabFolder) parent);
- } else if (TAG_SPACE.equals(tagName)) {
- item = readSeparator(element, (MTabFolder) parent);
- } else if (TAG_ITEM.equals(tagName)) {
- item = readSimpleItem(element, (MTabFolder) parent);
- }
- } else if (parent instanceof MTabItem) {
- if (TAG_PARAMETER.equals(tagName)) {
- readCommandParameter(element, (MTabItem) parent);
- }
- }
-
- readChildren(element.getChildNodes(), item);
- }
-
- private void readChildren(NodeList children, Object parent)
- throws Exception {
- int length = children.getLength();
- for (int i = 0; i < length; i++) {
- Node childNode = children.item(i);
- if (childNode.getNodeType() == Node.ELEMENT_NODE) {
- readElement((Element) childNode, parent);
- }
- }
- }
-
- private MTabItem readPage(Element element, MTabFolder tabFolder)
- throws Exception {
- String id = element.getAttribute(ATTR_ID);
- if (id == null || "".equals(id)) //$NON-NLS-1$
- throw new IllegalArgumentException("No id for page."); //$NON-NLS-1$
-
- String contributionURI = element.getAttribute(ATTR_CONTRIBUTION_URI);
- if (contributionURI == null
- || !contributionURI.startsWith("bundleclass://")) //$NON-NLS-1$
- throw new IllegalArgumentException(
- "Invalid contributionURI: " + contributionURI); //$NON-NLS-1$
- String[] contributionPaths = contributionURI.substring(14).split("/"); //$NON-NLS-1$
- if (contributionPaths.length != 2)
- throw new IllegalArgumentException(
- "Invalid contributionURI: " + contributionURI); //$NON-NLS-1$
- String bundleId = contributionPaths[0];
- String className = contributionPaths[1];
- Class> cls;
- try {
- Bundle bundle = Platform.getBundle(bundleId);
- if (bundle == null)
- throw new ClassNotFoundException();
- cls = bundle.loadClass(className);
- } catch (ClassNotFoundException e) {
- // ignore errors caused contribution not found
- return null;
- }
-
- Object contribution = ContextInjectionFactory.make(cls,
- part.getContext());
- if (!(contribution instanceof IDashboardPage))
- throw new IllegalArgumentException(
- "Invalid contribution type: " + contribution); //$NON-NLS-1$
-
- final IDashboardPage page = (IDashboardPage) contribution;
- page.setContext(part);
-
- String label = readLabel(element);
- page.setTitle(label);
-
- ImageDescriptor icon = readIcon(element);
- page.setImageDescriptor(icon);
-
- // add side-bar tab
- MTabItem item = new MTabItem(tabFolder, SWT.RADIO);
-
- item.setText(page.getTitle());
- item.setImage(page.getImage());
-
-// page.createControl(this.tabFolder.getBody());
-// item.setControl(page.getControl());
-
- item.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Control pageControl = page.getControl();
- if (pageControl != null) {
- pageControl.dispose();
- }
- page.dispose();
- }
- });
-
- item.setData(page);
- item.setData(DATA_ID, id);
-
- return item;
- }
-
- private MTabItem readCommand(Element element, MTabFolder tabFolder)
- throws Exception {
- String id = element.getAttribute(ATTR_ID);
- if (id == null || "".equals(id)) //$NON-NLS-1$
- throw new IllegalArgumentException("No id for command."); //$NON-NLS-1$
- final String commandId = element.getAttribute(ATTR_COMMAND_ID);
- if (commandId == null || "".equals(commandId)) //$NON-NLS-1$
- throw new IllegalArgumentException(
- "No command id found for command"); //$NON-NLS-1$
-
- String label = readLabel(element);
- ImageDescriptor icon = readIcon(element);
-
- MTabItem item = new MTabItem(tabFolder, SWT.PUSH);
-
- item.setText(label);
-
- final Image iconImage = icon == null ? null : icon.createImage();
- item.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- iconImage.dispose();
- }
- });
- item.setImage(iconImage);
-
- item.setData(DATA_ID, id);
- item.setData(DATA_PARAMETERS, new Properties());
-
- item.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- Map parameters = new HashMap();
- Properties commandParameters = (Properties) event.widget
- .getData(DATA_PARAMETERS);
- if (commandParameters != null) {
- for (Entry en : commandParameters
- .entrySet()) {
- parameters.put((String) en.getKey(), en.getValue());
- }
- }
- part.executeCommand(commandId, parameters);
- }
- });
- return item;
- }
-
- private MTabItem readSimpleItem(Element element, MTabFolder tabFolder)
- throws Exception {
- String id = element.getAttribute(ATTR_ID);
- if (id == null || "".equals(id)) //$NON-NLS-1$
- throw new IllegalArgumentException("No id for page."); //$NON-NLS-1$
-
- String label = readLabel(element);
- ImageDescriptor icon = readIcon(element);
-
- MTabItem item = new MTabItem(tabFolder, SWT.SIMPLE);
- item.setText(label);
- final Image iconImage = icon.createImage();
- item.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- iconImage.dispose();
- }
- });
- item.setImage(iconImage);
-
- item.setData(DATA_ID, id);
-
- return item;
- }
-
- private MTabItem readSeparator(Element element, MTabFolder tabFolder)
- throws Exception {
- String id = element.getAttribute(ATTR_ID);
- if (id == null || "".equals(id)) //$NON-NLS-1$
- throw new IllegalArgumentException("No id for page."); //$NON-NLS-1$
-
- MTabItem item = new MTabItem(tabFolder, SWT.SEPARATOR);
-
- item.setData(DATA_ID, id);
-
- String width = element.getAttribute(ATTR_WIDTH);
- if (VAL_FILL.equals(width)) {
- item.setWidth(SWT.SEPARATOR_FILL);
- } else if (width != null && !"".equals(width)) { //$NON-NLS-1$
- try {
- int widthValue = Integer.parseInt(width, 10);
- item.setWidth(widthValue);
- } catch (NumberFormatException e) {
- }
- }
-
- return item;
- }
-
- private void readCommandParameter(Element element, MTabItem item) {
- String name = element.getAttribute(ATTR_NAME);
- String value = element.getAttribute(ATTR_VALUE);
- if (name == null || "".equals(name) //$NON-NLS-1$
- || value == null || "".equals(value)) //$NON-NLS-1$
- return;
-
- Properties parameters = (Properties) item.getData(DATA_PARAMETERS);
- if (parameters == null)
- return;
-
- parameters.put(name, value);
- }
-
- private ImageDescriptor readIcon(Element element)
- throws MalformedURLException {
- String iconURI = element.getAttribute(ATTR_ICON_URI);
- ImageDescriptor icon = (iconURI == null || "".equals(iconURI)) //$NON-NLS-1$
- ? null : ImageDescriptor.createFromURL(new URL(iconURI));
- return icon;
- }
-
- private String readLabel(Element element) {
- String label = element.getAttribute(ATTR_LABEL);
- if (label.startsWith("%")) { //$NON-NLS-1$
- String nativeLabel = nlsProperties.getProperty(label.substring(1));
- if (nativeLabel != null) {
- label = nativeLabel;
- }
- }
- return label;
- }
-
- private MTabItem findPrimarySelection() {
- String lastPageId = part.getPersistedState(STATE_SELECTED_PAGE_ID);
- if (lastPageId != null) {
- MTabItem item = getItemById(lastPageId);
- if (item != null)
- return item;
- }
-
- int itemCount = tabFolder.getItemCount();
- for (int i = 0; i < itemCount; i++) {
- MTabItem item = tabFolder.getItem(i);
- if ((item.getStyle() & SWT.RADIO) != 0) {
- return item;
- }
- }
- return null;
- }
-
- public MTabItem getItemById(String pageId) {
- if (pageId == null)
- return null;
- int itemCount = tabFolder.getItemCount();
- for (int i = 0; i < itemCount; i++) {
- MTabItem item = tabFolder.getItem(i);
- if (pageId.equals(item.getData(DATA_ID)))
- return item;
- }
- return null;
- }
-
- public String getItemId(MTabItem item) {
- return (String) item.getData(DATA_ID);
- }
-
- public IDashboardPage getDashboardPage(MTabItem item) {
- Object data = item.getData();
- return data instanceof IDashboardPage ? (IDashboardPage) data : null;
- }
-
- protected void handlePageSelected(final IDashboardPage page) {
- ISelectionProvider selectionProvider = CathyPlugin.getAdapter(page,
- ISelectionProvider.class);
- part.setSelectionProvider(selectionProvider);
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.ui.internal.dashboard.pages.IDashboardPage;
+import org.xmind.ui.tabfolder.MTabFolder;
+import org.xmind.ui.tabfolder.MTabItem;
+import org.xmind.ui.util.XMLUtils;
+
+public class DashboardContent {
+
+ private static final String CONTENT_URI = "platform:/plugin/org.xmind.cathy/dashboard/dashboard.xml"; //$NON-NLS-1$
+ private static final String NLS_PATH_BASE = "dashboard/dashboard"; //$NON-NLS-1$
+
+ private static final String TAG_DASHBOARD = "dashboard"; //$NON-NLS-1$
+ private static final String TAG_PAGE = "page"; //$NON-NLS-1$
+ private static final String TAG_SPACE = "space"; //$NON-NLS-1$
+ private static final String TAG_COMMAND = "command"; //$NON-NLS-1$
+ private static final String TAG_PARAMETER = "parameter"; //$NON-NLS-1$
+ private static final String TAG_ITEM = "item"; //$NON-NLS-1$
+ private static final String ATTR_ID = "id"; //$NON-NLS-1$
+ private static final String ATTR_LABEL = "label"; //$NON-NLS-1$
+ private static final String ATTR_TOOLTIP = "tooltip"; //$NON-NLS-1$
+ private static final String ATTR_ICON_URI = "iconURI"; //$NON-NLS-1$
+ private static final String ATTR_CONTRIBUTION_URI = "contributionURI"; //$NON-NLS-1$
+ private static final String ATTR_COMMAND_ID = "commandId"; //$NON-NLS-1$
+ private static final String ATTR_NAME = "name"; //$NON-NLS-1$
+ private static final String ATTR_VALUE = "value"; //$NON-NLS-1$
+ private static final String ATTR_WIDTH = "width"; //$NON-NLS-1$
+ private static final String ATTR_COLOR = "color"; //$NON-NLS-1$
+
+ private static final String VAL_FILL = "fill"; //$NON-NLS-1$
+
+ private static final String DATA_ID = "org.xmind.ui.dashboard.itemId"; //$NON-NLS-1$
+ private static final String DATA_PARAMETERS = "org.xmind.ui.dashboard.commandParameters"; //$NON-NLS-1$
+
+ private static final String STATE_SELECTED_PAGE_ID = "selectedPageId"; //$NON-NLS-1$
+
+ private final DashboardPart part;
+
+ private final MTabFolder tabFolder;
+
+ private Properties nlsProperties = new Properties();
+
+ public DashboardContent(final DashboardPart part,
+ final MTabFolder tabFolder) {
+ this.part = part;
+ this.tabFolder = tabFolder;
+ loadFromDefaultLocation();
+ tabFolder.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ Object page = event.item.getData();
+ if (page instanceof IDashboardPage) {
+ handlePageSelected((IDashboardPage) page);
+ }
+ }
+ });
+ tabFolder.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ MTabItem item = tabFolder.getSelection();
+ String pageId = (String) item.getData(DATA_ID);
+ if (pageId != null) {
+ part.setPersistedState(STATE_SELECTED_PAGE_ID, pageId);
+ }
+ }
+ });
+ }
+
+ private void loadFromDefaultLocation() {
+ // load NLS properties
+ nlsProperties = CathyPlugin.getDefault()
+ .loadNLSProperties(NLS_PATH_BASE);
+
+ // load content xml
+ try {
+ URL docURL = new URL(CONTENT_URI);
+ loadFromURL(docURL);
+ } catch (Exception e) {
+ CathyPlugin.log(e,
+ "Failed to load dashboard content from " + CONTENT_URI); //$NON-NLS-1$
+ }
+
+ // set primary selection
+ MTabItem primarySelection = findPrimarySelection();
+ tabFolder.setSelection(primarySelection);
+
+ IDashboardPage page = getDashboardPage(primarySelection);
+ if (page != null) {
+ if (page.getControl() == null || page.getControl().isDisposed()) {
+ page.createControl(this.tabFolder.getBody());
+ primarySelection.setControl(page.getControl());
+ }
+ handlePageSelected(page);
+ }
+ }
+
+ private void loadFromURL(URL docURL) throws Exception {
+ InputStream docStream = docURL.openStream();
+ try {
+ Document doc = XMLUtils.getDefaultDocumentBuilder()
+ .parse(docStream);
+
+ Element rootElement = doc.getDocumentElement();
+ if (rootElement == null
+ || !TAG_DASHBOARD.equals(rootElement.getNodeName()))
+ throw new IllegalArgumentException(
+ "No 'dashboard' element in " + CONTENT_URI); //$NON-NLS-1$
+
+ readElement(rootElement, tabFolder);
+ } finally {
+ docStream.close();
+ }
+ }
+
+ private void readElement(Element element, Object parent) throws Exception {
+ String tagName = element.getTagName();
+ Object item = parent;
+ if (parent instanceof MTabFolder) {
+ if (TAG_PAGE.equals(tagName)) {
+ item = readPage(element, (MTabFolder) parent);
+ } else if (TAG_COMMAND.equals(tagName)) {
+ item = readCommand(element, (MTabFolder) parent);
+ } else if (TAG_SPACE.equals(tagName)) {
+ item = readSeparator(element, (MTabFolder) parent);
+ } else if (TAG_ITEM.equals(tagName)) {
+ item = readSimpleItem(element, (MTabFolder) parent);
+ }
+ } else if (parent instanceof MTabItem) {
+ if (TAG_PARAMETER.equals(tagName)) {
+ readCommandParameter(element, (MTabItem) parent);
+ }
+ }
+
+ readChildren(element.getChildNodes(), item);
+ }
+
+ private void readChildren(NodeList children, Object parent)
+ throws Exception {
+ int length = children.getLength();
+ for (int i = 0; i < length; i++) {
+ Node childNode = children.item(i);
+ if (childNode.getNodeType() == Node.ELEMENT_NODE) {
+ readElement((Element) childNode, parent);
+ }
+ }
+ }
+
+ private MTabItem readPage(Element element, MTabFolder tabFolder)
+ throws Exception {
+ String id = element.getAttribute(ATTR_ID);
+ if (id == null || "".equals(id)) //$NON-NLS-1$
+ throw new IllegalArgumentException("No id for page."); //$NON-NLS-1$
+
+ String contributionURI = element.getAttribute(ATTR_CONTRIBUTION_URI);
+ if (contributionURI == null
+ || !contributionURI.startsWith("bundleclass://")) //$NON-NLS-1$
+ throw new IllegalArgumentException(
+ "Invalid contributionURI: " + contributionURI); //$NON-NLS-1$
+ String[] contributionPaths = contributionURI.substring(14).split("/"); //$NON-NLS-1$
+ if (contributionPaths.length != 2)
+ throw new IllegalArgumentException(
+ "Invalid contributionURI: " + contributionURI); //$NON-NLS-1$
+ String bundleId = contributionPaths[0];
+ String className = contributionPaths[1];
+ Class> cls;
+ try {
+ Bundle bundle = Platform.getBundle(bundleId);
+ if (bundle == null)
+ throw new ClassNotFoundException();
+ cls = bundle.loadClass(className);
+ } catch (ClassNotFoundException e) {
+ // ignore errors caused contribution not found
+ return null;
+ }
+
+ Object contribution = ContextInjectionFactory.make(cls,
+ part.getContext());
+ if (!(contribution instanceof IDashboardPage))
+ throw new IllegalArgumentException(
+ "Invalid contribution type: " + contribution); //$NON-NLS-1$
+
+ final IDashboardPage page = (IDashboardPage) contribution;
+ page.setContext(part);
+
+ String label = readLabel(element);
+ page.setTitle(label);
+
+ ImageDescriptor icon = readIcon(element);
+ page.setImageDescriptor(icon);
+
+ // add side-bar tab
+ MTabItem item = new MTabItem(tabFolder, SWT.RADIO);
+
+ item.setText(page.getTitle());
+ String tooltip = readTooltip(element);
+ item.setTooltipText(tooltip);
+ item.setImage(page.getImage());
+
+// page.createControl(this.tabFolder.getBody());
+// item.setControl(page.getControl());
+
+ item.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ Control pageControl = page.getControl();
+ if (pageControl != null) {
+ pageControl.dispose();
+ }
+ page.dispose();
+ }
+ });
+
+ item.setData(page);
+ item.setData(DATA_ID, id);
+
+ return item;
+ }
+
+ private MTabItem readCommand(Element element, MTabFolder tabFolder)
+ throws Exception {
+ String id = element.getAttribute(ATTR_ID);
+ if (id == null || "".equals(id)) //$NON-NLS-1$
+ throw new IllegalArgumentException("No id for command."); //$NON-NLS-1$
+ final String commandId = element.getAttribute(ATTR_COMMAND_ID);
+ if (commandId == null || "".equals(commandId)) //$NON-NLS-1$
+ throw new IllegalArgumentException(
+ "No command id found for command"); //$NON-NLS-1$
+
+ String label = readLabel(element);
+ String tooltip = readTooltip(element);
+ ImageDescriptor icon = readIcon(element);
+
+ MTabItem item = new MTabItem(tabFolder, SWT.PUSH);
+
+ String width = element.getAttribute(ATTR_WIDTH);
+ if (width != null && !"".equals(width)) { //$NON-NLS-1$
+ try {
+ int widthValue = Integer.parseInt(width, 10);
+ item.setWidth(widthValue);
+ } catch (NumberFormatException e) {
+ }
+ }
+
+ item.setText(label);
+ item.setTooltipText(tooltip);
+
+ final Image iconImage = icon == null ? null : icon.createImage();
+ item.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ iconImage.dispose();
+ }
+ });
+ item.setImage(iconImage);
+
+ item.setData(DATA_ID, id);
+ item.setData(DATA_PARAMETERS, new Properties());
+
+ item.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ Map parameters = new HashMap();
+ Properties commandParameters = (Properties) event.widget
+ .getData(DATA_PARAMETERS);
+ if (commandParameters != null) {
+ for (Entry en : commandParameters
+ .entrySet()) {
+ parameters.put((String) en.getKey(), en.getValue());
+ }
+ }
+ part.executeCommand(commandId, parameters);
+ }
+ });
+ return item;
+ }
+
+ private MTabItem readSimpleItem(Element element, MTabFolder tabFolder)
+ throws Exception {
+ String id = element.getAttribute(ATTR_ID);
+ if (id == null || "".equals(id)) //$NON-NLS-1$
+ throw new IllegalArgumentException("No id for page."); //$NON-NLS-1$
+
+ String label = readLabel(element);
+ String tooltip = readTooltip(element);
+ ImageDescriptor icon = readIcon(element);
+
+ MTabItem item = new MTabItem(tabFolder, SWT.SIMPLE);
+ item.setText(label);
+ item.setTooltipText(tooltip);
+ final Image iconImage = icon.createImage();
+ item.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ iconImage.dispose();
+ }
+ });
+ item.setImage(iconImage);
+
+ item.setData(DATA_ID, id);
+
+ return item;
+ }
+
+ private MTabItem readSeparator(Element element, MTabFolder tabFolder)
+ throws Exception {
+ String id = element.getAttribute(ATTR_ID);
+ if (id == null || "".equals(id)) //$NON-NLS-1$
+ throw new IllegalArgumentException("No id for page."); //$NON-NLS-1$
+
+ MTabItem item = new MTabItem(tabFolder, SWT.SEPARATOR);
+
+ item.setData(DATA_ID, id);
+
+ String width = element.getAttribute(ATTR_WIDTH);
+ if (VAL_FILL.equals(width)) {
+ item.setWidth(SWT.SEPARATOR_FILL);
+ } else if (width != null && !"".equals(width)) { //$NON-NLS-1$
+ try {
+ int widthValue = Integer.parseInt(width, 10);
+ item.setWidth(widthValue);
+ } catch (NumberFormatException e) {
+ }
+ }
+
+ String color = element.getAttribute(ATTR_COLOR);
+ if (color != null && !"".equals(color)) //$NON-NLS-1$
+ item.setColor(color);
+
+ return item;
+ }
+
+ private void readCommandParameter(Element element, MTabItem item) {
+ String name = element.getAttribute(ATTR_NAME);
+ String value = element.getAttribute(ATTR_VALUE);
+ if (name == null || "".equals(name) //$NON-NLS-1$
+ || value == null || "".equals(value)) //$NON-NLS-1$
+ return;
+
+ Properties parameters = (Properties) item.getData(DATA_PARAMETERS);
+ if (parameters == null)
+ return;
+
+ parameters.put(name, value);
+ }
+
+ private ImageDescriptor readIcon(Element element)
+ throws MalformedURLException {
+ String iconURI = element.getAttribute(ATTR_ICON_URI);
+ ImageDescriptor icon = (iconURI == null || "".equals(iconURI)) //$NON-NLS-1$
+ ? null : ImageDescriptor.createFromURL(new URL(iconURI));
+ return icon;
+ }
+
+ private String readLabel(Element element) {
+ String label = element.getAttribute(ATTR_LABEL);
+ if (label.startsWith("%")) { //$NON-NLS-1$
+ String nativeLabel = nlsProperties.getProperty(label.substring(1));
+ if (nativeLabel != null) {
+ label = nativeLabel;
+ }
+ }
+ return label;
+ }
+
+ private String readTooltip(Element element) {
+ String tooltip = element.getAttribute(ATTR_TOOLTIP);
+ if (tooltip.startsWith("%")) { //$NON-NLS-1$
+ String nativeTooltip = nlsProperties
+ .getProperty(tooltip.substring(1));
+ if (nativeTooltip != null) {
+ tooltip = nativeTooltip;
+ }
+ }
+ return tooltip;
+ }
+
+ private MTabItem findPrimarySelection() {
+ String lastPageId = part.getPersistedState(STATE_SELECTED_PAGE_ID);
+ if (lastPageId != null) {
+ MTabItem item = getItemById(lastPageId);
+ if (item != null)
+ return item;
+ }
+
+ int itemCount = tabFolder.getItemCount();
+ for (int i = 0; i < itemCount; i++) {
+ MTabItem item = tabFolder.getItem(i);
+ if ((item.getStyle() & SWT.RADIO) != 0) {
+ return item;
+ }
+ }
+ return null;
+ }
+
+ public MTabItem getItemById(String pageId) {
+ if (pageId == null)
+ return null;
+ int itemCount = tabFolder.getItemCount();
+ for (int i = 0; i < itemCount; i++) {
+ MTabItem item = tabFolder.getItem(i);
+ if (pageId.equals(item.getData(DATA_ID)))
+ return item;
+ }
+ return null;
+ }
+
+ public String getItemId(MTabItem item) {
+ return (String) item.getData(DATA_ID);
+ }
+
+ public IDashboardPage getDashboardPage(MTabItem item) {
+ Object data = item.getData();
+ return data instanceof IDashboardPage ? (IDashboardPage) data : null;
+ }
+
+ protected void handlePageSelected(final IDashboardPage page) {
+ ISelectionProvider selectionProvider = CathyPlugin.getAdapter(page,
+ ISelectionProvider.class);
+ part.setSelectionProvider(selectionProvider);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardPart.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardPart.java
index 0e6e9a83f..de5e78520 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardPart.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardPart.java
@@ -1,472 +1,472 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-
-import org.eclipse.core.commands.ParameterizedCommand;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.e4.core.commands.ECommandService;
-import org.eclipse.e4.core.commands.EHandlerService;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.eclipse.e4.core.di.extensions.EventTopic;
-import org.eclipse.e4.ui.di.Focus;
-import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.commands.MCommand;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
-import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
-import org.eclipse.e4.ui.services.EMenuService;
-import org.eclipse.e4.ui.workbench.UIEvents;
-import org.eclipse.e4.ui.workbench.modeling.EModelService;
-import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbenchCommandConstants;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.commands.IElementUpdater;
-import org.eclipse.ui.internal.handlers.WizardHandler;
-import org.eclipse.ui.statushandlers.StatusManager;
-import org.osgi.service.event.Event;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.cathy.internal.ICathyConstants;
-import org.xmind.ui.internal.dashboard.pages.IDashboardContext;
-import org.xmind.ui.internal.dashboard.pages.IDashboardPage;
-import org.xmind.ui.internal.e4handlers.DisabledHandler;
-import org.xmind.ui.tabfolder.MTabFolder;
-import org.xmind.ui.tabfolder.MTabItem;
-
-/**
- * A view that shows the Dashboard for the Cathy application.
- *
- * @author Frank Shaka
- * @since 3.6.0
- */
-public class DashboardPart implements IDashboardContext {
-
- private static final String PERSISTED_STATE_KEY_PREFIX = "org.xmind.cathy.dashboard/"; //$NON-NLS-1$
-
- /**
- * A set of identifiers of commands that the Dashboard allows to be enabled.
- * All other commands registered in the application will be disabled when
- * the Dashboard is showing.
- *
- * @see #disableUnwantedCommands()
- */
- private static final String[] AVAILABLE_COMMAND_IDS = {
- "org.xmind.ui.command.showDashboard", //$NON-NLS-1$
- "org.xmind.ui.command.toggleDashboard", //$NON-NLS-1$
- "org.xmind.ui.command.welcome", //$NON-NLS-1$
- "org.xmind.ui.command.openWorkbook", //$NON-NLS-1$
- "org.xmind.ui.command.openHomeMap", //$NON-NLS-1$
- "org.xmind.ui.command.newWorkbook", //$NON-NLS-1$
- "org.xmind.ui.command.newFromTemplate", //$NON-NLS-1$
- "org.xmind.ui.command.clearWorkbookHistory", //$NON-NLS-1$
- "net.xmind.ui.command.checkForUpdates", //$NON-NLS-1$
- "net.xmind.ui.command.subscribeNewsletter", //$NON-NLS-1$
- "net.xmind.ui.command.feedback", //$NON-NLS-1$
- "net.xmind.ui.command.signIn", //$NON-NLS-1$
- "net.xmind.ui.command.signOut", //$NON-NLS-1$
- "net.xmind.ui.command.activatePro", //$NON-NLS-1$
- "net.xmind.ui.command.goFeaturedMaps", //$NON-NLS-1$
- "org.xmind.ui.command.showModelPart", //$NON-NLS-1$
- IWorkbenchCommandConstants.FILE_NEW,
- IWorkbenchCommandConstants.FILE_IMPORT,
- IWorkbenchCommandConstants.FILE_RESTART,
- IWorkbenchCommandConstants.FILE_EXIT,
- IWorkbenchCommandConstants.WINDOW_CLOSE_PART,
- IWorkbenchCommandConstants.WINDOW_PREFERENCES,
- IWorkbenchCommandConstants.VIEWS_SHOW_VIEW,
- IWorkbenchCommandConstants.WINDOW_RESET_PERSPECTIVE,
- IWorkbenchCommandConstants.WINDOW_ACTIVATE_EDITOR,
- IWorkbenchCommandConstants.WINDOW_NEXT_EDITOR,
- IWorkbenchCommandConstants.WINDOW_NEXT_VIEW,
- IWorkbenchCommandConstants.WINDOW_PREVIOUS_EDITOR,
- IWorkbenchCommandConstants.WINDOW_PREVIOUS_VIEW,
- IWorkbenchCommandConstants.HELP_HELP_CONTENTS,
- IWorkbenchCommandConstants.HELP_ABOUT,
- IWorkbenchCommandConstants.WINDOW_SHOW_KEY_ASSIST //
- };
-
- @Inject
- private IEclipseContext context;
-
- @Inject
- private MPart partModel;
-
- @Inject
- private EHandlerService handlerService;
-
- @Inject
- private ECommandService commandService;
-
- @Inject
- private ESelectionService selectionService;
-
- @Inject
- private EMenuService menuService;
-
- @Inject
- private EModelService modelService;
-
- @Inject
- private MApplication application;
-
- private MTabFolder tabFolder;
-
- private Set availableCommandIds;
-
- private DashboardContent content;
-
- private ISelectionProvider selectionProvider = null;
-
- private ISelectionChangedListener selectionChangedListener = new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- handleSelectionChanged(event);
- }
- };
-
- protected IEclipseContext getContext() {
- return context;
- }
-
- @PostConstruct
- public void postConstruct(Composite parent) {
-
- //
- context.set(IDashboardContext.class, this);
-
- tabFolder = new MTabFolder(parent);
- ResourceManager resourceManager = new LocalResourceManager(
- JFaceResources.getResources(), tabFolder);
- tabFolder.setStyleProvider(new DashboardStyleProvider(resourceManager));
- tabFolder.setBackground(
- parent.getDisplay().getSystemColor(SWT.COLOR_TRANSPARENT));
- tabFolder.addListener(SWT.Selection, new Listener() {
- public void handleEvent(org.eclipse.swt.widgets.Event event) {
- handlePageSelected();
- }
- });
-
- availableCommandIds = new HashSet();
- availableCommandIds.addAll(Arrays.asList(AVAILABLE_COMMAND_IDS));
-
- content = new DashboardContent(this, tabFolder);
-
- disableUnwantedCommands();
- }
-
- private void handlePageSelected() {
- if (tabFolder == null || content == null) {
- return;
- }
- MTabItem item = tabFolder.getSelection();
- String pageId = item == null ? null : content.getItemId(item);
- partModel.getTransientData()
- .put(ICathyConstants.DATA_DASHBOARD_SELECTED_PAGE_ID, pageId);
- }
-
- protected void executeCommand(String commandId,
- Map parameters) {
- if (commandService == null || handlerService == null)
- return;
-
- ParameterizedCommand command = commandService.createCommand(commandId,
- parameters);
- if (command == null)
- return;
-
- handlerService.executeHandler(command);
- }
-
- public void setSelectionProvider(ISelectionProvider selectionProvider) {
- ISelectionProvider oldSelectionProvider = this.selectionProvider;
- if (selectionProvider == oldSelectionProvider)
- return;
- if (oldSelectionProvider != null) {
- oldSelectionProvider
- .removeSelectionChangedListener(selectionChangedListener);
- }
- this.selectionProvider = selectionProvider;
- if (selectionProvider != null) {
- selectionProvider
- .addSelectionChangedListener(selectionChangedListener);
- }
- if (selectionService != null) {
- selectionService.setSelection(selectionProvider == null ? null
- : selectionProvider.getSelection());
- }
- }
-
- private void handleSelectionChanged(SelectionChangedEvent event) {
- if (selectionService != null) {
- selectionService.setSelection(event.getSelection());
- }
- }
-
- /**
- * Disables almost all commands unless explicitly kept enabled, to make sure
- * that the user can't trigger commands that may not be appropriate during
- * the appearance of the Dashboard.
- *
- * We activate a {@link DisabledHandler} handler object for each command to
- * be disabled. These handlers are registered within the context of this
- * view only, so that they do not override real handlers when the Dashboard
- * is hidden.
- *
- */
- private void disableUnwantedCommands() {
- if (handlerService == null || application == null)
- return;
-
- for (MCommand command : application.getCommands()) {
- String commandId = command.getElementId();
- if (!availableCommandIds.contains(commandId)) {
- handlerService.activateHandler(commandId,
- new DisabledHandler(findElementUpdater(commandId)));
- }
- }
- }
-
- /**
- * Finds an element updater that knows how to decorate UI elements like the
- * real handler of the command.
- *
- * @param commandId
- * the identifier of the command to match
- * @return
- */
- private IElementUpdater findElementUpdater(String commandId) {
- if (IWorkbenchCommandConstants.FILE_EXPORT.equals(commandId)) {
- return new WizardHandler.Export();
- } else if (IWorkbenchCommandConstants.FILE_IMPORT.equals(commandId)) {
- return new WizardHandler.Import();
- }
- return null;
- }
-
- @PreDestroy
- public void preDestroy() {
- this.content = null;
- if (this.tabFolder != null) {
- this.tabFolder.dispose();
- this.tabFolder = null;
- }
- }
-
- public void hideDashboard() {
- MWindow window = findWindowFor(partModel);
- if (window == null) {
- CathyPlugin.log("Failed to find window for Dashboard part."); //$NON-NLS-1$
- return;
- }
-
- if (window.getTags().contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
- window.getTags().remove(ICathyConstants.TAG_SHOW_DASHBOARD);
- }
- }
-
- private static MWindow findWindowFor(MUIElement element) {
- if (element == null)
- return null;
- if (element instanceof MWindow)
- return (MWindow) element;
- MPlaceholder placeholder = element.getCurSharedRef();
- if (placeholder != null)
- return findWindowFor(placeholder);
- return findWindowFor(element.getParent());
- }
-
- @Inject
- @Optional
- public void subscribeDashboardTransientData(
- @EventTopic(UIEvents.ApplicationElement.TOPIC_TRANSIENTDATA) Event event) {
- if (partModel == null
- || partModel != event.getProperty(UIEvents.EventTags.ELEMENT))
- return;
-
- Object selectedPageId = partModel.getTransientData()
- .get(ICathyConstants.DATA_DASHBOARD_SELECTED_PAGE_ID);
- if (selectedPageId == null || !(selectedPageId instanceof String))
- return;
-
- if (this.tabFolder == null || content == null)
- return;
-
- MTabItem item = content.getItemById((String) selectedPageId);
- IDashboardPage dashboardPage = content.getDashboardPage(item);
- if (dashboardPage != null) {
- Control control = dashboardPage.getControl();
- if (control == null || control.isDisposed()) {
- dashboardPage.createControl(this.tabFolder.getBody());
- item.setControl(dashboardPage.getControl());
- }
- dashboardPage.setFocus();
- this.tabFolder.setSelection(item);
- }
- }
-
- @Focus
- public void setFocus() {
- if (tabFolder != null && !tabFolder.isDisposed() && content != null) {
- MTabItem item = tabFolder.getSelection();
- if (item != null) {
- IDashboardPage page = content.getDashboardPage(item);
- if (page != null) {
- page.setFocus();
- return;
- } else {
- Control control = item.getControl();
- if (control != null) {
- control.setFocus();
- return;
- }
- }
- }
- tabFolder.setFocus();
- }
- }
-
- public T getAdapter(Class adapter) {
- if (adapter == MPart.class)
- return adapter.cast(partModel);
- if (context != null)
- return context.get(adapter);
- return null;
- }
-
- public void registerAvailableCommandId(String commandId) {
- availableCommandIds.add(commandId);
- }
-
- public boolean registerContextMenu(Object menuParent, final String menuId) {
- if (!(menuParent instanceof Control) || menuService == null
- || partModel == null) {
- return false;
- }
- Control parentControl = (Control) menuParent;
- MPopupMenu menuModel = null;
- for (MMenu item : partModel.getMenus()) {
- if (menuId.equals(item.getElementId())
- && item instanceof MPopupMenu) {
- menuModel = (MPopupMenu) item;
- break;
- }
- }
- if (menuModel == null) {
- menuModel = modelService.createModelElement(MPopupMenu.class);
- menuModel.setElementId(menuId);
- menuModel.getTags().add("menuContribution:popup"); //$NON-NLS-1$
- partModel.getMenus().add(menuModel);
- }
-
- if (menuModel.getWidget() instanceof Menu) {
- Menu menu = (Menu) menuModel.getWidget();
- parentControl.setMenu(menu);
- return true;
- }
-
- return menuService.registerContextMenu(parentControl, menuId);
- }
-
- public boolean openEditor(final IEditorInput input, final String editorId) {
- final IWorkbenchPage page = context.get(IWorkbenchPage.class);
- if (page == null)
- return false;
- try {
- page.openEditor(input, editorId);
- return true;
- } catch (PartInitException e) {
- StatusManager.getManager().handle(new Status(IStatus.ERROR,
- CathyPlugin.PLUGIN_ID, e.getMessage(), e),
- StatusManager.SHOW);
- return false;
- }
- }
-
- public boolean showView(final String viewId) {
- final IWorkbenchPage page = context.get(IWorkbenchPage.class);
- if (page == null)
- return false;
-
- try {
- page.showView(viewId);
- return true;
- } catch (PartInitException e) {
- StatusManager.getManager().handle(new Status(IStatus.ERROR,
- CathyPlugin.PLUGIN_ID, e.getMessage(), e),
- StatusManager.SHOW);
- return false;
- }
- }
-
- /*
- * (non-Javadoc)
- * @see
- * org.xmind.ui.internal.dashboard.pages.IDashboardContext#getPersistedState
- * (java.lang.String)
- */
- public String getPersistedState(String key) {
- Assert.isLegal(key != null);
- return partModel.getPersistedState()
- .get(PERSISTED_STATE_KEY_PREFIX + key);
- }
-
- /*
- * (non-Javadoc)
- * @see
- * org.xmind.ui.internal.dashboard.pages.IDashboardContext#setPersistedState
- * (java.lang.String, java.lang.String)
- */
- public void setPersistedState(String key, String value) {
- Assert.isLegal(key != null);
- if (value == null) {
- partModel.getPersistedState()
- .remove(PERSISTED_STATE_KEY_PREFIX + key);
- } else {
- partModel.getPersistedState().put(PERSISTED_STATE_KEY_PREFIX + key,
- value);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.xmind.ui.internal.dashboard.pages.IDashboardContext#
- * getContextVariable(java.lang.Class)
- */
- public T getContextVariable(Class key) {
- return context.get(key);
- }
-
- /*
- * (non-Javadoc)
- * @see org.xmind.ui.internal.dashboard.pages.IDashboardContext#
- * getContextVariable(java.lang.String)
- */
- public Object getContextVariable(String key) {
- return context.get(key);
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.core.di.extensions.EventTopic;
+import org.eclipse.e4.ui.di.Focus;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
+import org.eclipse.e4.ui.services.EMenuService;
+import org.eclipse.e4.ui.workbench.UIEvents;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbenchCommandConstants;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.internal.handlers.WizardHandler;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.osgi.service.event.Event;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.cathy.internal.ICathyConstants;
+import org.xmind.ui.internal.dashboard.pages.IDashboardContext;
+import org.xmind.ui.internal.dashboard.pages.IDashboardPage;
+import org.xmind.ui.internal.e4handlers.DisabledHandler;
+import org.xmind.ui.tabfolder.MTabFolder;
+import org.xmind.ui.tabfolder.MTabItem;
+
+/**
+ * A view that shows the Dashboard for the Cathy application.
+ *
+ * @author Frank Shaka
+ * @since 3.6.0
+ */
+public class DashboardPart implements IDashboardContext {
+
+ private static final String PERSISTED_STATE_KEY_PREFIX = "org.xmind.cathy.dashboard/"; //$NON-NLS-1$
+
+ /**
+ * A set of identifiers of commands that the Dashboard allows to be enabled.
+ * All other commands registered in the application will be disabled when
+ * the Dashboard is showing.
+ *
+ * @see #disableUnwantedCommands()
+ */
+ private static final String[] AVAILABLE_COMMAND_IDS = {
+ "org.xmind.ui.command.showDashboard", //$NON-NLS-1$
+ "org.xmind.ui.command.toggleDashboard", //$NON-NLS-1$
+ "org.xmind.ui.command.welcome", //$NON-NLS-1$
+ "org.xmind.ui.command.openWorkbook", //$NON-NLS-1$
+ "org.xmind.ui.command.openHomeMap", //$NON-NLS-1$
+ "org.xmind.ui.command.newWorkbook", //$NON-NLS-1$
+ "org.xmind.ui.command.newFromTemplate", //$NON-NLS-1$
+ "org.xmind.ui.command.clearWorkbookHistory", //$NON-NLS-1$
+ "net.xmind.ui.command.checkForUpdates", //$NON-NLS-1$
+ "net.xmind.ui.command.subscribeNewsletter", //$NON-NLS-1$
+ "net.xmind.ui.command.feedback", //$NON-NLS-1$
+ "net.xmind.ui.command.signIn", //$NON-NLS-1$
+ "net.xmind.ui.command.signOut", //$NON-NLS-1$
+ "net.xmind.ui.command.activatePro", //$NON-NLS-1$
+ "net.xmind.ui.command.goFeaturedMaps", //$NON-NLS-1$
+ "org.xmind.ui.command.showModelPart", //$NON-NLS-1$
+ IWorkbenchCommandConstants.FILE_NEW,
+ IWorkbenchCommandConstants.FILE_IMPORT,
+ IWorkbenchCommandConstants.FILE_RESTART,
+ IWorkbenchCommandConstants.FILE_EXIT,
+ IWorkbenchCommandConstants.WINDOW_CLOSE_PART,
+ IWorkbenchCommandConstants.WINDOW_PREFERENCES,
+ IWorkbenchCommandConstants.VIEWS_SHOW_VIEW,
+ IWorkbenchCommandConstants.WINDOW_RESET_PERSPECTIVE,
+ IWorkbenchCommandConstants.WINDOW_ACTIVATE_EDITOR,
+ IWorkbenchCommandConstants.WINDOW_NEXT_EDITOR,
+ IWorkbenchCommandConstants.WINDOW_NEXT_VIEW,
+ IWorkbenchCommandConstants.WINDOW_PREVIOUS_EDITOR,
+ IWorkbenchCommandConstants.WINDOW_PREVIOUS_VIEW,
+ IWorkbenchCommandConstants.HELP_HELP_CONTENTS,
+ IWorkbenchCommandConstants.HELP_ABOUT,
+ IWorkbenchCommandConstants.WINDOW_SHOW_KEY_ASSIST //
+ };
+
+ @Inject
+ private IEclipseContext context;
+
+ @Inject
+ private MPart partModel;
+
+ @Inject
+ private EHandlerService handlerService;
+
+ @Inject
+ private ECommandService commandService;
+
+ @Inject
+ private ESelectionService selectionService;
+
+ @Inject
+ private EMenuService menuService;
+
+ @Inject
+ private EModelService modelService;
+
+ @Inject
+ private MApplication application;
+
+ private MTabFolder tabFolder;
+
+ private Set availableCommandIds;
+
+ private DashboardContent content;
+
+ private ISelectionProvider selectionProvider = null;
+
+ private ISelectionChangedListener selectionChangedListener = new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ handleSelectionChanged(event);
+ }
+ };
+
+ protected IEclipseContext getContext() {
+ return context;
+ }
+
+ @PostConstruct
+ public void postConstruct(Composite parent) {
+
+ //
+ context.set(IDashboardContext.class, this);
+
+ tabFolder = new MTabFolder(parent);
+ ResourceManager resourceManager = new LocalResourceManager(
+ JFaceResources.getResources(), tabFolder);
+ tabFolder.setStyleProvider(new DashboardStyleProvider(resourceManager));
+ tabFolder.setBackground(
+ parent.getDisplay().getSystemColor(SWT.COLOR_TRANSPARENT));
+ tabFolder.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(org.eclipse.swt.widgets.Event event) {
+ handlePageSelected();
+ }
+ });
+
+ availableCommandIds = new HashSet();
+ availableCommandIds.addAll(Arrays.asList(AVAILABLE_COMMAND_IDS));
+
+ content = new DashboardContent(this, tabFolder);
+
+ disableUnwantedCommands();
+ }
+
+ private void handlePageSelected() {
+ if (tabFolder == null || content == null) {
+ return;
+ }
+ MTabItem item = tabFolder.getSelection();
+ String pageId = item == null ? null : content.getItemId(item);
+ partModel.getTransientData()
+ .put(ICathyConstants.DATA_DASHBOARD_SELECTED_PAGE_ID, pageId);
+ }
+
+ protected void executeCommand(String commandId,
+ Map parameters) {
+ if (commandService == null || handlerService == null)
+ return;
+
+ ParameterizedCommand command = commandService.createCommand(commandId,
+ parameters);
+ if (command == null)
+ return;
+
+ handlerService.executeHandler(command);
+ }
+
+ public void setSelectionProvider(ISelectionProvider selectionProvider) {
+ ISelectionProvider oldSelectionProvider = this.selectionProvider;
+ if (selectionProvider == oldSelectionProvider)
+ return;
+ if (oldSelectionProvider != null) {
+ oldSelectionProvider
+ .removeSelectionChangedListener(selectionChangedListener);
+ }
+ this.selectionProvider = selectionProvider;
+ if (selectionProvider != null) {
+ selectionProvider
+ .addSelectionChangedListener(selectionChangedListener);
+ }
+ if (selectionService != null) {
+ selectionService.setSelection(selectionProvider == null ? null
+ : selectionProvider.getSelection());
+ }
+ }
+
+ private void handleSelectionChanged(SelectionChangedEvent event) {
+ if (selectionService != null) {
+ selectionService.setSelection(event.getSelection());
+ }
+ }
+
+ /**
+ * Disables almost all commands unless explicitly kept enabled, to make sure
+ * that the user can't trigger commands that may not be appropriate during
+ * the appearance of the Dashboard.
+ *
+ * We activate a {@link DisabledHandler} handler object for each command to
+ * be disabled. These handlers are registered within the context of this
+ * view only, so that they do not override real handlers when the Dashboard
+ * is hidden.
+ *
+ */
+ private void disableUnwantedCommands() {
+ if (handlerService == null || application == null)
+ return;
+
+ for (MCommand command : application.getCommands()) {
+ String commandId = command.getElementId();
+ if (!availableCommandIds.contains(commandId)) {
+ handlerService.activateHandler(commandId,
+ new DisabledHandler(findElementUpdater(commandId)));
+ }
+ }
+ }
+
+ /**
+ * Finds an element updater that knows how to decorate UI elements like the
+ * real handler of the command.
+ *
+ * @param commandId
+ * the identifier of the command to match
+ * @return
+ */
+ private IElementUpdater findElementUpdater(String commandId) {
+ if (IWorkbenchCommandConstants.FILE_EXPORT.equals(commandId)) {
+ return new WizardHandler.Export();
+ } else if (IWorkbenchCommandConstants.FILE_IMPORT.equals(commandId)) {
+ return new WizardHandler.Import();
+ }
+ return null;
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ this.content = null;
+ if (this.tabFolder != null) {
+ this.tabFolder.dispose();
+ this.tabFolder = null;
+ }
+ }
+
+ public void hideDashboard() {
+ MWindow window = findWindowFor(partModel);
+ if (window == null) {
+ CathyPlugin.log("Failed to find window for Dashboard part."); //$NON-NLS-1$
+ return;
+ }
+
+ if (window.getTags().contains(ICathyConstants.TAG_SHOW_DASHBOARD)) {
+ window.getTags().remove(ICathyConstants.TAG_SHOW_DASHBOARD);
+ }
+ }
+
+ private static MWindow findWindowFor(MUIElement element) {
+ if (element == null)
+ return null;
+ if (element instanceof MWindow)
+ return (MWindow) element;
+ MPlaceholder placeholder = element.getCurSharedRef();
+ if (placeholder != null)
+ return findWindowFor(placeholder);
+ return findWindowFor(element.getParent());
+ }
+
+ @Inject
+ @Optional
+ public void subscribeDashboardTransientData(
+ @EventTopic(UIEvents.ApplicationElement.TOPIC_TRANSIENTDATA) Event event) {
+ if (partModel == null
+ || partModel != event.getProperty(UIEvents.EventTags.ELEMENT))
+ return;
+
+ Object selectedPageId = partModel.getTransientData()
+ .get(ICathyConstants.DATA_DASHBOARD_SELECTED_PAGE_ID);
+ if (selectedPageId == null || !(selectedPageId instanceof String))
+ return;
+
+ if (this.tabFolder == null || content == null)
+ return;
+
+ MTabItem item = content.getItemById((String) selectedPageId);
+ IDashboardPage dashboardPage = content.getDashboardPage(item);
+ if (dashboardPage != null) {
+ Control control = dashboardPage.getControl();
+ if (control == null || control.isDisposed()) {
+ dashboardPage.createControl(this.tabFolder.getBody());
+ item.setControl(dashboardPage.getControl());
+ }
+ dashboardPage.setFocus();
+ this.tabFolder.setSelection(item);
+ }
+ }
+
+ @Focus
+ public void setFocus() {
+ if (tabFolder != null && !tabFolder.isDisposed() && content != null) {
+ MTabItem item = tabFolder.getSelection();
+ if (item != null) {
+ IDashboardPage page = content.getDashboardPage(item);
+ if (page != null) {
+ page.setFocus();
+ return;
+ } else {
+ Control control = item.getControl();
+ if (control != null) {
+ control.setFocus();
+ return;
+ }
+ }
+ }
+ tabFolder.setFocus();
+ }
+ }
+
+ public T getAdapter(Class adapter) {
+ if (adapter == MPart.class)
+ return adapter.cast(partModel);
+ if (context != null)
+ return context.get(adapter);
+ return null;
+ }
+
+ public void registerAvailableCommandId(String commandId) {
+ availableCommandIds.add(commandId);
+ }
+
+ public boolean registerContextMenu(Object menuParent, final String menuId) {
+ if (!(menuParent instanceof Control) || menuService == null
+ || partModel == null) {
+ return false;
+ }
+ Control parentControl = (Control) menuParent;
+ MPopupMenu menuModel = null;
+ for (MMenu item : partModel.getMenus()) {
+ if (menuId.equals(item.getElementId())
+ && item instanceof MPopupMenu) {
+ menuModel = (MPopupMenu) item;
+ break;
+ }
+ }
+ if (menuModel == null) {
+ menuModel = modelService.createModelElement(MPopupMenu.class);
+ menuModel.setElementId(menuId);
+ menuModel.getTags().add("menuContribution:popup"); //$NON-NLS-1$
+ partModel.getMenus().add(menuModel);
+ }
+
+ if (menuModel.getWidget() instanceof Menu) {
+ Menu menu = (Menu) menuModel.getWidget();
+ parentControl.setMenu(menu);
+ return true;
+ }
+
+ return menuService.registerContextMenu(parentControl, menuId);
+ }
+
+ public boolean openEditor(final IEditorInput input, final String editorId) {
+ final IWorkbenchPage page = context.get(IWorkbenchPage.class);
+ if (page == null)
+ return false;
+ try {
+ page.openEditor(input, editorId);
+ return true;
+ } catch (PartInitException e) {
+ StatusManager.getManager().handle(new Status(IStatus.ERROR,
+ CathyPlugin.PLUGIN_ID, e.getMessage(), e),
+ StatusManager.SHOW);
+ return false;
+ }
+ }
+
+ public boolean showView(final String viewId) {
+ final IWorkbenchPage page = context.get(IWorkbenchPage.class);
+ if (page == null)
+ return false;
+
+ try {
+ page.showView(viewId);
+ return true;
+ } catch (PartInitException e) {
+ StatusManager.getManager().handle(new Status(IStatus.ERROR,
+ CathyPlugin.PLUGIN_ID, e.getMessage(), e),
+ StatusManager.SHOW);
+ return false;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.xmind.ui.internal.dashboard.pages.IDashboardContext#getPersistedState
+ * (java.lang.String)
+ */
+ public String getPersistedState(String key) {
+ Assert.isLegal(key != null);
+ return partModel.getPersistedState()
+ .get(PERSISTED_STATE_KEY_PREFIX + key);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.xmind.ui.internal.dashboard.pages.IDashboardContext#setPersistedState
+ * (java.lang.String, java.lang.String)
+ */
+ public void setPersistedState(String key, String value) {
+ Assert.isLegal(key != null);
+ if (value == null) {
+ partModel.getPersistedState()
+ .remove(PERSISTED_STATE_KEY_PREFIX + key);
+ } else {
+ partModel.getPersistedState().put(PERSISTED_STATE_KEY_PREFIX + key,
+ value);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.xmind.ui.internal.dashboard.pages.IDashboardContext#
+ * getContextVariable(java.lang.Class)
+ */
+ public T getContextVariable(Class key) {
+ return context.get(key);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.xmind.ui.internal.dashboard.pages.IDashboardContext#
+ * getContextVariable(java.lang.String)
+ */
+ public Object getContextVariable(String key) {
+ return context.get(key);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardStyleProvider.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardStyleProvider.java
index 29a4ddf55..ca16a6ea7 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardStyleProvider.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/DashboardStyleProvider.java
@@ -1,125 +1,125 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jface.resource.ColorDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.RGB;
-import org.xmind.ui.resources.ColorUtils;
-import org.xmind.ui.tabfolder.MTabFolder;
-import org.xmind.ui.tabfolder.MTabItem;
-import org.xmind.ui.util.StyleProvider;
-
-public class DashboardStyleProvider extends StyleProvider {
-
- private ResourceManager resourceManager;
-
- private Map keyToRGB = new HashMap();
-
- public DashboardStyleProvider(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
-
- @Override
- public Color getColor(Object widget, String key) {
- String defaultValue = null;
- if (widget instanceof MTabItem) {
- MTabItem item = (MTabItem) widget;
- if (FILL.equals(key)
- && (item.isSelected() || item.isPreselected())) {
- defaultValue = "#FFFFFF"; //$NON-NLS-1$
- } else if (TEXT.equals(key)) {
- defaultValue = "#FFFFFF"; //$NON-NLS-1$
- }
- } else if (widget instanceof MTabFolder) {
- if (MTabFolder.TAB_BAR.equals(key)) {
- defaultValue = "#535f5e"; //$NON-NLS-1$
- }
- if (MTabFolder.BODY.equals(key)) {
- defaultValue = "#F2F2F2"; //$NON-NLS-1$
- }
- }
- if (defaultValue != null) {
- RGB rgb = ColorUtils.toRGB(defaultValue);
- if (keyToRGB.containsKey(key))
- rgb = keyToRGB.get(key);
- return (Color) resourceManager.get(ColorDescriptor.createFrom(rgb));
- }
- return super.getColor(widget, key);
- }
-
- @Override
- public int getAlpha(Object widget, String key, int defaultValue) {
- if (widget instanceof MTabItem) {
- MTabItem item = (MTabItem) widget;
- if (FILL.equals(key)) {
- if (item.isSelected())
- return 0x26;
- if (item.isPreselected())
- return 0x13;
- }
- }
- return super.getAlpha(widget, key, defaultValue);
- }
-
- @Override
- public Font getFont(Object widget, String key) {
- if (widget instanceof MTabItem) {
- if (TEXT.equals(key))
- return (Font) resourceManager.get(JFaceResources
- .getDefaultFontDescriptor().setHeight(12));
- }
- return super.getFont(widget, key);
- }
-
- @Override
- public int getWidth(Object widget, String key, int defaultValue) {
- if (widget instanceof MTabItem) {
- if (IMAGE.equals(key))
- return 56;
- if (MARGIN.equals(key))
- return 3;
- if (SEPARATOR.equals(key))
- return 2;
- if (key == null)
- return 72;
- }
- return super.getWidth(widget, key, defaultValue);
- }
-
- @Override
- public int getHeight(Object widget, String key, int defaultValue) {
- if (widget instanceof MTabItem) {
- if (IMAGE.equals(key))
- return 45;
- if (MARGIN.equals(key))
- return 6;
- if (SEPARATOR.equals(key))
- return 2;
- if (key == null)
- return 74;
- }
- return super.getHeight(widget, key, defaultValue);
- }
-
- @Override
- public int getPosition(Object widget, String key, int defaultValue) {
- if (widget instanceof MTabItem) {
- if (TEXT.equals(key))
- return SWT.BOTTOM;
- } else if (widget instanceof MTabFolder) {
- if (MTabFolder.TAB_BAR.equals(key))
- return SWT.LEFT;
- }
- return super.getPosition(widget, key, defaultValue);
- }
-
- public void setColor(String key, RGB value) {
- keyToRGB.put(key, value);
- }
+package org.xmind.cathy.internal.dashboard;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.resource.ColorDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.RGB;
+import org.xmind.ui.resources.ColorUtils;
+import org.xmind.ui.tabfolder.MTabFolder;
+import org.xmind.ui.tabfolder.MTabItem;
+import org.xmind.ui.util.StyleProvider;
+
+public class DashboardStyleProvider extends StyleProvider {
+
+ private ResourceManager resourceManager;
+
+ private Map keyToRGB = new HashMap();
+
+ public DashboardStyleProvider(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
+
+ @Override
+ public Color getColor(Object widget, String key) {
+ String defaultValue = null;
+ if (widget instanceof MTabItem) {
+ MTabItem item = (MTabItem) widget;
+ if (FILL.equals(key)
+ && (item.isSelected() || item.isPreselected())) {
+ defaultValue = "#FFFFFF"; //$NON-NLS-1$
+ } else if (TEXT.equals(key)) {
+ defaultValue = "#FFFFFF"; //$NON-NLS-1$
+ }
+ } else if (widget instanceof MTabFolder) {
+ if (MTabFolder.TAB_BAR.equals(key)) {
+ defaultValue = "#535f5e"; //$NON-NLS-1$
+ }
+ if (MTabFolder.BODY.equals(key)) {
+ defaultValue = "#F2F2F2"; //$NON-NLS-1$
+ }
+ }
+ if (defaultValue != null) {
+ RGB rgb = ColorUtils.toRGB(defaultValue);
+ if (keyToRGB.containsKey(key))
+ rgb = keyToRGB.get(key);
+ return (Color) resourceManager.get(ColorDescriptor.createFrom(rgb));
+ }
+ return super.getColor(widget, key);
+ }
+
+ @Override
+ public int getAlpha(Object widget, String key, int defaultValue) {
+ if (widget instanceof MTabItem) {
+ MTabItem item = (MTabItem) widget;
+ if (FILL.equals(key)) {
+ if (item.isSelected())
+ return 0x26;
+ if (item.isPreselected())
+ return 0x13;
+ }
+ }
+ return super.getAlpha(widget, key, defaultValue);
+ }
+
+ @Override
+ public Font getFont(Object widget, String key) {
+ if (widget instanceof MTabItem) {
+ if (TEXT.equals(key))
+ return (Font) resourceManager.get(JFaceResources
+ .getDefaultFontDescriptor().setHeight(12));
+ }
+ return super.getFont(widget, key);
+ }
+
+ @Override
+ public int getWidth(Object widget, String key, int defaultValue) {
+ if (widget instanceof MTabItem) {
+ if (IMAGE.equals(key))
+ return 56;
+ if (MARGIN.equals(key))
+ return 3;
+ if (SEPARATOR.equals(key))
+ return 2;
+ if (key == null)
+ return 72;
+ }
+ return super.getWidth(widget, key, defaultValue);
+ }
+
+ @Override
+ public int getHeight(Object widget, String key, int defaultValue) {
+ if (widget instanceof MTabItem) {
+ if (IMAGE.equals(key))
+ return 45;
+ if (MARGIN.equals(key))
+ return 6;
+ if (SEPARATOR.equals(key))
+ return 2;
+ if (key == null)
+ return 74;
+ }
+ return super.getHeight(widget, key, defaultValue);
+ }
+
+ @Override
+ public int getPosition(Object widget, String key, int defaultValue) {
+ if (widget instanceof MTabItem) {
+ if (TEXT.equals(key))
+ return SWT.BOTTOM;
+ } else if (widget instanceof MTabFolder) {
+ if (MTabFolder.TAB_BAR.equals(key))
+ return SWT.LEFT;
+ }
+ return super.getPosition(widget, key, defaultValue);
+ }
+
+ public void setColor(String key, RGB value) {
+ keyToRGB.put(key, value);
+ }
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFileDashboardPage.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFileDashboardPage.java
index 48f34610e..b49abb6fd 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFileDashboardPage.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFileDashboardPage.java
@@ -1,450 +1,462 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.annotation.PostConstruct;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.resource.ColorDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.jface.util.Util;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StackLayout;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.ui.internal.dashboard.pages.DashboardPage;
-import org.xmind.ui.internal.dashboard.pages.IDashboardContext;
-import org.xmind.ui.internal.dashboard.pages.IDashboardPage;
-import org.xmind.ui.mindmap.MindMapUI;
-import org.xmind.ui.resources.ColorUtils;
-import org.xmind.ui.tabfolder.MTabBar;
-import org.xmind.ui.tabfolder.MTabBarItem;
-import org.xmind.ui.util.StyleProvider;
-
-public class NewFileDashboardPage extends DashboardPage implements IAdaptable {
-
- private class SegmentBarStyleProvider extends StyleProvider {
- @Override
- public Font getFont(Object widget, String key) {
- if (widget instanceof MTabBarItem) {
- if (TEXT.equals(key))
- return (Font) resourceManager
- .get(JFaceResources.getDefaultFontDescriptor()
- .setHeight(Util.isMac() ? 10 : 12));
- }
- return super.getFont(widget, key);
- }
-
- @Override
- public int getWidth(Object widget, String key, int defaultValue) {
- if (widget instanceof MTabBarItem) {
- if (key == null)
- return 100;
- } else if (widget instanceof MTabBar) {
- if (BORDER.equals(key))
- return 1;
- if (SEPARATOR.equals(key))
- return 1;
- if (CORNER.equals(key))
- return 6;
- }
- return super.getWidth(widget, key, defaultValue);
- }
-
- @Override
- public int getHeight(Object widget, String key, int defaultValue) {
- if (widget instanceof MTabBarItem) {
- //FIXME
- if (key == null)
- return 26;
- } else if (widget instanceof MTabBar) {
- if (BORDER.equals(key))
- return 1;
- if (SEPARATOR.equals(key))
- return 1;
- if (CORNER.equals(key))
- return 6;
- }
- return super.getHeight(widget, key, defaultValue);
- }
-
- @Override
- public int getPosition(Object widget, String key, int defaultValue) {
- if (widget instanceof MTabBarItem) {
- if (TEXT.equals(key))
- return SWT.BOTTOM;
- }
- return super.getPosition(widget, key, defaultValue);
- }
-
- @Override
- public Color getColor(Object widget, String key) {
- if (widget instanceof MTabBarItem) {
- MTabBarItem item = (MTabBarItem) widget;
- if (FILL.equals(key)) {
- if (item.isSelected())
- return (Color) resourceManager.get(ColorDescriptor
- .createFrom(ColorUtils.toRGB("#6B6A6B"))); //$NON-NLS-1$
- } else if (TEXT.equals(key)) {
- if (item.isSelected())
- return (Color) resourceManager.get(ColorDescriptor
- .createFrom(ColorUtils.toRGB("#FFFFFF"))); //$NON-NLS-1$
- return (Color) resourceManager.get(ColorDescriptor
- .createFrom(ColorUtils.toRGB("#2B2A2B"))); //$NON-NLS-1$
- }
- } else if (widget instanceof MTabBar) {
- if (BORDER.equals(key) || SEPARATOR.equals(key))
- return (Color) resourceManager.get(ColorDescriptor
- .createFrom(ColorUtils.toRGB("#A6A6A6"))); //$NON-NLS-1$
- }
- return super.getColor(widget, key);
- }
-
- @Override
- public int getAlpha(Object widget, String key, int defaultValue) {
- if (widget instanceof MTabBar) {
- if (BORDER.equals(key))
- return 0xC0;
- }
- return super.getAlpha(widget, key, defaultValue);
- }
- }
-
- private Control control = null;
-
- private ResourceManager resourceManager = null;
-
- private Composite titleBar = null;
- private Composite rightBar = null;
- private MTabBar tabBar = null;
-
- private Composite pageContainer = null;
-
- private List pages = new ArrayList();
-
- @PostConstruct
- private void init(IDashboardContext dashboardContext) {
- NewFromStructuresDashboardPage structurePage = new NewFromStructuresDashboardPage();
- structurePage.setTitle(WorkbenchMessages.DashboardBlankPage_name);
- structurePage
- .setDescription(WorkbenchMessages.DashboardBlankPage_message);
- structurePage.setContext(dashboardContext);
- pages.add(structurePage);
-
- NewFromTemplatesDashboardPage templatePage = new NewFromTemplatesDashboardPage();
- templatePage.setTitle(WorkbenchMessages.DashboardTemplatesPage_name);
- templatePage.setDescription(
- WorkbenchMessages.DashboardTemplatesPage_message);
- templatePage.setContext(dashboardContext);
- templatePage.registerAvailableCommands();
- pages.add(templatePage);
-
- }
-
- public void createControl(Composite parent) {
- final Composite composite = new Composite(parent, SWT.NONE);
-
- this.resourceManager = new LocalResourceManager(
- JFaceResources.getResources(), composite);
-
- composite.setBackground(parent.getBackground());
- composite.setForeground(parent.getForeground());
-
- GridLayoutFactory.fillDefaults().spacing(0, 0).numColumns(1)
- .applyTo(composite);
-
- Control titleBar = createTitleBar(composite);
- GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 44)
- .align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(titleBar);
-
- Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
- .grab(true, false).applyTo(separator);
-
- Control pageContainer = createPageContainer(composite);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
- .grab(true, true).applyTo(pageContainer);
-
- this.control = composite;
-
- for (IDashboardPage page : pages) {
- MTabBarItem item = new MTabBarItem(tabBar, SWT.RADIO);
- item.setText(page.getTitle());
- item.setData(page);
- }
-
- setTitleBarComponentLayoutData();
-
- showPage(tabBar.getItem(0));
- }
-
- private void setTitleBarComponentLayoutData() {
- FormData tabData = new FormData();
- // A side can't be attached to parent, so we have to get the size first.
- // CAUTION: This depends on the fact that the size won't change.
- Point tabSize = tabBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- tabData.left = new FormAttachment(50, -tabSize.x / 2);
- tabData.top = new FormAttachment(50, -tabSize.y / 2);
- tabData.bottom = new FormAttachment(50, tabSize.y / 2);
- tabBar.setLayoutData(tabData);
-
- FormData rightData = new FormData();
- rightData.top = new FormAttachment(0, 0);
- rightData.right = new FormAttachment(100, 0);
- rightData.bottom = new FormAttachment(100, 0);
- rightBar.setLayoutData(rightData);
- }
-
- private Control createTitleBar(Composite parent) {
- titleBar = new Composite(parent, SWT.NONE);
- FormLayout titleBarLayout = new FormLayout();
- titleBarLayout.marginWidth = 10;
- titleBarLayout.marginHeight = 0;
- titleBarLayout.marginRight = 15;
- titleBar.setLayout(titleBarLayout);
- titleBar.setForeground(parent.getForeground());
-// titleBar.setBackground(parent.getBackground());
- titleBar.setBackground((Color) JFaceResources.getResources()
- .get(ColorUtils.toDescriptor("#ececec"))); //$NON-NLS-1$
-
- Control titleLabel = createLeftTitleBarControl(titleBar);
- FormData leftData = new FormData();
- leftData.top = new FormAttachment(0, 0);
- leftData.left = new FormAttachment(0, 0);
- leftData.bottom = new FormAttachment(100, 0);
- titleLabel.setLayoutData(leftData);
-
- createCentralContainer(titleBar);
-// FormData tabData = new FormData();
-// // A side can't be attached to parent, so we have to get the size first.
-// // CAUTION: This depends on the fact that the size won't change.
-// Point tabSize = tabBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-// tabData.left = new FormAttachment(50, -tabSize.x / 2);
-// tabData.top = new FormAttachment(0, 0);
-// tabData.bottom = new FormAttachment(100, 0);
-// tabBar.setLayoutData(tabData);
-
- createRightBar(titleBar);
-// FormData rightData = new FormData();
-// rightData.top = new FormAttachment(0, 0);
-// rightData.right = new FormAttachment(100, 0);
-// rightData.bottom = new FormAttachment(100, 0);
-// rightBar.setLayoutData(rightData);
-
- return titleBar;
- }
-
- private Control createLeftTitleBarControl(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- composite.setForeground(parent.getForeground());
- GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 0)
- .applyTo(composite);
-
- Label titleNameLabel = new Label(composite, SWT.WRAP);
- titleNameLabel.setBackground(composite.getBackground());
- titleNameLabel.setForeground(composite.getForeground());
- titleNameLabel.setFont((Font) JFaceResources.getResources().get(
- JFaceResources.getHeaderFontDescriptor().increaseHeight(-1)));
- titleNameLabel.setText(
- WorkbenchMessages.NewFileDashboardPage_leftTitleBar_text);
- GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER)
- .grab(true, true).applyTo(titleNameLabel);
-
- return composite;
- }
-
- private Control createCentralContainer(Composite parent) {
- tabBar = new MTabBar(parent, SWT.NONE);
- tabBar.setBackground(
- parent.getDisplay().getSystemColor(SWT.COLOR_TRANSPARENT));
- tabBar.setStyleProvider(new SegmentBarStyleProvider());
-
- tabBar.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- showPage((MTabBarItem) event.item);
- }
- });
- return tabBar;
- }
-
- private Control createRightBar(Composite composite) {
- rightBar = new Composite(composite, SWT.NONE);
- GridLayoutFactory.fillDefaults().numColumns(1).applyTo(rightBar);
-
- createImportButton(rightBar);
-
- return rightBar;
- }
-
- private void createImportButton(Composite parent) {
- final Label importBtton = new Label(parent, SWT.NONE);
- importBtton.setBackground(parent.getBackground());
- importBtton.setToolTipText(
- WorkbenchMessages.NewFileDashboardPage_Import_button);
- importBtton.setImage((Image) resourceManager.get(
- CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
- "dashboard/new/button_import.png"))); //$NON-NLS-1$
- GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER)
- .grab(true, true).applyTo(importBtton);
-
- final IAction addTemplateAction = getAddTemplateAction();
-
- importBtton.addListener(SWT.MouseDown, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
- addTemplateAction.run();
- }
- });
-
- importBtton.addMouseTrackListener(new MouseTrackAdapter() {
-
- @Override
- public void mouseExit(MouseEvent e) {
- importBtton.setImage((Image) resourceManager.get(CathyPlugin
- .imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
- "dashboard/new/button_import.png"))); //$NON-NLS-1$
- }
-
- @Override
- public void mouseEnter(MouseEvent e) {
- importBtton.setImage((Image) resourceManager.get(CathyPlugin
- .imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
- "dashboard/new/button_import_hover.png"))); //$NON-NLS-1$
- }
- });
- }
-
- private IAction getAddTemplateAction() {
- Action addTemplateAction = new Action(
- WorkbenchMessages.NewFileDashboardPage_AddTemplates_label) {
- @Override
- public void run() {
- FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
- String ext = "*" + MindMapUI.FILE_EXT_TEMPLATE; //$NON-NLS-1$
- dialog.setFilterExtensions(new String[] { ext });
- dialog.setFilterNames(new String[] { NLS.bind("{0} ({1})", //$NON-NLS-1$
- WorkbenchMessages.NewFileDashboardPage_TemplateFilterName_label,
- ext) });
- String path = dialog.open();
- if (path == null)
- return;
-
- final File templateFile = new File(path);
- if (templateFile != null && templateFile.exists()) {
- SafeRunner.run(new SafeRunnable() {
- public void run() throws Exception {
- MindMapUI.getResourceManager()
- .addUserTemplateFromWorkbookURI(
- templateFile.toURI());
- }
- });
- }
-
- }
- };
- addTemplateAction.setToolTipText(
- WorkbenchMessages.NewFileDashboardPage_AddTemplates_tooltip);
-
- return addTemplateAction;
- }
-
- private Control createPageContainer(Composite parent) {
- pageContainer = new Composite(parent, SWT.NONE);
- pageContainer.setBackground(parent.getBackground());
-
- pageContainer.setLayout(new StackLayout());
-
- return pageContainer;
- }
-
- private void showPage(MTabBarItem item) {
- if (pageContainer == null || pageContainer.isDisposed())
- return;
-
- StackLayout layout = (StackLayout) pageContainer.getLayout();
-
- if (item == null) {
- layout.topControl = null;
- pageContainer.layout(true);
- return;
- }
-
- IDashboardPage page = (IDashboardPage) item.getData();
- if (page != null) {
- if (page.getControl() == null) {
- page.createControl(pageContainer);
- }
- layout.topControl = page.getControl();
- pageContainer.layout(true);
-
- updateTitleBar();
- }
-
- getContext().setSelectionProvider(getAdapter(ISelectionProvider.class));
- }
-
- private void updateTitleBar() {
- MTabBarItem item = tabBar.getSelection();
- IDashboardPage page = (IDashboardPage) item.getData();
- if (page instanceof NewFromTemplatesDashboardPage) {
- rightBar.setVisible(true);
- } else if (page instanceof NewFromStructuresDashboardPage) {
- rightBar.setVisible(false);
- }
- titleBar.layout(true);
- }
-
- public Control getControl() {
- return this.control;
- }
-
- public void setFocus() {
- MTabBarItem item = tabBar.getSelection();
- if (item != null) {
- IDashboardPage page = (IDashboardPage) item.getData();
- if (page != null) {
- page.setFocus();
- }
- }
- }
-
- public T getAdapter(Class adapter) {
- MTabBarItem item = tabBar.getSelection();
- IDashboardPage page = (IDashboardPage) item.getData();
- if (page instanceof IAdaptable) {
- return ((IAdaptable) page).getAdapter(adapter);
- }
-
- return null;
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.ColorDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.jface.util.Util;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseTrackAdapter;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.ui.internal.dashboard.pages.DashboardPage;
+import org.xmind.ui.internal.dashboard.pages.IDashboardContext;
+import org.xmind.ui.internal.dashboard.pages.IDashboardPage;
+import org.xmind.ui.mindmap.MindMapUI;
+import org.xmind.ui.resources.ColorUtils;
+import org.xmind.ui.tabfolder.MTabBar;
+import org.xmind.ui.tabfolder.MTabBarItem;
+import org.xmind.ui.util.StyleProvider;
+
+public class NewFileDashboardPage extends DashboardPage implements IAdaptable {
+
+ private class SegmentBarStyleProvider extends StyleProvider {
+ @Override
+ public Font getFont(Object widget, String key) {
+ if (widget instanceof MTabBarItem) {
+ if (TEXT.equals(key))
+ return (Font) resourceManager
+ .get(JFaceResources.getDefaultFontDescriptor()
+ .setHeight(Util.isMac() ? 10 : 12));
+ }
+ return super.getFont(widget, key);
+ }
+
+ @Override
+ public int getWidth(Object widget, String key, int defaultValue) {
+ if (widget instanceof MTabBarItem) {
+ if (key == null)
+ return 100;
+ } else if (widget instanceof MTabBar) {
+ if (BORDER.equals(key))
+ return 1;
+ if (SEPARATOR.equals(key))
+ return 1;
+ if (CORNER.equals(key))
+ return 6;
+ }
+ return super.getWidth(widget, key, defaultValue);
+ }
+
+ @Override
+ public int getHeight(Object widget, String key, int defaultValue) {
+ if (widget instanceof MTabBarItem) {
+ //FIXME
+ if (key == null)
+ return 26;
+ } else if (widget instanceof MTabBar) {
+ if (BORDER.equals(key))
+ return 1;
+ if (SEPARATOR.equals(key))
+ return 1;
+ if (CORNER.equals(key))
+ return 6;
+ }
+ return super.getHeight(widget, key, defaultValue);
+ }
+
+ @Override
+ public int getPosition(Object widget, String key, int defaultValue) {
+ if (widget instanceof MTabBarItem) {
+ if (TEXT.equals(key))
+ return SWT.BOTTOM;
+ }
+ return super.getPosition(widget, key, defaultValue);
+ }
+
+ @Override
+ public Color getColor(Object widget, String key) {
+ if (widget instanceof MTabBarItem) {
+ MTabBarItem item = (MTabBarItem) widget;
+ if (FILL.equals(key)) {
+ if (item.isSelected())
+ return (Color) resourceManager.get(ColorDescriptor
+ .createFrom(ColorUtils.toRGB("#6B6A6B"))); //$NON-NLS-1$
+ } else if (TEXT.equals(key)) {
+ if (item.isSelected())
+ return (Color) resourceManager.get(ColorDescriptor
+ .createFrom(ColorUtils.toRGB("#FFFFFF"))); //$NON-NLS-1$
+ return (Color) resourceManager.get(ColorDescriptor
+ .createFrom(ColorUtils.toRGB("#2B2A2B"))); //$NON-NLS-1$
+ }
+ } else if (widget instanceof MTabBar) {
+ if (BORDER.equals(key) || SEPARATOR.equals(key))
+ return (Color) resourceManager.get(ColorDescriptor
+ .createFrom(ColorUtils.toRGB("#A6A6A6"))); //$NON-NLS-1$
+ }
+ return super.getColor(widget, key);
+ }
+
+ @Override
+ public int getAlpha(Object widget, String key, int defaultValue) {
+ if (widget instanceof MTabBar) {
+ if (BORDER.equals(key))
+ return 0xC0;
+ }
+ return super.getAlpha(widget, key, defaultValue);
+ }
+ }
+
+ private Control control = null;
+
+ private ResourceManager resourceManager = null;
+
+ private Composite titleBar = null;
+ private Composite rightBar = null;
+ private MTabBar tabBar = null;
+
+ private Composite pageContainer = null;
+
+ private List pages = new ArrayList();
+
+ @PostConstruct
+ private void init(IDashboardContext dashboardContext) {
+ NewFromStructuresDashboardPage structurePage = new NewFromStructuresDashboardPage();
+ structurePage.setTitle(WorkbenchMessages.DashboardBlankPage_name);
+ structurePage
+ .setDescription(WorkbenchMessages.DashboardBlankPage_message);
+ structurePage.setContext(dashboardContext);
+ pages.add(structurePage);
+
+ NewFromTemplatesDashboardPage templatePage = new NewFromTemplatesDashboardPage();
+ templatePage.setTitle(WorkbenchMessages.DashboardTemplatesPage_name);
+ templatePage.setDescription(
+ WorkbenchMessages.DashboardTemplatesPage_message);
+ templatePage.setContext(dashboardContext);
+ templatePage.registerAvailableCommands();
+ pages.add(templatePage);
+
+ }
+
+ public void createControl(Composite parent) {
+ final Composite composite = new Composite(parent, SWT.NONE);
+
+ this.resourceManager = new LocalResourceManager(
+ JFaceResources.getResources(), composite);
+
+ composite.setBackground(parent.getBackground());
+ composite.setForeground(parent.getForeground());
+
+ GridLayoutFactory.fillDefaults().spacing(0, 0).numColumns(1)
+ .applyTo(composite);
+
+ Control titleBar = createTitleBar(composite);
+ GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 44)
+ .align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(titleBar);
+
+ Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
+ .grab(true, false).applyTo(separator);
+
+ Control pageContainer = createPageContainer(composite);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
+ .grab(true, true).applyTo(pageContainer);
+
+ this.control = composite;
+
+ for (IDashboardPage page : pages) {
+ MTabBarItem item = new MTabBarItem(tabBar, SWT.RADIO);
+ item.setText(page.getTitle());
+ item.setData(page);
+ }
+
+ setTitleBarComponentLayoutData();
+
+ showPage(tabBar.getItem(0));
+ }
+
+ private void setTitleBarComponentLayoutData() {
+ FormData tabData = new FormData();
+ // A side can't be attached to parent, so we have to get the size first.
+ // CAUTION: This depends on the fact that the size won't change.
+ Point tabSize = tabBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ tabData.left = new FormAttachment(50, -tabSize.x / 2);
+ tabData.top = new FormAttachment(50, -tabSize.y / 2);
+ tabData.bottom = new FormAttachment(50, tabSize.y / 2);
+ tabBar.setLayoutData(tabData);
+
+ FormData rightData = new FormData();
+ rightData.top = new FormAttachment(0, 0);
+ rightData.right = new FormAttachment(100, 0);
+ rightData.bottom = new FormAttachment(100, 0);
+ rightBar.setLayoutData(rightData);
+ }
+
+ private Control createTitleBar(Composite parent) {
+ titleBar = new Composite(parent, SWT.NONE);
+ FormLayout titleBarLayout = new FormLayout();
+ titleBarLayout.marginWidth = 10;
+ titleBarLayout.marginHeight = 0;
+ titleBarLayout.marginRight = 15;
+ titleBar.setLayout(titleBarLayout);
+ titleBar.setForeground(parent.getForeground());
+// titleBar.setBackground(parent.getBackground());
+ titleBar.setBackground((Color) JFaceResources.getResources()
+ .get(ColorUtils.toDescriptor("#ececec"))); //$NON-NLS-1$
+
+ Control titleLabel = createLeftTitleBarControl(titleBar);
+ FormData leftData = new FormData();
+ leftData.top = new FormAttachment(0, 0);
+ leftData.left = new FormAttachment(0, 0);
+ leftData.bottom = new FormAttachment(100, 0);
+ titleLabel.setLayoutData(leftData);
+
+ createCentralContainer(titleBar);
+// FormData tabData = new FormData();
+// // A side can't be attached to parent, so we have to get the size first.
+// // CAUTION: This depends on the fact that the size won't change.
+// Point tabSize = tabBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+// tabData.left = new FormAttachment(50, -tabSize.x / 2);
+// tabData.top = new FormAttachment(0, 0);
+// tabData.bottom = new FormAttachment(100, 0);
+// tabBar.setLayoutData(tabData);
+
+ createRightBar(titleBar);
+// FormData rightData = new FormData();
+// rightData.top = new FormAttachment(0, 0);
+// rightData.right = new FormAttachment(100, 0);
+// rightData.bottom = new FormAttachment(100, 0);
+// rightBar.setLayoutData(rightData);
+
+ return titleBar;
+ }
+
+ private Control createLeftTitleBarControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ composite.setForeground(parent.getForeground());
+ GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 0)
+ .applyTo(composite);
+
+ Label titleNameLabel = new Label(composite, SWT.WRAP);
+ titleNameLabel.setBackground(composite.getBackground());
+ titleNameLabel.setForeground(composite.getForeground());
+ titleNameLabel.setFont((Font) JFaceResources.getResources().get(
+ JFaceResources.getHeaderFontDescriptor().increaseHeight(-1)));
+ titleNameLabel.setText(
+ WorkbenchMessages.NewFileDashboardPage_leftTitleBar_text);
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER)
+ .grab(true, true).applyTo(titleNameLabel);
+
+ return composite;
+ }
+
+ private Control createCentralContainer(Composite parent) {
+ tabBar = new MTabBar(parent, SWT.NONE);
+ tabBar.setBackground(
+ parent.getDisplay().getSystemColor(SWT.COLOR_TRANSPARENT));
+ tabBar.setStyleProvider(new SegmentBarStyleProvider());
+
+ tabBar.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ showPage((MTabBarItem) event.item);
+ }
+ });
+ return tabBar;
+ }
+
+ private Control createRightBar(Composite composite) {
+ rightBar = new Composite(composite, SWT.NONE);
+ GridLayoutFactory.fillDefaults().numColumns(1).applyTo(rightBar);
+
+ createImportButton(rightBar);
+
+ return rightBar;
+ }
+
+ private void createImportButton(Composite parent) {
+ final Label importBtton = new Label(parent, SWT.NONE);
+ importBtton.setBackground(parent.getBackground());
+ importBtton.setToolTipText(
+ WorkbenchMessages.NewFileDashboardPage_Import_button);
+ importBtton.setImage((Image) resourceManager.get(
+ CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
+ "dashboard/new/button_import.png"))); //$NON-NLS-1$
+ GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER)
+ .grab(true, true).applyTo(importBtton);
+
+ final IAction addTemplateAction = getAddTemplateAction();
+
+ importBtton.addListener(SWT.MouseDown, new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ addTemplateAction.run();
+ }
+ });
+
+ importBtton.addMouseTrackListener(new MouseTrackAdapter() {
+
+ @Override
+ public void mouseExit(MouseEvent e) {
+ importBtton.setImage((Image) resourceManager.get(CathyPlugin
+ .imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
+ "dashboard/new/button_import.png"))); //$NON-NLS-1$
+ }
+
+ @Override
+ public void mouseEnter(MouseEvent e) {
+ importBtton.setImage((Image) resourceManager.get(CathyPlugin
+ .imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
+ "dashboard/new/button_import_hover.png"))); //$NON-NLS-1$
+ }
+ });
+ }
+
+ private IAction getAddTemplateAction() {
+ Action addTemplateAction = new Action(
+ WorkbenchMessages.NewFileDashboardPage_AddTemplates_label) {
+ @Override
+ public void run() {
+ FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
+ String ext = "*" + MindMapUI.FILE_EXT_TEMPLATE; //$NON-NLS-1$
+ dialog.setFilterExtensions(new String[] { ext });
+ dialog.setFilterNames(new String[] { NLS.bind("{0} ({1})", //$NON-NLS-1$
+ WorkbenchMessages.NewFileDashboardPage_TemplateFilterName_label,
+ ext) });
+ String path = dialog.open();
+ if (path == null)
+ return;
+
+ final File templateFile = new File(path);
+ if (templateFile != null && templateFile.exists()) {
+ SafeRunner.run(new SafeRunnable() {
+ public void run() throws Exception {
+ MindMapUI.getResourceManager()
+ .addUserTemplateFromWorkbookURI(
+ templateFile.toURI());
+ }
+ });
+ }
+
+ }
+ };
+ addTemplateAction.setToolTipText(
+ WorkbenchMessages.NewFileDashboardPage_AddTemplates_tooltip);
+
+ return addTemplateAction;
+ }
+
+ private Control createPageContainer(Composite parent) {
+ pageContainer = new Composite(parent, SWT.NONE);
+ pageContainer.setBackground(parent.getBackground());
+
+ pageContainer.setLayout(new StackLayout());
+
+ return pageContainer;
+ }
+
+ private void showPage(MTabBarItem item) {
+ if (pageContainer == null || pageContainer.isDisposed())
+ return;
+
+ StackLayout layout = (StackLayout) pageContainer.getLayout();
+
+ if (item == null) {
+ layout.topControl = null;
+ pageContainer.layout(true);
+ return;
+ }
+
+ IDashboardPage page = (IDashboardPage) item.getData();
+ if (page != null) {
+ if (page.getControl() == null) {
+ page.createControl(pageContainer);
+ }
+ layout.topControl = page.getControl();
+ pageContainer.layout(true);
+
+ updateTitleBar();
+ }
+
+ getContext().setSelectionProvider(getAdapter(ISelectionProvider.class));
+ }
+
+ @Override
+ public void dispose() {
+ if (pages != null) {
+ for (IDashboardPage page : pages) {
+ page.dispose();
+ }
+ pages.clear();
+ pages = null;
+ }
+ super.dispose();
+ }
+
+ private void updateTitleBar() {
+ MTabBarItem item = tabBar.getSelection();
+ IDashboardPage page = (IDashboardPage) item.getData();
+ if (page instanceof NewFromTemplatesDashboardPage) {
+ rightBar.setVisible(true);
+ } else if (page instanceof NewFromStructuresDashboardPage) {
+ rightBar.setVisible(false);
+ }
+ titleBar.layout(true);
+ }
+
+ public Control getControl() {
+ return this.control;
+ }
+
+ public void setFocus() {
+ MTabBarItem item = tabBar.getSelection();
+ if (item != null) {
+ IDashboardPage page = (IDashboardPage) item.getData();
+ if (page != null) {
+ page.setFocus();
+ }
+ }
+ }
+
+ public T getAdapter(Class adapter) {
+ MTabBarItem item = tabBar.getSelection();
+ IDashboardPage page = (IDashboardPage) item.getData();
+ if (page instanceof IAdaptable) {
+ return ((IAdaptable) page).getAdapter(adapter);
+ }
+
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFromStructuresDashboardPage.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFromStructuresDashboardPage.java
index 7a5d1bf36..ba1ffeeb6 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFromStructuresDashboardPage.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFromStructuresDashboardPage.java
@@ -1,159 +1,174 @@
-package org.xmind.cathy.internal.dashboard;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.draw2d.geometry.Insets;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.jface.viewers.IOpenListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.OpenEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.xmind.cathy.internal.dashboard.StructureListContentProvider.StructureDescriptor;
-import org.xmind.core.style.IStyle;
-import org.xmind.gef.EditDomain;
-import org.xmind.gef.GEF;
-import org.xmind.gef.ui.internal.SpaceCollaborativeEngine;
-import org.xmind.gef.util.Properties;
-import org.xmind.ui.gallery.GalleryLayout;
-import org.xmind.ui.gallery.GallerySelectTool;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.internal.MindMapUIPlugin;
-import org.xmind.ui.internal.dashboard.pages.DashboardPage;
-import org.xmind.ui.mindmap.MindMapUI;
-import org.xmind.ui.mindmap.WorkbookInitializer;
-import org.xmind.ui.resources.ColorUtils;
-
-@SuppressWarnings("restriction")
-public class NewFromStructuresDashboardPage extends DashboardPage
- implements IAdaptable {
-
- private GalleryViewer viewer;
-
- private ResourceManager resources;
-
- public void setFocus() {
- if (viewer != null && viewer.getControl() != null
- && !viewer.getControl().isDisposed()) {
- viewer.getControl().setFocus();
- }
- }
-
- public void createControl(Composite parent) {
- resources = new LocalResourceManager(JFaceResources.getResources(),
- parent);
-
- viewer = new GalleryViewer();
-
- EditDomain editDomain = new EditDomain();
- editDomain.installTool(GEF.TOOL_SELECT, new GallerySelectTool());
- viewer.setEditDomain(editDomain);
-
- Properties properties = viewer.getProperties();
- properties.set(GalleryViewer.Horizontal, Boolean.TRUE);
- properties.set(GalleryViewer.Wrap, Boolean.TRUE);
- properties.set(GalleryViewer.TitlePlacement,
- GalleryViewer.TITLE_BOTTOM);
- properties.set(GalleryViewer.SingleClickToOpen, Boolean.TRUE);
- properties.set(GalleryViewer.SolidFrames, true);
- properties.set(GalleryViewer.FlatFrames, true);
- properties.set(GalleryViewer.ImageConstrained, true);
- properties.set(GalleryViewer.Layout,
- new GalleryLayout(GalleryLayout.ALIGN_TOPLEFT,
- GalleryLayout.ALIGN_TOPLEFT, 30, 0,
- new Insets(10, 65, 20, 65)));
- properties.set(GalleryViewer.ContentPaneBorderWidth, 1);
- properties.set(GalleryViewer.ContentPaneBorderColor,
- (Color) resources.get(ColorUtils.toDescriptor("#cccccc"))); //$NON-NLS-1$
-
- properties.set(GalleryViewer.ContentPaneSpaceCollaborativeEngine,
- new SpaceCollaborativeEngine());
-
- Control control = viewer.createControl(parent);
- control.setBackground(parent.getBackground());
- control.setForeground(parent.getForeground());
-
- StructureListContentProvider contentAndLabelProvider = new StructureListContentProvider();
- viewer.setContentProvider(contentAndLabelProvider);
- viewer.setLabelProvider(
- new StructureListContentProvider.StructureListLabelProvider());
-
- viewer.setInput(StructureListContentProvider.getDefaultInput());
-
- viewer.addOpenListener(new IOpenListener() {
- public void open(OpenEvent event) {
- handleStructureSelected(event.getSelection());
- }
- });
-
- setControl(control);
- }
-
- private void handleStructureSelected(ISelection selection) {
- Display.getCurrent().asyncExec(new Runnable() {
- public void run() {
- if (viewer == null || viewer.getControl() == null
- || viewer.getControl().isDisposed())
- return;
-
- viewer.setSelection(StructuredSelection.EMPTY);
- }
- });
-
- if (selection == null || selection.isEmpty()
- || !(selection instanceof IStructuredSelection))
- return;
-
- Object selectedElement = ((IStructuredSelection) selection)
- .getFirstElement();
- if (selectedElement == null
- || !(selectedElement instanceof StructureDescriptor))
- return;
-
- final StructureDescriptor structure = (StructureDescriptor) selectedElement;
- final IStyle theme = chooseTheme(viewer.getControl().getShell(),
- structure.getValue());
- if (theme == null)
- return;
-
- MindMapUIPlugin.getDefault().getUsageDataCollector()
- .increase("CreateWorkbookCount"); //$NON-NLS-1$
- MindMapUIPlugin.getDefault().getUsageDataCollector()
- .increase("CreateSheetCount"); //$NON-NLS-1$
- MindMapUIPlugin.getDefault().getUsageDataCollector()
- .increase("StructureTypeCount:" + structure.getValue()); //$NON-NLS-1$
- WorkbookInitializer initializer = WorkbookInitializer.getDefault()
- .withStructureClass(structure.getValue()).withTheme(theme);
- IEditorInput editorInput = MindMapUI.getEditorInputFactory()
- .createEditorInputForWorkbookInitializer(initializer, null);
- getContext().openEditor(editorInput, MindMapUI.MINDMAP_EDITOR_ID);
- }
-
- private IStyle chooseTheme(Shell shell, String structureClass) {
- ThemeChooserDialog dialog = new ThemeChooserDialog(shell,
- structureClass);
- int result = dialog.open();
- if (result == ThemeChooserDialog.CANCEL)
- return null;
- return dialog.getSelectedTheme();
- }
-
- public T getAdapter(Class adapter) {
- if (viewer != null) {
- if (adapter.isAssignableFrom(viewer.getClass()))
- return adapter.cast(viewer);
- T obj = viewer.getAdapter(adapter);
- if (obj != null)
- return obj;
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Insets;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.xmind.cathy.internal.dashboard.StructureListContentProvider.StructureDescriptor;
+import org.xmind.core.internal.UserDataConstants;
+import org.xmind.core.style.IStyle;
+import org.xmind.gef.EditDomain;
+import org.xmind.gef.GEF;
+import org.xmind.gef.ui.internal.SpaceCollaborativeEngine;
+import org.xmind.gef.util.Properties;
+import org.xmind.ui.gallery.GalleryLayout;
+import org.xmind.ui.gallery.GallerySelectTool;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.internal.MindMapUIPlugin;
+import org.xmind.ui.internal.dashboard.pages.DashboardPage;
+import org.xmind.ui.mindmap.MindMapUI;
+import org.xmind.ui.mindmap.WorkbookInitializer;
+import org.xmind.ui.resources.ColorUtils;
+
+@SuppressWarnings("restriction")
+public class NewFromStructuresDashboardPage extends DashboardPage
+ implements IAdaptable {
+
+ private static final int FRAME_WIDTH = 210;
+ private static final int FRAME_HEIGHT = 130;
+
+ private GalleryViewer viewer;
+
+ private ResourceManager resources;
+
+ public void setFocus() {
+ if (viewer != null && viewer.getControl() != null
+ && !viewer.getControl().isDisposed()) {
+ viewer.getControl().setFocus();
+ }
+ }
+
+ public void createControl(Composite parent) {
+ resources = new LocalResourceManager(JFaceResources.getResources(),
+ parent);
+
+ viewer = new GalleryViewer();
+
+ EditDomain editDomain = new EditDomain();
+ editDomain.installTool(GEF.TOOL_SELECT, new GallerySelectTool());
+ viewer.setEditDomain(editDomain);
+
+ Properties properties = viewer.getProperties();
+ properties.set(GalleryViewer.Horizontal, Boolean.TRUE);
+ properties.set(GalleryViewer.Wrap, Boolean.TRUE);
+ properties.set(GalleryViewer.TitlePlacement,
+ GalleryViewer.TITLE_BOTTOM);
+ properties.set(GalleryViewer.SingleClickToOpen, Boolean.TRUE);
+ properties.set(GalleryViewer.SolidFrames, true);
+ properties.set(GalleryViewer.FlatFrames, true);
+ properties.set(GalleryViewer.ImageConstrained, true);
+ properties.set(GalleryViewer.ImageStretched, Boolean.TRUE);
+ properties.set(GalleryViewer.ContentPaneBorderWidth, 1);
+ properties.set(GalleryViewer.ContentPaneBorderColor,
+ (Color) resources.get(ColorUtils.toDescriptor("#cccccc"))); //$NON-NLS-1$
+
+ properties.set(GalleryViewer.FrameContentSize,
+ new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
+ properties.set(GalleryViewer.Layout,
+ new GalleryLayout(GalleryLayout.ALIGN_TOPLEFT,
+ GalleryLayout.ALIGN_TOPLEFT, 30, 0,
+ new Insets(10, 65, 20, 65)));
+
+ properties.set(GalleryViewer.ContentPaneSpaceCollaborativeEngine,
+ new SpaceCollaborativeEngine());
+
+ Control control = viewer.createControl(parent);
+ control.setBackground(parent.getBackground());
+ control.setForeground(parent.getForeground());
+
+ StructureListContentProvider contentAndLabelProvider = new StructureListContentProvider();
+ viewer.setContentProvider(contentAndLabelProvider);
+ viewer.setLabelProvider(
+ new StructureListContentProvider.StructureListLabelProvider());
+
+ viewer.setInput(StructureListContentProvider.getDefaultInput());
+
+ viewer.addOpenListener(new IOpenListener() {
+ public void open(OpenEvent event) {
+ handleStructureSelected(event.getSelection());
+ }
+ });
+
+ setControl(control);
+ }
+
+ private void handleStructureSelected(ISelection selection) {
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ if (viewer == null || viewer.getControl() == null
+ || viewer.getControl().isDisposed())
+ return;
+
+ viewer.setSelection(StructuredSelection.EMPTY);
+ }
+ });
+
+ if (selection == null || selection.isEmpty()
+ || !(selection instanceof IStructuredSelection))
+ return;
+
+ Object selectedElement = ((IStructuredSelection) selection)
+ .getFirstElement();
+ if (selectedElement == null
+ || !(selectedElement instanceof StructureDescriptor))
+ return;
+
+ final StructureDescriptor structure = (StructureDescriptor) selectedElement;
+ final IStyle theme = chooseTheme(viewer.getControl().getShell(),
+ structure.getValue());
+ if (theme == null)
+ return;
+
+ MindMapUIPlugin.getDefault().getUsageDataCollector().trackEvent(
+ UserDataConstants.CATEGORY_WORKBOOK,
+ UserDataConstants.CREATE_WORKBOOK);
+ MindMapUIPlugin.getDefault().getUsageDataCollector().trackEvent(
+ UserDataConstants.CATEGORY_SHEET,
+ UserDataConstants.CREATE_SHEET);
+
+ String vs = structure.getValue();
+ String ID = vs.replaceAll("\\.", "_"); //$NON-NLS-1$//$NON-NLS-2$
+ MindMapUIPlugin.getDefault().getUsageDataCollector().trackEvent(
+ UserDataConstants.CATEGORY_STRUCTURE,
+ String.format(UserDataConstants.USE_STRUCTURE_TYPE_S, ID));
+ WorkbookInitializer initializer = WorkbookInitializer.getDefault()
+ .withStructureClass(structure.getValue()).withTheme(theme);
+ IEditorInput editorInput = MindMapUI.getEditorInputFactory()
+ .createEditorInputForWorkbookInitializer(initializer, null);
+ getContext().openEditor(editorInput, MindMapUI.MINDMAP_EDITOR_ID);
+ }
+
+ private IStyle chooseTheme(Shell shell, String structureClass) {
+ ThemeChooserDialog dialog = new ThemeChooserDialog(shell,
+ structureClass);
+ int result = dialog.open();
+ if (result == ThemeChooserDialog.CANCEL)
+ return null;
+ return dialog.getSelectedTheme();
+ }
+
+ public T getAdapter(Class adapter) {
+ if (viewer != null) {
+ if (adapter.isAssignableFrom(viewer.getClass()))
+ return adapter.cast(viewer);
+ T obj = viewer.getAdapter(adapter);
+ if (obj != null)
+ return obj;
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFromTemplatesDashboardPage.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFromTemplatesDashboardPage.java
index ac30a7657..9e5c60fe8 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFromTemplatesDashboardPage.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/NewFromTemplatesDashboardPage.java
@@ -1,172 +1,179 @@
-package org.xmind.cathy.internal.dashboard;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.viewers.IOpenListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.OpenEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.xmind.cathy.internal.ICathyConstants;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.internal.MindMapUIPlugin;
-import org.xmind.ui.internal.dashboard.pages.DashboardPage;
-import org.xmind.ui.internal.dashboard.pages.IDashboardContext;
-import org.xmind.ui.mindmap.IResourceManagerListener;
-import org.xmind.ui.mindmap.ITemplate;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class NewFromTemplatesDashboardPage extends DashboardPage
- implements IResourceManagerListener, IAdaptable {
-
- private CategorizedTemplateViewer viewer;
-
- private boolean templateOpening;
-
- public void setFocus() {
- if (viewer != null && viewer.getControl() != null
- && !viewer.getControl().isDisposed()) {
- viewer.getControl().setFocus();
- }
- }
-
- @Override
- public void dispose() {
- MindMapUI.getResourceManager().removeResourceManagerListener(this);
- super.dispose();
- }
-
- public void createControl(Composite parent) {
- Composite container = new Composite(parent, SWT.NONE);
- container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- GridLayout layout = new GridLayout();
- layout.marginWidth = 0;
- layout.marginLeft = 60;
- layout.marginRight = 0;
- layout.marginHeight = 7;
- container.setLayout(layout);
-
- MindMapUIPlugin.getDefault().getUsageDataCollector()
- .increase("ShowTemplatesCount"); //$NON-NLS-1$
- viewer = new CategorizedTemplateViewer(container);
- Control control = viewer.getControl();
- control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- viewer.addOpenListener(new IOpenListener() {
- public void open(OpenEvent event) {
- if (!templateOpening) {
- handleTemplateSelected(event.getSelection());
- MindMapUIPlugin.getDefault().getUsageDataCollector()
- .increase("CreateWorkbookCount"); //$NON-NLS-1$
- MindMapUIPlugin.getDefault().getUsageDataCollector()
- .increase("CreateSheetCount"); //$NON-NLS-1$
- MindMapUIPlugin.getDefault().getUsageDataCollector()
- .increase("UseTemplatesCount"); //$NON-NLS-1$
- }
- }
- });
-
- MindMapUI.getResourceManager().addResourceManagerListener(this);
-
- registerContextMenu(control);
- setControl(container);
- }
-
- public void registerAvailableCommands() {
- IDashboardContext context = getContext();
-
- context.registerAvailableCommandId(
- ICathyConstants.COMMAND_TEMPLATE_DUPLICATE);
- context.registerAvailableCommandId(
- ICathyConstants.COMMAND_TEMPLATE_RENAME);
- context.registerAvailableCommandId(
- ICathyConstants.COMMAND_TEMPLATE_DELETE);
- }
-
- private void registerContextMenu(Control control) {
- getContext().registerContextMenu(control,
- ICathyConstants.POPUP_TEMPLATE);
-
- //add context menu for nested viewers' control.
- Object input = viewer.getInput();
- if (input instanceof Object[]) {
- Object[] groups = (Object[]) viewer.getInput();
- for (Object group : groups) {
- GalleryViewer nestedViewer = viewer.getNestedViewer(group);
- if (nestedViewer != null) {
- nestedViewer.getControl().setMenu(control.getMenu());
- }
- }
- }
- }
-
- public void addSelectionChangedListener(
- ISelectionChangedListener listener) {
- if (viewer != null) {
- viewer.addSelectionChangedListener(listener);
- }
- }
-
- public void userTemplateAdded(ITemplate template) {
- if (viewer != null) {
- viewer.userTemplateAdded(template);
- }
- }
-
- public void userTemplateRemoved(ITemplate template) {
- if (viewer != null) {
- viewer.userTemplateRemoved(template);
- }
- }
-
- private void handleTemplateSelected(ISelection selection) {
- templateOpening = true;
- Display.getCurrent().asyncExec(new Runnable() {
- public void run() {
- if (viewer == null || viewer.getControl() == null
- || viewer.getControl().isDisposed())
- return;
-
- viewer.setSelection(StructuredSelection.EMPTY);
- }
- });
-
- if (selection == null || selection.isEmpty()
- || !(selection instanceof IStructuredSelection)) {
- templateOpening = false;
- return;
- }
-
- Object selectedElement = ((IStructuredSelection) selection)
- .getFirstElement();
- if (selectedElement == null || !(selectedElement instanceof ITemplate))
- return;
-
- ITemplate template = (ITemplate) selectedElement;
- IEditorInput editorInput = MindMapUI.getEditorInputFactory()
- .createEditorInput(template.createWorkbookRef());
- getContext().openEditor(editorInput, MindMapUI.MINDMAP_EDITOR_ID);
-
- templateOpening = false;
- }
-
- public T getAdapter(Class adapter) {
- if (viewer != null) {
- if (adapter.isAssignableFrom(viewer.getClass()))
- return adapter.cast(viewer);
- T obj = viewer.getAdapter(adapter);
- if (obj != null)
- return obj;
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.xmind.cathy.internal.ICathyConstants;
+import org.xmind.core.internal.UserDataConstants;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.internal.MindMapUIPlugin;
+import org.xmind.ui.internal.dashboard.pages.DashboardPage;
+import org.xmind.ui.internal.dashboard.pages.IDashboardContext;
+import org.xmind.ui.mindmap.IResourceManagerListener;
+import org.xmind.ui.mindmap.ITemplate;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class NewFromTemplatesDashboardPage extends DashboardPage
+ implements IResourceManagerListener, IAdaptable {
+
+ private CategorizedTemplateViewer viewer;
+
+ private boolean templateOpening;
+
+ public void setFocus() {
+ if (viewer != null && viewer.getControl() != null
+ && !viewer.getControl().isDisposed()) {
+ viewer.getControl().setFocus();
+ }
+ }
+
+ @Override
+ public void dispose() {
+ MindMapUI.getResourceManager().removeResourceManagerListener(this);
+ super.dispose();
+ }
+
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ layout.marginLeft = 60;
+ layout.marginRight = 0;
+ layout.marginHeight = 7;
+ container.setLayout(layout);
+
+ MindMapUIPlugin.getDefault().getUsageDataCollector()
+ .trackView(UserDataConstants.VIEW_TEMPLATES);
+ viewer = new CategorizedTemplateViewer(container);
+ Control control = viewer.getControl();
+ control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ viewer.addOpenListener(new IOpenListener() {
+ public void open(OpenEvent event) {
+ if (!templateOpening) {
+ handleTemplateSelected(event.getSelection());
+ MindMapUIPlugin.getDefault().getUsageDataCollector()
+ .trackEvent(UserDataConstants.CATEGORY_WORKBOOK,
+ UserDataConstants.CREATE_WORKBOOK);
+ MindMapUIPlugin.getDefault().getUsageDataCollector()
+ .trackEvent(UserDataConstants.CATEGORY_TEMPLATE,
+ UserDataConstants.USE_TEMPLATES);
+ }
+ }
+ });
+
+ MindMapUI.getResourceManager().addResourceManagerListener(this);
+
+ registerContextMenu(control);
+ setControl(container);
+ }
+
+ public void registerAvailableCommands() {
+ IDashboardContext context = getContext();
+
+ context.registerAvailableCommandId(
+ ICathyConstants.COMMAND_TEMPLATE_DUPLICATE);
+ context.registerAvailableCommandId(
+ ICathyConstants.COMMAND_TEMPLATE_RENAME);
+ context.registerAvailableCommandId(
+ ICathyConstants.COMMAND_TEMPLATE_DELETE);
+ }
+
+ private void registerContextMenu(Control control) {
+ getContext().registerContextMenu(control,
+ ICathyConstants.POPUP_TEMPLATE);
+
+ //add context menu for nested viewers' control.
+ Object input = viewer.getInput();
+ if (input instanceof Object[]) {
+ Object[] groups = (Object[]) viewer.getInput();
+ for (Object group : groups) {
+ GalleryViewer nestedViewer = viewer.getNestedViewer(group);
+ if (nestedViewer != null) {
+ nestedViewer.getControl().setMenu(control.getMenu());
+ }
+ }
+ }
+ }
+
+ public void addSelectionChangedListener(
+ ISelectionChangedListener listener) {
+ if (viewer != null) {
+ viewer.addSelectionChangedListener(listener);
+ }
+ }
+
+ public void userTemplateAdded(ITemplate template) {
+ if (viewer != null) {
+ viewer.userTemplateAdded(template);
+ }
+ }
+
+ public void userTemplateRemoved(ITemplate template) {
+ if (viewer != null) {
+ viewer.userTemplateRemoved(template);
+ }
+ }
+
+ private void handleTemplateSelected(ISelection selection) {
+ templateOpening = true;
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ if (viewer == null || viewer.getControl() == null
+ || viewer.getControl().isDisposed())
+ return;
+
+ viewer.setSelection(StructuredSelection.EMPTY);
+ }
+ });
+
+ if (selection == null || selection.isEmpty()
+ || !(selection instanceof IStructuredSelection)) {
+ templateOpening = false;
+ return;
+ }
+
+ Object selectedElement = ((IStructuredSelection) selection)
+ .getFirstElement();
+ if (selectedElement == null || !(selectedElement instanceof ITemplate))
+ return;
+
+ ITemplate template = (ITemplate) selectedElement;
+ if (template != null && null != template.getName())
+ MindMapUIPlugin.getDefault().getUsageDataCollector().trackEvent(
+ UserDataConstants.CATEGORY_TEMPLATE,
+ String.format(UserDataConstants.USE_TEMPLATE_S,
+ template.getName().replaceAll(" ", "_"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+ IEditorInput editorInput = MindMapUI.getEditorInputFactory()
+ .createEditorInput(template.createWorkbookRef());
+ getContext().openEditor(editorInput, MindMapUI.MINDMAP_EDITOR_ID);
+
+ templateOpening = false;
+ }
+
+ public T getAdapter(Class adapter) {
+ if (viewer != null) {
+ if (adapter.isAssignableFrom(viewer.getClass()))
+ return adapter.cast(viewer);
+ T obj = viewer.getAdapter(adapter);
+ if (obj != null)
+ return obj;
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentContainerLayout.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentContainerLayout.java
index a5682be5e..931d6c240 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentContainerLayout.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentContainerLayout.java
@@ -1,106 +1,106 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.draw2d.AbstractHintLayout;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Rectangle;
-
-public class RecentContainerLayout extends AbstractHintLayout {
- private Map constraints = new HashMap();
-
- public RecentContainerLayout() {
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.draw2d.AbstractLayout#setConstraint(org.eclipse.draw2d.
- * IFigure, java.lang.Object)
- */
- @Override
- public void setConstraint(IFigure child, Object constraint) {
- constraints.put(child, constraint);
- super.setConstraint(child, constraint);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.draw2d.AbstractLayout#getConstraint(org.eclipse.draw2d.
- * IFigure)
- */
- @Override
- public Object getConstraint(IFigure child) {
- Object constraint = constraints.get(child);
- return constraint == null ? super.getConstraint(child) : constraint;
- }
-
- public void layout(IFigure container) {
- Rectangle area = container.getClientArea();
- for (Object child : container.getChildren()) {
- IFigure figure = (IFigure) child;
- Dimension childSize = figure.getPreferredSize(-1, -1);
- int childWidth = Math.min(area.width, childSize.width);
- int childHeight = Math.min(area.height, childSize.height);
-
- int childX, childY;
- Object constraint = getConstraint(figure);
- if (constraint instanceof Integer) {
- int bit = ((Integer) constraint).intValue();
- if ((bit & PositionConstants.LEFT) != 0) {
- childX = area.x;
- } else if ((bit & PositionConstants.RIGHT) != 0) {
- childX = area.x + area.width - childWidth;
- } else if ((bit & PositionConstants.CENTER) != 0) {
- childX = area.x + (area.width - childWidth) / 2;
- } else {
- childX = area.x;
- childWidth = area.width;
- }
- if ((bit & PositionConstants.TOP) != 0) {
- childY = area.y;
- } else if ((bit & PositionConstants.BOTTOM) != 0) {
- childY = area.y + area.height - childHeight;
- } else if ((bit & PositionConstants.MIDDLE) != 0) {
- childY = area.y + (area.height - childHeight) / 2;
- } else {
- childY = area.y;
- childHeight = area.height;
- }
- } else {
- childX = area.x;
- childY = area.y;
- childWidth = area.width;
- childHeight = area.height;
- }
-
- figure.setBounds(
- new Rectangle(childX, childY, childWidth, childHeight));
- }
- }
-
- @Override
- protected Dimension calculatePreferredSize(IFigure figure, int wHint,
- int hHint) {
- if (wHint > -1)
- wHint = Math.max(0, wHint - figure.getInsets().getWidth());
- if (hHint > -1)
- hHint = Math.max(0, hHint - figure.getInsets().getHeight());
-
- Dimension d = new Dimension();
- List children = figure.getChildren();
- IFigure child;
- for (int i = 0; i < children.size(); i++) {
- child = (IFigure) children.get(i);
- if (!isObservingVisibility() || child.isVisible())
- d.union(child.getPreferredSize(wHint, hHint));
- }
-
- d.expand(figure.getInsets().getWidth(), figure.getInsets().getHeight());
- d.union(getBorderPreferredSize(figure));
- return d;
- }
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.draw2d.AbstractHintLayout;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+public class RecentContainerLayout extends AbstractHintLayout {
+ private Map constraints = new HashMap();
+
+ public RecentContainerLayout() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.draw2d.AbstractLayout#setConstraint(org.eclipse.draw2d.
+ * IFigure, java.lang.Object)
+ */
+ @Override
+ public void setConstraint(IFigure child, Object constraint) {
+ constraints.put(child, constraint);
+ super.setConstraint(child, constraint);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.draw2d.AbstractLayout#getConstraint(org.eclipse.draw2d.
+ * IFigure)
+ */
+ @Override
+ public Object getConstraint(IFigure child) {
+ Object constraint = constraints.get(child);
+ return constraint == null ? super.getConstraint(child) : constraint;
+ }
+
+ public void layout(IFigure container) {
+ Rectangle area = container.getClientArea();
+ for (Object child : container.getChildren()) {
+ IFigure figure = (IFigure) child;
+ Dimension childSize = figure.getPreferredSize(-1, -1);
+ int childWidth = Math.min(area.width, childSize.width);
+ int childHeight = Math.min(area.height, childSize.height);
+
+ int childX, childY;
+ Object constraint = getConstraint(figure);
+ if (constraint instanceof Integer) {
+ int bit = ((Integer) constraint).intValue();
+ if ((bit & PositionConstants.LEFT) != 0) {
+ childX = area.x;
+ } else if ((bit & PositionConstants.RIGHT) != 0) {
+ childX = area.x + area.width - childWidth;
+ } else if ((bit & PositionConstants.CENTER) != 0) {
+ childX = area.x + (area.width - childWidth) / 2;
+ } else {
+ childX = area.x;
+ childWidth = area.width;
+ }
+ if ((bit & PositionConstants.TOP) != 0) {
+ childY = area.y;
+ } else if ((bit & PositionConstants.BOTTOM) != 0) {
+ childY = area.y + area.height - childHeight;
+ } else if ((bit & PositionConstants.MIDDLE) != 0) {
+ childY = area.y + (area.height - childHeight) / 2;
+ } else {
+ childY = area.y;
+ childHeight = area.height;
+ }
+ } else {
+ childX = area.x;
+ childY = area.y;
+ childWidth = area.width;
+ childHeight = area.height;
+ }
+
+ figure.setBounds(
+ new Rectangle(childX, childY, childWidth, childHeight));
+ }
+ }
+
+ @Override
+ protected Dimension calculatePreferredSize(IFigure figure, int wHint,
+ int hHint) {
+ if (wHint > -1)
+ wHint = Math.max(0, wHint - figure.getInsets().getWidth());
+ if (hHint > -1)
+ hHint = Math.max(0, hHint - figure.getInsets().getHeight());
+
+ Dimension d = new Dimension();
+ List children = figure.getChildren();
+ IFigure child;
+ for (int i = 0; i < children.size(); i++) {
+ child = (IFigure) children.get(i);
+ if (!isObservingVisibility() || child.isVisible())
+ d.union(child.getPreferredSize(wHint, hHint));
+ }
+
+ d.expand(figure.getInsets().getWidth(), figure.getInsets().getHeight());
+ d.union(getBorderPreferredSize(figure));
+ return d;
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileBlankPage.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileBlankPage.java
index 33f7e7547..bdc90cd49 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileBlankPage.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileBlankPage.java
@@ -1,81 +1,81 @@
-package org.xmind.cathy.internal.dashboard;
-
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.ui.resources.ColorUtils;
-import org.xmind.ui.views.Page;
-
-public class RecentFileBlankPage extends Page {
-
- private static final String COLOR_DESCRIPTION = "#9B9B9B"; //$NON-NLS-1$
- private LocalResourceManager resources;
-
- @Override
- protected Control doCreateControl(Composite parent) {
- final Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- composite.setForeground(parent.getForeground());
- GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(composite);
-
- if (resources == null)
- resources = new LocalResourceManager(JFaceResources.getResources(),
- composite);
- return createContent(composite);
- }
-
- private Control createContent(Composite parent) {
- Composite panel = new Composite(parent, SWT.NONE);
- panel.setBackground(parent.getBackground());
- GridLayoutFactory.fillDefaults().spacing(0, 24)
- .extendedMargins(0, 0, 0, 100).applyTo(panel);
- GridDataFactory.fillDefaults().grab(true, true)
- .align(SWT.CENTER, SWT.CENTER).applyTo(panel);
-
- Label imageLabel = new Label(panel, SWT.NONE);
- imageLabel.setImage((Image) resources.get(
- CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
- "dashboard/recent/blank_recent.png"))); //$NON-NLS-1$
- GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER)
- .grab(true, false).applyTo(imageLabel);
- Point imageSize = imageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-
- Control textArea = createTextArea(panel);
- GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.FILL)
- .grab(true, false).hint(imageSize.x + 140, SWT.DEFAULT)
- .applyTo(textArea);
-
- return parent;
- }
-
- private Control createTextArea(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- composite.setForeground(parent.getForeground());
- GridLayoutFactory.fillDefaults().spacing(0, 24).applyTo(composite);
-
- Label descriptionLabel = new Label(composite, SWT.CENTER | SWT.WRAP);
- descriptionLabel.setForeground((Color) resources
- .get(ColorUtils.toDescriptor(COLOR_DESCRIPTION)));
- descriptionLabel.setFont(
- (Font) resources.get(JFaceResources.getDefaultFontDescriptor()
- .setStyle(SWT.NORMAL).setHeight(12)));
- descriptionLabel
- .setText(WorkbenchMessages.RecentFileBlankPage_description);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
- .grab(true, false).applyTo(descriptionLabel);
-
- return composite;
- }
-}
+package org.xmind.cathy.internal.dashboard;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.ui.resources.ColorUtils;
+import org.xmind.ui.views.Page;
+
+public class RecentFileBlankPage extends Page {
+
+ private static final String COLOR_DESCRIPTION = "#9B9B9B"; //$NON-NLS-1$
+ private LocalResourceManager resources;
+
+ @Override
+ protected Control doCreateControl(Composite parent) {
+ final Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ composite.setForeground(parent.getForeground());
+ GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(composite);
+
+ if (resources == null)
+ resources = new LocalResourceManager(JFaceResources.getResources(),
+ composite);
+ return createContent(composite);
+ }
+
+ private Control createContent(Composite parent) {
+ Composite panel = new Composite(parent, SWT.NONE);
+ panel.setBackground(parent.getBackground());
+ GridLayoutFactory.fillDefaults().spacing(0, 24)
+ .extendedMargins(0, 0, 0, 100).applyTo(panel);
+ GridDataFactory.fillDefaults().grab(true, true)
+ .align(SWT.CENTER, SWT.CENTER).applyTo(panel);
+
+ Label imageLabel = new Label(panel, SWT.NONE);
+ imageLabel.setImage((Image) resources.get(
+ CathyPlugin.imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
+ "dashboard/recent/blank_recent.png"))); //$NON-NLS-1$
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER)
+ .grab(true, false).applyTo(imageLabel);
+ Point imageSize = imageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+
+ Control textArea = createTextArea(panel);
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.FILL)
+ .grab(true, false).hint(imageSize.x + 140, SWT.DEFAULT)
+ .applyTo(textArea);
+
+ return parent;
+ }
+
+ private Control createTextArea(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ composite.setForeground(parent.getForeground());
+ GridLayoutFactory.fillDefaults().spacing(0, 24).applyTo(composite);
+
+ Label descriptionLabel = new Label(composite, SWT.CENTER | SWT.WRAP);
+ descriptionLabel.setForeground((Color) resources
+ .get(ColorUtils.toDescriptor(COLOR_DESCRIPTION)));
+ descriptionLabel.setFont(
+ (Font) resources.get(JFaceResources.getDefaultFontDescriptor()
+ .setStyle(SWT.NORMAL).setHeight(12)));
+ descriptionLabel
+ .setText(WorkbenchMessages.RecentFileBlankPage_description);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
+ .grab(true, false).applyTo(descriptionLabel);
+
+ return composite;
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileGridDashboardPage.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileGridDashboardPage.java
index 0d89de052..5c92cec80 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileGridDashboardPage.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileGridDashboardPage.java
@@ -1,117 +1,123 @@
-package org.xmind.cathy.internal.dashboard;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IWorkbenchCommandConstants;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.cathy.internal.ICathyConstants;
-import org.xmind.ui.editor.IEditorHistory;
-import org.xmind.ui.editor.IEditorHistory.IEditorHistoryListener;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.internal.dashboard.pages.DashboardPage;
-import org.xmind.ui.internal.dashboard.pages.IDashboardContext;
-import org.xmind.ui.views.IPage;
-import org.xmind.ui.views.PageStack;
-
-public class RecentFileGridDashboardPage extends DashboardPage
- implements IAdaptable {
-
- private static final String COMMAND_OPEN_SEAWIND_FILE_ID = "org.xmind.ui.seawind.command.openSeawindFile"; //$NON-NLS-1$
-
- private static final String COMMAND_OPEN_LOCAL_FILE_ID = "org.xmind.ui.mindmap.command.openLocalFile"; //$NON-NLS-1$
-
- private GalleryViewer viewer;
-
- private PageStack stack;
-
- IPage recentBlankPage;
-
- IPage recentFileGridPage;
-
- public void createControl(Composite parent) {
-
- stack = new PageStack();
- stack.createControl(parent);
- stack.getControl().setBackground(parent.getBackground());
-
- final IEditorHistory editorHistory = PlatformUI.getWorkbench()
- .getService(IEditorHistory.class);
- editorHistory.addEditorHistoryListener(new IEditorHistoryListener() {
-
- @Override
- public void editorHistoryChanged() {
- if (getControl() == null || getControl().isDisposed())
- return;
- if (Display.getCurrent() == null)
- return;
- showPage(editorHistory);
- }
- });
-
- //do chose which viewer will show;
- showPage(editorHistory);
- }
-
- private void showPage(final IEditorHistory editorHistory) {
- Composite composite = stack.getStackComposite();
-
- if (editorHistory.getAllInputURIs().length == 0) {
- if (recentBlankPage == null) {
- recentBlankPage = new RecentFileBlankPage();
- recentBlankPage.createControl(composite);
- }
- stack.showPage(recentBlankPage);
- } else {
- if (recentFileGridPage == null) {
- recentFileGridPage = new RecentFileGridPage();
- recentFileGridPage.createControl(composite);
- viewer = recentFileGridPage.getAdapter(GalleryViewer.class);
- }
- stack.showPage(recentFileGridPage);
- }
- setControl(stack.getControl());
- stack.setFocus();
- }
-
- @Override
- public void setContext(IDashboardContext context) {
- super.setContext(context);
- context.registerAvailableCommandId(
- ICathyConstants.COMMAND_RECENTFILE_PIN);
- context.registerAvailableCommandId(
- ICathyConstants.COMMAND_RECENTFILE_UNPIN);
- context.registerAvailableCommandId(
- ICathyConstants.COMMAND_RECENTFILE_CLEAR);
- context.registerAvailableCommandId(
- IWorkbenchCommandConstants.EDIT_DELETE);
-
- //register command in DashboardContext
- context.registerAvailableCommandId(COMMAND_OPEN_SEAWIND_FILE_ID);
- context.registerAvailableCommandId(COMMAND_OPEN_LOCAL_FILE_ID);
- }
-
- public void setFocus() {
- if (viewer != null && viewer.getControl() != null
- && !viewer.getControl().isDisposed()) {
- getContext().registerContextMenu(viewer.getControl(),
- ICathyConstants.POPUP_RECENTFILE);
- }
- if (stack != null && stack.getControl() != null
- && !stack.getControl().isDisposed()) {
- stack.setFocus();
- }
- }
-
- public T getAdapter(Class adapter) {
- if (viewer != null) {
- if (adapter.isAssignableFrom(viewer.getClass()))
- return adapter.cast(viewer);
- T obj = viewer.getAdapter(adapter);
- if (obj != null)
- return obj;
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchCommandConstants;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.cathy.internal.ICathyConstants;
+import org.xmind.ui.editor.IEditorHistory;
+import org.xmind.ui.editor.IEditorHistory.IEditorHistoryListener;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.internal.dashboard.pages.DashboardPage;
+import org.xmind.ui.internal.dashboard.pages.IDashboardContext;
+import org.xmind.ui.views.IPage;
+import org.xmind.ui.views.PageStack;
+
+public class RecentFileGridDashboardPage extends DashboardPage
+ implements IAdaptable {
+
+ private GalleryViewer viewer;
+
+ private PageStack stack;
+
+ IPage recentBlankPage;
+
+ IPage recentFileGridPage;
+
+ private IEditorHistoryListener editorHistoryListener = new IEditorHistoryListener() {
+
+ @Override
+ public void editorHistoryChanged() {
+ if (getControl() == null || getControl().isDisposed())
+ return;
+ if (Display.getCurrent() == null)
+ return;
+ showPage(editorHistory);
+ }
+ };
+
+ private IEditorHistory editorHistory;
+
+ public void createControl(Composite parent) {
+
+ stack = new PageStack();
+ stack.createControl(parent);
+ stack.getControl().setBackground(parent.getBackground());
+
+ editorHistory = PlatformUI.getWorkbench()
+ .getService(IEditorHistory.class);
+ editorHistory.addEditorHistoryListener(editorHistoryListener);
+
+ //do chose which viewer will show;
+ showPage(editorHistory);
+ }
+
+ @Override
+ public void dispose() {
+ if (editorHistory != null) {
+ editorHistory.removeEditorHistoryListener(editorHistoryListener);
+ editorHistory = null;
+ }
+ super.dispose();
+ }
+
+ private void showPage(final IEditorHistory editorHistory) {
+ Composite composite = stack.getStackComposite();
+
+ if (editorHistory.getAllInputURIs().length == 0) {
+ if (recentBlankPage == null) {
+ recentBlankPage = new RecentFileBlankPage();
+ recentBlankPage.createControl(composite);
+ }
+ stack.showPage(recentBlankPage);
+ } else {
+ if (recentFileGridPage == null) {
+ recentFileGridPage = new RecentFileGridPage();
+ recentFileGridPage.createControl(composite);
+ viewer = recentFileGridPage.getAdapter(GalleryViewer.class);
+ }
+ stack.showPage(recentFileGridPage);
+ }
+ setControl(stack.getControl());
+ stack.setFocus();
+ }
+
+ @Override
+ public void setContext(IDashboardContext context) {
+ super.setContext(context);
+ context.registerAvailableCommandId(
+ ICathyConstants.COMMAND_RECENTFILE_PIN);
+ context.registerAvailableCommandId(
+ ICathyConstants.COMMAND_RECENTFILE_UNPIN);
+ context.registerAvailableCommandId(
+ ICathyConstants.COMMAND_RECENTFILE_CLEAR);
+ context.registerAvailableCommandId(
+ IWorkbenchCommandConstants.EDIT_DELETE);
+
+ }
+
+ public void setFocus() {
+ if (viewer != null && viewer.getControl() != null
+ && !viewer.getControl().isDisposed()) {
+ getContext().registerContextMenu(viewer.getControl(),
+ ICathyConstants.POPUP_RECENTFILE);
+ }
+ if (stack != null && stack.getControl() != null
+ && !stack.getControl().isDisposed()) {
+ stack.setFocus();
+ }
+ }
+
+ public T getAdapter(Class adapter) {
+ if (viewer != null) {
+ if (adapter.isAssignableFrom(viewer.getClass()))
+ return adapter.cast(viewer);
+ T obj = viewer.getAdapter(adapter);
+ if (obj != null)
+ return obj;
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileGridPage.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileGridPage.java
index a7ddbe5c1..0c0b4c723 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileGridPage.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileGridPage.java
@@ -1,177 +1,159 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.net.URI;
-
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.IParameter;
-import org.eclipse.core.commands.Parameterization;
-import org.eclipse.core.commands.ParameterizedCommand;
-import org.eclipse.core.commands.common.NotDefinedException;
-import org.eclipse.e4.core.commands.ECommandService;
-import org.eclipse.e4.core.commands.EHandlerService;
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.viewers.IOpenListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.OpenEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.resources.ColorUtils;
-import org.xmind.ui.views.Page;
-
-public class RecentFileGridPage extends Page {
-
- private static final String COMMANDPARAMETER_OPEN_CLOUD_FILE_URI = "org.xmind.ui.seawind.commandparameter.openCloudFile.uri"; //$NON-NLS-1$
-
- private static final String COMMAND_OPEN_SEAWIND_FILE_ID = "org.xmind.ui.seawind.command.openSeawindFile"; //$NON-NLS-1$
-
- private static final String COMMAND_OPEN_LOCAL_FILE_ID = "org.xmind.ui.mindmap.command.openLocalFile"; //$NON-NLS-1$
-
- private static final String COMMANDPARAMETER_OPEN_LOCAL_FILE_URI = "org.xmind.ui.mindmap.commandparameter.openLocalFile.uri"; //$NON-NLS-1$
-
- private GalleryViewer viewer;
-
- private LocalResourceManager resources;
-
- @Override
- protected Control doCreateControl(Composite parent) {
- final Composite composite = new Composite(parent, SWT.NONE);
- composite.setBackground(parent.getBackground());
- composite.setForeground(parent.getForeground());
- GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(composite);
- GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
-
- if (null == resources)
- resources = new LocalResourceManager(JFaceResources.getResources(),
- composite);
- Composite titleBar = new Composite(composite, SWT.NONE);
- titleBar.setBackground(
- (Color) resources.get(ColorUtils.toDescriptor("#ececec"))); //$NON-NLS-1$
- titleBar.setForeground(composite.getForeground());
- GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(titleBar);
- GridData titleBarData = new GridData(SWT.FILL, SWT.FILL, true, false);
- titleBarData.heightHint = 44;
- titleBar.setLayoutData(titleBarData);
-
- Label titleLabel = new Label(titleBar, SWT.NONE);
- titleLabel.setBackground(titleBar.getBackground());
- titleLabel.setForeground(
- (Color) resources.get(ColorUtils.toDescriptor("#000000"))); //$NON-NLS-1$
-
- titleLabel.setFont((Font) resources.get(
- JFaceResources.getHeaderFontDescriptor().increaseHeight(-1)));
-
- titleLabel.setText(WorkbenchMessages.DashboardRecentFiles_message);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(true, true).applyTo(titleLabel);
-
- Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
- separator.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-
- Composite panel = new Composite(composite, SWT.NONE);
- GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(panel);
- GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
-
- createViewer(panel);
- return composite;
- }
-
- private void createViewer(Composite parent) {
- viewer = new RecentFileViewer(parent);
-
- viewer.addOpenListener(new IOpenListener() {
- public void open(OpenEvent event) {
- handleOpenRecentFile(event.getSelection());
- }
- });
- }
-
- private void handleOpenRecentFile(ISelection selection) {
- if (!(selection instanceof IStructuredSelection))
- return;
-
- Object element = ((IStructuredSelection) selection).getFirstElement();
- if (!(element instanceof URI))
- return;
-
- URI uri = (URI) element;
- if (uri.getScheme().equalsIgnoreCase("seawind")) {//$NON-NLS-1$
- // TODO do execute command openEditor by seawind plugin
- openCloudFile(uri);
- } else if (uri.getScheme().equalsIgnoreCase("file")) { //$NON-NLS-1$
- //TODO do execute command openEditor by mindmap plugin
- openLocalFile(uri);
- }
- }
-
- private void openLocalFile(final URI uri) {
- executeCommand(COMMAND_OPEN_LOCAL_FILE_ID,
- COMMANDPARAMETER_OPEN_LOCAL_FILE_URI, uri);
- }
-
- private void openCloudFile(final URI uri) {
- executeCommand(COMMAND_OPEN_SEAWIND_FILE_ID,
- COMMANDPARAMETER_OPEN_CLOUD_FILE_URI, uri);
- }
-
- private void executeCommand(String commandId, String parameter, URI uri) {
- IWorkbenchWindow window = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- if (window == null)
- return;
-
- final EHandlerService hs = window.getService(EHandlerService.class);
- final ECommandService cs = window.getService(ECommandService.class);
-
- if (hs == null || cs == null)
- return;
-
- final Command command = cs.getCommand(commandId);
- if (command == null || !command.isDefined())
- return;
-
- try {
- IParameter param = command.getParameter(parameter);
- if (param == null)
- return;
-
- ParameterizedCommand pc = new ParameterizedCommand(command,
- new Parameterization[] {
- new Parameterization(param, uri.toString()) });
-
- if (!hs.canExecute(pc))
- return;
- hs.executeHandler(pc);
-
- } catch (NotDefinedException e) {
- CathyPlugin.log(e, this.getClass().getName()
- + "-->execute openLocalFileHandler or openCloudFileHandler"); //$NON-NLS-1$
- }
- }
-
- @Override
- public T getAdapter(Class adapter) {
- if (viewer != null) {
- if (adapter.isAssignableFrom(viewer.getClass()))
- return adapter.cast(viewer);
- T obj = viewer.getAdapter(adapter);
- if (obj != null)
- return obj;
- }
- return super.getAdapter(adapter);
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.net.URI;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IParameter;
+import org.eclipse.core.commands.Parameterization;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.ui.commands.MindMapCommandConstants;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.resources.ColorUtils;
+import org.xmind.ui.views.Page;
+
+public class RecentFileGridPage extends Page {
+
+ private GalleryViewer viewer;
+
+ private LocalResourceManager resources;
+
+ @Override
+ protected Control doCreateControl(Composite parent) {
+ final Composite composite = new Composite(parent, SWT.NONE);
+ composite.setBackground(parent.getBackground());
+ composite.setForeground(parent.getForeground());
+ GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(composite);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
+
+ if (null == resources)
+ resources = new LocalResourceManager(JFaceResources.getResources(),
+ composite);
+ Composite titleBar = new Composite(composite, SWT.NONE);
+ titleBar.setBackground(
+ (Color) resources.get(ColorUtils.toDescriptor("#ececec"))); //$NON-NLS-1$
+ titleBar.setForeground(composite.getForeground());
+ GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(titleBar);
+ GridData titleBarData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ titleBarData.heightHint = 44;
+ titleBar.setLayoutData(titleBarData);
+
+ Label titleLabel = new Label(titleBar, SWT.NONE);
+ titleLabel.setBackground(titleBar.getBackground());
+ titleLabel.setForeground(
+ (Color) resources.get(ColorUtils.toDescriptor("#000000"))); //$NON-NLS-1$
+
+ titleLabel.setFont((Font) resources.get(
+ JFaceResources.getHeaderFontDescriptor().increaseHeight(-1)));
+
+ titleLabel.setText(WorkbenchMessages.DashboardRecentFiles_message);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
+ .grab(true, true).applyTo(titleLabel);
+
+ Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ separator.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+ Composite panel = new Composite(composite, SWT.NONE);
+ GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(panel);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
+
+ createViewer(panel);
+ return composite;
+ }
+
+ private void createViewer(Composite parent) {
+ viewer = new RecentFileViewer(parent);
+
+ viewer.addOpenListener(new IOpenListener() {
+ public void open(OpenEvent event) {
+ handleOpenRecentFile(event.getSelection());
+ }
+ });
+ }
+
+ private void handleOpenRecentFile(ISelection selection) {
+ if (!(selection instanceof IStructuredSelection))
+ return;
+
+ Object element = ((IStructuredSelection) selection).getFirstElement();
+ if (!(element instanceof URI))
+ return;
+
+ URI uri = (URI) element;
+ openFile(uri);
+ }
+
+ private void openFile(final URI uri) {
+ executeCommand(MindMapCommandConstants.OPEN_WORKBOOK,
+ MindMapCommandConstants.OPEN_WORKBOOK_PARAM_URI, uri);
+ }
+
+ private void executeCommand(String commandId, String parameter, URI uri) {
+ IWorkbenchWindow window = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (window == null)
+ return;
+
+ final EHandlerService hs = window.getService(EHandlerService.class);
+ final ECommandService cs = window.getService(ECommandService.class);
+
+ if (hs == null || cs == null)
+ return;
+
+ final Command command = cs.getCommand(commandId);
+ if (command == null || !command.isDefined())
+ return;
+
+ try {
+ IParameter param = command.getParameter(parameter);
+ if (param == null)
+ return;
+
+ ParameterizedCommand pc = new ParameterizedCommand(command,
+ new Parameterization[] {
+ new Parameterization(param, uri.toString()) });
+
+ if (!hs.canExecute(pc))
+ return;
+ hs.executeHandler(pc);
+
+ } catch (NotDefinedException e) {
+ CathyPlugin.log(e, this.getClass().getName()
+ + "-->execute openLocalFileHandler or openCloudFileHandler"); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public T getAdapter(Class adapter) {
+ if (viewer != null) {
+ if (adapter.isAssignableFrom(viewer.getClass()))
+ return adapter.cast(viewer);
+ T obj = viewer.getAdapter(adapter);
+ if (obj != null)
+ return obj;
+ }
+ return super.getAdapter(adapter);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileViewer.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileViewer.java
index f5e810997..ace73bc65 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileViewer.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFileViewer.java
@@ -1,200 +1,220 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.net.URI;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Insets;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.cathy.internal.ICathyConstants;
-import org.xmind.cathy.internal.dashboard.RecentFilesGalleryPartFactory.RecentFilesFramePart;
-import org.xmind.gef.EditDomain;
-import org.xmind.gef.GEF;
-import org.xmind.gef.ui.internal.SpaceCollaborativeEngine;
-import org.xmind.gef.util.Properties;
-import org.xmind.ui.editor.IEditorHistory;
-import org.xmind.ui.gallery.GalleryLayout;
-import org.xmind.ui.gallery.GalleryNavigablePolicy;
-import org.xmind.ui.gallery.GallerySelectTool;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.resources.ColorUtils;
-
-public class RecentFileViewer extends GalleryViewer {
-
- private static final int FRAME_WIDTH = 215;
- private static final int FRAME_HEIGHT = 130;
- private static final String COLOR_CONTENT_BORDER = "#cccccc"; //$NON-NLS-1$
-
- private IEditorHistory editorHistory;
-
- private LocalResourceManager resources;
- private Control viewerControl;
-
- public RecentFileViewer(Composite parent) {
- editorHistory = PlatformUI.getWorkbench()
- .getService(IEditorHistory.class);
- initViewer(parent);
- registerHelper(parent.getShell());
- }
-
- private void registerHelper(Shell shell) {
- shell.setData(ICathyConstants.HELPER_RECENTFILE_PIN, new Runnable() {
- public void run() {
- final ISelection selection = getSelection();
- if (selection instanceof IStructuredSelection) {
- final List list = ((IStructuredSelection) selection)
- .toList();
- for (final Object element : list) {
- if (element instanceof URI) {
- final boolean isChecked = editorHistory
- .isPinned((URI) element);
- if (isChecked) {
- unPinRecentFile((URI) element);
- } else {
- pinRecentFile((URI) element);
- }
- }
- }
- }
-
- }
- });
- shell.setData(ICathyConstants.HELPER_RECENTFILE_DELETE, new Runnable() {
- public void run() {
- final ISelection selection = getSelection();
- if (selection instanceof IStructuredSelection) {
- final List list = ((IStructuredSelection) selection)
- .toList();
- for (final Object element : list) {
- if (element instanceof URI) {
- deleteRecentFile((URI) element);
- }
- }
- }
- }
- });
- shell.setData(ICathyConstants.HELPER_RECENTFILE_CLEAR, new Runnable() {
- public void run() {
- clearRecentFile();
- }
- });
- }
-
- @SuppressWarnings("restriction")
- private void initViewer(final Composite parent) {
- if (resources == null)
- resources = new LocalResourceManager(JFaceResources.getResources(),
- parent);
-
- EditDomain editDomain = new EditDomain();
- editDomain.installTool(GEF.TOOL_SELECT, new GallerySelectTool());
- editDomain.installEditPolicy(GalleryViewer.POLICY_NAVIGABLE,
- new GalleryNavigablePolicy());
- setEditDomain(editDomain);
-
- Properties properties = getProperties();
- properties.set(GalleryViewer.Horizontal, Boolean.TRUE);
- properties.set(GalleryViewer.Wrap, Boolean.TRUE);
- properties.set(GalleryViewer.TitlePlacement,
- GalleryViewer.TITLE_BOTTOM);
- properties.set(GalleryViewer.SingleClickToOpen, Boolean.FALSE);
- properties.set(GalleryViewer.SolidFrames, true);
- properties.set(GalleryViewer.FlatFrames, true);
- properties.set(GalleryViewer.ImageConstrained, Boolean.TRUE);
- properties.set(GalleryViewer.ImageStretched, Boolean.TRUE);
- properties.set(GalleryViewer.ContentPaneBorderWidth, 1);
- properties.set(GalleryViewer.CustomContentPaneDecorator, true);
- properties.set(GalleryViewer.ContentPaneBorderColor,
- resources.get(ColorUtils.toDescriptor(COLOR_CONTENT_BORDER)));
-
- properties.set(GalleryViewer.FrameContentSize,
- new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
- properties.set(GalleryViewer.Layout,
- new GalleryLayout(GalleryLayout.ALIGN_TOPLEFT,
- GalleryLayout.ALIGN_TOPLEFT, 30, 0,
- new Insets(10, 65, 20, 65)));
- properties.set(GalleryViewer.ContentPaneSpaceCollaborativeEngine,
- new SpaceCollaborativeEngine());
-
- final RecentFilesContentProvider contentProvider = new RecentFilesContentProvider();
- final RecentFilesLabelProvider labelProvider = new RecentFilesLabelProvider(
- parent);
- contentProvider.addContentChangeListener(new Runnable() {
- public void run() {
- handleRecentFileListChanged(contentProvider, labelProvider,
- true);
- parent.layout(true);
- }
- });
-
- viewerControl = createControl(parent);
- viewerControl.setBackground(parent.getBackground());
- viewerControl.setForeground(parent.getForeground());
- viewerControl
- .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- setPartFactory(new RecentFilesGalleryPartFactory());
- setContentProvider(contentProvider);
- setLabelProvider(labelProvider);
-
- IEditorHistory editorHistory = PlatformUI.getWorkbench()
- .getService(IEditorHistory.class);
- editorHistory.addEditorHistoryListener(contentProvider);
- setInput(editorHistory);
- handleRecentFileListChanged(contentProvider, labelProvider, true);
- }
-
- @Override
- public Control getControl() {
- if (viewerControl != null)
- return viewerControl;
- return super.getControl();
- }
-
- private void handleRecentFileListChanged(
- RecentFilesContentProvider contentProvider,
- RecentFilesLabelProvider labelProvider, boolean refresh) {
- if (refresh) {
- setInput(getInput());
- }
- }
-
- private void clearRecentFile() {
- editorHistory.clear();
- }
-
- private void deleteRecentFile(URI fileURI) {
- editorHistory.remove(fileURI);
- }
-
- private void pinRecentFile(URI fileURI) {
- editorHistory.pin(fileURI);
- updateRecentFilePart(fileURI);
- }
-
- private void unPinRecentFile(URI fileURI) {
- editorHistory.unPin(fileURI);
- updateRecentFilePart(fileURI);
- }
-
- private void updateRecentFilePart(URI pinURI) {
- RecentFilesFramePart part = findRecentFilePart(pinURI);
- if (part != null)
- part.update();
- }
-
- private RecentFilesFramePart findRecentFilePart(URI pinURI) {
- if (pinURI == null)
- return null;
- return (RecentFilesFramePart) getPartRegistry().getPartByModel(pinURI);
- }
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.net.URI;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Insets;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.cathy.internal.ICathyConstants;
+import org.xmind.cathy.internal.dashboard.RecentFilesGalleryPartFactory.RecentFilesFramePart;
+import org.xmind.gef.EditDomain;
+import org.xmind.gef.GEF;
+import org.xmind.gef.ui.internal.SpaceCollaborativeEngine;
+import org.xmind.gef.util.Properties;
+import org.xmind.ui.editor.IEditorHistory;
+import org.xmind.ui.gallery.GalleryLayout;
+import org.xmind.ui.gallery.GalleryNavigablePolicy;
+import org.xmind.ui.gallery.GallerySelectTool;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.resources.ColorUtils;
+
+public class RecentFileViewer extends GalleryViewer {
+
+ private static final int FRAME_WIDTH = 210;
+ private static final int FRAME_HEIGHT = 130;
+ private static final String COLOR_CONTENT_BORDER = "#cccccc"; //$NON-NLS-1$
+
+ private IEditorHistory editorHistory;
+
+ private LocalResourceManager resources;
+ private Control viewerControl;
+ private RecentFilesContentProvider contentProvider;
+
+ public RecentFileViewer(Composite parent) {
+ editorHistory = PlatformUI.getWorkbench()
+ .getService(IEditorHistory.class);
+ initViewer(parent);
+ registerHelper(parent.getShell());
+ }
+
+ private void registerHelper(Shell shell) {
+ shell.setData(ICathyConstants.HELPER_RECENTFILE_PIN, new Runnable() {
+ public void run() {
+ final ISelection selection = getSelection();
+ if (selection instanceof IStructuredSelection) {
+ final List list = ((IStructuredSelection) selection)
+ .toList();
+ for (final Object element : list) {
+ if (element instanceof URI) {
+ final boolean isChecked = editorHistory
+ .isPinned((URI) element);
+ if (isChecked) {
+ unPinRecentFile((URI) element);
+ } else {
+ pinRecentFile((URI) element);
+ }
+ }
+ }
+ }
+
+ }
+ });
+ shell.setData(ICathyConstants.HELPER_RECENTFILE_DELETE, new Runnable() {
+ public void run() {
+ final ISelection selection = getSelection();
+ if (selection instanceof IStructuredSelection) {
+ final List list = ((IStructuredSelection) selection)
+ .toList();
+ for (final Object element : list) {
+ if (element instanceof URI) {
+ deleteRecentFile((URI) element);
+ }
+ }
+ }
+ }
+ });
+ shell.setData(ICathyConstants.HELPER_RECENTFILE_CLEAR, new Runnable() {
+ public void run() {
+ clearRecentFile();
+ }
+ });
+ }
+
+ private void unregisterHelper(Shell shell) {
+ shell.setData(ICathyConstants.HELPER_RECENTFILE_CLEAR, null);
+ shell.setData(ICathyConstants.HELPER_RECENTFILE_DELETE, null);
+ shell.setData(ICathyConstants.HELPER_RECENTFILE_PIN, null);
+ }
+
+ private void handleDispose() {
+ if (viewerControl != null && !viewerControl.isDisposed())
+ unregisterHelper(viewerControl.getShell());
+ if (editorHistory != null)
+ editorHistory.removeEditorHistoryListener(contentProvider);
+ }
+
+ @SuppressWarnings("restriction")
+ private void initViewer(final Composite parent) {
+ if (resources == null)
+ resources = new LocalResourceManager(JFaceResources.getResources(),
+ parent);
+
+ EditDomain editDomain = new EditDomain();
+ editDomain.installTool(GEF.TOOL_SELECT, new GallerySelectTool());
+ editDomain.installEditPolicy(GalleryViewer.POLICY_NAVIGABLE,
+ new GalleryNavigablePolicy());
+ setEditDomain(editDomain);
+
+ Properties properties = getProperties();
+ properties.set(GalleryViewer.Horizontal, Boolean.TRUE);
+ properties.set(GalleryViewer.Wrap, Boolean.TRUE);
+ properties.set(GalleryViewer.TitlePlacement,
+ GalleryViewer.TITLE_BOTTOM);
+ properties.set(GalleryViewer.SingleClickToOpen, Boolean.FALSE);
+ properties.set(GalleryViewer.SolidFrames, true);
+ properties.set(GalleryViewer.FlatFrames, true);
+ properties.set(GalleryViewer.ImageConstrained, Boolean.TRUE);
+ properties.set(GalleryViewer.ImageStretched, Boolean.TRUE);
+ properties.set(GalleryViewer.ContentPaneBorderWidth, 1);
+ properties.set(GalleryViewer.CustomContentPaneDecorator, true);
+ properties.set(GalleryViewer.ContentPaneBorderColor,
+ resources.get(ColorUtils.toDescriptor(COLOR_CONTENT_BORDER)));
+
+ properties.set(GalleryViewer.FrameContentSize,
+ new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
+ properties.set(GalleryViewer.Layout,
+ new GalleryLayout(GalleryLayout.ALIGN_TOPLEFT,
+ GalleryLayout.ALIGN_TOPLEFT, 30, 0,
+ new Insets(10, 65, 20, 65)));
+ properties.set(GalleryViewer.ContentPaneSpaceCollaborativeEngine,
+ new SpaceCollaborativeEngine());
+
+ contentProvider = new RecentFilesContentProvider();
+ final RecentFilesLabelProvider labelProvider = new RecentFilesLabelProvider(
+ parent);
+ contentProvider.addContentChangeListener(new Runnable() {
+ public void run() {
+ handleRecentFileListChanged(contentProvider, labelProvider,
+ true);
+ parent.layout(true);
+ }
+ });
+
+ viewerControl = createControl(parent);
+ viewerControl.setBackground(parent.getBackground());
+ viewerControl.setForeground(parent.getForeground());
+ viewerControl
+ .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewerControl.addDisposeListener(new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ handleDispose();
+ }
+ });
+
+ setPartFactory(new RecentFilesGalleryPartFactory());
+ setContentProvider(contentProvider);
+ setLabelProvider(labelProvider);
+
+ editorHistory.addEditorHistoryListener(contentProvider);
+ setInput(editorHistory);
+ handleRecentFileListChanged(contentProvider, labelProvider, true);
+ }
+
+ @Override
+ public Control getControl() {
+ if (viewerControl != null)
+ return viewerControl;
+ return super.getControl();
+ }
+
+ private void handleRecentFileListChanged(
+ RecentFilesContentProvider contentProvider,
+ RecentFilesLabelProvider labelProvider, boolean refresh) {
+ if (refresh) {
+ setInput(getInput());
+ }
+ }
+
+ private void clearRecentFile() {
+ editorHistory.clear();
+ }
+
+ private void deleteRecentFile(URI fileURI) {
+ editorHistory.remove(fileURI);
+ }
+
+ private void pinRecentFile(URI fileURI) {
+ editorHistory.pin(fileURI);
+ updateRecentFilePart(fileURI);
+ }
+
+ private void unPinRecentFile(URI fileURI) {
+ editorHistory.unPin(fileURI);
+ updateRecentFilePart(fileURI);
+ }
+
+ private void updateRecentFilePart(URI pinURI) {
+ RecentFilesFramePart part = findRecentFilePart(pinURI);
+ if (part != null)
+ part.update();
+ }
+
+ private RecentFilesFramePart findRecentFilePart(URI pinURI) {
+ if (pinURI == null)
+ return null;
+ return (RecentFilesFramePart) getPartRegistry().getPartByModel(pinURI);
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesContentProvider.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesContentProvider.java
index ec9e6a664..4ba0bdb62 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesContentProvider.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesContentProvider.java
@@ -1,127 +1,127 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.common.EventManager;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.ui.internal.IPreferenceConstants;
-import org.eclipse.ui.internal.WorkbenchPlugin;
-import org.xmind.ui.editor.IEditorHistory;
-import org.xmind.ui.editor.IEditorHistory.IEditorHistoryListener;
-
-public class RecentFilesContentProvider extends EventManager
- implements IStructuredContentProvider, IEditorHistoryListener,
- IPropertyChangeListener {
-
- private static final int DEFAULT_ITEM_COUNT = 20;
-
- private IEditorHistory history = null;
-
- private IPreferenceStore preferenceStore = null;
-
- public void dispose() {
- clearListeners();
- if (preferenceStore != null) {
- preferenceStore.removePropertyChangeListener(this);
- preferenceStore = null;
- }
- if (history != null) {
- history.removeEditorHistoryListener(this);
- history = null;
- }
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (newInput != history) {
- if (history != null) {
- history.removeEditorHistoryListener(this);
- }
- history = (newInput instanceof IEditorHistory)
- ? (IEditorHistory) newInput : null;
- if (history != null) {
- history.addEditorHistoryListener(this);
- }
-
- if (history != null) {
- if (preferenceStore == null) {
- preferenceStore = WorkbenchPlugin.getDefault()
- .getPreferenceStore();
- preferenceStore.addPropertyChangeListener(this);
- }
- } else {
- if (preferenceStore != null) {
- preferenceStore.removePropertyChangeListener(this);
- preferenceStore = null;
- }
- }
- }
- }
-
- public Object[] getElements(Object inputElement) {
- if (inputElement != history)
- return new Object[0];
- return getRecentInput();
- }
-
- public URI[] getRecentInput() {
- if (history == null)
- return new URI[0];
- int itemsToShow = getItemCount();
- if (itemsToShow <= 0)
- return new URI[0];
-
- URI[] uncheckedURIs = history.getAllInputURIs();
- List recentInputURIs = new ArrayList();
- int count = 0;
- for (URI uri : uncheckedURIs) {
- if (!recentInputURIs.contains(uri)) {
- recentInputURIs.add(uri);
- count++;
- } else {
- history.remove(uri);
- }
- if (count == itemsToShow)
- break;
- }
-
- return recentInputURIs.toArray(new URI[recentInputURIs.size()]);
- }
-
- private int getItemCount() {
- if (preferenceStore == null)
- return DEFAULT_ITEM_COUNT;
- return preferenceStore.getInt(IPreferenceConstants.RECENT_FILES);
- }
-
- private void fireContentChanged() {
- Object[] listeners = getListeners();
- for (int i = 0; i < listeners.length; i++) {
- ((Runnable) listeners[i]).run();
- }
- }
-
- public void editorHistoryChanged() {
- fireContentChanged();
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- if (IPreferenceConstants.RECENT_FILES.equals(event.getProperty())) {
- fireContentChanged();
- }
- }
-
- public void addContentChangeListener(Runnable listener) {
- addListenerObject(listener);
- }
-
- public void removeContentChangeListener(Runnable listener) {
- removeListenerObject(listener);
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.common.EventManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.internal.IPreferenceConstants;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.xmind.ui.editor.IEditorHistory;
+import org.xmind.ui.editor.IEditorHistory.IEditorHistoryListener;
+
+public class RecentFilesContentProvider extends EventManager
+ implements IStructuredContentProvider, IEditorHistoryListener,
+ IPropertyChangeListener {
+
+ private static final int DEFAULT_ITEM_COUNT = 20;
+
+ private IEditorHistory history = null;
+
+ private IPreferenceStore preferenceStore = null;
+
+ public void dispose() {
+ clearListeners();
+ if (preferenceStore != null) {
+ preferenceStore.removePropertyChangeListener(this);
+ preferenceStore = null;
+ }
+ if (history != null) {
+ history.removeEditorHistoryListener(this);
+ history = null;
+ }
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput != history) {
+ if (history != null) {
+ history.removeEditorHistoryListener(this);
+ }
+ history = (newInput instanceof IEditorHistory)
+ ? (IEditorHistory) newInput : null;
+ if (history != null) {
+ history.addEditorHistoryListener(this);
+ }
+
+ if (history != null) {
+ if (preferenceStore == null) {
+ preferenceStore = WorkbenchPlugin.getDefault()
+ .getPreferenceStore();
+ preferenceStore.addPropertyChangeListener(this);
+ }
+ } else {
+ if (preferenceStore != null) {
+ preferenceStore.removePropertyChangeListener(this);
+ preferenceStore = null;
+ }
+ }
+ }
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement != history)
+ return new Object[0];
+ return getRecentInput();
+ }
+
+ public URI[] getRecentInput() {
+ if (history == null)
+ return new URI[0];
+ int itemsToShow = getItemCount();
+ if (itemsToShow <= 0)
+ return new URI[0];
+
+ URI[] uncheckedURIs = history.getAllInputURIs();
+ List recentInputURIs = new ArrayList();
+ int count = 0;
+ for (URI uri : uncheckedURIs) {
+ if (!recentInputURIs.contains(uri)) {
+ recentInputURIs.add(uri);
+ count++;
+ } else {
+ history.remove(uri);
+ }
+ if (count == itemsToShow)
+ break;
+ }
+
+ return recentInputURIs.toArray(new URI[recentInputURIs.size()]);
+ }
+
+ private int getItemCount() {
+ if (preferenceStore == null)
+ return DEFAULT_ITEM_COUNT;
+ return preferenceStore.getInt(IPreferenceConstants.RECENT_FILES);
+ }
+
+ private void fireContentChanged() {
+ Object[] listeners = getListeners();
+ for (int i = 0; i < listeners.length; i++) {
+ ((Runnable) listeners[i]).run();
+ }
+ }
+
+ public void editorHistoryChanged() {
+ fireContentChanged();
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if (IPreferenceConstants.RECENT_FILES.equals(event.getProperty())) {
+ fireContentChanged();
+ }
+ }
+
+ public void addContentChangeListener(Runnable listener) {
+ addListenerObject(listener);
+ }
+
+ public void removeContentChangeListener(Runnable listener) {
+ removeListenerObject(listener);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesGalleryPartFactory.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesGalleryPartFactory.java
index 69bbf7e50..45a060c0d 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesGalleryPartFactory.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesGalleryPartFactory.java
@@ -1,140 +1,140 @@
-package org.xmind.cathy.internal.dashboard;
-
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.jface.resource.FontDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.util.Util;
-import org.eclipse.jface.viewers.IBaseLabelProvider;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.xmind.gef.IGraphicalViewer;
-import org.xmind.gef.IViewer;
-import org.xmind.gef.draw2d.ITextFigure;
-import org.xmind.gef.draw2d.RotatableWrapLabel;
-import org.xmind.gef.part.IGraphicalPart;
-import org.xmind.gef.part.IPart;
-import org.xmind.gef.util.Properties;
-import org.xmind.ui.gallery.FrameBorderLayout;
-import org.xmind.ui.gallery.FrameDecorator;
-import org.xmind.ui.gallery.FrameFigure;
-import org.xmind.ui.gallery.FramePart;
-import org.xmind.ui.gallery.GalleryPartFactory;
-import org.xmind.ui.resources.ColorUtils;
-import org.xmind.ui.resources.FontUtils;
-
-public class RecentFilesGalleryPartFactory extends GalleryPartFactory {
- public static class RecentFilesFramePart extends FramePart {
- RecentFilesFrameFigure figure;
-
- public RecentFilesFramePart(Object model) {
- super(model);
- setDecorator(RecentFilesFrameDecorator.DEFAULT);
- }
-
- @Override
- protected IFigure createFigure() {
- figure = new RecentFilesFrameFigure();
- Properties properties = getSite().getViewer().getProperties();
- boolean useAdvancedRenderer = properties.getBoolean(
- IGraphicalViewer.VIEWER_RENDER_TEXT_AS_PATH, false);
- figure.setTitleRenderStyle(useAdvancedRenderer
- ? RotatableWrapLabel.ADVANCED : RotatableWrapLabel.NORMAL);
-
- return figure;
- }
-
- @Override
- protected void updateChildren() {
- super.updateChildren();
- boolean isSelected = figure.isSelected();
- if (isSelected) {
- figure.setForegroundColor(ColorConstants.white);
- figure.subTitle.setForegroundColor(ColorConstants.white);
- }
- }
- }
-
- private static class RecentFilesFrameDecorator extends FrameDecorator {
-
- public static final RecentFilesFrameDecorator DEFAULT = new RecentFilesFrameDecorator();
-
- @Override
- public void decorate(IGraphicalPart part, IFigure figure) {
- super.decorate(part, figure);
-
- IFigure f = part.getFigure();
- Object model = part.getModel();
-
- IViewer viewer = part.getSite().getViewer();
- IBaseLabelProvider labelProvider = viewer
- .getAdapter(IBaseLabelProvider.class);
-
- if (f instanceof RecentFilesFrameFigure
- && labelProvider instanceof RecentFilesLabelProvider) {
- decorateSubTitle(((RecentFilesFrameFigure) f).getSubTitle(),
- model, (RecentFilesLabelProvider) labelProvider);
- }
- }
-
- private void decorateSubTitle(ITextFigure subTitle, Object model,
- RecentFilesLabelProvider labelProvider) {
- if (model == null)
- return;
- String text = labelProvider.getSubtitle(model);
- if (text == null)
- return;
-
- subTitle.setText(text);
- subTitle.setForegroundColor((Color) JFaceResources.getResources()
- .get(ColorUtils.toDescriptor("#8f8f8f"))); //$NON-NLS-1$
- Font countFont = subTitle.getFont();
- if (countFont != null) {
- FontData[] fontData = countFont.getFontData();
- FontData[] newFontData = FontUtils.newHeight(fontData,
- Util.isMac() ? 9 : 7);
- subTitle.setFont((Font) JFaceResources.getResources()
- .get(FontDescriptor.createFrom(newFontData)));
- }
- }
- }
-
- private static class RecentFilesFrameFigure extends FrameFigure {
-
- private RotatableWrapLabel subTitle;
-
- Color subTitleColor = (Color) JFaceResources.getResources()
- .get(ColorUtils.toDescriptor("#8f8f8f")); //$NON-NLS-1$
-
- public RecentFilesFrameFigure() {
- super();
-
- subTitle = new RotatableWrapLabel(RotatableWrapLabel.NORMAL);
- subTitle.setTextAlignment(PositionConstants.CENTER);
- subTitle.setEnabled(false);
- subTitle.setAbbreviated(true);
- subTitle.setForegroundColor(subTitleColor);
- getTitleContainer().add(subTitle, FrameBorderLayout.BOTTOM);
-
- }
-
- public ITextFigure getSubTitle() {
- return subTitle;
- }
-
- @Override
- public void setSelected(boolean selected) {
- super.setSelected(selected);
- subTitle.setForegroundColor(
- selected ? ColorConstants.white : subTitleColor);
- }
- }
-
- @Override
- protected IPart createFramePart(IPart parent, Object model) {
- return new RecentFilesFramePart(model);
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.jface.resource.FontDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.Util;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.xmind.gef.IGraphicalViewer;
+import org.xmind.gef.IViewer;
+import org.xmind.gef.draw2d.ITextFigure;
+import org.xmind.gef.draw2d.RotatableWrapLabel;
+import org.xmind.gef.part.IGraphicalPart;
+import org.xmind.gef.part.IPart;
+import org.xmind.gef.util.Properties;
+import org.xmind.ui.gallery.FrameBorderLayout;
+import org.xmind.ui.gallery.FrameDecorator;
+import org.xmind.ui.gallery.FrameFigure;
+import org.xmind.ui.gallery.FramePart;
+import org.xmind.ui.gallery.GalleryPartFactory;
+import org.xmind.ui.resources.ColorUtils;
+import org.xmind.ui.resources.FontUtils;
+
+public class RecentFilesGalleryPartFactory extends GalleryPartFactory {
+ public static class RecentFilesFramePart extends FramePart {
+ RecentFilesFrameFigure figure;
+
+ public RecentFilesFramePart(Object model) {
+ super(model);
+ setDecorator(RecentFilesFrameDecorator.DEFAULT);
+ }
+
+ @Override
+ protected IFigure createFigure() {
+ figure = new RecentFilesFrameFigure();
+ Properties properties = getSite().getViewer().getProperties();
+ boolean useAdvancedRenderer = properties.getBoolean(
+ IGraphicalViewer.VIEWER_RENDER_TEXT_AS_PATH, false);
+ figure.setTitleRenderStyle(useAdvancedRenderer
+ ? RotatableWrapLabel.ADVANCED : RotatableWrapLabel.NORMAL);
+
+ return figure;
+ }
+
+ @Override
+ protected void updateChildren() {
+ super.updateChildren();
+ boolean isSelected = figure.isSelected();
+ if (isSelected) {
+ figure.setForegroundColor(ColorConstants.white);
+ figure.subTitle.setForegroundColor(ColorConstants.white);
+ }
+ }
+ }
+
+ private static class RecentFilesFrameDecorator extends FrameDecorator {
+
+ public static final RecentFilesFrameDecorator DEFAULT = new RecentFilesFrameDecorator();
+
+ @Override
+ public void decorate(IGraphicalPart part, IFigure figure) {
+ super.decorate(part, figure);
+
+ IFigure f = part.getFigure();
+ Object model = part.getModel();
+
+ IViewer viewer = part.getSite().getViewer();
+ IBaseLabelProvider labelProvider = viewer
+ .getAdapter(IBaseLabelProvider.class);
+
+ if (f instanceof RecentFilesFrameFigure
+ && labelProvider instanceof RecentFilesLabelProvider) {
+ decorateSubTitle(((RecentFilesFrameFigure) f).getSubTitle(),
+ model, (RecentFilesLabelProvider) labelProvider);
+ }
+ }
+
+ private void decorateSubTitle(ITextFigure subTitle, Object model,
+ RecentFilesLabelProvider labelProvider) {
+ if (model == null)
+ return;
+ String text = labelProvider.getSubtitle(model);
+ if (text == null)
+ return;
+
+ subTitle.setText(text);
+ subTitle.setForegroundColor((Color) JFaceResources.getResources()
+ .get(ColorUtils.toDescriptor("#8f8f8f"))); //$NON-NLS-1$
+ Font countFont = subTitle.getFont();
+ if (countFont != null) {
+ FontData[] fontData = countFont.getFontData();
+ FontData[] newFontData = FontUtils.newHeight(fontData,
+ Util.isMac() ? 9 : 7);
+ subTitle.setFont((Font) JFaceResources.getResources()
+ .get(FontDescriptor.createFrom(newFontData)));
+ }
+ }
+ }
+
+ private static class RecentFilesFrameFigure extends FrameFigure {
+
+ private RotatableWrapLabel subTitle;
+
+ Color subTitleColor = (Color) JFaceResources.getResources()
+ .get(ColorUtils.toDescriptor("#8f8f8f")); //$NON-NLS-1$
+
+ public RecentFilesFrameFigure() {
+ super();
+
+ subTitle = new RotatableWrapLabel(RotatableWrapLabel.NORMAL);
+ subTitle.setTextAlignment(PositionConstants.CENTER);
+ subTitle.setEnabled(false);
+ subTitle.setAbbreviated(true);
+ subTitle.setForegroundColor(subTitleColor);
+ getTitleContainer().add(subTitle, FrameBorderLayout.BOTTOM);
+
+ }
+
+ public ITextFigure getSubTitle() {
+ return subTitle;
+ }
+
+ @Override
+ public void setSelected(boolean selected) {
+ super.setSelected(selected);
+ subTitle.setForegroundColor(
+ selected ? ColorConstants.white : subTitleColor);
+ }
+ }
+
+ @Override
+ protected IPart createFramePart(IPart parent, Object model) {
+ return new RecentFilesFramePart(model);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesLabelProvider.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesLabelProvider.java
index d3925b3fc..8c9aa9f27 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesLabelProvider.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/RecentFilesLabelProvider.java
@@ -1,241 +1,235 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.sql.Date;
-import java.text.DateFormat;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Insets;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.PlatformUI;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.gef.draw2d.SizeableImageFigure;
-import org.xmind.ui.editor.IEditorHistory;
-import org.xmind.ui.editor.IEditorHistoryItem;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.gallery.IDecorationContext;
-import org.xmind.ui.gallery.ILabelDecorator;
-import org.xmind.ui.mindmap.IMindMapImages;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class RecentFilesLabelProvider extends LabelProvider
- implements ILabelDecorator {
-
- Image pinImage;
-
- protected static class RecentFrameContentLayout
- extends RecentContainerLayout {
-
- private IDecorationContext context;
-
- public RecentFrameContentLayout(IDecorationContext context) {
- this.context = context;
- }
-
- @Override
- protected Dimension calculatePreferredSize(IFigure figure, int wHint,
- int hHint) {
- if (context != null) {
- Insets insets = figure.getInsets();
- Dimension contentSize = (Dimension) context
- .getProperty(GalleryViewer.FrameContentSize, null);
- if (contentSize != null)
- return new Dimension(contentSize.width + insets.getWidth(),
- contentSize.height + insets.getHeight());
- }
- return super.calculatePreferredSize(figure, wHint, hHint);
- }
- }
-
- protected static final String COLOR_NONEXISTING_WORKBOOK_COVER = "#DDDDDD"; //$NON-NLS-1$
- protected static final String COLOR_NONEXISTING_WORKBOOK_TEXT = "#CCCCCC"; //$NON-NLS-1$
-
- private LocalResourceManager resources;
- private IEditorHistory editorHistory;
- private Map images;
-
- public RecentFilesLabelProvider(Composite parent) {
- this.images = new HashMap();
- resources = new LocalResourceManager(JFaceResources.getResources(),
- parent);
- editorHistory = PlatformUI.getWorkbench()
- .getService(IEditorHistory.class);
- }
-
- public void clear() {
- Object[] imageArray = images.values().toArray();
- images.clear();
- for (Object image : imageArray) {
- ((Image) image).dispose();
- }
- }
-
- @Override
- public void dispose() {
- resources.dispose();
- clear();
- super.dispose();
- }
-
- @Override
- public String getText(Object element) {
- if (!(element instanceof URI))
- return super.getText(element);
- URI uri = (URI) element;
- IEditorHistoryItem item = editorHistory.getItem(uri);
- if (item != null) {
- String name = item.getName();
- Assert.isTrue(name != null);
-
- StringBuffer buf = new StringBuffer();
- if (name.length() > 20)
- name = name.substring(0, 20) + "..."; //$NON-NLS-1$
- buf.append(name);
- if (uri.getScheme().equalsIgnoreCase("seawind")) { //$NON-NLS-1$
- buf.append(" "); //$NON-NLS-1$
- buf.append(
- WorkbenchMessages.RecentFilesLabelProvider_Cloud_text);
- }
- return buf.toString();
- }
- return uri.toString();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof URI) {
- URI uri = (URI) element;
- Image image = images.get(uri);
- if (image != null && !image.isDisposed())
- return image;
-
- image = getImageByThumb(uri);
- if (image != null && !image.isDisposed()) {
- images.put(uri, image);
- }
- return image;
- }
- return resources.createImage(
- MindMapUI.getImages().get(IMindMapImages.THUMBNAIL_LOST, true));
- }
-
- private Image getImageByThumb(URI uri) {
- InputStream thumbnailData = null;
- try {
- thumbnailData = editorHistory.loadThumbnailData(uri);
- if (thumbnailData != null) {
- return new Image(resources.getDevice(), thumbnailData);
- }
- } catch (IOException e) {
- CathyPlugin.log(e, String.format(
- "Failed to load preview image for recent page uri == %s", //$NON-NLS-1$
- uri));
- } catch (SWTException e) {
- CathyPlugin.log(e, String.format(
- "Failed to load preview image for recent page uri == %s", //$NON-NLS-1$
- uri));
- } finally {
- try {
- if (thumbnailData != null)
- thumbnailData.close();
- } catch (IOException e) {
- }
- }
- return resources.createImage(
- MindMapUI.getImages().get(IMindMapImages.THUMBNAIL_LOST, true));
- }
-
- public IFigure decorateFigure(IFigure figure, Object element,
- IDecorationContext context) {
- if (!(element instanceof URI))
- return figure;
-
- return decorateFrameFigure(figure, (URI) element, context);
- }
-
- protected IFigure decorateFrameFigure(IFigure contentPane, URI uri,
- IDecorationContext context) {
- SizeableImageFigure thumbnailFigure;
- SizeableImageFigure pinIcon;
-
- List figures = contentPane.getChildren();
- boolean needInitFigureContent = figures.isEmpty();
- if (needInitFigureContent) {
- contentPane.setLayoutManager(new RecentFrameContentLayout(context));
-
- thumbnailFigure = new SizeableImageFigure(getImage(uri));
- pinIcon = new SizeableImageFigure(getPinImage(uri));
-
- contentPane.add(thumbnailFigure);
- contentPane.add(pinIcon, Integer
- .valueOf(PositionConstants.LEFT | PositionConstants.TOP));
-
- if (context != null) {
- boolean imageConstrained = Boolean.TRUE.equals(context
- .getProperty(GalleryViewer.ImageConstrained, false));
- boolean imageStretched = Boolean.TRUE.equals(context
- .getProperty(GalleryViewer.ImageStretched, false));
- thumbnailFigure.setConstrained(imageConstrained);
- thumbnailFigure.setStretched(imageStretched);
- }
- } else {
- thumbnailFigure = (SizeableImageFigure) figures.get(0);
- pinIcon = (SizeableImageFigure) figures.get(1);
- }
-
- thumbnailFigure.setImage(getImage(uri));
- pinIcon.setImage(getPinImage(uri));
-
- return contentPane;
- }
-
- private Image getPinImage(URI uri) {
- boolean isPin = editorHistory.isPinned(uri);
- return isPin ? getPinImage() : null;
- }
-
- private Image getPinImage() {
- if (pinImage == null) {
- ImageDescriptor desc = MindMapUI.getImages().get(IMindMapImages.PIN,
- true);
- if (desc != null) {
- try {
- pinImage = resources.createImage(desc);
- } catch (Throwable e) {
- //e.printStackTrace();
- }
- }
- }
- return pinImage;
- }
-
- public String getSubtitle(Object element) {
- if (element instanceof URI) {
- IEditorHistoryItem item = editorHistory.getItem((URI) element);
- long t = item.getOpenedTime();
- Date date = new Date(t);
- return DateFormat
- .getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
- .format(date);
- }
- Date newDate = new Date(System.currentTimeMillis());
- return DateFormat
- .getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
- .format(newDate);
- }
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.sql.Date;
+import java.text.DateFormat;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Insets;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.gef.draw2d.SizeableImageFigure;
+import org.xmind.ui.editor.IEditorHistory;
+import org.xmind.ui.editor.IEditorHistoryItem;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.gallery.IDecorationContext;
+import org.xmind.ui.gallery.ILabelDecorator;
+import org.xmind.ui.mindmap.IMindMapImages;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class RecentFilesLabelProvider extends LabelProvider
+ implements ILabelDecorator {
+
+ Image pinImage;
+
+ protected static class RecentFrameContentLayout
+ extends RecentContainerLayout {
+
+ private IDecorationContext context;
+
+ public RecentFrameContentLayout(IDecorationContext context) {
+ this.context = context;
+ }
+
+ @Override
+ protected Dimension calculatePreferredSize(IFigure figure, int wHint,
+ int hHint) {
+ if (context != null) {
+ Insets insets = figure.getInsets();
+ Dimension contentSize = (Dimension) context
+ .getProperty(GalleryViewer.FrameContentSize, null);
+ if (contentSize != null)
+ return new Dimension(contentSize.width + insets.getWidth(),
+ contentSize.height + insets.getHeight());
+ }
+ return super.calculatePreferredSize(figure, wHint, hHint);
+ }
+ }
+
+ protected static final String COLOR_NONEXISTING_WORKBOOK_COVER = "#DDDDDD"; //$NON-NLS-1$
+ protected static final String COLOR_NONEXISTING_WORKBOOK_TEXT = "#CCCCCC"; //$NON-NLS-1$
+
+ private LocalResourceManager resources;
+ private IEditorHistory editorHistory;
+ private Map images;
+
+ public RecentFilesLabelProvider(Composite parent) {
+ this.images = new HashMap();
+ resources = new LocalResourceManager(JFaceResources.getResources(),
+ parent);
+ editorHistory = PlatformUI.getWorkbench()
+ .getService(IEditorHistory.class);
+ }
+
+ public void clear() {
+ Object[] imageArray = images.values().toArray();
+ images.clear();
+ for (Object image : imageArray) {
+ ((Image) image).dispose();
+ }
+ }
+
+ @Override
+ public void dispose() {
+ resources.dispose();
+ clear();
+ super.dispose();
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (!(element instanceof URI))
+ return super.getText(element);
+ URI uri = (URI) element;
+ IEditorHistoryItem item = editorHistory.getItem(uri);
+ if (item != null) {
+ String name = item.getName();
+ Assert.isTrue(name != null);
+
+ StringBuffer buf = new StringBuffer();
+ if (name.length() > 20)
+ name = name.substring(0, 20) + "..."; //$NON-NLS-1$
+ buf.append(name);
+ return buf.toString();
+ }
+ return uri.toString();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof URI) {
+ URI uri = (URI) element;
+ Image image = images.get(uri);
+ if (image != null && !image.isDisposed())
+ return image;
+
+ image = getImageByThumb(uri);
+ if (image != null && !image.isDisposed()) {
+ images.put(uri, image);
+ }
+ return image;
+ }
+ return resources.createImage(
+ MindMapUI.getImages().get(IMindMapImages.THUMBNAIL_LOST, true));
+ }
+
+ private Image getImageByThumb(URI uri) {
+ InputStream thumbnailData = null;
+ try {
+ thumbnailData = editorHistory.loadThumbnailData(uri);
+ if (thumbnailData != null) {
+ return new Image(resources.getDevice(), thumbnailData);
+ }
+ } catch (IOException e) {
+ CathyPlugin.log(e, String.format(
+ "Failed to load preview image for recent page uri == %s", //$NON-NLS-1$
+ uri));
+ } catch (SWTException e) {
+ CathyPlugin.log(e, String.format(
+ "Failed to load preview image for recent page uri == %s", //$NON-NLS-1$
+ uri));
+ } finally {
+ try {
+ if (thumbnailData != null)
+ thumbnailData.close();
+ } catch (IOException e) {
+ }
+ }
+ return resources.createImage(
+ MindMapUI.getImages().get(IMindMapImages.THUMBNAIL_LOST, true));
+ }
+
+ public IFigure decorateFigure(IFigure figure, Object element,
+ IDecorationContext context) {
+ if (!(element instanceof URI))
+ return figure;
+
+ return decorateFrameFigure(figure, (URI) element, context);
+ }
+
+ protected IFigure decorateFrameFigure(IFigure contentPane, URI uri,
+ IDecorationContext context) {
+ SizeableImageFigure thumbnailFigure;
+ SizeableImageFigure pinIcon;
+
+ List figures = contentPane.getChildren();
+ boolean needInitFigureContent = figures.isEmpty();
+ if (needInitFigureContent) {
+ contentPane.setLayoutManager(new RecentFrameContentLayout(context));
+
+ thumbnailFigure = new SizeableImageFigure(getImage(uri));
+ pinIcon = new SizeableImageFigure(getPinImage(uri));
+
+ contentPane.add(thumbnailFigure);
+ contentPane.add(pinIcon, Integer
+ .valueOf(PositionConstants.LEFT | PositionConstants.TOP));
+
+ if (context != null) {
+ boolean imageConstrained = Boolean.TRUE.equals(context
+ .getProperty(GalleryViewer.ImageConstrained, false));
+ boolean imageStretched = Boolean.TRUE.equals(context
+ .getProperty(GalleryViewer.ImageStretched, false));
+ thumbnailFigure.setConstrained(imageConstrained);
+ thumbnailFigure.setStretched(imageStretched);
+ }
+ } else {
+ thumbnailFigure = (SizeableImageFigure) figures.get(0);
+ pinIcon = (SizeableImageFigure) figures.get(1);
+ }
+
+ thumbnailFigure.setImage(getImage(uri));
+ pinIcon.setImage(getPinImage(uri));
+
+ return contentPane;
+ }
+
+ private Image getPinImage(URI uri) {
+ boolean isPin = editorHistory.isPinned(uri);
+ return isPin ? getPinImage() : null;
+ }
+
+ private Image getPinImage() {
+ if (pinImage == null) {
+ ImageDescriptor desc = MindMapUI.getImages().get(IMindMapImages.PIN,
+ true);
+ if (desc != null) {
+ try {
+ pinImage = resources.createImage(desc);
+ } catch (Throwable e) {
+ //e.printStackTrace();
+ }
+ }
+ }
+ return pinImage;
+ }
+
+ public String getSubtitle(Object element) {
+ if (element instanceof URI) {
+ IEditorHistoryItem item = editorHistory.getItem((URI) element);
+ long t = item.getOpenedTime();
+ Date date = new Date(t);
+ return DateFormat
+ .getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
+ .format(date);
+ }
+ Date newDate = new Date(System.currentTimeMillis());
+ return DateFormat
+ .getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
+ .format(newDate);
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/StructureListContentProvider.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/StructureListContentProvider.java
index 72e1bfd0b..568130c30 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/StructureListContentProvider.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/StructureListContentProvider.java
@@ -1,310 +1,309 @@
-package org.xmind.cathy.internal.dashboard;
-
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.graphics.Image;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.viewers.ImageCachedLabelProvider;
-
-public class StructureListContentProvider
- implements IStructuredContentProvider {
-
- public static final String CONTENT_URI = "platform:/plugin/org.xmind.cathy/dashboard/new/structures.xml"; //$NON-NLS-1$
- public static final String NLS_PATH_BASE = "dashboard/new/structures"; //$NON-NLS-1$
-
- private static final String TAG_STRUCTURE_LIST = "structure-list"; //$NON-NLS-1$
- private static final String TAG_STRUCTURE = "structure"; //$NON-NLS-1$
- private static final String ATTR_ID = "id"; //$NON-NLS-1$
- private static final String ATTR_NAME = "name"; //$NON-NLS-1$
- private static final String ATTR_ICON = "icon"; //$NON-NLS-1$
- private static final String ATTR_VALUE = "value"; //$NON-NLS-1$
- private static final String ATTR_ICON_HEIGHT = "icon-height"; //$NON-NLS-1$
- private static final String ATTR_ICON_WIDTH = "icon-width"; //$NON-NLS-1$
-
- public static final class ContentSource {
-
- public final String contentURI;
-
- public final String nlsPathBase;
-
- public ContentSource(String contentURI, String nlsPathBase) {
- this.contentURI = contentURI;
- this.nlsPathBase = nlsPathBase;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (obj == null || !(obj instanceof ContentSource))
- return false;
- ContentSource that = (ContentSource) obj;
- return (this.contentURI == that.contentURI
- || (this.contentURI != null
- && this.contentURI.equals(that.contentURI)))
- && (this.nlsPathBase == that.nlsPathBase
- || (this.nlsPathBase != null && this.nlsPathBase
- .equals(that.nlsPathBase)));
- }
-
- @Override
- public int hashCode() {
- int x = 37;
- if (contentURI != null) {
- x = x ^ contentURI.hashCode();
- }
- if (nlsPathBase != null) {
- x = x ^ nlsPathBase.hashCode();
- }
- return x;
- }
-
- }
-
- static class StructureDescriptor {
- private String id;
- private String value;
- private String name;
- private ImageDescriptor icon;
-
- public StructureDescriptor(String id, String value, String name,
- ImageDescriptor icon) {
- super();
- Assert.isNotNull(id);
- Assert.isNotNull(value);
- this.id = id;
- this.value = value;
- this.name = name;
- this.icon = icon;
- }
-
- public int hashCode() {
- return id.hashCode();
- }
-
- public String getId() {
- return id;
- }
-
- public String getName() {
- return this.name;
- }
-
- public String getValue() {
- return this.value;
- }
-
- public ImageDescriptor getIcon() {
- return this.icon;
- }
-
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (obj == null || !(obj instanceof StructureDescriptor))
- return false;
- StructureDescriptor that = (StructureDescriptor) obj;
- return this.id.equals(that.id);
- }
-
- }
-
- static class StructureListLabelProvider extends ImageCachedLabelProvider {
-
- @Override
- public String getText(Object element) {
- if (element instanceof StructureDescriptor)
- return ((StructureDescriptor) element).getName();
- return super.getText(element);
- }
-
- @Override
- protected Image createImage(Object element) {
- if (element instanceof StructureDescriptor) {
- ImageDescriptor icon = ((StructureDescriptor) element)
- .getIcon();
- if (icon != null)
- return icon.createImage();
- }
- return null;
- }
- }
-
- private ContentSource source = null;
-
- private List structureDescriptors = new ArrayList();
-
- private Dimension iconSizeHints = new Dimension();
-
- public void dispose() {
- structureDescriptors.clear();
- source = null;
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- ContentSource newSource = toContentSource(newInput);
- if (newSource == source
- || (newSource != null && newSource.equals(source)))
- return;
-
- source = newSource;
- structureDescriptors.clear();
- iconSizeHints = new Dimension();
-
- if (source != null) {
- readTemplatesFromSource(source);
- }
-
- if (viewer instanceof GalleryViewer) {
- ((GalleryViewer) viewer).getProperties()
- .set(GalleryViewer.FrameContentSize, iconSizeHints);
- }
- }
-
- private ContentSource toContentSource(Object input) {
- ContentSource newSource;
- if (input instanceof ContentSource) {
- newSource = (ContentSource) input;
- } else if (input instanceof String) {
- newSource = new ContentSource((String) input, null);
- } else {
- newSource = null;
- }
- return newSource;
- }
-
- public Object[] getElements(Object inputElement) {
- ContentSource inputSource = toContentSource(inputElement);
- if (inputSource == source
- || (inputSource != null && inputSource.equals(source))) {
- return structureDescriptors.toArray();
- }
- return new Object[0];
- }
-
- private void readTemplatesFromSource(ContentSource source) {
- Properties nlsProperties;
- if (source.nlsPathBase != null) {
- nlsProperties = CathyPlugin.getDefault()
- .loadNLSProperties(source.nlsPathBase);
- } else {
- nlsProperties = new Properties();
- }
-
- if (source.contentURI != null) {
- try {
- URL contentURL = new URL(source.contentURI);
- URL locatedURL = FileLocator.find(contentURL);
- if (locatedURL != null)
- contentURL = locatedURL;
- InputStream contentStream = contentURL.openStream();
- try {
- Document doc = DocumentBuilderFactory.newInstance()
- .newDocumentBuilder().parse(contentStream);
- readElement(doc.getDocumentElement(), nlsProperties);
- } finally {
- contentStream.close();
- }
- } catch (Exception e) {
- CathyPlugin.log(e,
- "Failed to load content for structure list from: " //$NON-NLS-1$
- + source.contentURI);
- }
- }
-
- }
-
- private void readElement(Element element, Properties nlsProperties) {
- String tagName = element.getTagName();
- if (TAG_STRUCTURE.equals(tagName)) {
- readTemplate(element, nlsProperties);
- } else if (TAG_STRUCTURE_LIST.equals(tagName)) {
- readGlobalAttributes(element);
- }
-
- readChildren(element.getChildNodes(), nlsProperties);
- }
-
- private void readChildren(NodeList children, Properties nlsProperties) {
- int length = children.getLength();
- for (int i = 0; i < length; i++) {
- Node node = children.item(i);
- if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
- readElement((Element) node, nlsProperties);
- }
- }
- }
-
- private void readTemplate(Element element, Properties nlsProperties) {
- String id = element.getAttribute(ATTR_ID);
- String name = element.getAttribute(ATTR_NAME);
- String iconURI = element.getAttribute(ATTR_ICON);
- String structureClass = element.getAttribute(ATTR_VALUE);
-
- if (id == null || "".equals(id)) //$NON-NLS-1$
- throw new IllegalArgumentException("Missing 'id' attribute"); //$NON-NLS-1$
-
- if (name == null) {
- name = ""; //$NON-NLS-1$
- } else if (name.startsWith("%")) { //$NON-NLS-1$
- String nativeName = nlsProperties.getProperty(name.substring(1));
- if (nativeName != null) {
- name = nativeName;
- }
- }
-
- ImageDescriptor icon;
- if (iconURI == null) {
- icon = null;
- } else {
- try {
- icon = ImageDescriptor.createFromURL(new URL(iconURI));
- } catch (MalformedURLException e) {
- CathyPlugin.log(e, "Invalid icon URI: '" + iconURI + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- icon = null;
- }
- }
-
- StructureDescriptor structureDescriptor = new StructureDescriptor(id,
- structureClass, name, icon);
- structureDescriptors.add(structureDescriptor);
- }
-
- private void readGlobalAttributes(Element element) {
- String iconWidth = element.getAttribute(ATTR_ICON_WIDTH);
- String iconHeight = element.getAttribute(ATTR_ICON_HEIGHT);
-
- if (iconWidth != null && iconHeight != null) {
- try {
- int width = Integer.parseInt(iconWidth, 10);
- int height = Integer.parseInt(iconHeight, 10);
- iconSizeHints.width = width;
- iconSizeHints.height = height;
- } catch (NumberFormatException e) {
- }
- }
- }
-
- public static final ContentSource getDefaultInput() {
- return new ContentSource(CONTENT_URI, NLS_PATH_BASE);
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.util.XMLUtils;
+import org.xmind.ui.viewers.ImageCachedLabelProvider;
+
+public class StructureListContentProvider
+ implements IStructuredContentProvider {
+
+ public static final String CONTENT_URI = "platform:/plugin/org.xmind.cathy/dashboard/new/structures.xml"; //$NON-NLS-1$
+ public static final String NLS_PATH_BASE = "dashboard/new/structures"; //$NON-NLS-1$
+
+ private static final String TAG_STRUCTURE_LIST = "structure-list"; //$NON-NLS-1$
+ private static final String TAG_STRUCTURE = "structure"; //$NON-NLS-1$
+ private static final String ATTR_ID = "id"; //$NON-NLS-1$
+ private static final String ATTR_NAME = "name"; //$NON-NLS-1$
+ private static final String ATTR_ICON = "icon"; //$NON-NLS-1$
+ private static final String ATTR_VALUE = "value"; //$NON-NLS-1$
+ private static final String ATTR_ICON_HEIGHT = "icon-height"; //$NON-NLS-1$
+ private static final String ATTR_ICON_WIDTH = "icon-width"; //$NON-NLS-1$
+
+ public static final class ContentSource {
+
+ public final String contentURI;
+
+ public final String nlsPathBase;
+
+ public ContentSource(String contentURI, String nlsPathBase) {
+ this.contentURI = contentURI;
+ this.nlsPathBase = nlsPathBase;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (obj == null || !(obj instanceof ContentSource))
+ return false;
+ ContentSource that = (ContentSource) obj;
+ return (this.contentURI == that.contentURI
+ || (this.contentURI != null
+ && this.contentURI.equals(that.contentURI)))
+ && (this.nlsPathBase == that.nlsPathBase
+ || (this.nlsPathBase != null && this.nlsPathBase
+ .equals(that.nlsPathBase)));
+ }
+
+ @Override
+ public int hashCode() {
+ int x = 37;
+ if (contentURI != null) {
+ x = x ^ contentURI.hashCode();
+ }
+ if (nlsPathBase != null) {
+ x = x ^ nlsPathBase.hashCode();
+ }
+ return x;
+ }
+
+ }
+
+ static class StructureDescriptor {
+ private String id;
+ private String value;
+ private String name;
+ private ImageDescriptor icon;
+
+ public StructureDescriptor(String id, String value, String name,
+ ImageDescriptor icon) {
+ super();
+ Assert.isNotNull(id);
+ Assert.isNotNull(value);
+ this.id = id;
+ this.value = value;
+ this.name = name;
+ this.icon = icon;
+ }
+
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getValue() {
+ return this.value;
+ }
+
+ public ImageDescriptor getIcon() {
+ return this.icon;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (obj == null || !(obj instanceof StructureDescriptor))
+ return false;
+ StructureDescriptor that = (StructureDescriptor) obj;
+ return this.id.equals(that.id);
+ }
+
+ }
+
+ static class StructureListLabelProvider extends ImageCachedLabelProvider {
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof StructureDescriptor)
+ return ((StructureDescriptor) element).getName();
+ return super.getText(element);
+ }
+
+ @Override
+ protected Image createImage(Object element) {
+ if (element instanceof StructureDescriptor) {
+ ImageDescriptor icon = ((StructureDescriptor) element)
+ .getIcon();
+ if (icon != null)
+ return icon.createImage();
+ }
+ return null;
+ }
+ }
+
+ private ContentSource source = null;
+
+ private List structureDescriptors = new ArrayList();
+
+ private Dimension iconSizeHints = new Dimension();
+
+ public void dispose() {
+ structureDescriptors.clear();
+ source = null;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ ContentSource newSource = toContentSource(newInput);
+ if (newSource == source
+ || (newSource != null && newSource.equals(source)))
+ return;
+
+ source = newSource;
+ structureDescriptors.clear();
+ iconSizeHints = new Dimension();
+
+ if (source != null) {
+ readTemplatesFromSource(source);
+ }
+
+ if (viewer instanceof GalleryViewer) {
+ ((GalleryViewer) viewer).getProperties()
+ .set(GalleryViewer.FrameContentSize, iconSizeHints);
+ }
+ }
+
+ private ContentSource toContentSource(Object input) {
+ ContentSource newSource;
+ if (input instanceof ContentSource) {
+ newSource = (ContentSource) input;
+ } else if (input instanceof String) {
+ newSource = new ContentSource((String) input, null);
+ } else {
+ newSource = null;
+ }
+ return newSource;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ ContentSource inputSource = toContentSource(inputElement);
+ if (inputSource == source
+ || (inputSource != null && inputSource.equals(source))) {
+ return structureDescriptors.toArray();
+ }
+ return new Object[0];
+ }
+
+ private void readTemplatesFromSource(ContentSource source) {
+ Properties nlsProperties;
+ if (source.nlsPathBase != null) {
+ nlsProperties = CathyPlugin.getDefault()
+ .loadNLSProperties(source.nlsPathBase);
+ } else {
+ nlsProperties = new Properties();
+ }
+
+ if (source.contentURI != null) {
+ try {
+ URL contentURL = new URL(source.contentURI);
+ URL locatedURL = FileLocator.find(contentURL);
+ if (locatedURL != null)
+ contentURL = locatedURL;
+ InputStream contentStream = contentURL.openStream();
+ try {
+ Document doc = XMLUtils.getDefaultDocumentBuilder()
+ .parse(contentStream);
+ readElement(doc.getDocumentElement(), nlsProperties);
+ } finally {
+ contentStream.close();
+ }
+ } catch (Exception e) {
+ CathyPlugin.log(e,
+ "Failed to load content for structure list from: " //$NON-NLS-1$
+ + source.contentURI);
+ }
+ }
+
+ }
+
+ private void readElement(Element element, Properties nlsProperties) {
+ String tagName = element.getTagName();
+ if (TAG_STRUCTURE.equals(tagName)) {
+ readTemplate(element, nlsProperties);
+ } else if (TAG_STRUCTURE_LIST.equals(tagName)) {
+ readGlobalAttributes(element);
+ }
+
+ readChildren(element.getChildNodes(), nlsProperties);
+ }
+
+ private void readChildren(NodeList children, Properties nlsProperties) {
+ int length = children.getLength();
+ for (int i = 0; i < length; i++) {
+ Node node = children.item(i);
+ if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
+ readElement((Element) node, nlsProperties);
+ }
+ }
+ }
+
+ private void readTemplate(Element element, Properties nlsProperties) {
+ String id = element.getAttribute(ATTR_ID);
+ String name = element.getAttribute(ATTR_NAME);
+ String iconURI = element.getAttribute(ATTR_ICON);
+ String structureClass = element.getAttribute(ATTR_VALUE);
+
+ if (id == null || "".equals(id)) //$NON-NLS-1$
+ throw new IllegalArgumentException("Missing 'id' attribute"); //$NON-NLS-1$
+
+ if (name == null) {
+ name = ""; //$NON-NLS-1$
+ } else if (name.startsWith("%")) { //$NON-NLS-1$
+ String nativeName = nlsProperties.getProperty(name.substring(1));
+ if (nativeName != null) {
+ name = nativeName;
+ }
+ }
+
+ ImageDescriptor icon;
+ if (iconURI == null) {
+ icon = null;
+ } else {
+ try {
+ icon = ImageDescriptor.createFromURL(new URL(iconURI));
+ } catch (MalformedURLException e) {
+ CathyPlugin.log(e, "Invalid icon URI: '" + iconURI + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ icon = null;
+ }
+ }
+
+ StructureDescriptor structureDescriptor = new StructureDescriptor(id,
+ structureClass, name, icon);
+ structureDescriptors.add(structureDescriptor);
+ }
+
+ private void readGlobalAttributes(Element element) {
+ String iconWidth = element.getAttribute(ATTR_ICON_WIDTH);
+ String iconHeight = element.getAttribute(ATTR_ICON_HEIGHT);
+
+ if (iconWidth != null && iconHeight != null) {
+ try {
+ int width = Integer.parseInt(iconWidth, 10);
+ int height = Integer.parseInt(iconHeight, 10);
+ iconSizeHints.width = width;
+ iconSizeHints.height = height;
+ } catch (NumberFormatException e) {
+ }
+ }
+ }
+
+ public static final ContentSource getDefaultInput() {
+ return new ContentSource(CONTENT_URI, NLS_PATH_BASE);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/TemplatePropertyTester.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/TemplatePropertyTester.java
index 11d461945..7623c078a 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/TemplatePropertyTester.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/TemplatePropertyTester.java
@@ -1,32 +1,32 @@
-package org.xmind.cathy.internal.dashboard;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.runtime.Assert;
-import org.xmind.ui.mindmap.ITemplate;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class TemplatePropertyTester extends PropertyTester {
-
- private static final String PROP_SYSTEM = "system"; //$NON-NLS-1$
-
- private static final String PROP_USER = "user"; //$NON-NLS-1$
-
- public boolean test(Object receiver, String property, Object[] args,
- Object expectedValue) {
- Assert.isLegal(receiver instanceof ITemplate,
- "Receiver is not an ITemplate object: " + receiver); //$NON-NLS-1$
-
- ITemplate template = (ITemplate) receiver;
-
- if (PROP_SYSTEM.equals(property)) {
- return MindMapUI.getResourceManager().isSystemTemplate(template);
- } else if (PROP_USER.equals(property)) {
- return MindMapUI.getResourceManager().isUserTemplate(template);
- }
-
- Assert.isLegal(false, "Unrecognized property: " + property); //$NON-NLS-1$
-
- return false;
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.runtime.Assert;
+import org.xmind.ui.mindmap.ITemplate;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class TemplatePropertyTester extends PropertyTester {
+
+ private static final String PROP_SYSTEM = "system"; //$NON-NLS-1$
+
+ private static final String PROP_USER = "user"; //$NON-NLS-1$
+
+ public boolean test(Object receiver, String property, Object[] args,
+ Object expectedValue) {
+ Assert.isLegal(receiver instanceof ITemplate,
+ "Receiver is not an ITemplate object: " + receiver); //$NON-NLS-1$
+
+ ITemplate template = (ITemplate) receiver;
+
+ if (PROP_SYSTEM.equals(property)) {
+ return MindMapUI.getResourceManager().isSystemTemplate(template);
+ } else if (PROP_USER.equals(property)) {
+ return MindMapUI.getResourceManager().isUserTemplate(template);
+ }
+
+ Assert.isLegal(false, "Unrecognized property: " + property); //$NON-NLS-1$
+
+ return false;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/ThemeChooserDialog.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/ThemeChooserDialog.java
index 5262ce44c..64be6fcd6 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/ThemeChooserDialog.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/dashboard/ThemeChooserDialog.java
@@ -1,167 +1,167 @@
-package org.xmind.cathy.internal.dashboard;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.viewers.IOpenListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.OpenEvent;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.core.style.IStyle;
-import org.xmind.gef.EditDomain;
-import org.xmind.gef.GEF;
-import org.xmind.gef.util.Properties;
-import org.xmind.ui.gallery.GallerySelectTool;
-import org.xmind.ui.gallery.GalleryViewer;
-import org.xmind.ui.internal.views.CategorizedThemeViewer;
-import org.xmind.ui.internal.views.ThemeLabelProvider;
-import org.xmind.ui.mindmap.IResourceManager;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class ThemeChooserDialog extends Dialog {
-
- private IStyle selectedTheme = null;
-
- private String structureClass;
-
- protected ThemeChooserDialog(Shell parentShell) {
- super(parentShell);
- setShellStyle(getShellStyle() | SWT.SHEET);
- }
-
- protected ThemeChooserDialog(Shell parentShell, String structureClass) {
- this(parentShell);
- this.structureClass = structureClass;
- }
-
- @Override
- protected boolean isResizable() {
- return true;
- }
-
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(WorkbenchMessages.DashboardThemeChoose_message);
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite) super.createDialogArea(parent);
-
- composite.setLayout(new FillLayout());
- GridData parentData = (GridData) composite.getLayoutData();
- parentData.widthHint = 940;
- parentData.heightHint = 500;
- doCreateViewer(composite);
- return composite;
- }
-
- private void doCreateViewer(Composite parent) {
-
- CategorizedThemeViewer viewer = doCreatePartControlViewer(parent);
-
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- selectedTheme = (IStyle) ((IStructuredSelection) event
- .getSelection()).getFirstElement();
- setButtonEnabled(IDialogConstants.OK_ID,
- !event.getSelection().isEmpty());
- }
- });
-
- viewer.addOpenListener(new IOpenListener() {
- public void open(OpenEvent event) {
- ISelection selection = event.getSelection();
- selectedTheme = selection.isEmpty() ? null
- : (IStyle) ((IStructuredSelection) selection)
- .getFirstElement();
- setReturnCode(OK);
- close();
- }
- });
- IResourceManager rm = MindMapUI.getResourceManager();
- IStyle defaultTheme = rm.getDefaultTheme();
- viewer.setSelection(new StructuredSelection(defaultTheme));
-
- }
-
- private CategorizedThemeViewer doCreatePartControlViewer(Composite parent) {
- Composite container = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(1, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- layout.verticalSpacing = 0;
- layout.horizontalSpacing = 0;
- container.setLayout(layout);
-
- CategorizedThemeViewer viewer = new CategorizedThemeViewer(container) {
-
- @Override
- protected void postInit() {
- // cancel change theme listener
- }
-
- @Override
- protected void initGalleryViewer(GalleryViewer galleryViewerer) {
- galleryViewerer.setLabelProvider(
- new ThemeLabelProvider(structureClass));
- EditDomain editDomain = new EditDomain();
- editDomain.installTool(GEF.TOOL_SELECT,
- new GallerySelectTool());
- galleryViewerer.setEditDomain(editDomain);
-
- Properties properties = galleryViewerer.getProperties();
- properties.set(GalleryViewer.TitlePlacement,
- GalleryViewer.TITLE_BOTTOM);
- properties.set(GalleryViewer.HideTitle, false);
- properties.set(GalleryViewer.SingleClickToOpen, Boolean.FALSE);
- properties.set(GalleryViewer.SolidFrames, true);
- properties.set(GalleryViewer.FlatFrames, true);
- properties.set(GalleryViewer.ImageConstrained, true);
- properties.set(GalleryViewer.CustomContentPaneDecorator, true);
- }
- };
- viewer.getControl()
- .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- return viewer;
- }
-
- @Override
- protected Button createButton(Composite parent, int id, String label,
- boolean defaultButton) {
- if (id == IDialogConstants.OK_ID)
- label = WorkbenchMessages.DashboardThemeCreate_label;
- return super.createButton(parent, id, label, defaultButton);
- }
-
- @Override
- protected void cancelPressed() {
- super.cancelPressed();
- selectedTheme = null;
- }
-
- public IStyle getSelectedTheme() {
- return selectedTheme;
- }
-
- private void setButtonEnabled(int id, boolean enabled) {
- Button button = getButton(id);
- if (button == null || button.isDisposed())
- return;
- button.setEnabled(enabled);
- }
-
-}
+package org.xmind.cathy.internal.dashboard;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.core.style.IStyle;
+import org.xmind.gef.EditDomain;
+import org.xmind.gef.GEF;
+import org.xmind.gef.util.Properties;
+import org.xmind.ui.gallery.GallerySelectTool;
+import org.xmind.ui.gallery.GalleryViewer;
+import org.xmind.ui.internal.views.CategorizedThemeViewer;
+import org.xmind.ui.internal.views.ThemeLabelProvider;
+import org.xmind.ui.mindmap.IResourceManager;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class ThemeChooserDialog extends Dialog {
+
+ private IStyle selectedTheme = null;
+
+ private String structureClass;
+
+ protected ThemeChooserDialog(Shell parentShell) {
+ super(parentShell);
+ setShellStyle(getShellStyle() | SWT.SHEET);
+ }
+
+ protected ThemeChooserDialog(Shell parentShell, String structureClass) {
+ this(parentShell);
+ this.structureClass = structureClass;
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(WorkbenchMessages.DashboardThemeChoose_message);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ composite.setLayout(new FillLayout());
+ GridData parentData = (GridData) composite.getLayoutData();
+ parentData.widthHint = 940;
+ parentData.heightHint = 500;
+ doCreateViewer(composite);
+ return composite;
+ }
+
+ private void doCreateViewer(Composite parent) {
+
+ CategorizedThemeViewer viewer = doCreatePartControlViewer(parent);
+
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ selectedTheme = (IStyle) ((IStructuredSelection) event
+ .getSelection()).getFirstElement();
+ setButtonEnabled(IDialogConstants.OK_ID,
+ !event.getSelection().isEmpty());
+ }
+ });
+
+ viewer.addOpenListener(new IOpenListener() {
+ public void open(OpenEvent event) {
+ ISelection selection = event.getSelection();
+ selectedTheme = selection.isEmpty() ? null
+ : (IStyle) ((IStructuredSelection) selection)
+ .getFirstElement();
+ setReturnCode(OK);
+ close();
+ }
+ });
+ IResourceManager rm = MindMapUI.getResourceManager();
+ IStyle defaultTheme = rm.getDefaultTheme();
+ viewer.setSelection(new StructuredSelection(defaultTheme));
+
+ }
+
+ private CategorizedThemeViewer doCreatePartControlViewer(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.verticalSpacing = 0;
+ layout.horizontalSpacing = 0;
+ container.setLayout(layout);
+
+ CategorizedThemeViewer viewer = new CategorizedThemeViewer(container) {
+
+ @Override
+ protected void postInit() {
+ // cancel change theme listener
+ }
+
+ @Override
+ protected void initGalleryViewer(GalleryViewer galleryViewerer) {
+ galleryViewerer.setLabelProvider(
+ new ThemeLabelProvider(structureClass));
+ EditDomain editDomain = new EditDomain();
+ editDomain.installTool(GEF.TOOL_SELECT,
+ new GallerySelectTool());
+ galleryViewerer.setEditDomain(editDomain);
+
+ Properties properties = galleryViewerer.getProperties();
+ properties.set(GalleryViewer.TitlePlacement,
+ GalleryViewer.TITLE_BOTTOM);
+ properties.set(GalleryViewer.HideTitle, false);
+ properties.set(GalleryViewer.SingleClickToOpen, Boolean.FALSE);
+ properties.set(GalleryViewer.SolidFrames, true);
+ properties.set(GalleryViewer.FlatFrames, true);
+ properties.set(GalleryViewer.ImageConstrained, true);
+ properties.set(GalleryViewer.CustomContentPaneDecorator, true);
+ }
+ };
+ viewer.getControl()
+ .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ return viewer;
+ }
+
+ @Override
+ protected Button createButton(Composite parent, int id, String label,
+ boolean defaultButton) {
+ if (id == IDialogConstants.OK_ID)
+ label = WorkbenchMessages.DashboardThemeCreate_label;
+ return super.createButton(parent, id, label, defaultButton);
+ }
+
+ @Override
+ protected void cancelPressed() {
+ super.cancelPressed();
+ selectedTheme = null;
+ }
+
+ public IStyle getSelectedTheme() {
+ return selectedTheme;
+ }
+
+ private void setButtonEnabled(int id, boolean enabled) {
+ Button button = getButton(id);
+ if (button == null || button.isDisposed())
+ return;
+ button.setEnabled(enabled);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ClearRecentFileHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ClearRecentFileHandler.java
index eecc5839f..dde6544f0 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ClearRecentFileHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ClearRecentFileHandler.java
@@ -1,24 +1,24 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.ICathyConstants;
-
-public class ClearRecentFileHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- Shell shell = HandlerUtil.getActiveShell(event);
- if (shell != null) {
- Object data = shell
- .getData(ICathyConstants.HELPER_RECENTFILE_CLEAR);
- if (data instanceof Runnable) {
- ((Runnable) data).run();
- }
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.ICathyConstants;
+
+public class ClearRecentFileHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Shell shell = HandlerUtil.getActiveShell(event);
+ if (shell != null) {
+ Object data = shell
+ .getData(ICathyConstants.HELPER_RECENTFILE_CLEAR);
+ if (data instanceof Runnable) {
+ ((Runnable) data).run();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DeleteRecentFileHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DeleteRecentFileHandler.java
index db2971313..e4e38fb6f 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DeleteRecentFileHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DeleteRecentFileHandler.java
@@ -1,24 +1,24 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.ICathyConstants;
-
-public class DeleteRecentFileHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- Shell shell = HandlerUtil.getActiveShell(event);
- if (shell != null) {
- Object data = shell
- .getData(ICathyConstants.HELPER_RECENTFILE_DELETE);
- if (data instanceof Runnable) {
- ((Runnable) data).run();
- }
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.ICathyConstants;
+
+public class DeleteRecentFileHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Shell shell = HandlerUtil.getActiveShell(event);
+ if (shell != null) {
+ Object data = shell
+ .getData(ICathyConstants.HELPER_RECENTFILE_DELETE);
+ if (data instanceof Runnable) {
+ ((Runnable) data).run();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DeleteTemplateHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DeleteTemplateHandler.java
index f156c64b5..57b11750f 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DeleteTemplateHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DeleteTemplateHandler.java
@@ -1,41 +1,41 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.ui.mindmap.ITemplate;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class DeleteTemplateHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- Object obj = ((IStructuredSelection) selection).getFirstElement();
- if (obj instanceof ITemplate) {
- ITemplate template = (ITemplate) obj;
- Shell activeShell = HandlerUtil.getActiveShell(event);
-
- if (!MessageDialog.openConfirm(activeShell,
- WorkbenchMessages.ConfirmDeleteTemplateDialog_title,
- NLS.bind(
- WorkbenchMessages.ConfirmDeleteTemplateDialog_message_withTemplateName,
- template.getName()))) {
- return null;
- }
- MindMapUI.getResourceManager().removeUserTemplate(template);
- }
- }
-
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.ui.mindmap.ITemplate;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class DeleteTemplateHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection) selection).getFirstElement();
+ if (obj instanceof ITemplate) {
+ ITemplate template = (ITemplate) obj;
+ Shell activeShell = HandlerUtil.getActiveShell(event);
+
+ if (!MessageDialog.openConfirm(activeShell,
+ WorkbenchMessages.ConfirmDeleteTemplateDialog_title,
+ NLS.bind(
+ WorkbenchMessages.ConfirmDeleteTemplateDialog_message_withTemplateName,
+ template.getName()))) {
+ return null;
+ }
+ MindMapUI.getResourceManager().removeUserTemplate(template);
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DuplicateTemplateHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DuplicateTemplateHandler.java
index db879371b..722ffefa5 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DuplicateTemplateHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/DuplicateTemplateHandler.java
@@ -1,30 +1,30 @@
-package org.xmind.cathy.internal.handlers;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.ui.internal.utils.ResourceUtils;
-import org.xmind.ui.mindmap.ITemplate;
-
-public class DuplicateTemplateHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- List templates = new ArrayList();
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- Object obj = ((IStructuredSelection) selection).getFirstElement();
- if (obj instanceof ITemplate) {
- templates.add((ITemplate) obj);
- }
- }
- ResourceUtils.duplicateTemplates(templates);
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.ui.internal.utils.ResourceUtils;
+import org.xmind.ui.mindmap.ITemplate;
+
+public class DuplicateTemplateHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ List templates = new ArrayList();
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection) selection).getFirstElement();
+ if (obj instanceof ITemplate) {
+ templates.add((ITemplate) obj);
+ }
+ }
+ ResourceUtils.duplicateTemplates(templates);
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/HideDashboardHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/HideDashboardHandler.java
index a2668f681..68153da98 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/HideDashboardHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/HideDashboardHandler.java
@@ -1,24 +1,24 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-public class HideDashboardHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow wbWindow = HandlerUtil.getActiveWorkbenchWindow(event);
- if (wbWindow != null) {
- MWindow window = wbWindow.getService(MWindow.class);
- if (window != null) {
- new org.xmind.ui.internal.e4handlers.HideDashboardHandler()
- .execute(window);
- }
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class HideDashboardHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow wbWindow = HandlerUtil.getActiveWorkbenchWindow(event);
+ if (wbWindow != null) {
+ MWindow window = wbWindow.getService(MWindow.class);
+ if (window != null) {
+ new org.xmind.ui.internal.e4handlers.HideDashboardHandler()
+ .execute(window);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/NewWizardHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/NewWizardHandler.java
index 71dc521f0..4c00d0287 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/NewWizardHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/NewWizardHandler.java
@@ -1,27 +1,27 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.ICathyConstants;
-
-public class NewWizardHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow wbWindow = HandlerUtil.getActiveWorkbenchWindow(event);
- if (wbWindow != null) {
- MWindow window = wbWindow.getService(MWindow.class);
- if (window != null) {
- org.xmind.ui.internal.e4handlers.ShowDashboardPageHandler
- .showDashboardPage(window,
- ICathyConstants.DASHBOARD_PAGE_NEW);
- }
- }
-
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.ICathyConstants;
+
+public class NewWizardHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow wbWindow = HandlerUtil.getActiveWorkbenchWindow(event);
+ if (wbWindow != null) {
+ MWindow window = wbWindow.getService(MWindow.class);
+ if (window != null) {
+ org.xmind.ui.internal.e4handlers.ShowDashboardPageHandler
+ .showDashboardPage(window,
+ ICathyConstants.DASHBOARD_PAGE_NEW);
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/PinRecentFileHanlder.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/PinRecentFileHanlder.java
index 8e0299585..0ca5390e7 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/PinRecentFileHanlder.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/PinRecentFileHanlder.java
@@ -1,23 +1,23 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.ICathyConstants;
-
-public class PinRecentFileHanlder extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- Shell shell = HandlerUtil.getActiveShell(event);
- if (shell != null) {
- Object data = shell.getData(ICathyConstants.HELPER_RECENTFILE_PIN);
- if (data instanceof Runnable) {
- ((Runnable) data).run();
- }
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.ICathyConstants;
+
+public class PinRecentFileHanlder extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Shell shell = HandlerUtil.getActiveShell(event);
+ if (shell != null) {
+ Object data = shell.getData(ICathyConstants.HELPER_RECENTFILE_PIN);
+ if (data instanceof Runnable) {
+ ((Runnable) data).run();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/RenameTemplateHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/RenameTemplateHandler.java
index ae13f7001..9aed96ba9 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/RenameTemplateHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/RenameTemplateHandler.java
@@ -1,23 +1,23 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.ICathyConstants;
-
-public class RenameTemplateHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- Shell shell = HandlerUtil.getActiveShell(event);
- if (shell != null) {
- Object data = shell.getData(ICathyConstants.HELPER_TEMPLATE_RENAME);
- if (data instanceof Runnable) {
- ((Runnable) data).run();
- }
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.ICathyConstants;
+
+public class RenameTemplateHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Shell shell = HandlerUtil.getActiveShell(event);
+ if (shell != null) {
+ Object data = shell.getData(ICathyConstants.HELPER_TEMPLATE_RENAME);
+ if (data instanceof Runnable) {
+ ((Runnable) data).run();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowAllPreferencesHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowAllPreferencesHandler.java
index d45d910cb..bd47e7705 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowAllPreferencesHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowAllPreferencesHandler.java
@@ -1,32 +1,32 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchCommandConstants;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.ui.util.PrefUtils;
-
-public class ShowAllPreferencesHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- final String preferencePageId = event
- .getParameter(IWorkbenchCommandConstants.WINDOW_PREFERENCES_PARM_PAGEID);
- final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil
- .getActiveWorkbenchWindow(event);
-
- final Shell shell;
- if (activeWorkbenchWindow == null) {
- shell = null;
- } else {
- shell = activeWorkbenchWindow.getShell();
- }
-
- PrefUtils.openPrefDialog(shell, preferencePageId);
-
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchCommandConstants;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.ui.util.PrefUtils;
+
+public class ShowAllPreferencesHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ final String preferencePageId = event
+ .getParameter(IWorkbenchCommandConstants.WINDOW_PREFERENCES_PARM_PAGEID);
+ final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil
+ .getActiveWorkbenchWindow(event);
+
+ final Shell shell;
+ if (activeWorkbenchWindow == null) {
+ shell = null;
+ } else {
+ shell = activeWorkbenchWindow.getShell();
+ }
+
+ PrefUtils.openPrefDialog(shell, preferencePageId);
+
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowCloudPageHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowCloudPageHandler.java
index 0e1c742e1..3803d4632 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowCloudPageHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowCloudPageHandler.java
@@ -1,30 +1,30 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- *
- * @author Frank Shaka
- * @since 3.6.50
- */
-public class ShowCloudPageHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow wbWindow = HandlerUtil.getActiveWorkbenchWindow(event);
- if (wbWindow != null) {
- MWindow window = wbWindow.getService(MWindow.class);
- if (window != null) {
- String pageId = "org.xmind.ui.part.dashboard.cloud"; //$NON-NLS-1$
- org.xmind.ui.internal.e4handlers.ShowDashboardPageHandler
- .showDashboardPage(window, pageId);
- }
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ *
+ * @author Frank Shaka
+ * @since 3.6.50
+ */
+public class ShowCloudPageHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow wbWindow = HandlerUtil.getActiveWorkbenchWindow(event);
+ if (wbWindow != null) {
+ MWindow window = wbWindow.getService(MWindow.class);
+ if (window != null) {
+ String pageId = "org.xmind.ui.part.dashboard.cloud"; //$NON-NLS-1$
+ org.xmind.ui.internal.e4handlers.ShowDashboardPageHandler
+ .showDashboardPage(window, pageId);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowDashboardPageHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowDashboardPageHandler.java
index 0c01853b2..fa785c203 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowDashboardPageHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ShowDashboardPageHandler.java
@@ -1,28 +1,28 @@
-
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.ICathyConstants;
-
-public class ShowDashboardPageHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow wbWindow = HandlerUtil.getActiveWorkbenchWindow(event);
- if (wbWindow != null) {
- MWindow window = wbWindow.getService(MWindow.class);
- if (window != null) {
- String pageId = event.getParameter(
- ICathyConstants.PARAMETER_DASHBOARD_PAGE_ID);
- org.xmind.ui.internal.e4handlers.ShowDashboardPageHandler
- .showDashboardPage(window, pageId);
- }
- }
- return null;
- }
-
+
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.ICathyConstants;
+
+public class ShowDashboardPageHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow wbWindow = HandlerUtil.getActiveWorkbenchWindow(event);
+ if (wbWindow != null) {
+ MWindow window = wbWindow.getService(MWindow.class);
+ if (window != null) {
+ String pageId = event.getParameter(
+ ICathyConstants.PARAMETER_DASHBOARD_PAGE_ID);
+ org.xmind.ui.internal.e4handlers.ShowDashboardPageHandler
+ .showDashboardPage(window, pageId);
+ }
+ }
+ return null;
+ }
+
}
\ No newline at end of file
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ToggleDashboardHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ToggleDashboardHandler.java
index 2a10921b1..fa876be02 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ToggleDashboardHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/ToggleDashboardHandler.java
@@ -1,20 +1,20 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-public class ToggleDashboardHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow wbw = HandlerUtil
- .getActiveWorkbenchWindowChecked(event);
- new org.xmind.ui.internal.e4handlers.ToggleDashboardHandler()
- .execute(wbw.getService(MWindow.class));
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class ToggleDashboardHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow wbw = HandlerUtil
+ .getActiveWorkbenchWindowChecked(event);
+ new org.xmind.ui.internal.e4handlers.ToggleDashboardHandler()
+ .execute(wbw.getService(MWindow.class));
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/UnpinRecentFileHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/UnpinRecentFileHandler.java
index f0e42f45d..0378d8cf0 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/UnpinRecentFileHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/UnpinRecentFileHandler.java
@@ -1,23 +1,23 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.ICathyConstants;
-
-public class UnpinRecentFileHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- Shell shell = HandlerUtil.getActiveShell(event);
- if (shell != null) {
- Object data = shell.getData(ICathyConstants.HELPER_RECENTFILE_PIN);
- if (data instanceof Runnable) {
- ((Runnable) data).run();
- }
- }
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.ICathyConstants;
+
+public class UnpinRecentFileHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Shell shell = HandlerUtil.getActiveShell(event);
+ if (shell != null) {
+ Object data = shell.getData(ICathyConstants.HELPER_RECENTFILE_PIN);
+ if (data instanceof Runnable) {
+ ((Runnable) data).run();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/WelcomeToXMindHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/WelcomeToXMindHandler.java
index 29ca952c4..a9d9ad527 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/WelcomeToXMindHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/WelcomeToXMindHandler.java
@@ -1,45 +1,47 @@
-package org.xmind.cathy.internal.handlers;
-
-import java.net.URI;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.ui.internal.MindMapUIPlugin;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class WelcomeToXMindHandler extends AbstractHandler {
-
- private static final String URL_WELCOME_FILE = "platform:/plugin/org.xmind.cathy/$nl$/resource/Welcome%20to%20XMind.xmind"; //$NON-NLS-1$
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
- if (window == null)
- return null;
-
- final IWorkbenchPage activePage = window.getActivePage();
- if (activePage == null)
- return null;
-
- MindMapUIPlugin.getDefault().getUsageDataCollector()
- .increase("WelcomeToXmindCount"); //$NON-NLS-1$
- SafeRunner.run(new SafeRunnable() {
- public void run() throws Exception {
- IEditorInput input = MindMapUI.getEditorInputFactory()
- .createEditorInput(new URI(URL_WELCOME_FILE),
- WorkbenchMessages.WelcomeToXMindHandler_welcomeToXMind_templatedName);
- activePage.openEditor(input, MindMapUI.MINDMAP_EDITOR_ID);
- }
- });
-
- return null;
- }
-
-}
+package org.xmind.cathy.internal.handlers;
+
+import java.net.URI;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.core.internal.UserDataConstants;
+import org.xmind.ui.internal.MindMapUIPlugin;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class WelcomeToXMindHandler extends AbstractHandler {
+
+ private static final String URL_WELCOME_FILE = "platform:/plugin/org.xmind.cathy/$nl$/resource/Welcome%20to%20XMind.xmind"; //$NON-NLS-1$
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
+ if (window == null)
+ return null;
+
+ final IWorkbenchPage activePage = window.getActivePage();
+ if (activePage == null)
+ return null;
+
+ MindMapUIPlugin.getDefault().getUsageDataCollector().trackEvent(
+ UserDataConstants.CATEGORY_OTHERS,
+ UserDataConstants.WELCOME_TO_XMIND);
+ SafeRunner.run(new SafeRunnable() {
+ public void run() throws Exception {
+ IEditorInput input = MindMapUI.getEditorInputFactory()
+ .createEditorInput(new URI(URL_WELCOME_FILE),
+ WorkbenchMessages.WelcomeToXMindHandler_welcomeToXMind_templatedName);
+ activePage.openEditor(input, MindMapUI.MINDMAP_EDITOR_ID);
+ }
+ });
+
+ return null;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/XMindHelpHandler.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/XMindHelpHandler.java
index fbe9f3834..1d8f97fea 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/XMindHelpHandler.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/handlers/XMindHelpHandler.java
@@ -1,45 +1,45 @@
-package org.xmind.cathy.internal.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.util.SafeRunnable;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.ui.browser.BrowserSupport;
-
-public class XMindHelpHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- SafeRunner.run(new SafeRunnable() {
- @Override
- public void run() throws Exception {
-// String internalURL = findInternalHelpURL();
-// if (internalURL != null) {
-// BrowserSupport.getInstance().createBrowser()
-// .openURL(internalURL);
-// } else {
- BrowserSupport.getInstance().createBrowser()
- .openURL(CathyPlugin.ONLINE_HELP_URL);
-// }
- }
- });
- return null;
- }
-
-// private String findInternalHelpURL() {
-// Bundle helpBundle = Platform.getBundle("org.xmind.ui.help"); //$NON-NLS-1$
-// if (helpBundle != null) {
-// URL url = FileLocator.find(helpBundle,
-// new Path("$nl$/contents/index.html"), null); //$NON-NLS-1$
-// if (url != null) {
-// try {
-// url = FileLocator.toFileURL(url);
-// return url.toExternalForm();
-// } catch (IOException e) {
-// }
-// }
-// }
-// return null;
-// }
-}
+package org.xmind.cathy.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.util.SafeRunnable;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.ui.browser.BrowserSupport;
+
+public class XMindHelpHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ SafeRunner.run(new SafeRunnable() {
+ @Override
+ public void run() throws Exception {
+// String internalURL = findInternalHelpURL();
+// if (internalURL != null) {
+// BrowserSupport.getInstance().createBrowser()
+// .openURL(internalURL);
+// } else {
+ BrowserSupport.getInstance().createBrowser()
+ .openURL(CathyPlugin.ONLINE_HELP_URL);
+// }
+ }
+ });
+ return null;
+ }
+
+// private String findInternalHelpURL() {
+// Bundle helpBundle = Platform.getBundle("org.xmind.ui.help"); //$NON-NLS-1$
+// if (helpBundle != null) {
+// URL url = FileLocator.find(helpBundle,
+// new Path("$nl$/contents/index.html"), null); //$NON-NLS-1$
+// if (url != null) {
+// try {
+// url = FileLocator.toFileURL(url);
+// return url.toExternalForm();
+// } catch (IOException e) {
+// }
+// }
+// }
+// return null;
+// }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/AbstractCheckFilesJob.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/AbstractCheckFilesJob.java
index 7d1505912..28f7d3e72 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/AbstractCheckFilesJob.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/AbstractCheckFilesJob.java
@@ -1,136 +1,136 @@
-package org.xmind.cathy.internal.jobs;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public abstract class AbstractCheckFilesJob extends Job {
-
- private final IWorkbench workbench;
-
- private List editorsToOpen;
-
- public AbstractCheckFilesJob(IWorkbench workbench, String jobName) {
- super(jobName);
- this.workbench = workbench;
- addJobChangeListener(new JobChangeAdapter() {
- @Override
- public void aboutToRun(IJobChangeEvent event) {
- prepare();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.core.runtime.jobs.JobChangeAdapter#done(org.eclipse
- * .core.runtime.jobs.IJobChangeEvent)
- */
- @Override
- public void done(IJobChangeEvent event) {
- finish();
- }
- });
- }
-
- protected void prepare() {
- editorsToOpen = null;
- }
-
- protected void finish() {
- editorsToOpen = null;
- }
-
- public IWorkbench getWorkbench() {
- return workbench;
- }
-
- protected void addEditorToOpen(IEditorInput input) {
- if (editorsToOpen == null)
- editorsToOpen = new ArrayList();
- editorsToOpen.add(input);
- }
-
- protected void openEditors(IProgressMonitor monitor, String taskName,
- int ticks, boolean activate) {
- if (editorsToOpen != null && !editorsToOpen.isEmpty()) {
- monitor = new SubProgressMonitor(monitor, ticks);
- monitor.beginTask(taskName, editorsToOpen.size());
- openEditors(monitor, editorsToOpen, activate);
- monitor.done();
- } else {
- monitor.worked(ticks);
- }
- }
-
- protected void openEditors(IProgressMonitor monitor,
- List editorInputs, boolean activate) {
- for (final IEditorInput input : editorInputs) {
- monitor.subTask(input.getName());
- IEditorPart editor = openEditor(input, activate);
- if (editor != null)
- activate = false;
- monitor.worked(1);
- }
- }
-
- protected IEditorPart openEditor(final IEditorInput input,
- final boolean activate) {
- if (input == null)
- return null;
-
- Display display = workbench.getDisplay();
- if (display == null)
- return null;
-
- final IEditorPart[] result = new IEditorPart[1];
- display.syncExec(new Runnable() {
- public void run() {
- IWorkbenchWindow window = getPrimaryWindow();
- if (window == null)
- return;
- final IWorkbenchPage page = window.getActivePage();
- if (page != null) {
- SafeRunner.run(new SafeRunnable(
- NLS.bind(
- WorkbenchMessages.CheckOpenFilesJob_FailsToOpen_message,
- input.getName())) {
- public void run() throws Exception {
- result[0] = page.openEditor(input,
- MindMapUI.MINDMAP_EDITOR_ID, activate);
- }
- });
- }
- }
-
- });
- return result[0];
- }
-
- private IWorkbenchWindow getPrimaryWindow() {
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- if (window == null) {
- IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
- if (windows != null && windows.length > 0) {
- window = windows[0];
- }
- }
- return window;
- }
-}
+package org.xmind.cathy.internal.jobs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public abstract class AbstractCheckFilesJob extends Job {
+
+ private final IWorkbench workbench;
+
+ private List editorsToOpen;
+
+ public AbstractCheckFilesJob(IWorkbench workbench, String jobName) {
+ super(jobName);
+ this.workbench = workbench;
+ addJobChangeListener(new JobChangeAdapter() {
+ @Override
+ public void aboutToRun(IJobChangeEvent event) {
+ prepare();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.jobs.JobChangeAdapter#done(org.eclipse
+ * .core.runtime.jobs.IJobChangeEvent)
+ */
+ @Override
+ public void done(IJobChangeEvent event) {
+ finish();
+ }
+ });
+ }
+
+ protected void prepare() {
+ editorsToOpen = null;
+ }
+
+ protected void finish() {
+ editorsToOpen = null;
+ }
+
+ public IWorkbench getWorkbench() {
+ return workbench;
+ }
+
+ protected void addEditorToOpen(IEditorInput input) {
+ if (editorsToOpen == null)
+ editorsToOpen = new ArrayList();
+ editorsToOpen.add(input);
+ }
+
+ protected void openEditors(IProgressMonitor monitor, String taskName,
+ int ticks, boolean activate) {
+ if (editorsToOpen != null && !editorsToOpen.isEmpty()) {
+ monitor = new SubProgressMonitor(monitor, ticks);
+ monitor.beginTask(taskName, editorsToOpen.size());
+ openEditors(monitor, editorsToOpen, activate);
+ monitor.done();
+ } else {
+ monitor.worked(ticks);
+ }
+ }
+
+ protected void openEditors(IProgressMonitor monitor,
+ List editorInputs, boolean activate) {
+ for (final IEditorInput input : editorInputs) {
+ monitor.subTask(input.getName());
+ IEditorPart editor = openEditor(input, activate);
+ if (editor != null)
+ activate = false;
+ monitor.worked(1);
+ }
+ }
+
+ protected IEditorPart openEditor(final IEditorInput input,
+ final boolean activate) {
+ if (input == null)
+ return null;
+
+ Display display = workbench.getDisplay();
+ if (display == null)
+ return null;
+
+ final IEditorPart[] result = new IEditorPart[1];
+ display.syncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = getPrimaryWindow();
+ if (window == null)
+ return;
+ final IWorkbenchPage page = window.getActivePage();
+ if (page != null) {
+ SafeRunner.run(new SafeRunnable(
+ NLS.bind(
+ WorkbenchMessages.CheckOpenFilesJob_FailsToOpen_message,
+ input.getName())) {
+ public void run() throws Exception {
+ result[0] = page.openEditor(input,
+ MindMapUI.MINDMAP_EDITOR_ID, activate);
+ }
+ });
+ }
+ }
+
+ });
+ return result[0];
+ }
+
+ private IWorkbenchWindow getPrimaryWindow() {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window == null) {
+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
+ if (windows != null && windows.length > 0) {
+ window = windows[0];
+ }
+ }
+ return window;
+ }
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/DownloadAndOpenFileJob.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/DownloadAndOpenFileJob.java
index eaa73ed56..21698493d 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/DownloadAndOpenFileJob.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/DownloadAndOpenFileJob.java
@@ -1,261 +1,266 @@
-package org.xmind.cathy.internal.jobs;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.core.Core;
-import org.xmind.core.IWorkbook;
-import org.xmind.core.event.ICoreEventListener;
-import org.xmind.core.event.ICoreEventSource2;
-import org.xmind.core.io.DirectoryStorage;
-import org.xmind.core.io.IStorage;
-import org.xmind.core.util.FileUtils;
-import org.xmind.ui.internal.imports.freemind.FreeMindImporter;
-import org.xmind.ui.internal.imports.mm.MindManagerImporter;
-import org.xmind.ui.io.DownloadJob;
-import org.xmind.ui.mindmap.MindMapUI;
-
-public class DownloadAndOpenFileJob extends Job {
-
- private IWorkbench workbench;
-
- private String url;
-
- private String targetName;
-
- private File tempFile;
-
- public DownloadAndOpenFileJob(IWorkbench workbench, String url,
- String targetName) {
- super(WorkbenchMessages.DownloadAndOpenFileJob_jobName);
- Assert.isNotNull(workbench);
- Assert.isNotNull(url);
- this.workbench = workbench;
- this.url = url;
- this.targetName = targetName;
- }
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- if (monitor.isCanceled())
- return Status.CANCEL_STATUS;
-
- monitor.beginTask(null, 2);
-
- IStatus downloaded = download(monitor);
- if (!downloaded.isOK())
- return downloaded;
-
- monitor.worked(1);
-
- IStatus opened = open(monitor);
- if (!opened.isOK())
- return opened;
-
- monitor.done();
-
- return Status.OK_STATUS;
- }
-
- private IStatus download(IProgressMonitor monitor) {
- if (monitor.isCanceled())
- return Status.CANCEL_STATUS;
-
- monitor.subTask(NLS.bind(
- WorkbenchMessages.DownloadAndOpenFileJob_Task_Download_with_url,
- url));
- tempFile = createTempPath(url);
- if (tempFile.getParentFile() == null
- || !tempFile.getParentFile().isDirectory()) {
- return new Status(IStatus.ERROR, MindMapUI.PLUGIN_ID,
- WorkbenchMessages.DownloadAndOpenFileJob_Error_FailedToCreateTempFile);
- }
-
- DownloadJob downloadJob = new DownloadJob(
- WorkbenchMessages.DownloadAndOpenFileJob_DownloadJob_jobName,
- url, tempFile.getAbsolutePath(), MindMapUI.PLUGIN_ID);
- downloadJob.setUser(true);
- downloadJob.schedule();
- try {
- downloadJob.join();
- } catch (InterruptedException e) {
- }
-
- if (monitor.isCanceled()) {
- downloadJob.cancel();
- return Status.CANCEL_STATUS;
- }
-
- IStatus downloaded = downloadJob.getResult();
- if (downloaded == null)
- // This should never happen?
- return new Status(IStatus.ERROR, MindMapUI.PLUGIN_ID,
- "No result retrieved from download job."); //$NON-NLS-1$
- return downloaded;
- }
-
- private IStatus open(IProgressMonitor monitor) {
- monitor.subTask(NLS.bind(
- WorkbenchMessages.DownloadAndOpenFileJob_Task_OpenDownloadedFile_with_url,
- url));
-
- try {
- IStorage tempStorage = createTempStorage();
- final IWorkbook workbook = loadWorkbook(monitor, tempStorage);
- if (workbook != null) {
- return openMindMapEditor(monitor, workbook);
- }
- } catch (Throwable e) {
- return new Status(IStatus.ERROR, MindMapUI.PLUGIN_ID,
- NLS.bind(
- WorkbenchMessages.DownloadAndOpenFileJob_Error_FailedToLoadWorkbook_with_url,
- url),
- e);
- }
- return Status.CANCEL_STATUS;
- }
-
- private IWorkbook loadWorkbook(IProgressMonitor monitor,
- IStorage tempStorage) throws Exception {
- String ext = FileUtils.getExtension(tempFile.getAbsolutePath());
- if (MindMapUI.FILE_EXT_XMIND.equalsIgnoreCase(ext)) {
- return loadWorkbookFromXMindFile(monitor, tempStorage);
- } else if (MindMapUI.FILE_EXT_TEMPLATE.equalsIgnoreCase(ext)) {
- return loadWorkbookFromTemplate(monitor, tempStorage);
- } else if (".mmap".equalsIgnoreCase(ext)) { //$NON-NLS-1$
- return loadWorkbookFromMindManagerFile(monitor, tempStorage);
- } else if (".mm".equalsIgnoreCase(ext)) { //$NON-NLS-1$
- return loadWorkbookFromFreeMindFile(monitor, tempStorage);
- }
- return null;
- }
-
- private IWorkbook loadWorkbookFromXMindFile(IProgressMonitor monitor,
- IStorage tempStorage) throws Exception {
- return Core.getWorkbookBuilder().loadFromFile(tempFile, tempStorage,
- null);
- }
-
- private IWorkbook loadWorkbookFromTemplate(IProgressMonitor monitor,
- IStorage tempStorage) throws Exception {
- return Core.getWorkbookBuilder().loadFromFile(tempFile, tempStorage,
- null);
- }
-
- private IWorkbook loadWorkbookFromMindManagerFile(IProgressMonitor monitor,
- IStorage tempStorage) throws Exception {
- MindManagerImporter importer = new MindManagerImporter(
- tempFile.getAbsolutePath());
- importer.build();
- return importer.getTargetWorkbook();
- }
-
- private IWorkbook loadWorkbookFromFreeMindFile(IProgressMonitor monitor,
- IStorage tempStorage) throws Exception {
- FreeMindImporter importer = new FreeMindImporter(
- tempFile.getAbsolutePath());
- importer.build();
- return importer.getTargetWorkbook();
- }
-
- private IStatus openMindMapEditor(final IProgressMonitor monitor,
- final IWorkbook workbook) {
- final IStatus[] result = new IStatus[1];
- result[0] = null;
- Display display = workbench.getDisplay();
- if (display == null || display.isDisposed()) {
- monitor.setCanceled(true);
- return Status.CANCEL_STATUS;
- }
- display.syncExec(new Runnable() {
- public void run() {
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- if (window == null)
- return;
-
- IWorkbenchPage page = window.getActivePage();
- if (page == null)
- return;
-
- String name = targetName == null ? getFileName(url)
- : targetName;
- IEditorInput input = MindMapUI.getEditorInputFactory()
- .createEditorInputForPreLoadedWorkbook(workbook, name);
- try {
- page.openEditor(input, MindMapUI.MINDMAP_EDITOR_ID, true);
- } catch (PartInitException e) {
- result[0] = e.getStatus();
- return;
- }
-
- if (workbook instanceof ICoreEventSource2) {
- ((ICoreEventSource2) workbook)
- .registerOnceCoreEventListener(
- Core.WorkbookPreSaveOnce,
- ICoreEventListener.NULL);
- }
-
- result[0] = Status.OK_STATUS;
- }
- });
- if (result[0] == null)
- return Status.CANCEL_STATUS;
- return result[0];
- }
-
- @Override
- protected void canceling() {
- super.canceling();
- Thread thread = getThread();
- if (thread != null) {
- thread.interrupt();
- }
- }
-
- private static File createTempPath(String url) {
- String fileName = getFileName(url);
- String ext = FileUtils.getExtension(fileName);
- String prefix = fileName.substring(0, fileName.length() - ext.length());
- return Core.getWorkspace().createTempFile("download", prefix + "_", //$NON-NLS-1$//$NON-NLS-2$
- ext);
- }
-
- private static IStorage createTempStorage() {
- File tempDir = Core.getWorkspace()
- .createTempFile("openFromDownloadedFile", "", ".temp"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- tempDir.mkdirs();
- return new DirectoryStorage(tempDir);
- }
-
- private static String getFileName(String url) {
- String path;
- try {
- path = new URI(url).getPath();
- } catch (URISyntaxException e) {
- int j = url.lastIndexOf('?');
- if (j < 0)
- path = url;
- else
- path = url.substring(0, j);
- }
- int i = path.lastIndexOf('/');
- if (i < 0)
- return path;
- return path.substring(i + 1);
- }
-
-}
+package org.xmind.cathy.internal.jobs;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.core.Core;
+import org.xmind.core.IWorkbook;
+import org.xmind.core.event.ICoreEventListener;
+import org.xmind.core.event.ICoreEventSource2;
+import org.xmind.core.io.DirectoryStorage;
+import org.xmind.core.io.IStorage;
+import org.xmind.core.util.FileUtils;
+import org.xmind.ui.internal.imports.freemind.FreeMindImporter;
+import org.xmind.ui.internal.imports.mm.MindManagerImporter;
+import org.xmind.ui.io.DownloadJob;
+import org.xmind.ui.mindmap.LazyPasswordBasedEncryptor;
+import org.xmind.ui.mindmap.MindMapUI;
+
+public class DownloadAndOpenFileJob extends Job {
+
+ private IWorkbench workbench;
+
+ private String url;
+
+ private String targetName;
+
+ private File tempFile;
+
+ public DownloadAndOpenFileJob(IWorkbench workbench, String url,
+ String targetName) {
+ super(WorkbenchMessages.DownloadAndOpenFileJob_jobName);
+ Assert.isNotNull(workbench);
+ Assert.isNotNull(url);
+ this.workbench = workbench;
+ this.url = url;
+ this.targetName = targetName;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
+ monitor.beginTask(null, 2);
+
+ IStatus downloaded = download(monitor);
+ if (!downloaded.isOK())
+ return downloaded;
+
+ monitor.worked(1);
+
+ IStatus opened = open(monitor);
+ if (!opened.isOK())
+ return opened;
+
+ monitor.done();
+
+ return Status.OK_STATUS;
+ }
+
+ private IStatus download(IProgressMonitor monitor) {
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
+ monitor.subTask(NLS.bind(
+ WorkbenchMessages.DownloadAndOpenFileJob_Task_Download_with_url,
+ url));
+ tempFile = createTempPath(url);
+ if (tempFile.getParentFile() == null
+ || !tempFile.getParentFile().isDirectory()) {
+ return new Status(IStatus.ERROR, MindMapUI.PLUGIN_ID,
+ WorkbenchMessages.DownloadAndOpenFileJob_Error_FailedToCreateTempFile);
+ }
+
+ DownloadJob downloadJob = new DownloadJob(
+ WorkbenchMessages.DownloadAndOpenFileJob_DownloadJob_jobName,
+ url, tempFile.getAbsolutePath(), MindMapUI.PLUGIN_ID);
+ downloadJob.setUser(true);
+ downloadJob.schedule();
+ try {
+ downloadJob.join();
+ } catch (InterruptedException e) {
+ }
+
+ if (monitor.isCanceled()) {
+ downloadJob.cancel();
+ return Status.CANCEL_STATUS;
+ }
+
+ IStatus downloaded = downloadJob.getResult();
+ if (downloaded == null)
+ // This should never happen?
+ return new Status(IStatus.ERROR, MindMapUI.PLUGIN_ID,
+ "No result retrieved from download job."); //$NON-NLS-1$
+ return downloaded;
+ }
+
+ private IStatus open(IProgressMonitor monitor) {
+ monitor.subTask(NLS.bind(
+ WorkbenchMessages.DownloadAndOpenFileJob_Task_OpenDownloadedFile_with_url,
+ url));
+
+ try {
+ IStorage tempStorage = createTempStorage();
+ final IWorkbook workbook = loadWorkbook(monitor, tempStorage);
+ if (workbook != null) {
+ return openMindMapEditor(monitor, workbook);
+ }
+ } catch (Throwable e) {
+ return new Status(IStatus.ERROR, MindMapUI.PLUGIN_ID,
+ NLS.bind(
+ WorkbenchMessages.DownloadAndOpenFileJob_Error_FailedToLoadWorkbook_with_url,
+ url),
+ e);
+ }
+ return Status.CANCEL_STATUS;
+ }
+
+ private IWorkbook loadWorkbook(IProgressMonitor monitor,
+ IStorage tempStorage) throws Exception {
+ String ext = FileUtils.getExtension(tempFile.getAbsolutePath());
+ if (MindMapUI.FILE_EXT_XMIND.equalsIgnoreCase(ext)) {
+ return loadWorkbookFromXMindFile(monitor, tempStorage);
+ } else if (MindMapUI.FILE_EXT_TEMPLATE.equalsIgnoreCase(ext)) {
+ return loadWorkbookFromTemplate(monitor, tempStorage);
+ } else if (".mmap".equalsIgnoreCase(ext)) { //$NON-NLS-1$
+ return loadWorkbookFromMindManagerFile(monitor, tempStorage);
+ } else if (".mm".equalsIgnoreCase(ext)) { //$NON-NLS-1$
+ return loadWorkbookFromFreeMindFile(monitor, tempStorage);
+ }
+ return null;
+ }
+
+ private IWorkbook loadWorkbookFromXMindFile(IProgressMonitor monitor,
+ IStorage tempStorage) throws Exception {
+ Core.getWorkbookBuilder()
+ .setEntryStreamNormalizer(new LazyPasswordBasedEncryptor());
+ return Core.getWorkbookBuilder().loadFromFile(tempFile, tempStorage,
+ null);
+ }
+
+ private IWorkbook loadWorkbookFromTemplate(IProgressMonitor monitor,
+ IStorage tempStorage) throws Exception {
+ Core.getWorkbookBuilder()
+ .setEntryStreamNormalizer(new LazyPasswordBasedEncryptor());
+ return Core.getWorkbookBuilder().loadFromFile(tempFile, tempStorage,
+ null);
+ }
+
+ private IWorkbook loadWorkbookFromMindManagerFile(IProgressMonitor monitor,
+ IStorage tempStorage) throws Exception {
+ MindManagerImporter importer = new MindManagerImporter(
+ tempFile.getAbsolutePath());
+ importer.build();
+ return importer.getTargetWorkbook();
+ }
+
+ private IWorkbook loadWorkbookFromFreeMindFile(IProgressMonitor monitor,
+ IStorage tempStorage) throws Exception {
+ FreeMindImporter importer = new FreeMindImporter(
+ tempFile.getAbsolutePath());
+ importer.build();
+ return importer.getTargetWorkbook();
+ }
+
+ private IStatus openMindMapEditor(final IProgressMonitor monitor,
+ final IWorkbook workbook) {
+ final IStatus[] result = new IStatus[1];
+ result[0] = null;
+ Display display = workbench.getDisplay();
+ if (display == null || display.isDisposed()) {
+ monitor.setCanceled(true);
+ return Status.CANCEL_STATUS;
+ }
+ display.syncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window == null)
+ return;
+
+ IWorkbenchPage page = window.getActivePage();
+ if (page == null)
+ return;
+
+ String name = targetName == null ? getFileName(url)
+ : targetName;
+ IEditorInput input = MindMapUI.getEditorInputFactory()
+ .createEditorInputForPreLoadedWorkbook(workbook, name);
+ try {
+ page.openEditor(input, MindMapUI.MINDMAP_EDITOR_ID, true);
+ } catch (PartInitException e) {
+ result[0] = e.getStatus();
+ return;
+ }
+
+ if (workbook instanceof ICoreEventSource2) {
+ ((ICoreEventSource2) workbook)
+ .registerOnceCoreEventListener(
+ Core.WorkbookPreSaveOnce,
+ ICoreEventListener.NULL);
+ }
+
+ result[0] = Status.OK_STATUS;
+ }
+ });
+ if (result[0] == null)
+ return Status.CANCEL_STATUS;
+ return result[0];
+ }
+
+ @Override
+ protected void canceling() {
+ super.canceling();
+ Thread thread = getThread();
+ if (thread != null) {
+ thread.interrupt();
+ }
+ }
+
+ private static File createTempPath(String url) {
+ String fileName = getFileName(url);
+ String ext = FileUtils.getExtension(fileName);
+ String prefix = fileName.substring(0, fileName.length() - ext.length());
+ return Core.getWorkspace().createTempFile("download", prefix + "_", //$NON-NLS-1$//$NON-NLS-2$
+ ext);
+ }
+
+ private static IStorage createTempStorage() {
+ File tempDir = Core.getWorkspace()
+ .createTempFile("openFromDownloadedFile", "", ".temp"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ tempDir.mkdirs();
+ return new DirectoryStorage(tempDir);
+ }
+
+ private static String getFileName(String url) {
+ String path;
+ try {
+ path = new URI(url).getPath();
+ } catch (URISyntaxException e) {
+ int j = url.lastIndexOf('?');
+ if (j < 0)
+ path = url;
+ else
+ path = url.substring(0, j);
+ }
+ int i = path.lastIndexOf('/');
+ if (i < 0)
+ return path;
+ return path.substring(i + 1);
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/OpenFilesJob.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/OpenFilesJob.java
index ccffbb816..8dbc6c5b7 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/OpenFilesJob.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/OpenFilesJob.java
@@ -1,277 +1,281 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-
-package org.xmind.cathy.internal.jobs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.core.Core;
-import org.xmind.core.IWorkbook;
-import org.xmind.core.command.Command;
-import org.xmind.core.command.CommandJob;
-import org.xmind.core.command.ICommand;
-import org.xmind.core.util.FileUtils;
-import org.xmind.ui.internal.MarkerImpExpUtils;
-import org.xmind.ui.internal.imports.freemind.FreeMindImporter;
-import org.xmind.ui.internal.imports.mm.MindManagerImporter;
-import org.xmind.ui.internal.prefs.MarkerManagerPrefPage;
-import org.xmind.ui.mindmap.MindMapUI;
-import org.xmind.ui.util.PrefUtils;
-import org.xmind.ui.wizards.MindMapImporter;
-
-/**
- * @author Frank Shaka
- *
- */
-public class OpenFilesJob extends AbstractCheckFilesJob {
-
- private List filesToOpen;
-
- private boolean markersImported = false;
-
- private List commandFilesToOpen = new ArrayList(1);
-
- public OpenFilesJob(IWorkbench workbench, String jobName) {
- super(workbench, jobName);
- this.filesToOpen = new ArrayList();
- }
-
- /**
- *
- */
- public OpenFilesJob(IWorkbench workbench, String jobName,
- Collection files) {
- super(workbench, jobName);
- this.filesToOpen = new ArrayList(files);
- }
-
- @Override
- protected void prepare() {
- markersImported = false;
- super.prepare();
- }
-
- @Override
- protected void finish() {
- filesToOpen.clear();
- markersImported = false;
- super.finish();
- }
-
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask(null, getTotalSteps());
- doCheckAndOpenFiles(monitor);
- monitor.done();
- return Status.OK_STATUS;
- }
-
- /**
- * Number of ticks that this job is going to consume.
- *
- * @return
- */
- protected int getTotalSteps() {
- return 4;
- }
-
- /**
- * Opens files.
- *
- * @param monitor
- * the progress monitor
- */
- protected void doCheckAndOpenFiles(IProgressMonitor monitor) {
- filterFilesToOpen(filesToOpen, new SubProgressMonitor(monitor, 1));
-
- if (filesToOpen.isEmpty()) {
- monitor.worked(2);
- } else {
- addEditors(new SubProgressMonitor(monitor, 1));
- openEditors(monitor,
- WorkbenchMessages.CheckOpenFilesJob_OpenFiles_name, 1,
- true);
- }
-
- onFilsOpened(new SubProgressMonitor(monitor, 1));
- }
-
- /**
- *
- */
- protected void onFilsOpened(IProgressMonitor monitor) {
- monitor.beginTask(null, 1);
- if (markersImported)
- showMarkersPrefPage();
- if (!commandFilesToOpen.isEmpty()) {
- openXMindCommandFiles();
- }
- monitor.done();
- }
-
- /**
- * Filters the files to open. Subclasses may add/remove files to/from the
- * `filesToOpen` list.
- *
- * @param monitor
- */
- protected void filterFilesToOpen(List filesToOpen,
- IProgressMonitor monitor) {
- monitor.beginTask(null, 1);
- monitor.done();
- }
-
- /**
- * Add editors to open.
- *
- * @param monitor
- */
- protected void addEditors(final IProgressMonitor monitor) {
- monitor.beginTask(WorkbenchMessages.CheckOpenFilesJob_OpenFiles_name,
- filesToOpen.size());
- for (final String fileName : filesToOpen) {
- SafeRunner.run(new SafeRunnable(NLS.bind(
- WorkbenchMessages.CheckOpenFilesJob_FailsToOpen_message,
- fileName)) {
- public void run() throws Exception {
- monitor.subTask(fileName);
- IEditorInput input = createEditorInput(fileName, monitor);
- if (input != null) {
- addEditorToOpen(input);
- }
- monitor.worked(1);
- }
- });
- }
- monitor.done();
- }
-
- /**
- * Create an editor input from the file, or do anything to open the file.
- *
- * @param fileName
- * @param monitor
- * @return
- * @throws Exception
- */
- protected IEditorInput createEditorInput(String fileName,
- IProgressMonitor monitor) throws Exception {
- final ICommand command = Command.parseURI(fileName);
- if (command != null) {
- new CommandJob(command, null).schedule();
- return null;
- }
-
- final String path = fileName;
- String extension = FileUtils.getExtension(path);
-
- if (CathyPlugin.COMMAND_FILE_EXT.equalsIgnoreCase(extension)) {
- return openXMindCommandFile(path);
- } else if (MindMapUI.FILE_EXT_TEMPLATE.equalsIgnoreCase(extension)) {
- return newFromTemplate(path, fileName);
- } else if (".mmap".equalsIgnoreCase(extension)) { //$NON-NLS-1$
- return importMindManagerFile(path, fileName);
- } else if (".mm".equalsIgnoreCase(extension)) { //$NON-NLS-1$
- return importFreeMindFile(path, fileName);
- } else if (MindMapUI.FILE_EXT_MARKER_PACKAGE
- .equalsIgnoreCase(extension)) {
- return importMarkers(path);
- } else if (new File(path).exists()) {
- return MindMapUI.getEditorInputFactory()
- .createEditorInputForFile(new File(path));
- } else {
- // assumes we're opening xmind files
- IWorkbook workbook = Core.getWorkbookBuilder().loadFromPath(path);
- return workbook == null ? null
- : MindMapUI.getEditorInputFactory()
- .createEditorInputForPreLoadedWorkbook(workbook,
- fileName);
- }
- }
-
- protected IEditorInput newFromTemplate(String path, String fileName)
- throws Exception {
- IWorkbook workbook = Core.getWorkbookBuilder().loadFromPath(path);
- return workbook == null ? null
- : MindMapUI.getEditorInputFactory()
- .createEditorInputForPreLoadedWorkbook(workbook,
- fileName);
- }
-
- protected IEditorInput importMindManagerFile(String path, String fileName)
- throws Exception {
- MindMapImporter importer = new MindManagerImporter(path);
- importer.build();
- IWorkbook workbook = importer.getTargetWorkbook();
- return workbook == null ? null
- : MindMapUI.getEditorInputFactory()
- .createEditorInputForPreLoadedWorkbook(workbook,
- fileName);
- }
-
- protected IEditorInput importFreeMindFile(String path, String fileName)
- throws Exception {
- FreeMindImporter importer = new FreeMindImporter(path);
- importer.build();
- IWorkbook workbook = importer.getTargetWorkbook();
- return workbook == null ? null
- : MindMapUI.getEditorInputFactory()
- .createEditorInputForPreLoadedWorkbook(workbook,
- fileName);
- }
-
- protected IEditorInput importMarkers(String path) throws Exception {
- MarkerImpExpUtils.importMarkerPackage(path);
- markersImported = true;
- return null;
- }
-
- private void showMarkersPrefPage() {
- Display display = getWorkbench().getDisplay();
- if (display == null || display.isDisposed())
- return;
-
- display.asyncExec(new Runnable() {
- public void run() {
- PrefUtils.openPrefDialog(null, MarkerManagerPrefPage.ID);
- }
- });
- }
-
- private IEditorInput openXMindCommandFile(String path) {
- commandFilesToOpen.add(path);
- return null;
- }
-
- private void openXMindCommandFiles() {
- for (String path : commandFilesToOpen) {
- new OpenXMindCommandFileJob(path).schedule(500);
- }
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+
+package org.xmind.cathy.internal.jobs;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.core.Core;
+import org.xmind.core.IWorkbook;
+import org.xmind.core.command.Command;
+import org.xmind.core.command.CommandJob;
+import org.xmind.core.command.ICommand;
+import org.xmind.core.util.FileUtils;
+import org.xmind.ui.internal.MarkerImpExpUtils;
+import org.xmind.ui.internal.imports.freemind.FreeMindImporter;
+import org.xmind.ui.internal.imports.mm.MindManagerImporter;
+import org.xmind.ui.internal.prefs.MarkerManagerPrefPage;
+import org.xmind.ui.mindmap.LazyPasswordBasedEncryptor;
+import org.xmind.ui.mindmap.MindMapUI;
+import org.xmind.ui.util.PrefUtils;
+import org.xmind.ui.wizards.MindMapImporter;
+
+/**
+ * @author Frank Shaka
+ */
+public class OpenFilesJob extends AbstractCheckFilesJob {
+
+ private List filesToOpen;
+
+ private boolean markersImported = false;
+
+ private List commandFilesToOpen = new ArrayList(1);
+
+ public OpenFilesJob(IWorkbench workbench, String jobName) {
+ super(workbench, jobName);
+ this.filesToOpen = new ArrayList();
+ }
+
+ /**
+ *
+ */
+ public OpenFilesJob(IWorkbench workbench, String jobName,
+ Collection files) {
+ super(workbench, jobName);
+ this.filesToOpen = new ArrayList(files);
+ }
+
+ @Override
+ protected void prepare() {
+ markersImported = false;
+ super.prepare();
+ }
+
+ @Override
+ protected void finish() {
+ filesToOpen.clear();
+ markersImported = false;
+ super.finish();
+ }
+
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask(null, getTotalSteps());
+ doCheckAndOpenFiles(monitor);
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Number of ticks that this job is going to consume.
+ *
+ * @return
+ */
+ protected int getTotalSteps() {
+ return 4;
+ }
+
+ /**
+ * Opens files.
+ *
+ * @param monitor
+ * the progress monitor
+ */
+ protected void doCheckAndOpenFiles(IProgressMonitor monitor) {
+ filterFilesToOpen(filesToOpen, new SubProgressMonitor(monitor, 1));
+
+ if (filesToOpen.isEmpty()) {
+ monitor.worked(2);
+ } else {
+ addEditors(new SubProgressMonitor(monitor, 1));
+ openEditors(monitor,
+ WorkbenchMessages.CheckOpenFilesJob_OpenFiles_name, 1,
+ true);
+ }
+
+ onFilsOpened(new SubProgressMonitor(monitor, 1));
+ }
+
+ /**
+ *
+ */
+ protected void onFilsOpened(IProgressMonitor monitor) {
+ monitor.beginTask(null, 1);
+ if (markersImported)
+ showMarkersPrefPage();
+ if (!commandFilesToOpen.isEmpty()) {
+ openXMindCommandFiles();
+ }
+ monitor.done();
+ }
+
+ /**
+ * Filters the files to open. Subclasses may add/remove files to/from the
+ * `filesToOpen` list.
+ *
+ * @param monitor
+ */
+ protected void filterFilesToOpen(List filesToOpen,
+ IProgressMonitor monitor) {
+ monitor.beginTask(null, 1);
+ monitor.done();
+ }
+
+ /**
+ * Add editors to open.
+ *
+ * @param monitor
+ */
+ protected void addEditors(final IProgressMonitor monitor) {
+ monitor.beginTask(WorkbenchMessages.CheckOpenFilesJob_OpenFiles_name,
+ filesToOpen.size());
+ for (final String fileName : filesToOpen) {
+ SafeRunner.run(new SafeRunnable(NLS.bind(
+ WorkbenchMessages.CheckOpenFilesJob_FailsToOpen_message,
+ fileName)) {
+ public void run() throws Exception {
+ monitor.subTask(fileName);
+ IEditorInput input = createEditorInput(fileName, monitor);
+ if (input != null) {
+ addEditorToOpen(input);
+ }
+ monitor.worked(1);
+ }
+ });
+ }
+ monitor.done();
+ }
+
+ /**
+ * Create an editor input from the file, or do anything to open the file.
+ *
+ * @param fileName
+ * @param monitor
+ * @return
+ * @throws Exception
+ */
+ protected IEditorInput createEditorInput(String fileName,
+ IProgressMonitor monitor) throws Exception {
+ final ICommand command = Command.parseURI(fileName);
+ if (command != null) {
+ new CommandJob(command, null).schedule();
+ return null;
+ }
+
+ final String path = fileName;
+ String extension = FileUtils.getExtension(path);
+
+ if (CathyPlugin.COMMAND_FILE_EXT.equalsIgnoreCase(extension)) {
+ return openXMindCommandFile(path);
+ } else if (MindMapUI.FILE_EXT_TEMPLATE.equalsIgnoreCase(extension)) {
+ return newFromTemplate(path, fileName);
+ } else if (".mmap".equalsIgnoreCase(extension)) { //$NON-NLS-1$
+ return importMindManagerFile(path, fileName);
+ } else if (".mm".equalsIgnoreCase(extension)) { //$NON-NLS-1$
+ return importFreeMindFile(path, fileName);
+ } else if (MindMapUI.FILE_EXT_MARKER_PACKAGE
+ .equalsIgnoreCase(extension)) {
+ return importMarkers(path);
+ } else if (new File(path).exists()) {
+ return MindMapUI.getEditorInputFactory()
+ .createEditorInputForFile(new File(path));
+ } else {
+ // assumes we're opening xmind files
+ Core.getWorkbookBuilder()
+ .setEntryStreamNormalizer(new LazyPasswordBasedEncryptor());
+ IWorkbook workbook = Core.getWorkbookBuilder().loadFromPath(path);
+ return workbook == null ? null
+ : MindMapUI.getEditorInputFactory()
+ .createEditorInputForPreLoadedWorkbook(workbook,
+ fileName);
+ }
+ }
+
+ protected IEditorInput newFromTemplate(String path, String fileName)
+ throws Exception {
+ Core.getWorkbookBuilder()
+ .setEntryStreamNormalizer(new LazyPasswordBasedEncryptor());
+ IWorkbook workbook = Core.getWorkbookBuilder().loadFromPath(path);
+ return workbook == null ? null
+ : MindMapUI.getEditorInputFactory()
+ .createEditorInputForPreLoadedWorkbook(workbook,
+ fileName);
+ }
+
+ protected IEditorInput importMindManagerFile(String path, String fileName)
+ throws Exception {
+ MindMapImporter importer = new MindManagerImporter(path);
+ importer.build();
+ IWorkbook workbook = importer.getTargetWorkbook();
+ return workbook == null ? null
+ : MindMapUI.getEditorInputFactory()
+ .createEditorInputForPreLoadedWorkbook(workbook,
+ fileName);
+ }
+
+ protected IEditorInput importFreeMindFile(String path, String fileName)
+ throws Exception {
+ FreeMindImporter importer = new FreeMindImporter(path);
+ importer.build();
+ IWorkbook workbook = importer.getTargetWorkbook();
+ return workbook == null ? null
+ : MindMapUI.getEditorInputFactory()
+ .createEditorInputForPreLoadedWorkbook(workbook,
+ fileName);
+ }
+
+ protected IEditorInput importMarkers(String path) throws Exception {
+ MarkerImpExpUtils.importMarkerPackage(path);
+ markersImported = true;
+ return null;
+ }
+
+ private void showMarkersPrefPage() {
+ Display display = getWorkbench().getDisplay();
+ if (display == null || display.isDisposed())
+ return;
+
+ display.asyncExec(new Runnable() {
+ public void run() {
+ PrefUtils.openPrefDialog(null, MarkerManagerPrefPage.ID);
+ }
+ });
+ }
+
+ private IEditorInput openXMindCommandFile(String path) {
+ commandFilesToOpen.add(path);
+ return null;
+ }
+
+ private void openXMindCommandFiles() {
+ for (String path : commandFilesToOpen) {
+ new OpenXMindCommandFileJob(path).schedule(500);
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/OpenXMindCommandFileJob.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/OpenXMindCommandFileJob.java
index 5e555541e..503a3ad0e 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/OpenXMindCommandFileJob.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/jobs/OpenXMindCommandFileJob.java
@@ -1,139 +1,139 @@
-/* ******************************************************************************
- * Copyright (c) 2006-2012 XMind Ltd. and others.
- *
- * This file is a part of XMind 3. XMind releases 3 and
- * above are dual-licensed under the Eclipse Public License (EPL),
- * which is available at http://www.eclipse.org/legal/epl-v10.html
- * and the GNU Lesser General Public License (LGPL),
- * which is available at http://www.gnu.org/licenses/lgpl.html
- * See http://www.xmind.net/license.html for details.
- *
- * Contributors:
- * XMind Ltd. - initial API and implementation
- *******************************************************************************/
-package org.xmind.cathy.internal.jobs;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.osgi.util.NLS;
-import org.xmind.cathy.internal.CathyPlugin;
-import org.xmind.cathy.internal.WorkbenchMessages;
-import org.xmind.core.command.transfer.IncomingCommandHandler;
-
-public class OpenXMindCommandFileJob extends Job {
-
- private static final String DEBUG_OPTION = "/debug/openXMindCommandFile"; //$NON-NLS-1$
-
- private static boolean DEBUGGING = CathyPlugin.getDefault()
- .isDebugging(DEBUG_OPTION);
-
- private static class InternalOpenXMindCommandFileHandler
- extends IncomingCommandHandler {
-
- protected IStatus createReadingErrorStatus(Throwable e) {
- return super.createReadingErrorStatus(e);
- }
-
- protected IStatus createWritingErrorStatus(Throwable e) {
- return super.createWritingErrorStatus(e);
- }
-
- }
-
- private static class NullOutputStream extends OutputStream {
-
- public void write(int b) throws IOException {
- // ignore all bits
- }
-
- public void write(byte[] b) throws IOException {
- // ignore all bits
- }
-
- public void write(byte[] b, int off, int len) throws IOException {
- // ignore all bits
- }
-
- }
-
- private String commandFilePath;
-
- public OpenXMindCommandFileJob(String commandFilePath) {
- super(NLS.bind(WorkbenchMessages.OpenXMindCommandFileJob_name,
- commandFilePath));
- this.commandFilePath = commandFilePath;
- setUser(false);
- }
-
- protected IStatus run(IProgressMonitor monitor) {
- if (commandFilePath == null)
- return new Status(IStatus.WARNING, CathyPlugin.PLUGIN_ID,
- WorkbenchMessages.OpenXMindCommandFileJob_failed_noCommandFilePath_text);
-
- File commandFile = new File(commandFilePath);
- if (!commandFile.exists() || !commandFile.isFile()
- || !commandFile.canRead())
- return new Status(IStatus.WARNING, CathyPlugin.PLUGIN_ID,
- NLS.bind(
- WorkbenchMessages.OpenXMindCommandFileJob_failed_fileIsNotReadable,
- commandFilePath));
-
- try {
- InputStream input = new FileInputStream(commandFile);
- try {
- OutputStream output = createOutputStream();
- try {
- IncomingCommandHandler handler = new InternalOpenXMindCommandFileHandler();
- handler.setPluginId(CathyPlugin.PLUGIN_ID);
- IStatus result = handler.handleIncomingCommand(monitor,
- input, output);
- if (DEBUGGING) {
- logOutput(output);
- }
- return result;
- } finally {
- output.close();
- }
- } finally {
- input.close();
- }
- } catch (IOException e) {
- return new Status(IStatus.WARNING, CathyPlugin.PLUGIN_ID,
- NLS.bind(
- WorkbenchMessages.OpenXMindCommandFileJob_failed_openXMindCommandFile,
- e.getLocalizedMessage()),
- e);
- }
- }
-
- private void logOutput(OutputStream output) {
- if (!(output instanceof ByteArrayOutputStream))
- return;
- try {
- String outputText = ((ByteArrayOutputStream) output)
- .toString("UTF-8"); //$NON-NLS-1$
- System.out.println("Response of XMind command file: " //$NON-NLS-1$
- + commandFilePath);
- System.out.println(outputText);
- } catch (UnsupportedEncodingException e2) {
- // Ignore encoding error
- }
- }
-
- private OutputStream createOutputStream() {
- if (DEBUGGING)
- return new ByteArrayOutputStream(4096);
- return new NullOutputStream();
- }
-
-}
+/* ******************************************************************************
+ * Copyright (c) 2006-2012 XMind Ltd. and others.
+ *
+ * This file is a part of XMind 3. XMind releases 3 and
+ * above are dual-licensed under the Eclipse Public License (EPL),
+ * which is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the GNU Lesser General Public License (LGPL),
+ * which is available at http://www.gnu.org/licenses/lgpl.html
+ * See https://www.xmind.net/license.html for details.
+ *
+ * Contributors:
+ * XMind Ltd. - initial API and implementation
+ *******************************************************************************/
+package org.xmind.cathy.internal.jobs;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.osgi.util.NLS;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.core.command.transfer.IncomingCommandHandler;
+
+public class OpenXMindCommandFileJob extends Job {
+
+ private static final String DEBUG_OPTION = "/debug/openXMindCommandFile"; //$NON-NLS-1$
+
+ private static boolean DEBUGGING = CathyPlugin.getDefault()
+ .isDebugging(DEBUG_OPTION);
+
+ private static class InternalOpenXMindCommandFileHandler
+ extends IncomingCommandHandler {
+
+ protected IStatus createReadingErrorStatus(Throwable e) {
+ return super.createReadingErrorStatus(e);
+ }
+
+ protected IStatus createWritingErrorStatus(Throwable e) {
+ return super.createWritingErrorStatus(e);
+ }
+
+ }
+
+ private static class NullOutputStream extends OutputStream {
+
+ public void write(int b) throws IOException {
+ // ignore all bits
+ }
+
+ public void write(byte[] b) throws IOException {
+ // ignore all bits
+ }
+
+ public void write(byte[] b, int off, int len) throws IOException {
+ // ignore all bits
+ }
+
+ }
+
+ private String commandFilePath;
+
+ public OpenXMindCommandFileJob(String commandFilePath) {
+ super(NLS.bind(WorkbenchMessages.OpenXMindCommandFileJob_name,
+ commandFilePath));
+ this.commandFilePath = commandFilePath;
+ setUser(false);
+ }
+
+ protected IStatus run(IProgressMonitor monitor) {
+ if (commandFilePath == null)
+ return new Status(IStatus.WARNING, CathyPlugin.PLUGIN_ID,
+ WorkbenchMessages.OpenXMindCommandFileJob_failed_noCommandFilePath_text);
+
+ File commandFile = new File(commandFilePath);
+ if (!commandFile.exists() || !commandFile.isFile()
+ || !commandFile.canRead())
+ return new Status(IStatus.WARNING, CathyPlugin.PLUGIN_ID,
+ NLS.bind(
+ WorkbenchMessages.OpenXMindCommandFileJob_failed_fileIsNotReadable,
+ commandFilePath));
+
+ try {
+ InputStream input = new FileInputStream(commandFile);
+ try {
+ OutputStream output = createOutputStream();
+ try {
+ IncomingCommandHandler handler = new InternalOpenXMindCommandFileHandler();
+ handler.setPluginId(CathyPlugin.PLUGIN_ID);
+ IStatus result = handler.handleIncomingCommand(monitor,
+ input, output);
+ if (DEBUGGING) {
+ logOutput(output);
+ }
+ return result;
+ } finally {
+ output.close();
+ }
+ } finally {
+ input.close();
+ }
+ } catch (IOException e) {
+ return new Status(IStatus.WARNING, CathyPlugin.PLUGIN_ID,
+ NLS.bind(
+ WorkbenchMessages.OpenXMindCommandFileJob_failed_openXMindCommandFile,
+ e.getLocalizedMessage()),
+ e);
+ }
+ }
+
+ private void logOutput(OutputStream output) {
+ if (!(output instanceof ByteArrayOutputStream))
+ return;
+ try {
+ String outputText = ((ByteArrayOutputStream) output)
+ .toString("UTF-8"); //$NON-NLS-1$
+ System.out.println("Response of XMind command file: " //$NON-NLS-1$
+ + commandFilePath);
+ System.out.println(outputText);
+ } catch (UnsupportedEncodingException e2) {
+ // Ignore encoding error
+ }
+ }
+
+ private OutputStream createOutputStream() {
+ if (DEBUGGING)
+ return new ByteArrayOutputStream(4096);
+ return new NullOutputStream();
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/messages.properties b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/messages.properties
index f2bff5c55..e6eea87ea 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/messages.properties
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/messages.properties
@@ -1,179 +1,181 @@
-AppWindowTitle=XMind
-ProWindowTitle=XMind Pro
-
-File_menu_text=&File
-Edit_menu_text=&Edit
-Help_menu_text=&Help
-SaveAction_text=&Save New Revision
-
-GeneralPrefPage_seePolicy_link=See Policy
-GeneralPrefPage_title=General
-GeneralPrefPage_usageData_text=Send usage data. (NO PRIVATE DATA\!)
-GeneralPrefPageSection_RecentFileCountSection_title=Files List
-GeneralPrefPageSection_AutoSaveGroup_title=Save & Backup
-RecentFiles_label=Size of the recently opened files list:
-RecentFileViewer_PinThisMapAction_label=Pin This Map
-RecentFileViewer_UnpinThisMap_label=Unpin This Map
-RestoreLastSession_label=Restore last session on startup
-CathyWorkbenchWindowAdvisor_menu_lockAction_text=Lock the Toolbars
-CathyWorkbenchWindowAdvisor_menu_resetAction_text=Reset
-CathyWorkbenchWindowAdvisor_windowTitle_home_prefix=Home -
-ChangeLanguage_button=&Change Now
-ChangeLanguageTo_description=Change language to:
-CheckUpdates_label=Check updates and news on startup
-AutoBackup_label=Auto backup editing files to Black Box
-AutoBackupIndicator_AutoSaveDisabled_description=Do not save opened workbooks automatically
-AutoBackupIndicator_AutoSaveDisabled_label=Auto Save: OFF
-AutoBackupIndicator_AutoSaveEnabled_label=Auto Save: ON
-AutoBackupIndicator_DisableAutoSaveAction_text=Disable Auto Save
-AutoBackupIndicator_EnableAutoSaveAction_text=Enable Auto Save
-AutoBackupIndicator_OpenPreferenceAction_text=Preference...
-AutoSave_label=Automatically save all workbooks every
-AutoSave_Minutes=minutes
-AutoSave_label2=Automatically save all opened workbooks every {0} minutes
-KeyAssist_text=&Key Assist...
-Help_text=XMind Help
-Help_toolTip=Help contents of XMind
-Update_text=Check For Updates...
-Update_toolTip=Find and Update...
-Startup_title=Startup
-StartupAction_label=When XMind starts:
-StartupAction_OpenDialog=Show templates and themes
-StartupAction_BlankMap=Open a blank map
-StartupAction_HomeMap=Open my home map
-StartupAction_LastSession=Open maps unclosed last time
-HomeMap_label=Home map:
-HomeMap_NotFound_error=Home map not found.
-
-appWindow_ListSelectionDialog_Text=XMind didn't shut down correctly. To reopen workbooks you had opened, select from the list below:
-appWindow_ListSelectionDialog_Title=Recover From Crash
-
-CheckOpenFilesJob_CheckFiles_name=Check for files to open
-CheckOpenFilesJob_OpenFiles_name=Open files
-CheckOpenFilesJob_ShowPresentation_name=Show presentation
-CheckOpenFilesJob_FailsToOpen_message=Fails to open file: {0}
-
-CheckRecoverFilesJob_jobName=Check And Recover Files
-CheckRecoverFilesJob_LoadFiles_name=Load information of files to recover
-CheckRecoverFilesJob_FilterFiles_name=Filter files to recover
-CheckRecoverFilesJob_RecoverFiles_name=Open recovered files
-
-CheckUpdatesJob_jobName=Find updates
-CheckUpdatesJob_Fail_message=Fail to find new updates of XMind. Please check your network connection and try again.
-CheckUpdatesJob_NoUpdate_message=No updates found. You are using the latest version of XMind.
-CheckUpdatesJob_NewUpdate_message=A new version of XMind is available. Download now?
-CheckUpdatesJob_NewUpdate_info_message=Version: {0}, Size: {1}
-CheckUpdatesJob_NewUpdate_moreDownloads_text=More downloads
-ConfirmDeleteTemplateDialog_message_withTemplateName=You are deleting the template ''{0}''.
-ConfirmDeleteTemplateDialog_title=XMind - Delete Template
-ConfirmToRestart_cancelButton=Cancel
-ConfirmToRestart_defaultButton=Restart
-ConfirmToRestart_description=Are you sure to change language to "{0}"? Restart to change now.
-ConfirmToRestart_title=Confirm to Restart
-ConstantsHacker_WizardHandler_menuLabel=Export {0}...
-
-StartupJob_jobName=Initializing XMind Workbench
-StartupJob_OpenBootstrapEditor_name=Open a bootstrap editor
-StartupJob_OpenBlankMap=Open a blank map
-StartupJob_OpenHomeMap=Open the home map
-StartupJob_OpenLastSession=Open maps unclosed last time
-SupportLanguageName_Arabic=Arabic
-SupportLanguageName_Danish=Danish
-SupportLanguageName_English=English
-SupportLanguageName_Spanish=Spanish
-SupportLanguageName_French=French
-SupportLanguageName_German=German
-SupportLanguageName_Italian=Italian
-SupportLanguageName_Japanese=Japanese
-SupportLanguageName_Korean=Korean
-SupportLanguageName_Portuguese_Brazilian=Portuguese(Brazilian)
-SupportLanguageName_Russian=Russian
-SupportLanguageName_SimplifiedCN=Simplified Chinese
-SupportLanguageName_Slovenian=Slovenian
-SupportLanguageName_TraditionalCN=Traditional Chinese
-
-PromptSaveEditorOnClosing_message=''{0}'' has unsaved changes. Save it before closing?
-
-About_LicensedTo=Licensed to {0}\n
-About_ProTitle={0} Pro
-About_PlusTitle={0} Plus
-About_ProSubscriptionTitle=\ Pro Subscription
-About_LicenseTypePattern=Activated as XMind{0}.\n
-About_LicenseType_Unactivated=Unactivated.\n
-
-DownloadAndOpenFileJob_jobName=Download And Open File
-DownloadAndOpenFileJob_Task_Download_with_url=Downloading from {0}
-DownloadAndOpenFileJob_Task_OpenDownloadedFile_with_url=Opening file donwloaded from {0}
-DownloadAndOpenFileJob_Error_FailedToCreateTempFile=Failed to make temporary location to receive downloaded file.
-DownloadAndOpenFileJob_Error_FailedToLoadWorkbook_with_url=Failed to load workbook from url: {0}
-DownloadAndOpenFileJob_DownloadJob_jobName=Download File
-OpenXMindCommandFileJob_failed_fileIsNotReadable=Failed to open XMind command file: File is not readable: {0}
-OpenXMindCommandFileJob_failed_noCommandFilePath_text=Failed to open XMind command file: No command file path specified.
-OpenXMindCommandFileJob_failed_openXMindCommandFile=Failed to open XMind command file: {0}
-OpenXMindCommandFileJob_name=Opening command file: {0}
-WelcomeDialog_item_slide_title=Slide-based Story
-WelcomeDialog_item_slide_description=Create slideshows from mind maps
-WelcomeDialog_item_cloud_title=XMind Cloud
-WelcomeDialog_item_cloud_description=Create folders and sort files in Cloud
-WelcomeDialog_item_high_dpi_title=High DPI Support
-WelcomeDialog_item_high_dpi_description=Better experience on high resolution screens
-WelcomeDialog_item_workspace_description=New design for more efficient map editing
-WelcomeDialog_item_workspace_title=New Workspace
-WelcomeDialog_okButton_text=OK
-WelcomeDialog_seePolicy_link=See Policy
-WelcomeDialog_uploadDataCheck_text=Send usage data. (NO PRIVATE DATA\!)
-WelcomDialog_Welcom_title=Welcome to XMind 8
-WelcomDialog_WhatIsNew_title=What's new?
-WelcomeToXMindHandler_welcomeToXMind_templatedName=Welcome to XMind
-WizardHandler_menuLabel=
-
-
-BetaVerifier_BetaExpiredPromptDialog_windowTitle=XMind Beta Expired
-BetaVerifier_BetaExpiredPromptDialog_message_withBrandingVersion_andBuildId=XMind{0} (v{1}) Beta Edition has expired. You can check and install the latest release now, or visit www.xmind.net and download by your self. Thank you for your trial.
-BetaVerifier_BetaExpiredPromptDialog_CheckAndInstallButton_text=&Check and Install
-BetaVerifier_BetaExpiredPromptDialog_ExitButton_text=&Exit
-BetaVerifier_BetaExpiredPromptDialog_DownloadFailure_message=Oops! An error occurred. Please try again later, or visit www.xmind.net and download the latest release manually.
-
-
-About_Copyright=Copyright (C) 2006 - 2016, XMind Ltd. All rights reserved.
-About_Homepage=http://www.xmind.net/
-About_BetaExpiryMessage_withExpiryTime=This beta edition will expire at {0}.\n
-
-LanguagePrefPage_ConfirmToRestart_laterButton=Restart Later
-LanguagePrefPage_ConfirmToRestart2_defaultButton=Restart Now
-LanguagePrefPage_ConfirmToRestart2_description=You need to restart XMind to change the language. Do you want to restart now?
-LanguagePrefPage_title=Language
-
-DashboardHideHome_tooltip=Hide Home
-DashboardShowHome_tooltip=Show Home
-
-DashboardBlankPage_name=Blank
-DashboardTemplatesPage_name=Templates
-DashboardBlankPage_message=Choose a Type
-DashboardTemplatesPage_message=Choose a Template
-
-DashboardRecentFiles_message=Recent
-
-DashboardThemeChoose_message=Choose a Theme
-DashboardThemeCreate_label=Create
-NewFileDashboardPage_AddTemplates_tooltip=Add Template...
-NewFileDashboardPage_AddTemplates_label=Add
-NewFileDashboardPage_DeleteTemplate_tooltip=Delete Template
-NewFileDashboardPage_DeleteTemplate_label=Delete
-NewFileDashboardPage_ExitEditMode_tooltip=Exit Templates Management Mode
-NewFileDashboardPage_ExitEditTemplatesMode_label=Done
-NewFileDashboardPage_GoIntoTemplatesManagerMode_tooltip=Manage Templates
-NewFileDashboardPage_GoToEditTemplateMode_label=Manage
-NewFileDashboardPage_leftTitleBar_text=New
-NewFileDashboardPage_TemplateFilterName_label=XMind Template
-NewFileDashboardPage_Import_button=Import
-
-TemplateViewer_SystemGroup_title=Build-in
-TemplateViewer_UserGroup_title=User
-
-RecentFileBlankPage_description=Recent files will appear as icons here.
-
-RecentFilesLabelProvider_Cloud_text=[Cloud]
-
-XStackRenderer_TopArea_tipLabel=Please open a map to continue the Operation.
-XStackRenderer_BottomArea_Add_button=New Blank Map
+AppWindowTitle=XMind
+ProWindowTitle=XMind Pro
+
+File_menu_text=&File
+Edit_menu_text=&Edit
+Help_menu_text=&Help
+SaveAction_text=&Save New Revision
+
+GeneralPrefPage_seePolicy_link=See Policy
+GeneralPrefPage_title=General
+GeneralPrefPage_usageData_text=Send usage data. (NO PRIVATE DATA\!)
+GeneralPrefPageSection_RecentFileCountSection_title=Files List
+GeneralPrefPageSection_AutoSaveGroup_title=Save & Backup
+RecentFiles_label=Size of the recently opened files list:
+RecentFileViewer_PinThisMapAction_label=Pin This Map
+RecentFileViewer_UnpinThisMap_label=Unpin This Map
+RestoreLastSession_label=Restore last session on startup
+CategorizedTemplateViewer_group_untitiledName=Untitled
+CategorizedTemplateViewer_template_untitiledName=Untitled
+CathyWorkbenchWindowAdvisor_menu_lockAction_text=Lock the Toolbars
+CathyWorkbenchWindowAdvisor_menu_resetAction_text=Reset
+CathyWorkbenchWindowAdvisor_windowTitle_home_prefix=Home -
+ChangeLanguage_button=&Change Now
+ChangeLanguageTo_description=Change language to:
+CheckUpdates_label=Check updates and news on startup
+AutoBackup_label=Auto backup editing files to Black Box
+AutoBackupIndicator_AutoSaveDisabled_description=Do not save opened workbooks automatically
+AutoBackupIndicator_AutoSaveDisabled_label=Auto Save: OFF
+AutoBackupIndicator_AutoSaveEnabled_label=Auto Save: ON
+AutoBackupIndicator_DisableAutoSaveAction_text=Disable Auto Save
+AutoBackupIndicator_EnableAutoSaveAction_text=Enable Auto Save
+AutoBackupIndicator_OpenPreferenceAction_text=Preference...
+AutoSave_label=Automatically save all workbooks every
+AutoSave_Minutes=minutes
+AutoSave_label2=Automatically save all opened workbooks every {0} minutes
+KeyAssist_text=&Key Assist...
+Help_text=XMind Help
+Help_toolTip=Help contents of XMind
+Update_text=Check For Updates...
+Update_toolTip=Find and Update...
+Startup_title=Startup
+StartupAction_label=When XMind starts:
+StartupAction_OpenDialog=Show templates and themes
+StartupAction_BlankMap=Open a blank map
+StartupAction_HomeMap=Open my home map
+StartupAction_LastSession=Open maps unclosed last time
+HomeMap_label=Home map:
+HomeMap_NotFound_error=Home map not found.
+
+appWindow_ListSelectionDialog_Text=XMind didn't shut down correctly. To reopen workbooks you had opened, select from the list below:
+appWindow_ListSelectionDialog_Title=Recover From Crash
+
+CheckOpenFilesJob_CheckFiles_name=Check for files to open
+CheckOpenFilesJob_OpenFiles_name=Open files
+CheckOpenFilesJob_ShowPresentation_name=Show presentation
+CheckOpenFilesJob_FailsToOpen_message=Fails to open file: {0}
+
+CheckRecoverFilesJob_jobName=Check And Recover Files
+CheckRecoverFilesJob_LoadFiles_name=Load information of files to recover
+CheckRecoverFilesJob_FilterFiles_name=Filter files to recover
+CheckRecoverFilesJob_RecoverFiles_name=Open recovered files
+
+CheckUpdatesJob_jobName=Find updates
+CheckUpdatesJob_Fail_message=Fail to find new updates of XMind. Please check your network connection and try again.
+CheckUpdatesJob_NoUpdate_message=No updates found. You are using the latest version of XMind.
+CheckUpdatesJob_NewUpdate_message=A new version of XMind is available. Download now?
+CheckUpdatesJob_NewUpdate_info_message=Version: {0}, Size: {1}
+CheckUpdatesJob_NewUpdate_moreDownloads_text=More downloads
+ConfirmDeleteTemplateDialog_message_withTemplateName=You are deleting the template ''{0}''.
+ConfirmDeleteTemplateDialog_title=XMind - Delete Template
+ConfirmToRestart_cancelButton=Cancel
+ConfirmToRestart_defaultButton=Restart
+ConfirmToRestart_description=Are you sure to change language to "{0}"? Restart to change now.
+ConfirmToRestart_title=Confirm to Restart
+ConstantsHacker_WizardHandler_menuLabel=Export {0}...
+
+StartupJob_jobName=Initializing XMind Workbench
+StartupJob_OpenBootstrapEditor_name=Open a bootstrap editor
+StartupJob_OpenBlankMap=Open a blank map
+StartupJob_OpenHomeMap=Open the home map
+StartupJob_OpenLastSession=Open maps unclosed last time
+SupportLanguageName_Arabic=Arabic
+SupportLanguageName_Danish=Danish
+SupportLanguageName_English=English
+SupportLanguageName_Spanish=Spanish
+SupportLanguageName_French=French
+SupportLanguageName_German=German
+SupportLanguageName_Italian=Italian
+SupportLanguageName_Japanese=Japanese
+SupportLanguageName_Korean=Korean
+SupportLanguageName_Portuguese_Brazilian=Portuguese(Brazilian)
+SupportLanguageName_Russian=Russian
+SupportLanguageName_SimplifiedCN=Simplified Chinese
+SupportLanguageName_Slovenian=Slovenian
+SupportLanguageName_TraditionalCN=Traditional Chinese
+
+PromptSaveEditorOnClosing_message=''{0}'' has unsaved changes. Save it before closing?
+
+About_LicensedTo=Licensed to {0}\n
+About_ProTitle={0} Pro
+About_PlusTitle={0} Plus
+About_ProSubscriptionTitle=\ Pro Subscription
+About_LicenseTypePattern=Activated as XMind{0}.\n
+About_LicenseType_Unactivated=Unactivated.\n
+
+DownloadAndOpenFileJob_jobName=Download And Open File
+DownloadAndOpenFileJob_Task_Download_with_url=Downloading from {0}
+DownloadAndOpenFileJob_Task_OpenDownloadedFile_with_url=Opening file donwloaded from {0}
+DownloadAndOpenFileJob_Error_FailedToCreateTempFile=Failed to make temporary location to receive downloaded file.
+DownloadAndOpenFileJob_Error_FailedToLoadWorkbook_with_url=Failed to load workbook from url: {0}
+DownloadAndOpenFileJob_DownloadJob_jobName=Download File
+OpenXMindCommandFileJob_failed_fileIsNotReadable=Failed to open XMind command file: File is not readable: {0}
+OpenXMindCommandFileJob_failed_noCommandFilePath_text=Failed to open XMind command file: No command file path specified.
+OpenXMindCommandFileJob_failed_openXMindCommandFile=Failed to open XMind command file: {0}
+OpenXMindCommandFileJob_name=Opening command file: {0}
+WelcomeDialog_item_slide_title=Slide-based Story
+WelcomeDialog_item_slide_description=Create slideshows from mind maps
+WelcomeDialog_item_cloud_title=XMind Cloud
+WelcomeDialog_item_cloud_description=Create folders and sort files in Cloud
+WelcomeDialog_item_high_dpi_title=High DPI Support
+WelcomeDialog_item_high_dpi_description=Better experience on high resolution screens
+WelcomeDialog_item_workspace_description=New design for more efficient map editing
+WelcomeDialog_item_workspace_title=New Workspace
+WelcomeDialog_okButton_text=OK
+WelcomeDialog_seePolicy_link=See Policy
+WelcomeDialog_uploadDataCheck_text=Send usage data. (NO PRIVATE DATA\!)
+WelcomDialog_Welcom_title=Welcome to XMind 8
+WelcomDialog_WhatIsNew_title=What's new?
+WelcomeToXMindHandler_welcomeToXMind_templatedName=Welcome to XMind
+WizardHandler_menuLabel=
+
+
+BetaVerifier_BetaExpiredPromptDialog_windowTitle=XMind Beta Expired
+BetaVerifier_BetaExpiredPromptDialog_message_withBrandingVersion_andBuildId=XMind{0} (v{1}) Beta Edition has expired. You can check and install the latest release now, or visit www.xmind.net and download by your self. Thank you for your trial.
+BetaVerifier_BetaExpiredPromptDialog_CheckAndInstallButton_text=&Check and Install
+BetaVerifier_BetaExpiredPromptDialog_ExitButton_text=&Exit
+BetaVerifier_BetaExpiredPromptDialog_DownloadFailure_message=Oops! An error occurred. Please try again later, or visit www.xmind.net and download the latest release manually.
+
+
+About_Copyright=Copyright (C) 2006 - 2019, XMind Ltd. All rights reserved.
+About_Homepage=https://www.xmind.net/
+About_BetaExpiryMessage_withExpiryTime=This beta edition will expire at {0}.\n
+
+LanguagePrefPage_ConfirmToRestart_laterButton=Restart Later
+LanguagePrefPage_ConfirmToRestart2_defaultButton=Restart Now
+LanguagePrefPage_ConfirmToRestart2_description=You need to restart XMind to change the language. Do you want to restart now?
+LanguagePrefPage_title=Language
+
+DashboardHideHome_tooltip=Hide Home
+DashboardShowHome_tooltip=Show Home
+
+DashboardBlankPage_name=Blank
+DashboardTemplatesPage_name=Templates
+DashboardBlankPage_message=Choose a Type
+DashboardTemplatesPage_message=Choose a Template
+
+DashboardRecentFiles_message=Recent
+
+DashboardThemeChoose_message=Choose a Theme
+DashboardThemeCreate_label=Create
+NewFileDashboardPage_AddTemplates_tooltip=Add Template...
+NewFileDashboardPage_AddTemplates_label=Add
+NewFileDashboardPage_DeleteTemplate_tooltip=Delete Template
+NewFileDashboardPage_DeleteTemplate_label=Delete
+NewFileDashboardPage_ExitEditMode_tooltip=Exit Templates Management Mode
+NewFileDashboardPage_ExitEditTemplatesMode_label=Done
+NewFileDashboardPage_GoIntoTemplatesManagerMode_tooltip=Manage Templates
+NewFileDashboardPage_GoToEditTemplateMode_label=Manage
+NewFileDashboardPage_leftTitleBar_text=New
+NewFileDashboardPage_TemplateFilterName_label=XMind Template
+NewFileDashboardPage_Import_button=Import
+
+TemplateViewer_SystemGroup_title=Build-in
+TemplateViewer_UserGroup_title=User
+
+RecentFileBlankPage_description=Recent files will appear as icons here.
+
+RecentFilesLabelProvider_Cloud_text=[Cloud]
+
+XStackRenderer_TopArea_tipLabel=Please open a map to continue the Operation.
+XStackRenderer_BottomArea_Add_button=New Blank Map
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XDialogRenderer.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XDialogRenderer.java
index 0536e8188..149a8fee9 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XDialogRenderer.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XDialogRenderer.java
@@ -1,463 +1,463 @@
-package org.xmind.cathy.internal.renderer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.di.annotations.Optional;
-import org.eclipse.e4.ui.di.UIEventTopic;
-import org.eclipse.e4.ui.internal.workbench.E4Workbench;
-import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.ui.MElementContainer;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.basic.MDialog;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
-import org.eclipse.e4.ui.model.application.ui.basic.MWindowElement;
-import org.eclipse.e4.ui.workbench.IPresentationEngine;
-import org.eclipse.e4.ui.workbench.UIEvents;
-import org.eclipse.e4.ui.workbench.UIEvents.ElementContainer;
-import org.eclipse.e4.ui.workbench.modeling.EPartService;
-import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler;
-import org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer;
-import org.eclipse.jface.util.Geometry;
-import org.eclipse.jface.window.IShellProvider;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Monitor;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Widget;
-import org.osgi.service.event.Event;
-import org.xmind.ui.internal.e4models.IModelConstants;
-
-public class XDialogRenderer extends SWTPartRenderer {
-
- private class WindowSizeUpdateJob implements Runnable {
- public List windowsToUpdate = new ArrayList();
-
- public void run() {
- boundsJob = null;
- while (!windowsToUpdate.isEmpty()) {
- MWindow window = windowsToUpdate.remove(0);
- Shell shell = (Shell) window.getWidget();
- if (shell == null || shell.isDisposed())
- continue;
- shell.setBounds(window.getX(), window.getY(), window.getWidth(),
- window.getHeight());
- }
- }
- }
-
- WindowSizeUpdateJob boundsJob;
-
- @Inject
- private IEclipseContext context;
-
- @Inject
- private Display display;
-
- @Inject
- private MApplication application;
-
- @Inject
- @Optional
- @Named("localActiveShell")
- private Shell parentShell;
-
- @SuppressWarnings("unchecked")
- @Inject
- @Optional
- private void subscribeTopicChildAdded(
- @UIEventTopic(ElementContainer.TOPIC_CHILDREN) Event event) {
- Object changedObject = event.getProperty(UIEvents.EventTags.ELEMENT);
- if (!(changedObject instanceof MDialog)) {
- return;
- }
- if (UIEvents.isADD(event)) {
- processContents((MElementContainer) changedObject);
- postProcess((MDialog) changedObject);
- }
- }
-
- @Inject
- @Optional
- private void subscribeTopicWindowChanged(
- @UIEventTopic(UIEvents.Window.TOPIC_ALL) Event event) {
- Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT);
- if (!(objElement instanceof MDialog)) {
- return;
- }
-
- // Is this listener interested ?
- MDialog dialogModel = (MDialog) objElement;
- if (dialogModel.getRenderer() != XDialogRenderer.this) {
- return;
- }
-
- // No widget == nothing to update
- Shell theShell = (Shell) dialogModel.getWidget();
- if (theShell == null) {
- return;
- }
-
- String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
-
- if (UIEvents.Window.X.equals(attName)
- || UIEvents.Window.Y.equals(attName)
- || UIEvents.Window.WIDTH.equals(attName)
- || UIEvents.Window.HEIGHT.equals(attName)) {
- if (boundsJob == null) {
- boundsJob = new WindowSizeUpdateJob();
- boundsJob.windowsToUpdate.add(dialogModel);
- theShell.getDisplay().asyncExec(boundsJob);
- } else {
- if (!boundsJob.windowsToUpdate.contains(dialogModel))
- boundsJob.windowsToUpdate.add(dialogModel);
- }
- }
- }
-
- @Override
- public Object createWidget(MUIElement element, Object parent) {
- final Widget newWidget;
-
- if (!(element instanceof MDialog)
- || (parent != null && !(parent instanceof Control)))
- return null;
-
- MDialog dialogModel = (MDialog) element;
-
- MApplication appModel = dialogModel.getContext()
- .get(MApplication.class);
- Boolean rtlMode = (Boolean) appModel.getTransientData()
- .get(E4Workbench.RTL_MODE);
- int rtlStyle = (rtlMode != null && rtlMode.booleanValue())
- ? SWT.RIGHT_TO_LEFT : 0;
-
- Shell parentShell = parent == null ? null
- : ((Control) parent).getShell();
-
- final Shell wbwShell;
-
- int styleOverride = getStyleOverride(dialogModel) | rtlStyle;
- if (parentShell == null) {
- int style = styleOverride == -1 ? SWT.SHELL_TRIM | rtlStyle
- : styleOverride;
- wbwShell = new Shell(display, style);
- dialogModel.getTags().add("topLevel"); //$NON-NLS-1$
- } else {
- int style = SWT.TITLE | SWT.RESIZE | SWT.MAX | SWT.CLOSE | rtlStyle;
- style = styleOverride == -1 ? style : styleOverride;
- if (dialogModel.getTags()
- .contains(IPresentationEngine.WINDOW_TOP_LEVEL))
- wbwShell = new Shell(display, style);
- else
- wbwShell = new Shell(parentShell, style);
- }
-
- wbwShell.setBackgroundMode(SWT.INHERIT_DEFAULT);
-
- Rectangle modelBounds = wbwShell.getBounds();
- modelBounds.x = dialogModel.getX();
- modelBounds.y = dialogModel.getY();
- modelBounds.height = dialogModel.getHeight();
- modelBounds.width = dialogModel.getWidth();
-
- // Force the shell onto the display if it would be invisible otherwise
- Rectangle displayBounds = Display.getCurrent().getPrimaryMonitor()
- .getBounds();
- if (!modelBounds.intersects(displayBounds)) {
- Rectangle clientArea = Display.getCurrent().getPrimaryMonitor()
- .getClientArea();
- modelBounds.x = clientArea.x;
- modelBounds.y = clientArea.y;
- }
- wbwShell.setBounds(modelBounds);
-
- setCSSInfo(dialogModel, wbwShell);
-
- wbwShell.setLayout(new FillLayout(SWT.VERTICAL));
- newWidget = wbwShell;
- bindWidget(element, newWidget);
-
- // set up context
- IEclipseContext localContext = getContext(dialogModel);
- localContext.set(Shell.class, wbwShell);
- localContext.set(E4Workbench.LOCAL_ACTIVE_SHELL, wbwShell);
- localContext.set(IShellProvider.class, new IShellProvider() {
- public Shell getShell() {
- return wbwShell;
- }
- });
- localContext.set(IWindowCloseHandler.class, new IWindowCloseHandler() {
- public boolean close(MWindow window) {
- return closeDetachedWindow(window);
- }
- });
-
- if (dialogModel.getLabel() != null)
- wbwShell.setText(dialogModel.getLocalizedLabel());
-
- if (dialogModel.getIconURI() != null
- && dialogModel.getIconURI().length() > 0) {
- wbwShell.setImage(getImage(dialogModel));
- } else {
- wbwShell.setImages(Window.getDefaultImages());
- }
-
- return newWidget;
- }
-
- private boolean closeDetachedWindow(MWindow window) {
- EPartService partService = window.getContext().get(EPartService.class);
- List parts = modelService.findElements(window, null, MPart.class,
- null);
- // this saves one part at a time, not ideal but better than not saving
- // at all
- for (MPart part : parts) {
- if (!partService.savePart(part, true)) {
- // user cancelled the operation, return false
- return false;
- }
- }
-
- // hide every part individually, following 3.x behaviour
- for (MPart part : parts) {
- partService.hidePart(part);
- }
- return true;
- }
-
- @Override
- public void hookControllerLogic(final MUIElement me) {
- super.hookControllerLogic(me);
- Widget widget = (Widget) me.getWidget();
-
- if (widget instanceof Shell && me instanceof MWindow) {
- final Shell shell = (Shell) widget;
- shell.addDisposeListener(new DisposeListener() {
-
- public void widgetDisposed(DisposeEvent e) {
- //Save user dialog bounds
- String splitSymbol = ","; //$NON-NLS-1$
- Rectangle bounds = shell.getBounds();
- String location = bounds.x + splitSymbol + bounds.y
- + splitSymbol + bounds.width + splitSymbol
- + bounds.height;
- me.getPersistedState().put(
- IModelConstants.KEY_DIALOG_PART_CUSTOM_LOCATION,
- location);
-
- MWindow window = (MWindow) me;
- IWindowCloseHandler closeHandler = window.getContext()
- .get(IWindowCloseHandler.class);
- // if there's no handler or the handler permits the close
- // request, clean-up as necessary
- if (closeHandler == null || closeHandler.close(window)) {
- Object parentModel = shell.getParent()
- .getData(OWNING_ME);
- if (parentModel instanceof MWindow) {
- List children = ((MWindow) parentModel)
- .getChildren();
- if (children.contains(window)) {
- children.remove(window);
- }
- } else {
- MWindow trimmedWindow = application.getChildren()
- .get(0);
- List windows = trimmedWindow.getWindows();
- if (windows.contains(window)) {
- windows.remove(window);
- }
- }
- }
- }
- });
- }
- }
-
- @Override
- public void processContents(MElementContainer me) {
- if (!(((MUIElement) me) instanceof MDialog))
- return;
- MDialog wbwModel = (MDialog) ((MUIElement) me);
- super.processContents(me);
-
- // Populate the main menu
- IPresentationEngine renderer = context.get(IPresentationEngine.class);
- if (wbwModel.getMainMenu() != null) {
- renderer.createGui(wbwModel.getMainMenu(), me.getWidget(), null);
- Shell shell = (Shell) me.getWidget();
- shell.setMenuBar((Menu) wbwModel.getMainMenu().getWidget());
- }
-
- // create Detached Windows
- for (MWindow dw : wbwModel.getWindows()) {
- renderer.createGui(dw, me.getWidget(), wbwModel.getContext());
- }
- }
-
- @Override
- public void postProcess(MUIElement shellME) {
- if (!(shellME instanceof MDialog))
- return;
- MDialog dialogModel = (MDialog) shellME;
- super.postProcess(shellME);
-
- Shell shell = (Shell) shellME.getWidget();
- String location = shellME.getPersistedState()
- .get(IModelConstants.KEY_DIALOG_PART_CUSTOM_LOCATION);
- location = location == null ? "" : location; //$NON-NLS-1$
- String[] locations = location.split(","); //$NON-NLS-1$
-
- if (locations.length < 4) {
- String[] tempLocations = new String[4];
- for (int i = 0; i < locations.length; i++)
- tempLocations[i] = locations[i];
- locations = tempLocations;
- }
-
- Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
- if (isNone(locations[2])) {
- locations[2] = String.valueOf(size.x);
- }
- if (isNone(locations[3])) {
- locations[3] = String.valueOf(size.y);
- }
- size = new Point(Integer.valueOf(locations[2]),
- Integer.valueOf(locations[3]));
- Point initLocation = getInitialLocation(shell, size);
- Rectangle bounds = getConstrainedShellBounds(shell,
- new Rectangle(initLocation.x, initLocation.y, size.x, size.y));
- if (isNone(locations[0]) && isNone(locations[1])) {
- locations[0] = String.valueOf(bounds.x);
- locations[1] = String.valueOf(bounds.y);
- }
-
- dialogModel.setX(Integer.valueOf(locations[0]));
- dialogModel.setY(Integer.valueOf(locations[1]));
- dialogModel.setWidth(Integer.valueOf(locations[2]));
- dialogModel.setHeight(Integer.valueOf(locations[3]));
-
- StringBuffer sb = new StringBuffer();
- sb.append(locations[0]);
- sb.append(","); //$NON-NLS-1$
- sb.append(locations[1]);
- sb.append(","); //$NON-NLS-1$
- sb.append(locations[2]);
- sb.append(","); //$NON-NLS-1$
- sb.append(locations[3]);
-
- dialogModel.getPersistedState().put(
- IModelConstants.KEY_DIALOG_PART_CUSTOM_LOCATION, sb.toString());
-
- shell.layout(true);
- forceLayout(shell);
- if (shellME.isVisible()) {
- shell.open();
- } else {
- shell.setVisible(false);
- }
- }
-
- private boolean isNone(String value) {
- return value == null || "".equals(value); //$NON-NLS-1$
- }
-
- private Point getInitialLocation(Shell shell, Point initialSize) {
- Composite parent = shell.getParent();
-
- Monitor monitor = shell.getDisplay().getPrimaryMonitor();
- if (parent != null) {
- monitor = parent.getMonitor();
- }
-
- Rectangle monitorBounds = monitor.getClientArea();
- Point centerPoint;
- if (parent != null) {
- centerPoint = Geometry.centerPoint(parent.getBounds());
- } else {
- centerPoint = Geometry.centerPoint(monitorBounds);
- }
-
- return new Point(centerPoint.x - (initialSize.x / 2),
- centerPoint.y - (initialSize.y / 2));
- }
-
- protected Rectangle getConstrainedShellBounds(Shell shell,
- Rectangle preferredSize) {
- Rectangle result = new Rectangle(preferredSize.x, preferredSize.y,
- preferredSize.width, preferredSize.height);
-
- Monitor mon = getClosestMonitor(shell.getDisplay(),
- Geometry.centerPoint(result));
-
- Rectangle bounds = mon.getClientArea();
-
- if (result.height > bounds.height) {
- result.height = bounds.height;
- }
-
- if (result.width > bounds.width) {
- result.width = bounds.width;
- }
-
- result.x = Math.max(bounds.x,
- Math.min(result.x, bounds.x + bounds.width - result.width));
- result.y = Math.max(bounds.y,
- Math.min(result.y, bounds.y + bounds.height - result.height));
-
- return result;
- }
-
- private static Monitor getClosestMonitor(Display toSearch, Point toFind) {
- int closest = Integer.MAX_VALUE;
-
- Monitor[] monitors = toSearch.getMonitors();
- Monitor result = monitors[0];
-
- for (int idx = 0; idx < monitors.length; idx++) {
- Monitor current = monitors[idx];
-
- Rectangle clientArea = current.getClientArea();
-
- if (clientArea.contains(toFind)) {
- return current;
- }
-
- int distance = Geometry
- .distanceSquared(Geometry.centerPoint(clientArea), toFind);
- if (distance < closest) {
- closest = distance;
- result = current;
- }
- }
-
- return result;
- }
-
- private void forceLayout(Shell shell) {
- int i = 0;
- while (shell.isLayoutDeferred()) {
- shell.setLayoutDeferred(false);
- i++;
- }
- while (i > 0) {
- shell.setLayoutDeferred(true);
- i--;
- }
- }
-
-}
+package org.xmind.cathy.internal.renderer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.di.UIEventTopic;
+import org.eclipse.e4.ui.internal.workbench.E4Workbench;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.MElementContainer;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.model.application.ui.basic.MDialog;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindowElement;
+import org.eclipse.e4.ui.workbench.IPresentationEngine;
+import org.eclipse.e4.ui.workbench.UIEvents;
+import org.eclipse.e4.ui.workbench.UIEvents.ElementContainer;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler;
+import org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer;
+import org.eclipse.jface.util.Geometry;
+import org.eclipse.jface.window.IShellProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Monitor;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+import org.osgi.service.event.Event;
+import org.xmind.ui.internal.e4models.IModelConstants;
+
+public class XDialogRenderer extends SWTPartRenderer {
+
+ private class WindowSizeUpdateJob implements Runnable {
+ public List windowsToUpdate = new ArrayList();
+
+ public void run() {
+ boundsJob = null;
+ while (!windowsToUpdate.isEmpty()) {
+ MWindow window = windowsToUpdate.remove(0);
+ Shell shell = (Shell) window.getWidget();
+ if (shell == null || shell.isDisposed())
+ continue;
+ shell.setBounds(window.getX(), window.getY(), window.getWidth(),
+ window.getHeight());
+ }
+ }
+ }
+
+ WindowSizeUpdateJob boundsJob;
+
+ @Inject
+ private IEclipseContext context;
+
+ @Inject
+ private Display display;
+
+ @Inject
+ private MApplication application;
+
+ @Inject
+ @Optional
+ @Named("localActiveShell")
+ private Shell parentShell;
+
+ @SuppressWarnings("unchecked")
+ @Inject
+ @Optional
+ private void subscribeTopicChildAdded(
+ @UIEventTopic(ElementContainer.TOPIC_CHILDREN) Event event) {
+ Object changedObject = event.getProperty(UIEvents.EventTags.ELEMENT);
+ if (!(changedObject instanceof MDialog)) {
+ return;
+ }
+ if (UIEvents.isADD(event)) {
+ processContents((MElementContainer) changedObject);
+ postProcess((MDialog) changedObject);
+ }
+ }
+
+ @Inject
+ @Optional
+ private void subscribeTopicWindowChanged(
+ @UIEventTopic(UIEvents.Window.TOPIC_ALL) Event event) {
+ Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT);
+ if (!(objElement instanceof MDialog)) {
+ return;
+ }
+
+ // Is this listener interested ?
+ MDialog dialogModel = (MDialog) objElement;
+ if (dialogModel.getRenderer() != XDialogRenderer.this) {
+ return;
+ }
+
+ // No widget == nothing to update
+ Shell theShell = (Shell) dialogModel.getWidget();
+ if (theShell == null) {
+ return;
+ }
+
+ String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
+
+ if (UIEvents.Window.X.equals(attName)
+ || UIEvents.Window.Y.equals(attName)
+ || UIEvents.Window.WIDTH.equals(attName)
+ || UIEvents.Window.HEIGHT.equals(attName)) {
+ if (boundsJob == null) {
+ boundsJob = new WindowSizeUpdateJob();
+ boundsJob.windowsToUpdate.add(dialogModel);
+ theShell.getDisplay().asyncExec(boundsJob);
+ } else {
+ if (!boundsJob.windowsToUpdate.contains(dialogModel))
+ boundsJob.windowsToUpdate.add(dialogModel);
+ }
+ }
+ }
+
+ @Override
+ public Object createWidget(MUIElement element, Object parent) {
+ final Widget newWidget;
+
+ if (!(element instanceof MDialog)
+ || (parent != null && !(parent instanceof Control)))
+ return null;
+
+ MDialog dialogModel = (MDialog) element;
+
+ MApplication appModel = dialogModel.getContext()
+ .get(MApplication.class);
+ Boolean rtlMode = (Boolean) appModel.getTransientData()
+ .get(E4Workbench.RTL_MODE);
+ int rtlStyle = (rtlMode != null && rtlMode.booleanValue())
+ ? SWT.RIGHT_TO_LEFT : 0;
+
+ Shell parentShell = parent == null ? null
+ : ((Control) parent).getShell();
+
+ final Shell wbwShell;
+
+ int styleOverride = getStyleOverride(dialogModel) | rtlStyle;
+ if (parentShell == null) {
+ int style = styleOverride == -1 ? SWT.SHELL_TRIM | rtlStyle
+ : styleOverride;
+ wbwShell = new Shell(display, style);
+ dialogModel.getTags().add("topLevel"); //$NON-NLS-1$
+ } else {
+ int style = SWT.TITLE | SWT.RESIZE | SWT.MAX | SWT.CLOSE | rtlStyle;
+ style = styleOverride == -1 ? style : styleOverride;
+ if (dialogModel.getTags()
+ .contains(IPresentationEngine.WINDOW_TOP_LEVEL))
+ wbwShell = new Shell(display, style);
+ else
+ wbwShell = new Shell(parentShell, style);
+ }
+
+ wbwShell.setBackgroundMode(SWT.INHERIT_DEFAULT);
+
+ Rectangle modelBounds = wbwShell.getBounds();
+ modelBounds.x = dialogModel.getX();
+ modelBounds.y = dialogModel.getY();
+ modelBounds.height = dialogModel.getHeight();
+ modelBounds.width = dialogModel.getWidth();
+
+ // Force the shell onto the display if it would be invisible otherwise
+ Rectangle displayBounds = Display.getCurrent().getPrimaryMonitor()
+ .getBounds();
+ if (!modelBounds.intersects(displayBounds)) {
+ Rectangle clientArea = Display.getCurrent().getPrimaryMonitor()
+ .getClientArea();
+ modelBounds.x = clientArea.x;
+ modelBounds.y = clientArea.y;
+ }
+ wbwShell.setBounds(modelBounds);
+
+ setCSSInfo(dialogModel, wbwShell);
+
+ wbwShell.setLayout(new FillLayout(SWT.VERTICAL));
+ newWidget = wbwShell;
+ bindWidget(element, newWidget);
+
+ // set up context
+ IEclipseContext localContext = getContext(dialogModel);
+ localContext.set(Shell.class, wbwShell);
+ localContext.set(E4Workbench.LOCAL_ACTIVE_SHELL, wbwShell);
+ localContext.set(IShellProvider.class, new IShellProvider() {
+ public Shell getShell() {
+ return wbwShell;
+ }
+ });
+ localContext.set(IWindowCloseHandler.class, new IWindowCloseHandler() {
+ public boolean close(MWindow window) {
+ return closeDetachedWindow(window);
+ }
+ });
+
+ if (dialogModel.getLabel() != null)
+ wbwShell.setText(dialogModel.getLocalizedLabel());
+
+ if (dialogModel.getIconURI() != null
+ && dialogModel.getIconURI().length() > 0) {
+ wbwShell.setImage(getImage(dialogModel));
+ } else {
+ wbwShell.setImages(Window.getDefaultImages());
+ }
+
+ return newWidget;
+ }
+
+ private boolean closeDetachedWindow(MWindow window) {
+ EPartService partService = window.getContext().get(EPartService.class);
+ List parts = modelService.findElements(window, null, MPart.class,
+ null);
+ // this saves one part at a time, not ideal but better than not saving
+ // at all
+ for (MPart part : parts) {
+ if (!partService.savePart(part, true)) {
+ // user cancelled the operation, return false
+ return false;
+ }
+ }
+
+ // hide every part individually, following 3.x behaviour
+ for (MPart part : parts) {
+ partService.hidePart(part);
+ }
+ return true;
+ }
+
+ @Override
+ public void hookControllerLogic(final MUIElement me) {
+ super.hookControllerLogic(me);
+ Widget widget = (Widget) me.getWidget();
+
+ if (widget instanceof Shell && me instanceof MWindow) {
+ final Shell shell = (Shell) widget;
+ shell.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ //Save user dialog bounds
+ String splitSymbol = ","; //$NON-NLS-1$
+ Rectangle bounds = shell.getBounds();
+ String location = bounds.x + splitSymbol + bounds.y
+ + splitSymbol + bounds.width + splitSymbol
+ + bounds.height;
+ me.getPersistedState().put(
+ IModelConstants.KEY_DIALOG_PART_CUSTOM_LOCATION,
+ location);
+
+ MWindow window = (MWindow) me;
+ IWindowCloseHandler closeHandler = window.getContext()
+ .get(IWindowCloseHandler.class);
+ // if there's no handler or the handler permits the close
+ // request, clean-up as necessary
+ if (closeHandler == null || closeHandler.close(window)) {
+ Object parentModel = shell.getParent()
+ .getData(OWNING_ME);
+ if (parentModel instanceof MWindow) {
+ List children = ((MWindow) parentModel)
+ .getChildren();
+ if (children.contains(window)) {
+ children.remove(window);
+ }
+ } else {
+ MWindow trimmedWindow = application.getChildren()
+ .get(0);
+ List windows = trimmedWindow.getWindows();
+ if (windows.contains(window)) {
+ windows.remove(window);
+ }
+ }
+ }
+ }
+ });
+ }
+ }
+
+ @Override
+ public void processContents(MElementContainer me) {
+ if (!(((MUIElement) me) instanceof MDialog))
+ return;
+ MDialog wbwModel = (MDialog) ((MUIElement) me);
+ super.processContents(me);
+
+ // Populate the main menu
+ IPresentationEngine renderer = context.get(IPresentationEngine.class);
+ if (wbwModel.getMainMenu() != null) {
+ renderer.createGui(wbwModel.getMainMenu(), me.getWidget(), null);
+ Shell shell = (Shell) me.getWidget();
+ shell.setMenuBar((Menu) wbwModel.getMainMenu().getWidget());
+ }
+
+ // create Detached Windows
+ for (MWindow dw : wbwModel.getWindows()) {
+ renderer.createGui(dw, me.getWidget(), wbwModel.getContext());
+ }
+ }
+
+ @Override
+ public void postProcess(MUIElement shellME) {
+ if (!(shellME instanceof MDialog))
+ return;
+ MDialog dialogModel = (MDialog) shellME;
+ super.postProcess(shellME);
+
+ Shell shell = (Shell) shellME.getWidget();
+ String location = shellME.getPersistedState()
+ .get(IModelConstants.KEY_DIALOG_PART_CUSTOM_LOCATION);
+ location = location == null ? "" : location; //$NON-NLS-1$
+ String[] locations = location.split(","); //$NON-NLS-1$
+
+ if (locations.length < 4) {
+ String[] tempLocations = new String[4];
+ for (int i = 0; i < locations.length; i++)
+ tempLocations[i] = locations[i];
+ locations = tempLocations;
+ }
+
+ Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ if (isNone(locations[2])) {
+ locations[2] = String.valueOf(size.x);
+ }
+ if (isNone(locations[3])) {
+ locations[3] = String.valueOf(size.y);
+ }
+ size = new Point(Integer.valueOf(locations[2]),
+ Integer.valueOf(locations[3]));
+ Point initLocation = getInitialLocation(shell, size);
+ Rectangle bounds = getConstrainedShellBounds(shell,
+ new Rectangle(initLocation.x, initLocation.y, size.x, size.y));
+ if (isNone(locations[0]) && isNone(locations[1])) {
+ locations[0] = String.valueOf(bounds.x);
+ locations[1] = String.valueOf(bounds.y);
+ }
+
+ dialogModel.setX(Integer.valueOf(locations[0]));
+ dialogModel.setY(Integer.valueOf(locations[1]));
+ dialogModel.setWidth(Integer.valueOf(locations[2]));
+ dialogModel.setHeight(Integer.valueOf(locations[3]));
+
+ StringBuffer sb = new StringBuffer();
+ sb.append(locations[0]);
+ sb.append(","); //$NON-NLS-1$
+ sb.append(locations[1]);
+ sb.append(","); //$NON-NLS-1$
+ sb.append(locations[2]);
+ sb.append(","); //$NON-NLS-1$
+ sb.append(locations[3]);
+
+ dialogModel.getPersistedState().put(
+ IModelConstants.KEY_DIALOG_PART_CUSTOM_LOCATION, sb.toString());
+
+ shell.layout(true);
+ forceLayout(shell);
+ if (shellME.isVisible()) {
+ shell.open();
+ } else {
+ shell.setVisible(false);
+ }
+ }
+
+ private boolean isNone(String value) {
+ return value == null || "".equals(value); //$NON-NLS-1$
+ }
+
+ private Point getInitialLocation(Shell shell, Point initialSize) {
+ Composite parent = shell.getParent();
+
+ Monitor monitor = shell.getDisplay().getPrimaryMonitor();
+ if (parent != null) {
+ monitor = parent.getMonitor();
+ }
+
+ Rectangle monitorBounds = monitor.getClientArea();
+ Point centerPoint;
+ if (parent != null) {
+ centerPoint = Geometry.centerPoint(parent.getBounds());
+ } else {
+ centerPoint = Geometry.centerPoint(monitorBounds);
+ }
+
+ return new Point(centerPoint.x - (initialSize.x / 2),
+ centerPoint.y - (initialSize.y / 2));
+ }
+
+ protected Rectangle getConstrainedShellBounds(Shell shell,
+ Rectangle preferredSize) {
+ Rectangle result = new Rectangle(preferredSize.x, preferredSize.y,
+ preferredSize.width, preferredSize.height);
+
+ Monitor mon = getClosestMonitor(shell.getDisplay(),
+ Geometry.centerPoint(result));
+
+ Rectangle bounds = mon.getClientArea();
+
+ if (result.height > bounds.height) {
+ result.height = bounds.height;
+ }
+
+ if (result.width > bounds.width) {
+ result.width = bounds.width;
+ }
+
+ result.x = Math.max(bounds.x,
+ Math.min(result.x, bounds.x + bounds.width - result.width));
+ result.y = Math.max(bounds.y,
+ Math.min(result.y, bounds.y + bounds.height - result.height));
+
+ return result;
+ }
+
+ private static Monitor getClosestMonitor(Display toSearch, Point toFind) {
+ int closest = Integer.MAX_VALUE;
+
+ Monitor[] monitors = toSearch.getMonitors();
+ Monitor result = monitors[0];
+
+ for (int idx = 0; idx < monitors.length; idx++) {
+ Monitor current = monitors[idx];
+
+ Rectangle clientArea = current.getClientArea();
+
+ if (clientArea.contains(toFind)) {
+ return current;
+ }
+
+ int distance = Geometry
+ .distanceSquared(Geometry.centerPoint(clientArea), toFind);
+ if (distance < closest) {
+ closest = distance;
+ result = current;
+ }
+ }
+
+ return result;
+ }
+
+ private void forceLayout(Shell shell) {
+ int i = 0;
+ while (shell.isLayoutDeferred()) {
+ shell.setLayoutDeferred(false);
+ i++;
+ }
+ while (i > 0) {
+ shell.setLayoutDeferred(true);
+ i--;
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XEditorStackRenderer.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XEditorStackRenderer.java
new file mode 100644
index 000000000..d9a844306
--- /dev/null
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XEditorStackRenderer.java
@@ -0,0 +1,166 @@
+package org.xmind.cathy.internal.renderer;
+
+import org.eclipse.draw2d.TextUtilities;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.util.Util;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.ui.PlatformUI;
+import org.xmind.cathy.internal.CathyPlugin;
+import org.xmind.cathy.internal.WorkbenchMessages;
+import org.xmind.ui.internal.utils.CommandUtils;
+import org.xmind.ui.resources.ColorUtils;
+
+public class XEditorStackRenderer extends StackRenderer {
+
+ private static final int CORNER = 5;
+
+ private ResourceManager resources;
+
+ private Rectangle buttonBounds;
+
+ private Color buttonBackground;
+
+ @Override
+ public Object createWidget(MUIElement element, Object parent) {
+ final CTabFolder ctf = (CTabFolder) super.createWidget(element, parent);
+ resources = new LocalResourceManager(JFaceResources.getResources(),
+ ctf);
+ buttonBackground = (Color) resources.get(
+ ColorUtils.toDescriptor(Util.isMac() ? "#ffffff" : "#e1e1e1")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ ctf.addPaintListener(new PaintListener() {
+
+ @Override
+ public void paintControl(PaintEvent e) {
+
+ if (!isNullEditorState(ctf)) {
+ return;
+ }
+
+ /// Set focus with no edit content, let the dashboard lose focus (Shift + Command + C key binding )
+ if (e.display.getActiveShell() == ctf.getShell()) {
+ ctf.setFocus();
+ }
+
+ /// paint null-content-tip area (size: 144 * 172)
+ GC gc = e.gc;
+ boolean oldAdvanced = gc.getAdvanced();
+ int oldAntialias = gc.getAntialias();
+ try {
+ gc.setAdvanced(true);
+ gc.setAntialias(SWT.ON);
+
+ /// compute size & location
+ Rectangle clientArea = ctf.getClientArea();
+
+ Image image = (Image) resources.get(CathyPlugin
+ .imageDescriptorFromPlugin(CathyPlugin.PLUGIN_ID,
+ "icons/views/null_editor_tip.png")); //$NON-NLS-1$
+ Point imageSize = new Point(image.getBounds().width,
+ image.getBounds().height);
+
+ Dimension textExtents = TextUtilities.INSTANCE
+ .getTextExtents(
+ WorkbenchMessages.XStackRenderer_BottomArea_Add_button,
+ gc.getFont());
+ Point buttonSize = new Point(
+ Math.max(128, textExtents.width + 10),
+ Util.isMac() ? 21 : 25);
+
+ /// drag tip image
+ Point imagePos = new Point(
+ clientArea.x + (clientArea.width - imageSize.x) / 2,
+ clientArea.y + (clientArea.height
+ - (imageSize.y + 40 + buttonSize.y)) / 2);
+ gc.drawImage(image, imagePos.x, imagePos.y);
+
+ /// draw create button
+ Point buttonPos = new Point(
+ clientArea.x
+ + (clientArea.width - buttonSize.x) / 2,
+ imagePos.y + image.getBounds().height + 40);
+ buttonBounds = new Rectangle(buttonPos.x, buttonPos.y,
+ buttonSize.x, buttonSize.y);
+
+ drawButton(gc, buttonBounds);
+
+ /// draw text
+ Point textPos = new Point(buttonBounds.x
+ + (buttonBounds.width - textExtents.width) / 2,
+ buttonBounds.y
+ + (buttonBounds.height - textExtents.height)
+ / 2);
+
+ gc.setBackground(buttonBackground);
+ gc.setForeground((Color) resources
+ .get(ColorUtils.toDescriptor("#000000"))); //$NON-NLS-1$
+ gc.drawText(
+ WorkbenchMessages.XStackRenderer_BottomArea_Add_button,
+ textPos.x, textPos.y);
+
+ } finally {
+ gc.setAdvanced(oldAdvanced);
+ gc.setAntialias(oldAntialias);
+ }
+ }
+ });
+
+ ctf.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ if (isNullEditorState(ctf) && buttonBounds != null
+ && buttonBounds.contains(e.x, e.y)) {
+ CommandUtils.executeCommand(
+ "org.xmind.ui.command.newWorkbook", //$NON-NLS-1$
+ PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow());
+ }
+ }
+ });
+
+ return ctf;
+ }
+
+ private boolean isNullEditorState(CTabFolder ctf) {
+ return ctf.getItemCount() == 0;
+ }
+
+ private void drawButton(GC gc, Rectangle buttonBounds) {
+ if (!Util.isMac()) {
+ gc.setForeground(
+ (Color) resources.get(ColorUtils.toDescriptor("#f0f0f0"))); //$NON-NLS-1$
+ gc.drawRectangle(buttonBounds.x - 1, buttonBounds.y - 1,
+ buttonBounds.width + 2, buttonBounds.height + 2);
+ }
+
+ gc.setBackground(buttonBackground);
+ gc.setForeground(
+ (Color) resources.get(ColorUtils.toDescriptor("#adadad"))); //$NON-NLS-1$
+ if (Util.isMac()) {
+ gc.fillRoundRectangle(buttonBounds.x, buttonBounds.y,
+ buttonBounds.width, buttonBounds.height, CORNER, CORNER);
+ gc.drawRoundRectangle(buttonBounds.x, buttonBounds.y,
+ buttonBounds.width, buttonBounds.height, CORNER, CORNER);
+ } else {
+ gc.fillRectangle(buttonBounds);
+ gc.drawRectangle(buttonBounds);
+ }
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XMenuManagerRenderer.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XMenuManagerRenderer.java
index 8a6712a3e..48232a507 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XMenuManagerRenderer.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XMenuManagerRenderer.java
@@ -1,65 +1,65 @@
-package org.xmind.cathy.internal.renderer;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
-import org.eclipse.e4.ui.model.application.MApplication;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
-import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer;
-
-public class XMenuManagerRenderer extends MenuManagerRenderer {
-
- private static final String[] retainedIconMenus = {
- "org.xmind.ui.toolbar.mindmap.topic.menu", //$NON-NLS-1$
- "org.xmind.ui.toolbar.export.export.menu", //$NON-NLS-1$
- "org.xmind.ui.toolbar.mindmap.insert.menu" //$NON-NLS-1$
- };
-
- @Inject
- private MApplication application;
-
- @Override
- public void processContributions(MMenu menuModel, String elementId,
- boolean isMenuBar, boolean isPopup) {
- if (elementId == null) {
- return;
- }
-
- List elements = menuModel.getChildren();
- for (MMenuElement menuItem : elements) {
- if (menuItem instanceof MMenuElement) {
- if (!checkRetainedIconMenu(menuModel)) {
- ((MMenuElement) menuItem).setIconURI(null);
- }
- menuItem.setTooltip(""); //$NON-NLS-1$
- }
- }
-
- final ArrayList toContribute = new ArrayList();
- ContributionsAnalyzer.XXXgatherMenuContributions(menuModel,
- application.getMenuContributions(), elementId, toContribute,
- null, isPopup);
- for (MMenuContribution contri : toContribute) {
- List children = contri.getChildren();
- for (MMenuElement me : children) {
- if (!checkRetainedIconMenu(menuModel)) {
- ((MMenuElement) me).setIconURI(null);
- }
- me.setTooltip(""); //$NON-NLS-1$
- }
- }
- super.processContributions(menuModel, elementId, isMenuBar, isPopup);
- }
-
- private boolean checkRetainedIconMenu(MMenu menuModel) {
- return Arrays.asList(retainedIconMenus)
- .contains(menuModel.getElementId());
- }
-
-}
+package org.xmind.cathy.internal.renderer;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
+import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer;
+
+public class XMenuManagerRenderer extends MenuManagerRenderer {
+
+ private static final String[] retainedIconMenus = {
+ "org.xmind.ui.toolbar.mindmap.topic.menu", //$NON-NLS-1$
+ "org.xmind.ui.toolbar.export.export.menu", //$NON-NLS-1$
+ "org.xmind.ui.toolbar.mindmap.insert.menu" //$NON-NLS-1$
+ };
+
+ @Inject
+ private MApplication application;
+
+ @Override
+ public void processContributions(MMenu menuModel, String elementId,
+ boolean isMenuBar, boolean isPopup) {
+ if (elementId == null) {
+ return;
+ }
+
+ List elements = menuModel.getChildren();
+ for (MMenuElement menuItem : elements) {
+ if (menuItem instanceof MMenuElement) {
+ if (!checkRetainedIconMenu(menuModel)) {
+ ((MMenuElement) menuItem).setIconURI(null);
+ }
+ menuItem.setTooltip(""); //$NON-NLS-1$
+ }
+ }
+
+ final ArrayList toContribute = new ArrayList();
+ ContributionsAnalyzer.XXXgatherMenuContributions(menuModel,
+ application.getMenuContributions(), elementId, toContribute,
+ null, isPopup);
+ for (MMenuContribution contri : toContribute) {
+ List children = contri.getChildren();
+ for (MMenuElement me : children) {
+ if (!checkRetainedIconMenu(menuModel)) {
+ ((MMenuElement) me).setIconURI(null);
+ }
+ me.setTooltip(""); //$NON-NLS-1$
+ }
+ }
+ super.processContributions(menuModel, elementId, isMenuBar, isPopup);
+ }
+
+ private boolean checkRetainedIconMenu(MMenu menuModel) {
+ return Arrays.asList(retainedIconMenus)
+ .contains(menuModel.getElementId());
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XRightStackRenderer.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XRightStackRenderer.java
deleted file mode 100644
index a3606e2e0..000000000
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XRightStackRenderer.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package org.xmind.cathy.internal.renderer;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-
-import org.eclipse.e4.core.services.events.IEventBroker;
-import org.eclipse.e4.ui.model.application.ui.MElementContainer;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
-import org.eclipse.e4.ui.model.application.ui.basic.MStackElement;
-import org.eclipse.e4.ui.workbench.IPresentationEngine;
-import org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StackLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-
-public class XRightStackRenderer extends LazyStackRenderer {
-
- @Inject
- private IPresentationEngine renderer;
-
- @Inject
- private IEventBroker eventBroker;
-
- @Override
- public Object createWidget(MUIElement element, Object parent) {
- if (!(element instanceof MPartStack) || !(parent instanceof Composite))
- return null;
-
- MPartStack viewStack = (MPartStack) element;
-
- Composite parentComposite = (Composite) parent;
- Composite viewContainer = null;
-
- // Ensure that all rendered PartStacks have an Id
- if (element.getElementId() == null
- || element.getElementId().length() == 0) {
- String generatedId = "RightStack@" //$NON-NLS-1$
- + Integer.toHexString(element.hashCode());
- element.setElementId(generatedId);
- }
-
- int styleOverride = getStyleOverride(viewStack);
- int style = styleOverride == -1 ? SWT.NONE : styleOverride;
- //TODO Should use custom composite?
- viewContainer = new Composite(parentComposite, style);
- viewContainer.setLayout(new StackLayout());
-
- bindWidget(element, viewContainer);
-
- return viewContainer;
- }
-
- @Override
- protected void showTab(MUIElement element) {
- super.showTab(element);
-
- if (element instanceof MPartStack
- && element.getRenderer() == XRightStackRenderer.this) {
- MPartStack stackModel = (MPartStack) element;
- MUIElement curSel = stackModel.getSelectedElement();
- MPart part = (MPart) ((curSel instanceof MPlaceholder)
- ? ((MPlaceholder) curSel).getRef() : curSel);
- if (curSel instanceof MPlaceholder) {
- part.setCurSharedRef((MPlaceholder) curSel);
- }
- }
-
- // an invisible element won't have the correct widget hierarchy
- if (!element.isVisible()) {
- return;
- }
-
- final Composite viewContainer = (Composite) getParentWidget(element);
- Control ctrl = (Control) element.getWidget();
- if (ctrl != null && ctrl.getParent() != viewContainer) {
- ctrl.setParent(viewContainer);
- } else if (ctrl == null) {
- renderer.createGui(element);
- }
-
- ctrl = (Control) element.getWidget();
-
- if (ctrl instanceof Composite) {
- ((Composite) ctrl).layout(false, true);
- }
- ((StackLayout) viewContainer.getLayout()).topControl = ctrl;
- viewContainer.layout(true, true);
-
- }
-
- @Override
- public void childRendered(final MElementContainer parentElement,
- MUIElement element) {
- super.childRendered(parentElement, element);
-
- if (!(((MUIElement) parentElement) instanceof MPartStack)
- || !(element instanceof MStackElement))
- return;
- showTab(element);
- }
-
- @PostConstruct
- public void init() {
- super.init(eventBroker);
- }
-
- @PreDestroy
- public void contextDisposed() {
- super.contextDisposed(eventBroker);
- }
-}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XRightTrimBarLayout.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XRightTrimBarLayout.java
index bf400bf0f..aeadd6103 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XRightTrimBarLayout.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XRightTrimBarLayout.java
@@ -1,127 +1,127 @@
-package org.xmind.cathy.internal.renderer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Layout;
-import org.xmind.cathy.internal.ICathyConstants;
-
-public class XRightTrimBarLayout extends Layout {
-
- private static final int MARGIN_LEFT = -2;
- private static final int MARGIN_RIGHT = -2;
- private static final int MARGIN_TOP = 20;
- private static final int MARGIN_BOTTOM = 0;
-
- @Override
- protected Point computeSize(Composite composite, int wHint, int hHint,
- boolean flushCache) {
- int width = 0;
- Control[] children = composite.getChildren();
- for (Control child : children) {
- Point size = child.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
- width = Math.max(width, size.x);
- }
- width = width + MARGIN_LEFT + MARGIN_RIGHT;
- return new Point(width, hHint);
- }
-
- @Override
- protected void layout(Composite composite, boolean flushCache) {
- Rectangle bounds = composite.getBounds();
- bounds.x = MARGIN_LEFT;
- bounds.y = MARGIN_TOP;
- bounds.width -= (MARGIN_LEFT + MARGIN_RIGHT);
- bounds.height -= (MARGIN_TOP + MARGIN_BOTTOM);
-
- int curX = bounds.x;
- int curY = bounds.y;
-
- List beginingControls = new ArrayList();
- List centerControls = new ArrayList();
- List endControls = new ArrayList();
-
- int centerControlsHeight = 0;
- int endControlsHeight = 0;
-
- Control[] children = composite.getChildren();
- for (Control child : children) {
- if (isBegining(child)) {
- beginingControls.add(child);
- } else if (isCenter(child)) {
- centerControls.add(child);
- centerControlsHeight += child.computeSize(SWT.DEFAULT,
- SWT.DEFAULT).y;
- } else if (isEnd(child)) {
- endControls.add(child);
- endControlsHeight += child.computeSize(SWT.DEFAULT,
- SWT.DEFAULT).y;
- } else {
- centerControls.add(child);
- centerControlsHeight += child.computeSize(SWT.DEFAULT,
- SWT.DEFAULT).y;
- }
- }
-
- for (Control bc : beginingControls) {
- Point size = bc.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- bc.setBounds(curX, curY, size.x, size.y);
- curY += size.y;
- }
-
- curY = Math.max(curY, (bounds.height - centerControlsHeight) / 2);
-
- for (Control cc : centerControls) {
- Point size = cc.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- cc.setBounds(curX, curY, size.x, size.y);
- curY += size.y;
- }
-
- curY = Math.max(curY, bounds.y + bounds.height - endControlsHeight);
-
- for (Control ec : endControls) {
- Point size = ec.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- ec.setBounds(curX, curY, size.x, size.y);
- curY += size.y;
- }
-
- }
-
- private boolean isBegining(Control ctrl) {
- MUIElement element = (MUIElement) ctrl
- .getData(AbstractPartRenderer.OWNING_ME);
- if (element != null && element.getTags()
- .contains(ICathyConstants.TAG_TRIMBAR_LAYOUT_BEGINING))
- return true;
-
- return false;
- }
-
- private boolean isCenter(Control ctrl) {
- MUIElement element = (MUIElement) ctrl
- .getData(AbstractPartRenderer.OWNING_ME);
- if (element != null && element.getTags()
- .contains(ICathyConstants.TAG_TRIMBAR_LAYOUT_CENTER))
- return true;
-
- return false;
- }
-
- private boolean isEnd(Control ctrl) {
- MUIElement element = (MUIElement) ctrl
- .getData(AbstractPartRenderer.OWNING_ME);
- if (element != null && element.getTags()
- .contains(ICathyConstants.TAG_TRIMBAR_LAYOUT_END))
- return true;
-
- return false;
- }
-
-}
+package org.xmind.cathy.internal.renderer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Layout;
+import org.xmind.cathy.internal.ICathyConstants;
+
+public class XRightTrimBarLayout extends Layout {
+
+ private static final int MARGIN_LEFT = -2;
+ private static final int MARGIN_RIGHT = -2;
+ private static final int MARGIN_TOP = 20;
+ private static final int MARGIN_BOTTOM = 0;
+
+ @Override
+ protected Point computeSize(Composite composite, int wHint, int hHint,
+ boolean flushCache) {
+ int width = 0;
+ Control[] children = composite.getChildren();
+ for (Control child : children) {
+ Point size = child.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ width = Math.max(width, size.x);
+ }
+ width = width + MARGIN_LEFT + MARGIN_RIGHT;
+ return new Point(width, hHint);
+ }
+
+ @Override
+ protected void layout(Composite composite, boolean flushCache) {
+ Rectangle bounds = composite.getBounds();
+ bounds.x = MARGIN_LEFT;
+ bounds.y = MARGIN_TOP;
+ bounds.width -= (MARGIN_LEFT + MARGIN_RIGHT);
+ bounds.height -= (MARGIN_TOP + MARGIN_BOTTOM);
+
+ int curX = bounds.x;
+ int curY = bounds.y;
+
+ List beginingControls = new ArrayList();
+ List centerControls = new ArrayList();
+ List endControls = new ArrayList();
+
+ int centerControlsHeight = 0;
+ int endControlsHeight = 0;
+
+ Control[] children = composite.getChildren();
+ for (Control child : children) {
+ if (isBegining(child)) {
+ beginingControls.add(child);
+ } else if (isCenter(child)) {
+ centerControls.add(child);
+ centerControlsHeight += child.computeSize(SWT.DEFAULT,
+ SWT.DEFAULT).y;
+ } else if (isEnd(child)) {
+ endControls.add(child);
+ endControlsHeight += child.computeSize(SWT.DEFAULT,
+ SWT.DEFAULT).y;
+ } else {
+ centerControls.add(child);
+ centerControlsHeight += child.computeSize(SWT.DEFAULT,
+ SWT.DEFAULT).y;
+ }
+ }
+
+ for (Control bc : beginingControls) {
+ Point size = bc.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ bc.setBounds(curX, curY, size.x, size.y);
+ curY += size.y;
+ }
+
+ curY = Math.max(curY, (bounds.height - centerControlsHeight) / 2);
+
+ for (Control cc : centerControls) {
+ Point size = cc.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ cc.setBounds(curX, curY, size.x, size.y);
+ curY += size.y;
+ }
+
+ curY = Math.max(curY, bounds.y + bounds.height - endControlsHeight);
+
+ for (Control ec : endControls) {
+ Point size = ec.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ ec.setBounds(curX, curY, size.x, size.y);
+ curY += size.y;
+ }
+
+ }
+
+ private boolean isBegining(Control ctrl) {
+ MUIElement element = (MUIElement) ctrl
+ .getData(AbstractPartRenderer.OWNING_ME);
+ if (element != null && element.getTags()
+ .contains(ICathyConstants.TAG_TRIMBAR_LAYOUT_BEGINING))
+ return true;
+
+ return false;
+ }
+
+ private boolean isCenter(Control ctrl) {
+ MUIElement element = (MUIElement) ctrl
+ .getData(AbstractPartRenderer.OWNING_ME);
+ if (element != null && element.getTags()
+ .contains(ICathyConstants.TAG_TRIMBAR_LAYOUT_CENTER))
+ return true;
+
+ return false;
+ }
+
+ private boolean isEnd(Control ctrl) {
+ MUIElement element = (MUIElement) ctrl
+ .getData(AbstractPartRenderer.OWNING_ME);
+ if (element != null && element.getTags()
+ .contains(ICathyConstants.TAG_TRIMBAR_LAYOUT_END))
+ return true;
+
+ return false;
+ }
+
+}
diff --git a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XSashLayout.java b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XSashLayout.java
index 4d9e8027d..71283ceb1 100644
--- a/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XSashLayout.java
+++ b/bundles/org.xmind.cathy/src/org/xmind/cathy/internal/renderer/XSashLayout.java
@@ -1,191 +1,191 @@
-package org.xmind.cathy.internal.renderer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.e4.ui.model.application.ui.MGenericTile;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Layout;
-import org.eclipse.swt.widgets.Shell;
-
-public class XSashLayout extends Layout {
-
- int suggestedSizeForViewStack = 310;
- int suggestedDownDistanceForViewStack = 22;
-
- int marginLeft = 0;
- int marginRight = 0;
- int marginTop = 0;
- int marginBottom = 0;
- int sashWidth = 0;
-
- MUIElement root;
-
- class SashRect {
- Rectangle rect;
- MGenericTile> container;
- MUIElement left;
- MUIElement right;
-
- public SashRect(Rectangle rect, MGenericTile> container,
- MUIElement left, MUIElement right) {
- this.container = container;
- this.rect = rect;
- this.left = left;
- this.right = right;
- }
- }
-
- public XSashLayout(MUIElement root) {
- this.root = root;
- }
-
- @Override
- protected void layout(Composite composite, boolean flushCache) {
- if (root == null)
- return;
-
- Rectangle bounds = composite.getBounds();
- if (composite instanceof Shell)
- bounds = ((Shell) composite).getClientArea();
- else {
- bounds.x = 0;
- bounds.y = 0;
- }
-
- bounds.width -= (marginLeft + marginRight);
- bounds.height -= (marginTop + marginBottom);
- bounds.x += marginLeft;
- bounds.y += marginTop;
-
- tileSubNodes(bounds, root);
- }
-
- @Override
- protected Point computeSize(Composite composite, int wHint, int hHint,
- boolean flushCache) {
- return new Point(600, 400);
- }
-
- private int totalScalableSectionWeight(MGenericTile> node) {
- int total = 0;
- for (MUIElement subNode : node.getChildren()) {
- if (subNode.isToBeRendered() && subNode.isVisible()) {
- Object renderer = subNode.getRenderer();
- if (renderer != null
- && renderer.getClass() != XRightStackRenderer.class) {
- total += getWeight(subNode);
- }
- }
- }
- return total;
- }
-
- private void tileSubNodes(Rectangle bounds, MUIElement node) {
- if (node != root)
- setRectangle(node, bounds);
-
- if (!(node instanceof MGenericTile>))
- return;
-
- MGenericTile> sashContainer = (MGenericTile>) node;
- List visibleChildren = getVisibleChildren(sashContainer);
- int childCount = visibleChildren.size();
-
- // How many pixels do we have?
- int availableWidth = sashContainer.isHorizontal() ? bounds.width
- : bounds.height;
-
- // Subtract off the room for the sashes
- availableWidth -= ((childCount - 1) * sashWidth);
-
- int availableScalableSectionWidth = availableWidth;
-
- // Get the total of the weights
- double totalScalableSectionWeight = totalScalableSectionWeight(
- sashContainer);
- for (MUIElement subNode : visibleChildren) {
- Object renderer = subNode.getRenderer();
- if (renderer != null
- && renderer.getClass() == XRightStackRenderer.class) {
- availableScalableSectionWidth -= suggestedSizeForViewStack;
- }
- }
- int tilePos = sashContainer.isHorizontal() ? bounds.x : bounds.y;
-
- MUIElement prev = null;
- for (MUIElement subNode : visibleChildren) {
- // Add a 'sash' between this node and the 'prev'
- if (prev != null) {
- tilePos += sashWidth;
- }
-
- // Calc the new size as a %'age of the total
- int weight = getWeight(subNode);
- double ratio = weight / totalScalableSectionWeight;
- int newSize = (int) ((availableScalableSectionWidth * ratio) + 0.5);
- Object renderer = subNode.getRenderer();
-
- int y = bounds.y;
- int height = bounds.height;
- if (renderer != null
- && renderer.getClass() == XRightStackRenderer.class) {
- newSize = suggestedSizeForViewStack;
- y = y + suggestedDownDistanceForViewStack;
- height = height - suggestedDownDistanceForViewStack - 1;
- }
-
- Rectangle subBounds = sashContainer.isHorizontal()
- ? new Rectangle(tilePos, y, newSize, height)
- : new Rectangle(bounds.x, tilePos, bounds.width, newSize);
- tilePos += newSize;
-
- tileSubNodes(subBounds, subNode);
- prev = subNode;
- }
- }
-
- /**
- * @param node
- * @param bounds
- */
- private void setRectangle(MUIElement node, Rectangle bounds) {
- if (node.getWidget() instanceof Control) {
- Control ctrl = (Control) node.getWidget();
- ctrl.setBounds(bounds);
- } else if (node.getWidget() instanceof Rectangle) {
- Rectangle theRect = (Rectangle) node.getWidget();
- theRect.x = bounds.x;
- theRect.y = bounds.y;
- theRect.width = bounds.width;
- theRect.height = bounds.height;
- }
- }
-
- private List getVisibleChildren(MGenericTile> sashContainer) {
- List visKids = new ArrayList();
- for (MUIElement child : sashContainer.getChildren()) {
- if (child.isToBeRendered() && child.isVisible())
- visKids.add(child);
- }
- return visKids;
- }
-
- private static int getWeight(MUIElement element) {
- String info = element.getContainerData();
- if (info == null || info.length() == 0) {
- return 0;
- }
-
- try {
- int value = Integer.parseInt(info);
- return value;
- } catch (NumberFormatException e) {
- return 0;
- }
- }
-}
+package org.xmind.cathy.internal.renderer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.e4.ui.model.application.ui.MGenericTile;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Layout;
+import org.eclipse.swt.widgets.Shell;
+
+public class XSashLayout extends Layout {
+
+ int suggestedSizeForViewStack = 310;
+ int suggestedDownDistanceForViewStack = 22;
+
+ int marginLeft = 0;
+ int marginRight = 0;
+ int marginTop = 0;
+ int marginBottom = 0;
+ int sashWidth = 0;
+
+ MUIElement root;
+
+ class SashRect {
+ Rectangle rect;
+ MGenericTile> container;
+ MUIElement left;
+ MUIElement right;
+
+ public SashRect(Rectangle rect, MGenericTile> container,
+ MUIElement left, MUIElement right) {
+ this.container = container;
+ this.rect = rect;
+ this.left = left;
+ this.right = right;
+ }
+ }
+
+ public XSashLayout(MUIElement root) {
+ this.root = root;
+ }
+
+ @Override
+ protected void layout(Composite composite, boolean flushCache) {
+ if (root == null)
+ return;
+
+ Rectangle bounds = composite.getBounds();
+ if (composite instanceof Shell)
+ bounds = ((Shell) composite).getClientArea();
+ else {
+ bounds.x = 0;
+ bounds.y = 0;
+ }
+
+ bounds.width -= (marginLeft + marginRight);
+ bounds.height -= (marginTop + marginBottom);
+ bounds.x += marginLeft;
+ bounds.y += marginTop;
+
+ tileSubNodes(bounds, root);
+ }
+
+ @Override
+ protected Point computeSize(Composite composite, int wHint, int hHint,
+ boolean flushCache) {
+ return new Point(600, 400);
+ }
+
+ private int totalScalableSectionWeight(MGenericTile> node) {
+ int total = 0;
+ for (MUIElement subNode : node.getChildren()) {
+ if (subNode.isToBeRendered() && subNode.isVisible()) {
+ Object renderer = subNode.getRenderer();
+ if (renderer != null
+ && renderer.getClass() != XStackRenderer.class) {
+ total += getWeight(subNode);
+ }
+ }
+ }
+ return total;
+ }
+
+ private void tileSubNodes(Rectangle bounds, MUIElement node) {
+ if (node != root)
+ setRectangle(node, bounds);
+
+ if (!(node instanceof MGenericTile>))
+ return;
+
+ MGenericTile> sashContainer = (MGenericTile>) node;
+ List visibleChildren = getVisibleChildren(sashContainer);
+ int childCount = visibleChildren.size();
+
+ // How many pixels do we have?
+ int availableWidth = sashContainer.isHorizontal() ? bounds.width
+ : bounds.height;
+
+ // Subtract off the room for the sashes
+ availableWidth -= ((childCount - 1) * sashWidth);
+
+ int availableScalableSectionWidth = availableWidth;
+
+ // Get the total of the weights
+ double totalScalableSectionWeight = totalScalableSectionWeight(
+ sashContainer);
+ for (MUIElement subNode : visibleChildren) {
+ Object renderer = subNode.getRenderer();
+ if (renderer != null
+ && renderer.getClass() == XStackRenderer.class) {
+ availableScalableSectionWidth -= suggestedSizeForViewStack;
+ }
+ }
+ int tilePos = sashContainer.isHorizontal() ? bounds.x : bounds.y;
+
+ MUIElement prev = null;
+ for (MUIElement subNode : visibleChildren) {
+ // Add a 'sash' between this node and the 'prev'
+ if (prev != null) {
+ tilePos += sashWidth;
+ }
+
+ // Calc the new size as a %'age of the total
+ int weight = getWeight(subNode);
+ double ratio = weight / totalScalableSectionWeight;
+ int newSize = (int) ((availableScalableSectionWidth * ratio) + 0.5);
+ Object renderer = subNode.getRenderer();
+
+ int y = bounds.y;
+ int height = bounds.height;
+ if (renderer != null
+ && renderer.getClass() == XStackRenderer.class) {
+ newSize = suggestedSizeForViewStack;
+ y = y + suggestedDownDistanceForViewStack;
+ height = height - suggestedDownDistanceForViewStack - 1;
+ }
+
+ Rectangle subBounds = sashContainer.isHorizontal()
+ ? new Rectangle(tilePos, y, newSize, height)
+ : new Rectangle(bounds.x, tilePos, bounds.width, newSize);
+ tilePos += newSize;
+
+ tileSubNodes(subBounds, subNode);
+ prev = subNode;
+ }
+ }
+
+ /**
+ * @param node
+ * @param bounds
+ */
+ private void setRectangle(MUIElement node, Rectangle bounds) {
+ if (node.getWidget() instanceof Control) {
+ Control ctrl = (Control) node.getWidget();
+ ctrl.setBounds(bounds);
+ } else if (node.getWidget() instanceof Rectangle) {
+ Rectangle theRect = (Rectangle) node.getWidget();
+ theRect.x = bounds.x;
+ theRect.y = bounds.y;
+ theRect.width = bounds.width;
+ theRect.height = bounds.height;
+ }
+ }
+
+ private List