Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Spungin2014-04-08 17:08:38 -0400
committerSteven Spungin2014-05-08 08:55:57 -0400
commit23d21424073f1c6795657c62162ed15783577fbf (patch)
tree0fe9786e05e8b83be5edd106e4622b0174405b1b
parent39b256f472d87f540db485117f6b32c2fc2f9135 (diff)
downloadorg.eclipse.e4.tools-23d21424073f1c6795657c62162ed15783577fbf.tar.gz
org.eclipse.e4.tools-23d21424073f1c6795657c62162ed15783577fbf.tar.xz
org.eclipse.e4.tools-23d21424073f1c6795657c62162ed15783577fbf.zip
Bug 432555, Bug 432372 - [model editor] add row filter and ability to
add attribute columns to list tab. Bug 424730 - Find (Class) button of Model Editor does not find classes outside the project Bug 404136 - Model editor should be able to select icons from other bundles/projects Remove empty values when filtering. BundleClass URI Editor (with Find, Create, Goto, and select Bundle or Package features) Icon URI Editor (with Find and filter by Bundle features) EmptyFilterOptionDialog. Model commands for marking duplicate and repairing duplicate items. Filter By Item Or Attribute -(and auto add filtered column) - with filter option for empty values Added Filtering To FindContribution dialog Added Empty utility class Find Contribution enhancements Engine for converting a project to bundle while importing a resoure Ongoing maintainance Change-Id: If3ee932af6e8a94f4668f5f5cdec92bc516ed0de Signed-off-by: Steven Spungin <steven@spungin.tv>
-rw-r--r--bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java38
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF4
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties1
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/build.properties3
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/fragment.e4xmi17
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/add_column.gifbin0 -> 543 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/bundle.pngbin0 -> 402 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/command.gifbin0 -> 528 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/copy_to_project.pngbin0 -> 354 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/filter_by_attribute.gifbin0 -> 166 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/filter_by_item.gifbin0 -> 585 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/find.pngbin0 -> 380 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/mark_occurrences.pngbin0 -> 557 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/missing_image_placeholder.pngbin0 -> 861 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/package_obj.gifbin0 -> 227 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/projects.pngbin0 -> 532 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/remove_filter.pngbin0 -> 325 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/reset_columns.gifbin0 -> 325 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/use_anyway.gifbin0 -> 331 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/add_to_dir_wiz.pngbin0 -> 6174 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/attribute_wiz.gifbin0 -> 3291 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/error_wiz.gifbin0 -> 3374 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/location_wiz.pngbin0 -> 7016 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newefix_wizban.pngbin0 -> 7540 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newfolder_wiz.pngbin0 -> 5842 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newsearch_wiz.gifbin0 -> 3122 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/package_wiz.pngbin0 -> 8344 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/plugin_wiz.gifbin0 -> 1737 bytes
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/plugin.xml7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/FilterEx.java104
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java33
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/ResourceSearchScope.java54
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java16
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties16
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java1
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java88
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AddonsEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AreaEditor.java8
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectMenuItemEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectToolItemEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DynamicMenuContributionEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/HandlerEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuItemEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartDescriptorEditor.java10
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java11
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PerspectiveEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolControlEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolItemEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialog.java349
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithHardcodedScope.java425
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithScopeAndFilter.java474
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AreaIconDialogEditor.java16
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/BundleImageCache.java130
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java233
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionDataFile.java677
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java973
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuIconDialogEditor.java6
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuItemIconDialogEditor.java6
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartDescriptorIconDialogEditor.java8
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartIconDialogEditor.java6
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PerspectiveIconDialogEditor.java6
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ToolItemIconDialogEditor.java6
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/WindowIconDialogEditor.java6
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ContributionUriCellEditor.java56
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/E4ToolItemMenu.java111
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeEditingSupport.java112
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeTableViewerColumn.java71
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IViewEObjects.java9
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java447
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/Messages.java19
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/E.java101
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/EmptyFilterOption.java (renamed from bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/SearchScope.java)27
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/TitleAreaFilterDialog.java163
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/TitleAreaFilterDialogWithEmptyOptions.java152
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/messages.properties5
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/BundleConverter.java65
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/Messages.java72
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformClassContributionCollector.java49
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java515
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformIconContributionCollector.java53
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/BundleClassDialog.java331
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/FindContributionDialog.java424
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/FindIconDialog.java38
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/IconDialog.java307
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedResourceDialog.java512
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/ProjectFolderPickerDialog.java257
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/ReferencedProjectPickerDialog.java75
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/UriDialog.java32
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/UriDialogType.java22
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/messages.properties58
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/AbstractHandler.java28
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateAttributesHandler.java64
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateElementIdsHandler.java20
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateItemsBase.java111
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateLabelsHandler.java20
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/RepairDuplicateItemsHandler.java115
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/UnmarkItemsHandler.java27
99 files changed, 7622 insertions, 655 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java
index 77060deb..5702b9e2 100644
--- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java
+++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/PDEClassContributionProvider.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.editor3x;
@@ -20,7 +21,12 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.e4.tools.emf.ui.common.FilterEx;
import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider;
+import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
@@ -34,14 +40,34 @@ public class PDEClassContributionProvider implements IClassContributionProvider
public PDEClassContributionProvider() {
searchEngine = new SearchEngine();
}
-
+
@SuppressWarnings("restriction")
public void findContribution(final Filter filter, final ContributionResultHandler handler) {
- // filter.project may be null in the live editor
- IJavaSearchScope scope = filter.project != null ? PDEJavaHelper
- .getSearchScope(filter.project) : SearchEngine
- .createWorkspaceScope();
-
+ boolean followReferences = true;
+ if (filter instanceof FilterEx) {
+ FilterEx filterEx = (FilterEx) filter;
+ if (filterEx.getSearchScope().contains(ResourceSearchScope.PROJECT) &&
+ !filterEx.getSearchScope().contains(ResourceSearchScope.REFERENCES)) {
+ followReferences = false;
+ }
+
+ }
+ IJavaSearchScope scope = null;
+ if (followReferences == false){
+ IJavaProject javaProject = JavaCore.create(filter.project);
+ IPackageFragmentRoot[] roots;
+ try {
+ roots = javaProject.getPackageFragmentRoots();
+ scope = SearchEngine.createJavaSearchScope(roots, false);
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ }else{
+ // filter.project may be null in the live editor
+ scope = filter.project != null ? PDEJavaHelper
+ .getSearchScope(filter.project) : SearchEngine
+ .createWorkspaceScope();
+ }
char[] packageName = null;
char[] typeName = null;
String currentContent = filter.namePattern;
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF
index f76095a5..f8fcbafb 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF
@@ -34,7 +34,9 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.9.0",
org.eclipse.equinox.preferences;bundle-version="3.4.0",
org.eclipse.e4.ui.workbench.swt;bundle-version="0.10.0",
org.eclipse.emf.ecore.xmi;bundle-version="2.9.0",
- org.eclipse.jdt.core
+ org.eclipse.jdt.core,
+ org.eclipse.pde.core,
+ org.eclipse.e4.core.commands
Bundle-ActivationPolicy: lazy
Import-Package: javax.annotation;version="1.0.0",
javax.inject;version="1.0.0",
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties b/bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties
index c8488e2b..cd369c37 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties
+++ b/bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties
@@ -97,6 +97,7 @@ IMG_org.eclipse.e4.tools.emf.ui.obj16.chart_organisation=/icons/full/obj16/chart
IMG_org.eclipse.e4.tools.emf.ui.obj16.error_obj=/icons/full/obj16/error_obj.gif
IMG_org.eclipse.e4.tools.emf.ui.obj16.world_edit=/icons/full/obj16/world_edit.png
IMG_org.eclipse.e4.tools.emf.ui.obj16.bullet_go=/icons/full/obj16/bullet_go.png
+IMG_org.eclipse.e4.tools.emf.ui.obj16.bundle = /icons/full/obj16/bundle.png
IMG_org.eclipse.e4.tools.emf.ui.wizban.fieldrefact_wiz=/icons/full/wizban/fieldrefact_wiz.png
IMG_org.eclipse.e4.tools.emf.ui.wizban.import_wiz=/icons/full/wizban/import_wiz.png
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/build.properties b/bundles/org.eclipse.e4.tools.emf.ui/build.properties
index cb921121..11fb1086 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/build.properties
+++ b/bundles/org.eclipse.e4.tools.emf.ui/build.properties
@@ -6,7 +6,8 @@ bin.includes = .,\
plugin.xml,\
css/,\
OSGI-INF/,\
- schema/
+ schema/,\
+ fragment.e4xmi
output.. = bin/
jars.compile.order = .
source.. = src/
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/fragment.e4xmi b/bundles/org.eclipse.e4.tools.emf.ui/fragment.e4xmi
new file mode 100644
index 00000000..cadc6334
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/fragment.e4xmi
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="ASCII"?>
+<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_GxnD8Ly2EeOxWJvPH-7sUQ">
+ <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Kmj8QLy2EeOxWJvPH-7sUQ" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
+ <elements xsi:type="commands:Command" xmi:id="_RRp7QLy2EeOxWJvPH-7sUQ" elementId="org.eclipse.e4.tools.emf.ui.command.mark_duplicate_ids" commandName="Mark Duplicate Model Element Ids" description="Marks Duplicate Model Element Ids"/>
+ <elements xsi:type="commands:Command" xmi:id="_9ITpgL2IEeOqSr2XZwfnmA" elementId="org.eclipse.e4.tools.emf.ui.command.mark_duplicate_labels" commandName="Mark Duplicate Model Labels" description="Marks Duplicate Model Labels"/>
+ <elements xsi:type="commands:Command" xmi:id="_RObi4L2MEeOqSr2XZwfnmA" elementId="org.eclipse.e4.tools.emf.ui.command.mark_duplicate_attributes" commandName="Mark Duplicate Model Attributes..." description="Marks Duplicate Model Attributes"/>
+ <elements xsi:type="commands:Command" xmi:id="_dySeYLzDEeO8eO1Rpb-rFA" elementId="org.eclipse.e4.tools.emf.ui.command.repair_duplicate_ids" commandName="Repair Duplicate Model Element IDs" description="Repairs Duplicate Model Element IDs"/>
+ <elements xsi:type="commands:Command" xmi:id="_CFlw8L2LEeOqSr2XZwfnmA" elementId="org.eclipse.e4.tools.emf.ui.command.unmark" commandName="Unmark Model Items" description="Unmarks All Model Items"/>
+ </fragments>
+ <fragments xsi:type="fragment:StringModelFragment" xmi:id="_jtmcsLy3EeOxWJvPH-7sUQ" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
+ <elements xsi:type="commands:Handler" xmi:id="_p45hULy3EeOxWJvPH-7sUQ" elementId="org.eclipse.e4.tools.emf.ui.handler.mark_duplicate_ids" contributionURI="bundleclass://org.eclipse.e4.tools.emf.ui/org.eclipse.e4.tools.emf.ui.internal.handlers.MarkDuplicateElementIdsHandler" command="_RRp7QLy2EeOxWJvPH-7sUQ"/>
+ <elements xsi:type="commands:Handler" xmi:id="_AOEgkL2JEeOqSr2XZwfnmA" elementId="org.eclipse.e4.tools.emf.ui.handler.mark_duplicate_labels" contributionURI="bundleclass://org.eclipse.e4.tools.emf.ui/org.eclipse.e4.tools.emf.ui.internal.handlers.MarkDuplicateLabelsHandler" command="_9ITpgL2IEeOqSr2XZwfnmA"/>
+ <elements xsi:type="commands:Handler" xmi:id="_TgJt4L2MEeOqSr2XZwfnmA" elementId="org.eclipse.e4.tools.emf.ui.handler.mark_duplicate_attributes" contributionURI="bundleclass://org.eclipse.e4.tools.emf.ui/org.eclipse.e4.tools.emf.ui.internal.handlers.MarkDuplicateAttributesHandler" command="_RObi4L2MEeOqSr2XZwfnmA"/>
+ <elements xsi:type="commands:Handler" xmi:id="_smaaALzDEeO8eO1Rpb-rFA" elementId="org.eclipse.e4.tools.emf.ui.handler.repair_duplicate_ids" contributionURI="bundleclass://org.eclipse.e4.tools.emf.ui/org.eclipse.e4.tools.emf.ui.internal.handlers.RepairDuplicateItemsHandler" command="_dySeYLzDEeO8eO1Rpb-rFA"/>
+ <elements xsi:type="commands:Handler" xmi:id="_Fin4gL2LEeOqSr2XZwfnmA" elementId="org.eclipse.e4.tools.emf.ui.handler.unmark" contributionURI="bundleclass://org.eclipse.e4.tools.emf.ui/org.eclipse.e4.tools.emf.ui.internal.handlers.UnmarkItemsHandler" command="_CFlw8L2LEeOqSr2XZwfnmA"/>
+ </fragments>
+</fragment:ModelFragments>
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/add_column.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/add_column.gif
new file mode 100644
index 00000000..b8715247
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/add_column.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/bundle.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/bundle.png
new file mode 100644
index 00000000..dd9003b1
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/bundle.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/command.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/command.gif
new file mode 100644
index 00000000..d6b3bdcc
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/command.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/copy_to_project.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/copy_to_project.png
new file mode 100644
index 00000000..c21bd732
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/copy_to_project.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/filter_by_attribute.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/filter_by_attribute.gif
new file mode 100644
index 00000000..cfb58e43
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/filter_by_attribute.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/filter_by_item.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/filter_by_item.gif
new file mode 100644
index 00000000..b9f9aaa4
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/filter_by_item.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/find.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/find.png
new file mode 100644
index 00000000..611189d6
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/find.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/mark_occurrences.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/mark_occurrences.png
new file mode 100644
index 00000000..8bb23610
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/mark_occurrences.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/missing_image_placeholder.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/missing_image_placeholder.png
new file mode 100644
index 00000000..78a436c0
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/missing_image_placeholder.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/package_obj.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/package_obj.gif
new file mode 100644
index 00000000..131c28da
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/package_obj.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/projects.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/projects.png
new file mode 100644
index 00000000..13e0451b
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/projects.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/remove_filter.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/remove_filter.png
new file mode 100644
index 00000000..ea14834f
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/remove_filter.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/reset_columns.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/reset_columns.gif
new file mode 100644
index 00000000..ea14834f
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/reset_columns.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/use_anyway.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/use_anyway.gif
new file mode 100644
index 00000000..2f1c5a8f
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/obj16/use_anyway.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/add_to_dir_wiz.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/add_to_dir_wiz.png
new file mode 100644
index 00000000..684431cd
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/add_to_dir_wiz.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/attribute_wiz.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/attribute_wiz.gif
new file mode 100644
index 00000000..8a70e59b
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/attribute_wiz.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/error_wiz.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/error_wiz.gif
new file mode 100644
index 00000000..2eb9efee
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/error_wiz.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/location_wiz.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/location_wiz.png
new file mode 100644
index 00000000..d79281c2
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/location_wiz.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newefix_wizban.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newefix_wizban.png
new file mode 100644
index 00000000..5d02d1cb
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newefix_wizban.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newfolder_wiz.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newfolder_wiz.png
new file mode 100644
index 00000000..f4861b1c
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newfolder_wiz.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newsearch_wiz.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newsearch_wiz.gif
new file mode 100644
index 00000000..a585f294
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/newsearch_wiz.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/package_wiz.png b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/package_wiz.png
new file mode 100644
index 00000000..07efd3e0
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/package_wiz.png
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/plugin_wiz.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/plugin_wiz.gif
new file mode 100644
index 00000000..5457eafa
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/wizban/plugin_wiz.gif
Binary files differ
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/plugin.xml b/bundles/org.eclipse.e4.tools.emf.ui/plugin.xml
index 91859ac6..aabe5383 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/plugin.xml
+++ b/bundles/org.eclipse.e4.tools.emf.ui/plugin.xml
@@ -15,5 +15,12 @@
class="org.eclipse.e4.tools.emf.ui.internal.PreferenceInitializer">
</initializer>
</extension>
+ <extension
+ id="id1"
+ point="org.eclipse.e4.workbench.model">
+ <fragment
+ uri="fragment.e4xmi">
+ </fragment>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/FilterEx.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/FilterEx.java
new file mode 100644
index 00000000..765aca72
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/FilterEx.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.common;
+
+import java.util.EnumSet;
+import java.util.List;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.Filter;
+
+/**
+ * An extension to the Filter class, allowing for bundles, packages, and
+ * locations to be specified.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class FilterEx extends Filter {
+
+ private List<String> bundles;
+ private List<String> packages;
+ private List<String> locations;
+ private EnumSet<ResourceSearchScope> searchScope = EnumSet.noneOf(ResourceSearchScope.class);
+ private boolean includeNonBundles;
+
+ public FilterEx(IProject project, String regNamePattern) {
+ super(project, regNamePattern);
+ }
+
+ /**
+ * Sets the bundles to filter on
+ *
+ * @param filterBundles
+ */
+ public void setBundles(List<String> filterBundles) {
+ bundles = filterBundles;
+ }
+
+ public void setPackages(List<String> filterPackages) {
+ packages = filterPackages;
+ }
+
+ public List<String> getBundles() {
+ return bundles;
+ }
+
+ /**
+ * Sets the packages to filter on
+ *
+ * @return
+ */
+ public List<String> getPackages() {
+ return packages;
+ }
+
+ public List<String> getLocations() {
+ return locations;
+ }
+
+ /**
+ * Sets the installed project locations to filter on
+ *
+ * @param locations
+ */
+ public void setLocations(List<String> locations) {
+ this.locations = locations;
+ }
+
+ public EnumSet<ResourceSearchScope> getSearchScope() {
+ return searchScope;
+ }
+
+ /**
+ * Sets the scope for the search.
+ *
+ * @param searchScope
+ */
+ public void setSearchScope(EnumSet<ResourceSearchScope> searchScope) {
+ this.searchScope = searchScope;
+ }
+
+ /**
+ * Include plain old java projects, resource projects, and others in
+ * searches. No manifest required.
+ *
+ * @param includeNonBundles
+ */
+ public void setIncludeNonBundles(boolean includeNonBundles) {
+ this.includeNonBundles = includeNonBundles;
+ }
+
+ public boolean isIncludeNonBundles() {
+ return includeNonBundles;
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java
index 53383e00..16f3e60c 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/IClassContributionProvider.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.common;
@@ -18,7 +19,17 @@ public interface IClassContributionProvider {
public final String className;
public final String sourceType;
public final String iconPath;
-
+
+ /**
+ * This is used if the resource is not contained in a referenced bundle,
+ * not a bundle, or not a project. It can be a jar file or a folder.
+ */
+ public String installLocation;
+ /**
+ * Path to the resource relative to the installLocation
+ */
+ public String resourceRelativePath;
+
public ContributionData(String bundleName, String className, String sourceType, String iconPath) {
this.bundleName = bundleName;
this.className = className;
@@ -26,20 +37,32 @@ public interface IClassContributionProvider {
this.iconPath = iconPath;
}
}
-
+
public class Filter {
public final IProject project;
public final String namePattern;
-
+ public int maxResults;
+ public Object userData;
+
public Filter(IProject project, String namePattern) {
this.project = project;
this.namePattern = namePattern;
}
}
-
+
public interface ContributionResultHandler {
public void result(ContributionData data);
+
+ /**
+ * This method is called at the end of a search. If the search
+ * terminated because maxResults was exceeded, the hint parameter will
+ * contain the number of additional results, or -1 if there are an
+ * unspecified number of additional results.
+ *
+ * No there are no additional results, hint will be 0.
+ */
+ public void moreResults(int hint, Filter filter);
}
-
+
public void findContribution(Filter filter, ContributionResultHandler handler);
}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/ResourceSearchScope.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/ResourceSearchScope.java
new file mode 100644
index 00000000..229b4299
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/ResourceSearchScope.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 404136, 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.common;
+
+/**
+ * Specifies the scope when searching for a resource. This differs from the PDE
+ * search functions in that <li>more than just java objects can be queried. <li>
+ * Searches can specify the current project only, current workspace, non bundle
+ * projects, and target platform.
+ *
+ * @author Steven Spungin
+ *
+ */
+public enum ResourceSearchScope {
+ /**
+ * The current project only
+ */
+ PROJECT,
+ /**
+ * Projects in the current workspace
+ */
+ WORKSPACE,
+ /**
+ * All plugins in target platform
+ */
+ TARGET_PLATFORM,
+ /**
+ * Eclipse Plugins and OSGi Bundles
+ */
+ // BUNDLES,
+ /**
+ * Eclipse Plugins
+ */
+ // PLUGINS,
+ /**
+ * Include resources in packages not exported by their bundles. Only applies
+ * to SearchScope.TargetPlatform and SearchScope.Workspace
+ */
+ NOT_EXPORTED,
+ /**
+ * Follow references to dependent projects and bundles. Only applies to
+ * SearchScope.Project
+ */
+ REFERENCES
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
index 8f96ada0..23d7128f 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
@@ -487,6 +487,12 @@ public class Messages {
public String AbstractIconDialog_current_project;
public String AbstractIconDialog_scope;
+ public static String AbstractIconDialogWithScopeAndFilter_details;
+ public static String AbstractIconDialogWithScopeAndFilter_icon;
+ public static String AbstractIconDialogWithScopeAndFilter_iconName;
+ public static String AbstractIconDialogWithScopeAndFilter_maxDisplayedImageSize;
+ public static String AbstractIconDialogWithScopeAndFilter_typeToStartSearch;
+
public String BindingContextSelectionDialog_ShellTitle;
public String BindingContextSelectionDialog_Title;
public String BindingContextSelectionDialog_Message;
@@ -677,4 +683,14 @@ public class Messages {
public static String ListTab_col_item;
public static String ListTab_col_label;
public static String ListTab_col_go;
+
+ public static String ListTab_addColumn;
+ public static String ListTab_filterByAttribute;
+ public static String ListTab_filterByItem;
+ public static String ListTab_mark;
+ public static String ListTab_markAttribute;
+ public static String ListTab_removeFilter;
+ public static String ListTab_resetColumns;
+ public static String ListTab_selectAnAttribute;
+ public static String ListTab_selectAType;
}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
index 77a4a81d..cb892aa4 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
@@ -497,6 +497,12 @@ VWindowTrimEditor_AddWindowTrim=Window Trim
AbstractIconDialog_IconName=IconName
+AbstractIconDialogWithScopeAndFilter_details=Details
+AbstractIconDialogWithScopeAndFilter_icon=Icon
+AbstractIconDialogWithScopeAndFilter_iconName=Icon Name
+AbstractIconDialogWithScopeAndFilter_maxDisplayedImageSize=Max Displayed Image Size
+AbstractIconDialogWithScopeAndFilter_typeToStartSearch=Type to start search
+
BindingContextSelectionDialog_ShellTitle=BindingContext Dialog
BindingContextSelectionDialog_Title=BindingContext
BindingContextSelectionDialog_Message=Search for a BindingContext
@@ -687,3 +693,13 @@ ListTab_col_id=ID
ListTab_col_item=Item
ListTab_col_label=Label
ListTab_col_go=Go
+
+ListTab_addColumn=Add Column
+ListTab_filterByAttribute=Filter By Attribute
+ListTab_filterByItem=Filter By Item
+ListTab_mark=Mark
+ListTab_markAttribute=Filter By Attribute
+ListTab_removeFilter=Remove Filter
+ListTab_resetColumns=Reset Columns
+ListTab_selectAnAttribute=Select an attribute
+ListTab_selectAType=Select a type
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java
index 48ecfb7b..dffdc5d0 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java
@@ -112,6 +112,7 @@ public class ResourceProvider extends BasicResourceProvider {
public static final String IMG_Obj16_error_obj = "IMG_org.eclipse.e4.tools.emf.ui.obj16.error_obj"; //$NON-NLS-1$
public static final String IMG_Obj16_world_edit = "IMG_org.eclipse.e4.tools.emf.ui.obj16.world_edit"; //$NON-NLS-1$
public static final String IMG_Obj16_bullet_go = "IMG_org.eclipse.e4.tools.emf.ui.obj16.bullet_go"; //$NON-NLS-1$
+ public static final String IMG_Obj16_bundle = "IMG_org.eclipse.e4.tools.emf.ui.obj16.bundle"; //$NON-NLS-1$
public static final String IMG_Wizban16_fieldrefact_wiz = "IMG_org.eclipse.e4.tools.emf.ui.wizban.fieldrefact_wiz"; //$NON-NLS-1$
public static final String IMG_Wizban16_import_wiz = "IMG_org.eclipse.e4.tools.emf.ui.wizban.import_wiz"; //$NON-NLS-1$
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
index 32fac0dd..5538517f 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
@@ -10,7 +10,7 @@
* Wim Jongman <wim.jongman@remainsoftware.com> - Maintenance
* Marco Descher <marco@descher.at> - Bug395982, 426653, 422465
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
- * Steven Spungin <steven@spungin.tv> - Bug 396902, 431755, 431735
+ * Steven Spungin <steven@spungin.tv> - Bug 396902, 431755, 431735, 424730, 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common;
@@ -291,6 +291,9 @@ public class ModelEditor implements IGotoObject {
@Inject
ESelectionService selectionService;
+ @Inject
+ MApplication app;
+
private IEclipseContext context;
private boolean fragment;
private Handler clipboardHandler;
@@ -343,6 +346,12 @@ public class ModelEditor implements IGotoObject {
private ListTab listTab;
+ private CTabItem tabItemXmi;
+
+ private CTabItem tabItemList;
+
+ private CTabItem tabItemTree;
+
public ModelEditor(Composite composite, IEclipseContext context, IModelResource modelProvider, IProject project, final IResourcePool resourcePool) {
this.resourcePool = resourcePool;
this.modelProvider = modelProvider;
@@ -411,15 +420,17 @@ public class ModelEditor implements IGotoObject {
emfDocumentProvider = new EMFDocumentResourceMediator(modelProvider);
editorTabFolder = new CTabFolder(composite, SWT.BOTTOM);
- CTabItem item = new CTabItem(editorTabFolder, SWT.NONE);
- item.setText(messages.ModelEditor_Form);
- item.setControl(createFormTab(editorTabFolder));
- item.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_application_form));
-
- item = new CTabItem(editorTabFolder, SWT.NONE);
- item.setText(messages.ModelEditor_XMI);
- item.setControl(createXMITab(editorTabFolder));
- item.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_chart_organisation));
+ tabItemTree = new CTabItem(editorTabFolder, SWT.NONE);
+ tabItemTree.setText(messages.ModelEditor_Form);
+ tabItemTree.setControl(createFormTab(editorTabFolder));
+ tabItemTree.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_application_form));
+
+ tab_list_show(preferences.getBoolean("tab-list-show", false)); //$NON-NLS-1$
+
+ tabItemXmi = new CTabItem(editorTabFolder, SWT.NONE);
+ tabItemXmi.setText(messages.ModelEditor_XMI);
+ tabItemXmi.setControl(createXMITab(editorTabFolder));
+ tabItemXmi.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_chart_organisation));
editorTabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -429,11 +440,34 @@ public class ModelEditor implements IGotoObject {
}
});
- tab_list_show(preferences.getBoolean("tab-list-show", false)); //$NON-NLS-1$
+ editorTabFolder.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ // When the list tab is visible, register the IViewEObjects
+ // interface
+ // This allows external commands to interact with the view.
+ // Eventually, all 3 tabs, or even the ModelEditor itself, could
+ // implement the interface.
+ String key = "org.eclipse.e4.tools.active-object-viewer"; //$NON-NLS-1$
+ if (editorTabFolder.getSelectionIndex() == getTabIndex(listTab.getTabItem())) {
+ app.getContext().set(key, listTab);
+ } else {
+ app.getContext().set(key, null);
+ }
+ }
+ });
editorTabFolder.setSelection(0);
}
+ /**
+ * @param tabItem
+ * @return The index of the tab item. Should never return -1.
+ */
+ static public int getTabIndex(CTabItem tabItem) {
+ return Arrays.asList(tabItem.getParent().getItems()).indexOf(tabItem);
+ }
+
private void findAndHighlight(Control control) {
if (control != null) {
MApplicationElement m = findModelElement(control);
@@ -1296,7 +1330,9 @@ public class ModelEditor implements IGotoObject {
child.set(CTabFolder.class, editorTabFolder);
child.set(EMFDocumentResourceMediator.class, emfDocumentProvider);
child.set(IGotoObject.class, this);
+ child.set(Messages.class, messages);
listTab = ContextInjectionFactory.make(ListTab.class, child);
+ tabItemList = listTab.getTabItem();
}
}
}
@@ -1422,7 +1458,8 @@ public class ModelEditor implements IGotoObject {
if (clipboardService != null) {
clipboardService.setHandler(clipboardHandler);
}
- viewer.getControl().setFocus();
+ // See bug 432095.
+ // viewer.getControl().setFocus();
}
@PreDestroy
@@ -1801,12 +1838,12 @@ public class ModelEditor implements IGotoObject {
viewer.reveal(object);
viewer.setSelection(new StructuredSelection(object));
- editorTabFolder.setSelection(0);
+ editorTabFolder.setSelection(getTabIndex(tabItemTree));
break;
case TAB_XMI:
- editorTabFolder.setSelection(1);
- // model was not updating in xmi document (selection listener
- // was not firing from programatic setSelection()
+ editorTabFolder.setSelection(getTabIndex(tabItemXmi));
+ // model was not updating in XMI document (selection listener
+ // was not firing from programmatic setSelection()
emfDocumentProvider.updateFromEMF();
try {
@@ -1817,28 +1854,13 @@ public class ModelEditor implements IGotoObject {
} else {
sourceViewer.setSelection(new TextSelection(0, 0), true);
}
- // String elementId = (String) EmfUtil.getAttributeValue(object, "elementId"); //$NON-NLS-1$
- // if (elementId != null && elementId.isEmpty() == false) {
- // int loc2 = emfDocumentProvider.indexOf(object);
- // loc = emfDocumentProvider.getDocument().search(0,
- // elementId, true, true, true);
- // if (loc >= 0) {
- // ISelection selection = new TextSelection(loc,
- // elementId.length());
- // sourceViewer.setSelection(selection, true);
- // } else {
- // sourceViewer.setSelection(new TextSelection(0, 0));
- // }
- // } else {
- // sourceViewer.setSelection(new TextSelection(0, 0));
- // }
} catch (Exception e) {
e.printStackTrace();
}
break;
case TAB_LIST:
- if (listTab != null) {
- editorTabFolder.setSelection(Arrays.asList(editorTabFolder.getItems()).indexOf(listTab.getTabItem()));
+ if (tabItemList != null) {
+ editorTabFolder.setSelection(getTabIndex(tabItemList));
listTab.getViewer().setSelection(new StructuredSelection(object), true);
}
break;
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AddonsEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AddonsEditor.java
index 1e4a6c04..f33cb1c1 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AddonsEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AddonsEditor.java
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -17,6 +18,7 @@ import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ContributionURIValidator;
import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
@@ -63,6 +65,9 @@ public class AddonsEditor extends AbstractComponentEditor {
@Optional
private IProject project;
+ @Inject
+ IEclipseContext eclipseContext;
+
private StackLayout stackLayout;
@Inject
@@ -191,7 +196,7 @@ public class AddonsEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
+ ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), eclipseContext, project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AreaEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AreaEditor.java
index 99ec4143..4aa400a7 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AreaEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/AreaEditor.java
@@ -8,7 +8,7 @@
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
- * Steven Spungin <steven@spungin.tv> - Bug 433408
+ * Steven Spungin <steven@spungin.tv> - Bug 433408, 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -20,6 +20,7 @@ import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.databinding.property.list.IListProperty;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ImageTooltip;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -95,6 +96,9 @@ public class AreaEditor extends AbstractComponentEditor {
private IProject project;
@Inject
+ IEclipseContext eclipseContext;
+
+ @Inject
public AreaEditor() {
super();
}
@@ -256,7 +260,7 @@ public class AreaEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- AreaIconDialogEditor dialog = new AreaIconDialogEditor(b.getShell(), project, getEditingDomain(), (MApplicationElement) getMaster().getValue(), Messages);
+ AreaIconDialogEditor dialog = new AreaIconDialogEditor(b.getShell(), eclipseContext, project, getEditingDomain(), (MApplicationElement) getMaster().getValue(), Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectMenuItemEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectMenuItemEditor.java
index d8931cc6..bdaefb43 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectMenuItemEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectMenuItemEditor.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -18,6 +19,7 @@ import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.observable.value.WritableValue;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.common.ContributionURIValidator;
import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -59,6 +61,9 @@ public class DirectMenuItemEditor extends MenuItemEditor {
private IEMFValueProperty UI_ELEMENT__VISIBLE_WHEN = EMFProperties.value(UiPackageImpl.Literals.UI_ELEMENT__VISIBLE_WHEN);
@Inject
+ IEclipseContext eclipseContext;
+
+ @Inject
public DirectMenuItemEditor() {
super();
}
@@ -158,7 +163,7 @@ public class DirectMenuItemEditor extends MenuItemEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
+ ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), eclipseContext, project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectToolItemEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectToolItemEditor.java
index 1344120a..b2a0720a 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectToolItemEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DirectToolItemEditor.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -17,6 +18,7 @@ import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.observable.value.WritableValue;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.common.ContributionURIValidator;
import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -58,6 +60,9 @@ public class DirectToolItemEditor extends ToolItemEditor {
private IEMFValueProperty UI_ELEMENT__VISIBLE_WHEN = EMFProperties.value(UiPackageImpl.Literals.UI_ELEMENT__VISIBLE_WHEN);
@Inject
+ IEclipseContext eclipseContext;
+
+ @Inject
public DirectToolItemEditor() {
super();
}
@@ -121,7 +126,7 @@ public class DirectToolItemEditor extends ToolItemEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
+ ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), eclipseContext, project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DynamicMenuContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DynamicMenuContributionEditor.java
index abb1e9e9..c2603eda 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DynamicMenuContributionEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DynamicMenuContributionEditor.java
@@ -8,6 +8,7 @@
* Contributors:
* Marco Descher <marco@descher.at> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
*******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -17,6 +18,7 @@ import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ContributionURIValidator;
import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
@@ -66,6 +68,9 @@ public class DynamicMenuContributionEditor extends AbstractComponentEditor {
@Optional
private IProject project;
+ @Inject
+ IEclipseContext eclipseContext;
+
public DynamicMenuContributionEditor() {
super();
}
@@ -198,7 +203,7 @@ public class DynamicMenuContributionEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
+ ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), eclipseContext, project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/HandlerEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/HandlerEditor.java
index b621da2c..c79c9b35 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/HandlerEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/HandlerEditor.java
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -17,6 +18,7 @@ import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.CommandToStringConverter;
import org.eclipse.e4.tools.emf.ui.common.ContributionURIValidator;
@@ -72,6 +74,9 @@ public class HandlerEditor extends AbstractComponentEditor {
private IProject project;
@Inject
+ IEclipseContext eclipseContext;
+
+ @Inject
public HandlerEditor() {
super();
}
@@ -215,7 +220,7 @@ public class HandlerEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
+ ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), eclipseContext, project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java
index 32df3efb..118c37f9 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java
@@ -9,6 +9,7 @@
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Marco Descher <marco@descher.at> - Bug 395982
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -27,6 +28,7 @@ import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.databinding.property.list.IListProperty;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ImageTooltip;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -107,6 +109,9 @@ public class MenuEditor extends AbstractComponentEditor {
@Optional
private IProject project;
+ @Inject
+ IEclipseContext eclipseContext;
+
private Action addExpression;
private static class Struct {
@@ -415,7 +420,7 @@ public class MenuEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- MenuIconDialogEditor dialog = new MenuIconDialogEditor(b.getShell(), project, getEditingDomain(), (MMenu) getMaster().getValue(), Messages);
+ MenuIconDialogEditor dialog = new MenuIconDialogEditor(b.getShell(), eclipseContext, project, getEditingDomain(), (MMenu) getMaster().getValue(), Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuItemEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuItemEditor.java
index 84a526a0..eeadda41 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuItemEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuItemEditor.java
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -21,6 +22,7 @@ import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ImageTooltip;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -82,6 +84,9 @@ public abstract class MenuItemEditor extends AbstractComponentEditor {
@Optional
protected IProject project;
+ @Inject
+ IEclipseContext eclipseContext;
+
private Action addExpression;
public MenuItemEditor() {
@@ -226,7 +231,7 @@ public abstract class MenuItemEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- MenuItemIconDialogEditor dialog = new MenuItemIconDialogEditor(b.getShell(), project, getEditingDomain(), (MMenuItem) getMaster().getValue(), Messages);
+ MenuItemIconDialogEditor dialog = new MenuItemIconDialogEditor(b.getShell(), eclipseContext, project, getEditingDomain(), (MMenuItem) getMaster().getValue(), Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartDescriptorEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartDescriptorEditor.java
index 5e7703d3..aebc5b3c 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartDescriptorEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartDescriptorEditor.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
- * Steven Spungin <steven@spungin.tv> - Bug 404166
+ * Steven Spungin <steven@spungin.tv> - Bug 404166, 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -20,6 +20,7 @@ import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.property.list.IListProperty;
import org.eclipse.core.databinding.property.value.IValueProperty;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
import org.eclipse.e4.tools.emf.ui.common.ImageTooltip;
@@ -77,6 +78,9 @@ public class PartDescriptorEditor extends AbstractComponentEditor {
@Optional
private IProject project;
+ @Inject
+ IEclipseContext eclipseContext;
+
private IListProperty PART__MENUS = EMFProperties.list(BasicPackageImpl.Literals.PART_DESCRIPTOR__MENUS);
private IListProperty HANDLER_CONTAINER__HANDLERS = EMFProperties.list(CommandsPackageImpl.Literals.HANDLER_CONTAINER__HANDLERS);
private IValueProperty PART__TOOLBAR = EMFProperties.value(BasicPackageImpl.Literals.PART_DESCRIPTOR__TOOLBAR);
@@ -196,7 +200,7 @@ public class PartDescriptorEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- PartDescriptorIconDialogEditor dialog = new PartDescriptorIconDialogEditor(b.getShell(), project, getEditingDomain(), (MPartDescriptor) getMaster().getValue(), Messages);
+ PartDescriptorIconDialogEditor dialog = new PartDescriptorIconDialogEditor(b.getShell(), eclipseContext, project, getEditingDomain(), (MPartDescriptor) getMaster().getValue(), Messages);
dialog.open();
}
});
@@ -248,7 +252,7 @@ public class PartDescriptorEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MPartDescriptor) getMaster().getValue(), BasicPackageImpl.Literals.PART_DESCRIPTOR__CONTRIBUTION_URI, Messages);
+ ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), eclipseContext, project, getEditingDomain(), (MPartDescriptor) getMaster().getValue(), BasicPackageImpl.Literals.PART_DESCRIPTOR__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java
index eeaaedcf..15be9c08 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java
@@ -7,7 +7,8 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
- ******************************************************************************/
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
+******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
import javax.inject.Inject;
@@ -21,6 +22,7 @@ import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.property.list.IListProperty;
import org.eclipse.core.databinding.property.value.IValueProperty;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ContributionURIValidator;
import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
@@ -91,6 +93,9 @@ public class PartEditor extends AbstractComponentEditor {
private IProject project;
@Inject
+ IEclipseContext eclipseContext;
+
+ @Inject
public PartEditor() {
super();
}
@@ -214,7 +219,7 @@ public class PartEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- PartIconDialogEditor dialog = new PartIconDialogEditor(b.getShell(), project, getEditingDomain(), (MPart) getMaster().getValue(), Messages);
+ PartIconDialogEditor dialog = new PartIconDialogEditor(b.getShell(), eclipseContext, project, getEditingDomain(), (MPart) getMaster().getValue(), Messages);
dialog.open();
}
});
@@ -267,7 +272,7 @@ public class PartEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
+ ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), eclipseContext, project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PerspectiveEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PerspectiveEditor.java
index caa2b8b3..fbff8850 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PerspectiveEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PerspectiveEditor.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -19,6 +20,7 @@ import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.databinding.property.list.IListProperty;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ImageTooltip;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -80,6 +82,9 @@ public class PerspectiveEditor extends AbstractComponentEditor {
private IProject project;
@Inject
+ IEclipseContext eclipseContext;
+
+ @Inject
public PerspectiveEditor() {
super();
}
@@ -242,7 +247,7 @@ public class PerspectiveEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- PerspectiveIconDialogEditor dialog = new PerspectiveIconDialogEditor(b.getShell(), project, getEditingDomain(), (MPerspective) getMaster().getValue(), Messages);
+ PerspectiveIconDialogEditor dialog = new PerspectiveIconDialogEditor(b.getShell(), eclipseContext, project, getEditingDomain(), (MPerspective) getMaster().getValue(), Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolControlEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolControlEditor.java
index b07392ac..ac9d5bfb 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolControlEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolControlEditor.java
@@ -9,6 +9,7 @@
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
* Dmitry Spiridenok <d.spiridenok@gmail.com> - Bug 412672
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -16,6 +17,7 @@ import javax.inject.Inject;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -65,6 +67,9 @@ public class ToolControlEditor extends AbstractComponentEditor {
private IProject project;
@Inject
+ IEclipseContext eclipseContext;
+
+ @Inject
public ToolControlEditor() {
super();
}
@@ -187,7 +192,7 @@ public class ToolControlEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
+ ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), eclipseContext, project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolItemEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolItemEditor.java
index 68aa5e89..ea2c3678 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolItemEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolItemEditor.java
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -24,6 +25,7 @@ import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.databinding.property.value.IValueProperty;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ImageTooltip;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -84,6 +86,9 @@ public abstract class ToolItemEditor extends AbstractComponentEditor {
@Optional
protected IProject project;
+ @Inject
+ IEclipseContext eclipseContext;
+
private Button createRemoveMenu;
public ToolItemEditor() {
@@ -231,7 +236,7 @@ public abstract class ToolItemEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- ToolItemIconDialogEditor dialog = new ToolItemIconDialogEditor(b.getShell(), project, getEditingDomain(), (MToolItem) getMaster().getValue(), Messages);
+ ToolItemIconDialogEditor dialog = new ToolItemIconDialogEditor(b.getShell(), eclipseContext, project, getEditingDomain(), (MToolItem) getMaster().getValue(), Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java
index 0ccc350b..604612b8 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component;
@@ -23,6 +24,7 @@ import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.databinding.property.list.IListProperty;
import org.eclipse.core.databinding.property.value.IValueProperty;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.ImageTooltip;
import org.eclipse.e4.tools.emf.ui.common.Util;
@@ -89,6 +91,9 @@ public class WindowEditor extends AbstractComponentEditor {
private IProject project;
@Inject
+ IEclipseContext eclipseContext;
+
+ @Inject
public WindowEditor() {
super();
}
@@ -253,7 +258,7 @@ public class WindowEditor extends AbstractComponentEditor {
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- WindowIconDialogEditor dialog = new WindowIconDialogEditor(b.getShell(), project, getEditingDomain(), (MWindow) getMaster().getValue(), Messages);
+ WindowIconDialogEditor dialog = new WindowIconDialogEditor(b.getShell(), eclipseContext, project, getEditingDomain(), (MWindow) getMaster().getValue(), Messages);
dialog.open();
}
});
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialog.java
index 79578852..4de500e5 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialog.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialog.java
@@ -7,377 +7,58 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
- * Steven Spungin <steven@spungin.tv> - Bug 404136
+ * Steven Spungin <steven@spungin.tv> - Bug 404136, Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-import org.eclipse.core.databinding.observable.list.IObservableList;
-import org.eclipse.core.databinding.observable.list.WritableList;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceVisitor;
-import org.eclipse.core.runtime.CoreException;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
-import org.eclipse.e4.tools.emf.ui.internal.StringMatcher;
import org.eclipse.e4.ui.model.application.MApplicationElement;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-public abstract class AbstractIconDialog extends TitleAreaDialog {
- private TableViewer viewer;
+public abstract class AbstractIconDialog extends AbstractIconDialogWithScopeAndFilter {
private IProject project;
private MApplicationElement element;
private EStructuralFeature feature;
private EditingDomain editingDomain;
- private Map<IFile, Image> icons = Collections.synchronizedMap(new HashMap<IFile, Image>());
- private SearchScope searchScope = SearchScope.PROJECT;
+ // private Map<IFile, Image> icons = Collections.synchronizedMap(new
+ // HashMap<IFile, Image>());
protected Messages Messages;
- private Text textFilter;
- public AbstractIconDialog(Shell parentShell, IProject project, EditingDomain editingDomain, MApplicationElement element, EStructuralFeature feature, Messages Messages) {
- super(parentShell);
+ public AbstractIconDialog(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MApplicationElement element, EStructuralFeature feature, Messages Messages) {
+ super(parentShell, context);
this.editingDomain = editingDomain;
this.element = element;
this.feature = feature;
this.project = project;
this.Messages = Messages;
+ context.set(Messages.class, Messages);
}
- protected abstract String getShellTitle();
-
- protected abstract String getDialogTitle();
-
- protected abstract String getDialogMessage();
-
@Override
- protected Control createDialogArea(Composite parent) {
- Composite comp = (Composite) super.createDialogArea(parent);
-
- getShell().setText(getShellTitle());
- setTitle(getDialogTitle());
- setMessage(getDialogMessage());
-
- Composite container = new Composite(comp, SWT.NONE);
- container.setLayoutData(new GridData(GridData.FILL_BOTH));
- container.setLayout(new GridLayout(2, false));
-
- Label lblScope = new Label(container, SWT.NONE);
- lblScope.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
- lblScope.setText(Messages.AbstractIconDialog_scope);
-
- Composite compOptions = new Composite(container, SWT.NONE);
- compOptions.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- compOptions.setLayout(new RowLayout());
-
- Button btnProject = new Button(compOptions, SWT.RADIO);
- btnProject.setText(Messages.AbstractIconDialog_current_project);
- btnProject.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- searchScope = SearchScope.PROJECT;
- textFilter.notifyListeners(SWT.Modify, new Event());
-
- }
- });
- btnProject.setSelection(true);
-
- Button btnWorkspace = new Button(compOptions, SWT.RADIO);
- btnWorkspace.setText(Messages.AbstractIconDialog_all_workspace_bundles);
- btnWorkspace.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- searchScope = SearchScope.WORKSPACE;
- textFilter.notifyListeners(SWT.Modify, new Event());
- }
- });
-
- btnWorkspace.setSelection(searchScope == SearchScope.WORKSPACE);
- btnProject.setSelection(searchScope == SearchScope.PROJECT);
-
- Label l = new Label(container, SWT.NONE);
- l.setText(Messages.AbstractIconDialog_IconName);
-
- textFilter = new Text(container, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH);
- textFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- new Label(container, SWT.NONE);
-
- viewer = new TableViewer(container);
- GridData gd = new GridData(GridData.FILL_BOTH);
- viewer.getControl().setLayoutData(gd);
- viewer.setContentProvider(new ObservableListContentProvider());
- viewer.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- IFile file = (IFile) cell.getElement();
- StyledString styledString = new StyledString(file.getProjectRelativePath().toString(), null);
-
- Image img = icons.get(file);
- if (img == null) {
- InputStream in = null;
- try {
- in = file.getContents();
- img = new Image(cell.getControl().getDisplay(), in);
- icons.put(file, img);
- } catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
-
- String bundle = getBundle(file);
- if (bundle != null) {
- styledString.append(" - " + bundle, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
- }
-
- cell.setImage(img);
- cell.setText(styledString.getString());
- cell.setStyleRanges(styledString.getStyleRanges());
- }
- });
-
- final WritableList list = new WritableList();
- viewer.setInput(list);
- viewer.addDoubleClickListener(new IDoubleClickListener() {
-
- @Override
- public void doubleClick(DoubleClickEvent event) {
- okPressed();
- }
- });
-
- textFilter.addModifyListener(new ModifyListener() {
- private IconMatchCallback callback;
- private Timer timer = new Timer(true);
- private TimerTask task;
-
- @Override
- public void modifyText(ModifyEvent e) {
- if (callback != null) {
- callback.cancel = true;
- }
- if (task != null) {
- task.cancel();
- }
- list.clear();
-
- clearImages();
-
- callback = new IconMatchCallback(list);
- task = new SearchThread(callback, textFilter.getText(), project, searchScope);
- timer.schedule(task, 500);
- }
- });
-
- getShell().addDisposeListener(new DisposeListener() {
-
- @Override
- public void widgetDisposed(DisposeEvent e) {
- clearImages();
- }
- });
-
- return comp;
- }
-
- private void clearImages() {
- for (Image img : icons.values()) {
- img.dispose();
- }
- icons.clear();
+ protected String getFilterTextMessage() {
+ return "Type to start search";
}
@Override
- protected boolean isResizable() {
- return true;
+ protected String getResourceNameText() {
+ return "Icon Name";
}
@Override
protected void okPressed() {
- IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
- if (!s.isEmpty()) {
- IFile file = (IFile) s.getFirstElement();
- String bundle = getBundle(file);
- String uri = "platform:/plugin/" + bundle + "/" + file.getProjectRelativePath().toString(); //$NON-NLS-1$//$NON-NLS-2$
+ super.okPressed();
+ String uri = getValue();
+ if (uri != null) {
Command cmd = SetCommand.create(editingDomain, element, feature, uri);
if (cmd.canExecute()) {
editingDomain.getCommandStack().execute(cmd);
- super.okPressed();
- }
- }
- }
-
- private String getBundle(IFile file) {
- IProject project = file.getProject();
- IFile f = project.getFile("/META-INF/MANIFEST.MF"); //$NON-NLS-1$
-
- if (f != null && f.exists()) {
- BufferedReader r = null;
- try {
- InputStream s = f.getContents();
- r = new BufferedReader(new InputStreamReader(s));
- String line;
- while ((line = r.readLine()) != null) {
- if (line.startsWith("Bundle-SymbolicName:")) { //$NON-NLS-1$
- int start = line.indexOf(':');
- int end = line.indexOf(';');
- if (end == -1) {
- end = line.length();
- }
- return line.substring(start + 1, end).trim();
- }
- }
- } catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- if (r != null) {
- try {
- r.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
- return null;
- }
-
- private class IconMatchCallback {
- private volatile boolean cancel;
- private IObservableList list;
-
- private IconMatchCallback(IObservableList list) {
- this.list = list;
- }
-
- public void match(final IFile file) {
- if (!cancel) {
- list.getRealm().exec(new Runnable() {
-
- @Override
- public void run() {
- list.add(file);
- }
- });
- }
- }
- }
-
- private static class SearchThread extends TimerTask {
- private final IconMatchCallback callback;
- private final IProject project;
- private final StringMatcher matcherGif;
- private final StringMatcher matcherJpg;
- private final StringMatcher matcherPng;
- private SearchScope searchScope;
-
- public SearchThread(IconMatchCallback callback, String pattern, IProject project, SearchScope searchScope) {
- this.matcherGif = new StringMatcher("*" + pattern + "*.gif", true, false); //$NON-NLS-1$//$NON-NLS-2$
- this.matcherJpg = new StringMatcher("*" + pattern + "*.jpg", true, false); //$NON-NLS-1$//$NON-NLS-2$
- this.matcherPng = new StringMatcher("*" + pattern + "*.png", true, false); //$NON-NLS-1$//$NON-NLS-2$
- this.callback = callback;
- this.project = project;
- this.searchScope = searchScope;
- }
-
- @Override
- public void run() {
- List<IProject> projects;
- switch (searchScope) {
- case WORKSPACE:
- projects = Arrays.asList(project.getWorkspace().getRoot().getProjects());
- break;
- case PROJECT:
- default:
- projects = Arrays.asList(project);
- break;
- }
- try {
- for (IProject project : projects) {
- // Only search bundles
- if (project.getFile("/META-INF/MANIFEST.MF").exists() == false) { //$NON-NLS-1$
- continue;
- }
- project.accept(new IResourceVisitor() {
-
- @Override
- public boolean visit(IResource resource) throws CoreException {
- if (callback.cancel) {
- return false;
- }
-
- if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.PROJECT) {
- return true;
- } else if (resource.getType() == IResource.FILE && !resource.isLinked()) {
- String path = resource.getProjectRelativePath().toString();
- if (matcherGif.match(path) || matcherPng.match(path) || matcherJpg.match(path)) {
- callback.match((IFile) resource);
- }
- }
- return false;
- }
-
- });
- }
- } catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
}
}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithHardcodedScope.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithHardcodedScope.java
new file mode 100644
index 00000000..8fb47c6d
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithHardcodedScope.java
@@ -0,0 +1,425 @@
+/*******************************************************************************
+ * Copyright (c) 2010 BestSolution.at 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:
+ * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 404136, 424730
+ ******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope;
+import org.eclipse.e4.tools.emf.ui.internal.Messages;
+import org.eclipse.e4.tools.emf.ui.internal.StringMatcher;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Based of of AbstractIconDialog, but passively returns selection instead of
+ * modifying model.
+ *
+ * @author Steven Spungin
+ *
+ */
+public abstract class AbstractIconDialogWithHardcodedScope extends TitleAreaDialog {
+ private TableViewer viewer;
+ private IProject project;
+ private Map<IFile, Image> icons = Collections.synchronizedMap(new HashMap<IFile, Image>());
+ private ResourceSearchScope searchScope = ResourceSearchScope.PROJECT;
+
+ protected Messages Messages;
+ private Text textSearch;
+ private String value;
+ private IEclipseContext context;
+
+ public AbstractIconDialogWithHardcodedScope(Shell parentShell, IEclipseContext context) {
+ super(parentShell);
+ this.context = context;
+ this.project = context.get(IProject.class);
+ Messages = context.get(Messages.class);
+ }
+
+ protected IEclipseContext getContext() {
+ return context;
+ }
+
+ protected abstract String getShellTitle();
+
+ protected abstract String getDialogTitle();
+
+ protected abstract String getDialogMessage();
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite comp = (Composite) super.createDialogArea(parent);
+
+ getShell().setText(getShellTitle());
+ setTitle(getDialogTitle());
+ setMessage(getDialogMessage());
+ String bundleFilter = (String) context.get("bundle");
+ if (E.notEmpty(bundleFilter)) {
+ setMessage("Filtering by bundle " + bundleFilter); //$NON-NLS-1$
+ }
+
+ Composite container = new Composite(comp, SWT.NONE);
+ container.setLayoutData(new GridData(GridData.FILL_BOTH));
+ container.setLayout(new GridLayout(2, false));
+
+ Composite compOptions = new Composite(container, SWT.NONE);
+ compOptions.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ compOptions.setLayout(new RowLayout());
+
+ if (E.isEmpty(bundleFilter)) {
+ Button btnProject = new Button(compOptions, SWT.RADIO);
+ btnProject.setText("Project");
+ btnProject.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ searchScope = ResourceSearchScope.PROJECT;
+ textSearch.notifyListeners(SWT.Modify, new Event());
+
+ }
+ });
+ btnProject.setSelection(true);
+
+ Button btnWorkspace = new Button(compOptions, SWT.RADIO);
+ btnWorkspace.setText("Workspace");
+ btnWorkspace.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ searchScope = ResourceSearchScope.WORKSPACE;
+ textSearch.notifyListeners(SWT.Modify, new Event());
+ }
+ });
+
+ btnWorkspace.setSelection(searchScope == ResourceSearchScope.WORKSPACE);
+ btnProject.setSelection(searchScope == ResourceSearchScope.PROJECT);
+ } else {
+ searchScope = ResourceSearchScope.WORKSPACE;
+ }
+
+ Label l = new Label(container, SWT.NONE);
+ l.setText(Messages.AbstractIconDialog_IconName);
+
+ textSearch = new Text(container, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH);
+ textSearch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ new Label(container, SWT.NONE);
+
+ viewer = new TableViewer(container, SWT.FULL_SELECTION);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ viewer.getControl().setLayoutData(gd);
+ viewer.setContentProvider(new ObservableListContentProvider());
+ viewer.setLabelProvider(new StyledCellLabelProvider() {
+ @Override
+ public void update(ViewerCell cell) {
+ IFile file = (IFile) cell.getElement();
+ StyledString styledString = new StyledString(file.getProjectRelativePath().toString(), null);
+
+ Image img = icons.get(file);
+ if (img == null) {
+ InputStream in = null;
+ try {
+ in = file.getContents();
+ img = new Image(cell.getControl().getDisplay(), in);
+ icons.put(file, img);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ String bundle = getBundle(file);
+ if (bundle != null) {
+ styledString.append(" - " + bundle, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ }
+
+ cell.setImage(img);
+ cell.setText(styledString.getString());
+ cell.setStyleRanges(styledString.getStyleRanges());
+ }
+ });
+
+ final WritableList list = new WritableList();
+ viewer.setInput(list);
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ okPressed();
+ }
+ });
+
+ textSearch.addModifyListener(new ModifyListener() {
+ private IconMatchCallback callback;
+ private Timer timer = new Timer(true);
+ private TimerTask task;
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (callback != null) {
+ callback.cancel = true;
+ }
+ if (task != null) {
+ task.cancel();
+ }
+ list.clear();
+
+ clearImages();
+
+ callback = new IconMatchCallback(list);
+ task = new SearchThread(callback, textSearch.getText(), project, context, searchScope);
+ timer.schedule(task, 500);
+ }
+ });
+
+ getShell().addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ clearImages();
+ }
+ });
+
+ textSearch.notifyListeners(SWT.Modify, new Event());
+
+ return comp;
+ }
+
+ private void clearImages() {
+ for (Image img : icons.values()) {
+ img.dispose();
+ }
+ icons.clear();
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected void okPressed() {
+ value = null;
+ IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
+ if (!s.isEmpty()) {
+ IFile file = (IFile) s.getFirstElement();
+ String bundle = getBundle(file);
+ value = "platform:/plugin/" + bundle + "/" + file.getProjectRelativePath().toString(); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ super.okPressed();
+ }
+
+ private String getBundle(IFile file) {
+ IProject project = file.getProject();
+ IFile f = project.getFile("/META-INF/MANIFEST.MF"); //$NON-NLS-1$
+
+ if (f != null && f.exists()) {
+ BufferedReader r = null;
+ try {
+ InputStream s = f.getContents();
+ r = new BufferedReader(new InputStreamReader(s));
+ String line;
+ while ((line = r.readLine()) != null) {
+ if (line.startsWith("Bundle-SymbolicName:")) { //$NON-NLS-1$
+ int start = line.indexOf(':');
+ int end = line.indexOf(';');
+ if (end == -1) {
+ end = line.length();
+ }
+ return line.substring(start + 1, end).trim();
+ }
+ }
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ if (r != null) {
+ try {
+ r.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ private class IconMatchCallback {
+ private volatile boolean cancel;
+ private IObservableList list;
+
+ private IconMatchCallback(IObservableList list) {
+ this.list = list;
+ }
+
+ public void match(final IFile file) {
+ if (!cancel) {
+ list.getRealm().exec(new Runnable() {
+
+ @Override
+ public void run() {
+ list.add(file);
+ }
+ });
+ }
+ }
+ }
+
+ private static class SearchThread extends TimerTask {
+ private final IconMatchCallback callback;
+ private final IProject project;
+ private final StringMatcher matcherGif;
+ private final StringMatcher matcherJpg;
+ private final StringMatcher matcherPng;
+ private IEclipseContext context;
+ private ResourceSearchScope searchScope;
+
+ public SearchThread(IconMatchCallback callback, String pattern, IProject project, IEclipseContext context, ResourceSearchScope searchScope) {
+ this.context = context;
+ this.matcherGif = new StringMatcher("*" + pattern + "*.gif", true, false); //$NON-NLS-1$//$NON-NLS-2$
+ this.matcherJpg = new StringMatcher("*" + pattern + "*.jpg", true, false); //$NON-NLS-1$//$NON-NLS-2$
+ this.matcherPng = new StringMatcher("*" + pattern + "*.png", true, false); //$NON-NLS-1$//$NON-NLS-2$
+ this.callback = callback;
+ this.project = project;
+ this.searchScope = searchScope;
+ }
+
+ @Override
+ public void run() {
+ List<IProject> projects;
+ switch (searchScope) {
+ case WORKSPACE:
+ projects = Arrays.asList(project.getWorkspace().getRoot().getProjects());
+ break;
+ case PROJECT:
+ default:
+ projects = Arrays.asList(project);
+ break;
+ }
+ try {
+ for (IProject project : projects) {
+ // Only search bundles
+ IFile iFile = project.getFile("/META-INF/MANIFEST.MF"); //$NON-NLS-1$
+ if (iFile.exists() == false) {
+ continue;
+ }
+ // Only search target bundle if specified
+ String bundle = (String) context.get("bundle");
+ if (E.notEmpty(bundle)) {
+ InputStream inputStream = null;
+ try {
+ inputStream = iFile.getContents();
+ Properties props = new Properties();
+ props.load(inputStream);
+ String name = props.getProperty("Bundle-SymbolicName"); //$NON-NLS-1$
+ String[] parts = name.split(";"); //$NON-NLS-1$
+ if (parts[0].equals(bundle) == false) {
+ continue;
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ try {
+ inputStream.close();
+ } catch (Exception ex) {
+ }
+ }
+ }
+ project.accept(new IResourceVisitor() {
+
+ @Override
+ public boolean visit(IResource resource) throws CoreException {
+ if (callback.cancel) {
+ return false;
+ }
+
+ if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.PROJECT) {
+ return true;
+ } else if (resource.getType() == IResource.FILE && !resource.isLinked()) {
+ String path = resource.getProjectRelativePath().toString();
+ if (matcherGif.match(path) || matcherPng.match(path) || matcherJpg.match(path)) {
+ callback.match((IFile) resource);
+ }
+ }
+ return false;
+ }
+
+ });
+ }
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithScopeAndFilter.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithScopeAndFilter.java
new file mode 100644
index 00000000..6aa99a24
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AbstractIconDialogWithScopeAndFilter.java
@@ -0,0 +1,474 @@
+/*******************************************************************************
+
+ * Copyright (c) 2010 BestSolution.at 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:
+ * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 404136, 424730
+ ******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.common.FilterEx;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
+import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope;
+import org.eclipse.e4.tools.emf.ui.internal.Messages;
+import org.eclipse.e4.tools.emf.ui.internal.StringMatcher;
+import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformIconContributionCollector;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * A FilteredContributionDialog with additional options for icon resources.
+ * Features in include
+ * <ul>
+ * <li>Rebuilding the viewer when row height decreases. (Workaround for an SWT
+ * limitation)
+ * <li>Icon previews are displace in the first column.
+ * <li>Limited the maximum image size.
+ * </ul>
+ *
+ * @author "Steven Spungin"
+ *
+ * @see @FilteredContributionDialog
+ */
+public abstract class AbstractIconDialogWithScopeAndFilter extends FilteredContributionDialog {
+ private IProject project;
+ private Map<IFile, Image> icons = Collections.synchronizedMap(new HashMap<IFile, Image>());
+
+ static public class Entry {
+ IFile file;
+ String installLocation;
+ }
+
+ protected Integer maxDisplayedImageSize;
+ protected int maxImageHeight;
+ public static TargetPlatformIconContributionCollector collector;
+
+ public AbstractIconDialogWithScopeAndFilter(Shell parentShell, IEclipseContext context) {
+ super(parentShell, context);
+ this.project = context.get(IProject.class);
+ }
+
+ @Override
+ protected String getFilterTextMessage() {
+ return Messages.AbstractIconDialogWithScopeAndFilter_typeToStartSearch;
+ }
+
+ @Override
+ protected String getResourceNameText() {
+ return Messages.AbstractIconDialogWithScopeAndFilter_iconName;
+ }
+
+ @Override
+ protected ClassContributionCollector getCollector() {
+ if (collector == null) {
+ collector = TargetPlatformIconContributionCollector.getInstance();
+ }
+ return collector;
+ }
+
+ @Override
+ protected void createOptions(Composite compOptions) {
+ super.createOptions(compOptions);
+
+ Label lblMaxSize = new Label(compOptions, SWT.NONE);
+ lblMaxSize.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ lblMaxSize.setText(Messages.AbstractIconDialogWithScopeAndFilter_maxDisplayedImageSize);
+
+ final ComboViewer cv = new ComboViewer(compOptions);
+ cv.getCombo().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 1, 1));
+ cv.add(10);
+ cv.add(20);
+ cv.add(30);
+ cv.add(50);
+ cv.add(100);
+ cv.add(150);
+ cv.add(200);
+ maxDisplayedImageSize = 30;
+ cv.setSelection(new StructuredSelection(maxDisplayedImageSize));
+
+ cv.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ maxDisplayedImageSize = (Integer) ((IStructuredSelection) cv.getSelection()).getFirstElement();
+ rebuildViewer();
+ refreshSearch();
+ // combo viewer cannot make rows smaller, so we will need to
+ // rebuild it in that case.
+ }
+ });
+ }
+
+ @Override
+ protected void rebuildViewer() {
+ super.rebuildViewer();
+ getViewer().getTable().setHeaderVisible(true);
+
+ ((GridData) getViewer().getTable().getLayoutData()).minimumHeight = 100;
+
+ TableViewerColumn colIcon = new TableViewerColumn(getViewer(), SWT.NONE);
+ colIcon.getColumn().setText(Messages.AbstractIconDialogWithScopeAndFilter_icon);
+ TableViewerColumn colText = new TableViewerColumn(getViewer(), SWT.NONE);
+ colText.getColumn().setText(Messages.AbstractIconDialogWithScopeAndFilter_details);
+
+ // resize the row height using a MeasureItem listener
+ getViewer().getTable().addListener(SWT.MeasureItem, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ // height cannot be per row so simply set
+ event.height = maxDisplayedImageSize;
+ }
+ });
+
+ colIcon.setLabelProvider(new StyledCellLabelProvider() {
+ @Override
+ public void update(ViewerCell cell) {
+ IFile file;
+ if (cell.getElement() instanceof ContributionData) {
+ file = new ContributionDataFile((ContributionData) cell.getElement());
+ } else if (cell.getElement() instanceof Entry) {
+ file = ((Entry) cell.getElement()).file;
+ } else {
+ file = (IFile) cell.getElement();
+ }
+
+ Image img = icons.get(file);
+ if (img == null) {
+ InputStream in = null;
+ try {
+ in = file.getContents();
+ img = new Image(cell.getControl().getDisplay(), in);
+ icons.put(file, img);
+ } catch (Exception e) {
+ // e.printStackTrace();
+ return;
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ // scale image if larger then max height
+ // also remember max width for column resizing
+ if (img != null) {
+ double scale1 = ((double) maxDisplayedImageSize) / img.getImageData().height;
+ double scale2 = ((double) maxDisplayedImageSize) / img.getImageData().width;
+ if (scale2 < scale1) {
+ scale1 = scale2;
+ }
+ if (scale1 < 1) {
+ int width = (int) (img.getImageData().width * scale1);
+ if (width == 0)
+ width = 1;
+ int height = (int) (img.getImageData().height * scale1);
+ if (height == 0)
+ height = 1;
+ Image img2 = new Image(img.getDevice(), img.getImageData().scaledTo(width, height));
+ img.dispose();
+ img = img2;
+ icons.put(file, img);
+ }
+ int width = AbstractIconDialogWithScopeAndFilter.this.getViewer().getTable().getColumn(0).getWidth();
+ if (img.getImageData().width > width) {
+ AbstractIconDialogWithScopeAndFilter.this.getViewer().getTable().getColumn(0).setWidth(img.getImageData().width);
+ }
+ int height = img.getImageData().height;
+ if (height > maxImageHeight) {
+ maxImageHeight = height;
+ }
+ }
+
+ cell.setImage(img);
+ }
+ });
+ colIcon.getColumn().setWidth(30);
+
+ colText.setLabelProvider(new StyledCellLabelProvider() {
+ @Override
+ public void update(ViewerCell cell) {
+ IFile file;
+ String installLocation = null;
+ if (cell.getElement() instanceof ContributionData) {
+ ContributionData contributionData = (ContributionData) cell.getElement();
+ file = new ContributionDataFile(contributionData);
+ installLocation = contributionData.installLocation;
+ } else if (cell.getElement() instanceof Entry) {
+ file = ((Entry) cell.getElement()).file;
+ installLocation = ((Entry) cell.getElement()).installLocation;
+ } else {
+ file = (IFile) cell.getElement();
+ }
+ StyledString styledString = new StyledString(file.getProjectRelativePath().toString(), null);
+ String bundle = FilteredContributionDialog.getBundle(file);
+ if (bundle != null) {
+ styledString.append(" - " + bundle, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ } else if (installLocation != null) {
+ styledString.append(" - " + installLocation, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ }
+
+ cell.setText(styledString.getString());
+ cell.setStyleRanges(styledString.getStyleRanges());
+ }
+ });
+ colText.getColumn().setWidth(400);
+
+ getShell().addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ clearImages();
+ }
+ });
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite comp = (Composite) super.createDialogArea(parent);
+ maxDisplayedImageSize = 20;
+ rebuildViewer();
+
+ return comp;
+ }
+
+ private IconMatchCallback callback;
+ private String returnValue;
+ private SearchThread task;
+
+ @Override
+ protected boolean doSearch() {
+
+ // if (getSearchScopes().contains(SearchScope.TARGET_PLATFORM) ||
+ // getSearchScopes().contains(SearchScope.WORKSPACE)) {
+ if (getSearchScopes().contains(ResourceSearchScope.TARGET_PLATFORM)) {
+ return false;
+ } else {
+ Timer timer = new Timer(true);
+
+ if (callback != null) {
+ callback.cancel = true;
+ }
+ if (task != null) {
+ task.cancel();
+ }
+ task = null;
+
+ clearImages();
+
+ callback = new IconMatchCallback((IObservableList) getViewer().getInput());
+ FilterEx filter = new FilterEx(project, getFilterTextBox().getText());
+ filter.setSearchScope(getSearchScopes());
+ filter.setBundles(getFilterBundles());
+ filter.setLocations(getFilterLocations());
+ filter.setPackages(getFilterPackages());
+ filter.setIncludeNonBundles(includeNonBundles);
+ task = new SearchThread(callback, filter);
+ timer.schedule(task, 500);
+ // }
+ return true;
+ }
+ }
+
+ private void clearImages() {
+ for (Image img : icons.values()) {
+ img.dispose();
+ }
+ icons.clear();
+ }
+
+ @Override
+ protected void okPressed() {
+ returnValue = null;
+ IFile file = getSelectedIfile();
+ if (file != null) {
+ String installLocation = null;
+ if (file instanceof ContributionDataFile) {
+ ContributionDataFile cdf = (ContributionDataFile) file;
+ installLocation = cdf.getContributionData().installLocation;
+
+ }
+ file = checkResourceAccessible(file, installLocation);
+ if (file != null) {
+ String bundle = getBundle(file);
+ String uri;
+ uri = "platform:/plugin/" + bundle + "/" + file.getProjectRelativePath().toString(); //$NON-NLS-1$ //$NON-NLS-2$
+ returnValue = uri;
+ super.okPressed();
+ }
+ }
+ }
+
+ private class IconMatchCallback {
+ private volatile boolean cancel;
+ private IObservableList list;
+
+ private IconMatchCallback(IObservableList list) {
+ this.list = list;
+ }
+
+ public void match(final IFile file, final String installLocation) {
+ if (!cancel) {
+ list.getRealm().exec(new Runnable() {
+
+ @Override
+ public void run() {
+ Entry entry = new Entry();
+ entry.file = file;
+ entry.installLocation = installLocation;
+ list.add(entry);
+ }
+ });
+ }
+ }
+ }
+
+ private static class SearchThread extends TimerTask {
+ private final IconMatchCallback callback;
+ private final StringMatcher matcherGif;
+ private final StringMatcher matcherJpg;
+ private final StringMatcher matcherPng;
+ private FilterEx filter;
+ private boolean includeNonBundles;
+
+ public SearchThread(IconMatchCallback callback, FilterEx filter) {
+ this.matcherGif = new StringMatcher("*" + filter.namePattern + "*.gif", true, false); //$NON-NLS-1$//$NON-NLS-2$
+ this.matcherJpg = new StringMatcher("*" + filter.namePattern + "*.jpg", true, false); //$NON-NLS-1$//$NON-NLS-2$
+ this.matcherPng = new StringMatcher("*" + filter.namePattern + "*.png", true, false); //$NON-NLS-1$//$NON-NLS-2$
+ this.callback = callback;
+ this.filter = filter;
+ }
+
+ @Override
+ public void run() {
+ List<IProject> projects;
+ if (filter.getSearchScope().contains(ResourceSearchScope.TARGET_PLATFORM)) {
+ // never should be here because it is cached and not run as
+ // thread
+ return;
+ } else if (filter.getSearchScope().contains(ResourceSearchScope.WORKSPACE)) {
+ projects = Arrays.asList(filter.project.getWorkspace().getRoot().getProjects());
+ } else if (filter.getSearchScope().contains(ResourceSearchScope.PROJECT)) {
+ if (filter.getSearchScope().contains(ResourceSearchScope.REFERENCES)) {
+ projects = new ArrayList<IProject>();
+ projects.add(filter.project);
+ try {
+ for (IProject ref : filter.project.getReferencedProjects()) {
+ projects.add(ref);
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ } else {
+ projects = Arrays.asList(filter.project);
+ }
+ } else {
+ return;
+ }
+
+ try {
+ for (final IProject project : projects) {
+ // Only search bundles unless requested
+ if (includeNonBundles == false && filter.project.getFile("/META-INF/MANIFEST.MF").exists() == false) { //$NON-NLS-1$
+ continue;
+ }
+ project.accept(new IResourceVisitor() {
+
+ @Override
+ public boolean visit(IResource resource) throws CoreException {
+ if (callback.cancel) {
+ return false;
+ }
+
+ if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.PROJECT) {
+ return true;
+ } else if (resource.getType() == IResource.FILE && !resource.isLinked()) {
+ String path = resource.getProjectRelativePath().toString();
+ if (matcherGif.match(path) || matcherPng.match(path) || matcherJpg.match(path)) {
+ if (E.notEmpty(filter.getPackages())) {
+ if (!filter.getPackages().contains(resource.getProjectRelativePath().removeLastSegments(1).toOSString())) {
+ return false;
+ }
+ }
+ if (E.notEmpty(filter.getLocations())) {
+ if (!filter.getLocations().contains(project.getLocation().toOSString())) {
+ return false;
+ }
+ }
+ if (E.notEmpty(filter.getBundles())) {
+ String bundle = getBundle(project);
+ if (bundle == null || !filter.getBundles().contains(bundle)) {
+ return false;
+ }
+ }
+ if (!filter.isIncludeNonBundles()) {
+ String bundle = getBundle(project);
+ if (bundle == null) {
+ return false;
+ }
+
+ }
+ callback.match((IFile) resource, project.getLocation().toOSString());
+ }
+ }
+ return false;
+ }
+
+ });
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public String getValue() {
+ return returnValue;
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AreaIconDialogEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AreaIconDialogEditor.java
index eaf383a3..7a76c373 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AreaIconDialogEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/AreaIconDialogEditor.java
@@ -7,11 +7,12 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
- * Steven Spungin <steven@spungin.tv> - Bug 433408
+ * Steven Spungin <steven@spungin.tv> - Bug 433408, 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.ui.model.application.MApplicationElement;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
@@ -20,8 +21,8 @@ import org.eclipse.swt.widgets.Shell;
public class AreaIconDialogEditor extends AbstractIconDialog {
- public AreaIconDialogEditor(Shell parentShell, IProject project, EditingDomain editingDomain, MApplicationElement element, Messages Messages) {
- super(parentShell, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
+ public AreaIconDialogEditor(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MApplicationElement element, Messages Messages) {
+ super(parentShell, context, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
}
@Override
@@ -39,4 +40,13 @@ public class AreaIconDialogEditor extends AbstractIconDialog {
return Messages.AreaIconDialogEditor_DialogMessage;
}
+ @Override
+ protected String getFilterTextMessage() {
+ return "Enter text";
+ }
+
+ @Override
+ protected String getResourceNameText() {
+ return "Icon";
+ }
}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/BundleImageCache.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/BundleImageCache.java
new file mode 100644
index 00000000..470eb0aa
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/BundleImageCache.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.services.IResourcePool;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * A manager for images. Features include:
+ * <ul>
+ * <li>Eliminates the need to pass in Display when creating images
+ * <li>Loading an image from a bundle
+ * <li>Cleanup of cache
+ * </ul>
+ *
+ * Images returned by this method must never be disposed of outside of this
+ * class, as placeholders are used.
+ *
+ * @author "Steven Spungin"
+ *
+ */
+public class BundleImageCache {
+
+ private Display display;
+ private ClassLoader classloader;
+ ArrayList<Image> images;
+ static private Image imgPlaceholder;
+ private IEclipseContext context;
+
+ public BundleImageCache(Display display, ClassLoader classloader) {
+ this(display, classloader, null);
+ }
+
+ public BundleImageCache(Display display, ClassLoader classloader, IEclipseContext context) {
+ this.display = display;
+ this.classloader = classloader;
+ this.context = context;
+ images = new ArrayList<Image>();
+ }
+
+ /**
+ * Creates the image, and tracks it for a bulk dispose operation.
+ *
+ * @param path
+ * @return
+ */
+ public Image create(String path) {
+ Image img;
+ try {
+ img = new Image(display, classloader.getResourceAsStream(path));
+ images.add(img);
+ } catch (Exception e) {
+ e.printStackTrace();
+ img = getPlaceholder();
+ }
+ return img;
+ }
+
+ /**
+ * Uses IResourcePool to obtain image. Does not track object.
+ *
+ * @param key
+ * @return
+ */
+ public Image loadFromKey(String key) {
+ Image ret = null;
+ try {
+ ret = context.get(IResourcePool.class).getImageUnchecked(key);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ if (ret == null) {
+ ret = getPlaceholder();
+ }
+ return ret;
+ }
+
+ protected Image getPlaceholder() {
+ if (imgPlaceholder == null) {
+ imgPlaceholder = new Image(Display.getDefault(), classloader.getResourceAsStream("/icons/full/obj16/missing_image_placeholder.png")); //$NON-NLS-1$
+ }
+ return imgPlaceholder;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ if (imgPlaceholder != null && imgPlaceholder.isDisposed() == false) {
+ imgPlaceholder.dispose();
+ }
+ }
+
+ public void dispose() {
+ for (Iterator<Image> it = images.iterator(); it.hasNext();) {
+ Image image = it.next();
+ if (image.isDisposed() == false) {
+ image.dispose();
+ }
+ it.remove();
+ }
+ }
+
+ public Image create(String bundleId, String path) {
+ if (path.startsWith("/") == false) { //$NON-NLS-1$
+ path = "/" + path; //$NON-NLS-1$
+ }
+ Image img;
+ try {
+ img = new Image(display, new URL("platform:/plugin/" + bundleId + path).openStream()); //$NON-NLS-1$
+ images.add(img);
+ } catch (Exception e) {
+ e.printStackTrace();
+ img = getPlaceholder();
+ }
+ return img;
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java
index 93d3ae1a..ff07eea5 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java
@@ -8,15 +8,17 @@
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Lars Vogel <lars.vogel@gmail.com> - Enhancements
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
-import org.eclipse.core.databinding.observable.list.IObservableList;
-import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformClassContributionCollector;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformContributionCollector;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
-import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionResultHandler;
-import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.Filter;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector;
import org.eclipse.e4.ui.model.application.MApplicationElement;
@@ -24,46 +26,24 @@ import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
-public class ContributionClassDialog extends TitleAreaDialog {
+public class ContributionClassDialog extends FilteredContributionDialog {
+
private IProject project;
- private Image javaClassImage;
private MApplicationElement contribution;
private EditingDomain editingDomain;
- private TableViewer viewer;
private EStructuralFeature feature;
private Messages Messages;
- public ContributionClassDialog(Shell parentShell, IProject project, EditingDomain editingDomain, MApplicationElement contribution, EStructuralFeature feature, Messages Messages) {
- super(parentShell);
+ public ContributionClassDialog(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MApplicationElement contribution, EStructuralFeature feature, Messages Messages) {
+ super(parentShell, context);
this.project = project;
this.contribution = contribution;
this.editingDomain = editingDomain;
@@ -72,161 +52,76 @@ public class ContributionClassDialog extends TitleAreaDialog {
}
@Override
- protected boolean isResizable() {
- return true;
+ protected Image getTitleImage() {
+ return new Image(getShell().getDisplay(), getClass().getClassLoader().getResourceAsStream("/icons/full/wizban/newclass_wiz.png")); //$NON-NLS-1$
}
@Override
- protected Control createDialogArea(Composite parent) {
- Composite comp = (Composite) super.createDialogArea(parent);
-
- getShell().setText(Messages.ContributionClassDialog_ShellTitle);
- setTitle(Messages.ContributionClassDialog_DialogTitle);
- setMessage(Messages.ContributionClassDialog_DialogMessage);
-
- final Image titleImage = new Image(comp.getDisplay(), getClass().getClassLoader().getResourceAsStream("/icons/full/wizban/newclass_wiz.png")); //$NON-NLS-1$
- setTitleImage(titleImage);
-
- getShell().addDisposeListener(new DisposeListener() {
-
- @Override
- public void widgetDisposed(DisposeEvent e) {
- javaClassImage.dispose();
- titleImage.dispose();
- }
- });
-
- javaClassImage = new Image(getShell().getDisplay(), getClass().getClassLoader().getResourceAsStream("/icons/full/obj16/class_obj.gif")); //$NON-NLS-1$
-
- Composite container = new Composite(comp, SWT.NONE);
- container.setLayoutData(new GridData(GridData.FILL_BOTH));
- container.setLayout(new GridLayout(2, false));
-
- Label l = new Label(container, SWT.NONE);
- l.setText(Messages.ContributionClassDialog_Label_Classname);
-
- final Text t = new Text(container, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH);
- t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- t.setMessage(Messages.ContributionClassDialog_FilterText_Message);
-
- new Label(container, SWT.NONE);
-
- viewer = new TableViewer(container);
- GridData gd = new GridData(GridData.FILL_BOTH);
- viewer.getControl().setLayoutData(gd);
- viewer.setContentProvider(new ObservableListContentProvider());
- viewer.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- ContributionData data = (ContributionData) cell.getElement();
- StyledString styledString = new StyledString(data.className, null);
-
- if (data.bundleName != null) {
- styledString.append(" - " + data.bundleName, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
- }
-
- if (data.sourceType != null) {
- styledString.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
- styledString.append(data.sourceType + "", StyledString.COUNTER_STYLER); //$NON-NLS-1$
- }
-
- if (data.iconPath == null) {
- cell.setImage(javaClassImage);
- }
-
- cell.setText(styledString.getString());
- cell.setStyleRanges(styledString.getStyleRanges());
- }
- });
- viewer.addDoubleClickListener(new IDoubleClickListener() {
-
- @Override
- public void doubleClick(DoubleClickEvent event) {
- okPressed();
- }
- });
-
- final WritableList list = new WritableList();
- viewer.setInput(list);
-
- final ClassContributionCollector collector = getCollector();
-
- t.addModifyListener(new ModifyListener() {
- private ContributionResultHandlerImpl currentResultHandler;
-
- @Override
- public void modifyText(ModifyEvent e) {
- if (currentResultHandler != null) {
- currentResultHandler.cancled = true;
+ protected void okPressed() {
+ IStructuredSelection s = (IStructuredSelection) getViewer().getSelection();
+ if (!s.isEmpty()) {
+ ContributionData cd = (ContributionData) s.getFirstElement();
+ ContributionDataFile cdf = new ContributionDataFile(cd);
+ IFile file = checkResourceAccessible(cdf, cd.installLocation);
+ if (file != null) {
+ String uri = "bundleclass://" + cd.bundleName + "/" + cd.className; //$NON-NLS-1$ //$NON-NLS-2$
+ Command cmd = SetCommand.create(editingDomain, contribution, feature, uri);
+ if (cmd.canExecute()) {
+ editingDomain.getCommandStack().execute(cmd);
+ super.okPressed();
}
- list.clear();
- currentResultHandler = new ContributionResultHandlerImpl(list);
- Filter filter = new Filter(project, t.getText());
- collector.findContributions(filter, currentResultHandler);
- t.addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- if (e.keyCode == SWT.ARROW_DOWN) {
- if (viewer.getTable().getItemCount() > 0) {
- viewer.getTable().setFocus();
- viewer.getTable().select(0);
- }
- }
- }
- });
- viewer.getTable().addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- super.keyPressed(e);
- if ((e.keyCode == SWT.ARROW_UP) && (viewer.getTable().getSelectionIndex() == 0)) {
- t.setFocus();
- }
- }
- });
}
- });
-
- return comp;
+ }
}
@Override
- protected void okPressed() {
- IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
- if (!s.isEmpty()) {
- ContributionData cd = (ContributionData) s.getFirstElement();
- String uri = "bundleclass://" + cd.bundleName + "/" + cd.className; //$NON-NLS-1$ //$NON-NLS-2$
- Command cmd = SetCommand.create(editingDomain, contribution, feature, uri);
- if (cmd.canExecute()) {
- editingDomain.getCommandStack().execute(cmd);
- super.okPressed();
+ protected ClassContributionCollector getCollector() {
+ switch (getScope()) {
+ case TARGET_PLATFORM:
+ case WORKSPACE:
+ if (collector instanceof TargetPlatformContributionCollector == false) {
+ collector = TargetPlatformClassContributionCollector.getInstance();
+ }
+ break;
+ case PROJECT:
+ Bundle bundle = FrameworkUtil.getBundle(ContributionClassDialog.class);
+ BundleContext context = bundle.getBundleContext();
+ ServiceReference<?> ref = context.getServiceReference(ClassContributionCollector.class.getName());
+ if (ref != null) {
+ collector = (ClassContributionCollector) context.getService(ref);
+ } else {
+ collector = null;
}
+ break;
+ default:
+ collector = null;
+ break;
}
+ return collector;
}
- private ClassContributionCollector getCollector() {
- Bundle bundle = FrameworkUtil.getBundle(ContributionClassDialog.class);
- BundleContext context = bundle.getBundleContext();
- ServiceReference ref = context.getServiceReference(ClassContributionCollector.class.getName());
- if (ref != null) {
- return (ClassContributionCollector) context.getService(ref);
- }
- return null;
+ @Override
+ protected String getShellTitle() {
+ return Messages.ContributionClassDialog_DialogTitle;
}
- private static class ContributionResultHandlerImpl implements ContributionResultHandler {
- private boolean cancled = false;
- private IObservableList list;
+ @Override
+ protected String getDialogTitle() {
+ return Messages.ContributionClassDialog_DialogTitle;
+ }
- public ContributionResultHandlerImpl(IObservableList list) {
- this.list = list;
- }
+ @Override
+ protected String getDialogMessage() {
+ return Messages.ContributionClassDialog_DialogMessage;
+ }
- @Override
- public void result(ContributionData data) {
- if (!cancled) {
- list.add(data);
- }
- }
+ @Override
+ protected String getResourceNameText() {
+ return Messages.ContributionClassDialog_Label_Classname;
+ }
+ @Override
+ protected String getFilterTextMessage() {
+ return Messages.ContributionClassDialog_FilterText_Message;
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionDataFile.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionDataFile.java
new file mode 100644
index 00000000..cd90c844
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionDataFile.java
@@ -0,0 +1,677 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFileState;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IPathVariableManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourceAttributes;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
+
+/**
+ * An IFile wrapper for ContributionData. This is only partially implemented for
+ * the icon search dialog.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class ContributionDataFile implements IFile {
+
+ private ContributionData data;
+ private IPath path;
+
+ public ContributionDataFile(ContributionData data) {
+ this.data = data;
+ if (data.iconPath != null) {
+ this.path = Path.fromOSString(data.iconPath);
+ }
+ }
+
+ public String getBundle() {
+ return data.bundleName;
+ }
+
+ public ContributionData getContributionData() {
+ return data;
+ }
+
+ @Override
+ public IPath getProjectRelativePath() {
+ if (getContributionData().installLocation != null) {
+ return new Path(data.resourceRelativePath);
+ } else {
+ return new Path(data.iconPath);
+ }
+ }
+
+ @Override
+ public void accept(IResourceProxyVisitor visitor, int memberFlags) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void accept(IResourceProxyVisitor visitor, int depth, int memberFlags) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void accept(IResourceVisitor visitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void accept(IResourceVisitor visitor, int depth, boolean includePhantoms) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void clearHistory(IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void copy(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void copy(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void copy(IProjectDescription description, boolean force, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void copy(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public IMarker createMarker(String type) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IResourceProxy createProxy() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void delete(boolean force, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void deleteMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean exists() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public IMarker findMarker(long id) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) throws CoreException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getFileExtension() {
+ return path.getFileExtension();
+ }
+
+ @Override
+ public long getLocalTimeStamp() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public IPath getLocation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public URI getLocationURI() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IMarker getMarker(long id) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public long getModificationStamp() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public IPathVariableManager getPathVariableManager() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IContainer getParent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Map<QualifiedName, String> getPersistentProperties() throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getPersistentProperty(QualifiedName key) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IProject getProject() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IPath getRawLocation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public URI getRawLocationURI() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ResourceAttributes getResourceAttributes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Map<QualifiedName, Object> getSessionProperties() throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Object getSessionProperty(QualifiedName key) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getType() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public IWorkspace getWorkspace() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isAccessible() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isDerived() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isDerived(int options) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isHidden() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isHidden(int options) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isLinked() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isVirtual() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isLinked(int options) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isLocal(int depth) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isPhantom() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isSynchronized(int depth) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isTeamPrivateMember() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isTeamPrivateMember(int options) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void move(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void move(IProjectDescription description, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void revertModificationStamp(long value) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setDerived(boolean isDerived) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setDerived(boolean isDerived, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setHidden(boolean isHidden) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setLocal(boolean flag, int depth, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public long setLocalTimeStamp(long value) throws CoreException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setPersistentProperty(QualifiedName key, String value) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setSessionProperty(QualifiedName key, Object value) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTeamPrivateMember(boolean isTeamPrivate) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void touch(IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Object getAdapter(Class adapter) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean contains(ISchedulingRule rule) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isConflicting(ISchedulingRule rule) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void appendContents(InputStream source, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void appendContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void create(InputStream source, boolean force, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void create(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void createLink(IPath localLocation, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void createLink(URI location, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void delete(boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getCharset() throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getCharset(boolean checkImplicit) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getCharsetFor(Reader reader) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IContentDescription getContentDescription() throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public InputStream getContents() throws CoreException {
+ URL url;
+ try {
+ if (path.getFileExtension().equals("jar")) {
+ ZipFile zip = new ZipFile(path.toOSString());
+ ZipEntry entry;
+ if (getContributionData().className != null) {
+ entry = zip.getEntry(getContributionData().className.replace('.', '/') + ".class"); //$NON-NLS-1$
+ } else {
+ entry = zip.getEntry(data.iconPath);
+ }
+ return zip.getInputStream(entry);
+ } else {
+ url = new URL("platform:/plugin/" + data.bundleName + "/" + data.iconPath); //$NON-NLS-1$ //$NON-NLS-2$
+ InputStream ret;
+ try {
+ ret = url.openStream();
+ } catch (Exception e) {
+ return new BufferedInputStream(new FileInputStream(data.installLocation + "/" + data.resourceRelativePath)); //$NON-NLS-1$
+ }
+ return ret;
+ }
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ throw new CoreException(Status.CANCEL_STATUS);
+ } catch (IOException e) {
+ // perhaps not a bundle
+ // e.printStackTrace();
+ throw new CoreException(Status.CANCEL_STATUS);
+ }
+ }
+
+ @Override
+ public InputStream getContents(boolean force) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getEncoding() throws CoreException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public IPath getFullPath() {
+ return path;
+ }
+
+ @Override
+ public IFileState[] getHistory(IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void move(IPath destination, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setCharset(String newCharset) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setContents(InputStream source, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setContents(IFileState source, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setContents(IFileState source, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java
new file mode 100644
index 00000000..e31df874
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java
@@ -0,0 +1,973 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Scanner;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.common.FilterEx;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionResultHandler;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.Filter;
+import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope;
+import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.AbstractIconDialogWithScopeAndFilter.Entry;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.TitleAreaFilterDialog;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformClassContributionCollector;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformIconContributionCollector;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.NonReferencedResourceDialog;
+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.pde.internal.core.project.PDEProject;
+import org.eclipse.pde.internal.core.text.bundle.BundleModel;
+import org.eclipse.pde.internal.core.text.bundle.ImportPackageHeader;
+import org.eclipse.pde.internal.core.text.bundle.ImportPackageObject;
+import org.eclipse.pde.internal.core.text.bundle.RequireBundleHeader;
+import org.eclipse.pde.internal.core.text.bundle.RequireBundleObject;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Abstract base class for a find contribution dialog.<br />
+ * Includes a filter text box, scope options, and filter options.
+ *
+ * @author Steven Spungin
+ *
+ */
+public abstract class FilteredContributionDialog extends TitleAreaDialog {
+
+ private static final int MAX_RESULTS = 500;
+ private Image contributionTypeImage;
+ private TableViewer viewer;
+ private ResourceSearchScope searchScope = ResourceSearchScope.PROJECT;
+ private EnumSet<ResourceSearchScope> searchScopes = EnumSet.of(ResourceSearchScope.PROJECT);
+ // private EnumSet<SearchScope> searchScopes =
+ // EnumSet.of(SearchScope.PROJECT, SearchScope.REFERENCES);
+ protected ClassContributionCollector collector;
+ private Text textBox;
+ private Button btnFilterNone;
+ private Button btnFilterBundle;
+ private Button btnFilterPackage;
+ private List<String> filterBundles;
+ private List<String> filterPackages;
+ private Button btnFilterLocation;
+ private List<String> filterLocations;
+ private Button btnClearCache;
+ private IEclipseContext context;
+ private Composite compOptions;
+ protected boolean includeNonBundles;
+ private Label lblStatus;
+ private Button btnIncludeNoneBundle;
+ private WritableList viewerList;
+ protected BundleImageCache imageCache;
+
+ abstract protected ClassContributionCollector getCollector();
+
+ abstract protected String getFilterTextMessage();
+
+ abstract protected String getResourceNameText();
+
+ abstract protected String getDialogMessage();
+
+ abstract protected String getDialogTitle();
+
+ abstract protected String getShellTitle();
+
+ private static class ContributionResultHandlerImpl implements ContributionResultHandler {
+ private boolean cancled = false;
+ private IObservableList list;
+
+ public ContributionResultHandlerImpl(IObservableList list) {
+ this.list = list;
+ }
+
+ @Override
+ public void result(ContributionData data) {
+ if (!cancled) {
+ list.add(data);
+ }
+ }
+
+ @Override
+ public void moreResults(int hint, Filter filter) {
+ FilteredContributionDialog dlg = (FilteredContributionDialog) filter.userData;
+ // dlg.setStatus("More than " + filter.maxResults +
+ // " items were found and have not been displayed");
+ if (hint != 0) {
+ dlg.setMessage("More than " + filter.maxResults + " items were found. Not all results have been displayed.");
+ } else {
+ dlg.setMessage("");
+ }
+ }
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ textBox.notifyListeners(SWT.Modify, new Event());
+ return ret;
+ }
+
+ public FilteredContributionDialog(Shell parentShell, IEclipseContext context) {
+ super(parentShell);
+ this.context = context;
+ imageCache = new BundleImageCache(context.get(Display.class), getClass().getClassLoader());
+ }
+
+ public void setStatus(final String message) {
+ getShell().getDisplay().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ lblStatus.setText(message);
+ }
+ });
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ ((GridLayout) parent.getLayout()).numColumns = 4;
+
+ btnClearCache = new Button(parent, SWT.PUSH);
+ btnClearCache.setText("Clear Model Cache");
+ btnClearCache.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ getCollector().clearModelCache();
+ }
+ });
+
+ btnClearCache.moveAbove(getButton(0));
+
+ lblStatus = new Label(parent, SWT.NONE);
+ lblStatus.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ lblStatus.setText(""); //$NON-NLS-1$
+ lblStatus.moveAbove(btnClearCache);
+
+ // This is called here instead of create contents because btnClearCache
+ // is referenced in updateUiState.
+ updateUiState();
+ }
+
+ // TODO add results found (and/or more indicator)
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite comp = (Composite) super.createDialogArea(parent);
+ getShell().addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ imageCache.dispose();
+
+ if (contributionTypeImage.isDisposed() == false) {
+ contributionTypeImage.dispose();
+ }
+ if (getTitleImageLabel().getImage() != null && getTitleImage().isDisposed() == false) {
+ getTitleImageLabel().getImage().dispose();
+ }
+ }
+ });
+
+ getShell().setText(getShellTitle());
+ setTitle(getDialogTitle());
+ setMessage(getDialogMessage());
+
+ final Image titleImage = getTitleImage();
+ setTitleImage(titleImage);
+
+ // TODO param or context
+ contributionTypeImage = imageCache.create("/icons/full/obj16/class_obj.gif"); //$NON-NLS-1$
+
+ compOptions = new Composite(comp, SWT.NONE);
+ compOptions.setLayoutData(new GridData(GridData.FILL_BOTH));
+ compOptions.setLayout(new GridLayout(2, false));
+
+ createOptions(compOptions);
+
+ Label l = new Label(compOptions, SWT.NONE);
+ l.setText(getResourceNameText());
+
+ textBox = new Text(compOptions, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH);
+ textBox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ textBox.setMessage(getFilterTextMessage());
+
+ new Label(compOptions, SWT.NONE);
+
+ rebuildViewer();
+
+ collector = getCollector();
+
+ textBox.addModifyListener(new ModifyListener() {
+ private ContributionResultHandlerImpl currentResultHandler;
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (currentResultHandler != null) {
+ currentResultHandler.cancled = true;
+ }
+ viewerList.clear();
+
+ setMessage(""); //$NON-NLS-1$
+ if (doSearch() == true) {
+ return;
+ }
+
+ currentResultHandler = new ContributionResultHandlerImpl(viewerList);
+ FilterEx filter;
+ if (searchScopes.contains(ResourceSearchScope.PROJECT)) {
+ filter = new FilterEx(context.get(IProject.class), textBox.getText());
+ } else {
+ // filter = new FilterEx(null, textBox.getText());
+ filter = new FilterEx(context.get(IProject.class), textBox.getText());
+ }
+ filter.maxResults = MAX_RESULTS;
+ filter.userData = FilteredContributionDialog.this;
+ filter.setBundles(filterBundles);
+ filter.setPackages(filterPackages);
+ filter.setLocations(filterLocations);
+ filter.setSearchScope(searchScopes);
+ filter.setIncludeNonBundles(includeNonBundles);
+ collector.findContributions(filter, currentResultHandler);
+ textBox.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode == SWT.ARROW_DOWN) {
+ if (viewer.getTable().getItemCount() > 0) {
+ viewer.getTable().setFocus();
+ viewer.getTable().select(0);
+ }
+ }
+ }
+ });
+ viewer.getTable().addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ super.keyPressed(e);
+ if ((e.keyCode == SWT.ARROW_UP) && (viewer.getTable().getSelectionIndex() == 0)) {
+ textBox.setFocus();
+ }
+ }
+ });
+ }
+ });
+
+ return comp;
+ }
+
+ protected Image getTitleImage() {
+ return imageCache.create("/icons/full/wizban/newsearch_wiz.gif"); //$NON-NLS-1$
+ }
+
+ protected void createOptions(Composite compOptions) {
+ {
+ Label lblScope = new Label(compOptions, SWT.NONE);
+ lblScope.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ lblScope.setText("Scope");
+
+ Composite compScope = new Composite(compOptions, SWT.NONE);
+ compScope.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false));
+ compScope.setLayout(new RowLayout());
+
+ final Button btnScopeProject = new Button(compScope, SWT.RADIO);
+ btnScopeProject.setText("Project Only");
+ btnScopeProject.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnScopeProject.getSelection()) {
+ searchScope = ResourceSearchScope.PROJECT;
+ searchScopes = EnumSet.of(ResourceSearchScope.PROJECT);
+ updateUiState();
+ getCollector();
+ refreshSearch();
+ }
+ }
+ });
+ btnScopeProject.setSelection(searchScopes.contains(ResourceSearchScope.PROJECT) && !searchScopes.contains(ResourceSearchScope.REFERENCES));
+
+ final Button btnProjectAndReferences = new Button(compScope, SWT.RADIO);
+ btnProjectAndReferences.setText("Project and References");
+ btnProjectAndReferences.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnProjectAndReferences.getSelection()) {
+ searchScope = ResourceSearchScope.PROJECT;
+ searchScopes = EnumSet.of(ResourceSearchScope.PROJECT, ResourceSearchScope.REFERENCES);
+ updateUiState();
+ getCollector();
+ refreshSearch();
+ }
+ }
+ });
+ btnProjectAndReferences.setSelection(searchScopes.contains(ResourceSearchScope.PROJECT) && searchScopes.contains(ResourceSearchScope.REFERENCES));
+
+ final Button btnScopeWorkspace = new Button(compScope, SWT.RADIO);
+ btnScopeWorkspace.setText("Workspace");
+ btnScopeWorkspace.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnScopeWorkspace.getSelection()) {
+ searchScope = ResourceSearchScope.WORKSPACE;
+ searchScopes = EnumSet.of(ResourceSearchScope.WORKSPACE);
+ updateUiState();
+ getCollector();
+ refreshSearch();
+ }
+ }
+ });
+ btnScopeWorkspace.setSelection(searchScopes.contains(ResourceSearchScope.WORKSPACE));
+
+ final Button btnScopeTargetPlatform = new Button(compScope, SWT.RADIO);
+ btnScopeTargetPlatform.setText("Target Platform");
+ btnScopeTargetPlatform.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnScopeTargetPlatform.getSelection()) {
+ searchScope = ResourceSearchScope.TARGET_PLATFORM;
+ searchScopes = EnumSet.of(ResourceSearchScope.TARGET_PLATFORM);
+ updateUiState();
+ getCollector();
+ refreshSearch();
+ }
+ }
+ });
+ btnScopeTargetPlatform.setSelection(searchScopes.contains(ResourceSearchScope.TARGET_PLATFORM));
+ }
+
+ {
+ Label lblFilter = new Label(compOptions, SWT.NONE);
+ lblFilter.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ lblFilter.setText("Scope Filter");
+
+ Composite compFilter = new Composite(compOptions, SWT.NONE);
+ compFilter.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false));
+ compFilter.setLayout(new RowLayout());
+
+ btnFilterNone = new Button(compFilter, SWT.CHECK);
+ btnFilterNone.setText("None");
+ btnFilterNone.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnFilterNone.getSelection()) {
+ removeFilters();
+ }
+ }
+ });
+
+ btnFilterBundle = new Button(compFilter, SWT.CHECK);
+ btnFilterBundle.setText("Bundle");
+ btnFilterBundle.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnFilterBundle.getSelection()) {
+ showBundleFilter();
+ } else {
+ filterBundles = null;
+ refreshSearch();
+ updateUiState();
+ }
+ }
+ });
+
+ btnFilterPackage = new Button(compFilter, SWT.CHECK);
+ btnFilterPackage.setText("Package");
+ btnFilterPackage.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnFilterPackage.getSelection()) {
+ showPackageFilter();
+ } else {
+ filterPackages = null;
+ refreshSearch();
+ updateUiState();
+ }
+ }
+ });
+
+ btnFilterLocation = new Button(compFilter, SWT.CHECK);
+ btnFilterLocation.setText("Location");
+ btnFilterLocation.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnFilterLocation.getSelection()) {
+ showLocationFilter();
+ } else {
+ filterLocations = null;
+ refreshSearch();
+ updateUiState();
+ }
+ }
+ });
+
+ }
+ {
+ Label lblIncludeNoneBundle = new Label(compOptions, SWT.NONE);
+ lblIncludeNoneBundle.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ lblIncludeNoneBundle.setText("Non Bundles");
+
+ btnIncludeNoneBundle = new Button(compOptions, SWT.CHECK);
+ btnIncludeNoneBundle.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ btnIncludeNoneBundle.setText("");
+ btnIncludeNoneBundle.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ includeNonBundles = btnIncludeNoneBundle.getSelection();
+ refreshSearch();
+ }
+ });
+ }
+ }
+
+ /**
+ *
+ * @return false if default search should be performed, or true if virtual
+ * function will handle
+ */
+ protected boolean doSearch() {
+ return false;
+ }
+
+ protected void updateUiState() {
+ btnFilterNone.setSelection(E.isEmpty(filterBundles) && E.isEmpty(filterPackages) && E.isEmpty(filterLocations));
+ btnFilterBundle.setSelection(E.notEmpty(filterBundles));
+ btnFilterPackage.setSelection(E.notEmpty(filterPackages));
+ btnFilterLocation.setSelection(E.notEmpty(filterLocations));
+
+ // original (default) contribution filter does not support this
+ // filtering API
+ boolean enabled = !searchScopes.contains(ResourceSearchScope.PROJECT);
+ btnFilterNone.setEnabled(enabled);
+ btnFilterBundle.setEnabled(enabled);
+ btnFilterLocation.setEnabled(enabled);
+ btnFilterPackage.setEnabled(enabled);
+ btnClearCache.setEnabled(enabled);
+ btnIncludeNoneBundle.setEnabled(enabled);
+ }
+
+ protected void removeFilters() {
+ filterBundles = null;
+ setFilterPackages(null);
+ filterLocations = null;
+ refreshSearch();
+ updateUiState();
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ public List<String> getFilterPackages() {
+ return filterPackages;
+ }
+
+ public void setFilterPackages(List<String> filterPackages) {
+ this.filterPackages = filterPackages;
+ }
+
+ public List<String> getFilterLocations() {
+ return filterLocations;
+ }
+
+ public void setFilterLocations(List<String> filterLocations) {
+ this.filterLocations = filterLocations;
+ }
+
+ public List<String> getFilterBundles() {
+ return filterBundles;
+ }
+
+ public void setFilterBundles(List<String> filterBundles) {
+ this.filterBundles = filterBundles;
+ }
+
+ protected void refreshSearch() {
+ textBox.notifyListeners(SWT.Modify, new Event());
+ }
+
+ protected void showBundleFilter() {
+ final Collection<String> bundleIds;
+ // TODO make HasBundles an interface so we are not tied to
+ // implementation
+ if (getCollector() instanceof TargetPlatformClassContributionCollector) {
+ bundleIds = TargetPlatformClassContributionCollector.getInstance().getBundleIds();
+ } else if (getCollector() instanceof TargetPlatformIconContributionCollector) {
+ bundleIds = TargetPlatformIconContributionCollector.getInstance().getBundleIds();
+ } else {
+ return;
+ }
+
+ final ArrayList<String> sorted = new ArrayList<String>(bundleIds);
+ Collections.sort(sorted);
+
+ TitleAreaFilterDialog dlg = new TitleAreaFilterDialog(getShell(), new ColumnLabelProvider()) {
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ getViewer().setInput(sorted);
+ setMessage("Select the bundle to filter on.");
+ setTitle("Bundle Filter");
+ getShell().setText("Bundle Filter");
+ try {
+ setTitleImage(imageCache.create("/icons/full/wizban/plugin_wiz.gif"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return ret;
+ }
+ };
+ if (dlg.open() == Dialog.OK) {
+ setFilterBundles((List<String>) dlg.asList());
+ refreshSearch();
+ }
+ updateUiState();
+ }
+
+ protected void showPackageFilter() {
+ final Collection<String> packages;
+ // TODO make HasPackages an interface so we are not tied to
+ // implementation
+ if (getCollector() instanceof TargetPlatformClassContributionCollector) {
+ packages = TargetPlatformClassContributionCollector.getInstance().getPackages();
+ } else if (getCollector() instanceof TargetPlatformIconContributionCollector) {
+ packages = TargetPlatformIconContributionCollector.getInstance().getPackages();
+ } else {
+ return;
+ }
+
+ final ArrayList<String> sorted = new ArrayList<String>(packages);
+ Collections.sort(sorted);
+
+ TitleAreaFilterDialog dlg = new TitleAreaFilterDialog(getShell(), new ColumnLabelProvider()) {
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ getViewer().setInput(sorted);
+ setMessage("Select the package to filter on.");
+ setTitle("Package Filter");
+ getShell().setText("Package Filter");
+ setTitleImage(imageCache.create("/icons/full/wizban/package_wiz.png"));
+ return ret;
+ }
+ };
+ if (dlg.open() == Dialog.OK) {
+ setFilterPackages((List<String>) dlg.asList());
+ refreshSearch();
+ }
+ updateUiState();
+ }
+
+ public ResourceSearchScope getScope() {
+ return searchScope;
+ }
+
+ public void setScope(ResourceSearchScope scope) {
+ this.searchScope = scope;
+ }
+
+ public void setCollector(ClassContributionCollector collector) {
+ this.collector = collector;
+ }
+
+ protected void showLocationFilter() {
+ final Collection<String> locations;
+ // TODO make HasLocations an interface so we are not tied to
+ // implementation
+ if (getCollector() instanceof TargetPlatformClassContributionCollector) {
+ locations = TargetPlatformClassContributionCollector.getInstance().getLocations();
+ } else if (getCollector() instanceof TargetPlatformIconContributionCollector) {
+ locations = TargetPlatformIconContributionCollector.getInstance().getLocations();
+ } else {
+ return;
+ }
+
+ // add all parent paths
+ final HashSet<String> parentLocations = new HashSet<String>();
+ for (String location : locations) {
+ if (location.endsWith(".jar")) {
+ int index = location.lastIndexOf(File.separator);
+ if (index >= 0) {
+ location = location.substring(0, index);
+ parentLocations.add(location);
+ }
+ } else {
+ parentLocations.add(location);
+ }
+ }
+
+ final ArrayList<String> sorted = new ArrayList<String>(parentLocations);
+ Collections.sort(sorted);
+
+ TitleAreaFilterDialog dlg = new TitleAreaFilterDialog(getShell(), new ColumnLabelProvider()) {
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ getViewer().setInput(sorted);
+ setMessage("Select the location to filter on.");
+ setTitle("Location Filter");
+ getShell().setText("Location Filter");
+ setTitleImage(imageCache.create("/icons/full/wizban/location_wiz.png"));
+ return ret;
+ }
+ };
+ if (dlg.open() == Dialog.OK) {
+ setFilterLocations((List<String>) dlg.asList());
+ refreshSearch();
+ }
+ updateUiState();
+ }
+
+ protected void rebuildViewer() {
+
+ viewerList = new WritableList();
+
+ TableViewer oldViewer = viewer;
+ viewer = new TableViewer(compOptions, SWT.FULL_SELECTION);
+ if (oldViewer != null) {
+ viewer.getTable().moveAbove(oldViewer.getTable());
+ oldViewer.getTable().dispose();
+ }
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ viewer.getControl().setLayoutData(gd);
+ viewer.setContentProvider(new ObservableListContentProvider());
+ viewer.setLabelProvider(new StyledCellLabelProvider() {
+ @Override
+ public void update(ViewerCell cell) {
+ ContributionData data;
+ if (cell.getElement() instanceof ContributionData) {
+ data = (ContributionData) cell.getElement();
+ } else if (cell.getElement() instanceof ContributionDataFile) {
+ data = ((ContributionDataFile) cell.getElement()).getContributionData();
+ } else {
+ return;
+ }
+
+ StyledString styledString = new StyledString();
+ if (data.className != null) {
+ styledString.append(data.className, null);
+ }
+
+ if (data.bundleName != null) {
+ styledString.append(" - " + data.bundleName, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ } else if (data.installLocation != null) {
+ styledString.append(" - " + data.installLocation, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ }
+
+ if (data.sourceType != null) {
+ styledString.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ styledString.append(data.sourceType + "", StyledString.COUNTER_STYLER); //$NON-NLS-1$
+ }
+
+ if (data.iconPath == null) {
+ cell.setImage(contributionTypeImage);
+ }
+
+ cell.setText(styledString.getString());
+ cell.setStyleRanges(styledString.getStyleRanges());
+ }
+ });
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ okPressed();
+ }
+ });
+
+ viewer.setInput(viewerList);
+
+ if (oldViewer != null) {
+ getViewer().getTable().getParent().layout(true, true);
+ getViewer().getTable().getParent().redraw();
+ }
+ }
+
+ public TableViewer getViewer() {
+ return viewer;
+ }
+
+ public void setViewer(TableViewer viewer) {
+ this.viewer = viewer;
+ }
+
+ protected Text getFilterTextBox() {
+ return textBox;
+ }
+
+ public ResourceSearchScope getSearchScope() {
+ return searchScope;
+ }
+
+ protected IFile getSelectedIfile() {
+ IStructuredSelection s = (IStructuredSelection) getViewer().getSelection();
+ if (!s.isEmpty()) {
+ Object selected = s.getFirstElement();
+ if (selected instanceof ContributionData) {
+ ContributionData contributionData = (ContributionData) selected;
+ return new ContributionDataFile(contributionData);
+ } else if (selected instanceof IFile) {
+ return (IFile) selected;
+ } else if (selected instanceof Entry) {
+ Entry entry = (Entry) selected;
+ ContributionData cd = new ContributionData(null, null, "Java", entry.file.getFullPath().toOSString());
+ cd.installLocation = entry.installLocation;
+ cd.resourceRelativePath = entry.file.getProjectRelativePath().toOSString();
+ return new ContributionDataFile(cd);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns non null if the selected resource is accessible from the current
+ * project<br />
+ * Restrictions may include non-existent file, non exported class, or the
+ * resource is in a location that is not a bundle.<br />
+ * The function, through user intervention, may find a way to resolve the
+ * file and return a resolution.
+ *
+ * @param file
+ * @param installLocation
+ * @return The original file, a fixed-up (copied or referred) file, or null.
+ */
+ protected IFile checkResourceAccessible(final IFile file, String installLocation) {
+
+ // Obviously null is not accessible
+ if (file == null) {
+ return null;
+ }
+
+ // Not a bundle
+ final String bundle = getBundle(file);
+ if (bundle == null) {
+ NonReferencedResourceDialog dlg = new NonReferencedResourceDialog(getShell(), context.get(IProject.class), bundle, file, installLocation, context) {
+ @Override
+ public String getMessage() {
+ String message = "The resource is not contained in a bundle.";
+ // message +=
+ // "\nTo access during runtime, you need to copy the resource into this project, or into a referenced project.";
+ // message +=
+ // "\nYou can also convert the resource's project into a bundle and then import reference the bundle";
+ return message;
+ }
+ };
+ if (dlg.open() == IDialogConstants.OK_ID) {
+ return dlg.getResult();
+ } else {
+ return null;
+ }
+
+ }
+
+ // Reference by current project
+ IProject currentProject = context.get(IProject.class);
+ if (currentProject != null && !getBundle(currentProject).equals(bundle)) {
+ boolean found = false;
+ // search the current project's manifest for require-bundle
+ try {
+ BundleModel model = loadBundleModel(currentProject);
+
+ RequireBundleHeader rbh = (RequireBundleHeader) model.getBundle().getManifestHeader("Require-Bundle");
+ if (rbh != null) {
+ for (RequireBundleObject item : rbh.getRequiredBundles()) {
+ if (item.getValue().equals(bundle)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ // search the current project's manifest for import-package
+ if (!found) {
+ if (file instanceof ContributionDataFile) {
+ ContributionDataFile cdFile = (ContributionDataFile) file;
+ String className = cdFile.getContributionData().className;
+ if (className != null) {
+ String pakage = NonReferencedResourceDialog.getPackageFromClassName(className);
+ ImportPackageHeader iph = (ImportPackageHeader) model.getBundle().getManifestHeader("Import-Package");
+ if (iph != null) {
+ for (ImportPackageObject item : iph.getPackages()) {
+ if (item.getValue().equals(pakage)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ }
+
+ if (!found) {
+ NonReferencedResourceDialog dlg = new NonReferencedResourceDialog(getShell(), context.get(IProject.class), bundle, file, installLocation, context);
+ if (dlg.open() == IDialogConstants.OK_ID) {
+ return dlg.getResult();
+ } else {
+ return null;
+ }
+ }
+ }
+ return file;
+ }
+
+ public BundleModel loadBundleModel(IProject currentProject) throws CoreException {
+ Document document = new Document();
+ String content = new Scanner(PDEProject.getManifest(currentProject).getContents()).useDelimiter("\\Z").next();
+ document.set(content);
+ BundleModel model = new BundleModel(document, false);
+ model.load();
+ return model;
+ }
+
+ protected EnumSet<ResourceSearchScope> getSearchScopes() {
+ return searchScopes;
+ }
+
+ static public String getBundle(IFile file) {
+
+ if (file instanceof ContributionDataFile) {
+ ContributionDataFile cdFile = (ContributionDataFile) file;
+ String ret = cdFile.getBundle();
+ if (ret != null) {
+ return ret;
+ } else if (cdFile.getContributionData().installLocation != null) {
+ return getBundle(cdFile.getContributionData().installLocation);
+ } else {
+ return null;
+ }
+ }
+
+ IProject project = file.getProject();
+ return getBundle(project);
+ }
+
+ static String getBundle(IProject project) {
+ IFile f = project.getFile("/META-INF/MANIFEST.MF"); //$NON-NLS-1$
+
+ if (f != null && f.exists()) {
+ BufferedReader r = null;
+ try {
+ InputStream s = f.getContents();
+ r = new BufferedReader(new InputStreamReader(s));
+ String line;
+ while ((line = r.readLine()) != null) {
+ if (line.startsWith("Bundle-SymbolicName:")) { //$NON-NLS-1$
+ int start = line.indexOf(':');
+ int end = line.indexOf(';');
+ if (end == -1) {
+ end = line.length();
+ }
+ return line.substring(start + 1, end).trim();
+ }
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (r != null) {
+ try {
+ r.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Searches the directory for a manifest and parses the symbolic name.
+ *
+ * @param rootDirectory
+ * @return
+ */
+ public static String getBundle(String rootDirectory) {
+ File f = new File(new File(rootDirectory), "/META-INF/MANIFEST.MF"); //$NON-NLS-1$
+
+ if (f.exists()) {
+ BufferedReader r = null;
+ try {
+ InputStream s = new FileInputStream(f);
+ r = new BufferedReader(new InputStreamReader(s));
+ String line;
+ while ((line = r.readLine()) != null) {
+ if (line.startsWith("Bundle-SymbolicName:")) { //$NON-NLS-1$
+ int start = line.indexOf(':');
+ int end = line.indexOf(';');
+ if (end == -1) {
+ end = line.length();
+ }
+ return line.substring(start + 1, end).trim();
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (r != null) {
+ try {
+ r.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuIconDialogEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuIconDialogEditor.java
index 33583695..cc1fb680 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuIconDialogEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuIconDialogEditor.java
@@ -7,10 +7,12 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
@@ -19,8 +21,8 @@ import org.eclipse.swt.widgets.Shell;
public class MenuIconDialogEditor extends AbstractIconDialog {
- public MenuIconDialogEditor(Shell parentShell, IProject project, EditingDomain editingDomain, MMenu element, Messages Messages) {
- super(parentShell, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
+ public MenuIconDialogEditor(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MMenu element, Messages Messages) {
+ super(parentShell, context, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
}
@Override
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuItemIconDialogEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuItemIconDialogEditor.java
index 2d5ad184..0a91fe07 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuItemIconDialogEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/MenuItemIconDialogEditor.java
@@ -7,10 +7,12 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
@@ -19,8 +21,8 @@ import org.eclipse.swt.widgets.Shell;
public class MenuItemIconDialogEditor extends AbstractIconDialog {
- public MenuItemIconDialogEditor(Shell parentShell, IProject project, EditingDomain editingDomain, MMenuItem element, Messages Messages) {
- super(parentShell, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
+ public MenuItemIconDialogEditor(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MMenuItem element, Messages Messages) {
+ super(parentShell, context, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
}
@Override
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartDescriptorIconDialogEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartDescriptorIconDialogEditor.java
index 92814cd1..abce02f9 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartDescriptorIconDialogEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartDescriptorIconDialogEditor.java
@@ -7,10 +7,12 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
- ******************************************************************************/
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
+******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
@@ -19,8 +21,8 @@ import org.eclipse.swt.widgets.Shell;
public class PartDescriptorIconDialogEditor extends AbstractIconDialog {
- public PartDescriptorIconDialogEditor(Shell parentShell, IProject project, EditingDomain editingDomain, MPartDescriptor element, Messages Messages) {
- super(parentShell, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
+ public PartDescriptorIconDialogEditor(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MPartDescriptor element, Messages Messages) {
+ super(parentShell, context, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
}
@Override
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartIconDialogEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartIconDialogEditor.java
index 8f283343..ed311dd7 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartIconDialogEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PartIconDialogEditor.java
@@ -7,10 +7,12 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
@@ -19,8 +21,8 @@ import org.eclipse.swt.widgets.Shell;
public class PartIconDialogEditor extends AbstractIconDialog {
- public PartIconDialogEditor(Shell parentShell, IProject project, EditingDomain editingDomain, MPart element, Messages Messages) {
- super(parentShell, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
+ public PartIconDialogEditor(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MPart element, Messages Messages) {
+ super(parentShell, context, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
}
@Override
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PerspectiveIconDialogEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PerspectiveIconDialogEditor.java
index 189632c3..81bf9fef 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PerspectiveIconDialogEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/PerspectiveIconDialogEditor.java
@@ -7,10 +7,12 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
@@ -19,8 +21,8 @@ import org.eclipse.swt.widgets.Shell;
public class PerspectiveIconDialogEditor extends AbstractIconDialog {
- public PerspectiveIconDialogEditor(Shell parentShell, IProject project, EditingDomain editingDomain, MPerspective element, Messages Messages) {
- super(parentShell, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
+ public PerspectiveIconDialogEditor(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MPerspective element, Messages Messages) {
+ super(parentShell, context, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
}
@Override
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ToolItemIconDialogEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ToolItemIconDialogEditor.java
index 242fba0f..9d6e1089 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ToolItemIconDialogEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ToolItemIconDialogEditor.java
@@ -7,10 +7,12 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
import org.eclipse.e4.ui.model.application.ui.menu.MToolItem;
@@ -19,8 +21,8 @@ import org.eclipse.swt.widgets.Shell;
public class ToolItemIconDialogEditor extends AbstractIconDialog {
- public ToolItemIconDialogEditor(Shell parentShell, IProject project, EditingDomain editingDomain, MToolItem element, Messages Messages) {
- super(parentShell, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
+ public ToolItemIconDialogEditor(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MToolItem element, Messages Messages) {
+ super(parentShell, context, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
}
@Override
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/WindowIconDialogEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/WindowIconDialogEditor.java
index 1a0fbaff..dc22bb17 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/WindowIconDialogEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/WindowIconDialogEditor.java
@@ -7,10 +7,12 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - Bug 424730
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
@@ -19,8 +21,8 @@ import org.eclipse.swt.widgets.Shell;
public class WindowIconDialogEditor extends AbstractIconDialog {
- public WindowIconDialogEditor(Shell parentShell, IProject project, EditingDomain editingDomain, MWindow element, Messages Messages) {
- super(parentShell, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
+ public WindowIconDialogEditor(Shell parentShell, IEclipseContext context, IProject project, EditingDomain editingDomain, MWindow element, Messages Messages) {
+ super(parentShell, context, project, editingDomain, element, UiPackageImpl.Literals.UI_LABEL__ICON_URI, Messages);
}
@Override
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ContributionUriCellEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ContributionUriCellEditor.java
new file mode 100644
index 00000000..66f14b47
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ContributionUriCellEditor.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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: Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.BundleClassDialog;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.IconDialog;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.UriDialog;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.UriDialogType;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.DialogCellEditor;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * A cell editor that when selected offers the option to edit, view, or goto the
+ * item.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class ContributionUriCellEditor extends DialogCellEditor {
+
+ private UriDialog dlg;
+
+ public ContributionUriCellEditor(Composite parent, int style, IEclipseContext context, UriDialogType dialogType) {
+ super(parent, style);
+ switch (dialogType) {
+ case ICON:
+ dlg = new IconDialog(parent.getShell(), context);
+ break;
+ case BUNDLECLASS:
+ default:
+ dlg = new BundleClassDialog(parent.getShell(), context);
+ break;
+ }
+ }
+
+ @Override
+ protected Object openDialogBox(Control cellEditorWindow) {
+ dlg.setUri((String) getValue());
+ if (dlg.open() == Dialog.OK) {
+ return dlg.getUri();
+ } else {
+ return getValue();
+ }
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/E4ToolItemMenu.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/E4ToolItemMenu.java
new file mode 100644
index 00000000..3dbba0f5
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/E4ToolItemMenu.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+
+/**
+ * A tool item that displays commands in a drop down menu. The enabled state is
+ * set by querying the handler when the menu is opened.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class E4ToolItemMenu {
+
+ public static final String SEPARATOR = "~separator~"; //$NON-NLS-1$
+ private IEclipseContext context;
+ private ArrayList<String> commandIds = new ArrayList<String>();
+ private Menu menu;
+ private ECommandService commandService;
+ private EHandlerService handlerService;
+ private ToolItem toolItem;
+
+ public E4ToolItemMenu(final ToolBar parent, IEclipseContext context) {
+
+ toolItem = new ToolItem(parent, SWT.DROP_DOWN);
+ this.context = context;
+ commandService = this.context.get(ECommandService.class);
+ handlerService = this.context.get(EHandlerService.class);
+
+ menu = new Menu(parent.getShell(), SWT.POP_UP);
+
+ toolItem.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ // if (event.detail == SWT.ARROW) {
+ Rectangle rect = toolItem.getBounds();
+ Point pt = new Point(rect.x, rect.y + rect.height);
+ pt = parent.toDisplay(pt);
+ menu.setLocation(pt.x, pt.y);
+ menu.setVisible(true);
+ for (MenuItem mi : menu.getItems()) {
+ if (mi.getData() instanceof ParameterizedCommand) {
+ ParameterizedCommand cmd = (ParameterizedCommand) mi.getData();
+ mi.setEnabled(handlerService.canExecute(cmd));
+ }
+ }
+ // }
+ };
+ });
+ }
+
+ public void addCommands(Collection<String> commandIds) {
+ this.commandIds.addAll(commandIds);
+
+ for (String id : commandIds) {
+ if (id.equals(SEPARATOR)) {
+ new MenuItem(menu, SWT.SEPARATOR);
+ } else {
+ ParameterizedCommand myCommand = commandService.createCommand(id, null);
+ if (myCommand != null) {
+ final MenuItem item = new MenuItem(menu, SWT.PUSH);
+ try {
+ item.setText(myCommand.getName());
+ } catch (NotDefinedException e1) {
+ item.setText(id);
+ e1.printStackTrace();
+ }
+ item.setData(myCommand);
+ item.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ParameterizedCommand cmd = (ParameterizedCommand) item.getData();
+ handlerService.executeHandler(cmd);
+ }
+
+ });
+ }
+ }
+ }
+ }
+
+ public ToolItem getToolItem() {
+ return toolItem;
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeEditingSupport.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeEditingSupport.java
index 4c30a06e..68a7c6dd 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeEditingSupport.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeEditingSupport.java
@@ -6,57 +6,126 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Steven Spungin <steven@spungin.tv> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
*******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.UriDialogType;
+
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.util.Policy;
import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
+// Restrictions: Only handles boolean and String types
class EAttributeEditingSupport extends EditingSupport {
private String attName;
- private TextCellEditor editor;
private TableViewer tableViewer;
private boolean wasNull;
private IEclipseContext context;
+ static public enum ATT_TYPE {
+ STRING, BOOLEAN, INTEGER, NOT_AN_ATTRIBUTE, OTHER;
+ }
+
public EAttributeEditingSupport(TableViewer tableViewer, String attName, IEclipseContext context) {
super(tableViewer);
this.tableViewer = tableViewer;
this.attName = attName;
this.context = context;
- editor = new TextCellEditor(tableViewer.getTable(), SWT.NONE);
}
@Override
protected CellEditor getCellEditor(Object element) {
- return editor;
+ switch (getAttributeType(element, attName)) {
+ case BOOLEAN:
+ return new CheckboxCellEditor(tableViewer.getTable(), SWT.CHECK);
+ case STRING:
+ case INTEGER:
+ default:
+ if ("contributionURI".equals(attName)) { //$NON-NLS-1$
+ return new ContributionUriCellEditor(tableViewer.getTable(), SWT.NONE, context, UriDialogType.BUNDLECLASS);
+ }
+ if ("iconURI".equals(attName)) { //$NON-NLS-1$
+ return new ContributionUriCellEditor(tableViewer.getTable(), SWT.NONE, context, UriDialogType.ICON);
+ }
+ return new TextCellEditor(tableViewer.getTable(), SWT.NONE);
+ }
+ }
+
+ static public ATT_TYPE getAttributeType(Object element, String attName) {
+ EAttribute att = EmfUtil.getAttribute((EObject) element, attName);
+ if (att == null) {
+ return ATT_TYPE.NOT_AN_ATTRIBUTE;
+ }
+ String instanceTypeName = att.getEType().getInstanceTypeName();
+ if (instanceTypeName.equals(String.class.getName())) {
+ return ATT_TYPE.STRING;
+ } else if (instanceTypeName.equals(boolean.class.getName())) {
+ return ATT_TYPE.BOOLEAN;
+ } else if (instanceTypeName.equals(int.class.getName())) {
+ return ATT_TYPE.INTEGER;
+ } else {
+ return ATT_TYPE.OTHER;
+ }
}
@Override
protected boolean canEdit(Object element) {
- return EmfUtil.getAttribute((EObject) element, attName) != null;
+ EAttribute att = EmfUtil.getAttribute((EObject) element, attName);
+ if (att == null) {
+ return false;
+ } else {
+ String instanceTypeName = att.getEType().getInstanceTypeName();
+ if (instanceTypeName.equals(String.class.getName())) {
+ return true;
+ } else if (instanceTypeName.equals(boolean.class.getName())) {
+ return true;
+ } else if (instanceTypeName.equals(int.class.getName())) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
@Override
protected Object getValue(Object element) {
EObject eObject = (EObject) element;
Object value = eObject.eGet(EmfUtil.getAttribute(eObject, attName));
- if (value == null) {
- value = ""; //$NON-NLS-1$
- wasNull = true;
- } else {
+ switch (getAttributeType(element, attName)) {
+ case BOOLEAN:
wasNull = false;
+ break;
+ case INTEGER:
+ if (value == null) {
+ value = ""; //$NON-NLS-1$
+ wasNull = true;
+ } else {
+ return Integer.toString((Integer) value);
+ }
+ break;
+ case STRING:
+ default:
+ if (value == null) {
+ value = ""; //$NON-NLS-1$
+ wasNull = true;
+ } else {
+ wasNull = false;
+ }
+ break;
}
return value;
}
@@ -64,12 +133,33 @@ class EAttributeEditingSupport extends EditingSupport {
@Override
protected void setValue(Object element, Object value) {
EObject eObject = (EObject) element;
- if (value.equals("") && wasNull) { //$NON-NLS-1$
- value = null;
+ switch (getAttributeType(element, attName)) {
+ case INTEGER:
+ if (value.equals("")) { //$NON-NLS-1$
+ value = null;
+ } else {
+ try {
+ value = Integer.parseInt(value.toString());
+ } catch (Exception e) {
+ return;
+ }
+ }
+ break;
+ case BOOLEAN:
+ case STRING:
+ default:
+ if (value.equals("") && wasNull) { //$NON-NLS-1$
+ value = null;
+ }
+ break;
}
Command cmd = SetCommand.create(context.get(EditingDomain.class), eObject, EmfUtil.getAttribute(eObject, attName), value);
context.get(EditingDomain.class).getCommandStack().execute(cmd);
TableViewerUtil.updateAndPack(tableViewer, eObject);
}
+ static public TableViewerColumn getTableViewerColumn(TableViewer viewer, int index) {
+ return (TableViewerColumn) viewer.getTable().getColumn(index).getData(Policy.JFACE + ".columnViewer"); //$NON-NLS-1$
+
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeTableViewerColumn.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeTableViewerColumn.java
index 63030ac5..e003e3d4 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeTableViewerColumn.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeTableViewerColumn.java
@@ -6,12 +6,14 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Steven Spungin <steven@spungin.tv> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
*******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider;
+import org.eclipse.e4.tools.services.IResourcePool;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ColumnLabelProvider;
@@ -19,18 +21,29 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
/**
* A table viewer column for editing an EMF EAttribute If the object does not
* have an attribute with the given ID, the field is disabled.
- *
+ *
* @author Steven Spungin
*
*/
public class EAttributeTableViewerColumn {
+ private TableViewerColumn tlc;
+ private IResourcePool resourcePool;
+ private String attName;
+ private TableViewer tvResults;
+
public EAttributeTableViewerColumn(final TableViewer tvResults, String label, final String attName, final IEclipseContext context) {
- TableViewerColumn tlc = new TableViewerColumn(tvResults, SWT.NONE);
+ this.tvResults = tvResults;
+ this.attName = attName;
+ tlc = new TableViewerColumn(tvResults, SWT.NONE);
+
+ // CAN be null. Used for checkbox icon.
+ resourcePool = context.get(IResourcePool.class);
tlc.getColumn().setText(label);
tlc.setLabelProvider(new ColumnLabelProvider() {
@@ -44,21 +57,57 @@ public class EAttributeTableViewerColumn {
} else {
value = ""; //$NON-NLS-1$
}
- return super.getText(value);
+ switch (EAttributeEditingSupport.getAttributeType(element, attName)) {
+ case BOOLEAN:
+ // if no icons provided, use text instead of checkbox
+ return resourcePool == null && ((Boolean) value) ? "X" : ""; //$NON-NLS-1$ //$NON-NLS-2$
+ case STRING:
+ case NOT_AN_ATTRIBUTE:
+ case OTHER:
+ default:
+ return super.getText(value);
+ }
}
@Override
- public Color getBackground(Object element) {
- EObject eObject = (EObject) element;
- EAttribute eAtt = EmfUtil.getAttribute(eObject, attName);
- if (eAtt == null) {
- return tvResults.getTable().getDisplay().getSystemColor(SWT.COLOR_GRAY);
- } else {
- return super.getBackground(element);
+ public Image getImage(Object element) {
+ switch (EAttributeEditingSupport.getAttributeType(element, attName)) {
+ case BOOLEAN:
+ if (resourcePool != null) {
+ Object value = EmfUtil.getAttributeValue((EObject) element, attName);
+ if (value != null && value.equals(true)) {
+ return resourcePool.getImageUnchecked(ResourceProvider.IMG_Widgets_checkbox_obj);
+ }
+ }
+ // fall through
+ case STRING:
+ case NOT_AN_ATTRIBUTE:
+ case OTHER:
+ default:
+ return super.getImage(element);
}
}
+
+ @Override
+ public Color getBackground(Object element) {
+ return EAttributeTableViewerColumn.this.getBackground(element);
+ }
});
tlc.setEditingSupport(new EAttributeEditingSupport(tvResults, attName, context));
}
+ public Color getBackground(Object element) {
+ EObject eObject = (EObject) element;
+ EAttribute eAtt = EmfUtil.getAttribute(eObject, attName);
+ if (eAtt == null) {
+ return tvResults.getTable().getDisplay().getSystemColor(SWT.COLOR_GRAY);
+ } else {
+ return null;
+ }
+ }
+
+ public void dispose() {
+ tlc.getColumn().dispose();
+ }
+
}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IViewEObjects.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IViewEObjects.java
index 24781744..a7ec21d8 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IViewEObjects.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IViewEObjects.java
@@ -6,13 +6,14 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Steven Spungin <steven@spungin.tv> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
*******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
import java.util.Collection;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
/**
* This interface provides a common API for editing trees, lists, and xml
@@ -54,4 +55,10 @@ public interface IViewEObjects {
* are ignored.
*/
void deleteEObjects(Collection<EObject> list);
+
+ /**
+ *
+ * @return The editing domain for the implementor's model.
+ */
+ EditingDomain getEditingDomain();
}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java
index a793a761..d1ab894a 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java
@@ -6,13 +6,16 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Steven Spungin <steven@spungin.tv> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
*******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct;
@@ -23,8 +26,14 @@ import org.eclipse.e4.tools.emf.ui.common.IModelResource;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider;
import org.eclipse.e4.tools.emf.ui.internal.common.ModelEditor;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.BundleImageCache;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.EmptyFilterOption;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.TitleAreaFilterDialog;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.TitleAreaFilterDialogWithEmptyOptions;
import org.eclipse.e4.tools.emf.ui.internal.common.xml.EMFDocumentResourceMediator;
import org.eclipse.e4.tools.services.IResourcePool;
+import org.eclipse.e4.tools.services.Translation;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.TreeIterator;
@@ -32,36 +41,57 @@ import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.DeleteCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
/**
* A tab that contains a list EObjects, and provides editable columns for
* EObject features.
- *
+ *
* @author Steven Spungin
*
*/
public class ListTab implements IViewEObjects {
+ static final String ELIPSIS = "..."; //$NON-NLS-1$
+
// The table will only include EObjects that define this attribute
- private static final String FILTER_ATTRUBUTE_ID = "elementId"; //$NON-NLS-1$
+ private static final String FILTER_ATTRIBUTE_ID = "elementId"; //$NON-NLS-1$
ConcurrentHashMap<String, List<EObject>> mapId_Object = new ConcurrentHashMap<String, List<EObject>>();
@@ -80,8 +110,14 @@ public class ListTab implements IViewEObjects {
private IResourcePool resourcePool;
@Inject
+ @Translation
+ protected Messages Messages;
+
+ @Inject
MApplication app;
+ BundleImageCache imageCache;
+
private CTabItem tabItem;
private ModelResourceContentProvider provider;
@@ -90,6 +126,15 @@ public class ListTab implements IViewEObjects {
private Collection<?> highlightedItems;
+ HashMap<String, EAttributeTableViewerColumn> defaultColumns = new HashMap<String, EAttributeTableViewerColumn>();
+ HashMap<String, EAttributeTableViewerColumn> optionalColumns = new HashMap<String, EAttributeTableViewerColumn>();
+
+ private ToolItem filterByItem;
+
+ private ToolItem filterByAttribute;
+
+ protected Image imgMarkedItem;
+
@PreDestroy
public void preDestroy() {
// race condition issue with observables (exception is not thrown when
@@ -100,6 +145,19 @@ public class ListTab implements IViewEObjects {
@PostConstruct
public void postConstruct(final CTabFolder tabFolder) {
+ imageCache = new BundleImageCache(context.get(Display.class), getClass().getClassLoader());
+ tabFolder.addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ imageCache.dispose();
+ }
+ });
+ try {
+ imgMarkedItem = imageCache.create("org.eclipse.e4.tools.emf.ui", "/icons/full/obj16/mark_occurrences.png"); //$NON-NLS-1$//$NON-NLS-2$
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ }
documentListener = new IDocumentListener() {
@@ -114,7 +172,7 @@ public class ListTab implements IViewEObjects {
};
context.get(EMFDocumentResourceMediator.class).getDocument().addDocumentListener(documentListener);
- tabItem = new CTabItem(tabFolder, SWT.NONE);
+ tabItem = new CTabItem(tabFolder, SWT.NONE, 1);
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@@ -122,19 +180,186 @@ public class ListTab implements IViewEObjects {
tabItem.setControl(composite);
tabItem.setText(Messages.ListTab_0);
- tabItem.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_world_edit));
+ tabItem.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Widgets_table_obj));
+
+ final ToolBar toolBar = new ToolBar(composite, SWT.FLAT | SWT.NO_FOCUS);
+ toolBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
+
+ {
+ ToolItem button = new ToolItem(toolBar, SWT.PUSH);
+ button.setText(Messages.ListTab_addColumn + ELIPSIS);
+ button.setImage(imageCache.create("/icons/full/obj16/add_column.gif")); //$NON-NLS-1$
+
+ button.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ TitleAreaFilterDialogWithEmptyOptions dlg = createEObjectAttributePicker(Messages.ListTab_addColumn);
+ dlg.setShowEmptyOptions(false);
+ if (dlg.open() == dlg.OK) {
+ // Add Column
+ String attName = dlg.getFirstElement().toString();
+ addColumn(attName);
+ }
+ }
+ });
+ }
+
{
- Label label = new Label(composite, SWT.NONE);
- GridData layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
- layoutData.horizontalSpan = 2;
- label.setLayoutData(layoutData);
- label.setText(Messages.ListTab_7 + FILTER_ATTRUBUTE_ID);
+ ToolItem button = new ToolItem(toolBar, SWT.PUSH);
+ button.setText(Messages.ListTab_resetColumns);
+ button.setImage(imageCache.create("/icons/full/obj16/reset_columns.gif")); //$NON-NLS-1$
+
+ button.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ for (EAttributeTableViewerColumn col : optionalColumns.values()) {
+ col.dispose();
+ }
+ optionalColumns.clear();
+ TableViewerUtil.refreshAndPack(tvResults);
+ }
+ });
+ }
+
+ new ToolItem(toolBar, SWT.SEPARATOR);
+
+ filterByItem = new ToolItem(toolBar, SWT.NONE);
+ {
+
+ filterByItem.setText(Messages.ListTab_filterByItem + ELIPSIS);
+ filterByItem.setImage(imageCache.create("/icons/full/obj16/filter_by_item.gif")); //$NON-NLS-1$
+
+ filterByItem.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ final TitleAreaFilterDialog dlg = createElementTypePicker(Messages.ListTab_filterByItem);
+ if (dlg.open() == Window.OK) {
+ final String name = dlg.getFirstElement().toString();
+ mapId_Object.clear();
+ final ArrayList<EObject> filtered = new ArrayList<EObject>();
+ for (EObject object : getAllEObjects()) {
+ if (object.eClass().getName().equals(name)) {
+ filtered.add(object);
+ // filter.setText(Messages.ListTab_7 +
+ // attFilter);
+
+ }
+
+ ViewerFilter viewerFilter = new ViewerFilter() {
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ return filtered.contains(element);
+ }
+
+ };
+ tvResults.setFilters(new ViewerFilter[] { viewerFilter });
+ filterByItem.setText(Messages.ListTab_filterByItem + ELIPSIS + "(" + name + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ filterByAttribute.setText(Messages.ListTab_filterByAttribute + ELIPSIS);
+ }
+ }
+ };
+ });
}
- tvResults = new TableViewer(composite);
+ filterByAttribute = new ToolItem(toolBar, SWT.NONE);
+ {
+
+ filterByAttribute.setText(Messages.ListTab_filterByAttribute + ELIPSIS);
+ filterByAttribute.setImage(imageCache.create("/icons/full/obj16/filter_by_attribute.gif")); //$NON-NLS-1$
+
+ filterByAttribute.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ TitleAreaFilterDialogWithEmptyOptions dlg = createEObjectAttributePicker(Messages.ListTab_filterByAttribute);
+ if (dlg.open() == dlg.OK) {
+ final String attFilter = dlg.getFirstElement().toString();
+ final EmptyFilterOption emptyOption = dlg.getEmptyFilterOption();
+ mapId_Object.clear();
+ final ArrayList<EObject> filtered = new ArrayList<EObject>();
+ for (EObject object : getAllEObjects()) {
+ if (EmfUtil.getAttribute(object, attFilter) != null) {
+ filtered.add(object);
+ ViewerFilter viewerFilter = new ViewerFilter() {
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ // if filtering on attribute, always
+ // reject if not defined for model
+ // element
+ if (EmfUtil.getAttribute((EObject) element, attFilter) == null) {
+ return false;
+ }
+ switch (emptyOption) {
+ case EXCLUDE:
+ if (E.isEmpty(EmfUtil.getAttributeValue((EObject) element, attFilter))) {
+ return false;
+ } else {
+ return filtered.contains(element);
+ }
+ case ONLY:
+ if (E.notEmpty((EmfUtil.getAttributeValue((EObject) element, attFilter)))) {
+ return false;
+ } else {
+ return true;
+ }
+ default:
+ case INCLUDE:
+ if (E.isEmpty(EmfUtil.getAttributeValue((EObject) element, attFilter))) {
+ return true;
+ } else {
+ return filtered.contains(element);
+ }
+ }
+ }
+ };
+ tvResults.setFilters(new ViewerFilter[] { viewerFilter });
+ filterByAttribute.setText(Messages.ListTab_filterByAttribute + ELIPSIS + "(" + attFilter + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ filterByItem.setText(Messages.ListTab_filterByItem + ELIPSIS);
+
+ }
+ }
+ addColumn(attFilter);
+ }
+ };
+ });
+ }
+
+ {
+ final ToolItem filterRemove = new ToolItem(toolBar, SWT.NONE);
+ filterRemove.setText(Messages.ListTab_removeFilter);
+ filterRemove.setImage(imageCache.create("/icons/full/obj16/remove_filter.png")); //$NON-NLS-1$
+
+ filterRemove.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ tvResults.setFilters(new ViewerFilter[0]);
+ filterByItem.setText(Messages.ListTab_filterByItem + ELIPSIS);
+ filterByAttribute.setText(Messages.ListTab_markAttribute + ELIPSIS);
+ };
+ });
+ }
+
+ new ToolItem(toolBar, SWT.SEPARATOR);
+
+ {
+ final E4ToolItemMenu tiCommands = new E4ToolItemMenu(toolBar, context);
+ tiCommands.getToolItem().setImage(imageCache.create("/icons/full/obj16/command.gif")); //$NON-NLS-1$
+
+ ArrayList<String> commandIds = new ArrayList<String>();
+ commandIds.add("org.eclipse.e4.tools.emf.ui.command.mark_duplicate_attributes"); //$NON-NLS-1$
+ commandIds.add("org.eclipse.e4.tools.emf.ui.command.mark_duplicate_ids"); //$NON-NLS-1$
+ commandIds.add("org.eclipse.e4.tools.emf.ui.command.mark_duplicate_labels"); //$NON-NLS-1$
+ commandIds.add("org.eclipse.e4.tools.emf.ui.command.repair_duplicate_ids"); //$NON-NLS-1$
+ commandIds.add(E4ToolItemMenu.SEPARATOR);
+ commandIds.add("org.eclipse.e4.tools.emf.ui.command.unmark"); //$NON-NLS-1$
+ tiCommands.addCommands(commandIds);
+
+ }
+
+ tvResults = new TableViewer(composite, SWT.FULL_SELECTION);
tvResults.getTable().setHeaderVisible(true);
tvResults.getTable().setLinesVisible(true);
- // tvResults.setContentProvider(ArrayContentProvider.getInstance());
provider = new ModelResourceContentProvider();
tvResults.setContentProvider(provider);
@@ -186,9 +411,33 @@ public class ListTab implements IViewEObjects {
}
});
+ TableViewerColumn colMarked = new TableViewerColumn(tvResults, SWT.NONE);
+ colMarked.getColumn().setWidth(16);
+ colMarked.getColumn().setText(Messages.ListTab_mark);
+ colMarked.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public Image getImage(Object element) {
+ Image ret = null;
+ if (isHighlighted(element)) {
+ try {
+ ret = imgMarkedItem;
+ } catch (Exception e) {
+ } //$NON-NLS-1$
+ } else {
+ ret = null;
+ }
+ return ret;
+ }
+
+ @Override
+ public String getText(Object element) {
+ return ""; //$NON-NLS-1$
+ }
+ });
+
TableViewerColumn colItem = new TableViewerColumn(tvResults, SWT.NONE);
colItem.getColumn().setText(Messages.ListTab_col_item);
- colItem.setLabelProvider(new ColumnLabelProvider() {
+ colItem.setLabelProvider(new ColumnLabelProvider_Markable() {
@Override
public String getText(Object element) {
EObject eObject = (EObject) element;
@@ -199,34 +448,50 @@ public class ListTab implements IViewEObjects {
app.getContext().set("org.eclipse.e4.tools.active-object-viewer", this); //$NON-NLS-1$
TableViewerColumn colId = new TableViewerColumn(tvResults, SWT.NONE);
- colId.getColumn().setText(Messages.ListTab_col_id);
- colId.setLabelProvider(new ColumnLabelProvider() {
+ colId.getColumn().setText("elementId"); //$NON-NLS-1$
+ colId.setLabelProvider(new ColumnLabelProvider_Markable() {
@Override
public String getText(Object element) {
EObject eObject = (EObject) element;
- EAttribute eAtt = EmfUtil.getAttribute(eObject, FILTER_ATTRUBUTE_ID);
+ EAttribute eAtt = EmfUtil.getAttribute(eObject, "elementId"); //$NON-NLS-1$
return super.getText(eObject.eGet(eAtt));
}
+ });
+ colId.setEditingSupport(new EAttributeEditingSupport(tvResults, FILTER_ATTRIBUTE_ID, context));
+ EAttributeTableViewerColumn colLabel = new EAttributeTableViewerColumn_Markable(tvResults, "label", "label", context); //$NON-NLS-1$ //$NON-NLS-2$
+
+ defaultColumns.put("label", colLabel); //$NON-NLS-1$
+
+ // Custom selection for marked items
+ tvResults.getTable().addListener(SWT.EraseItem, new Listener() {
@Override
- public Color getBackground(Object element) {
- Color ret = super.getBackground(element);
- if (highlightedItems != null && highlightedItems.contains(element)) {
- return ret = tvResults.getTable().getDisplay().getSystemColor(SWT.COLOR_YELLOW);
+ public void handleEvent(Event event) {
+ event.detail &= ~SWT.HOT;
+ if ((event.detail & SWT.SELECTED) == 0)
+ return; // / item not selected
+
+ TableItem item = (TableItem) event.item;
+ if (isHighlighted(item.getData())) {
+
+ Table table = (Table) event.widget;
+ int clientWidth = table.getClientArea().width;
+ GC gc = event.gc;
+ // Color oldForeground = gc.getForeground();
+ // Color oldBackground = gc.getBackground();
+
+ // gc.setBackground(item.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
+ gc.setForeground(item.getDisplay().getSystemColor(SWT.COLOR_RED));
+ gc.fillRectangle(0, event.y, clientWidth, event.height);
+
+ // gc.setForeground(oldForeground);
+ // gc.setBackground(oldBackground);
+ event.detail &= ~SWT.SELECTED;
}
- return ret;
}
});
- colId.setEditingSupport(new EAttributeEditingSupport(tvResults, FILTER_ATTRUBUTE_ID, context));
-
- @SuppressWarnings("unused")
- EAttributeTableViewerColumn colLabel = new EAttributeTableViewerColumn(tvResults, Messages.ListTab_col_label, "label", context); //$NON-NLS-1$
-
- // Testing the commandName attribute column
- // Any attribute can be added this way
- // @SuppressWarnings("unused")
- //EAttributeTableViewerColumn colName = new EAttributeTableViewerColumn(tvResults, Messages.ListTab_commandname, "commandName", context); //$NON-NLS-1$
+ tvResults.getTable().setFocus();
reload();
}
@@ -290,4 +555,124 @@ public class ListTab implements IViewEObjects {
reload();
}
}
+
+ private TitleAreaFilterDialogWithEmptyOptions createEObjectAttributePicker(final String title) {
+ // Get Attribute Names
+ final HashSet<String> set = new HashSet<String>();
+ Collection<EObject> allEObjects = getAllEObjects();
+ for (EObject obj : allEObjects) {
+ for (EAttribute attribute : obj.eClass().getEAllAttributes()) {
+ set.add(attribute.getName());
+ }
+ }
+ final ArrayList<String> sorted = new ArrayList<String>(set);
+ Collections.sort(sorted);
+
+ // Select Attribute
+ ILabelProvider renderer = new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return String.valueOf(element);
+ }
+ };
+ TitleAreaFilterDialogWithEmptyOptions dlg = new TitleAreaFilterDialogWithEmptyOptions(context.get(Shell.class), renderer) {
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ setMessage(Messages.ListTab_selectAnAttribute);
+ try {
+ setTitleImage(imageCache.create("org.eclipse.e4.tools.emf.ui", "/icons/full/wizban/attribute_wiz.gif")); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ setTitle(title);
+ setElements(sorted.toArray(new String[0]));
+ return ret;
+ }
+ };
+ return dlg;
+ }
+
+ private TitleAreaFilterDialog createElementTypePicker(final String title) {
+ // Get Attribute Names
+ final HashSet<String> set = new HashSet<String>();
+ Collection<EObject> allEObjects = getAllEObjects();
+ for (EObject obj : allEObjects) {
+ set.add(obj.eClass().getName());
+ }
+
+ final ArrayList<String> sorted = new ArrayList<String>(set);
+ Collections.sort(sorted);
+
+ ILabelProvider renderer = new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return String.valueOf(element);
+ }
+ };
+ TitleAreaFilterDialog dlg = new TitleAreaFilterDialog(context.get(Shell.class), renderer) {
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ setMessage(Messages.ListTab_selectAType);
+ setTitle(title);
+ setElements(sorted.toArray(new String[0]));
+ return ret;
+ }
+ };
+ return dlg;
+ }
+
+ /**
+ * Adds a column if it does not already exist
+ *
+ * @param attName
+ */
+ private void addColumn(String attName) {
+ if (optionalColumns.containsKey(attName) == false && defaultColumns.containsKey(attName) == false) {
+ EAttributeTableViewerColumn colName = new EAttributeTableViewerColumn_Markable(tvResults, attName, attName, context);
+ TableViewerUtil.refreshAndPack(tvResults);
+ optionalColumns.put(attName, colName);
+ }
+ }
+
+ private class EAttributeTableViewerColumn_Markable extends EAttributeTableViewerColumn {
+ public EAttributeTableViewerColumn_Markable(TableViewer tvResults, String label, String attName, IEclipseContext context) {
+ super(tvResults, label, attName, context);
+ }
+
+ @Override
+ public Color getBackground(Object element) {
+ Color ret;
+ if (isHighlighted(element)) {
+ return ret = tvResults.getTable().getDisplay().getSystemColor(SWT.COLOR_YELLOW);
+ } else {
+ ret = super.getBackground(element);
+ }
+ return ret;
+ }
+ }
+
+ private class ColumnLabelProvider_Markable extends ColumnLabelProvider {
+ @Override
+ public Color getBackground(Object element) {
+ Color ret;
+ if (isHighlighted(element)) {
+ ret = tvResults.getTable().getDisplay().getSystemColor(SWT.COLOR_YELLOW);
+ } else {
+ ret = super.getBackground(element);
+ }
+ return ret;
+ }
+ }
+
+ @Override
+ public EditingDomain getEditingDomain() {
+ return modelResource.getEditingDomain();
+ }
+
+ public boolean isHighlighted(Object element) {
+ return highlightedItems != null && highlightedItems.contains(element);
+ }
}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/Messages.java
new file mode 100644
index 00000000..7981b5b9
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/Messages.java
@@ -0,0 +1,19 @@
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.messages"; //$NON-NLS-1$
+ public static String TitleAreaFilterDialog_enterFilterText;
+ public static String TitleAreaFilterDialogWithEmptyOptions_emptyValueDescription;
+ public static String TitleAreaFilterDialogWithEmptyOptions_excludeEmptyValues;
+ public static String TitleAreaFilterDialogWithEmptyOptions_includeEmptyValues;
+ public static String TitleAreaFilterDialogWithEmptyOptions_onlyEmptyValues;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/E.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/E.java
new file mode 100644
index 00000000..8f6a4cab
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/E.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
+ *******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty;
+
+import java.util.Collection;
+
+/**
+ * E is for empty. Very useful functions for determining empty objects. Avoids
+ * null checking and content checking, and makes code clearer. <br />
+ * An object is empty if it is null, an empty string, or an empty collection
+ *
+ * @author Steven Spungin
+ *
+ */
+public class E {
+
+ public static boolean notEmpty(String object) {
+ return !isEmpty(object);
+ }
+
+ public static boolean notEmpty(Collection<?> object) {
+ return !isEmpty(object);
+ }
+
+ public static boolean notEmpty(Object object) {
+ return !isEmpty(object);
+ }
+
+ public static boolean isEmpty(String object) {
+ return (object == null || object.isEmpty());
+ }
+
+ public static boolean isEmpty(Collection<?> object) {
+ return (object == null || object.isEmpty());
+ }
+
+ public static boolean isEmpty(Object object) {
+ if (object == null) {
+ return true;
+ } else if (object instanceof String && ((String) object).isEmpty()) {
+ return true;
+ } else if (object instanceof Collection<?> && ((Collection<?>) object).isEmpty()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ *
+ * @param obj1
+ * @param obj2
+ * @return true if (both objects are null) or (both objects are not null and
+ * equal)
+ */
+ static public boolean equals(Object obj1, Object obj2) {
+ if (obj1 == null) {
+ if (obj2 == null) {
+ return true;
+ } else {
+ return false;
+ }
+ } else if (obj2 == null) {
+ return false;
+ } else {
+ return obj1.equals(obj2);
+ }
+ }
+
+ /**
+ * Compares 2 objects.
+ *
+ * @param obj1
+ * @param obj2
+ * @return If both objects are null, returns 0. If only 1 object is null, it
+ * will return 1 or -1. Otherwise call compareTo on the first
+ * object.
+ */
+ static public <T> int compareTo(Comparable<T> obj1, T obj2) {
+ if (obj1 == null) {
+ if (obj2 == null) {
+ return 0;
+ } else {
+ return -1;
+ }
+ } else if (obj2 == null) {
+ return 1;
+ } else {
+ return obj1.compareTo(obj2);
+ }
+
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/SearchScope.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/EmptyFilterOption.java
index bd09e708..1bbba602 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/SearchScope.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/EmptyFilterOption.java
@@ -6,32 +6,29 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 404136
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
*******************************************************************************/
-package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty;
/**
- * Specifies the scope when searching for a resource
+ * Options for working with empty values in filters. <br />
+ * An empty value is a null object, empty string, or empty collection.
*
* @author Steven Spungin
*
*/
-public enum SearchScope {
+public enum EmptyFilterOption {
/**
- * Resources in the current project
+ * Do not include empty values
*/
- PROJECT,
+ EXCLUDE,
/**
- * Opened projects in the current workspace
+ * Include empty values
*/
- WORKSPACE,
+ INCLUDE,
/**
- * The current project, and projects the current project depends on
+ * Include only empty values
*/
- DEPENDENT,
- /**
- * All projects in the current workspace and bundles in the target platform
- */
- TARGET_PLATFORM
-}
+ ONLY
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/TitleAreaFilterDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/TitleAreaFilterDialog.java
new file mode 100644
index 00000000..df02c420
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/TitleAreaFilterDialog.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.Messages;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Extends TitleAreaDialog to include a filter text box.<br />
+ * If no item is selected, the dialog result is Dialog.Cancel, even if OK is
+ * pressed. A result of Dialog.Ok is ensured to have at least 1 selected item.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class TitleAreaFilterDialog extends TitleAreaDialog {
+
+ private ILabelProvider labelProvider;
+ private TableViewer viewer;
+ private Object result;
+ private Text text;
+
+ public TitleAreaFilterDialog(Shell parentShell, ILabelProvider labelProvider) {
+ super(parentShell);
+ this.labelProvider = labelProvider;
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite comp = (Composite) super.createDialogArea(parent);
+
+ comp.setLayoutData(new GridData(GridData.FILL_BOTH));
+ comp.setLayout(new GridLayout(1, false));
+
+ text = new Text(comp, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH);
+ text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ text.setMessage(Messages.TitleAreaFilterDialog_enterFilterText);
+
+ viewer = new TableViewer(comp, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
+ viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
+ viewer.setLabelProvider(labelProvider);
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
+
+ viewer.setFilters(new ViewerFilter[] { new ViewerFilter() {
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ return isFiltered(element, text.getText());
+ }
+ } });
+
+ text.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ viewer.refresh();
+ }
+ });
+
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ result = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
+ if (result != null) {
+ okPressed();
+ }
+ }
+ });
+
+ return comp;
+ }
+
+ /**
+ * Default returns true if string value contains the filterText, and it is
+ * case insensitive.
+ *
+ * @param element
+ * @param filterText
+ * @return
+ */
+ protected boolean isFiltered(Object element, String filterText) {
+ filterText = filterText.toLowerCase();
+ if (filterText.isEmpty()) {
+ return true;
+ } else if (element.toString().toLowerCase().contains(filterText)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ protected void okPressed() {
+ result = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
+ if (result == null) {
+ cancelPressed();
+ } else {
+ super.okPressed();
+ }
+ }
+
+ public void setElements(Object[] array) {
+ viewer.setInput(array);
+ }
+
+ public Object getFirstElement() {
+ return result;
+ }
+
+ protected TableViewer getViewer() {
+ return viewer;
+ }
+
+ protected Text getText() {
+ return text;
+ }
+
+ public List<?> asList() {
+ Object firstElement = getFirstElement();
+ if (firstElement == null) {
+ return Collections.EMPTY_LIST;
+ } else {
+ return Arrays.asList(firstElement);
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/TitleAreaFilterDialogWithEmptyOptions.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/TitleAreaFilterDialogWithEmptyOptions.java
new file mode 100644
index 00000000..2ef35a9c
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/empty/TitleAreaFilterDialogWithEmptyOptions.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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: Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
+ *******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.Messages;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * A standard ElementListSelectionDialog with additional options for including,
+ * excluding, and selecting empty values.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class TitleAreaFilterDialogWithEmptyOptions extends TitleAreaFilterDialog {
+ private Button btnExcludeEmptyValues;
+ private Button btnOnlyEmptyValues;
+ private Button btnIncludeEmptyValues;
+ private EmptyFilterOption emptyFilterOption;
+ private boolean bShowEmptyOptions = true;
+ private Composite compOptions;
+ private Composite parent;
+
+ public TitleAreaFilterDialogWithEmptyOptions(Shell parent, ILabelProvider renderer) {
+ super(parent, renderer);
+ }
+
+ @Override
+ protected org.eclipse.swt.widgets.Control createDialogArea(Composite parent) {
+ this.parent = parent;
+ Composite comp = (Composite) super.createDialogArea(parent);
+
+ // Label labelEmptyInfo = new Label(comp, SWT.NONE);
+ // labelEmptyInfo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER,
+ // false, false));
+ // labelEmptyInfo.setText("An empty value is defined as a null object, an empty string, or an empty collection.");
+
+ compOptions = new Composite(comp, SWT.NONE);
+ compOptions.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ compOptions.setLayout(new RowLayout());
+
+ // labelEmptyInfo.moveAbove(getText());
+ compOptions.moveAbove(getText());
+
+ btnExcludeEmptyValues = new Button(compOptions, SWT.RADIO);
+ btnExcludeEmptyValues.setText(Messages.TitleAreaFilterDialogWithEmptyOptions_excludeEmptyValues);
+ btnExcludeEmptyValues.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setEmptyFilterOption(EmptyFilterOption.EXCLUDE);
+ }
+ });
+
+ btnIncludeEmptyValues = new Button(compOptions, SWT.RADIO);
+ btnIncludeEmptyValues.setText(Messages.TitleAreaFilterDialogWithEmptyOptions_includeEmptyValues);
+ btnIncludeEmptyValues.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setEmptyFilterOption(EmptyFilterOption.INCLUDE);
+ }
+ });
+
+ btnOnlyEmptyValues = new Button(compOptions, SWT.RADIO);
+ btnOnlyEmptyValues.setText(Messages.TitleAreaFilterDialogWithEmptyOptions_onlyEmptyValues);
+ btnOnlyEmptyValues.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setEmptyFilterOption(EmptyFilterOption.ONLY);
+ }
+ });
+
+ String toolTip = Messages.TitleAreaFilterDialogWithEmptyOptions_emptyValueDescription;
+ btnExcludeEmptyValues.setToolTipText(toolTip);
+ btnIncludeEmptyValues.setToolTipText(toolTip);
+ btnOnlyEmptyValues.setToolTipText(toolTip);
+
+ setEmptyFilterOption(EmptyFilterOption.EXCLUDE);
+
+ updateEmptyOptionState();
+
+ parent.pack();
+ return comp;
+ }
+
+ @Override
+ public boolean close() {
+ return super.close();
+ }
+
+ public EmptyFilterOption getEmptyFilterOption() {
+ return emptyFilterOption;
+ }
+
+ public void setEmptyFilterOption(EmptyFilterOption emptyFilterOption) {
+ this.emptyFilterOption = emptyFilterOption;
+ updateUi();
+ }
+
+ private void updateUi() {
+ if (btnExcludeEmptyValues == null) {
+ return;
+ }
+ switch (emptyFilterOption) {
+ case EXCLUDE:
+ btnExcludeEmptyValues.setSelection(true);
+ btnIncludeEmptyValues.setSelection(false);
+ btnOnlyEmptyValues.setSelection(false);
+ break;
+ case INCLUDE:
+ btnExcludeEmptyValues.setSelection(false);
+ btnIncludeEmptyValues.setSelection(true);
+ btnOnlyEmptyValues.setSelection(false);
+ break;
+ case ONLY:
+ btnExcludeEmptyValues.setSelection(false);
+ btnIncludeEmptyValues.setSelection(false);
+ btnOnlyEmptyValues.setSelection(true);
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void setShowEmptyOptions(boolean bShow) {
+ this.bShowEmptyOptions = bShow;
+ updateEmptyOptionState();
+ }
+
+ private void updateEmptyOptionState() {
+ if (compOptions == null) {
+ return;
+ }
+ compOptions.setVisible(bShowEmptyOptions);
+ ((GridData) compOptions.getLayoutData()).exclude = bShowEmptyOptions == false;
+ parent.layout();
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/messages.properties
new file mode 100644
index 00000000..324ca93b
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/messages.properties
@@ -0,0 +1,5 @@
+TitleAreaFilterDialog_enterFilterText=Enter filter text
+TitleAreaFilterDialogWithEmptyOptions_emptyValueDescription=An empty value is defined as a null object, an empty string, or an empty collection.
+TitleAreaFilterDialogWithEmptyOptions_excludeEmptyValues=Exclude Empty Values
+TitleAreaFilterDialogWithEmptyOptions_includeEmptyValues=Include Empty Values
+TitleAreaFilterDialogWithEmptyOptions_onlyEmptyValues=Only Empty Values
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/BundleConverter.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/BundleConverter.java
new file mode 100644
index 00000000..4fafe7a1
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/BundleConverter.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator;
+
+import java.io.FileOutputStream;
+import java.util.jar.Manifest;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * Converts the given install location into a bundle.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class BundleConverter {
+
+ /**
+ *
+ * @param installLocation
+ * @return The bundleId of the bundle, or null if not converted
+ * @throws Exception
+ */
+ public static String convertProjectToBundle(String installLocation, IWorkspace workspace) throws Exception {
+ IPath project = Path.fromOSString(installLocation);
+ if (project.toFile().isDirectory() == false) {
+ throw new Exception(Messages.BundleConverter_installLocationNotADirectory);
+ }
+ IPath metaDir = project.append("META-INF"); //$NON-NLS-1$
+ if (metaDir.toFile().isDirectory() == false) {
+ if (metaDir.toFile().mkdir() == false) {
+ throw new Exception(Messages.BundleConverter_couldNotCreateMetaInfDir);
+ }
+ }
+ IPath manifestPath = metaDir.append("MANIFEST.MF"); //$NON-NLS-1$
+ if (manifestPath.toFile().isFile()) {
+ throw new Exception(Messages.BundleConverter_projectIsAlreadyABundle);
+ }
+ Manifest manifest = new Manifest();
+ // TODO prompt for names
+ IPath path = Path.fromOSString(installLocation);
+ String bundleId = path.lastSegment();
+ String bundleName = path.lastSegment();
+ manifest.getMainAttributes().putValue("Manifest-Version", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$
+ manifest.getMainAttributes().putValue("Bundle-SymbolicName", bundleId); //$NON-NLS-1$
+ manifest.getMainAttributes().putValue("Bundle-Name", bundleName); //$NON-NLS-1$
+ manifest.getMainAttributes().putValue("Bundle-Version", "0.0.1"); //$NON-NLS-1$ //$NON-NLS-2$
+ manifest.write(new FileOutputStream(manifestPath.toFile()));
+ IProject targetProject = workspace.getRoot().getProject(bundleId);
+ targetProject.refreshLocal(2, null);
+ return bundleId;
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/Messages.java
new file mode 100644
index 00000000..7f5dfcb1
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/Messages.java
@@ -0,0 +1,72 @@
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.messages"; //$NON-NLS-1$
+ public static String BundleClassDialog_bundle;
+ public static String BundleClassDialog_bundleClassEditor;
+ public static String BundleClassDialog_class;
+ public static String BundleClassDialog_create_goto;
+ public static String BundleClassDialog_find;
+ public static String BundleClassDialog_package;
+ public static String BundleClassDialog_uri;
+ public static String BundleConverter_couldNotCreateMetaInfDir;
+ public static String BundleConverter_installLocationNotADirectory;
+ public static String BundleConverter_projectIsAlreadyABundle;
+ public static String FindContributionDialog_findBundle;
+ public static String FindContributionDialog_findClass;
+ public static String FindContributionDialog_findIcon;
+ public static String FindContributionDialog_findPackage;
+ public static String FindContributionDialog_inBundle;
+ public static String FindContributionDialog_inPackage;
+ public static String FindIconDialog_findIcon;
+ public static String FindIconDialog_searchByFilename;
+ public static String IconDialog_bundle;
+ public static String IconDialog_find;
+ public static String IconDialog_folder;
+ public static String IconDialog_icon;
+ public static String IconDialog_selectIcon;
+ public static String IconDialog_selectIcon_MESSAGE;
+ public static String IconDialog_selectIcon_TITLE;
+ public static String IconDialog_uri;
+ public static String IconDialog_uriEditor;
+ public static String NonReferencedResourceDialog__ast_notInABundle_ast;
+ public static String NonReferencedResourceDialog_2;
+ public static String NonReferencedResourceDialog_ast_notInABundle_ast;
+ public static String NonReferencedResourceDialog_bundle;
+ public static String NonReferencedResourceDialog_class;
+ public static String NonReferencedResourceDialog_convertAndRequire;
+ public static String NonReferencedResourceDialog_copyToReferenedProject;
+ public static String NonReferencedResourceDialog_copyToThisProject;
+ public static String NonReferencedResourceDialog_directory;
+ public static String NonReferencedResourceDialog_error;
+ public static String NonReferencedResourceDialog_importPackage;
+ public static String NonReferencedResourceDialog_installLocation;
+ public static String NonReferencedResourceDialog_package;
+ public static String NonReferencedResourceDialog_requireBundle;
+ public static String NonReferencedResourceDialog_resource;
+ public static String NonReferencedResourceDialog_resourceNotReferenced;
+ public static String NonReferencedResourceDialog_resourceReferenceWarning;
+ public static String NonReferencedResourceDialog_selectProjectToReceiveCopy;
+ public static String NonReferencedResourceDialog_selectTheFolderResourceCopy;
+ public static String NonReferencedResourceDialog_url;
+ public static String NonReferencedResourceDialog_useAnyway;
+ public static String ProjectFolderPickerDialog_0;
+ public static String ProjectFolderPickerDialog_6;
+ public static String ProjectFolderPickerDialog_sourceResourceDirectory;
+ public static String ProjectFolderPickerDialog_sourceResourceName;
+ public static String ProjectFolderPickerDialog_useSourceDirectory;
+ public static String ReferencedProjectPickerDialog_selectReferencedProject;
+ public static String TargetPlatformClassContributionCollector_classes;
+ public static String TargetPlatformContributionCollector_pleaseWait;
+ public static String TargetPlatformContributionCollector_updatingTargetPlatformCache;
+ public static String TargetPlatformIconContributionCollector_images;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformClassContributionCollector.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformClassContributionCollector.java
new file mode 100644
index 00000000..eea44f59
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformClassContributionCollector.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator;
+
+import java.util.regex.Pattern;
+
+/**
+ * A contribution collector encompassing the current target platform.<br />
+ * Uses FilterEx for bundle, package, and location filtering
+ *
+ * @author Steven Spungin
+ *
+ */
+public class TargetPlatformClassContributionCollector extends TargetPlatformContributionCollector {
+
+ protected TargetPlatformClassContributionCollector(String cacheName) {
+ super(cacheName);
+ }
+
+ static final private Pattern pattern = Pattern.compile("(.*/)?([^/]+)\\.class"); //$NON-NLS-1$
+ protected static TargetPlatformClassContributionCollector instance;
+
+ static public TargetPlatformClassContributionCollector getInstance() {
+ if (instance == null) {
+ instance = new TargetPlatformClassContributionCollector(Messages.TargetPlatformClassContributionCollector_classes);
+ }
+ return instance;
+ }
+
+ @Override
+ protected boolean shouldIgnore(String name) {
+ return name.contains("$"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected Pattern getFilePattern() {
+ return pattern;
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java
new file mode 100644
index 00000000..1a5addaf
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformContributionCollector.java
@@ -0,0 +1,515 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.e4.tools.emf.ui.common.FilterEx;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
+import org.eclipse.e4.tools.emf.ui.common.IModelElementProvider;
+import org.eclipse.e4.tools.emf.ui.common.ResourceSearchScope;
+import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.FilteredContributionDialog;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.pde.core.plugin.IPluginBase;
+import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.eclipse.pde.internal.core.PDECore;
+import org.eclipse.pde.internal.core.TargetPlatformHelper;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+/**
+ * A contribution collector encompassing the current target platform.<br />
+ * Uses FilterEx for bundle, package, and location filtering.<br />
+ * This implementation finds resources based on file names, not by parsing file
+ * contents.
+ *
+ * @author Steven Spungin
+ *
+ */
+public abstract class TargetPlatformContributionCollector extends ClassContributionCollector {
+
+ ArrayList<Entry> cacheEntry = new ArrayList<Entry>();
+ HashSet<String> cacheBundleId = new HashSet<String>();
+ HashSet<String> cachePackage = new HashSet<String>();
+ HashSet<String> cacheLocation = new HashSet<String>();
+ private Pattern patternFile;
+ protected String cacheName;
+
+ static class Entry {
+ String name;
+ String path;
+ String installLocation;
+ String relativePath;
+ String bundleSymName;
+ String pakage;
+ }
+
+ @SuppressWarnings("unused")
+ private TargetPlatformContributionCollector() {
+ }
+
+ protected TargetPlatformContributionCollector(String cacheName) {
+
+ this.cacheName = cacheName;
+ patternFile = getFilePattern();
+
+ addContributor(new IClassContributionProvider() {
+
+ @Override
+ public void findContribution(Filter filter, ContributionResultHandler handler) {
+
+ Pattern patternName = Pattern.compile(filter.namePattern, Pattern.CASE_INSENSITIVE);
+
+ reloadCache(false);
+
+ int maxResults = filter.maxResults;
+ if (maxResults == 0) {
+ maxResults = 100;
+ }
+
+ int found = 0;
+ boolean more = false;
+ for (Entry e : cacheEntry) {
+ // Check for FilterEx filters
+ if (filter instanceof FilterEx) {
+ FilterEx filterEx = (FilterEx) filter;
+ if (E.notEmpty(filterEx.getBundles())) {
+ if (!filterEx.getBundles().contains(e.bundleSymName)) {
+ continue;
+ }
+ }
+ if (E.notEmpty(filterEx.getPackages())) {
+ if (!filterEx.getPackages().contains(e.pakage)) {
+ continue;
+ }
+ }
+ if (E.notEmpty(filterEx.getLocations())) {
+ boolean locationFound = false;
+ for (String location : filterEx.getLocations()) {
+ if (e.installLocation.startsWith(location)) {
+ locationFound = true;
+ break;
+ }
+ }
+ if (!locationFound) {
+ continue;
+ }
+ }
+ if (filterEx.isIncludeNonBundles() == false) {
+ if (e.bundleSymName == null) {
+ continue;
+ }
+ }
+ if (filterEx.getSearchScope().contains(ResourceSearchScope.WORKSPACE)) {
+ if (filter.project != null) {
+ IWorkspace workspace = filter.project.getWorkspace();
+ boolean fnd = false;
+ for (IProject project : workspace.getRoot().getProjects()) {
+ // String path =
+ // project.getLocationURI().getPath();
+ String path = project.getName();
+ if (e.installLocation.contains(path)) {
+ fnd = true;
+ break;
+ }
+ }
+ if (!fnd) {
+ continue;
+ }
+ }
+ }
+ }
+ Matcher m = patternName.matcher(e.name);
+ if (m.find()) {
+ found++;
+ if (found > maxResults) {
+ more = true;
+ handler.moreResults(-1, filter);
+ break;
+ } else {
+ handler.result(makeData(e));
+ }
+ }
+
+ }
+ if (!more) {
+ handler.moreResults(0, filter);
+ }
+ }
+ });
+
+ addModelElementContributor(new IModelElementProvider() {
+
+ @Override
+ public void getModelElements(Filter filter, ModelResultHandler handler) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void clearCache() {
+ cacheEntry.clear();
+ cacheBundleId.clear();
+ cachePackage.clear();
+ cacheLocation.clear();
+ outputDirectories.clear();
+ }
+ });
+ }
+
+ protected ContributionData makeData(Entry e) {
+ // If class is in a java project, strip the source directory
+ // String path = e.path;// .replace("/", ".") + e.name;
+ // path = stripSourceDirectory(path, e.installLocation);
+ IPath ip = Path.fromOSString(e.path);
+ ip = ip.addTrailingSeparator().makeRelative();
+ ip = ip.append(e.name);
+ String className = ip.toOSString().replace('/', '.');
+ ContributionData data = new ContributionData(e.bundleSymName, className, "Java", e.installLocation); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ data.installLocation = e.installLocation;
+ data.resourceRelativePath = e.relativePath;
+ return data;
+ }
+
+ /**
+ *
+ * @return A copy of the bundle IDs in the cache.
+ */
+ public Collection<String> getBundleIds() {
+ reloadCache(false);
+ return new ArrayList<String>(cacheBundleId);
+ }
+
+ /**
+ *
+ * @return A copy of the bundle IDs in the cache.
+ */
+ public Collection<String> getPackages() {
+ reloadCache(false);
+ return new ArrayList<String>(cachePackage);
+ }
+
+ /**
+ *
+ * @return A copy of the bundle IDs in the cache.
+ */
+ public Collection<String> getLocations() {
+ reloadCache(false);
+ return new ArrayList<String>(cacheLocation);
+ }
+
+ /**
+ * Ensures the cache is loaded. By default it is loaded on first access, and
+ * kept static until forced to reloaded.
+ *
+ * @param force
+ * true to force reload the cache
+ */
+ private void reloadCache(boolean force) {
+ if (cacheEntry.isEmpty() || force) {
+ cacheEntry.clear();
+ cacheBundleId.clear();
+ cachePackage.clear();
+ cacheLocation.clear();
+ outputDirectories.clear();
+
+ ProgressMonitorDialog dlg = new ProgressMonitorDialog(Display.getDefault().getActiveShell()) {
+
+ @Override
+ protected Control createContents(Composite parent) {
+ // TODO odd this is not a bean.
+ Composite ret = (Composite) super.createContents(parent);
+ Label label = new Label(ret, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
+ label.setText(Messages.TargetPlatformContributionCollector_pleaseWait);
+
+ return ret;
+ }
+ };
+ try {
+ dlg.run(true, true, new IRunnableWithProgress() {
+
+ @Override
+ public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+
+ // load workspace projects
+ for (final IProject pj : PDECore.getWorkspace().getRoot().getProjects()) {
+ if (monitor.isCanceled()) {
+ break;
+ }
+ String rootDirectory = pj.getLocation().toOSString();
+ TargetPlatformContributionCollector.this.visit(monitor, FilteredContributionDialog.getBundle(rootDirectory), rootDirectory, new File(rootDirectory));
+ }
+
+ // load target platform bundles
+ IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
+ monitor.beginTask(Messages.TargetPlatformContributionCollector_updatingTargetPlatformCache + cacheName + ")", models.length); //$NON-NLS-2$
+ for (IPluginModelBase pluginModelBase : models) {
+ monitor.subTask(pluginModelBase.getPluginBase().getId());
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ break;
+ }
+
+ IPluginBase pluginBase = pluginModelBase.getPluginBase();
+ if (pluginBase == null) {
+ // bundle = getBundle(new File())
+ continue;
+ }
+ URL url;
+ try {
+ String installLocation = pluginModelBase.getInstallLocation();
+ if (installLocation.endsWith(".jar")) { //$NON-NLS-1$
+ url = new URL("file://" + installLocation); //$NON-NLS-1$
+ ZipInputStream zis = new ZipInputStream(url.openStream());
+ while (true) {
+ ZipEntry entry = zis.getNextEntry();
+ if (entry == null) {
+ break;
+ } else {
+ String name2 = entry.getName();
+ if (shouldIgnore(name2)) {
+ continue;
+ }
+ Matcher m = patternFile.matcher(name2);
+ if (m.matches()) {
+ Entry e = new Entry();
+ e.installLocation = installLocation;
+ cacheLocation.add(installLocation);
+ e.name = m.group(2);
+ e.path = m.group(1);
+ if (e.path != null) {
+ e.pakage = e.path.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$
+ if (e.pakage.startsWith(".")) { //$NON-NLS-1$
+ e.pakage = e.pakage.substring(1);
+ }
+ if (e.pakage.endsWith(".")) { //$NON-NLS-1$
+ e.pakage = e.pakage.substring(0, e.pakage.length() - 1);
+ }
+ } else {
+ e.pakage = ""; //$NON-NLS-1$
+ }
+ cachePackage.add(e.pakage);
+
+ e.bundleSymName = pluginBase.getId();
+ if (e.path == null) {
+ e.path = ""; //$NON-NLS-1$
+ }
+ cacheEntry.add(e);
+ cacheBundleId.add(pluginBase.getId());
+
+ //
+ // System.out.println(group
+ // + " -> "
+ // +
+ // m.group(2));
+ }
+ }
+ }
+ } else {
+ // not a jar file
+ String bundle = getBundle(new File(installLocation));
+ if (bundle != null) {
+ visit(monitor, bundle, installLocation, new File(installLocation));
+ }
+ }
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ monitor.done();
+ }
+ });
+ } catch (InvocationTargetException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ }
+
+ // @Refactor
+ static public String getBundle(File file) {
+ if (file.isDirectory() == false) {
+ return null;
+ }
+
+ File f = new File(file, "META-INF/MANIFEST.MF"); //$NON-NLS-1$
+
+ if (f.exists() && f.isFile()) {
+ BufferedReader r = null;
+ try {
+ InputStream s = new FileInputStream(f);
+ r = new BufferedReader(new InputStreamReader(s));
+ String line;
+ while ((line = r.readLine()) != null) {
+ if (line.startsWith("Bundle-SymbolicName:")) { //$NON-NLS-1$
+ int start = line.indexOf(':');
+ int end = line.indexOf(';');
+ if (end == -1) {
+ end = line.length();
+ }
+ return line.substring(start + 1, end).trim();
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (r != null) {
+ try {
+ r.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ protected void visit(IProgressMonitor monitor, String bundleName, String installLocation, File file) {
+ for (File fChild : file.listFiles()) {
+ if (fChild.isDirectory()) {
+ visit(monitor, bundleName, installLocation, fChild);
+ } else {
+ String name2 = fChild.getAbsolutePath().substring(installLocation.length() + 1);
+ name2 = stripOutputDirectory(name2, installLocation);
+ if (shouldIgnore(name2)) {
+ continue;
+ }
+ Matcher m = patternFile.matcher(name2);
+ if (m.matches()) {
+ Entry e = new Entry();
+ e.installLocation = installLocation;
+ cacheLocation.add(installLocation);
+ e.name = m.group(2);
+ if (e.name.contains("$")) { //$NON-NLS-1$
+ continue;
+ }
+ e.path = m.group(1);
+ if (e.path != null) {
+ e.pakage = e.path.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$
+ if (e.pakage.startsWith(".")) { //$NON-NLS-1$
+ e.pakage = e.pakage.substring(1);
+ }
+ if (e.pakage.endsWith(".")) { //$NON-NLS-1$
+ e.pakage = e.pakage.substring(0, e.pakage.length() - 1);
+ }
+ } else {
+ e.pakage = ""; //$NON-NLS-1$
+ }
+ if (e.path == null) {
+ e.path = ""; //$NON-NLS-1$
+ }
+ e.relativePath = Path.fromOSString(file.getAbsolutePath().replace(e.installLocation, "")).makeRelative().toOSString(); //$NON-NLS-1$
+
+ e.bundleSymName = bundleName;
+ // TODO we need project to strip source paths.
+ // e.pakage = e.pakage.replaceAll("^bin.", "");
+ cachePackage.add(e.pakage);
+ cacheEntry.add(e);
+ if (bundleName != null) {
+ cacheBundleId.add(bundleName);
+ }
+ }
+ }
+ }
+
+ }
+
+ static private String stripOutputDirectory(String path, String installLocation) {
+ if (installLocation.matches(".*\\.jar")) { //$NON-NLS-1$
+ return path;
+ }
+ for (String sourceDirectory : getOutputDirectories(installLocation)) {
+ if (path.startsWith(sourceDirectory)) {
+ path = path.substring(sourceDirectory.length());
+ break;
+ }
+ }
+ return path;
+ }
+
+ /**
+ * A cache of the output directories for install locations (if install
+ * location has a classpath file with appropriate output entries)
+ */
+ static private HashMap<String, List<String>> outputDirectories = new HashMap<String, List<String>>();
+
+ // Returns the Eclipse output directories for an install location. The
+ // directories are relative to the install location.
+ // <classpathentry kind="output" path="bin"/>
+ static private List<String> getOutputDirectories(String installLocation) {
+ List<String> ret = outputDirectories.get(installLocation);
+ if (ret == null) {
+ ret = new ArrayList<String>();
+ outputDirectories.put(installLocation, ret);
+ try {
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(installLocation + File.separator + ".classpath")); //$NON-NLS-1$
+ XPath xp = XPathFactory.newInstance().newXPath();
+ NodeList list = (NodeList) xp.evaluate("//classpathentry[@kind='output']/@path", doc, XPathConstants.NODESET); //$NON-NLS-1$
+ for (int i = 0; i < list.getLength(); i++) {
+ String value = list.item(i).getNodeValue();
+ ret.add(value);
+ }
+ } catch (Exception e) {
+ }
+ }
+ return ret;
+ }
+
+ protected boolean shouldIgnore(String name) {
+ return false;
+ }
+
+ protected abstract Pattern getFilePattern();
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformIconContributionCollector.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformIconContributionCollector.java
new file mode 100644
index 00000000..56eeb909
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/TargetPlatformIconContributionCollector.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator;
+
+import java.util.regex.Pattern;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
+
+/**
+ * A contribution collector encompassing the current target platform.<br />
+ * Uses FilterEx for bundle, package, and location filtering
+ *
+ * @author Steven Spungin
+ *
+ */
+public class TargetPlatformIconContributionCollector extends TargetPlatformContributionCollector {
+
+ protected TargetPlatformIconContributionCollector(String cacheName) {
+ super(cacheName);
+ }
+
+ static final Pattern pattern = Pattern.compile("(.*/)?([^/]+\\.(jpg|jpeg|png|gif))"); //$NON-NLS-1$
+ protected static TargetPlatformIconContributionCollector instance;
+
+ static public TargetPlatformIconContributionCollector getInstance() {
+ if (instance == null) {
+ instance = new TargetPlatformIconContributionCollector(Messages.TargetPlatformIconContributionCollector_images);
+ }
+ return instance;
+ }
+
+ @Override
+ protected Pattern getFilePattern() {
+ return pattern;
+ };
+
+ @Override
+ protected ContributionData makeData(Entry e) {
+ ContributionData data = new ContributionData(e.bundleSymName, null, "Java", e.path + e.name); //$NON-NLS-1$
+ data.installLocation = e.installLocation;
+ data.resourceRelativePath = data.iconPath;
+ return data;
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/BundleClassDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/BundleClassDialog.java
new file mode 100644
index 00000000..27b6dbe4
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/BundleClassDialog.java
@@ -0,0 +1,331 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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: Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
+import org.eclipse.e4.tools.emf.ui.internal.common.ModelEditor;
+import org.eclipse.e4.ui.model.application.ui.basic.MBasicFactory;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * A dialog for creating, editing, replacing, or removing a bundleclass.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class BundleClassDialog extends Dialog implements UriDialog {
+ private Text txtUri;
+ private Text txtBundle;
+ private Text txtClass;
+ private Text txtPackage;
+ public String uri = ""; //$NON-NLS-1$
+ private String bundle = ""; //$NON-NLS-1$
+ private String clazz = ""; //$NON-NLS-1$
+ private String pakage = ""; //$NON-NLS-1$
+ private Composite parent;
+ protected boolean ignoreModify;
+ private IEclipseContext context;
+
+ static Pattern patternBundleClass = Pattern.compile("bundleclass:/*([^/]+)/((.*)\\.)?([^\\.]+)"); //$NON-NLS-1$
+
+ public BundleClassDialog(Shell parentShell, IEclipseContext context) {
+ super(parentShell);
+ this.context = context;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ newShell.setText(Messages.BundleClassDialog_bundleClassEditor);
+ super.configureShell(newShell);
+ }
+
+ @Override
+ protected int getShellStyle() {
+ return super.getShellStyle() | SWT.RESIZE;
+ }
+
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ this.parent = parent;
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setLayout(new GridLayout(2, false));
+
+ ToolBar toolBar = new ToolBar(composite, SWT.NO_FOCUS);
+ toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+
+ {
+ Label lbl = new Label(composite, SWT.NONE);
+ lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ lbl.setText(Messages.BundleClassDialog_uri);
+
+ txtUri = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ txtUri.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txtUri.setText("bundleclass://"); //$NON-NLS-1$
+
+ txtUri.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (ignoreModify) {
+ return;
+ }
+ ignoreModify = true;
+ setUri(txtUri.getText());
+ txtBundle.setText(bundle);
+ txtPackage.setText(pakage);
+ txtClass.setText(clazz);
+ ignoreModify = false;
+ parent.pack();
+ }
+ });
+ }
+
+ // common listener for text boxes
+ ModifyListener listener = new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (ignoreModify) {
+ return;
+ }
+ ignoreModify = true;
+ String prefix;
+ prefix = "bundleclass://"; //$NON-NLS-1$
+ setUri(prefix + txtBundle.getText() + "/" + txtPackage.getText() + "." + txtClass.getText()); //$NON-NLS-1$//$NON-NLS-2$
+ txtUri.setText(getUri());
+ ignoreModify = false;
+ }
+ };
+
+ {
+ Link lbl = new Link(composite, SWT.NONE);
+ lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ lbl.setText("<A>" + Messages.BundleClassDialog_bundle + "</A>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ txtBundle = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ txtBundle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txtBundle.addModifyListener(listener);
+
+ lbl.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IEclipseContext childCtx = context.createChild();
+ childCtx.set(Bundle.class, FrameworkUtil.getBundle(FindContributionDialog.class));
+ childCtx.set("bundle", getBundle()); //$NON-NLS-1$
+ childCtx.set("package", getPackage()); //$NON-NLS-1$
+ childCtx.set("mode", "show-bundles"); //$NON-NLS-1$ //$NON-NLS-2$
+ FindContributionDialog dlg = new FindContributionDialog(childCtx);
+ if (dlg.open() == Dialog.OK) {
+ String uri = getUri(dlg);
+ Matcher matcher = getMatcher(uri);
+ if (matcher.matches()) {
+ txtBundle.setText(matcher.group(1));
+ }
+ }
+ }
+ });
+ }
+
+ {
+ Link lbl = new Link(composite, SWT.NONE);
+ lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ lbl.setText("<A>" + Messages.BundleClassDialog_package + "</A>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ txtPackage = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ txtPackage.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txtPackage.addModifyListener(listener);
+
+ lbl.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IEclipseContext childCtx = context.createChild();
+ childCtx.set(Bundle.class, FrameworkUtil.getBundle(FindContributionDialog.class));
+ childCtx.set("bundle", getBundle()); //$NON-NLS-1$
+ childCtx.set("package", getPackage()); //$NON-NLS-1$
+ childCtx.set("mode", "show-packages"); //$NON-NLS-1$ //$NON-NLS-2$
+ FindContributionDialog dlg = new FindContributionDialog(childCtx);
+ if (dlg.open() == Dialog.OK) {
+ String uri = getUri(dlg);
+ Matcher matcher = getMatcher(uri);
+ if (matcher.matches()) {
+ txtPackage.setText(matcher.group(3));
+ }
+ }
+ }
+ });
+ }
+
+ {
+ Link lbl = new Link(composite, SWT.NONE);
+ lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ lbl.setText("<A>" + Messages.BundleClassDialog_class + "</A>"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+
+ txtClass = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ txtClass.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txtClass.addModifyListener(listener);
+
+ lbl.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IEclipseContext childCtx = context.createChild();
+ childCtx.set(Bundle.class, FrameworkUtil.getBundle(FindContributionDialog.class));
+ childCtx.set("bundle", getBundle()); //$NON-NLS-1$
+ childCtx.set("package", getPackage()); //$NON-NLS-1$
+
+ FindContributionDialog dlg = new FindContributionDialog(childCtx);
+ if (dlg.open() == Window.OK) {
+ txtUri.setText(getUri(dlg));
+ }
+ }
+ });
+ }
+
+ ToolItem btnGo = new ToolItem(toolBar, SWT.PUSH);
+ // btnGo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
+ // false, 2, 1));
+ btnGo.setText(Messages.BundleClassDialog_create_goto);
+ btnGo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ MPart dummyPart = MBasicFactory.INSTANCE.createPart();
+ dummyPart.setContributionURI(getUri());
+ final IContributionClassCreator c = context.get(ModelEditor.class).getContributionCreator(org.eclipse.e4.ui.model.application.ui.basic.impl.BasicPackageImpl.Literals.PART);
+ c.createOpen(dummyPart, context.get(EditingDomain.class), context.get(IProject.class), getShell());
+ setUri(dummyPart.getContributionURI());
+ okPressed();
+ } catch (Exception e2) {
+ // TODO: handle exception
+ }
+ }
+ });
+
+ ToolItem btnFind = new ToolItem(toolBar, SWT.PUSH);
+ // btnFind.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
+ // false, 2, 1));
+ btnFind.setText(Messages.BundleClassDialog_find + "..."); //$NON-NLS-2$ //$NON-NLS-1$
+ btnFind.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IEclipseContext childCtx = context.createChild();
+ childCtx.set(Bundle.class, FrameworkUtil.getBundle(FindContributionDialog.class));
+ FindContributionDialog dialog = new FindContributionDialog(childCtx);
+ if (dialog.open() == Dialog.OK) {
+ txtUri.setText(getUri(dialog));
+ }
+ }
+ });
+
+ ToolItem btnRemove = new ToolItem(toolBar, SWT.PUSH);
+ // btnRemove.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER,
+ // false, false, 2, 1));
+ btnRemove.setText("Remove"); //$NON-NLS-1$
+ btnRemove.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ txtUri.setText(""); //$NON-NLS-1$
+ close();
+ }
+ });
+
+ txtUri.setText(uri);
+ txtBundle.setText(bundle);
+ txtClass.setText(clazz);
+ return composite;
+ }
+
+ protected String getUri(FindContributionDialog dlg) {
+ return dlg.getBundleclassUri();
+ }
+
+ @Override
+ public int open() {
+ int ret = super.open();
+ return ret;
+ }
+
+ @Override
+ public String getUri() {
+ return uri;
+ }
+
+ @Override
+ public void setUri(String uri) {
+ this.uri = uri == null ? "" : uri.toString(); //$NON-NLS-1$
+ Matcher matcher = getMatcher(this.uri);
+ if (matcher.matches()) {
+ bundle = matcher.group(1);
+ pakage = matcher.group(3);
+ if (pakage == null) {
+ pakage = ""; //$NON-NLS-1$
+ }
+ clazz = matcher.group(4);
+ } else {
+ bundle = ""; //$NON-NLS-1$
+ pakage = ""; //$NON-NLS-1$
+ clazz = ""; //$NON-NLS-1$
+ }
+ }
+
+ protected String getBundle() {
+ return bundle;
+ }
+
+ protected void setBundle(String bundle) {
+ this.bundle = bundle;
+ }
+
+ protected String getClazz() {
+ return clazz;
+ }
+
+ protected void setClazz(String clazz) {
+ this.clazz = clazz;
+ }
+
+ protected String getPackage() {
+ return pakage;
+ }
+
+ protected void setPackage(String pakage) {
+ this.pakage = pakage;
+ }
+
+ private Matcher getMatcher(String uri) {
+ return patternBundleClass.matcher(uri);
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/FindContributionDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/FindContributionDialog.java
new file mode 100644
index 00000000..7a42234e
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/FindContributionDialog.java
@@ -0,0 +1,424 @@
+/*******************************************************************************
+ * Copyright (c) 2010 BestSolution.at 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:
+ * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Lars Vogel <lars.vogel@gmail.com> - Enhancements
+ * Steven Spungin <steven@spungin.tv> - Modified to be generic picker, Bug 424730
+ ******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+import java.util.Iterator;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionResultHandler;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.Filter;
+import org.eclipse.e4.tools.emf.ui.internal.Messages;
+import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A find dialog for model contributions. List can be filtered by bundle and/or
+ * package
+ *
+ * @author Steven Spungin
+ *
+ */
+public class FindContributionDialog extends TitleAreaDialog {
+ private IProject project;
+ private Image javaClassImage;
+ private TableViewer viewer;
+ private Messages Messages;
+ private String bundleclassUri;
+ @SuppressWarnings("unused")
+ private IEclipseContext context;
+ private String packageFilter;
+ private String bundleFilter;
+ private Bundle bundle;
+ private String mode;
+ private Image titleImage;
+ private String platformUri;
+
+ public FindContributionDialog(IEclipseContext context) {
+ super(context.get(Shell.class));
+ this.context = context;
+ this.project = context.get(IProject.class);
+ this.Messages = context.get(Messages.class);
+ packageFilter = (String) context.get("package"); //$NON-NLS-1$
+ bundleFilter = (String) context.get("bundle"); //$NON-NLS-1$
+ bundle = context.get(Bundle.class);
+ mode = (String) context.get("mode"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite comp = (Composite) super.createDialogArea(parent);
+
+ // TODO param
+ getShell().setText(Messages.ContributionClassDialog_ShellTitle);
+
+ if ("show-bundles".equals(mode)) { //$NON-NLS-1$
+ // TODO create icon
+ } else if ("show-packages".equals(mode)) { //$NON-NLS-1$
+ // TODO create icon
+ } else if ("show-icons".equals(mode)) { //$NON-NLS-1$
+ // TODO create icon
+ } else {
+ titleImage = new Image(comp.getDisplay(), getClass().getClassLoader().getResourceAsStream("/icons/full/wizban/newclass_wiz.png")); //$NON-NLS-1$
+ setTitleImage(titleImage);
+ }
+
+ getShell().addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ javaClassImage.dispose();
+ if (titleImage != null) {
+ titleImage.dispose();
+ }
+ }
+ });
+
+ javaClassImage = new Image(getShell().getDisplay(), getClass().getClassLoader().getResourceAsStream("/icons/full/obj16/class_obj.gif")); //$NON-NLS-1$
+
+ Composite container = new Composite(comp, SWT.NONE);
+ container.setLayoutData(new GridData(GridData.FILL_BOTH));
+ container.setLayout(new GridLayout(2, false));
+
+ Label l = new Label(container, SWT.NONE);
+ // TODO param
+ l.setText(Messages.ContributionClassDialog_Label_Classname);
+
+ final Text t = new Text(container, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH);
+ t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // TODO param
+ t.setMessage(Messages.ContributionClassDialog_FilterText_Message);
+
+ new Label(container, SWT.NONE);
+
+ viewer = new TableViewer(container, SWT.FULL_SELECTION);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ viewer.getControl().setLayoutData(gd);
+ viewer.setContentProvider(new ObservableListContentProvider());
+ viewer.setLabelProvider(new StyledCellLabelProvider() {
+ @Override
+ public void update(ViewerCell cell) {
+ ContributionData data = (ContributionData) cell.getElement();
+ StyledString styledString = new StyledString();
+ if ("show-bundles".equals(mode)) { //$NON-NLS-1$
+ styledString.append(data.bundleName, StyledString.DECORATIONS_STYLER);
+ } else if ("show-packages".equals(mode)) { //$NON-NLS-1$
+ int dot = data.className.lastIndexOf("."); //$NON-NLS-1$
+ String packageName;
+ if (dot >= 0) {
+ packageName = data.className.substring(0, dot);
+ } else {
+ packageName = ""; //$NON-NLS-1$
+ }
+ styledString.append(packageName, StyledString.DECORATIONS_STYLER);
+ } else if ("show-icons".equals(mode)) { //$NON-NLS-1$
+ styledString.append(data.iconPath, null);
+
+ if (data.bundleName != null) {
+ styledString.append(" - " + data.bundleName, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ }
+
+ if (data.sourceType != null) {
+ styledString.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ styledString.append(data.sourceType + "", StyledString.COUNTER_STYLER); //$NON-NLS-1$
+ }
+
+ if (data.iconPath == null) {
+ cell.setImage(javaClassImage);
+ }
+ } else {
+ styledString.append(data.className, null);
+
+ if (data.bundleName != null) {
+ styledString.append(" - " + data.bundleName, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ }
+
+ if (data.sourceType != null) {
+ styledString.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
+ styledString.append(data.sourceType + "", StyledString.COUNTER_STYLER); //$NON-NLS-1$
+ }
+
+ if (data.iconPath == null) {
+ cell.setImage(javaClassImage);
+ }
+ }
+
+ cell.setText(styledString.getString());
+ cell.setStyleRanges(styledString.getStyleRanges());
+ }
+ });
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ okPressed();
+ }
+ });
+
+ final WritableList list = new WritableList();
+ viewer.setInput(list);
+
+ final ClassContributionCollector collector = getCollector();
+
+ t.addModifyListener(new ModifyListener() {
+ private ContributionResultHandlerImpl currentResultHandler;
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (currentResultHandler != null) {
+ currentResultHandler.cancled = true;
+ }
+ list.clear();
+ currentResultHandler = new ContributionResultHandlerImpl(list);
+ Filter filter = new Filter(project, t.getText());
+ collector.findContributions(filter, currentResultHandler);
+ t.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode == SWT.ARROW_DOWN) {
+ if (viewer.getTable().getItemCount() > 0) {
+ viewer.getTable().setFocus();
+ viewer.getTable().select(0);
+ }
+ }
+ }
+ });
+ viewer.getTable().addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ super.keyPressed(e);
+ if ((e.keyCode == SWT.ARROW_UP) && (viewer.getTable().getSelectionIndex() == 0)) {
+ t.setFocus();
+ }
+ }
+ });
+ }
+ });
+
+ viewer.setFilters(new ViewerFilter[] { new ViewerFilter() {
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ ContributionData cd = (ContributionData) element;
+ if ("show-bundles".equals(mode)) { //$NON-NLS-1$
+ // only add first item from each bundle
+ boolean found = false;
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ ContributionData cd2 = (ContributionData) it.next();
+ if (cd2.bundleName == null || cd2.bundleName.equals(cd.bundleName)) {
+ if (found == false) {
+ found = true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return true;
+ } else if ("show-packages".equals(mode)) { //$NON-NLS-1$
+ if (bundleFilter != null && bundleFilter.isEmpty() == false) {
+ if (!bundleFilter.equals(cd.bundleName)) {
+ return false;
+ }
+ }
+ String packageName;
+ int last = cd.className.lastIndexOf("."); //$NON-NLS-1$
+ if (last >= 0) {
+ packageName = cd.className.substring(0, last);
+ } else {
+ packageName = ""; //$NON-NLS-1$
+ }
+ // only add first item from each package
+ boolean found = false;
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ boolean matches = false;
+ ContributionData cd2 = (ContributionData) it.next();
+ if (packageName.isEmpty() && cd2.className.contains(".") == false) { //$NON-NLS-1$
+ matches = true;
+ } else if (cd2.className.startsWith(packageName + ".")) { //$NON-NLS-1$
+ matches = true;
+ }
+ if (matches) {
+ if (found == false) {
+ found = true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return true;
+ } else if ("show-icons".equals(mode)) { //$NON-NLS-1$
+ if (cd.iconPath == null) {
+ return false;
+ }
+ if (bundleFilter != null && bundleFilter.isEmpty() == false) {
+ if (!bundleFilter.equals(cd.bundleName)) {
+ return false;
+ }
+ }
+ if (packageFilter != null && packageFilter.isEmpty() == false) {
+ if (!cd.className.startsWith(packageFilter + ".")) { //$NON-NLS-1$
+ return false;
+ }
+ }
+ return true;
+ } else {
+ if (bundleFilter != null && bundleFilter.isEmpty() == false) {
+ if (!bundleFilter.equals(cd.bundleName)) {
+ return false;
+ }
+ }
+ if (packageFilter != null && packageFilter.isEmpty() == false) {
+ if (!cd.className.startsWith(packageFilter + ".")) { //$NON-NLS-1$
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+ } });
+
+ StringBuilder sbFind = new StringBuilder();
+
+ if ("show-bundles".equals(mode)) { //$NON-NLS-1$
+ setTitle(org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findBundle);
+ sbFind.append(org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findBundle);
+ } else if ("show-packages".equals(mode)) { //$NON-NLS-1$
+ setTitle(org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findPackage);
+ sbFind.append(org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findPackage);
+ if (E.notEmpty(bundleFilter)) {
+ sbFind.append(" " + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inBundle + " " + bundleFilter); //$NON-NLS-1$ //$NON-NLS-3$
+ }
+ } else if ("show-icons".equals(mode)) { //$NON-NLS-1$
+ setTitle(org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findIcon);
+ sbFind.append(org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findIcon);
+ if (E.notEmpty(bundleFilter)) {
+ sbFind.append(" " + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inBundle + " " + bundleFilter); //$NON-NLS-1$ //$NON-NLS-3$
+ }
+ if (E.notEmpty(packageFilter)) {
+ sbFind.append(" " + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inPackage + " " + packageFilter); //$NON-NLS-1$ //$NON-NLS-3$
+ }
+ } else {
+ setTitle(org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findClass);
+ sbFind.append(org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findClass);
+ if (E.notEmpty(bundleFilter)) {
+ sbFind.append(" " + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inBundle + " " + bundleFilter); //$NON-NLS-1$ //$NON-NLS-3$
+ }
+ if (E.notEmpty(packageFilter)) {
+ sbFind.append(" " + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inPackage + " " + packageFilter); //$NON-NLS-1$ //$NON-NLS-3$
+ }
+ }
+ setMessage(sbFind.toString());
+
+ // preload list if few items
+ if (list.size() <= 30) {
+ t.notifyListeners(SWT.Modify, null);
+ }
+ return comp;
+ }
+
+ @Override
+ protected void okPressed() {
+ IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
+ if (!s.isEmpty()) {
+ ContributionData cd = (ContributionData) s.getFirstElement();
+ String uri = "bundleclass://" + cd.bundleName + "/" + cd.className; //$NON-NLS-1$ //$NON-NLS-2$
+ platformUri = "platform:/plugin/" + cd.bundleName + "/" + cd.className; //$NON-NLS-1$ //$NON-NLS-2$
+ setBundleclassUri(uri);
+ super.okPressed();
+ } else {
+ super.cancelPressed();
+ }
+ }
+
+ private ClassContributionCollector getCollector() {
+ if (bundle == null) {
+ return null;
+ }
+ BundleContext context = bundle.getBundleContext();
+ ServiceReference ref = context.getServiceReference(ClassContributionCollector.class.getName());
+ if (ref != null) {
+ return (ClassContributionCollector) context.getService(ref);
+ }
+ return null;
+ }
+
+ public String getBundleclassUri() {
+ return bundleclassUri;
+ }
+
+ public String getPlatformUri() {
+ return platformUri;
+ }
+
+ public void setBundleclassUri(String bundleclass) {
+ this.bundleclassUri = bundleclass;
+ }
+
+ private static class ContributionResultHandlerImpl implements ContributionResultHandler {
+ private boolean cancled = false;
+ private IObservableList list;
+
+ public ContributionResultHandlerImpl(IObservableList list) {
+ this.list = list;
+ }
+
+ @Override
+ public void result(ContributionData data) {
+ if (!cancled) {
+ list.add(data);
+ }
+ }
+
+ @Override
+ public void moreResults(int hint, Filter filter) {
+ }
+
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/FindIconDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/FindIconDialog.java
new file mode 100644
index 00000000..d4716fa3
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/FindIconDialog.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.AbstractIconDialogWithScopeAndFilter;
+import org.eclipse.swt.widgets.Shell;
+
+final class FindIconDialog extends AbstractIconDialogWithScopeAndFilter {
+ FindIconDialog(Shell parentShell, IEclipseContext context) {
+ super(parentShell, context);
+ }
+
+ @Override
+ protected String getShellTitle() {
+ return Messages.FindIconDialog_findIcon;
+ }
+
+ @Override
+ protected String getDialogTitle() {
+ return Messages.FindIconDialog_findIcon;
+ }
+
+ @Override
+ protected String getDialogMessage() {
+ return Messages.FindIconDialog_searchByFilename;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/IconDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/IconDialog.java
new file mode 100644
index 00000000..312364bc
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/IconDialog.java
@@ -0,0 +1,307 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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: Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.AbstractIconDialogWithHardcodedScope;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.AbstractIconDialogWithScopeAndFilter;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * A dialog for creating, editing, replacing, or removing a bundleclass.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class IconDialog extends Dialog implements UriDialog {
+ private Text txtUri;
+ private Text txtBundle;
+ private Text txtIcon;
+ private Text txtPath;
+ public String uri = ""; //$NON-NLS-1$
+ private String bundle = ""; //$NON-NLS-1$
+ private String icon = ""; //$NON-NLS-1$
+ private String path = ""; //$NON-NLS-1$
+ protected boolean ignoreModify;
+ private IEclipseContext context;
+
+ static Pattern patternIcon = Pattern.compile("platform:/plugin/*([^/]+)/((.*)/)?([^/]+)"); //$NON-NLS-1$
+
+ public IconDialog(Shell parentShell, IEclipseContext context) {
+ super(parentShell);
+ this.context = context;
+ }
+
+ @Override
+ protected int getShellStyle() {
+ return super.getShellStyle() | SWT.RESIZE;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ newShell.setText(Messages.IconDialog_uriEditor);
+ super.configureShell(newShell);
+ }
+
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setLayout(new GridLayout(2, false));
+
+ ToolBar toolBar = new ToolBar(composite, SWT.NO_FOCUS);
+ toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+
+ {
+ Label lbl = new Label(composite, SWT.NONE);
+ lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ lbl.setText(Messages.IconDialog_uri);
+
+ txtUri = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ txtUri.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txtUri.setText("platform://plugin/"); //$NON-NLS-1$
+
+ txtUri.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (ignoreModify) {
+ return;
+ }
+ ignoreModify = true;
+ setUri(txtUri.getText());
+ txtBundle.setText(bundle);
+ txtPath.setText(path);
+ txtIcon.setText(icon);
+ ignoreModify = false;
+ parent.pack();
+ }
+ });
+ }
+
+ // common listener for text boxes
+ ModifyListener listener = new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (ignoreModify) {
+ return;
+ }
+ ignoreModify = true;
+ String prefix;
+
+ prefix = "platform:/plugin/"; //$NON-NLS-1$
+ setUri(prefix + txtBundle.getText() + "/" + txtPath.getText() + "/" + txtIcon.getText()); //$NON-NLS-1$//$NON-NLS-2$
+
+ txtUri.setText(getUri());
+ ignoreModify = false;
+ }
+ };
+
+ {
+ Link lbl = new Link(composite, SWT.NONE);
+ lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ lbl.setText("<A>" + Messages.IconDialog_bundle + "</A>"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ txtBundle = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ txtBundle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txtBundle.addModifyListener(listener);
+
+ lbl.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IEclipseContext childCtx = context.createChild();
+ childCtx.set(Bundle.class, FrameworkUtil.getBundle(FindContributionDialog.class));
+ childCtx.set("bundle", getBundle()); //$NON-NLS-1$
+ childCtx.set("package", getPath()); //$NON-NLS-1$
+ childCtx.set("mode", "show-bundles"); //$NON-NLS-1$ //$NON-NLS-2$
+ FindContributionDialog dlg = new FindContributionDialog(childCtx);
+ if (dlg.open() == Dialog.OK) {
+ String uri = getUri(dlg);
+ Matcher matcher = getMatcher(uri);
+ if (matcher.matches()) {
+ txtBundle.setText(matcher.group(1));
+ }
+ }
+ }
+ });
+ }
+
+ {
+ Link lbl = new Link(composite, SWT.NONE);
+ lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ lbl.setText("path"); //$NON-NLS-1$
+
+ txtPath = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ txtPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txtPath.addModifyListener(listener);
+ }
+
+ {
+ Link lbl = new Link(composite, SWT.NONE);
+ lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ lbl.setText("<A>" + Messages.IconDialog_icon + "</A>"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ txtIcon = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ txtIcon.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txtIcon.addModifyListener(listener);
+
+ lbl.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IEclipseContext childCtx = context.createChild();
+ childCtx.set(Bundle.class, FrameworkUtil.getBundle(FindContributionDialog.class));
+ childCtx.set(Messages.IconDialog_bundle, getBundle());
+ childCtx.set(Messages.IconDialog_folder, getPath());
+ AbstractIconDialogWithHardcodedScope dlg = new AbstractIconDialogWithHardcodedScope(getParentShell(), childCtx) {
+
+ @Override
+ protected String getShellTitle() {
+ return org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.IconDialog_selectIcon;
+ }
+
+ @Override
+ protected String getDialogTitle() {
+ return org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.IconDialog_selectIcon_TITLE;
+ }
+
+ @Override
+ protected String getDialogMessage() {
+ return org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.IconDialog_selectIcon_MESSAGE;
+ }
+ };
+ if (dlg.open() == Dialog.OK) {
+ txtUri.setText(dlg.getValue());
+ }
+ }
+ });
+ }
+
+ ToolItem btnFind = new ToolItem(toolBar, SWT.PUSH);
+ // btnFind.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
+ // false, 2, 1));
+ btnFind.setText(Messages.IconDialog_find + "..."); //$NON-NLS-1$
+ btnFind.setImage(new Image(getShell().getDisplay(), getClass().getResourceAsStream("/icons/full/obj16/find.png"))); //$NON-NLS-1$
+ btnFind.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IEclipseContext childCtx = context.createChild();
+ AbstractIconDialogWithScopeAndFilter dlg = new FindIconDialog(getParentShell(), childCtx);
+ if (dlg.open() == Dialog.OK) {
+ txtUri.setText(dlg.getValue());
+ // getContents().pack(true);
+ getShell().pack();
+ }
+ }
+ });
+
+ ToolItem btnRemove = new ToolItem(toolBar, SWT.PUSH);
+ // btnRemove.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER,
+ // false, false, 2, 1));
+ btnRemove.setText("Remove"); //$NON-NLS-1$
+ btnRemove.setImage(new Image(getShell().getDisplay(), getClass().getResourceAsStream("/icons/full/obj16/remove_filter.png"))); //$NON-NLS-1$
+ btnRemove.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ txtUri.setText(""); //$NON-NLS-1$
+ close();
+ }
+ });
+
+ txtUri.setText(uri);
+ txtBundle.setText(bundle);
+ txtIcon.setText(icon);
+ return composite;
+ }
+
+ protected String getUri(FindContributionDialog dlg) {
+ return dlg.getPlatformUri();
+ }
+
+ @Override
+ public int open() {
+ int ret = super.open();
+ return ret;
+ }
+
+ @Override
+ public String getUri() {
+ return uri;
+ }
+
+ @Override
+ public void setUri(String uri) {
+ this.uri = uri == null ? "" : uri.toString(); //$NON-NLS-1$
+ Matcher matcher = getMatcher(this.uri);
+ if (matcher.matches()) {
+ bundle = matcher.group(1);
+ path = matcher.group(3);
+ if (path == null) {
+ path = ""; //$NON-NLS-1$
+ }
+ icon = matcher.group(4);
+ } else {
+ bundle = ""; //$NON-NLS-1$
+ path = ""; //$NON-NLS-1$
+ icon = ""; //$NON-NLS-1$
+ }
+ }
+
+ protected String getBundle() {
+ return bundle;
+ }
+
+ protected void setBundle(String bundle) {
+ this.bundle = bundle;
+ }
+
+ protected String getIcon() {
+ return icon;
+ }
+
+ protected void setIcon(String icon) {
+ this.icon = icon;
+ }
+
+ protected String getPath() {
+ return path;
+ }
+
+ protected void setPath(String pakage) {
+ this.path = pakage;
+ }
+
+ private Matcher getMatcher(String uri) {
+ Matcher matcher;
+ matcher = patternIcon.matcher(uri);
+ return matcher;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedResourceDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedResourceDialog.java
new file mode 100644
index 00000000..49d7837b
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedResourceDialog.java
@@ -0,0 +1,512 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipFile;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData;
+import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.BundleImageCache;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.ContributionDataFile;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.FilteredContributionDialog;
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.BundleConverter;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.pde.internal.core.util.CoreUtility;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+public class NonReferencedResourceDialog extends TitleAreaDialog {
+ private String bundle;
+ private final IFile file;
+ private IFile result;
+ private IProject project;
+ private String className;
+ private String installLocation;
+ protected Runnable okAction;
+ private BundleImageCache imageCache;
+ private IEclipseContext context;
+
+ public NonReferencedResourceDialog(Shell parentShell, IProject project, String bundle, IFile file, String installLocation, IEclipseContext context) {
+ super(parentShell);
+ this.project = project;
+ this.bundle = bundle;
+ this.file = file;
+ this.installLocation = installLocation;
+ this.context = context;
+
+ if (bundle == null && installLocation != null) {
+ this.bundle = FilteredContributionDialog.getBundle(installLocation);
+ }
+ if (file instanceof ContributionDataFile) {
+ ContributionDataFile cdf = (ContributionDataFile) file;
+ this.className = cdf.getContributionData().className;
+ }
+ }
+
+ @Override
+ protected void okPressed() {
+ if (okAction != null) {
+ try {
+ okAction.run();
+ super.okPressed();
+ } catch (Exception e) {
+ }
+ } else {
+ super.okPressed();
+ }
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite comp = (Composite) super.createDialogArea(parent);
+
+ Composite compInfo = new Composite(comp, SWT.NONE);
+ compInfo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ compInfo.setLayout(new GridLayout(2, false));
+
+ String message = ""; //$NON-NLS-1$
+ Button defaultButton = null;
+
+ if (installLocation != null) {
+ Label label = new Label(compInfo, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label.setText(Messages.NonReferencedResourceDialog_installLocation);
+
+ Label label2 = new Label(compInfo, SWT.NONE);
+ label2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label2.setText(installLocation);
+ }
+
+ if (className != null) {
+ ContributionData cd = ((ContributionDataFile) file).getContributionData();
+ Label label = new Label(compInfo, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label.setText(Messages.NonReferencedResourceDialog_2);
+
+ Label label2 = new Label(compInfo, SWT.NONE);
+ label2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ if (bundle != null) {
+ label2.setText(bundle);
+ } else {
+ label2.setText(Messages.NonReferencedResourceDialog__ast_notInABundle_ast);
+ }
+
+ Label label3 = new Label(compInfo, SWT.NONE);
+ label3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label3.setText(Messages.NonReferencedResourceDialog_package);
+
+ Label label4 = new Label(compInfo, SWT.NONE);
+ label4.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label4.setText(getPackageFromClassName(className));
+
+ Label label5 = new Label(compInfo, SWT.NONE);
+ label5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label5.setText(Messages.NonReferencedResourceDialog_class);
+
+ Label label6 = new Label(compInfo, SWT.NONE);
+ label6.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label6.setText(cd.className.substring(cd.className.lastIndexOf('.') + 1));
+
+ if (bundle != null) {
+ Label label7 = new Label(compInfo, SWT.NONE);
+ label7.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label7.setText(Messages.NonReferencedResourceDialog_url);
+
+ Label label8 = new Label(compInfo, SWT.NONE);
+ label8.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label8.setText("bundleclass://" + bundle + "/" + className); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } else {
+ Label label = new Label(compInfo, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label.setText(Messages.NonReferencedResourceDialog_bundle);
+
+ Label label2 = new Label(compInfo, SWT.NONE);
+ label2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ if (bundle != null) {
+ label2.setText(bundle);
+ } else {
+ label2.setText(Messages.NonReferencedResourceDialog_ast_notInABundle_ast);
+ }
+
+ Label label7 = new Label(compInfo, SWT.NONE);
+ label7.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label7.setText(Messages.NonReferencedResourceDialog_directory);
+
+ Label label8 = new Label(compInfo, SWT.NONE);
+ label8.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label8.setText(file.getFullPath().removeFirstSegments(1).removeLastSegments(1).toOSString());
+
+ Label label3 = new Label(compInfo, SWT.NONE);
+ label3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label3.setText(Messages.NonReferencedResourceDialog_resource);
+
+ Label label4 = new Label(compInfo, SWT.NONE);
+ label4.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label4.setText(file.getFullPath().lastSegment());
+
+ if (bundle != null) {
+ Label label5 = new Label(compInfo, SWT.NONE);
+ label5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ label5.setText(Messages.NonReferencedResourceDialog_url);
+
+ Label label6 = new Label(compInfo, SWT.NONE);
+ label6.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label6.setText("platform:/plugin/" + bundle + "/" + file.getFullPath().removeFirstSegments(1).toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ Label lblMessage = new Label(comp, SWT.NONE);
+ lblMessage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ lblMessage.setText(message);
+
+ if (bundle != null) {
+ final Button btnRequire = new Button(comp, SWT.RADIO);
+ btnRequire.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+ btnRequire.setText(Messages.NonReferencedResourceDialog_requireBundle);
+ btnRequire.setImage(imageCache.loadFromKey(ResourceProvider.IMG_Obj16_bundle));
+ btnRequire.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnRequire.getSelection()) {
+ okAction = new Runnable() {
+
+ @Override
+ public void run() {
+ doRequireBundle(bundle, installLocation);
+ }
+ };
+ }
+ }
+ });
+ defaultButton = btnRequire;
+ }
+
+ // make sure className is not in the default package (contains '.')
+ if (className != null && bundle != null && className.contains(".")) { //$NON-NLS-1$
+ final Button btnImport = new Button(comp, SWT.RADIO);
+ btnImport.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+ btnImport.setText(Messages.NonReferencedResourceDialog_importPackage);
+ btnImport.setImage(imageCache.create("/icons/full/obj16/package_obj.gif")); //$NON-NLS-1$
+ btnImport.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnImport.getSelection()) {
+ okAction = new Runnable() {
+ @Override
+ public void run() {
+ IFile fileManifest = project.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
+ Manifest manifest;
+ try {
+ manifest = new Manifest(fileManifest.getContents());
+ String value = manifest.getMainAttributes().getValue("Import-Package"); //$NON-NLS-1$
+
+ String packageName = getPackageFromClassName(className);
+ // TODO ensure the packageName is not
+ // already in the manifest (although it
+ // should not be if we are here)
+ if (value == null) {
+ value = packageName;
+ } else {
+ value += "," + packageName; //$NON-NLS-1$
+ }
+ manifest.getMainAttributes().putValue("Import-Package", value); //$NON-NLS-1$
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ manifest.write(bos);
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ fileManifest.setContents(bis, true, true, null);
+ result = file;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ }
+ }
+ });
+ }
+
+ if (bundle != null) {
+ final Button btnUseAnyway = new Button(comp, SWT.RADIO);
+ btnUseAnyway.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+ btnUseAnyway.setText(Messages.NonReferencedResourceDialog_useAnyway);
+ btnUseAnyway.setImage(imageCache.create("/icons/full/obj16/use_anyway.gif")); //$NON-NLS-1$
+ btnUseAnyway.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnUseAnyway.getSelection()) {
+ result = file;
+ okAction = null;
+ }
+ }
+ });
+
+ } else {
+ if (file instanceof ContributionDataFile) {
+ final ContributionDataFile cdf = (ContributionDataFile) file;
+ final Button btnConvertToBundle = new Button(comp, SWT.RADIO);
+ btnConvertToBundle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+ btnConvertToBundle.setText(Messages.NonReferencedResourceDialog_convertAndRequire);
+ btnConvertToBundle.setImage(imageCache.create("/icons/full/obj16/bundle.png")); //$NON-NLS-1$
+ btnConvertToBundle.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnConvertToBundle.getSelection()) {
+ okAction = new Runnable() {
+
+ @Override
+ public void run() {
+ String bundleId;
+ try {
+ ContributionData contributionData = cdf.getContributionData();
+ bundleId = BundleConverter.convertProjectToBundle(contributionData.installLocation, project.getWorkspace());
+ if (bundleId != null) {
+
+ ContributionData cdConverted = new ContributionData(bundleId, contributionData.className, contributionData.sourceType, contributionData.iconPath);
+ cdConverted.installLocation = installLocation;
+ cdConverted.resourceRelativePath = Path.fromOSString(contributionData.iconPath).removeFirstSegments(1).toOSString();
+ doRequireBundle(bundleId, installLocation);
+ result = new ContributionDataFile(cdConverted);
+ }
+ } catch (Exception e1) {
+ MessageDialog.openError(getShell(), Messages.NonReferencedResourceDialog_error, e1.getMessage());
+ }
+ }
+ };
+ }
+ }
+ });
+ }
+ }
+
+ if (className == null) {
+ final Button btnCopy = new Button(comp, SWT.RADIO);
+ defaultButton = btnCopy;
+ btnCopy.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+ btnCopy.setText(Messages.NonReferencedResourceDialog_copyToThisProject);
+ btnCopy.setImage(imageCache.create("/icons/full/obj16/copy_to_project.png")); //$NON-NLS-1$
+ btnCopy.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnCopy.getSelection()) {
+ okAction = new Runnable() {
+
+ @Override
+ public void run() {
+ copyResourceToProject(project);
+ }
+ };
+ }
+ }
+ });
+ }
+
+ if (className == null) {
+ final Button btnCopy2 = new Button(comp, SWT.RADIO);
+ btnCopy2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+ btnCopy2.setText(Messages.NonReferencedResourceDialog_copyToReferenedProject);
+ btnCopy2.setImage(imageCache.create("/icons/full/obj16/copy_to_project.png")); //$NON-NLS-1$
+ btnCopy2.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (btnCopy2.getSelection()) {
+ okAction = new Runnable() {
+
+ @Override
+ public void run() {
+ ReferencedProjectPickerDialog dlg = new ReferencedProjectPickerDialog(getShell(), project) {
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ setMessage(Messages.NonReferencedResourceDialog_selectProjectToReceiveCopy);
+ setTitleImage(imageCache.create("/icons/full/wizban/plugin_wiz.gif")); //$NON-NLS-1$
+
+ return ret;
+ }
+ };
+ if (dlg.open() == IDialogConstants.OK_ID) {
+ copyResourceToProject((IProject) dlg.getFirstElement());
+ }
+ }
+ };
+ }
+ }
+ });
+ }
+
+ if (defaultButton != null) {
+ defaultButton.setSelection(true);
+ defaultButton.notifyListeners(SWT.Selection, new Event());
+ }
+ return comp;
+ }
+
+ // @Refactor
+ static public String getPackageFromClassName(String className) {
+ int index = className.lastIndexOf('.');
+ if (index >= 0) {
+ return className.substring(0, index);
+ } else {
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ imageCache = new BundleImageCache(parent.getDisplay(), getClass().getClassLoader(), context);
+ getShell().addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ imageCache.dispose();
+ }
+ });
+
+ Control ret = super.createContents(parent);
+ setMessage(Messages.NonReferencedResourceDialog_resourceNotReferenced);
+ String message = getMessage();
+ setMessage(message);
+ setTitle(Messages.NonReferencedResourceDialog_resourceReferenceWarning);
+ getShell().setText(Messages.NonReferencedResourceDialog_resourceReferenceWarning);
+ try {
+ setTitleImage(imageCache.create("org.eclipse.e4.tools.emf.ui", "/icons/full/wizban/newefix_wizban.png")); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return ret;
+ }
+
+ public IFile getResult() {
+ return result;
+ }
+
+ public void copyResourceToProject(IProject project) {
+ try {
+ ProjectFolderPickerDialog dlg = new ProjectFolderPickerDialog(getShell(), project, file.getFullPath().toOSString()) {
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ setMessage(Messages.NonReferencedResourceDialog_selectTheFolderResourceCopy);
+ setTitleImage(imageCache.create("org.eclipse.e4.tools.emf.ui", "/icons/full/wizban/add_to_dir_wiz.png")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ return ret;
+ }
+ };
+
+ if (dlg.open() == IDialogConstants.OK_ID) {
+ // String filename = ((ContributionDataFile)
+ // file).getContributionData().className + ".class";
+ IPath newPath = Path.fromOSString(dlg.getValue());
+ if (newPath.isEmpty() == false) {
+ CoreUtility.createFolder(project.getFolder(newPath));
+ }
+ if (className != null) {
+ newPath.append(className + ".class"); //$NON-NLS-1$
+ } else {
+ String name = file.getFullPath().lastSegment();
+ newPath = newPath.append(name);
+ }
+ IFile fileClone = project.getFile(newPath);
+ fileClone.create(file.getContents(), false, null);
+ result = fileClone;
+ }
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ MessageDialog.openError(getShell(), "Error", e1.getMessage()); //$NON-NLS-1$
+
+ }
+ }
+
+ public void doRequireBundle(String bundle, String installLocation) {
+
+ // Get source bundle version from manifest
+ String version = null;
+ InputStream srcStream = null;
+ try {
+ Manifest manifestSource;
+ if (installLocation.endsWith(".jar")) { //$NON-NLS-1$
+ ZipFile zip = new ZipFile(installLocation);
+ srcStream = zip.getInputStream(zip.getEntry("META-INF/MANIFEST.MF")); //$NON-NLS-1$
+ manifestSource = new Manifest(srcStream);
+ zip.close();
+ } else {
+ srcStream = new BufferedInputStream(new FileInputStream(installLocation + "/META-INF/MANIFEST.MF")); //$NON-NLS-1$
+ manifestSource = new Manifest(srcStream);
+ }
+ version = manifestSource.getMainAttributes().getValue("Bundle-Version"); //$NON-NLS-1$
+ if (version != null) {
+ version = version.replaceFirst("\\.qualifier", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return;
+ } finally {
+ try {
+ srcStream.close();
+ } catch (Exception e) {
+ }
+ }
+
+ IFile fileManifest = project.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
+ Manifest manifest;
+ try {
+ manifest = new Manifest(fileManifest.getContents());
+ String value = manifest.getMainAttributes().getValue("Require-Bundle"); //$NON-NLS-1$
+ if (value == null) {
+ manifest.getMainAttributes().putValue("Require-Bundle", bundle); //$NON-NLS-1$
+ } else {
+ value += "," + bundle; //$NON-NLS-1$
+ if (version != null) {
+ value += ";bundle-version=" + version; //$NON-NLS-1$
+ }
+ manifest.getMainAttributes().putValue("Require-Bundle", value); //$NON-NLS-1$
+ }
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ manifest.write(bos);
+ // StringReader reader = new
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ fileManifest.setContents(bis, true, true, null);
+ result = file;
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ }
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/ProjectFolderPickerDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/ProjectFolderPickerDialog.java
new file mode 100644
index 00000000..0c918aba
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/ProjectFolderPickerDialog.java
@@ -0,0 +1,257 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages;
+
+import java.net.URL;
+import java.util.ArrayList;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+public class ProjectFolderPickerDialog extends TitleAreaDialog {
+
+ private TreeViewer viewer;
+ private IProject project;
+ private String srcPath;
+ private String value;
+
+ protected ProjectFolderPickerDialog(Shell parentShell, IProject project, String srcPath) {
+ super(parentShell);
+ this.project = project;
+ this.srcPath = srcPath;
+ }
+
+ static class ProjectContentProvider implements ITreeContentProvider {
+
+ private IProject project;
+
+ public ProjectContentProvider() {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ this.project = (IProject) newInput;
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return new Object[] { project.getName() };
+ }
+
+ @Override
+ public Object[] getChildren(final Object parentElement) {
+ if (parentElement instanceof String) {
+ return getChildren(project);
+ }
+ final IResource resource = (IResource) parentElement;
+ final ArrayList<Object> list = new ArrayList<Object>();
+ IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
+
+ @Override
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ if (proxy.getType() == IResource.FOLDER && proxy.requestResource().getParent() == resource) {
+ if (proxy.requestResource().equals(resource) == false) {
+ list.add(proxy.requestResource());
+ }
+ }
+ return true;
+ }
+ };
+ try {
+ resource.accept(visitor, IResource.DEPTH_ONE);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ return list.toArray(new Object[0]);
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ IResource resource = (IResource) element;
+ return resource.getParent();
+ }
+
+ Boolean found = false;
+
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof String) {
+ return true;
+ }
+ final IResource resource = (IResource) element;
+ try {
+ found = false;
+ resource.accept(new IResourceProxyVisitor() {
+
+ @Override
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ if (proxy.getType() == IResource.FOLDER && proxy.requestResource().equals(resource) == false) {
+ found = true;
+ return false;
+ }
+ return true;
+ }
+ }, IResource.DEPTH_ONE);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ return found;
+ }
+ }
+
+ static class ProjectLabelProvider extends ColumnLabelProvider {
+ @Override
+ public String getText(Object element) {
+ if (element instanceof String) {
+ return element.toString();
+ }
+ IResource resource = (IResource) element;
+ return resource.getName();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ try {
+ if (element instanceof String) {
+ return new Image(Display.getDefault(), new URL(Messages.ProjectFolderPickerDialog_0).openStream());
+ }
+ return new Image(Display.getDefault(), new URL("platform:/plugin/org.eclipse.ui.ide/icons/full/obj16/folder.png").openStream()); //$NON-NLS-1$
+ } catch (Exception e) {
+ return super.getImage(element);
+ }
+ }
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+
+ Button button = new Button(parent, SWT.PUSH);
+ button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ button.setText(Messages.ProjectFolderPickerDialog_useSourceDirectory);
+ button.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ value = Path.fromOSString(srcPath).removeLastSegments(1).toOSString();
+ ProjectFolderPickerDialog.super.okPressed();
+ }
+ });
+ button.moveAbove(getButton(IDialogConstants.CANCEL_ID));
+
+ ((GridLayout) parent.getLayout()).numColumns = 3;
+ }
+
+ @Override
+ protected void okPressed() {
+ Object selected = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
+ if (selected == null || selected instanceof String) {
+ value = ""; //$NON-NLS-1$
+ } else {
+ IResource resource = (IResource) selected;
+ value = resource.getFullPath().removeFirstSegments(1).toOSString();
+ }
+
+ super.okPressed();
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ // TODO Auto-generated method stub
+ Composite ret = (Composite) super.createDialogArea(parent);
+
+ viewer = new TreeViewer(ret);
+ viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
+ viewer.setContentProvider(new ProjectContentProvider());
+ viewer.setLabelProvider(new ProjectLabelProvider());
+ viewer.setInput(project);
+ viewer.expandToLevel(2);
+
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ okPressed();
+ }
+ });
+
+ if (srcPath != null) {
+
+ IPath path = Path.fromOSString(srcPath);
+
+ Composite compPath = new Composite(ret, SWT.NONE);
+ compPath.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ compPath.setLayout(new GridLayout(2, false));
+
+ Label label = new Label(compPath, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label.setText(Messages.ProjectFolderPickerDialog_sourceResourceName);
+
+ Label label2 = new Label(compPath, SWT.NONE);
+ label2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label2.setText(path.lastSegment());
+
+ Label label3 = new Label(compPath, SWT.NONE);
+ label3.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ label3.setText(Messages.ProjectFolderPickerDialog_sourceResourceDirectory);
+
+ Label lblResourcePath = new Label(compPath, SWT.NONE);
+ lblResourcePath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ lblResourcePath.setText(path.removeLastSegments(1).toOSString());
+ }
+
+ String message = Messages.ProjectFolderPickerDialog_6;
+ getShell().setText(message);
+ setTitle(message);
+ setMessage(message);
+ return ret;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/ReferencedProjectPickerDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/ReferencedProjectPickerDialog.java
new file mode 100644
index 00000000..be001910
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/ReferencedProjectPickerDialog.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.BundleImageCache;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.TitleAreaFilterDialog;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+public class ReferencedProjectPickerDialog extends TitleAreaFilterDialog {
+
+ private IProject project;
+ private BundleImageCache imageCache;
+ static protected Image imgProject;
+
+ protected ReferencedProjectPickerDialog(final Shell parentShell, IProject project) {
+ super(parentShell, new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ IProject project = (IProject) element;
+ return project.getName();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return imgProject;
+ }
+ });
+ this.project = project;
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ imageCache = new BundleImageCache(parent.getDisplay(), getClass().getClassLoader());
+ getShell().addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ imageCache.dispose();
+ imgProject = null;
+ }
+ });
+ imgProject = imageCache.create("/icons/full/obj16/projects.png"); //$NON-NLS-1$
+
+ Control ret = super.createContents(parent);
+ try {
+ setElements(project.getReferencedProjects());
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ String message = Messages.ReferencedProjectPickerDialog_selectReferencedProject;
+ setMessage(message);
+ getShell().setText(message);
+ setTitle(message);
+ return ret;
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/UriDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/UriDialog.java
new file mode 100644
index 00000000..dd945d56
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/UriDialog.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+/**
+ * An interface for a URI Dialog
+ *
+ * @author Steven Spungin
+ *
+ */
+public interface UriDialog {
+
+ void setUri(String uri);
+
+ String getUri();
+
+ /**
+ * See @org.eclipse.jface.dialogs.Dialog.open
+ *
+ * @return Dialog.OK if the user submitted a response.
+ */
+ int open();
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/UriDialogType.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/UriDialogType.java
new file mode 100644
index 00000000..31b180bf
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/UriDialogType.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 424730
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs;
+
+/**
+ * Enum of various URI Dialog Types
+ *
+ * @author Steven Spungin
+ *
+ */
+public enum UriDialogType {
+ BUNDLECLASS, ICON
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/messages.properties
new file mode 100644
index 00000000..bed4ce9a
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/messages.properties
@@ -0,0 +1,58 @@
+BundleClassDialog_bundle=bundle
+BundleClassDialog_bundleClassEditor=BundleClass Editor
+BundleClassDialog_class=class
+BundleClassDialog_create_goto=Create/Goto
+BundleClassDialog_find=Find
+BundleClassDialog_package=package
+BundleClassDialog_uri=URI
+BundleConverter_couldNotCreateMetaInfDir=Could not create META-INF directory
+BundleConverter_installLocationNotADirectory=Install location is not a directory
+BundleConverter_projectIsAlreadyABundle=Project is already a bundle
+FindContributionDialog_findBundle=Find Bundle
+FindContributionDialog_findClass=Find Class
+FindContributionDialog_findIcon=Find Icon
+FindContributionDialog_findPackage=Find Package
+FindContributionDialog_inBundle=In Bundle
+FindContributionDialog_inPackage=In Package
+FindIconDialog_findIcon=Find Icon
+FindIconDialog_searchByFilename=Search By Filename
+IconDialog_bundle=bundle
+IconDialog_find=Find
+IconDialog_folder=folder
+IconDialog_icon=icon
+IconDialog_selectIcon=Select Icon
+IconDialog_selectIcon_MESSAGE=Select Icon
+IconDialog_selectIcon_TITLE=Select Icon
+IconDialog_uri=URI
+IconDialog_uriEditor=URI Editor
+NonReferencedResourceDialog__ast_notInABundle_ast=*** NOT IN A BUNDLE ***
+NonReferencedResourceDialog_2=Bundle
+NonReferencedResourceDialog_ast_notInABundle_ast=*** NOT IN A BUNDLE ***
+NonReferencedResourceDialog_bundle=Bundle
+NonReferencedResourceDialog_class=Class
+NonReferencedResourceDialog_convertAndRequire=Convert Resource's Project To A Bundle And Require It
+NonReferencedResourceDialog_copyToReferenedProject=Copy To A Referenced Project...
+NonReferencedResourceDialog_copyToThisProject=Copy To This Project...
+NonReferencedResourceDialog_directory=Directory
+NonReferencedResourceDialog_error=Error
+NonReferencedResourceDialog_importPackage=Import Package
+NonReferencedResourceDialog_installLocation=Install Location
+NonReferencedResourceDialog_package=Package
+NonReferencedResourceDialog_requireBundle=Require Bundle
+NonReferencedResourceDialog_resource=Resource
+NonReferencedResourceDialog_resourceNotReferenced=The resource's bundle is not referenced by this project's bundle.
+NonReferencedResourceDialog_resourceReferenceWarning=Resource Reference Warning
+NonReferencedResourceDialog_selectProjectToReceiveCopy=Select the project to receive the copied resource:
+NonReferencedResourceDialog_selectTheFolderResourceCopy=Select the folder where the resource will be copied to:
+NonReferencedResourceDialog_url=URL
+NonReferencedResourceDialog_useAnyway=Use Anyway (Resolve Later)
+ProjectFolderPickerDialog_0=platform:/plugin/org.eclipse.ui.images/eclipse-png/org.eclipse.jdt.ui/icons/full/eview16/projects.png
+ProjectFolderPickerDialog_6=Select Project Folder
+ProjectFolderPickerDialog_sourceResourceDirectory=Source Resource Directory
+ProjectFolderPickerDialog_sourceResourceName=Source Resource Name
+ProjectFolderPickerDialog_useSourceDirectory=Use source resource directory
+ReferencedProjectPickerDialog_selectReferencedProject=Select Referenced Project
+TargetPlatformClassContributionCollector_classes=Classes
+TargetPlatformContributionCollector_pleaseWait=Please wait while the target platform lookup cache updates...
+TargetPlatformContributionCollector_updatingTargetPlatformCache=Updating Target Platform Cache (
+TargetPlatformIconContributionCollector_images=Images
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/AbstractHandler.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/AbstractHandler.java
new file mode 100644
index 00000000..62a9074e
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/AbstractHandler.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432372
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.handlers;
+
+import javax.inject.Named;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.IViewEObjects;
+
+public class AbstractHandler {
+
+ static final public String VIEWER_KEY = "org.eclipse.e4.tools.active-object-viewer"; //$NON-NLS-1$
+
+ @CanExecute
+ public boolean canExecute(@Optional @Named(VIEWER_KEY) IViewEObjects viewer) {
+ return (viewer != null);
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateAttributesHandler.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateAttributesHandler.java
new file mode 100644
index 00000000..b3cc7ff8
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateAttributesHandler.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432372
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.handlers;
+
+import java.util.Collection;
+import java.util.HashSet;
+import javax.inject.Named;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.IViewEObjects;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.TitleAreaFilterDialogWithEmptyOptions;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+public class MarkDuplicateAttributesHandler extends MarkDuplicateItemsBase {
+
+ @Execute
+ public void execute(@Named(VIEWER_KEY) IViewEObjects viewer, IEclipseContext context) {
+ final HashSet<String> set = new HashSet<String>();
+ Collection<EObject> allEObjects = viewer.getAllEObjects();
+ for (EObject obj : allEObjects) {
+ for (EAttribute attribute : obj.eClass().getEAllAttributes()) {
+ set.add(attribute.getName());
+ }
+ }
+ ILabelProvider renderer = new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return String.valueOf(element);
+ }
+ };
+
+ TitleAreaFilterDialogWithEmptyOptions dlg = new TitleAreaFilterDialogWithEmptyOptions(context.get(Shell.class), renderer) {
+ @Override
+ protected Control createContents(Composite parent) {
+ Control ret = super.createContents(parent);
+ setMessage("Select an attribute to mark duplicate values");
+ setTitle("Mark Duplicates");
+ setElements(set.toArray(new String[0]));
+ return ret;
+ }
+ };
+ if (dlg.open() == Window.OK) {
+ Collection<EObject> marked = getDuplicateList(dlg.getFirstElement().toString(), allEObjects);
+ applyEmptyOption(marked, dlg.getFirstElement().toString(), dlg.getEmptyFilterOption());
+ viewer.highlightEObjects(marked);
+ }
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateElementIdsHandler.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateElementIdsHandler.java
new file mode 100644
index 00000000..b8cb1453
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateElementIdsHandler.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432372
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.handlers;
+
+public class MarkDuplicateElementIdsHandler extends MarkDuplicateItemsBase {
+
+ public MarkDuplicateElementIdsHandler() {
+ setAttributeName("elementId"); //$NON-NLS-1$
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateItemsBase.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateItemsBase.java
new file mode 100644
index 00000000..848e40a6
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateItemsBase.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432372
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.handlers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.EmfUtil;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.IViewEObjects;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.EmptyFilterOption;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+
+public class MarkDuplicateItemsBase extends AbstractHandler {
+
+ private String attName;
+
+ @Execute
+ public void execute(IEclipseContext context) {
+ IViewEObjects viewer = (IViewEObjects) context.get(VIEWER_KEY);
+ Collection<EObject> duplicates = getDuplicateList(getAttName(), viewer.getAllEObjects());
+ applyEmptyOption(duplicates, getAttName(), EmptyFilterOption.EXCLUDE);
+ viewer.highlightEObjects(duplicates);
+ }
+
+ static Collection<EObject> getDuplicateList(String attName, Collection<EObject> all) {
+ Map<String, List<EObject>> map = getDuplicateMap(attName, all);
+ List<EObject> duplicates = new ArrayList<EObject>();
+ for (String key : map.keySet()) {
+ List<EObject> list = map.get(key);
+ if (list.size() > 1) {
+ duplicates.addAll(list);
+ }
+ }
+ return duplicates;
+ }
+
+ static Map<String, List<EObject>> getDuplicateMap(String attName, Collection<EObject> selected) {
+ ConcurrentHashMap<String, List<EObject>> map = new ConcurrentHashMap<String, List<EObject>>();
+ for (Iterator<?> it = selected.iterator(); it.hasNext();) {
+ Object object = it.next();
+ if (object instanceof EObject) {
+ EObject item = (EObject) object;
+ EAttribute att = EmfUtil.getAttribute(item, attName);
+ if (att != null) {
+ String attValue;
+ Object obj = item.eGet(att);
+ if (obj == null) {
+ attValue = ""; //$NON-NLS-1$
+ } else {
+ attValue = String.valueOf(obj);
+ }
+ List<EObject> list = map.get(attValue);
+ if (list == null) {
+ list = new ArrayList<EObject>();
+ map.put(attValue, list);
+ }
+ list.add(item);
+ }
+ }
+ }
+ return map;
+ }
+
+ public String getAttName() {
+ return attName;
+ }
+
+ public void setAttributeName(String attName) {
+ this.attName = attName;
+ }
+
+ static protected void applyEmptyOption(Collection<EObject> marked, String attName, EmptyFilterOption emptyFilterOption) {
+ switch (emptyFilterOption) {
+ case EXCLUDE:
+ for (Iterator<?> it = marked.iterator(); it.hasNext();) {
+ EObject eObject = (EObject) it.next();
+ if (E.isEmpty(EmfUtil.getAttributeValue(eObject, attName))) {
+ it.remove();
+ }
+ }
+ break;
+ case ONLY:
+ for (Iterator<?> it = marked.iterator(); it.hasNext();) {
+ EObject eObject = (EObject) it.next();
+ if (E.notEmpty(EmfUtil.getAttributeValue(eObject, attName))) {
+ it.remove();
+ }
+ }
+ break;
+ case INCLUDE:
+ default:
+ break;
+ }
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateLabelsHandler.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateLabelsHandler.java
new file mode 100644
index 00000000..e352bc13
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/MarkDuplicateLabelsHandler.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432372
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.handlers;
+
+public class MarkDuplicateLabelsHandler extends MarkDuplicateItemsBase {
+
+ public MarkDuplicateLabelsHandler() {
+ setAttributeName("label"); //$NON-NLS-1$
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/RepairDuplicateItemsHandler.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/RepairDuplicateItemsHandler.java
new file mode 100644
index 00000000..a0eae910
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/RepairDuplicateItemsHandler.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432372
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.handlers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.EmfUtil;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.IViewEObjects;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.EmptyFilterOption;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+
+public class RepairDuplicateItemsHandler extends MarkDuplicateItemsBase {
+
+ static public String name = "org.eclipse.e4.tools.active-object-viewer"; //$NON-NLS-1$
+ static String attName = "elementId"; //$NON-NLS-1$
+
+ @Override
+ @Execute
+ public void execute(IEclipseContext context) {
+ IViewEObjects viewer = (IViewEObjects) context.get(name);
+ Collection<EObject> all = viewer.getAllEObjects();
+ Map<String, List<EObject>> map = MarkDuplicateElementIdsHandler.getDuplicateMap(attName, all);
+ Iterator<Entry<String, List<EObject>>> it = map.entrySet().iterator();
+ CompoundCommand compoundCommand = new CompoundCommand();
+ EditingDomain editingDomain = viewer.getEditingDomain();
+
+ while (it.hasNext()) {
+ Entry<String, List<EObject>> entry = it.next();
+ List<EObject> listDups = entry.getValue();
+ if (listDups.size() > 1) {
+ ArrayList<EObject> toFix = new ArrayList<EObject>(listDups.subList(1, listDups.size()));
+ Iterator<EObject> itToFix = toFix.iterator();
+ while (itToFix.hasNext()) {
+ EObject eObject = itToFix.next();
+ EAttribute att = EmfUtil.getAttribute(eObject, attName);
+ String value = (String) eObject.eGet(att);
+ // do not repair empty or null values
+ if (E.isEmpty(value)) {
+ break;
+ }
+ int index = -1;
+ while (map.containsKey(value)) {
+ index++;
+ int lastDot = value.lastIndexOf('.');
+ if (lastDot == -1) {
+ lastDot = value.length();
+ }
+ try {
+ String suffix = value.substring(lastDot + 1);
+ Integer.parseInt(suffix);
+ // ends with integer
+ value = value.substring(0, lastDot);
+ } catch (Exception e) {
+ }
+ value = value + "." + index; //$NON-NLS-1$
+ }
+ Command cmd = SetCommand.create(editingDomain, eObject, att, value);
+ compoundCommand.append(cmd);
+ // Note: If the compound command cannot execute, we
+ // must revert these changes
+ listDups.remove(eObject);
+ List<EObject> newList = new ArrayList<EObject>();
+ newList.add(eObject);
+ map.put(value, newList);
+ // Note: end
+
+ }
+ }
+ }
+
+ if (compoundCommand.isEmpty() == false) {
+ if (compoundCommand.canExecute()) {
+ editingDomain.getCommandStack().execute(compoundCommand);
+ } else {
+ // this will rollback our local map changes
+ // Object obj =
+ // ContextInjectionFactory.make(MarkDuplicateItemsHandler.class,
+ // context);
+ // ContextInjectionFactory.invoke(obj, Execute.class, context);
+ }
+ Collection<EObject> duplicateList = MarkDuplicateElementIdsHandler.getDuplicateList(attName, all);
+ applyEmptyOption(duplicateList, attName, EmptyFilterOption.EXCLUDE);
+ viewer.highlightEObjects(duplicateList);
+ }
+ }
+
+ @CanExecute
+ public boolean canExecute(IEclipseContext context) {
+ IViewEObjects viewer = (IViewEObjects) context.get(name);
+ return (viewer != null);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/UnmarkItemsHandler.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/UnmarkItemsHandler.java
new file mode 100644
index 00000000..b7918889
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/handlers/UnmarkItemsHandler.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432372
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.handlers;
+
+import java.util.Collections;
+import javax.inject.Named;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.IViewEObjects;
+import org.eclipse.emf.ecore.EObject;
+
+public class UnmarkItemsHandler extends AbstractHandler {
+
+ @Execute
+ public void execute(@Named(VIEWER_KEY) IViewEObjects viewer) {
+ viewer.highlightEObjects(Collections.<EObject> emptyList());
+ }
+
+} \ No newline at end of file

Back to the top