Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOndrej Ilcik2015-09-16 10:48:54 +0000
committerVladimir Piskarev2015-12-14 14:14:34 +0000
commitbf76e1bcb343cd727c854f09de600ca8ac105a16 (patch)
tree0345d021300a34fd4bf515adacb18774104e1902
parentc58fce1ffcb9cf29427584fd1e175dbe3a92fddf (diff)
downloadorg.eclipse.handly-bf76e1bcb343cd727c854f09de600ca8ac105a16.tar.gz
org.eclipse.handly-bf76e1bcb343cd727c854f09de600ca8ac105a16.tar.xz
org.eclipse.handly-bf76e1bcb343cd727c854f09de600ca8ac105a16.zip
Bug 475468 - Java model example: Navigator
Signed-off-by: Ondrej Ilcik <ilcik@codasip.com> Change-Id: I67d116067281bb73eaf1cb11da3bca0beabe43a8
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/META-INF/MANIFEST.MF11
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/build.properties5
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/eview16/jperspective.gifbin0 -> 374 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/eview16/package.gifbin0 -> 145 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/obj16/empty_pack_fldr_obj.gifbin0 -> 334 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/obj16/java_model_obj.gifbin0 -> 208 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/obj16/jcu_resource_obj.gifbin0 -> 573 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/obj16/unknown_obj.gifbin0 -> 368 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/abstract_co.gifbin0 -> 79 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/constr_ovr.gifbin0 -> 81 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/final_co.gifbin0 -> 64 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/implm_co.gifbin0 -> 63 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/native_co.gifbin0 -> 76 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/static_co.gifbin0 -> 79 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/sync_impl.gifbin0 -> 113 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/synch_co.gifbin0 -> 165 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/transient_co.gifbin0 -> 99 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/icons/ovr16/volatile_co.gifbin0 -> 75 bytes
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/plugin.xml258
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/examples/javamodel/ui/JavaModelContentProvider.java168
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/examples/javamodel/ui/JavaModelLabelProvider.java98
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/Activator.java82
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/IJavaImages.java33
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/ImageDescriptorRegistry.java91
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementAdapterFactory.java86
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementComparator.java191
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementContainmentAdapter.java33
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementImageDescriptor.java239
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementImageProvider.java545
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementLabelComposer.java312
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementSorter.java36
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/PersistableJavaElementFactory.java80
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/EmptyInnerPackageFilter.java47
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/EmptyPackageFilter.java78
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/OutputFolderFilter.java57
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/JavaLinkHelper.java122
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/JavaNavigator.java258
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/OpenAction.java92
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/OpenActionProvider.java104
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/WorkingSetActionProvider.java88
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/preferences/MembersOrderPreferenceCache.java231
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/util/JavaFlags.java278
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetElementAdapter.java39
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetPage.java63
-rw-r--r--org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetUpdater.java34
-rw-r--r--org.eclipse.handly.examples.javamodel/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/examples/javamodel/IPackageFragment.java14
-rw-r--r--org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/internal/examples/javamodel/PackageFragment.java24
48 files changed, 3789 insertions, 11 deletions
diff --git a/org.eclipse.handly.examples.javamodel.ui/META-INF/MANIFEST.MF b/org.eclipse.handly.examples.javamodel.ui/META-INF/MANIFEST.MF
index d26f6509..37f30275 100644
--- a/org.eclipse.handly.examples.javamodel.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.handly.examples.javamodel.ui/META-INF/MANIFEST.MF
@@ -9,5 +9,14 @@ Bundle-Activator: org.eclipse.handly.internal.examples.javamodel.ui.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.handly,
org.eclipse.handly.examples.javamodel,
- org.eclipse.ui
+ org.eclipse.handly.ui,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.ui,
+ org.eclipse.ui,
+ org.eclipse.ui.ide,
+ org.eclipse.ui.navigator,
+ org.eclipse.ui.workbench.texteditor
+Export-Package: org.eclipse.handly.examples.javamodel.ui
diff --git a/org.eclipse.handly.examples.javamodel.ui/build.properties b/org.eclipse.handly.examples.javamodel.ui/build.properties
index af618acb..4e6ecc71 100644
--- a/org.eclipse.handly.examples.javamodel.ui/build.properties
+++ b/org.eclipse.handly.examples.javamodel.ui/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2015 1C-Soft LLC.
+# Copyright (c) 2015 1C-Soft LLC and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
#
# Contributors:
# Vladimir Piskarev (1C) - initial API and implementation
+# Ondrej Ilcik (Codasip)
###############################################################################
source.. = src/
@@ -14,5 +15,7 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties,\
+ plugin.xml,\
+ icons/,\
about.html
src.includes = about.html
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/eview16/jperspective.gif b/org.eclipse.handly.examples.javamodel.ui/icons/eview16/jperspective.gif
new file mode 100644
index 00000000..053bcd55
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/eview16/jperspective.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/eview16/package.gif b/org.eclipse.handly.examples.javamodel.ui/icons/eview16/package.gif
new file mode 100644
index 00000000..983932fc
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/eview16/package.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/obj16/empty_pack_fldr_obj.gif b/org.eclipse.handly.examples.javamodel.ui/icons/obj16/empty_pack_fldr_obj.gif
new file mode 100644
index 00000000..989b5bfe
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/obj16/empty_pack_fldr_obj.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/obj16/java_model_obj.gif b/org.eclipse.handly.examples.javamodel.ui/icons/obj16/java_model_obj.gif
new file mode 100644
index 00000000..8c8a7eaa
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/obj16/java_model_obj.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/obj16/jcu_resource_obj.gif b/org.eclipse.handly.examples.javamodel.ui/icons/obj16/jcu_resource_obj.gif
new file mode 100644
index 00000000..9a1797d2
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/obj16/jcu_resource_obj.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/obj16/unknown_obj.gif b/org.eclipse.handly.examples.javamodel.ui/icons/obj16/unknown_obj.gif
new file mode 100644
index 00000000..7d988f9b
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/obj16/unknown_obj.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/abstract_co.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/abstract_co.gif
new file mode 100644
index 00000000..533acc43
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/abstract_co.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/constr_ovr.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/constr_ovr.gif
new file mode 100644
index 00000000..3977bc0f
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/constr_ovr.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/final_co.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/final_co.gif
new file mode 100644
index 00000000..01c580d4
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/final_co.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/implm_co.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/implm_co.gif
new file mode 100644
index 00000000..7766c9db
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/implm_co.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/native_co.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/native_co.gif
new file mode 100644
index 00000000..783c7243
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/native_co.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/static_co.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/static_co.gif
new file mode 100644
index 00000000..499664d5
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/static_co.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/sync_impl.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/sync_impl.gif
new file mode 100644
index 00000000..2a0a3857
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/sync_impl.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/synch_co.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/synch_co.gif
new file mode 100644
index 00000000..5893bda5
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/synch_co.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/transient_co.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/transient_co.gif
new file mode 100644
index 00000000..2a386dee
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/transient_co.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/volatile_co.gif b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/volatile_co.gif
new file mode 100644
index 00000000..4345539f
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/icons/ovr16/volatile_co.gif
Binary files differ
diff --git a/org.eclipse.handly.examples.javamodel.ui/plugin.xml b/org.eclipse.handly.examples.javamodel.ui/plugin.xml
new file mode 100644
index 00000000..989f4be2
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/plugin.xml
@@ -0,0 +1,258 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2015 Codasip Ltd.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+ Ondrej Ilcik (Codasip)
+-->
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.views">
+ <view
+ id="org.eclipse.handly.examples.javamodel.ui.views.JavaNavigator"
+ category="org.eclipse.handly.examples"
+ name="Java Navigator (Handly)"
+ icon="icons/eview16/package.gif"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.navigator.JavaNavigator"
+ restorable="true">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.perspectiveExtensions">
+ <perspectiveExtension
+ targetID="org.eclipse.jdt.ui.JavaPerspective">
+ <view
+ id="org.eclipse.handly.examples.javamodel.ui.views.JavaNavigator"
+ relative="org.eclipse.jdt.ui.PackageExplorer"
+ relationship="stack"
+ visible="false">
+ </view>
+ </perspectiveExtension>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.viewer">
+ <viewer
+ viewerId="org.eclipse.handly.examples.javamodel.ui.views.JavaNavigator">
+ <popupMenu
+ id="org.eclipse.handly.examples.javamodel.ui.views.JavaNavigator#PopupMenu"
+ allowsPlatformContributions="true">
+ <insertionPoint name="group.new"/>
+ <insertionPoint
+ name="group.open"
+ separator="true"/>
+ <insertionPoint name="group.openWith"/>
+ <insertionPoint name="group.edit"
+ separator="true"/>
+ <insertionPoint name="group.reorganize" />
+ <insertionPoint
+ name="group.port"
+ separator="true"/>
+ <insertionPoint
+ name="group.build"
+ separator="true"/>
+ <insertionPoint
+ name="group.generate"
+ separator="true"/>
+ <insertionPoint
+ name="group.search"
+ separator="true"/>
+ <insertionPoint
+ name="additions"
+ separator="true"/>
+ <insertionPoint
+ name="group.properties"
+ separator="true"/>
+ </popupMenu>
+ </viewer>
+ <viewerContentBinding
+ viewerId="org.eclipse.handly.examples.javamodel.ui.views.JavaNavigator">
+ <includes>
+ <contentExtension
+ pattern="org.eclipse.handly.examples.javamodel.ui.navigator.*">
+ </contentExtension>
+ <contentExtension
+ pattern="org.eclipse.handly.examples.javamodel.ui.filters.*">
+ </contentExtension>
+ <contentExtension
+ pattern="org.eclipse.ui.navigator.resources.filters.*">
+ </contentExtension>
+ </includes>
+ </viewerContentBinding>
+ <viewerActionBinding
+ viewerId="org.eclipse.handly.examples.javamodel.ui.views.JavaNavigator">
+ <includes>
+ <actionExtension
+ pattern="org.eclipse.handly.examples.javamodel.ui.navigator.OpenActionProvider">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.OpenActions">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.GotoActions">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.GoIntoActions">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.PortingActions">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.NewActions">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.PropertiesActionProvider">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.WorkManagementActionProvider">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.ResourceMgmtActions">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.UndoRedoActionProvider">
+ </actionExtension>
+ <actionExtension
+ pattern="org.eclipse.handly.examples.javamodel.ui.navigator.WorkingSetActionProvider">
+ </actionExtension>
+ </includes>
+ </viewerActionBinding>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.navigatorContent">
+ <navigatorContent
+ id="org.eclipse.handly.examples.javamodel.ui.navigator.JavaContent"
+ name="Java Content (Handly)"
+ icon="icons/eview16/jperspective.gif"
+ activeByDefault="true"
+ contentProvider="org.eclipse.handly.examples.javamodel.ui.JavaModelContentProvider"
+ labelProvider="org.eclipse.handly.examples.javamodel.ui.JavaModelLabelProvider"
+ priority="normal">
+ <possibleChildren>
+ <or>
+ <instanceof
+ value="org.eclipse.handly.examples.javamodel.IJavaElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.core.resources.IResource">
+ </instanceof>
+ </or>
+ </possibleChildren>
+ <triggerPoints>
+ <or>
+ <instanceof
+ value="org.eclipse.handly.examples.javamodel.IJavaElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.core.resources.IResource">
+ </instanceof>
+ </or>
+ </triggerPoints>
+ <commonSorter
+ class="org.eclipse.handly.internal.examples.javamodel.ui.JavaElementSorter">
+ </commonSorter>
+ <commonWizard
+ menuGroupId="group.new"
+ type="new"
+ wizardId="org.eclipse.jdt.ui.wizards.JavaProjectWizard">
+ <enablement></enablement>
+ </commonWizard>
+ </navigatorContent>
+ <actionProvider
+ id="org.eclipse.handly.examples.javamodel.ui.navigator.OpenActionProvider"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.navigator.OpenActionProvider">
+ <enablement></enablement>
+ </actionProvider>
+ <actionProvider
+ id="org.eclipse.handly.examples.javamodel.ui.navigator.WorkingSetActionProvider"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.navigator.WorkingSetActionProvider">
+ <enablement></enablement>
+ </actionProvider>
+ <commonFilter
+ id="org.eclipse.handly.examples.javamodel.ui.filters.HideOutputFolder"
+ name="Java output folders"
+ description="Hides Java output folders of the Java projects. A Java output folder is where the compiled Java classes are."
+ activeByDefault="true"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.filters.OutputFolderFilter"
+ visibleInUI="true">
+ </commonFilter>
+ <commonFilter
+ id="org.eclipse.handly.examples.javamodel.ui.filters.HideEmptyPackages"
+ name="Empty packages"
+ description="Hides all empty packages."
+ activeByDefault="false"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.filters.EmptyPackageFilter"
+ visibleInUI="true">
+ </commonFilter>
+ <commonFilter
+ id="org.eclipse.handly.examples.javamodel.ui.filters.HideEmptyParentPackages"
+ name="Empty parent packages"
+ description="Hides empty packages which do not contain Java files but other sub-folders."
+ activeByDefault="true"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.filters.EmptyInnerPackageFilter"
+ visibleInUI="true">
+ </commonFilter>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.linkHelper">
+ <linkHelper
+ id="org.eclipse.handly.examples.javamodel.ui.navigator.JavaLinkHelper"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.navigator.JavaLinkHelper">
+ <editorInputEnablement>
+ <or>
+ <instanceof
+ value="org.eclipse.ui.IFileEditorInput">
+ </instanceof>
+ </or>
+ </editorInputEnablement>
+ <selectionEnablement>
+ <or>
+ <instanceof
+ value="org.eclipse.handly.examples.javamodel.IJavaElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.core.resources.IResource">
+ </instanceof>
+ </or>
+ </selectionEnablement>
+ </linkHelper>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.handly.examples.javamodel.IJavaElement"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.JavaElementAdapterFactory">
+ <adapter
+ type="org.eclipse.core.resources.IResource">
+ </adapter>
+ <adapter
+ type="org.eclipse.ui.IPersistableElement">
+ </adapter>
+ <adapter
+ type="org.eclipse.ui.IContainmentAdapter">
+ </adapter>
+ </factory>
+ </extension>
+ <extension
+ point="org.eclipse.ui.elementFactories">
+ <factory
+ id="org.eclipse.handly.examples.javamodel.ui.PersistableJavaElementFactory"
+ class="org.eclipse.handly.internal.examples.javamodel.ui.PersistableJavaElementFactory">
+ </factory>
+ </extension>
+ <extension
+ point="org.eclipse.ui.workingSets">
+ <workingSet
+ id="org.eclipse.handly.examples.javamodel.ui.JavaWorkingSetPage"
+ name="Java (Handly)"
+ description="Working set for Java elements"
+ pageClass="org.eclipse.handly.internal.examples.javamodel.ui.workingset.JavaWorkingSetPage"
+ elementAdapterClass="org.eclipse.handly.internal.examples.javamodel.ui.workingset.JavaWorkingSetElementAdapter"
+ updaterClass="org.eclipse.handly.internal.examples.javamodel.ui.workingset.JavaWorkingSetUpdater">
+ </workingSet>
+ </extension>
+</plugin>
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/examples/javamodel/ui/JavaModelContentProvider.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/examples/javamodel/ui/JavaModelContentProvider.java
new file mode 100644
index 00000000..b4e2e34c
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/examples/javamodel/ui/JavaModelContentProvider.java
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.examples.javamodel.ui;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.handly.examples.javamodel.ICompilationUnit;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.IJavaModel;
+import org.eclipse.handly.examples.javamodel.IJavaProject;
+import org.eclipse.handly.examples.javamodel.IPackageFragment;
+import org.eclipse.handly.examples.javamodel.IPackageFragmentRoot;
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Common content provider for Java model.
+ */
+public class JavaModelContentProvider
+ implements ITreeContentProvider
+{
+ protected static final Object[] NO_CHILDREN = new Object[0];
+
+ @Override
+ public Object[] getElements(Object inputElement)
+ {
+ return getChildren(inputElement);
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement)
+ {
+ if (parentElement instanceof IJavaModel)
+ {
+ try
+ {
+ Object[] javaProjects =
+ ((IJavaModel)parentElement).getJavaProjects();
+ Object[] nonJavaProjects =
+ ((IJavaModel)parentElement).getNonJavaProjects();
+ return concat(javaProjects, nonJavaProjects);
+ }
+ catch (CoreException e)
+ {
+ }
+ }
+ if (parentElement instanceof IJavaProject)
+ {
+ try
+ {
+ Object[] children = ((IJavaElement)parentElement).getChildren();
+ Object[] nonJavaResources =
+ ((IJavaProject)parentElement).getNonJavaResources();
+ return concat(children, nonJavaResources);
+ }
+ catch (CoreException e)
+ {
+ }
+ }
+ if (parentElement instanceof IPackageFragmentRoot)
+ {
+ try
+ {
+ IPackageFragment[] children =
+ ((IPackageFragmentRoot)parentElement).getPackageFragments();
+ Object[] nonJavaResources =
+ ((IPackageFragmentRoot)parentElement).getNonJavaResources();
+ return concat(children, nonJavaResources);
+ }
+ catch (CoreException e)
+ {
+ }
+ }
+ if (parentElement instanceof IPackageFragment)
+ {
+ try
+ {
+ Object[] children =
+ ((IPackageFragment)parentElement).getCompilationUnits();
+ Object[] nonJavaResources =
+ ((IPackageFragment)parentElement).getNonJavaResources();
+ return concat(children, nonJavaResources);
+ }
+ catch (CoreException e)
+ {
+ }
+ }
+ if (parentElement instanceof ICompilationUnit)
+ {
+ try
+ {
+ return ((ICompilationUnit)parentElement).getTypes();
+ }
+ catch (CoreException e)
+ {
+ }
+ }
+ if (parentElement instanceof IJavaElement)
+ {
+ try
+ {
+ return ((IJavaElement)parentElement).getChildren();
+ }
+ catch (CoreException e)
+ {
+ }
+ }
+ if (parentElement instanceof IContainer)
+ {
+ try
+ {
+ return ((IContainer)parentElement).members();
+ }
+ catch (CoreException e)
+ {
+ }
+ }
+ return NO_CHILDREN;
+ }
+
+ @Override
+ public Object getParent(Object element)
+ {
+ if (element instanceof IJavaElement)
+ return ((IJavaElement)element).getParent();
+ if (element instanceof IResource)
+ {
+ IContainer parent = ((IResource)element).getParent();
+ IJavaElement javaParent = JavaModelCore.create(parent);
+ return javaParent != null ? javaParent : parent;
+ }
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren(Object element)
+ {
+ return getChildren(element).length > 0;
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ }
+
+ @Override
+ public void dispose()
+ {
+ }
+
+ private static Object[] concat(Object[] a, Object[] b)
+ {
+ Object[] c = new Object[a.length + b.length];
+ System.arraycopy(a, 0, c, 0, a.length);
+ System.arraycopy(b, 0, c, a.length, b.length);
+ return c;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/examples/javamodel/ui/JavaModelLabelProvider.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/examples/javamodel/ui/JavaModelLabelProvider.java
new file mode 100644
index 00000000..5cef1ade
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/examples/javamodel/ui/JavaModelLabelProvider.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.examples.javamodel.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.internal.examples.javamodel.ui.Activator;
+import org.eclipse.handly.internal.examples.javamodel.ui.JavaElementImageProvider;
+import org.eclipse.handly.internal.examples.javamodel.ui.JavaElementLabelComposer;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+/**
+ * Common label provider for Java model.
+ */
+public class JavaModelLabelProvider
+ extends LabelProvider
+ implements IStyledLabelProvider
+{
+ private JavaElementImageProvider imageProvider =
+ new JavaElementImageProvider();
+
+ @Override
+ public StyledString getStyledText(Object element)
+ {
+ if (element instanceof IJavaElement)
+ {
+ try
+ {
+ StyledString ss = new StyledString();
+ JavaElementLabelComposer.create(ss).appendElementLabel(
+ (IJavaElement)element);
+ return ss;
+ }
+ catch (CoreException e)
+ {
+ Activator.log(e.getStatus());
+ }
+ }
+ return new StyledString(getText(element));
+ }
+
+ @Override
+ public String getText(Object element)
+ {
+ if (element instanceof IJavaElement)
+ {
+ try
+ {
+ StringBuilder sb = new StringBuilder();
+ JavaElementLabelComposer.create(sb).appendElementLabel(
+ (IJavaElement)element);
+ return sb.toString();
+ }
+ catch (CoreException e)
+ {
+ Activator.log(e.getStatus());
+ }
+ }
+ else if (element instanceof IAdaptable)
+ {
+ IWorkbenchAdapter wbadapter =
+ (IWorkbenchAdapter)((IAdaptable)element).getAdapter(
+ IWorkbenchAdapter.class);
+ if (wbadapter != null)
+ {
+ return wbadapter.getLabel(element);
+ }
+ }
+ return super.getText(element);
+ };
+
+ @Override
+ public Image getImage(Object element)
+ {
+ try
+ {
+ return imageProvider.getImage(element);
+ }
+ catch (CoreException e)
+ {
+ Activator.log(e.getStatus());
+ }
+ return super.getImage(element);
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/Activator.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/Activator.java
index 60408a07..88b5b9de 100644
--- a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/Activator.java
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 1C-Soft LLC.
+ * Copyright (c) 2015 1C-Soft LLC and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,14 +7,22 @@
*
* Contributors:
* Vladimir Piskarev (1C) - initial API and implementation
+ * Ondrej Ilcik (Codasip)
*******************************************************************************/
package org.eclipse.handly.internal.examples.javamodel.ui;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.handly.internal.examples.javamodel.ui.preferences.MembersOrderPreferenceCache;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.BundleContext;
/**
- * The activator class controls the plug-in life cycle
+ * The activator class controls the plug-in life cycle.
*/
public class Activator
extends AbstractUIPlugin
@@ -24,27 +32,89 @@ public class Activator
private static Activator plugin;
+ private ImageDescriptorRegistry imageDescriptorRegistry;
+ private MembersOrderPreferenceCache membersOrderPreferenceCache;
+
@Override
public void start(BundleContext context) throws Exception
{
super.start(context);
plugin = this;
+
+ imageDescriptorRegistry = new ImageDescriptorRegistry();
+ membersOrderPreferenceCache = new MembersOrderPreferenceCache();
+ membersOrderPreferenceCache.install(getJavaPreferenceStore());
}
@Override
public void stop(BundleContext context) throws Exception
{
- plugin = null;
- super.stop(context);
+ try
+ {
+ if (membersOrderPreferenceCache != null)
+ {
+ membersOrderPreferenceCache.dispose();
+ membersOrderPreferenceCache = null;
+ }
+ if (imageDescriptorRegistry != null)
+ {
+ imageDescriptorRegistry.dispose();
+ imageDescriptorRegistry = null;
+ }
+ }
+ finally
+ {
+ plugin = null;
+ super.stop(context);
+ }
}
/**
- * Returns the shared instance
+ * Returns the shared instance of this plug-in.
*
- * @return the shared instance
+ * @return the shared instance of this plug-in
*/
public static Activator getDefault()
{
return plugin;
}
+
+ /**
+ * Returns the image descriptor registry for this plug-in.
+ *
+ * @return registry
+ */
+ public static ImageDescriptorRegistry getImageDescriptorRegistry()
+ {
+ return getDefault().imageDescriptorRegistry;
+ }
+
+ /**
+ * Returns cached preferences for Java element member ordering.
+ *
+ * @return preferences
+ */
+ public static MembersOrderPreferenceCache getMemberOrderPreferenceCache()
+ {
+ return getDefault().membersOrderPreferenceCache;
+ }
+
+ public static void log(IStatus status)
+ {
+ getDefault().getLog().log(status);
+ }
+
+ public static IStatus createErrorStatus(String msg, Throwable e)
+ {
+ return new Status(IStatus.ERROR, PLUGIN_ID, 0, msg, e);
+ }
+
+ /*
+ * Returns preference store for JDT UI plug-in.
+ */
+ private IPreferenceStore getJavaPreferenceStore()
+ {
+ return new ScopedPreferenceStore(InstanceScope.INSTANCE,
+ JavaUI.ID_PLUGIN);
+ }
}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/IJavaImages.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/IJavaImages.java
new file mode 100644
index 00000000..2ae975c8
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/IJavaImages.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+/**
+ * Paths to Java element icons stored in this plug-in.
+ * These icons are not provided as shared images by JDT UI plug-in.
+ */
+public interface IJavaImages
+{
+ String IMG_OBJS_CUNIT_RESOURCE = "icons/obj16/jcu_resource_obj.gif"; //$NON-NLS-1$
+ String IMG_OBJS_UNKNOWN = "icons/obj16/unknown_obj.gif"; //$NON-NLS-1$
+ String IMG_OBJS_JAVA_MODEL = "icons/obj16/java_model_obj.gif"; //$NON-NLS-1$
+ String IMG_OBJS_EMPTY_PACK_RESOURCE = "icons/obj16/empty_pack_fldr_obj.gif"; //$NON-NLS-1$
+ String IMG_OVR_ABSTRACT = "icons/ovr16/abstract_co.gif"; //$NON-NLS-1$
+ String IMG_OVR_CONSTRUCTOR = "icons/ovr16/constr_ovr.gif"; //$NON-NLS-1$
+ String IMG_OVR_FINAL = "icons/ovr16/final_co.gif"; //$NON-NLS-1$
+ String IMG_OVR_IMPLEMENTS = "icons/ovr16/implm_co.gif"; //$NON-NLS-1$
+ String IMG_OVR_NATIVE = "icons/ovr16/native_co.gif"; //$NON-NLS-1$
+ String IMG_OVR_STATIC = "icons/ovr16/static_co.gif"; //$NON-NLS-1$
+ String IMG_OVR_SYNCH_AND_IMPLEMENTS = "icons/ovr16/sync_impl.gif"; //$NON-NLS-1$
+ String IMG_OVR_SYNCH = "icons/ovr16/synch_co.gif"; //$NON-NLS-1$
+ String IMG_OVR_TRANSIENT = "icons/ovr16/transient_co.gif"; //$NON-NLS-1$
+ String IMG_OVR_VOLATILE = "icons/ovr16/volatile_co.gif"; //$NON-NLS-1$
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/ImageDescriptorRegistry.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/ImageDescriptorRegistry.java
new file mode 100644
index 00000000..ea161b06
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/ImageDescriptorRegistry.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.debug.internal.ui.ImageDescriptorRegistry)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * A registry that maps <code>ImageDescriptor</code>s to <code>Image</code>s.
+ */
+public class ImageDescriptorRegistry
+{
+ private HashMap<ImageDescriptor, Image> fRegistry =
+ new HashMap<ImageDescriptor, Image>(10);
+ private Display fDisplay;
+
+ /**
+ * Creates a new image descriptor registry for the given display. All images
+ * managed by this registry will be disposed when the display gets disposed.
+ */
+ public ImageDescriptorRegistry()
+ {
+ fDisplay = PlatformUI.getWorkbench().getDisplay();
+ Assert.isNotNull(fDisplay);
+ hookDisplay();
+ }
+
+ /**
+ * Returns the image associated with the given image descriptor.
+ *
+ * @param descriptor the image descriptor for which the registry manages an image,
+ * or <code>null</code> for a missing image descriptor
+ * @return the image associated with the image descriptor or <code>null</code>
+ * if the image descriptor can't create the requested image.
+ */
+ public Image get(ImageDescriptor descriptor)
+ {
+ if (descriptor == null)
+ descriptor = ImageDescriptor.getMissingImageDescriptor();
+
+ Image result = fRegistry.get(descriptor);
+ if (result != null)
+ return result;
+
+ result = descriptor.createImage();
+ if (result != null)
+ fRegistry.put(descriptor, result);
+ return result;
+ }
+
+ /**
+ * Disposes all images managed by this registry.
+ */
+ public void dispose()
+ {
+ for (Iterator<Image> iter =
+ fRegistry.values().iterator(); iter.hasNext();)
+ {
+ Image image = iter.next();
+ image.dispose();
+ }
+ fRegistry.clear();
+ }
+
+ private void hookDisplay()
+ {
+ fDisplay.disposeExec(new Runnable()
+ {
+ public void run()
+ {
+ dispose();
+ }
+ });
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementAdapterFactory.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementAdapterFactory.java
new file mode 100644
index 00000000..f32d9dcf
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementAdapterFactory.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.handly.examples.javamodel.ICompilationUnit;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.IJavaModel;
+import org.eclipse.handly.examples.javamodel.IJavaProject;
+import org.eclipse.handly.examples.javamodel.IPackageFragment;
+import org.eclipse.handly.examples.javamodel.IPackageFragmentRoot;
+import org.eclipse.handly.examples.javamodel.IType;
+import org.eclipse.ui.IContainmentAdapter;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * Adapts Java elements to various other types.
+ */
+public class JavaElementAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ IResource.class, IPersistableElement.class, IContainmentAdapter.class };
+
+ private static final IContainmentAdapter CONTAINMENT_ADAPTER =
+ new JavaElementContainmentAdapter();
+
+ @Override
+ public Class<?>[] getAdapterList()
+ {
+ return ADAPTER_LIST;
+ }
+
+ @Override
+ public Object getAdapter(Object element,
+ @SuppressWarnings("rawtypes") Class adapterType)
+ {
+ IJavaElement java = (IJavaElement)element;
+ if (IResource.class.equals(adapterType))
+ {
+ return getResource(java);
+ }
+ else if (IPersistableElement.class.equals(adapterType))
+ {
+ return new PersistableJavaElementFactory(java);
+ }
+ else if (IContainmentAdapter.class.equals(adapterType))
+ {
+ return CONTAINMENT_ADAPTER;
+ }
+ return null;
+ }
+
+ private IResource getResource(IJavaElement element)
+ {
+ if (element instanceof IType)
+ {
+ // top level types behave like the CU
+ IJavaElement parent = element.getParent();
+ if (parent instanceof ICompilationUnit)
+ {
+ return ((ICompilationUnit)parent).getResource();
+ }
+ }
+ else if (element instanceof ICompilationUnit)
+ {
+ return ((ICompilationUnit)element).getResource();
+ }
+ else if (element instanceof IPackageFragment
+ || element instanceof IPackageFragmentRoot
+ || element instanceof IJavaProject || element instanceof IJavaModel)
+ {
+ return element.getResource();
+ }
+ return null;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementComparator.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementComparator.java
new file mode 100644
index 00000000..f17665ab
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementComparator.java
@@ -0,0 +1,191 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.jdt.ui.JavaElementComparator)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.handly.examples.javamodel.ICompilationUnit;
+import org.eclipse.handly.examples.javamodel.IField;
+import org.eclipse.handly.examples.javamodel.IImportContainer;
+import org.eclipse.handly.examples.javamodel.IImportDeclaration;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.IJavaProject;
+import org.eclipse.handly.examples.javamodel.IMember;
+import org.eclipse.handly.examples.javamodel.IMethod;
+import org.eclipse.handly.examples.javamodel.IPackageDeclaration;
+import org.eclipse.handly.examples.javamodel.IPackageFragment;
+import org.eclipse.handly.examples.javamodel.IPackageFragmentRoot;
+import org.eclipse.handly.examples.javamodel.IType;
+import org.eclipse.handly.internal.examples.javamodel.ui.preferences.MembersOrderPreferenceCache;
+import org.eclipse.handly.internal.examples.javamodel.ui.util.JavaFlags;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+
+/**
+ * Viewer comparator for Java elements.
+ */
+public class JavaElementComparator
+ extends ViewerComparator
+{
+ private static final int PROJECTS = 1;
+ private static final int PACKAGEFRAGMENTROOTS = 2;
+ private static final int PACKAGEFRAGMENT = 3;
+
+ private static final int COMPILATIONUNITS = 4;
+
+ private static final int RESOURCEFOLDERS = 7;
+ private static final int RESOURCES = 8;
+
+ private static final int PACKAGE_DECL = 10;
+ private static final int IMPORT_CONTAINER = 11;
+ private static final int IMPORT_DECLARATION = 12;
+
+ // Includes all categories ordered using the OutlineSortOrderPage:
+ // types, initializers, methods & fields
+ private static final int MEMBERSOFFSET = 15;
+
+ private static final int JAVAELEMENTS = 50;
+ private static final int OTHERS = 51;
+
+ private MembersOrderPreferenceCache memberOrderCache =
+ Activator.getMemberOrderPreferenceCache();
+
+ @Override
+ public int category(Object element)
+ {
+ try
+ {
+ if (element instanceof IJavaElement)
+ {
+ if (element instanceof IMethod)
+ {
+ IMethod method = (IMethod)element;
+ if (method.isConstructor())
+ {
+ return getMemberCategory(
+ MembersOrderPreferenceCache.CONSTRUCTORS_INDEX);
+ }
+ int flags = method.getFlags();
+ if (Flags.isStatic(flags))
+ return getMemberCategory(
+ MembersOrderPreferenceCache.STATIC_METHODS_INDEX);
+ else
+ return getMemberCategory(
+ MembersOrderPreferenceCache.METHOD_INDEX);
+ }
+ else if (element instanceof IField)
+ {
+ int flags = ((IField)element).getFlags();
+ if (Flags.isEnum(flags))
+ {
+ return getMemberCategory(
+ MembersOrderPreferenceCache.ENUM_CONSTANTS_INDEX);
+ }
+ if (Flags.isStatic(flags))
+ return getMemberCategory(
+ MembersOrderPreferenceCache.STATIC_FIELDS_INDEX);
+ else
+ return getMemberCategory(
+ MembersOrderPreferenceCache.FIELDS_INDEX);
+ }
+ else if (element instanceof IType)
+ {
+ return getMemberCategory(
+ MembersOrderPreferenceCache.TYPE_INDEX);
+ }
+ else if (element instanceof IPackageDeclaration)
+ {
+ return PACKAGE_DECL;
+ }
+ else if (element instanceof IImportContainer)
+ {
+ return IMPORT_CONTAINER;
+ }
+ else if (element instanceof IImportDeclaration)
+ {
+ return IMPORT_DECLARATION;
+ }
+ else if (element instanceof IPackageFragment)
+ {
+ return PACKAGEFRAGMENT;
+ }
+ else if (element instanceof IPackageFragmentRoot)
+ {
+ return PACKAGEFRAGMENTROOTS;
+ }
+ else if (element instanceof IJavaProject)
+ {
+ return PROJECTS;
+ }
+ else if (element instanceof ICompilationUnit)
+ {
+ return COMPILATIONUNITS;
+ }
+ return JAVAELEMENTS;
+ }
+ else if (element instanceof IFile)
+ {
+ return RESOURCES;
+ }
+ else if (element instanceof IProject)
+ {
+ return PROJECTS;
+ }
+ else if (element instanceof IContainer)
+ {
+ return RESOURCEFOLDERS;
+ }
+ }
+ catch (CoreException e)
+ {
+ Activator.log(e.getStatus());
+ }
+ return OTHERS;
+ }
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2)
+ {
+ if (e1 instanceof IMember)
+ {
+ if (memberOrderCache.isSortByVisibility())
+ {
+ try
+ {
+ int flags1 = JavaFlags.getVisibilityCode((IMember)e1);
+ int flags2 = JavaFlags.getVisibilityCode((IMember)e2);
+ int vis = memberOrderCache.getVisibilityIndex(flags1)
+ - memberOrderCache.getVisibilityIndex(flags2);
+ if (vis != 0)
+ {
+ return vis;
+ }
+ }
+ catch (CoreException e)
+ {
+ Activator.log(e.getStatus());
+ }
+ }
+ }
+ return super.compare(viewer, e1, e2);
+ }
+
+ private int getMemberCategory(int kind)
+ {
+ int offset = memberOrderCache.getCategoryIndex(kind);
+ return offset + MEMBERSOFFSET;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementContainmentAdapter.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementContainmentAdapter.java
new file mode 100644
index 00000000..3b5c9808
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementContainmentAdapter.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.handly.model.IHandle;
+import org.eclipse.handly.ui.workingset.AbstractContainmentAdapter;
+
+/**
+ * Containment adapter for Java elements.
+ */
+public class JavaElementContainmentAdapter
+ extends AbstractContainmentAdapter
+{
+ @Override
+ protected IHandle getElementFor(IResource resource)
+ {
+ IJavaElement element = JavaModelCore.create(resource);
+ if (element != null && element.exists())
+ return element;
+ return null;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementImageDescriptor.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementImageDescriptor.java
new file mode 100644
index 00000000..c1049453
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementImageDescriptor.java
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.jdt.ui.JavaElementImageDescriptor)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.CompositeImageDescriptor;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * A <code>JavaElementImageDescriptor</code> consists of a base image and several
+ * adornments. The adornments are computed according to the flags either passed
+ * during creation or set via the method {@link #setAdornments(int)}.
+ */
+public class JavaElementImageDescriptor
+ extends CompositeImageDescriptor
+{
+ public static final Point SMALL_SIZE = new Point(16, 16);
+
+ /** Flag to render the abstract adornment. */
+ public static final int ABSTRACT = 0x001;
+
+ /** Flag to render the final adornment. */
+ public static final int FINAL = 0x002;
+
+ /** Flag to render the synchronized adornment. */
+ public static final int SYNCHRONIZED = 0x004;
+
+ /** Flag to render the static adornment. */
+ public static final int STATIC = 0x008;
+
+ /** Flag to render the 'implements' adornment. */
+ public static final int IMPLEMENTS = 0x100;
+
+ /** Flag to render the 'constructor' adornment. */
+ public static final int CONSTRUCTOR = 0x200;
+
+ /** Flag to render the 'volatile' adornment. */
+ public static final int VOLATILE = 0x800;
+
+ /** Flag to render the 'transient' adornment. */
+ public static final int TRANSIENT = 0x1000;
+
+ /** Flag to render the 'native' adornment. */
+ public static final int NATIVE = 0x4000;
+
+ private ImageDescriptor fBaseImage;
+ private int fFlags;
+
+ /**
+ * Creates a new JavaElementImageDescriptor.
+ *
+ * @param baseImage an image descriptor used as the base image
+ * @param flags flags indicating which adornments are to be rendered.
+ * See {@link #setAdornments(int)} for valid values.
+ */
+ public JavaElementImageDescriptor(ImageDescriptor baseImage, int flags)
+ {
+ fBaseImage = baseImage;
+ Assert.isNotNull(fBaseImage);
+ fFlags = flags;
+ Assert.isTrue(fFlags >= 0);
+ }
+
+ /**
+ * Sets the descriptors adornments. Valid values are: {@link #ABSTRACT},
+ * {@link #FINAL}, {@link #SYNCHRONIZED}, {@link #STATIC}, {@link #IMPLEMENTS},
+ * {@link #CONSTRUCTOR}, {@link #VOLATILE}, {@link #TRANSIENT}, {@link #NATIVE},
+ * or any combination of those.
+ *
+ * @param adornments the image descriptors adornments
+ */
+ public void setAdornments(int adornments)
+ {
+ Assert.isTrue(adornments >= 0);
+ fFlags = adornments;
+ }
+
+ /**
+ * Returns the current adornments.
+ *
+ * @return the current adornments
+ */
+ public int getAdronments()
+ {
+ return fFlags;
+ }
+
+ @Override
+ public boolean equals(Object object)
+ {
+ if (object == null || !JavaElementImageDescriptor.class.equals(
+ object.getClass()))
+ {
+ return false;
+ }
+ JavaElementImageDescriptor other = (JavaElementImageDescriptor)object;
+ return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return fBaseImage.hashCode() | fFlags;
+ }
+
+ @Override
+ protected Point getSize()
+ {
+ return SMALL_SIZE;
+ }
+
+ @Override
+ protected void drawCompositeImage(int width, int height)
+ {
+ ImageData bg = getImageData(fBaseImage);
+ drawImage(bg, 0, 0);
+ drawTopRight();
+ drawBottomRight();
+ }
+
+ private ImageData getImageData(ImageDescriptor descriptor)
+ {
+ ImageData data = descriptor.getImageData(); // see bug 51965: getImageData can return null
+ if (data == null)
+ {
+ data = DEFAULT_IMAGE_DATA;
+ Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "Image data not available: " + descriptor.toString()));
+ }
+ return data;
+ }
+
+ private void addTopRightImage(ImageDescriptor desc, Point pos)
+ {
+ ImageData data = getImageData(desc);
+ int x = pos.x - data.width;
+ if (x >= 0)
+ {
+ drawImage(data, x, pos.y);
+ pos.x = x;
+ }
+ }
+
+ private void addBottomRightImage(ImageDescriptor desc, Point pos)
+ {
+ ImageData data = getImageData(desc);
+ int x = pos.x - data.width;
+ int y = pos.y - data.height;
+ if (x >= 0 && y >= 0)
+ {
+ drawImage(data, x, y);
+ pos.x = x;
+ }
+ }
+
+ private void drawTopRight()
+ {
+ Point pos = new Point(getSize().x, 0);
+ if ((fFlags & ABSTRACT) != 0)
+ {
+ addTopRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_ABSTRACT), pos);
+ }
+ if ((fFlags & CONSTRUCTOR) != 0)
+ {
+ addTopRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_CONSTRUCTOR), pos);
+ }
+ if ((fFlags & FINAL) != 0)
+ {
+ addTopRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_FINAL), pos);
+ }
+ if ((fFlags & VOLATILE) != 0)
+ {
+ addTopRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_VOLATILE), pos);
+ }
+ if ((fFlags & STATIC) != 0)
+ {
+ addTopRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_STATIC), pos);
+ }
+ if ((fFlags & NATIVE) != 0)
+ {
+ addTopRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_NATIVE), pos);
+ }
+ }
+
+ private void drawBottomRight()
+ {
+ Point size = getSize();
+ Point pos = new Point(size.x, size.y);
+
+ int flags = fFlags;
+
+ int syncAndImpl = SYNCHRONIZED | IMPLEMENTS;
+ if ((flags & syncAndImpl) == syncAndImpl)
+ {
+ // both flags set: merged overlay image
+ addBottomRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_SYNCH_AND_IMPLEMENTS),
+ pos);
+ flags &= ~syncAndImpl; // clear to not render again
+ }
+ if ((flags & IMPLEMENTS) != 0)
+ {
+ addBottomRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_IMPLEMENTS), pos);
+ }
+ if ((flags & SYNCHRONIZED) != 0)
+ {
+ addBottomRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_SYNCH), pos);
+ }
+
+ // fields:
+ if ((flags & TRANSIENT) != 0)
+ {
+ addBottomRightImage(Activator.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID, IJavaImages.IMG_OVR_TRANSIENT), pos);
+ }
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementImageProvider.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementImageProvider.java
new file mode 100644
index 00000000..f001d891
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementImageProvider.java
@@ -0,0 +1,545 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.handly.examples.javamodel.ICompilationUnit;
+import org.eclipse.handly.examples.javamodel.IField;
+import org.eclipse.handly.examples.javamodel.IImportContainer;
+import org.eclipse.handly.examples.javamodel.IImportDeclaration;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.IJavaModel;
+import org.eclipse.handly.examples.javamodel.IJavaProject;
+import org.eclipse.handly.examples.javamodel.IMember;
+import org.eclipse.handly.examples.javamodel.IMethod;
+import org.eclipse.handly.examples.javamodel.IPackageDeclaration;
+import org.eclipse.handly.examples.javamodel.IPackageFragment;
+import org.eclipse.handly.examples.javamodel.IPackageFragmentRoot;
+import org.eclipse.handly.examples.javamodel.IType;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.ui.ISharedImages;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+/**
+ * Default strategy for construction of Java element icons.
+ */
+public class JavaElementImageProvider
+{
+ public Image getImage(Object element) throws CoreException
+ {
+ ImageDescriptor descriptor = getDescriptor(element);
+ if (descriptor == null)
+ return null;
+ return getRegistry().get(descriptor);
+ }
+
+ private static ImageDescriptor getDescriptor(Object element)
+ throws CoreException
+ {
+ if (element instanceof IJavaElement)
+ {
+ return getJavaImageDescriptor((IJavaElement)element);
+ }
+ else if (element instanceof IFile)
+ {
+ IFile file = (IFile)element;
+ if (JavaCore.isJavaLikeFileName(file.getName()))
+ {
+ return getCUResourceImageDescriptor(file);
+ }
+ return getWorkbenchImageDescriptor(file);
+ }
+ else if (element instanceof IAdaptable)
+ {
+ return getWorkbenchImageDescriptor((IAdaptable)element);
+ }
+ return null;
+ }
+
+ private static ImageDescriptor getWorkbenchImageDescriptor(
+ IAdaptable adaptable)
+ {
+ IWorkbenchAdapter wbAdapter = (IWorkbenchAdapter)adaptable.getAdapter(
+ IWorkbenchAdapter.class);
+ if (wbAdapter == null)
+ {
+ return null;
+ }
+ return wbAdapter.getImageDescriptor(adaptable);
+ }
+
+ /*
+ * Returns an image descriptor for a Java source file which is not on the
+ * project build path.
+ *
+ * @param file
+ * @return descriptor
+ */
+ private static ImageDescriptor getCUResourceImageDescriptor(IFile file)
+ {
+ return Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
+ IJavaImages.IMG_OBJS_CUNIT_RESOURCE);
+ }
+
+ private static ImageDescriptor getJavaImageDescriptor(IJavaElement element)
+ throws CoreException
+ {
+ ImageDescriptor baseDesc = getBaseImageDescriptor(element);
+ if (baseDesc != null)
+ {
+ int adornmentFlags = computeJavaAdornmentFlags(element);
+ return new JavaElementImageDescriptor(baseDesc, adornmentFlags);
+ }
+ return null;
+ }
+
+ /*
+ * Returns an image descriptor for a java element. This is the base image,
+ * no overlays.
+ *
+ * @param element the element
+ * @return returns the image descriptor
+ * @throws CoreException
+ */
+ private static ImageDescriptor getBaseImageDescriptor(IJavaElement element)
+ throws CoreException
+ {
+ if (element instanceof IMethod)
+ {
+ IMethod method = (IMethod)element;
+ IType declType = method.getDeclaringType();
+ int flags = method.getFlags();
+ if (declType.isEnum() && isDefaultFlag(flags)
+ && method.isConstructor())
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_PRIVATE);
+ return getMethodImageDescriptor(declType.isInterface()
+ || declType.isAnnotation(), flags);
+ }
+ else if (element instanceof IField)
+ {
+ IMember member = (IMember)element;
+ IType declType = member.getDeclaringType();
+ return getFieldImageDescriptor(declType.isInterface()
+ || declType.isAnnotation(), member.getFlags());
+ }
+ else if (element instanceof IPackageDeclaration)
+ {
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_PACKDECL);
+ }
+ else if (element instanceof IImportDeclaration)
+ {
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_IMPDECL);
+ }
+ else if (element instanceof IImportContainer)
+ {
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_IMPCONT);
+ }
+ else if (element instanceof IType)
+ {
+ IType type = (IType)element;
+
+ IType declType = type.getDeclaringType();
+ boolean isInner = declType != null;
+ boolean isInInterfaceOrAnnotation = isInner
+ && (declType.isInterface() || declType.isAnnotation());
+ return getTypeImageDescriptor(isInner, isInInterfaceOrAnnotation,
+ type.getFlags());
+ }
+ else if (element instanceof IPackageFragmentRoot)
+ {
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_PACKFRAG_ROOT);
+ }
+ else if (element instanceof IPackageFragment)
+ {
+ return getPackageFragmentIcon(element);
+ }
+ else if (element instanceof ICompilationUnit)
+ {
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_CUNIT);
+ }
+ else if (element instanceof IJavaProject)
+ {
+ IJavaProject jp = (IJavaProject)element;
+ if (jp.getProject().isOpen())
+ {
+ IProject project = jp.getProject();
+ IWorkbenchAdapter adapter =
+ (IWorkbenchAdapter)project.getAdapter(
+ IWorkbenchAdapter.class);
+ if (adapter != null)
+ {
+ ImageDescriptor result = adapter.getImageDescriptor(
+ project);
+ if (result != null)
+ return result;
+ }
+ return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
+ IDE.SharedImages.IMG_OBJ_PROJECT);
+ }
+ return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
+ IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED);
+ }
+ else if (element instanceof IJavaModel)
+ {
+ return Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
+ IJavaImages.IMG_OBJS_JAVA_MODEL);
+ }
+ else
+ {
+ IWorkbenchAdapter wbAdapter = (IWorkbenchAdapter)element.getAdapter(
+ IWorkbenchAdapter.class);
+ if (wbAdapter != null)
+ {
+ ImageDescriptor imageDescriptor = wbAdapter.getImageDescriptor(
+ element);
+ if (imageDescriptor != null)
+ {
+ return imageDescriptor;
+ }
+ }
+ return null;
+ }
+ }
+
+ private static int computeJavaAdornmentFlags(IJavaElement element)
+ throws CoreException
+ {
+ int flags = 0;
+ try
+ {
+ if (element instanceof IMember)
+ {
+ IMember member = (IMember)element;
+
+ int modifiers = member.getFlags();
+ if (Flags.isAbstract(modifiers) && confirmAbstract(member))
+ flags |= JavaElementImageDescriptor.ABSTRACT;
+ if (Flags.isFinal(modifiers) || isInterfaceOrAnnotationField(
+ member) || isEnumConstant(member, modifiers))
+ flags |= JavaElementImageDescriptor.FINAL;
+ if (Flags.isStatic(modifiers)
+ || isInterfaceOrAnnotationFieldOrType(member)
+ || isEnumConstant(member, modifiers))
+ flags |= JavaElementImageDescriptor.STATIC;
+
+ if (element instanceof IMethod)
+ {
+ if (((IMethod)element).isConstructor())
+ flags |= JavaElementImageDescriptor.CONSTRUCTOR;
+ if (Flags.isSynchronized(modifiers)) // collides with 'super' flag
+ flags |= JavaElementImageDescriptor.SYNCHRONIZED;
+ if (Flags.isNative(modifiers))
+ flags |= JavaElementImageDescriptor.NATIVE;
+ }
+
+ if (element instanceof IField)
+ {
+ if (Flags.isVolatile(modifiers))
+ flags |= JavaElementImageDescriptor.VOLATILE;
+ if (Flags.isTransient(modifiers))
+ flags |= JavaElementImageDescriptor.TRANSIENT;
+ }
+ }
+ }
+ catch (CoreException e)
+ {
+ // do nothing. Can't compute runnable adornment or get flags
+ Activator.log(e.getStatus());
+ }
+ return flags;
+ }
+
+ private static ImageDescriptorRegistry getRegistry()
+ {
+ return Activator.getImageDescriptorRegistry();
+ }
+
+ private static boolean isDefaultFlag(int flags)
+ {
+ return !Flags.isPublic(flags) && !Flags.isProtected(flags)
+ && !Flags.isPrivate(flags);
+ }
+
+ private static ImageDescriptor getMethodImageDescriptor(
+ boolean isInterfaceOrAnnotation, int flags)
+ {
+ if (Flags.isPublic(flags) || isInterfaceOrAnnotation)
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_PUBLIC);
+ if (Flags.isProtected(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_PROTECTED);
+ if (Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_PRIVATE);
+
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_DEFAULT);
+ }
+
+ private static ImageDescriptor getFieldImageDescriptor(
+ boolean isInInterfaceOrAnnotation, int flags)
+ {
+ if (Flags.isPublic(flags) || isInInterfaceOrAnnotation || Flags.isEnum(
+ flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_FIELD_PUBLIC);
+ if (Flags.isProtected(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_FIELD_PROTECTED);
+ if (Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_FIELD_PRIVATE);
+
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_FIELD_PRIVATE);
+ }
+
+ private static ImageDescriptor getPackageFragmentIcon(IJavaElement element)
+ throws CoreException
+ {
+ IPackageFragment fragment = (IPackageFragment)element;
+ boolean containsJavaElements = false;
+ boolean containsNonJavaElements = false;
+ try
+ {
+ containsJavaElements = fragment.getCompilationUnits().length > 0;
+ containsNonJavaElements = fragment.getNonJavaResources().length > 0;
+ }
+ catch (CoreException e)
+ {
+ // log and assume no children
+ Activator.log(e.getStatus());
+ }
+ if (!containsJavaElements && containsNonJavaElements)
+ return Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
+ IJavaImages.IMG_OBJS_EMPTY_PACK_RESOURCE);
+ else if (!containsJavaElements)
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_EMPTY_PACKAGE);
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_PACKAGE);
+ }
+
+ private static ImageDescriptor getTypeImageDescriptor(boolean isInner,
+ boolean isInInterfaceOrAnnotation, int flags)
+ {
+ if (Flags.isEnum(flags))
+ {
+ if (isInner)
+ {
+ return getInnerEnumImageDescriptor(isInInterfaceOrAnnotation,
+ flags);
+ }
+ return getEnumImageDescriptor(flags);
+ }
+ else if (Flags.isAnnotation(flags))
+ {
+ if (isInner)
+ {
+ return getInnerAnnotationImageDescriptor(
+ isInInterfaceOrAnnotation, flags);
+ }
+ return getAnnotationImageDescriptor(flags);
+ }
+ else if (Flags.isInterface(flags))
+ {
+ if (isInner)
+ {
+ return getInnerInterfaceImageDescriptor(
+ isInInterfaceOrAnnotation, flags);
+ }
+ return getInterfaceImageDescriptor(flags);
+ }
+ else
+ {
+ if (isInner)
+ {
+ return getInnerClassImageDescriptor(isInInterfaceOrAnnotation,
+ flags);
+ }
+ return getClassImageDescriptor(flags);
+ }
+ }
+
+ private static ImageDescriptor getClassImageDescriptor(int flags)
+ {
+ if (Flags.isPublic(flags) || Flags.isProtected(flags)
+ || Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_CLASS);
+ else
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_CLASS_DEFAULT);
+ }
+
+ private static ImageDescriptor getInnerClassImageDescriptor(
+ boolean isInInterfaceOrAnnotation, int flags)
+ {
+ if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INNER_CLASS_PUBLIC);
+ else if (Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INNER_CLASS_PRIVATE);
+ else if (Flags.isProtected(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INNER_CLASS_PROTECTED);
+ else
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INNER_CLASS_DEFAULT);
+ }
+
+ private static ImageDescriptor getInnerEnumImageDescriptor(
+ boolean isInInterfaceOrAnnotation, int flags)
+ {
+ if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ENUM);
+ else if (Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ENUM_PRIVATE);
+ else if (Flags.isProtected(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ENUM_PROTECTED);
+ else
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ENUM_DEFAULT);
+ }
+
+ private static ImageDescriptor getEnumImageDescriptor(int flags)
+ {
+ if (Flags.isPublic(flags) || Flags.isProtected(flags)
+ || Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ENUM);
+ else
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ENUM_DEFAULT);
+ }
+
+ private static ImageDescriptor getAnnotationImageDescriptor(int flags)
+ {
+ if (Flags.isPublic(flags) || Flags.isProtected(flags)
+ || Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ANNOTATION);
+ else
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ANNOTATION_DEFAULT);
+ }
+
+ private static ImageDescriptor getInnerAnnotationImageDescriptor(
+ boolean isInInterfaceOrAnnotation, int flags)
+ {
+ if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ANNOTATION);
+ else if (Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ANNOTATION_PRIVATE);
+ else if (Flags.isProtected(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ANNOTATION_PROTECTED);
+ else
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_ANNOTATION_DEFAULT);
+ }
+
+ private static ImageDescriptor getInterfaceImageDescriptor(int flags)
+ {
+ if (Flags.isPublic(flags) || Flags.isProtected(flags)
+ || Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INTERFACE);
+ else
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INTERFACE_DEFAULT);
+ }
+
+ private static ImageDescriptor getInnerInterfaceImageDescriptor(
+ boolean isInInterfaceOrAnnotation, int flags)
+ {
+ if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INNER_INTERFACE_PUBLIC);
+ else if (Flags.isPrivate(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INNER_INTERFACE_PRIVATE);
+ else if (Flags.isProtected(flags))
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INNER_INTERFACE_PROTECTED);
+ else
+ return JavaUI.getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_OBJS_INTERFACE_DEFAULT);
+ }
+
+ private static boolean confirmAbstract(IMember element) throws CoreException
+ {
+ if (element instanceof IType)
+ {
+ return !((IType)element).isInterface();
+ }
+ return !element.getDeclaringType().isInterface();
+ }
+
+ private static boolean isEnumConstant(IMember element, int modifiers)
+ {
+ if (element instanceof IField)
+ {
+ return Flags.isEnum(modifiers);
+ }
+ return false;
+ }
+
+ private static boolean isInterfaceOrAnnotationField(IMember element)
+ throws CoreException
+ {
+ // always show the final symbol on interface fields
+ if (element instanceof IField)
+ {
+ return element.getDeclaringType().isInterface();
+ }
+ return false;
+ }
+
+ private static boolean isInterfaceOrAnnotationFieldOrType(IMember element)
+ throws CoreException
+ {
+ // always show the static symbol on interface fields and types
+ if (element instanceof IField)
+ {
+ return element.getDeclaringType().isInterface();
+ }
+ else if (element instanceof IType && element.getDeclaringType() != null)
+ {
+ return element.getDeclaringType().isInterface();
+ }
+ return false;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementLabelComposer.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementLabelComposer.java
new file mode 100644
index 00000000..1d11c84d
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementLabelComposer.java
@@ -0,0 +1,312 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabelComposer)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.IMethod;
+import org.eclipse.handly.examples.javamodel.IPackageFragment;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.jdt.ui.JavaElementLabels;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.StyledString.Styler;
+
+/**
+ * Label composer for Java elements.
+ */
+public class JavaElementLabelComposer
+{
+ private final Object buffer;
+
+ /**
+ * Constructs a string-based label composer.
+ *
+ * @param sb string builder to fill (not <code>null</code>)
+ */
+ public static JavaElementLabelComposer create(StringBuilder sb)
+ {
+ Assert.isNotNull(sb);
+ return new JavaElementLabelComposer(sb);
+ }
+
+ /**
+ * Constructs a {@link StyledString}-based label composer.
+ *
+ * @param ss styled string to fill (not <code>null</code>)
+ */
+ public static JavaElementLabelComposer create(StyledString ss)
+ {
+ Assert.isNotNull(ss);
+ return new JavaElementLabelComposer(ss);
+ }
+
+ private JavaElementLabelComposer(Object buffer)
+ {
+ this.buffer = buffer;
+ }
+
+ /**
+ * Appends label for the specified Java element.
+ *
+ * @param element a Java element (not <code>null</code>)
+ * @throws CoreException
+ */
+ public void appendElementLabel(IJavaElement element) throws CoreException
+ {
+ if (element instanceof IMethod)
+ {
+ appendMethodLabel((IMethod)element);
+ }
+ else if (element instanceof IPackageFragment)
+ {
+ appendPackageFragmentLabel((IPackageFragment)element);
+ }
+ else
+ {
+ append(element.getName());
+ }
+ }
+
+ private void appendMethodLabel(IMethod method) throws CoreException
+ {
+ append(method.getName());
+
+ // parameters
+ append('(');
+ String[] paramTypes = method.getParameterTypes();
+ for (int i = 0; i < paramTypes.length; i++)
+ {
+ if (i > 0)
+ append(JavaElementLabels.COMMA_STRING);
+
+ String simpleName = getSimpleTypeName(method, paramTypes[i]);
+ append(simpleName);
+ }
+ append(')');
+
+ // exceptions
+ String[] exceptionTypes = method.getExceptionTypes();
+ if (exceptionTypes.length > 0)
+ {
+ append(" throws "); //$NON-NLS-1$
+ for (int i = 0; i < exceptionTypes.length; i++)
+ {
+ if (i > 0)
+ append(JavaElementLabels.COMMA_STRING);
+
+ String simpleName = getSimpleTypeName(method,
+ exceptionTypes[i]);
+ append(simpleName);
+ }
+ }
+
+ // return type
+ if (!method.isConstructor())
+ {
+ int offset = getLength();
+ append(JavaElementLabels.DECL_STRING);
+ appendTypeSignatureLabel(method, method.getReturnType());
+ setStyle(offset, getLength() - offset,
+ StyledString.DECORATIONS_STYLER);
+ }
+ }
+
+ private void appendPackageFragmentLabel(IPackageFragment pack)
+ {
+ if (pack.isDefaultPackage())
+ {
+ append(JavaElementLabels.DEFAULT_PACKAGE);
+ }
+ else
+ {
+ append(pack.getName());
+ }
+ }
+
+ private void appendTypeSignatureLabel(IJavaElement enclosingElement,
+ String typeSig)
+ {
+ int sigKind = Signature.getTypeSignatureKind(typeSig);
+ switch (sigKind)
+ {
+ case Signature.BASE_TYPE_SIGNATURE:
+ append(Signature.toString(typeSig));
+ break;
+ case Signature.ARRAY_TYPE_SIGNATURE:
+ appendTypeSignatureLabel(enclosingElement, Signature.getElementType(
+ typeSig));
+ for (int dim = Signature.getArrayCount(typeSig); dim > 0; dim--)
+ {
+ append('[').append(']');
+ }
+ break;
+ case Signature.CLASS_TYPE_SIGNATURE:
+ String baseType = getSimpleTypeName(enclosingElement, typeSig);
+ append(baseType);
+
+ String[] typeArguments = Signature.getTypeArguments(typeSig);
+ appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments);
+ break;
+ case Signature.TYPE_VARIABLE_SIGNATURE:
+ append(getSimpleTypeName(enclosingElement, typeSig));
+ break;
+ case Signature.WILDCARD_TYPE_SIGNATURE:
+ char ch = typeSig.charAt(0);
+ if (ch == Signature.C_STAR)
+ {
+ append('?'); // workaround for bug 85713
+ }
+ else
+ {
+ if (ch == Signature.C_EXTENDS)
+ {
+ append("? extends "); //$NON-NLS-1$
+ appendTypeSignatureLabel(enclosingElement,
+ typeSig.substring(1));
+ }
+ else if (ch == Signature.C_SUPER)
+ {
+ append("? super "); //$NON-NLS-1$
+ appendTypeSignatureLabel(enclosingElement,
+ typeSig.substring(1));
+ }
+ }
+ break;
+ case Signature.CAPTURE_TYPE_SIGNATURE:
+ appendTypeSignatureLabel(enclosingElement, typeSig.substring(1));
+ break;
+ case Signature.INTERSECTION_TYPE_SIGNATURE:
+ String[] typeBounds = Signature.getIntersectionTypeBounds(typeSig);
+ appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds);
+ break;
+ default:
+ // unknown
+ }
+ }
+
+ private void appendTypeArgumentSignaturesLabel(
+ IJavaElement enclosingElement, String[] typeArgsSig)
+ {
+ if (typeArgsSig.length > 0)
+ {
+ append("<");
+ for (int i = 0; i < typeArgsSig.length; i++)
+ {
+ if (i > 0)
+ {
+ append(JavaElementLabels.COMMA_STRING);
+ }
+ appendTypeSignatureLabel(enclosingElement, typeArgsSig[i]);
+ }
+ append(">");
+ }
+ }
+
+ private void appendTypeBoundsSignaturesLabel(IJavaElement enclosingElement,
+ String[] typeArgsSig)
+ {
+ for (int i = 0; i < typeArgsSig.length; i++)
+ {
+ if (i > 0)
+ {
+ append(" | "); //$NON-NLS-1$
+ }
+ appendTypeSignatureLabel(enclosingElement, typeArgsSig[i]);
+ }
+ }
+
+ /*
+ * Converts signature to a simple name.
+ *
+ * @param enclosingElement
+ * @param typeSig
+ * @return the simple name
+ */
+ private String getSimpleTypeName(IJavaElement enclosingElement,
+ String typeSig)
+ {
+ return Signature.getSimpleName(Signature.toString(
+ Signature.getTypeErasure(typeSig)));
+ }
+
+ /*
+ * Appends the string representation of the given character to the buffer.
+ *
+ * @param ch the character to append
+ * @return a reference to this object
+ */
+ private JavaElementLabelComposer append(char ch)
+ {
+ if (buffer instanceof StringBuilder)
+ {
+ ((StringBuilder)buffer).append(ch);
+ }
+ else
+ {
+ ((StyledString)buffer).append(ch);
+ }
+ return this;
+ }
+
+ /*
+ * Appends the given string to the buffer.
+ *
+ * @param string the string to append
+ * @return a reference to this object
+ */
+ private JavaElementLabelComposer append(String string)
+ {
+ if (string == null)
+ return this;
+
+ if (buffer instanceof StringBuilder)
+ {
+ ((StringBuilder)buffer).append(string);
+ }
+ else
+ {
+ ((StyledString)buffer).append(string);
+ }
+ return this;
+ }
+
+ /*
+ * Sets a styler to use for the given source range.
+ *
+ * @see StyledString#setStyle(int, int, Styler)
+ */
+ private void setStyle(int offset, int length, Styler styler)
+ {
+ // only used for styled strings
+ if (buffer instanceof StyledString)
+ {
+ ((StyledString)buffer).setStyle(offset, length, styler);
+ }
+ }
+
+ /*
+ * Returns the current length of the buffer.
+ */
+ private int getLength()
+ {
+ if (buffer instanceof StringBuilder)
+ {
+ return ((StringBuilder)buffer).length();
+ }
+ else
+ {
+ return ((StyledString)buffer).length();
+ }
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementSorter.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementSorter.java
new file mode 100644
index 00000000..501284bb
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/JavaElementSorter.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+/**
+ * Java element sorter. Uses {@link JavaElementComparator} internally.
+ */
+public class JavaElementSorter
+ extends ViewerSorter
+{
+ private final JavaElementComparator comparator =
+ new JavaElementComparator();
+
+ @Override
+ public int category(Object element)
+ {
+ return comparator.category(element);
+ }
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2)
+ {
+ return comparator.compare(viewer, e1, e2);
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/PersistableJavaElementFactory.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/PersistableJavaElementFactory.java
new file mode 100644
index 00000000..281cd246
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/PersistableJavaElementFactory.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.handly.examples.javamodel.ICompilationUnit;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * This class is used to save and recreate an IJavaElement object.
+ * As such, it implements the IPersistableElement interface for storage
+ * and the IElementFactory interface for recreation.
+ *
+ * @see IMemento
+ * @see IPersistableElement
+ * @see IElementFactory
+ */
+public class PersistableJavaElementFactory
+ implements IElementFactory, IPersistableElement
+{
+ private static final String KEY = "elementID"; //$NON-NLS-1$
+ private static final String FACTORY_ID =
+ "org.eclipse.handly.examples.javamodel.ui.PersistableJavaElementFactory"; //$NON-NLS-1$
+
+ private IJavaElement element;
+
+ public PersistableJavaElementFactory()
+ {
+ }
+
+ public PersistableJavaElementFactory(IJavaElement element)
+ {
+ this.element = element;
+ }
+
+ @Override
+ public IAdaptable createElement(IMemento memento)
+ {
+ String value = memento.getString(KEY);
+ if (value != null)
+ {
+ IPath path = Path.fromPortableString(value);
+ IResource resource =
+ ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if (resource != null)
+ return JavaModelCore.create(resource);
+ }
+ return null;
+ }
+
+ @Override
+ public void saveState(IMemento memento)
+ {
+ if (element.getAncestor(ICompilationUnit.class) != null)
+ return; // element inside compilation unit
+ memento.putString(KEY, element.getPath().toPortableString());
+ }
+
+ @Override
+ public String getFactoryId()
+ {
+ return FACTORY_ID;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/EmptyInnerPackageFilter.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/EmptyInnerPackageFilter.java
new file mode 100644
index 00000000..5a863ffd
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/EmptyInnerPackageFilter.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.filters;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.handly.examples.javamodel.IPackageFragment;
+import org.eclipse.handly.internal.examples.javamodel.ui.Activator;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+/**
+ * Filters out empty non-leaf package fragments.
+ */
+public class EmptyInnerPackageFilter
+ extends ViewerFilter
+{
+ @Override
+ public boolean select(Viewer viewer, Object parent, Object element)
+ {
+ if (element instanceof IPackageFragment)
+ {
+ try
+ {
+ IPackageFragment pkg = (IPackageFragment)element;
+ if (pkg.isDefaultPackage())
+ return pkg.getChildren().length > 0;
+ return !pkg.hasSubpackages() || pkg.getChildren().length > 0
+ || EmptyPackageFilter.hasUnfilteredResources(viewer, pkg);
+ }
+ catch (CoreException e)
+ {
+ Activator.log(e.getStatus());
+ }
+ }
+ return true;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/EmptyPackageFilter.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/EmptyPackageFilter.java
new file mode 100644
index 00000000..61af09f8
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/EmptyPackageFilter.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.jdt.internal.ui.filters.EmptyPackageFilter)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.filters;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.handly.examples.javamodel.IPackageFragment;
+import org.eclipse.handly.internal.examples.javamodel.ui.Activator;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+/**
+ * Filters out all empty package fragments.
+ */
+public class EmptyPackageFilter
+ extends ViewerFilter
+{
+ @Override
+ public boolean select(Viewer viewer, Object parent, Object element)
+ {
+ if (element instanceof IPackageFragment)
+ {
+ IPackageFragment pkg = (IPackageFragment)element;
+ try
+ {
+ return pkg.getChildren().length > 0 || hasUnfilteredResources(
+ viewer, pkg);
+ }
+ catch (CoreException e)
+ {
+ Activator.log(e.getStatus());
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Tells whether the given package has unfiltered resources.
+ *
+ * @param viewer the viewer
+ * @param pkg the package
+ * @return <code>true</code> if the package has unfiltered resources
+ * @throws CoreException
+ */
+ static boolean hasUnfilteredResources(Viewer viewer, IPackageFragment pkg)
+ throws CoreException
+ {
+ Object[] resources = pkg.getNonJavaResources();
+ int length = resources.length;
+ if (length == 0)
+ return false;
+
+ if (!(viewer instanceof StructuredViewer))
+ return true;
+
+ ViewerFilter[] filters = ((StructuredViewer)viewer).getFilters();
+ resourceLoop: for (int i = 0; i < length; i++)
+ {
+ for (int j = 0; j < filters.length; j++)
+ {
+ if (!filters[j].select(viewer, pkg, resources[i]))
+ continue resourceLoop;
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/OutputFolderFilter.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/OutputFolderFilter.java
new file mode 100644
index 00000000..3e60cbaa
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/filters/OutputFolderFilter.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.filters;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.handly.examples.javamodel.IJavaProject;
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.handly.internal.examples.javamodel.Activator;
+import org.eclipse.handly.internal.examples.javamodel.JavaProject;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+/**
+ * Filters out output folders in Java projects.
+ */
+public class OutputFolderFilter
+ extends ViewerFilter
+{
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element)
+ {
+ if (element instanceof IFolder)
+ {
+ try
+ {
+ IFolder folder = (IFolder)element;
+
+ IJavaProject jProject = JavaModelCore.create(
+ folder.getProject());
+ if (jProject != null && jProject.exists())
+ {
+ IPath outputLoc =
+ ((JavaProject)jProject).getOutputLocation();
+ if (outputLoc.equals(folder.getFullPath()))
+ {
+ return false;
+ }
+ }
+ }
+ catch (CoreException e)
+ {
+ Activator.log(e.getStatus());
+ }
+ }
+ return true;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/JavaLinkHelper.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/JavaLinkHelper.java
new file mode 100644
index 00000000..787ff387
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/JavaLinkHelper.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 1C-Soft LLC and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vladimir Piskarev (1C) - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.handly.internal.examples.basic.ui.navigator.FooLinkHelper)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.navigator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.handly.examples.javamodel.ICompilationUnit;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.handly.model.ISourceElement;
+import org.eclipse.handly.model.SourceElements;
+import org.eclipse.handly.util.TextRange;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.ILinkHelper;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * Link helper for the Java Navigator.
+ */
+public class JavaLinkHelper
+ implements ILinkHelper
+{
+ @Override
+ public IStructuredSelection findSelection(IEditorInput editorInput)
+ {
+ if (editorInput instanceof IFileEditorInput)
+ {
+ IFile file = ((IFileEditorInput)editorInput).getFile();
+ ICompilationUnit cu = (ICompilationUnit)JavaModelCore.create(file);
+ if (cu != null)
+ {
+ IViewPart navigatorView =
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(
+ JavaNavigator.ID);
+ if (navigatorView != null)
+ {
+ IStructuredSelection currentSelection =
+ (IStructuredSelection)navigatorView.getSite().getSelectionProvider().getSelection();
+ if (currentSelection != null
+ && currentSelection.size() == 1)
+ {
+ Object element = currentSelection.getFirstElement();
+ if (element instanceof IJavaElement)
+ {
+ if (cu.equals(((IJavaElement)element).getAncestor(
+ ICompilationUnit.class)))
+ return currentSelection;
+ }
+ }
+ }
+ return new StructuredSelection(cu);
+ }
+ else
+ {
+ return new StructuredSelection(file);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void activateEditor(IWorkbenchPage page,
+ IStructuredSelection selection)
+ {
+ if (selection == null || selection.size() != 1)
+ return;
+ Object element = selection.getFirstElement();
+ IFile file = toFile(element);
+ if (file != null)
+ {
+ IEditorPart editor = page.findEditor(new FileEditorInput(file));
+ if (editor != null)
+ {
+ page.bringToTop(editor);
+ revealInEditor(editor, element);
+ }
+ }
+ }
+
+ static IFile toFile(Object element)
+ {
+ IResource resource = null;
+ if (element instanceof IJavaElement)
+ resource = ((IJavaElement)element).getResource();
+ else if (element instanceof IResource)
+ resource = (IResource)element;
+ if (resource instanceof IFile)
+ return (IFile)resource;
+ return null;
+ }
+
+ static void revealInEditor(IEditorPart editor, Object element)
+ {
+ if (editor instanceof ITextEditor && element instanceof ISourceElement)
+ {
+ TextRange identifyingRange = SourceElements.getSourceElementInfo(
+ (ISourceElement)element).getIdentifyingRange();
+ if (identifyingRange == null)
+ return;
+ ((ITextEditor)editor).selectAndReveal(identifyingRange.getOffset(),
+ identifyingRange.getLength());
+ }
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/JavaNavigator.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/JavaNavigator.java
new file mode 100644
index 00000000..fc447f7f
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/JavaNavigator.java
@@ -0,0 +1,258 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.ui.views.navigator.ResourceNavigator)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.navigator;
+
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.handly.internal.examples.javamodel.ui.Activator;
+import org.eclipse.handly.model.IElementChangeEvent;
+import org.eclipse.handly.model.IElementChangeListener;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.util.Util;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPreferenceConstants;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ResourceWorkingSetFilter;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * Java Navigator view.
+ */
+public class JavaNavigator
+ extends CommonNavigator
+ implements IElementChangeListener
+{
+ /**
+ * Java Navigator view id.
+ */
+ public static final String ID =
+ "org.eclipse.handly.examples.javamodel.ui.views.JavaNavigator"; //$NON-NLS-1$
+
+ private static final String STORE_SECTION = "JavaNavigator"; //$NON-NLS-1$
+ private static final String STORE_WORKING_SET =
+ "ResourceWorkingSetFilter.STORE_WORKING_SET"; //$NON-NLS-1$
+
+ private IDialogSettings settings;
+ private IWorkingSet workingSet;
+ private boolean emptyWorkingSet;
+ private ResourceWorkingSetFilter workingSetFilter =
+ new ResourceWorkingSetFilter();
+ private IPropertyChangeListener workingSetListener =
+ new IPropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ String property = event.getProperty();
+ Object newValue = event.getNewValue();
+ Object oldValue = event.getOldValue();
+
+ if (IWorkingSetManager.CHANGE_WORKING_SET_REMOVE.equals(
+ property) && oldValue == workingSet)
+ {
+ setWorkingSet(null);
+ }
+ else if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(
+ property) && newValue == workingSet)
+ {
+ updateTitle();
+ }
+ else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(
+ property) && newValue == workingSet)
+ {
+ if (workingSet.isAggregateWorkingSet()
+ && workingSet.isEmpty())
+ {
+ // act as if the working set has been made null
+ if (!emptyWorkingSet)
+ {
+ emptyWorkingSet = true;
+ workingSetFilter.setWorkingSet(null);
+ }
+ }
+ else
+ {
+ // we've gone from empty to non-empty on our set.
+ // Restore it.
+ if (emptyWorkingSet)
+ {
+ emptyWorkingSet = false;
+ workingSetFilter.setWorkingSet(workingSet);
+ }
+ }
+ refresh();
+ }
+ }
+ };
+
+ /**
+ * Constructs a new Java Navigator view.
+ */
+ public JavaNavigator()
+ {
+ IDialogSettings viewsSettings =
+ Activator.getDefault().getDialogSettings();
+ settings = viewsSettings.getSection(STORE_SECTION);
+ if (settings == null)
+ settings = viewsSettings.addNewSection(STORE_SECTION);
+ }
+
+ /**
+ * Sets the working set for this view, or <code>null</code> to clear it.
+ *
+ * @param workingSet the working set, or <code>null</code> to clear it
+ */
+ public void setWorkingSet(IWorkingSet workingSet)
+ {
+ boolean refreshNeeded = internalSetWorkingSet(workingSet);
+
+ workingSetFilter.setWorkingSet(emptyWorkingSet ? null : workingSet);
+
+ if (workingSet != null)
+ settings.put(STORE_WORKING_SET, workingSet.getName());
+ else
+ settings.put(STORE_WORKING_SET, ""); //$NON-NLS-1$
+
+ updateTitle();
+ if (refreshNeeded)
+ {
+ refresh();
+ }
+ }
+
+ /**
+ * Returns the active working set, or <code>null<code> if none.
+ *
+ * @return the active working set, or <code>null<code> if none
+ */
+ public IWorkingSet getWorkingSet()
+ {
+ return workingSetFilter.getWorkingSet();
+ }
+
+ @Override
+ public CommonViewer createCommonViewer(Composite aParent)
+ {
+ CommonViewer viewer = super.createCommonViewer(aParent);
+ initWorkingSetFilter();
+ viewer.addFilter(workingSetFilter);
+ IWorkingSetManager workingSetManager =
+ PlatformUI.getWorkbench().getWorkingSetManager();
+ workingSetManager.addPropertyChangeListener(workingSetListener);
+ return viewer;
+ }
+
+ @Override
+ public void init(IViewSite site) throws PartInitException
+ {
+ super.init(site);
+ JavaModelCore.getJavaModel().addElementChangeListener(this);
+ }
+
+ @Override
+ public void dispose()
+ {
+ IWorkingSetManager workingSetManager =
+ PlatformUI.getWorkbench().getWorkingSetManager();
+ workingSetManager.removePropertyChangeListener(workingSetListener);
+ JavaModelCore.getJavaModel().removeElementChangeListener(this);
+ super.dispose();
+ }
+
+ @Override
+ public void elementChanged(IElementChangeEvent event)
+ {
+ // NOTE: don't hold on the event or its delta.
+ // The delta is only valid during the dynamic scope of the notification.
+ // In particular, don't pass it to another thread (e.g. via asyncExec).
+ final Control control = getCommonViewer().getControl();
+ control.getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ if (!control.isDisposed())
+ {
+ refresh(); // full refresh should suffice for our example (but not for production code)
+ }
+ }
+ });
+ }
+
+ @Override
+ protected Object getInitialInput()
+ {
+ return JavaModelCore.getJavaModel();
+ }
+
+ private void refresh()
+ {
+ Control control = getCommonViewer().getControl();
+ control.setRedraw(false);
+ BusyIndicator.showWhile(control.getDisplay(), new Runnable()
+ {
+ public void run()
+ {
+ TreePath[] treePaths = getCommonViewer().getExpandedTreePaths();
+ getCommonViewer().refresh();
+ getCommonViewer().setExpandedTreePaths(treePaths);
+ }
+ });
+ control.setRedraw(true);
+ }
+
+ private boolean internalSetWorkingSet(IWorkingSet workingSet)
+ {
+ boolean refreshNeeded = !Util.equals(this.workingSet, workingSet);
+ this.workingSet = workingSet;
+ emptyWorkingSet = workingSet != null
+ && workingSet.isAggregateWorkingSet() && workingSet.isEmpty();
+ return refreshNeeded;
+ }
+
+ private void initWorkingSetFilter()
+ {
+ String workingSetName = settings.get(STORE_WORKING_SET);
+
+ IWorkingSet workingSet = null;
+
+ if (workingSetName != null && !workingSetName.isEmpty())
+ {
+ IWorkingSetManager workingSetManager =
+ PlatformUI.getWorkbench().getWorkingSetManager();
+ workingSet = workingSetManager.getWorkingSet(workingSetName);
+ }
+ else if (PlatformUI.getPreferenceStore().getBoolean(
+ IWorkbenchPreferenceConstants.USE_WINDOW_WORKING_SET_BY_DEFAULT))
+ {
+ // use the window set by default if the global preference is set
+ workingSet = getSite().getPage().getAggregateWorkingSet();
+ }
+
+ if (workingSet != null)
+ {
+ // Only initialize filter. Don't set working set into viewer.
+ // Working set is set via WorkingSetFilterActionGroup
+ // during action creation.
+ workingSetFilter.setWorkingSet(workingSet);
+ internalSetWorkingSet(workingSet);
+ }
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/OpenAction.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/OpenAction.java
new file mode 100644
index 00000000..35b5838d
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/OpenAction.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 1C-Soft LLC and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vladimir Piskarev (1C) - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * org.eclipse.handly.internal.examples.basic.ui.navigator.OpenAction)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.navigator;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.util.OpenStrategy;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * Opens an editor on an applicable element.
+ */
+class OpenAction
+ extends BaseSelectionListenerAction
+{
+ private IWorkbenchPage page;
+
+ /**
+ * Constructs an open action for the given workbench page.
+ *
+ * @param page the workbench page to open the editor in
+ * (not <code>null</code>)
+ */
+ public OpenAction(IWorkbenchPage page)
+ {
+ super("&Open");
+ if (page == null)
+ throw new IllegalArgumentException();
+ this.page = page;
+ }
+
+ @Override
+ public void run()
+ {
+ IStructuredSelection selection = getStructuredSelection();
+ if (selection == null)
+ return;
+ Iterator<?> it = selection.iterator();
+ while (it.hasNext())
+ {
+ Object element = it.next();
+ IFile file = JavaLinkHelper.toFile(element);
+ if (file != null)
+ {
+ IEditorPart editor = null;
+ try
+ {
+ editor = IDE.openEditor(page, file,
+ OpenStrategy.activateOnOpen());
+ }
+ catch (PartInitException e)
+ {
+ }
+ if (editor != null)
+ {
+ JavaLinkHelper.revealInEditor(editor, element);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected boolean updateSelection(IStructuredSelection selection)
+ {
+ if (selection == null || selection.isEmpty())
+ return false;
+ Iterator<?> it = selection.iterator();
+ while (it.hasNext())
+ {
+ Object element = it.next();
+ if (JavaLinkHelper.toFile(element) == null)
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/OpenActionProvider.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/OpenActionProvider.java
new file mode 100644
index 00000000..92a13ee0
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/OpenActionProvider.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 1C-Soft LLC and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vladimir Piskarev (1C) - initial API and implementation
+ * Ondrej Ilcik (Codasip) - adaptation (adapted from
+ * o.e.handly.internal.examples.basic.ui.navigator.OpenActionProvider)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.navigator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.handly.examples.javamodel.ICompilationUnit;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.actions.OpenWithMenu;
+import org.eclipse.ui.navigator.CommonActionProvider;
+import org.eclipse.ui.navigator.ICommonActionConstants;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.eclipse.ui.navigator.ICommonMenuConstants;
+import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
+
+/**
+ * Provides 'Open' action and 'Open with' submenu for the Java Navigator.
+ */
+public class OpenActionProvider
+ extends CommonActionProvider
+{
+ private OpenAction openAction;
+
+ @Override
+ public void init(ICommonActionExtensionSite actionSite)
+ {
+ super.init(actionSite);
+ openAction = new OpenAction(getPage());
+ }
+
+ @Override
+ public void fillContextMenu(IMenuManager menu)
+ {
+ if (openAction == null)
+ return;
+
+ IStructuredSelection selection =
+ (IStructuredSelection)getContext().getSelection();
+ openAction.selectionChanged(selection);
+ if (openAction.isEnabled())
+ {
+ menu.insertAfter(ICommonMenuConstants.GROUP_OPEN, openAction);
+ }
+
+ addOpenWithMenu(menu);
+ }
+
+ @Override
+ public void fillActionBars(IActionBars actionBars)
+ {
+ if (openAction == null)
+ return;
+
+ IStructuredSelection selection =
+ (IStructuredSelection)getContext().getSelection();
+ openAction.selectionChanged(selection);
+ if (openAction.isEnabled())
+ {
+ actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN,
+ openAction);
+ }
+ }
+
+ private void addOpenWithMenu(IMenuManager menu)
+ {
+ IStructuredSelection selection =
+ (IStructuredSelection)getContext().getSelection();
+ if (selection == null || selection.size() != 1)
+ return;
+
+ Object element = selection.getFirstElement();
+
+ IFile file = null;
+ if (element instanceof ICompilationUnit)
+ file = ((ICompilationUnit)element).getFile();
+ else if (element instanceof IFile)
+ file = (IFile)element;
+ if (file != null)
+ {
+ IMenuManager submenu = new MenuManager("Open Wit&h");
+ submenu.add(new OpenWithMenu(getPage(), file));
+
+ menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
+ }
+ }
+
+ private IWorkbenchPage getPage()
+ {
+ return ((ICommonViewerWorkbenchSite)getActionSite().getViewSite()).getPage();
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/WorkingSetActionProvider.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/WorkingSetActionProvider.java
new file mode 100644
index 00000000..f7d156bc
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/navigator/WorkingSetActionProvider.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.navigator;
+
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
+import org.eclipse.ui.navigator.CommonActionProvider;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
+
+/**
+ * Provides {@link WorkingSetFilterActionGroup} for the Java Navigator.
+ */
+public class WorkingSetActionProvider
+ extends CommonActionProvider
+{
+ private WorkingSetFilterActionGroup workingSetActionGroup;
+ private boolean contributedToViewMenu = false;
+
+ @Override
+ public void init(ICommonActionExtensionSite actionSite)
+ {
+ super.init(actionSite);
+ ICommonViewerWorkbenchSite viewSite =
+ (ICommonViewerWorkbenchSite)actionSite.getViewSite();
+ final JavaNavigator navigator = (JavaNavigator)viewSite.getPart();
+ IPropertyChangeListener workingSetUpdater =
+ new IPropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ String property = event.getProperty();
+
+ if (WorkingSetFilterActionGroup.CHANGE_WORKING_SET.equals(
+ property))
+ {
+ Object newValue = event.getNewValue();
+
+ if (newValue instanceof IWorkingSet)
+ {
+ navigator.setWorkingSet((IWorkingSet)newValue);
+ }
+ else if (newValue == null)
+ {
+ navigator.setWorkingSet(null);
+ }
+ }
+ }
+ };
+ workingSetActionGroup = new WorkingSetFilterActionGroup(
+ viewSite.getShell(), workingSetUpdater);
+ workingSetActionGroup.setWorkingSet(navigator.getWorkingSet());
+ }
+
+ @Override
+ public void fillActionBars(IActionBars actionBars)
+ {
+ if (!contributedToViewMenu)
+ {
+ try
+ {
+ workingSetActionGroup.fillActionBars(actionBars);
+ }
+ finally
+ {
+ contributedToViewMenu = true;
+ }
+ }
+ }
+
+ @Override
+ public void dispose()
+ {
+ workingSetActionGroup.dispose();
+ super.dispose();
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/preferences/MembersOrderPreferenceCache.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/preferences/MembersOrderPreferenceCache.java
new file mode 100644
index 00000000..49ff4f0e
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/preferences/MembersOrderPreferenceCache.java
@@ -0,0 +1,231 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik - adaptation (adapted from
+ * org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.preferences;
+
+import java.util.StringTokenizer;
+
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.ui.PreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+/**
+ * Cached preferences for ordering Java elements.
+ */
+public class MembersOrderPreferenceCache
+ implements IPropertyChangeListener
+{
+ public static final int TYPE_INDEX = 0;
+ public static final int CONSTRUCTORS_INDEX = 1;
+ public static final int METHOD_INDEX = 2;
+ public static final int FIELDS_INDEX = 3;
+ public static final int INIT_INDEX = 4;
+ public static final int STATIC_FIELDS_INDEX = 5;
+ public static final int STATIC_INIT_INDEX = 6;
+ public static final int STATIC_METHODS_INDEX = 7;
+ public static final int ENUM_CONSTANTS_INDEX = 8;
+ public static final int N_CATEGORIES = ENUM_CONSTANTS_INDEX + 1;
+
+ private static final int PUBLIC_INDEX = 0;
+ private static final int PRIVATE_INDEX = 1;
+ private static final int PROTECTED_INDEX = 2;
+ private static final int DEFAULT_INDEX = 3;
+ private static final int N_VISIBILITIES = DEFAULT_INDEX + 1;
+
+ private int[] fCategoryOffsets;
+
+ private boolean fSortByVisibility;
+ private int[] fVisibilityOffsets;
+
+ private IPreferenceStore fPreferenceStore;
+
+ public void install(IPreferenceStore store)
+ {
+ fPreferenceStore = store;
+ store.addPropertyChangeListener(this);
+ fSortByVisibility = store.getBoolean(
+ PreferenceConstants.APPEARANCE_ENABLE_VISIBILITY_SORT_ORDER);
+ }
+
+ public void dispose()
+ {
+ fPreferenceStore.removePropertyChangeListener(this);
+ fPreferenceStore = null;
+ }
+
+ public int getCategoryIndex(int kind)
+ {
+ if (fCategoryOffsets == null)
+ {
+ fCategoryOffsets = getCategoryOffsets();
+ }
+ return fCategoryOffsets[kind];
+ }
+
+ public boolean isSortByVisibility()
+ {
+ return fSortByVisibility;
+ }
+
+ public int getVisibilityIndex(int modifierFlags)
+ {
+ if (fVisibilityOffsets == null)
+ {
+ fVisibilityOffsets = getVisibilityOffsets();
+ }
+ int kind = DEFAULT_INDEX;
+ if (Flags.isPublic(modifierFlags))
+ {
+ kind = PUBLIC_INDEX;
+ }
+ else if (Flags.isProtected(modifierFlags))
+ {
+ kind = PROTECTED_INDEX;
+ }
+ else if (Flags.isPrivate(modifierFlags))
+ {
+ kind = PRIVATE_INDEX;
+ }
+
+ return fVisibilityOffsets[kind];
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ String property = event.getProperty();
+
+ if (PreferenceConstants.APPEARANCE_MEMBER_SORT_ORDER.equals(property))
+ {
+ fCategoryOffsets = null;
+ }
+ else if (PreferenceConstants.APPEARANCE_VISIBILITY_SORT_ORDER.equals(
+ property))
+ {
+ fVisibilityOffsets = null;
+ }
+ else if (PreferenceConstants.APPEARANCE_ENABLE_VISIBILITY_SORT_ORDER.equals(
+ property))
+ {
+ fSortByVisibility = fPreferenceStore.getBoolean(
+ PreferenceConstants.APPEARANCE_ENABLE_VISIBILITY_SORT_ORDER);
+ }
+ }
+
+ private int[] getCategoryOffsets()
+ {
+ int[] offsets = new int[N_CATEGORIES];
+ IPreferenceStore store = fPreferenceStore;
+ String key = PreferenceConstants.APPEARANCE_MEMBER_SORT_ORDER;
+ boolean success = fillCategoryOffsetsFromPreferenceString(
+ store.getString(key), offsets);
+ if (!success)
+ {
+ store.setToDefault(key);
+ fillCategoryOffsetsFromPreferenceString(store.getDefaultString(key),
+ offsets);
+ }
+ return offsets;
+ }
+
+ private static boolean fillCategoryOffsetsFromPreferenceString(String str,
+ int[] offsets)
+ {
+ StringTokenizer tokenizer = new StringTokenizer(str, ","); //$NON-NLS-1$
+ int i = 0;
+ offsets[ENUM_CONSTANTS_INDEX] = i++; // enum constants always on top
+
+ while (tokenizer.hasMoreTokens())
+ {
+ String token = tokenizer.nextToken().trim();
+ if ("T".equals(token)) //$NON-NLS-1$
+ {
+ offsets[TYPE_INDEX] = i++;
+ }
+ else if ("M".equals(token)) //$NON-NLS-1$
+ {
+ offsets[METHOD_INDEX] = i++;
+ }
+ else if ("F".equals(token)) //$NON-NLS-1$
+ {
+ offsets[FIELDS_INDEX] = i++;
+ }
+ else if ("I".equals(token)) //$NON-NLS-1$
+ {
+ offsets[INIT_INDEX] = i++;
+ }
+ else if ("SF".equals(token)) //$NON-NLS-1$
+ {
+ offsets[STATIC_FIELDS_INDEX] = i++;
+ }
+ else if ("SI".equals(token)) //$NON-NLS-1$
+ {
+ offsets[STATIC_INIT_INDEX] = i++;
+ }
+ else if ("SM".equals(token)) //$NON-NLS-1$
+ {
+ offsets[STATIC_METHODS_INDEX] = i++;
+ }
+ else if ("C".equals(token)) //$NON-NLS-1$
+ {
+ offsets[CONSTRUCTORS_INDEX] = i++;
+ }
+ }
+ return i == N_CATEGORIES;
+ }
+
+ private int[] getVisibilityOffsets()
+ {
+ int[] offsets = new int[N_VISIBILITIES];
+ IPreferenceStore store = fPreferenceStore;
+ String key = PreferenceConstants.APPEARANCE_VISIBILITY_SORT_ORDER;
+ boolean success = fillVisibilityOffsetsFromPreferenceString(
+ store.getString(key), offsets);
+ if (!success)
+ {
+ store.setToDefault(key);
+ fillVisibilityOffsetsFromPreferenceString(store.getDefaultString(
+ key), offsets);
+ }
+ return offsets;
+ }
+
+ private static boolean fillVisibilityOffsetsFromPreferenceString(String str,
+ int[] offsets)
+ {
+ StringTokenizer tokenizer = new StringTokenizer(str, ","); //$NON-NLS-1$
+ int i = 0;
+ while (tokenizer.hasMoreTokens())
+ {
+ String token = tokenizer.nextToken().trim();
+ if ("B".equals(token)) //$NON-NLS-1$
+ {
+ offsets[PUBLIC_INDEX] = i++;
+ }
+ else if ("V".equals(token)) //$NON-NLS-1$
+ {
+ offsets[PRIVATE_INDEX] = i++;
+ }
+ else if ("R".equals(token)) //$NON-NLS-1$
+ {
+ offsets[PROTECTED_INDEX] = i++;
+ }
+ else if ("D".equals(token)) //$NON-NLS-1$
+ {
+ offsets[DEFAULT_INDEX] = i++;
+ }
+ }
+ return i == N_VISIBILITIES;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/util/JavaFlags.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/util/JavaFlags.java
new file mode 100644
index 00000000..9a89b2df
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/util/JavaFlags.java
@@ -0,0 +1,278 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Ondrej Ilcik - adaptation (adapted from
+ * org.eclipse.jdt.internal.corext.util.JdtFlags)
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.util;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.handly.examples.javamodel.IField;
+import org.eclipse.handly.examples.javamodel.IMember;
+import org.eclipse.handly.examples.javamodel.IMethod;
+import org.eclipse.handly.examples.javamodel.IType;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.dom.Modifier;
+
+/**
+ * Utility class to detect Java element modifiers including implicit ones
+ * as defined in the Java Language Specification.
+ */
+public class JavaFlags
+{
+ public static final String VISIBILITY_STRING_PRIVATE = "private"; //$NON-NLS-1$
+ public static final String VISIBILITY_STRING_PACKAGE = ""; //$NON-NLS-1$
+ public static final String VISIBILITY_STRING_PROTECTED = "protected"; //$NON-NLS-1$
+ public static final String VISIBILITY_STRING_PUBLIC = "public"; //$NON-NLS-1$
+
+ public static final int VISIBILITY_CODE_INVALID = -1;
+
+ public static boolean isAbstract(IMember member) throws CoreException
+ {
+ if (isInterfaceOrAnnotationMethod(member))
+ return true;
+ return Flags.isAbstract(member.getFlags());
+ }
+
+ public static boolean isDeprecated(IMember member) throws CoreException
+ {
+ return Flags.isDeprecated(member.getFlags());
+ }
+
+ public static boolean isFinal(IMember member) throws CoreException
+ {
+ if (isInterfaceOrAnnotationField(member))
+ return true;
+ if (isEnumConstant(member))
+ return true;
+ return Flags.isFinal(member.getFlags());
+ }
+
+ public static boolean isNative(IMember member) throws CoreException
+ {
+ return Flags.isNative(member.getFlags());
+ }
+
+ public static boolean isPackageVisible(IMember member) throws CoreException
+ {
+ return !isPrivate(member) && !isProtected(member) && !isPublic(member);
+ }
+
+ public static boolean isPrivate(IMember member) throws CoreException
+ {
+ return Flags.isPrivate(member.getFlags());
+ }
+
+ public static boolean isProtected(IMember member) throws CoreException
+ {
+ return Flags.isProtected(member.getFlags());
+ }
+
+ public static boolean isPublic(IMember member) throws CoreException
+ {
+ if (isInterfaceOrAnnotationMember(member))
+ return true;
+ if (isEnumConstant(member))
+ return true;
+ return Flags.isPublic(member.getFlags());
+ }
+
+ public static boolean isStatic(IMember member) throws CoreException
+ {
+ if (isNestedInterfaceOrAnnotation(member))
+ return true;
+ if (member instanceof IMethod && isInterfaceOrAnnotationMember(member))
+ return true;
+ if (isEnumConstant(member))
+ return true;
+ return Flags.isStatic(member.getFlags());
+ }
+
+ public static boolean isStrictfp(IMember member) throws CoreException
+ {
+ return Flags.isStrictfp(member.getFlags());
+ }
+
+ public static boolean isSynchronized(IMember member) throws CoreException
+ {
+ return Flags.isSynchronized(member.getFlags());
+ }
+
+ public static boolean isSynthetic(IMember member) throws CoreException
+ {
+ return Flags.isSynthetic(member.getFlags());
+ }
+
+ public static boolean isAnnotation(IMember member) throws CoreException
+ {
+ return Flags.isAnnotation(member.getFlags());
+ }
+
+ public static boolean isEnum(IMember member) throws CoreException
+ {
+ return Flags.isEnum(member.getFlags());
+ }
+
+ public static boolean isVarargs(IMethod method) throws CoreException
+ {
+ return Flags.isVarargs(method.getFlags());
+ }
+
+ public static boolean isTransient(IMember member) throws CoreException
+ {
+ return Flags.isTransient(member.getFlags());
+ }
+
+ public static boolean isVolatile(IMember member) throws CoreException
+ {
+ return Flags.isVolatile(member.getFlags());
+ }
+
+ public static int getVisibilityCode(IMember member) throws CoreException
+ {
+ if (isPublic(member))
+ return Modifier.PUBLIC;
+ else if (isProtected(member))
+ return Modifier.PROTECTED;
+ else if (isPackageVisible(member))
+ return Modifier.NONE;
+ else if (isPrivate(member))
+ return Modifier.PRIVATE;
+ Assert.isTrue(false);
+ return VISIBILITY_CODE_INVALID;
+ }
+
+ public static String getVisibilityString(int visibilityCode)
+ {
+ if (Modifier.isPublic(visibilityCode))
+ return VISIBILITY_STRING_PUBLIC;
+ if (Modifier.isProtected(visibilityCode))
+ return VISIBILITY_STRING_PROTECTED;
+ if (Modifier.isPrivate(visibilityCode))
+ return VISIBILITY_STRING_PRIVATE;
+ return VISIBILITY_STRING_PACKAGE;
+ }
+
+ public static int getVisibilityCode(String visibilityString)
+ {
+ Assert.isNotNull(visibilityString);
+ if (VISIBILITY_STRING_PACKAGE.equals(visibilityString))
+ return 0;
+ else if (VISIBILITY_STRING_PRIVATE.equals(visibilityString))
+ return Modifier.PRIVATE;
+ else if (VISIBILITY_STRING_PROTECTED.equals(visibilityString))
+ return Modifier.PROTECTED;
+ else if (VISIBILITY_STRING_PUBLIC.equals(visibilityString))
+ return Modifier.PUBLIC;
+ return VISIBILITY_CODE_INVALID;
+ }
+
+ public static void assertVisibility(int visibility)
+ {
+ Assert.isTrue(visibility == Modifier.PUBLIC
+ || visibility == Modifier.PROTECTED || visibility == Modifier.NONE
+ || visibility == Modifier.PRIVATE);
+ }
+
+ /**
+ * Compares two visibilities.
+ *
+ * @param newVisibility the 'new' visibility
+ * @param oldVisibility the 'old' visibility
+ * @return <code>true</code> iff the 'new' visibility is strictly higher
+ * than the old visibility
+ *
+ * @see Modifier#PUBLIC
+ * @see Modifier#PROTECTED
+ * @see Modifier#NONE
+ * @see Modifier#PRIVATE
+ */
+ public static boolean isHigherVisibility(int newVisibility,
+ int oldVisibility)
+ {
+ assertVisibility(oldVisibility);
+ assertVisibility(newVisibility);
+ switch (oldVisibility)
+ {
+ case Modifier.PRIVATE:
+ return newVisibility == Modifier.NONE
+ || newVisibility == Modifier.PUBLIC
+ || newVisibility == Modifier.PROTECTED;
+ case Modifier.NONE:
+ return newVisibility == Modifier.PUBLIC
+ || newVisibility == Modifier.PROTECTED;
+
+ case Modifier.PROTECTED:
+ return newVisibility == Modifier.PUBLIC;
+
+ case Modifier.PUBLIC:
+ return false;
+ default:
+ Assert.isTrue(false);
+ return false;
+ }
+ }
+
+ public static int getLowerVisibility(int visibility1, int visibility2)
+ {
+ if (isHigherVisibility(visibility1, visibility2))
+ return visibility2;
+ else
+ return visibility1;
+ }
+
+ public static int clearAccessModifiers(int flags)
+ {
+ return clearFlag(Modifier.PROTECTED | Modifier.PUBLIC
+ | Modifier.PRIVATE, flags);
+ }
+
+ private static int clearFlag(int flag, int flags)
+ {
+ return flags & ~flag;
+ }
+
+ private static boolean isInterfaceOrAnnotationMethod(IMember member)
+ throws CoreException
+ {
+ return (member instanceof IMethod) && isInterfaceOrAnnotationMember(
+ member);
+ }
+
+ private static boolean isInterfaceOrAnnotationField(IMember member)
+ throws CoreException
+ {
+ return (member instanceof IType) && isInterfaceOrAnnotationMember(
+ member);
+ }
+
+ private static boolean isInterfaceOrAnnotationMember(IMember member)
+ throws CoreException
+ {
+ return member.getDeclaringType() != null
+ && member.getDeclaringType().isInterface();
+ }
+
+ private static boolean isNestedInterfaceOrAnnotation(IMember member)
+ throws CoreException
+ {
+ return (member instanceof IType) && member.getDeclaringType() != null
+ && ((IType)member).isInterface();
+ }
+
+ private static boolean isEnumConstant(IMember member) throws CoreException
+ {
+ return (member instanceof IField) && isEnum(member);
+ }
+
+ private JavaFlags()
+ {
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetElementAdapter.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetElementAdapter.java
new file mode 100644
index 00000000..24c56d1c
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetElementAdapter.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.workingset;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.handly.examples.javamodel.IJavaElement;
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.handly.ui.workingset.AbstractWorkingSetElementAdapter;
+
+/**
+ * Element adapter for Java working set.
+ */
+public class JavaWorkingSetElementAdapter
+ extends AbstractWorkingSetElementAdapter
+{
+ @Override
+ protected boolean isModelElement(IAdaptable element)
+ {
+ return element instanceof IJavaElement;
+ }
+
+ @Override
+ protected IAdaptable adaptFromResource(IResource resource)
+ {
+ IJavaElement element = JavaModelCore.create(resource);
+ if (element != null && element.exists())
+ return element;
+ return resource;
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetPage.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetPage.java
new file mode 100644
index 00000000..6d4ab91f
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetPage.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.workingset;
+
+import org.eclipse.handly.examples.javamodel.ICompilationUnit;
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.handly.examples.javamodel.ui.JavaModelContentProvider;
+import org.eclipse.handly.examples.javamodel.ui.JavaModelLabelProvider;
+import org.eclipse.handly.ui.workingset.AbstractWorkingSetPage;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+
+/**
+ * The Java working set page allows the user to create and edit a Java working set.
+ */
+public class JavaWorkingSetPage
+ extends AbstractWorkingSetPage
+{
+ /**
+ * Default constructor.
+ */
+ public JavaWorkingSetPage()
+ {
+ super("javaWorkingSetPage", "Java Working Set", null); //$NON-NLS-1$
+ }
+
+ @Override
+ protected String getPageId()
+ {
+ return "org.eclipse.handly.examples.javamodel.ui.JavaWorkingSetPage"; //$NON-NLS-1$
+ }
+
+ @Override
+ protected void configureTree(TreeViewer tree)
+ {
+ tree.setContentProvider(new JavaModelContentProvider()
+ {
+ @Override
+ public Object[] getChildren(Object parentElement)
+ {
+ if (parentElement instanceof ICompilationUnit)
+ return NO_CHILDREN;
+ return super.getChildren(parentElement);
+ }
+ });
+ tree.setLabelProvider(new JavaModelLabelProvider());
+ tree.setInput(JavaModelCore.getJavaModel());
+ }
+
+ @Override
+ protected void configureTable(TableViewer table)
+ {
+ table.setLabelProvider(new JavaModelLabelProvider());
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetUpdater.java b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetUpdater.java
new file mode 100644
index 00000000..b5185228
--- /dev/null
+++ b/org.eclipse.handly.examples.javamodel.ui/src/org/eclipse/handly/internal/examples/javamodel/ui/workingset/JavaWorkingSetUpdater.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Codasip Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ondrej Ilcik (Codasip) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.handly.internal.examples.javamodel.ui.workingset;
+
+import org.eclipse.handly.examples.javamodel.JavaModelCore;
+import org.eclipse.handly.model.IElementChangeListener;
+import org.eclipse.handly.ui.workingset.AbstractWorkingSetUpdater;
+
+/**
+ * Java working set updater.
+ */
+public class JavaWorkingSetUpdater
+ extends AbstractWorkingSetUpdater
+{
+ @Override
+ protected void addElementChangeListener(IElementChangeListener listener)
+ {
+ JavaModelCore.getJavaModel().addElementChangeListener(listener);
+ }
+
+ @Override
+ protected void removeElementChangeListener(IElementChangeListener listener)
+ {
+ JavaModelCore.getJavaModel().removeElementChangeListener(listener);
+ }
+}
diff --git a/org.eclipse.handly.examples.javamodel/META-INF/MANIFEST.MF b/org.eclipse.handly.examples.javamodel/META-INF/MANIFEST.MF
index c0c113b2..da13b061 100644
--- a/org.eclipse.handly.examples.javamodel/META-INF/MANIFEST.MF
+++ b/org.eclipse.handly.examples.javamodel/META-INF/MANIFEST.MF
@@ -12,4 +12,5 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.jdt.core,
org.eclipse.handly
-Export-Package: org.eclipse.handly.examples.javamodel
+Export-Package: org.eclipse.handly.examples.javamodel,
+ org.eclipse.handly.internal.examples.javamodel;x-friends:="org.eclipse.handly.examples.javamodel.ui"
diff --git a/org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/examples/javamodel/IPackageFragment.java b/org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/examples/javamodel/IPackageFragment.java
index 2d24f899..e205420a 100644
--- a/org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/examples/javamodel/IPackageFragment.java
+++ b/org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/examples/javamodel/IPackageFragment.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 1C-Soft LLC.
+ * Copyright (c) 2015 1C-Soft LLC and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Vladimir Piskarev (1C) - initial API and implementation
+ * Ondrej Ilcik (Codasip)
*******************************************************************************/
package org.eclipse.handly.examples.javamodel;
@@ -65,4 +66,15 @@ public interface IPackageFragment
* @return <code>true</code> if this package fragment is a default package
*/
boolean isDefaultPackage();
+
+ /**
+ * Returns whether this package fragment's name is a prefix of other
+ * package fragments in this package fragment's root.
+ *
+ * @return <code>true</code> if this package fragment's name is a prefix
+ * of other package fragments in this package fragment's root
+ * @throws CoreException if this element does not exist or if an exception
+ * occurs while accessing its corresponding resource
+ */
+ boolean hasSubpackages() throws CoreException;
}
diff --git a/org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/internal/examples/javamodel/PackageFragment.java b/org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/internal/examples/javamodel/PackageFragment.java
index 4aebe049..62798df7 100644
--- a/org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/internal/examples/javamodel/PackageFragment.java
+++ b/org.eclipse.handly.examples.javamodel/src/org/eclipse/handly/internal/examples/javamodel/PackageFragment.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 1C-Soft LLC.
+ * Copyright (c) 2015 1C-Soft LLC and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Vladimir Piskarev (1C) - initial API and implementation
+ * Ondrej Ilcik (Codasip)
*******************************************************************************/
package org.eclipse.handly.internal.examples.javamodel;
@@ -128,6 +129,27 @@ public class PackageFragment
}
@Override
+ public boolean hasSubpackages() throws CoreException
+ {
+ IPackageFragment[] packages = getParent().getChildren(
+ IPackageFragment.class);
+ int namesLength = simpleNames.length;
+ nextPackage: for (IPackageFragment pkg : packages)
+ {
+ String[] otherNames = ((PackageFragment)pkg).simpleNames;
+ if (otherNames.length <= namesLength)
+ continue nextPackage;
+ for (int i = 0; i < namesLength; i++)
+ {
+ if (!simpleNames[i].equals(otherNames[i]))
+ continue nextPackage;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
protected HandleManager getHandleManager()
{
return JavaModelManager.INSTANCE.getHandleManager();

Back to the top