Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Spungin2014-04-05 02:19:54 +0000
committerSteven Spungin2014-04-06 03:26:30 +0000
commit6a113089889fb86df228f97118cd48c56ebe42b8 (patch)
tree7d65b9e520e7f9bc1ed463dbb761b21620ea6f68
parent324e4d99200fa18b3f2924d33640db0e98fef87e (diff)
downloadorg.eclipse.e4.tools-6a113089889fb86df228f97118cd48c56ebe42b8.tar.gz
org.eclipse.e4.tools-6a113089889fb86df228f97118cd48c56ebe42b8.tar.xz
org.eclipse.e4.tools-6a113089889fb86df228f97118cd48c56ebe42b8.zip
Bug 431735 - e4 Model Editor Table TabI20140407-2200
Change-Id: I1404b5e00defe2417177390a86d0ea444aaa0d03 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/ModelEditorPreferencePage.java126
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java19
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties20
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java35
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java151
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeEditingSupport.java75
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeTableViewerColumn.java64
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EmfUtil.java85
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IGotoObject.java32
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IViewEObjects.java57
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java293
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ModelResourceContentProvider.java103
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/TableViewerUtil.java61
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/xml/EMFDocumentResourceMediator.java31
14 files changed, 1102 insertions, 50 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelEditorPreferencePage.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelEditorPreferencePage.java
index 64315c76..f1a22076 100644
--- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelEditorPreferencePage.java
+++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelEditorPreferencePage.java
@@ -1,3 +1,9 @@
+/*******************************************************************************
+ *
+ * Contributors:
+ * Steven Spungin <steven@spungin.tv> - Bug 431735
+ ******************************************************************************/
+
package org.eclipse.e4.tools.emf.editor3x;
import org.eclipse.core.runtime.preferences.InstanceScope;
@@ -10,17 +16,19 @@ 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.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
-public class ModelEditorPreferencePage extends PreferencePage implements
- IWorkbenchPreferencePage {
+public class ModelEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private BooleanFieldEditor fAutoGeneratedId;
private BooleanFieldEditor fShowXMIId;
private ColorFieldEditor fColorValueNotRendered;
private ColorFieldEditor fColorValueNotVisible;
private ColorFieldEditor fColorValueNotVisibleAndRendered;
+ private BooleanFieldEditor fShowListTab;
+ private BooleanFieldEditor fShowSearch;
public ModelEditorPreferencePage() {
}
@@ -34,53 +42,93 @@ public class ModelEditorPreferencePage extends PreferencePage implements
}
public void init(IWorkbench workbench) {
- setPreferenceStore(new ScopedPreferenceStore(InstanceScope.INSTANCE,"org.eclipse.e4.tools.emf.ui"));
+ setPreferenceStore(new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.e4.tools.emf.ui"));
}
@Override
protected Control createContents(Composite parent) {
Composite result = new Composite(parent, SWT.NONE);
result.setLayout(new GridLayout());
-
- {
- fColorValueNotRendered = new ColorFieldEditor("notRenderedColor", "Not rendered color", result);
- fColorValueNotRendered.setPage(this);
- fColorValueNotRendered.setPreferenceStore(getPreferenceStore());
- fColorValueNotRendered.load();
- }
{
- fColorValueNotVisible = new ColorFieldEditor("notVisibleColor", "Not visible color", result);
- fColorValueNotVisible.setPage(this);
- fColorValueNotVisible.setPreferenceStore(getPreferenceStore());
- fColorValueNotVisible.load();
- }
-
- {
- fColorValueNotVisibleAndRendered = new ColorFieldEditor("notVisibleAndRenderedColor", "Not visible and not rendered color", result);
- fColorValueNotVisibleAndRendered.setPage(this);
- fColorValueNotVisibleAndRendered.setPreferenceStore(getPreferenceStore());
- fColorValueNotVisibleAndRendered.load();
+ Group group = new Group(result, SWT.NONE);
+ group.setText("Color");
+ group.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+ group.setLayout(new GridLayout(2, false));
+
+ {
+ fColorValueNotRendered = new ColorFieldEditor("notRenderedColor", "Not rendered color", group);
+ fColorValueNotRendered.setPage(this);
+ fColorValueNotRendered.setPreferenceStore(getPreferenceStore());
+ fColorValueNotRendered.load();
+ }
+
+ {
+ fColorValueNotVisible = new ColorFieldEditor("notVisibleColor", "Not visible color", group);
+ fColorValueNotVisible.setPage(this);
+ fColorValueNotVisible.setPreferenceStore(getPreferenceStore());
+ fColorValueNotVisible.load();
+ }
+
+ {
+ fColorValueNotVisibleAndRendered = new ColorFieldEditor("notVisibleAndRenderedColor", "Not visible and not rendered color", group);
+ fColorValueNotVisibleAndRendered.setPage(this);
+ fColorValueNotVisibleAndRendered.setPreferenceStore(getPreferenceStore());
+ fColorValueNotVisibleAndRendered.load();
+ }
}
-
+
{
- Composite container = new Composite(result, SWT.NONE);
- container.setLayoutData(new GridData(GridData.FILL,GridData.CENTER,false,false,2,1));
- fAutoGeneratedId = new BooleanFieldEditor("autoCreateElementId", "Autogenerate Element-Id", container);
- fAutoGeneratedId.setPage(this);
- fAutoGeneratedId.setPreferenceStore(getPreferenceStore());
- fAutoGeneratedId.load();
+ Group group = new Group(result, SWT.NONE);
+ group.setText("Form Tab");
+ group.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+ group.setLayout(new GridLayout(2, false));
+
+ {
+ Composite container = new Composite(group, SWT.NONE);
+ container.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+ fAutoGeneratedId = new BooleanFieldEditor("autoCreateElementId", "Autogenerate Element-Id", container);
+ fAutoGeneratedId.setPage(this);
+ fAutoGeneratedId.setPreferenceStore(getPreferenceStore());
+ fAutoGeneratedId.load();
+ }
+
+ {
+ Composite container = new Composite(group, SWT.NONE);
+ container.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+ fShowXMIId = new BooleanFieldEditor("showXMIId", "Show XMI:ID", container);
+ fShowXMIId.setPage(this);
+ fShowXMIId.setPreferenceStore(getPreferenceStore());
+ fShowXMIId.load();
+ }
+
+ {
+ Composite container = new Composite(group, SWT.NONE);
+ container.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+ fShowSearch = new BooleanFieldEditor("tab-form-search-show", "Searchable tree on form tab\n" + "(forces read only XMI tab)\n" + "(requires reopening model)", container);
+ fShowSearch.setPage(this);
+ fShowSearch.setPreferenceStore(getPreferenceStore());
+ fShowSearch.load();
+ }
+
}
-
+
{
- Composite container = new Composite(result, SWT.NONE);
- container.setLayoutData(new GridData(GridData.FILL,GridData.CENTER,false,false,2,1));
- fShowXMIId = new BooleanFieldEditor("showXMIId", "Show XMI:ID", container);
- fShowXMIId.setPage(this);
- fShowXMIId.setPreferenceStore(getPreferenceStore());
- fShowXMIId.load();
+ Group group = new Group(result, SWT.NONE);
+ group.setText("Tabs");
+ group.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+ group.setLayout(new GridLayout(2, false));
+
+ {
+ Composite container = new Composite(group, SWT.NONE);
+ container.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1));
+ fShowListTab = new BooleanFieldEditor("tab-list-show", "Show List Tab", container);
+ fShowListTab.setPage(this);
+ fShowListTab.setPreferenceStore(getPreferenceStore());
+ fShowListTab.load();
+ }
}
-
+
return result;
}
@@ -91,6 +139,8 @@ public class ModelEditorPreferencePage extends PreferencePage implements
fColorValueNotRendered.store();
fColorValueNotVisible.store();
fColorValueNotVisibleAndRendered.store();
+ fShowListTab.store();
+ fShowSearch.store();
return super.performOk();
}
@@ -101,9 +151,11 @@ public class ModelEditorPreferencePage extends PreferencePage implements
fColorValueNotRendered.loadDefault();
fColorValueNotVisible.loadDefault();
fColorValueNotVisibleAndRendered.loadDefault();
+ fShowListTab.loadDefault();
+ fShowSearch.loadDefault();
super.performDefaults();
}
-
+
@Override
public void dispose() {
super.dispose();
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 9ebdff81..b84dd752 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
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Marco Descher <marco@descher.at> - Bug 395982, 396975, 426653
+ * Steven Spungin <steven@spungin.tv> - Bug 431735
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal;
@@ -644,4 +645,22 @@ public class Messages {
public String ModelEditor_ExtractFragment_NoParentId;
public String KeyBindingEditor_SequenceLowercase;
public String ModelTooling_CommandId_tooltip;
+
+ public static String ModelEditor_goto_list;
+ public static String ModelEditor_goto_xmi;
+ public static String EmfUtil_ex_attribute_not_found;
+ public static String ListTab_0;
+ public static String ListTab_1;
+ public static String ListTab_2;
+ public static String ListTab_3;
+ public static String ListTab_4;
+ public static String ListTab_5;
+ public static String ListTab_6;
+ public static String ListTab_7;
+ public static String ListTab_8;
+ public static String ListTab_9;
+ public static String ListTab_col_id;
+ public static String ListTab_col_item;
+ public static String ListTab_col_label;
+ public static String ListTab_col_go;
}
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 160cac65..5088e954 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
@@ -9,6 +9,7 @@
# * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
# * Sopot Cela <sopotcela@gmail.com> - enhancements
# * Marco Descher <marco@descher.at> - Bug 395982, 396975, 426653
+# * Steven Spungin <steven@spungin.tv> - Bug 431735
# ******************************************************************************
ModelTooling_Common_Up=Up
ModelTooling_Common_Down=Down
@@ -654,5 +655,24 @@ Special_UnknownElement_Detail= Use an extension point!
VWindowSharedElementsEditor_Area=Area
ModelEditor_ExtractFragment=Extract into a fragment
ModelEditor_ExtractFragment_NoParentId=Can not extract because parent container has no ID. \nAdd an ID and try again.
+ModelEditor_goto_list=Goto List
+ModelEditor_goto_xmi=Goto XMI
KeyBindingEditor_SequenceLowercase=Key sequences should be specified in uppercase characters
ModelTooling_CommandId_tooltip=Command identifier. Must be defined for a command to work properly.
+
+
+EmfUtil_ex_attribute_not_found=Attribute not found:
+ListTab_0=List
+ListTab_1=Mark Duplicate IDs
+ListTab_2=Duplicate IDs will be highlighted
+ListTab_3=Repair Duplicate IDs
+ListTab_4=Duplicate IDs will be replaced using a unique suffix
+ListTab_5=Delete Selected Items
+ListTab_6=Selected items will be deleted
+ListTab_7=Showing items with attribute:
+ListTab_8=xmi
+ListTab_9=form
+ListTab_col_id=ID
+ListTab_col_item=Item
+ListTab_col_label=Label
+ListTab_col_go=Go
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java
index 2068b5c2..2587345e 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/PreferenceInitializer.java
@@ -1,3 +1,9 @@
+/*******************************************************************************
+ *
+ * Contributors:
+ * Steven Spungin <steven@spungin.tv> - Bug 431735
+ ******************************************************************************/
+
package org.eclipse.e4.tools.emf.ui.internal;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
@@ -10,25 +16,36 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
- IEclipsePreferences pref = InstanceScope.INSTANCE.getNode("org.eclipse.e4.tools.emf.ui");
+ IEclipsePreferences pref = InstanceScope.INSTANCE.getNode("org.eclipse.e4.tools.emf.ui"); //$NON-NLS-1$
- if (pref.get("notRenderedColor", null) == null) {
+ if (pref.get("notRenderedColor", null) == null) { //$NON-NLS-1$
String val = StringConverter.asString(new RGB(200, 200, 200));
- pref.put("notRenderedColor", val);
+ pref.put("notRenderedColor", val); //$NON-NLS-1$
}
- if (pref.get("notVisibleColor", null) == null) {
+ if (pref.get("notVisibleColor", null) == null) { //$NON-NLS-1$
String val = StringConverter.asString(new RGB(200, 200, 200));
- pref.put("notVisibleColor", val);
+ pref.put("notVisibleColor", val); //$NON-NLS-1$
}
- if (pref.get("notVisibleAndRenderedColor", null) == null) {
+ if (pref.get("notVisibleAndRenderedColor", null) == null) { //$NON-NLS-1$
String val = StringConverter.asString(new RGB(200, 200, 200));
- pref.put("notVisibleAndRenderedColor", val);
+ pref.put("notVisibleAndRenderedColor", val); //$NON-NLS-1$
+ }
+
+ if (pref.get("autoCreateElementId", null) == null) { //$NON-NLS-1$
+ pref.putBoolean("autoCreateElementId", true); //$NON-NLS-1$
+ }
+
+ // TODO: if accepted, this should default to true
+ if (pref.get("tab-list-show", null) == null) { //$NON-NLS-1$
+ pref.putBoolean("tab-list-show", false); //$NON-NLS-1$
}
- if (pref.get("autoCreateElementId", null) == null) {
- pref.putBoolean("autoCreateElementId", true);
+ // TODO: After XMI tab is not forced disabled, this should default to
+ // true
+ if (pref.get("tab-form-search-show", null) == null) { //$NON-NLS-1$
+ pref.putBoolean("tab-form-search-show", false); //$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 f3b4542e..32fac0dd 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,11 +10,12 @@
* 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
+ * Steven Spungin <steven@spungin.tv> - Bug 396902, 431755, 431735
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -40,6 +41,7 @@ import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.RegistryFactory;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Execute;
@@ -103,6 +105,9 @@ import org.eclipse.e4.tools.emf.ui.internal.common.component.TrimContributionEdi
import org.eclipse.e4.tools.emf.ui.internal.common.component.TrimmedWindowEditor;
import org.eclipse.e4.tools.emf.ui.internal.common.component.WindowEditor;
import org.eclipse.e4.tools.emf.ui.internal.common.component.WizardDialogEditor;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.EmfUtil;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.IGotoObject;
+import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.ListTab;
import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VApplicationAddons;
import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VApplicationCategoriesEditor;
import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VApplicationWindowEditor;
@@ -186,7 +191,9 @@ import org.eclipse.jface.resource.StringConverter;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
@@ -234,7 +241,7 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TreeItem;
-public class ModelEditor {
+public class ModelEditor implements IGotoObject {
private static final String ORG_ECLIPSE_E4_TOOLS_MODELEDITOR_FILTEREDTREE_ENABLED_XMITAB_DISABLED = "org.eclipse.e4.tools.modeleditor.filteredtree.enabled.xmitab.disabled";//$NON-NLS-1$
public static final String CSS_CLASS_KEY = "org.eclipse.e4.ui.css.CssClassName"; //$NON-NLS-1$
@@ -266,6 +273,10 @@ public class ModelEditor {
private static final int VERTICAL_RULER_WIDTH = 20;
+ public static final int TAB_FORM = 0;
+ public static final int TAB_XMI = 1;
+ public static final int TAB_LIST = 2;
+
private Map<EClass, AbstractComponentEditor> editorMap = new HashMap<EClass, AbstractComponentEditor>();
private Map<String, AbstractComponentEditor> virtualEditors = new HashMap<String, AbstractComponentEditor>();
private Map<Class<?>, List<AbstractElementEditorContribution>> tabContributions = new HashMap<Class<?>, List<AbstractElementEditorContribution>>();
@@ -297,6 +308,10 @@ public class ModelEditor {
private boolean showXMIId;
@Inject
+ @Preference(nodePath = "org.eclipse.e4.tools.emf.ui")
+ IEclipsePreferences preferences;
+
+ @Inject
@Optional
private IExtensionLookup extensionLookup;
@@ -326,6 +341,8 @@ public class ModelEditor {
private boolean saving;
+ private ListTab listTab;
+
public ModelEditor(Composite composite, IEclipseContext context, IModelResource modelProvider, IProject project, final IResourcePool resourcePool) {
this.resourcePool = resourcePool;
this.modelProvider = modelProvider;
@@ -412,6 +429,8 @@ public class ModelEditor {
}
});
+ tab_list_show(preferences.getBoolean("tab-list-show", false)); //$NON-NLS-1$
+
editorTabFolder.setSelection(0);
}
@@ -485,7 +504,7 @@ public class ModelEditor {
});
String property = System.getProperty(ORG_ECLIPSE_E4_TOOLS_MODELEDITOR_FILTEREDTREE_ENABLED_XMITAB_DISABLED);
- if (property != null) {
+ if (property != null || preferences.getBoolean("tab-form-search-show", false)) { //$NON-NLS-1$
sourceViewer.setEditable(false);
sourceViewer.getTextWidget().setEnabled(false);
}
@@ -852,6 +871,31 @@ public class ModelEditor {
};
manager.add(expandAction);
+
+ if (s.getFirstElement() instanceof EObject) {
+ manager.add(new Separator());
+ final EObject el = (EObject) s.getFirstElement();
+ Action gotoXmiAction = new Action(Messages.ModelEditor_goto_xmi) {
+ @Override
+ public void run() {
+ gotoEObject(TAB_XMI, el);
+ }
+ };
+ manager.add(gotoXmiAction);
+
+ if (listTab != null) {
+ if (EmfUtil.getAttribute(el, "elementId") != null) { //$NON-NLS-1$
+ Action gotoListAction = new Action(Messages.ModelEditor_goto_list) {
+ @Override
+ public void run() {
+ gotoEObject(TAB_LIST, el);
+ }
+ };
+ manager.add(gotoListAction);
+ }
+ }
+
+ }
}
});
@@ -993,7 +1037,7 @@ public class ModelEditor {
TreeViewer tempViewer = null;
String property = System.getProperty(ORG_ECLIPSE_E4_TOOLS_MODELEDITOR_FILTEREDTREE_ENABLED_XMITAB_DISABLED);
- if (property != null) {
+ if (property != null || preferences.getBoolean("tab-form-search-show", false)) { //$NON-NLS-1$
FilteredTree viewParent = new FilteredTree(treeArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL, new PatternFilter(), true);
tempViewer = viewParent.getViewer();
} else {
@@ -1235,6 +1279,29 @@ public class ModelEditor {
}
@Inject
+ public void tab_list_show(@Preference("tab-list-show") Boolean show) {
+ if (editorTabFolder == null) {
+ return;
+ }
+ if (show == false) {
+ if (listTab != null) {
+ // remove the tab from the folder
+ listTab.getTabItem().dispose();
+ ContextInjectionFactory.uninject(listTab, listTab.getContext());
+ listTab = null;
+ }
+ } else {
+ if (listTab == null) {
+ IEclipseContext child = context.createChild();
+ child.set(CTabFolder.class, editorTabFolder);
+ child.set(EMFDocumentResourceMediator.class, emfDocumentProvider);
+ child.set(IGotoObject.class, this);
+ listTab = ContextInjectionFactory.make(ListTab.class, child);
+ }
+ }
+ }
+
+ @Inject
public void setNotVisibleColor(@Preference("notVisibleColor") String color) {
RGB current = JFaceResources.getColorRegistry().getRGB(ComponentLabelProvider.NOT_VISIBLE_KEY);
@@ -1721,4 +1788,80 @@ public class ModelEditor {
}
}
+ @Override
+ public void gotoEObject(int targetHint, EObject object) {
+ if (object == null) {
+ // do nothing
+ } else {
+ switch (targetHint) {
+ case TAB_FORM:
+ // make sure tree node has been instantiated
+ ObservableListTreeContentProvider provider = (ObservableListTreeContentProvider) viewer.getContentProvider();
+ getFirstMatchingItem(object, provider, provider.getChildren(viewer.getInput()));
+
+ viewer.reveal(object);
+ viewer.setSelection(new StructuredSelection(object));
+ editorTabFolder.setSelection(0);
+ break;
+ case TAB_XMI:
+ editorTabFolder.setSelection(1);
+ // model was not updating in xmi document (selection listener
+ // was not firing from programatic setSelection()
+ emfDocumentProvider.updateFromEMF();
+
+ try {
+ // select the entire start tag
+ IRegion region = emfDocumentProvider.findStartTag(object);
+ if (region != null) {
+ sourceViewer.setSelection(new TextSelection(region.getOffset(), region.getLength()), true);
+ } 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()));
+ listTab.getViewer().setSelection(new StructuredSelection(object), true);
+ }
+ break;
+ default:
+ break;
+ }
+ // }
+ }
+ }
+
+ // This will ensure the provider has created the tree node (so we can reveal
+ // it).
+ private Object getFirstMatchingItem(EObject target, ObservableListTreeContentProvider provider, Object[] items) {
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] == target) {
+ return items[i];
+ }
+ Object found = getFirstMatchingItem(target, provider, provider.getChildren(items[i]));
+ if (found != null) {
+ return found;
+ }
+ }
+ return null;
+ }
+
}
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
new file mode 100644
index 00000000..4c30a06e
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeEditingSupport.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
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.swt.SWT;
+
+class EAttributeEditingSupport extends EditingSupport {
+
+ private String attName;
+ private TextCellEditor editor;
+ private TableViewer tableViewer;
+ private boolean wasNull;
+ private IEclipseContext context;
+
+ 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;
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return EmfUtil.getAttribute((EObject) element, attName) != null;
+ }
+
+ @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 {
+ wasNull = false;
+ }
+ return value;
+ }
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ EObject eObject = (EObject) element;
+ if (value.equals("") && wasNull) { //$NON-NLS-1$
+ value = null;
+ }
+ 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);
+ }
+
+} \ 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
new file mode 100644
index 00000000..63030ac5
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EAttributeTableViewerColumn.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
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * 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 {
+
+ public EAttributeTableViewerColumn(final TableViewer tvResults, String label, final String attName, final IEclipseContext context) {
+ TableViewerColumn tlc = new TableViewerColumn(tvResults, SWT.NONE);
+
+ tlc.getColumn().setText(label);
+ tlc.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ EObject eObject = (EObject) element;
+ EAttribute eAtt = EmfUtil.getAttribute(eObject, attName);
+ Object value;
+ if (eAtt != null) {
+ value = eObject.eGet(eAtt);
+ } else {
+ value = ""; //$NON-NLS-1$
+ }
+ 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);
+ }
+ }
+ });
+ tlc.setEditingSupport(new EAttributeEditingSupport(tvResults, attName, context));
+ }
+
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EmfUtil.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EmfUtil.java
new file mode 100644
index 00000000..36c1557d
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/EmfUtil.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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 org.eclipse.e4.tools.emf.ui.internal.Messages;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * Convenience methods for accessing EMF Objects
+ *
+ * @author Steven Spungin
+ *
+ */
+public class EmfUtil {
+ /**
+ * Returns the EAttribute with the given name for the specified object, or
+ * null if non-existent
+ *
+ * @param eObject
+ * @param attName
+ * @return the EAttribute with the given name for the specified object, or
+ * null if non-existent
+ */
+ static public EAttribute getAttribute(EObject eObject, String attName) {
+ if (attName == null || attName.isEmpty()) {
+ return null;
+ }
+ // return (EAttribute)
+ // eObject.eGet(eObject.eClass().getEStructuralFeature(attName));
+ for (EAttribute att : eObject.eClass().getEAllAttributes()) {
+ if (attName.equals(att.getName())) {
+ return att;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the EAttribute value with the given attribute name for the
+ * specified object. Returns null if the attribute is not define, or has
+ * null as the value.
+ *
+ * @param eObject
+ * @param attName
+ * @return the EAttribute value with the given attribute name for the
+ * specified object, Returns null if the attribute is not defined,
+ * or has null as the value.
+ */
+ static public Object getAttributeValue(EObject eObject, String attName) {
+ EAttribute att = getAttribute(eObject, attName);
+ if (att == null) {
+ return null;
+ } else {
+ return eObject.eGet(att);
+ }
+ }
+
+ /**
+ * Returns the EAttribute value with the given attribute name for the
+ * specified object. Throws if the attribute is not defined.
+ *
+ * @param eObject
+ * @param attName
+ * @return
+ * @throws Exception
+ */
+ static public Object getAttributeValueThrows(EObject eObject, String attName) throws Exception {
+ EAttribute att = getAttribute(eObject, attName);
+ if (att == null) {
+ throw new Exception(Messages.EmfUtil_ex_attribute_not_found + attName);
+ } else {
+ return eObject.eGet(att);
+ }
+ }
+} \ 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/IGotoObject.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IGotoObject.java
new file mode 100644
index 00000000..fecd0ee8
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IGotoObject.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
+ *******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * This interface allows a UI object to reveal and select an EMF object.
+ *
+ * @author Steven Spungin
+ *
+ */
+public interface IGotoObject {
+ /**
+ *
+ * @param targetHint
+ * An object specific hint used for resolution when the same
+ * object is available in multiple locations on the target.
+ * @param object
+ * the EObject to reveal, and select.
+ */
+ void gotoEObject(int targetHint, EObject object);
+}
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
new file mode 100644
index 00000000..24781744
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/IViewEObjects.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.Collection;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * This interface provides a common API for editing trees, lists, and xml
+ * editors that display EObjects.
+ *
+ * @author Steven Spungin
+ *
+ */
+public interface IViewEObjects {
+
+ /**
+ * Highlights the indicated items. Objects that are not managed are ignored.
+ * All other items are un-highlighted.
+ *
+ * @param items
+ * Collection of objects to highlight.
+ */
+ void highlightEObjects(Collection<EObject> items);
+
+ /**
+ * All EObjects that are managed by the view.
+ *
+ * @return All EObjects that are managed by the view's provider
+ */
+ Collection<EObject> getAllEObjects();
+
+ /**
+ * All EObjects that are selected by the view
+ *
+ * @return All EObjects that are selected by the view
+ */
+ Collection<EObject> getSelectedEObjects();
+
+ /**
+ * Deletes the objects specified.
+ *
+ * @param list
+ * The list of objects to delete. Objects that are not managed
+ * are ignored.
+ */
+ void deleteEObjects(Collection<EObject> list);
+}
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
new file mode 100644
index 00000000..a793a761
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ListTab.java
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * 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 java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+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.xml.EMFDocumentResourceMediator;
+import org.eclipse.e4.tools.services.IResourcePool;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.util.TreeIterator;
+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.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.IStructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Color;
+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;
+
+/**
+ * A tab that contains a list EObjects, and provides editable columns for
+ * EObject features.
+ *
+ * @author Steven Spungin
+ *
+ */
+public class ListTab implements IViewEObjects {
+
+ // The table will only include EObjects that define this attribute
+ private static final String FILTER_ATTRUBUTE_ID = "elementId"; //$NON-NLS-1$
+
+ ConcurrentHashMap<String, List<EObject>> mapId_Object = new ConcurrentHashMap<String, List<EObject>>();
+
+ @Inject
+ private IEclipseContext context;
+
+ @Inject
+ private IModelResource modelResource;
+
+ private TableViewer tvResults;
+
+ @Inject
+ private IGotoObject gotoObjectHandler;
+
+ @Inject
+ private IResourcePool resourcePool;
+
+ @Inject
+ MApplication app;
+
+ private CTabItem tabItem;
+
+ private ModelResourceContentProvider provider;
+
+ private IDocumentListener documentListener;
+
+ private Collection<?> highlightedItems;
+
+ @PreDestroy
+ public void preDestroy() {
+ // race condition issue with observables (exception is not thrown when
+ // break points are set)
+ tvResults.setContentProvider(ArrayContentProvider.getInstance());
+ context.get(EMFDocumentResourceMediator.class).getDocument().removeDocumentListener(documentListener);
+ }
+
+ @PostConstruct
+ public void postConstruct(final CTabFolder tabFolder) {
+
+ documentListener = new IDocumentListener() {
+
+ @Override
+ public void documentChanged(DocumentEvent event) {
+ reload();
+ }
+
+ @Override
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ }
+ };
+ context.get(EMFDocumentResourceMediator.class).getDocument().addDocumentListener(documentListener);
+
+ tabItem = new CTabItem(tabFolder, SWT.NONE);
+
+ Composite composite = new Composite(tabFolder, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setLayout(new GridLayout(2, false));
+ tabItem.setControl(composite);
+ tabItem.setText(Messages.ListTab_0);
+
+ tabItem.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_world_edit));
+ {
+ 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);
+ }
+
+ tvResults = new TableViewer(composite);
+ tvResults.getTable().setHeaderVisible(true);
+ tvResults.getTable().setLinesVisible(true);
+ // tvResults.setContentProvider(ArrayContentProvider.getInstance());
+
+ provider = new ModelResourceContentProvider();
+ tvResults.setContentProvider(provider);
+
+ tvResults.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ ((GridData) tvResults.getTable().getLayoutData()).horizontalSpan = 2;
+
+ final Image imgForm = resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_application_form);
+ final Image imgXmi = resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_chart_organisation);
+
+ final TableViewerColumn colGo = new TableViewerColumn(tvResults, SWT.NONE);
+ colGo.getColumn().setText(Messages.ListTab_col_go);
+
+ colGo.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public Image getImage(Object element) {
+ return imgForm;
+ }
+
+ @Override
+ public String getText(Object element) {
+ return ""; //$NON-NLS-1$
+ }
+ });
+
+ final TableViewerColumn colGoXmi = new TableViewerColumn(tvResults, SWT.NONE);
+ colGoXmi.getColumn().setText(Messages.ListTab_col_go);
+
+ colGoXmi.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return ""; //$NON-NLS-1$
+ };
+
+ @Override
+ public Image getImage(Object element) {
+ return imgXmi;
+ };
+ });
+
+ tvResults.getTable().addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ if (TableViewerUtil.isColumnClicked(tvResults, e, colGo)) {
+ gotoObjectHandler.gotoEObject(ModelEditor.TAB_FORM, (EObject) TableViewerUtil.getData(tvResults, e));
+ } else if (TableViewerUtil.isColumnClicked(tvResults, e, colGoXmi)) {
+ gotoObjectHandler.gotoEObject(ModelEditor.TAB_XMI, (EObject) TableViewerUtil.getData(tvResults, e));
+ }
+ }
+ });
+
+ TableViewerColumn colItem = new TableViewerColumn(tvResults, SWT.NONE);
+ colItem.getColumn().setText(Messages.ListTab_col_item);
+ colItem.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ EObject eObject = (EObject) element;
+ return super.getText(eObject.eClass().getName());
+ }
+ });
+
+ 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() {
+ @Override
+ public String getText(Object element) {
+ EObject eObject = (EObject) element;
+ EAttribute eAtt = EmfUtil.getAttribute(eObject, FILTER_ATTRUBUTE_ID);
+ return super.getText(eObject.eGet(eAtt));
+ }
+
+ @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);
+ }
+ 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$
+
+ reload();
+ }
+
+ public void reload() {
+ tvResults.setInput(modelResource);
+ TableViewerUtil.refreshAndPack(tvResults);
+ }
+
+ public TableViewer getViewer() {
+ return tvResults;
+ }
+
+ public CTabItem getTabItem() {
+ return tabItem;
+ }
+
+ public IEclipseContext getContext() {
+ return context;
+ }
+
+ @Override
+ public void highlightEObjects(Collection<EObject> items) {
+ highlightedItems = items;
+ tvResults.refresh();
+ }
+
+ @Override
+ public List<EObject> getAllEObjects() {
+ ArrayList<EObject> list = new ArrayList<EObject>();
+ TreeIterator<Object> itTree = EcoreUtil.getAllContents(modelResource.getRoot());
+ while (itTree.hasNext()) {
+ Object object = itTree.next();
+ EObject eObject = (EObject) object;
+ EAttribute att = EmfUtil.getAttribute(eObject, "elementId"); //$NON-NLS-1$
+ if (att != null) {
+ list.add(eObject);
+ }
+ }
+ return list;
+ }
+
+ @Override
+ public Collection<EObject> getSelectedEObjects() {
+ ArrayList<EObject> selected = new ArrayList<EObject>();
+ for (Object item : ((IStructuredSelection) tvResults.getSelection()).toList()) {
+ if (item instanceof EObject) {
+ selected.add((EObject) item);
+
+ }
+ }
+ return selected;
+ }
+
+ @Override
+ public void deleteEObjects(Collection<EObject> list) {
+ if (list.isEmpty() == false) {
+ Command cmd = DeleteCommand.create(modelResource.getEditingDomain(), list);
+ if (cmd.canExecute()) {
+ modelResource.getEditingDomain().getCommandStack().execute(cmd);
+ }
+ reload();
+ }
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ModelResourceContentProvider.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ModelResourceContentProvider.java
new file mode 100644
index 00000000..1f3db3a4
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/ModelResourceContentProvider.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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 org.eclipse.e4.tools.emf.ui.common.IModelResource;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class ModelResourceContentProvider implements IStructuredContentProvider {
+
+ private Object[] items = new Object[0];
+ private EContentAdapter adapter;
+ private Viewer viewer;
+
+ public ModelResourceContentProvider() {
+ adapter = new EContentAdapter() {
+ @Override
+ public void notifyChanged(Notification notification) {
+ switch (notification.getEventType()) {
+ case Notification.REMOVING_ADAPTER:
+ return;
+ }
+
+ if (viewer != null && viewer.getControl().isDisposed() == false) {
+ viewer.refresh();
+ }
+ super.notifyChanged(notification);
+
+ // boolean optimize = false;
+ // switch (notification.getEventType()) {
+ //
+ // case Notification.SET:
+ // // optimized to only update row if SET and not elementId
+ // // if the id is modified, we need to reindex our id map
+ // // (by forcing input)
+ // if (notification.getFeature() != EmfUtil.getAttribute((EObject) notification.getFeature(), "elementId")) { //$NON-NLS-1$
+ // if (viewer instanceof TableViewer) {
+ // optimize = true;
+ // }
+ // }
+ // break;
+ // default:
+ // break;
+ // }
+ // if (optimize) {
+ // EClass eClass = (EClass) ((EAttribute)
+ // notification.getFeature()).eContainer();
+ // ((TableViewer) viewer).update(eClass, null);
+ // } else {
+ // viewer.setInput(viewer.getInput());
+ // }
+ }
+ };
+ }
+
+ @Override
+ public Object[] getElements(Object object) {
+ return items;
+ }
+
+ @Override
+ public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
+ this.viewer = viewer;
+ ArrayList<EObject> list = new ArrayList<EObject>();
+ IModelResource modelProvider = (IModelResource) newInput;
+ if (newInput != oldInput && newInput != null) {
+ ((EObject) modelProvider.getRoot().get(0)).eAdapters().add(adapter);
+ }
+ if (newInput != null) {
+ TreeIterator<Object> itTree = EcoreUtil.getAllContents(modelProvider.getRoot());
+ while (itTree.hasNext()) {
+ Object next = itTree.next();
+ EObject eObject = (EObject) next;
+ EAttribute att = EmfUtil.getAttribute(eObject, "elementId"); //$NON-NLS-1$
+ if (att != null) {
+ list.add(eObject);
+ }
+ }
+ }
+
+ items = list.toArray(new Object[0]);
+ }
+
+ @Override
+ public void dispose() {
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/TableViewerUtil.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/TableViewerUtil.java
new file mode 100644
index 00000000..252cffd5
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/tabs/TableViewerUtil.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.Arrays;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class TableViewerUtil {
+ static public void refreshAndPack(TableViewer viewer) {
+ viewer.refresh();
+ for (TableColumn col : viewer.getTable().getColumns()) {
+ col.pack();
+ }
+ }
+
+ static public void updateAndPack(TableViewer viewer, Object object) {
+ viewer.update(object, null);
+ for (TableColumn col : viewer.getTable().getColumns()) {
+ col.pack();
+ }
+ }
+
+ public static boolean isColumnClicked(TableViewer viewer, MouseEvent e, TableViewerColumn tvColumn) {
+ boolean ret;
+ ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
+ if (cell == null) {
+ ret = false;
+ } else {
+ int index = Arrays.asList(viewer.getTable().getColumns()).indexOf(tvColumn.getColumn());
+ if (index == -1) {
+ ret = false;
+ } else {
+ ret = index == cell.getColumnIndex();
+ }
+ }
+ return ret;
+ }
+
+ public static Object getData(TableViewer viewer, MouseEvent e) {
+ ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
+ if (cell == null) {
+ return null;
+ } else {
+ return cell.getElement();
+ }
+ }
+} \ 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/xml/EMFDocumentResourceMediator.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/xml/EMFDocumentResourceMediator.java
index 5889901a..9a4c036a 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/xml/EMFDocumentResourceMediator.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/xml/EMFDocumentResourceMediator.java
@@ -1,3 +1,8 @@
+/*******************************************************************************
+ * Contributors:
+ * Steven Spungin <steven@spungin.tv> - Bug 431735
+ *******************************************************************************/
+
package org.eclipse.e4.tools.emf.ui.internal.common.xml;
import java.io.IOException;
@@ -10,9 +15,12 @@ import org.eclipse.e4.tools.emf.ui.common.IModelResource;
import org.eclipse.e4.ui.internal.workbench.E4XMIResource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.IRegion;
import org.xml.sax.InputSource;
public class EMFDocumentResourceMediator {
@@ -92,4 +100,27 @@ public class EMFDocumentResourceMediator {
}
return writer.toString();
}
+
+ /**
+ * @param object
+ * @return The region for the start tag of the EObject, or null if not found.
+ */
+ public IRegion findStartTag(EObject object) {
+ if (object == null){
+ return null;
+ }
+ E4XMIResource root = (E4XMIResource) ((EObject) modelResource.getRoot().get(0)).eResource();
+ String xmiId = root.getID(object);
+
+ FindReplaceDocumentAdapter find = new FindReplaceDocumentAdapter(document);
+ IRegion region;
+ try {
+ //TODO This will not work if the element has '<' or '>' in an attribute value
+ region = find.find(0, "<.*?" + xmiId + ".*?>", true, true, false, true); //$NON-NLS-1$ //$NON-NLS-2$
+ return region;
+ } catch (BadLocationException e) {
+ return null;
+ }
+ }
+
}

Back to the top