summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhubner2008-10-30 08:53:45 (EDT)
committerdhubner2008-10-30 08:53:45 (EDT)
commit711470ef01a61551dae52358c9f44a0d57becce9 (patch)
tree0c948f627ba4a84e31a10460ac3ebf5dd556c6e9
parentdd816d531653fe6904dc9f445e9a1558678c9f1d (diff)
downloadorg.eclipse.xpand-711470ef01a61551dae52358c9f44a0d57becce9.zip
org.eclipse.xpand-711470ef01a61551dae52358c9f44a0d57becce9.tar.gz
org.eclipse.xpand-711470ef01a61551dae52358c9f44a0d57becce9.tar.bz2
Show Errors and Wrnings in the tree
-rw-r--r--examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF3
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/error.gifbin0 -> 82 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/icons/warning_co.gifbin0 -> 116 bytes
-rw-r--r--examples/org.eclipse.emf.generic.editor/plugin.xml4
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java25
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java98
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/MarkerHandler.java82
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java48
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/DecoratingItemLabelProvider.java41
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java54
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java76
-rw-r--r--examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java28
12 files changed, 304 insertions, 155 deletions
diff --git a/examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF b/examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF
index 4cdd526..1dc18a4 100644
--- a/examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF
+++ b/examples/org.eclipse.emf.generic.editor/META-INF/MANIFEST.MF
@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.xtend,
org.eclipse.xtend.typesystem.emf,
org.eclipse.jdt.core;bundle-version="3.4.2",
- org.eclipse.xtend.shared.ui
+ org.eclipse.xtend.shared.ui,
+ org.eclipse.emf.ecore.xmi;bundle-version="2.4.1"
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.emf.editor,
org.eclipse.emf.editor.extxpt,
diff --git a/examples/org.eclipse.emf.generic.editor/icons/error.gif b/examples/org.eclipse.emf.generic.editor/icons/error.gif
new file mode 100644
index 0000000..119dccc
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/error.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/icons/warning_co.gif b/examples/org.eclipse.emf.generic.editor/icons/warning_co.gif
new file mode 100644
index 0000000..3af228c
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/icons/warning_co.gif
Binary files differ
diff --git a/examples/org.eclipse.emf.generic.editor/plugin.xml b/examples/org.eclipse.emf.generic.editor/plugin.xml
index a18f52f..ef8de43 100644
--- a/examples/org.eclipse.emf.generic.editor/plugin.xml
+++ b/examples/org.eclipse.emf.generic.editor/plugin.xml
@@ -29,10 +29,6 @@
priority="high">
<describer
class="org.eclipse.emf.ecore.xmi.impl.XMLContentHandlerImpl$XMI$Describer">
- <parameter
- name="org.eclipse.emf.generic.editor.parameter1"
- value="org.eclipse.emf.generic.editor.parameter1">
- </parameter>
</describer>
</content-type>
</extension>
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java
index 766dd97..0dad1ca 100644
--- a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEPlugin.java
@@ -18,7 +18,6 @@ package org.eclipse.emf.editor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.editor.ui.ImageRegistry;
-import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
@@ -30,7 +29,7 @@ import org.osgi.framework.BundleContext;
*/
public class EEPlugin extends AbstractUIPlugin {
// The plug-in ID
- public static final String PLUGIN_ID = "org.openarchitectureware.emf.generic.editor";
+ public static final String PLUGIN_ID = "org.eclipse.emf.generic.editor";
// The shared instance
private static EEPlugin plugin;
@@ -44,7 +43,9 @@ public class EEPlugin extends AbstractUIPlugin {
/*
* (non-Javadoc)
*
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
*/
@Override
public void start(BundleContext context) throws Exception {
@@ -52,16 +53,12 @@ public class EEPlugin extends AbstractUIPlugin {
plugin = this;
}
- @Override
- public IPreferenceStore getPreferenceStore() {
- // TODO Auto-generated method stub
- return super.getPreferenceStore();
- }
-
/*
* (non-Javadoc)
*
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
*/
@Override
public void stop(BundleContext context) throws Exception {
@@ -91,18 +88,16 @@ public class EEPlugin extends AbstractUIPlugin {
* the path
* @return the image descriptor
*/
- public static ImageDescriptor getImageDescriptor(String path) {
+ public ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
public static void logError(String string, Throwable e) {
- getDefault().getLog().log(
- new Status(IStatus.ERROR, PLUGIN_ID, string, e));
+ getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, string, e));
}
public static void logWarning(String string) {
- getDefault().getLog().log(
- new Status(IStatus.WARNING, EEPlugin.PLUGIN_ID, string));
+ getDefault().getLog().log(new Status(IStatus.WARNING, EEPlugin.PLUGIN_ID, string));
}
public static void logError(String string) {
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java
index 5c068e9..77029da 100644
--- a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/EEditor.java
@@ -15,20 +15,16 @@
*/
package org.eclipse.emf.editor;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
-import java.util.Map;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
@@ -41,6 +37,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.editor.extxpt.ExtXptFacade;
import org.eclipse.emf.editor.extxpt.WorkspaceResourceManager;
+import org.eclipse.emf.editor.provider.DecoratingItemLabelProvider;
import org.eclipse.emf.editor.provider.ExtendedLabelProvider;
import org.eclipse.emf.editor.provider.ExtendedReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.editor.provider.ExtendedReflectiveItemProviderAdapterFactory.ExtendedReflectiveItemProvider;
@@ -49,9 +46,9 @@ import org.eclipse.emf.editor.ui.EEMasterDetailsBlock;
import org.eclipse.emf.editor.ui.ImageRegistry;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -61,7 +58,7 @@ import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.IMessage;
import org.eclipse.ui.forms.IMessageManager;
@@ -83,7 +80,6 @@ import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;
public class EEditor extends EcoreEditor implements ChangeListener {
private static final String ESTRUCTURALFEATURE_KEY = EcorePackage.Literals.ESTRUCTURAL_FEATURE.getName();
- protected static final String MARKER_ID = Activator.getId() + ".problem";
private ManagedForm managedForm;
private EEMasterDetailsBlock mdBlock;
@@ -110,13 +106,15 @@ public class EEditor extends EcoreEditor implements ChangeListener {
*
*/
private void rejectFactory(ComposedAdapterFactory caf) {
- // REMOVE reflective factory
+ // REMOVE reflective factory for EObjects
caf.removeAdapterFactory(caf.getFactoryForType(EcorePackage.eINSTANCE.getEFactoryInstance().create(
EcorePackage.Literals.EOBJECT)));
// ADD extended factory
ExtendedLabelProvider customProvider = new ExtendedLabelProvider(facade);
+ ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
+
ExtendedReflectiveItemProviderAdapterFactory extendedReflectiveItemProviderAdapterFactory = new ExtendedReflectiveItemProviderAdapterFactory(
- customProvider);
+ new DecoratingItemLabelProvider(customProvider, decorator),facade);
caf.addAdapterFactory(extendedReflectiveItemProviderAdapterFactory);
// register item provider for details view
@@ -160,18 +158,19 @@ public class EEditor extends EcoreEditor implements ChangeListener {
getSite().getShell().getDisplay().syncExec(new Runnable() {
public void run() {
- Object object = null;
Control c = null;
for (IMessage message : messages) {
- object = ((List<?>) message.getData()).get(0);
- if (object != null) {
- getViewer().setSelection(new StructuredSelection(object), true);
- }
- if (message.getData() instanceof Map) {
- EStructuralFeature f = (EStructuralFeature) ((List<?>) message.getData())
- .get(1);
- if (f != null) {
- c = mdBlock.findControl(ESTRUCTURALFEATURE_KEY, f);
+ if (message.getData() instanceof Collection<?>) {
+ List<?> data = (List<?>) message.getData();
+ Object object = data.get(0);
+ if (object != null) {
+ getViewer().setSelection(new StructuredSelection(object), true);
+ }
+ if (data.size() > 1) {
+ EStructuralFeature f = (EStructuralFeature) data.get(1);
+ if (f != null) {
+ c = mdBlock.findControl(ESTRUCTURALFEATURE_KEY, f);
+ }
}
}
break;
@@ -198,7 +197,7 @@ public class EEditor extends EcoreEditor implements ChangeListener {
checkModel();
}
};
- action.setImageDescriptor(EEPlugin.getImageDescriptor("icons/complete_task.gif"));
+ action.setImageDescriptor(EEPlugin.getDefault().getImageDescriptor("icons/complete_task.gif"));
toolBarManager.add(action);
}
};
@@ -234,6 +233,7 @@ public class EEditor extends EcoreEditor implements ChangeListener {
private void initInternal() {
project = getFile().getProject();
facade = createExtXptFacade();
+
if (editingDomain.getAdapterFactory() instanceof ComposedAdapterFactory) {
ComposedAdapterFactory caf = (ComposedAdapterFactory) editingDomain.getAdapterFactory();
rejectFactory(caf);
@@ -264,20 +264,16 @@ public class EEditor extends EcoreEditor implements ChangeListener {
}
}
- /**
- *
- */
public void checkModel() {
- final List<MessageData> messages = new ModelCheckor(facade).check(getEditingDomain().getResourceSet());
+ final List<MessageData> messages = new ModelCheckor(facade).check(getEditingDomain(), getFile());
getSite().getShell().getDisplay().asyncExec(new Runnable() {
+
public void run() {
IMessageManager messageManager = managedForm.getMessageManager();
messageManager.removeMessages();
messageManager.setAutoUpdate(false);
for (MessageData md : messages) {
messageManager.addMessage(md.getKey(), md.getMessage(), md.getData(), md.getStatus());
- if (getFile() != null)
- addMarker(getFile(), md.getMessage(), md.getStatus());
}
messageManager.update();
messageManager.setAutoUpdate(true);
@@ -285,40 +281,6 @@ public class EEditor extends EcoreEditor implements ChangeListener {
});
}
- private void addMarker(final IFile file, final String message, final int severity) {
- try {
- new WorkspaceModifyOperation() {
-
- @Override
- protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException,
- InterruptedException {
-
- try {
- // FIXME own MarkerType
- IMarker marker = file.createMarker(MARKER_ID);
- marker.setAttribute(IMarker.MESSAGE, message);
- int status = IMarker.SEVERITY_INFO;
- switch (severity) {
- case IMessageProvider.ERROR:
- status = IMarker.SEVERITY_ERROR;
- break;
- case IMessageProvider.WARNING:
- status = IMarker.SEVERITY_WARNING;
- break;
- }
- marker.setAttribute(IMarker.SEVERITY, status);
- }
- catch (CoreException e) {
- e.printStackTrace();
- }
- }
- }.run(new NullProgressMonitor());
- }
- catch (final Exception e) {
- e.printStackTrace();
- }
- }
-
private ExtXptFacade createExtXptFacade() {
final List<EPackage> packs = findMetaModelPackages();
TypeSystemImpl ts = new TypeSystemImpl();
@@ -356,11 +318,20 @@ public class EEditor extends EcoreEditor implements ChangeListener {
return (IFile) getEditorInput().getAdapter(IFile.class);
}
+ /**
+ * @return
+ */
public ExtendedReflectiveItemProvider getExtendedReflectiveItemProvider() {
-
return extendedReflectiveItemProvider;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent
+ * )
+ */
public void stateChanged(ChangeEvent e) {
Display.getDefault().asyncExec(new Runnable() {
@@ -370,6 +341,9 @@ public class EEditor extends EcoreEditor implements ChangeListener {
});
}
+ /**
+ * @return
+ */
public ExtXptFacade getExtXptFacade() {
return facade;
}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/MarkerHandler.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/MarkerHandler.java
new file mode 100644
index 0000000..f9cfafe
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/MarkerHandler.java
@@ -0,0 +1,82 @@
+package org.eclipse.emf.editor;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.xtend.shared.ui.Activator;
+
+/**
+ * @author Dennis Hübner - Initial contribution and API
+ *
+ */
+public class MarkerHandler {
+ protected static final String MARKER_ID = Activator.getId() + ".problem";
+
+ void deleteMarkers(final IResource resource, IProgressMonitor monitor) {
+ checkResource(resource);
+ run(new WorkspaceModifyOperation(ResourcesPlugin.getWorkspace().getRuleFactory().markerRule(resource)) {
+ @Override
+ protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException,
+ InterruptedException {
+ resource.deleteMarkers(MARKER_ID, true, IResource.DEPTH_INFINITE);
+ }
+ }, monitor);
+ }
+
+ private void checkResource(final IResource resource) {
+ Assert.isLegal(resource != null);
+ Assert.isLegal(resource.exists(), "Can't handle Marker for a non existing resource '" + resource.getFullPath()
+ + "'");
+ Assert.isLegal(!resource.getResourceAttributes().isReadOnly(), "Can't handle Marker for read only resource'"
+ + resource.getFullPath() + "'");
+ }
+
+ private void run(WorkspaceModifyOperation workspaceModifyOperation, IProgressMonitor monitor) {
+ try {
+ workspaceModifyOperation.run(monitor);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ void addMarker(final IFile file, final String message, final int severity) {
+ checkResource(file);
+ run(new WorkspaceModifyOperation() {
+
+ @Override
+ protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException,
+ InterruptedException {
+
+ try {
+ // FIXME own MarkerType
+ IMarker marker = file.createMarker(MARKER_ID);
+ marker.setAttribute(IMarker.MESSAGE, message);
+ int status = IMarker.SEVERITY_INFO;
+ switch (severity) {
+ case IMessageProvider.ERROR:
+ status = IMarker.SEVERITY_ERROR;
+ break;
+ case IMessageProvider.WARNING:
+ status = IMarker.SEVERITY_WARNING;
+ break;
+ }
+ marker.setAttribute(IMarker.SEVERITY, status);
+ }
+ catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }, new NullProgressMonitor());
+ }
+
+} \ No newline at end of file
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java
index c582fd8..5d4ed7d 100644
--- a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ModelCheckor.java
@@ -19,6 +19,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.EList;
@@ -28,6 +30,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil;
import org.eclipse.emf.editor.extxpt.ExtXptFacade;
import org.eclipse.emf.editor.extxpt.ExtXptHelper;
@@ -40,6 +43,7 @@ import org.eclipse.jface.dialogs.IMessageProvider;
*
*/
public class ModelCheckor {
+ private MarkerHandler markerHandler = new MarkerHandler();
private EclipseResourcesUtil eclipseResourcesUtil = EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE ? new EclipseResourcesUtil()
: null;
@@ -50,29 +54,32 @@ public class ModelCheckor {
this.facade = facade;
}
- public List<MessageData> check(ResourceSet toCheck) {
+ public List<MessageData> check(EditingDomain ed, IFile file) {
+ ResourceSet toCheck = ed.getResourceSet();
List<MessageData> messages = new ArrayList<MessageData>();
+ markerHandler.deleteMarkers(file, new NullProgressMonitor());
try {
// get copy
EList<Resource> resources = toCheck.getResources();
if (resources != null) {
-
for (Resource res : resources) {
+ // Clear Marker
+ if (eclipseResourcesUtil != null) {
+ eclipseResourcesUtil.deleteMarkers(res);
+ }
TreeIterator<EObject> allContents = res.getAllContents();
if (!allContents.hasNext())
continue;
-
EObject rootObject = allContents.next();
- Issues issues = facade.check(rootObject);
- for (MWEDiagnostic issue : issues.getErrors()) {
- messages.add(createMessageFromIssue(issue, IMessageProvider.ERROR));
- }
- for (MWEDiagnostic issue : issues.getWarnings()) {
- messages.add(createMessageFromIssue(issue, IMessageProvider.WARNING));
+ // xtend checks
+ List<MessageData> checkValidation = checkValidation(rootObject);
+ for (MessageData md : checkValidation) {
+ markerHandler.addMarker(file, md.getMessage(), md.getStatus());
}
- List<MessageData> ecoreValidation = ecoreValidation(rootObject);
- messages.addAll(ecoreValidation);
+ // ecore
+ messages.addAll(checkValidation);
+ messages.addAll(ecoreValidation(rootObject));
}
}
}
@@ -87,13 +94,20 @@ public class ModelCheckor {
return messages;
}
- private List<MessageData> ecoreValidation(EObject rootObject) {
- int status = IMessageProvider.INFORMATION;
- // Clear Marker
- if (eclipseResourcesUtil != null) {
- //eclipseResourcesUtil.deleteMarkers(rootObject);
+ private List<MessageData> checkValidation(EObject root) {
+ List<MessageData> messages = new ArrayList<MessageData>();
+ Issues issues = facade.check(root);
+ for (MWEDiagnostic issue : issues.getErrors()) {
+ messages.add(createMessageFromIssue(issue, IMessageProvider.ERROR));
}
+ for (MWEDiagnostic issue : issues.getWarnings()) {
+ messages.add(createMessageFromIssue(issue, IMessageProvider.WARNING));
+ }
+ return messages;
+ }
+ private List<MessageData> ecoreValidation(EObject rootObject) {
+ int status = IMessageProvider.INFORMATION;
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(rootObject);
switch (diagnostic.getSeverity()) {
@@ -147,6 +161,8 @@ public class ModelCheckor {
}
}
md.setData(data);
+
return md;
}
+
} \ No newline at end of file
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/DecoratingItemLabelProvider.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/DecoratingItemLabelProvider.java
new file mode 100644
index 0000000..48bdca4
--- /dev/null
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/DecoratingItemLabelProvider.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2008 itemis AG (http://www.itemis.eu) 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
+ *
+ *******************************************************************************/
+package org.eclipse.emf.editor.provider;
+
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.ILabelDecorator;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Dennis Hübner - Initial contribution and API
+ *
+ */
+public class DecoratingItemLabelProvider extends DecoratingLabelProvider implements IItemLabelProvider {
+
+ public DecoratingItemLabelProvider(final IItemLabelProvider provider, ILabelDecorator decorator) {
+ super(new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return provider.getText(element);
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ Object im = provider.getImage(element);
+
+ if (im instanceof Image)
+ return (Image) im;
+
+ return super.getImage(element);
+ }
+ }, decorator);
+ }
+}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java
index b1e1c31..6846c80 100644
--- a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedLabelProvider.java
@@ -56,20 +56,22 @@ public class ExtendedLabelProvider implements IItemLabelProvider {
if (element instanceof EObject) {
EObject eObject = (EObject) element;
String iconName = evaluate(eObject, ICON_EXTENSION_NAME);
- Resource eResource = eObject.eClass().eResource();
// TODO try instance scope
- // retVal = locateImage(iconName, eObject.eResource(), eObject);
+ retVal = locateImage(iconName, eObject.eResource(), eObject);
// if not found try metamodel scope
+ Resource eResource = eObject.eClass().eResource();
if (retVal == null && iconName != null)
retVal = locateImage(iconName, eResource, eObject);
}
- } catch (Throwable ex) {
+ }
+ catch (Throwable ex) {
EEPlugin.logError("ERROR", ex);
}
- if (retVal != null)
- return retVal;
- // Fallback: Ask registry for image
- return registryItemLabelProvider.getImage(element);
+ if (retVal == null) {
+ // Fallback: Ask registry for image
+ retVal = registryItemLabelProvider.getImage(element);
+ }
+ return retVal;
}
@@ -81,8 +83,8 @@ public class ExtendedLabelProvider implements IItemLabelProvider {
* @throws MalformedURLException
* @throws IOException
*/
- private Object locateImage(String iconName, Resource eResource,
- EObject eObject) throws MalformedURLException, IOException {
+ private Object locateImage(String iconName, Resource eResource, EObject eObject) throws MalformedURLException,
+ IOException {
// TODO understand the requirements :)
Object retVal = null;
if (eResource != null) {
@@ -93,36 +95,32 @@ public class ExtendedLabelProvider implements IItemLabelProvider {
// platform resource... good
String platformString = metaModelURI.toPlatformString(true);
- IFile metaModelFile = ResourcesPlugin.getWorkspace().getRoot()
- .getFile(new Path(platformString));
+ IFile metaModelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformString));
if (metaModelFile != null) {
// using IFile to allow resource change listening
- IFile f = metaModelFile.getProject()
- .getFile(iconURI.path());
+ IFile f = metaModelFile.getProject().getFile(iconURI.path());
if (f != null && f.exists()) {
// ask registry
retVal = ImageRegistry.getDefault().getImage(f);
}
}
- } else if (metaModelURI.isArchive()) {// archived
+ }
+ else if (metaModelURI.isArchive()) {// archived
// handle archived resources
// return URI. Image will be stored in
// ExtendedImageRegistry
// which is not refreshable
if (checkAccessable(iconURI))
retVal = iconURI;
- } else {
+ }
+ else {
// eResource not present physically... bad
- URI classpathURI = URI
- .createURI(ClasspathUriResolver.CLASSPATH_SCHEME + ":"
- + iconURI.path());
- URI iconNormalizedURI = new ClasspathUriResolver().resolve(
- facade.getProject(), classpathURI);
+ URI classpathURI = URI.createURI(ClasspathUriResolver.CLASSPATH_SCHEME + ":" + iconURI.path());
+ URI iconNormalizedURI = new ClasspathUriResolver().resolve(facade.getProject(), classpathURI);
// return URI. Image will be stored in
// ExtendedImageRegistry
// which is not refreshable
- if (!ClasspathUriResolver.isClassapthUri(iconNormalizedURI)
- && checkAccessable(iconNormalizedURI))
+ if (!ClasspathUriResolver.isClassapthUri(iconNormalizedURI) && checkAccessable(iconNormalizedURI))
retVal = iconNormalizedURI;
}
}
@@ -136,7 +134,8 @@ public class ExtendedLabelProvider implements IItemLabelProvider {
InputStream in = url.openStream();// check readable
in.close();
return true;
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
// ignore no feedback to user
}
}
@@ -151,15 +150,16 @@ public class ExtendedLabelProvider implements IItemLabelProvider {
*/
private URI createIconURI(EObject eObject, String iconName, URI metaModelURI) {
String packageName = packageName(eObject);
- return metaModelURI.trimSegments(metaModelURI.segmentCount())
- .appendSegment(ICONS_FOLDER).appendSegment(packageName)
- .appendSegment(iconName);
+ return metaModelURI.trimSegments(metaModelURI.segmentCount()).appendSegment(ICONS_FOLDER).appendSegment(
+ packageName).appendSegment(iconName);
}
/*
* (non-Javadoc)
*
- * @see org.eclipse.emf.edit.provider.IItemLabelProvider#getText(java.lang.Object)
+ * @see
+ * org.eclipse.emf.edit.provider.IItemLabelProvider#getText(java.lang.Object
+ * )
*/
public String getText(Object element) {
String text = evaluate(element, LABEL_EXTENSION_NAME);
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java
index 38d9ce7..0e6b166 100644
--- a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/provider/ExtendedReflectiveItemProviderAdapterFactory.java
@@ -17,25 +17,45 @@ package org.eclipse.emf.editor.provider;
*/
import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.ReflectiveItemProvider;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
+import org.eclipse.emf.editor.EEPlugin;
+import org.eclipse.emf.editor.extxpt.ExtXptFacade;
+import org.eclipse.emf.mwe.core.issues.MWEDiagnostic;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.DecorationOverlayIcon;
+import org.eclipse.jface.viewers.IDecoration;
+import org.eclipse.swt.graphics.Image;
/**
* @author Dennis Huebner
*
*/
-public class ExtendedReflectiveItemProviderAdapterFactory extends
- ReflectiveItemProviderAdapterFactory {
+public class ExtendedReflectiveItemProviderAdapterFactory extends ReflectiveItemProviderAdapterFactory {
- public final class ExtendedReflectiveItemProvider extends
- ReflectiveItemProvider {
- private final ExtendedLabelProvider labelProvider;
+ private final ExtXptFacade facade;
+
+ public ExtendedReflectiveItemProviderAdapterFactory(final DecoratingLabelProvider decoratingLabelProvider,
+ ExtXptFacade facade) {
+ super();
+ this.facade = facade;
+ reflectiveItemProviderAdapter = new ExtendedReflectiveItemProvider(this, decoratingLabelProvider);
+ }
+
+ public final class ExtendedReflectiveItemProvider extends ReflectiveItemProvider {
+ private final DecoratingLabelProvider labelProvider;
private ExtendedReflectiveItemProvider(AdapterFactory adapterFactory,
- ExtendedLabelProvider labelProvider) {
+ DecoratingLabelProvider decoratingLabelProvider) {
super(adapterFactory);
- this.labelProvider = labelProvider;
+ this.labelProvider = decoratingLabelProvider;
}
public String getTextForFeature(EStructuralFeature feature) {
@@ -55,21 +75,45 @@ public class ExtendedReflectiveItemProviderAdapterFactory extends
return text;
}
+ protected Image annotateImage(Image image, Diagnostic diag) {
+ ImageDescriptor[] descriptors = new ImageDescriptor[5];
+ if (diag.getSeverity() == Diagnostic.ERROR)
+ descriptors[IDecoration.BOTTOM_LEFT] = EEPlugin.getDefault().getImageDescriptor("/icons/error.gif");
+ if (diag.getSeverity() == Diagnostic.WARNING)
+ descriptors[IDecoration.BOTTOM_RIGHT] = EEPlugin.getDefault().getImageDescriptor("/icons/warning_co.gif");
+ image = getImageManager().createImage(new DecorationOverlayIcon(image, descriptors));
+ return image;
+
+ }
+
+ private org.eclipse.jface.resource.ResourceManager getImageManager() {
+
+ return new LocalResourceManager(JFaceResources.getResources());
+ }
+
@Override
public Object getImage(Object object) {
Object imURI = labelProvider.getImage(object);
- if (imURI != null) {
- return imURI;
+ if (imURI == null)
+ imURI = super.getImage(object);
+ Image im = ExtendedImageRegistry.getInstance().getImage(imURI);
+ if (im != null) {
+ if (object instanceof EObject) {
+ MWEDiagnostic[] errors = facade.check((EObject) object).getIssues();
+ if (errors.length > 0) {
+ for (MWEDiagnostic diag : errors) {
+ if (object.equals(diag.getElement())) {
+ im = annotateImage(im, diag);
+ break;
+ }
+ }
+ }
+ }
+ return im;
}
- return super.getImage(object);
+ return imURI;
}
- }
- public ExtendedReflectiveItemProviderAdapterFactory(
- final ExtendedLabelProvider labelProvider) {
- super();
- reflectiveItemProviderAdapter = new ExtendedReflectiveItemProvider(
- this, labelProvider);
}
}
diff --git a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java
index c3f2396..8a43817 100644
--- a/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java
+++ b/examples/org.eclipse.emf.generic.editor/src/org/eclipse/emf/editor/ui/EEMasterDetailsBlock.java
@@ -56,21 +56,20 @@ public class EEMasterDetailsBlock extends MasterDetailsBlock {
/*
* (non-Javadoc)
*
- * @see org.eclipse.ui.forms.MasterDetailsBlock#createMasterPart(org.eclipse.ui.forms.IManagedForm,
- * org.eclipse.swt.widgets.Composite)
+ * @see
+ * org.eclipse.ui.forms.MasterDetailsBlock#createMasterPart(org.eclipse.
+ * ui.forms.IManagedForm, org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createMasterPart(IManagedForm managedForm, Composite parent) {
Composite container = managedForm.getToolkit().createComposite(parent);
container.setLayout(new GridLayout());
// container.setLayoutData(new GridData(GridData.FILL_VERTICAL));
- Section section = managedForm.getToolkit().createSection(container,
- ExpandableComposite.TITLE_BAR);
+ Section section = managedForm.getToolkit().createSection(container, ExpandableComposite.TITLE_BAR);
section.setLayout(new FillLayout());
section.setLayoutData(new GridData(GridData.FILL_BOTH));
section.setText("Model");
- Composite mastersClientArea = managedForm.getToolkit().createComposite(
- section);
+ Composite mastersClientArea = managedForm.getToolkit().createComposite(section);
section.setClient(mastersClientArea);
masterSectionPart = new SectionPart(section);
managedForm.addPart(masterSectionPart);
@@ -79,7 +78,9 @@ public class EEMasterDetailsBlock extends MasterDetailsBlock {
/*
* (non-Javadoc)
*
- * @see org.eclipse.ui.forms.MasterDetailsBlock#createToolBarActions(org.eclipse.ui.forms.IManagedForm)
+ * @see
+ * org.eclipse.ui.forms.MasterDetailsBlock#createToolBarActions(org.eclipse
+ * .ui.forms.IManagedForm)
*/
@Override
protected void createToolBarActions(IManagedForm managedForm) {
@@ -96,8 +97,7 @@ public class EEMasterDetailsBlock extends MasterDetailsBlock {
haction.setChecked(sashForm.getOrientation() == SWT.VERTICAL);
haction.setToolTipText("Horizontal orientation");
- haction.setImageDescriptor(EEPlugin
- .getImageDescriptor("/icons/det_pane_under.gif"));
+ haction.setImageDescriptor(EEPlugin.getDefault().getImageDescriptor("/icons/det_pane_under.gif"));
Action vaction = new Action("ver", IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
@@ -108,8 +108,7 @@ public class EEMasterDetailsBlock extends MasterDetailsBlock {
vaction.setChecked(sashForm.getOrientation() == SWT.HORIZONTAL);
vaction.setToolTipText("Vertical orientation");
- vaction.setImageDescriptor(EEPlugin
- .getImageDescriptor("/icons/det_pane_right.gif"));
+ vaction.setImageDescriptor(EEPlugin.getDefault().getImageDescriptor("/icons/det_pane_right.gif"));
form.getToolBarManager().add(haction);
form.getToolBarManager().add(vaction);
createMoreToolBarActions(form.getToolBarManager());
@@ -125,7 +124,9 @@ public class EEMasterDetailsBlock extends MasterDetailsBlock {
/*
* (non-Javadoc)
*
- * @see org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.forms.DetailsPart)
+ * @see
+ * org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.
+ * forms.DetailsPart)
*/
@Override
protected void registerPages(DetailsPart detailsPart) {
@@ -135,8 +136,7 @@ public class EEMasterDetailsBlock extends MasterDetailsBlock {
public Control findControl(String key, Object data) {
if (detailsPart.getCurrentPage() instanceof GenericDetailsPage) {
- return ((GenericDetailsPage) detailsPart.getCurrentPage())
- .locateControl(key, data);
+ return ((GenericDetailsPage) detailsPart.getCurrentPage()).locateControl(key, data);
}
return null;
}