diff options
author | Laurent Redor | 2014-04-10 12:50:27 +0000 |
---|---|---|
committer | Laurent Redor | 2014-04-16 14:43:20 +0000 |
commit | d777741471a5e4f9cb04e7e5356cb108a85feb12 (patch) | |
tree | e7884151893762329ada3d9cd64a0c1f14c14ff1 | |
parent | 976694c726d6a3147fddede1a5a883f5412465c6 (diff) | |
download | org.eclipse.sirius-d777741471a5e4f9cb04e7e5356cb108a85feb12.tar.gz org.eclipse.sirius-d777741471a5e4f9cb04e7e5356cb108a85feb12.tar.xz org.eclipse.sirius-d777741471a5e4f9cb04e7e5356cb108a85feb12.zip |
[430263] Replace the Sirius decorator by a more complete LabelProvider.
The current Sirius decorator ("org.eclipse.ui.decorators" extension
point) implies that if Sirius is installed, a large part of Sirius
plugins are getting loaded and started even if your are not using it.
This decorator adds a decorator on semantic resources of non Modeling
project. This is now done by the SiriusCommonLabelProvider.
Warning: If the Sirius Content Management is active (for example in
"Project Explorer"), Sirius plugins are getting loaded and started even
with this fix.
Bug: 430263
Change-Id: I7cc11ec343b54a12a58531c5eb366a88d5843987
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
7 files changed, 223 insertions, 144 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html index c23180479a..826d0cc6e8 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html @@ -285,6 +285,14 @@ <li>The behavior of method <code>org.eclipse.sirius.business.api.modelingproject.ModelingProject.getMainRepresentationsFileURI()</code> has changed. It now marks this project as invalid and adds a marker on it, if it is considered as invalid (no or many representations files). </li> + <li>A new query + <code>org.eclipse.sirius.business.api.query.IFileQuery</code> has been added with a method to check if file is handled by an opened session, ie: + <ul> + <li>a semantic resource of this session,</LI></li> + <li>a referenced sub representations file,</LI></li> + <li>a controlled resource.</li> + </ul> + </li> </ul> <h4 id="Changesinorg.eclipse.sirius.diagram">Changes in <code>org.eclipse.sirius.diagram</code> @@ -1321,4 +1329,4 @@ void removeSelectedView(DView view); </li> </ul> </body> -</html> +</html>
\ No newline at end of file diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile index 5d1acfdc86..d69b3277e3 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile @@ -79,6 +79,10 @@ h4. Changes in @org.eclipse.sirius@ * In class @org.eclipse.sirius.business.api.dialect.description.AbstractInterpretedExpressionQuery@, the protected methods @appendAllLocalVariableDefinitions()@ and @appendEditMaskVariables()@ now take a @Map<String, Collection<String>>@ instead of a Guava-specific @Multimap@. The new protected method @addDefinition()@ can be used to make it easier to add entries to the map. Subclasses in Sirius have been updated to match the new signature. * The message @org.eclipse.sirius.business.api.modelingproject.ModelingProject.ZERO_REPRESENTATIONS_FILE_FOUND_IN@ has been removed without replacement. It was not really an API constant. * The behavior of method @org.eclipse.sirius.business.api.modelingproject.ModelingProject.getMainRepresentationsFileURI()@ has changed. It now marks this project as invalid and adds a marker on it, if it is considered as invalid (no or many representations files). +* A new query @org.eclipse.sirius.business.api.query.IFileQuery@ has been added with a method to check if file is handled by an opened session, ie: +** a semantic resource of this session,</LI> +** a referenced sub representations file,</LI> +** a controlled resource. h4. Changes in @org.eclipse.sirius.diagram@ diff --git a/plugins/org.eclipse.sirius.ui/plugin.xml b/plugins/org.eclipse.sirius.ui/plugin.xml index 3d86177d32..17c311d6af 100644 --- a/plugins/org.eclipse.sirius.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.ui/plugin.xml @@ -276,28 +276,6 @@ </provider> </extension> <extension - point="org.eclipse.ui.decorators"> - <decorator - adaptable="false" - class="org.eclipse.sirius.ui.tools.internal.views.common.navigator.SessionLabelDecorator" - id="org.eclipse.sirius.ui.session.decorator" - label="Sirius Content Management" - lightweight="true" - location="TOP_RIGHT" - state="true"> - <enablement> - <or> - <objectClass - name="org.eclipse.core.resources.IFile"> - </objectClass> - <objectClass - name="org.eclipse.core.resources.IProject"> - </objectClass> - </or> - </enablement> - </decorator> - </extension> - <extension point="org.eclipse.ui.navigator.viewer"> <viewer viewerId="org.eclipse.sirius.ui.tools.views.model.explorer"> @@ -379,6 +357,13 @@ class="org.eclipse.sirius.ui.tools.internal.views.common.ResourceExtender" id="org.eclipse.sirius.ui.eobjectIResourceExtender"> </propertyTester> + <propertyTester + id="org.eclipse.sirius.ui.SemanticResourceFileTester" + type="org.eclipse.core.resources.IFile" + namespace="org.eclipse.sirius.ui" + properties="isSemanticResourceFileTester" + class="org.eclipse.sirius.ui.tools.internal.views.common.FileHandledByOpenedSessionTester"> + </propertyTester> </extension> <extension point="org.eclipse.ui.navigator.navigatorContent"> @@ -485,38 +470,63 @@ <instanceof value="org.eclipse.emf.ecore.resource.Resource"> </instanceof> - <adapt - type="org.eclipse.core.resources.IProject"> + <adapt type="org.eclipse.core.resources.IProject"> <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.sirius.nature.modelingproject"> </test> </adapt> <and> - <instanceof - value="org.eclipse.core.resources.IFile"> - </instanceof> + <instanceof value="org.eclipse.core.resources.IFile"/> <test forcePluginActivation="true" property="org.eclipse.sirius.ui.isFileForSessionTester"> </test> </and> + <and> + <not> + <adapt type="org.eclipse.core.resources.IProject"> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.sirius.nature.modelingproject"> + </test> + </adapt> + </not> + <instanceof value="org.eclipse.core.resources.IFile"/> + <test + forcePluginActivation="true" + property="org.eclipse.sirius.ui.isSemanticResourceFileTester"> + </test> + </and> </or> </possibleChildren> <triggerPoints> <or> <and> - <instanceof - value="org.eclipse.core.resources.IFile"> - </instanceof> + <instanceof value="org.eclipse.core.resources.IFile"/> <test forcePluginActivation="true" property="org.eclipse.sirius.ui.isFileForSessionTester"> </test> </and> <adapt type="org.eclipse.core.resources.IProject" > - <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.sirius.nature.modelingproject"/> - </adapt> + <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.sirius.nature.modelingproject"/> + </adapt> + <and> + <not> + <adapt type="org.eclipse.core.resources.IProject"> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.sirius.nature.modelingproject"> + </test> + </adapt> + </not> + <instanceof value="org.eclipse.core.resources.IFile"/> + <test + forcePluginActivation="true" + property="org.eclipse.sirius.ui.isSemanticResourceFileTester"> + </test> + </and> </or> </triggerPoints> </navigatorContent> diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileHandledByOpenedSessionTester.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileHandledByOpenedSessionTester.java new file mode 100644 index 0000000000..24bc6e7be6 --- /dev/null +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileHandledByOpenedSessionTester.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2014 THALES GLOBAL SERVICES. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.ui.tools.internal.views.common; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IFile; +import org.eclipse.sirius.business.api.query.IFileQuery; + +/** + * Property tester to check that an {@link IFile} is handled by an opened + * session, ie: + * <UL> + * <LI>a semantic resource of this session,</LI> + * <LI>a referenced sub representations file,</LI> + * <LI>a controlled resource.</LI> + * </UL> + * + * @author lredor + */ +public class FileHandledByOpenedSessionTester extends PropertyTester { + + /** + * Constructor. + */ + public FileHandledByOpenedSessionTester() { + } + + /** + * {@inheritDoc} + */ + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + boolean result = false; + if (receiver instanceof IFile) { + IFile file = (IFile) receiver; + result = new IFileQuery(file).isResourceHandledByOpenedSession(); + } + return result; + } +} diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SessionLabelDecorator.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SessionLabelDecorator.java deleted file mode 100644 index 1fd8941452..0000000000 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SessionLabelDecorator.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 THALES GLOBAL SERVICES. - * 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: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.sirius.ui.tools.internal.views.common.navigator; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IDecoration; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ILightweightLabelDecorator; -import org.eclipse.sirius.business.api.modelingproject.ModelingProject; -import org.eclipse.sirius.business.api.session.Session; -import org.eclipse.sirius.business.api.session.SessionManager; -import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject; -import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -import com.google.common.collect.Iterables; - -/** - * Label decorator for files handled by a session. - * - * @author mporhel - * - */ -public class SessionLabelDecorator implements ILightweightLabelDecorator { - - /** - * Id of the decorator. - */ - public static final String ID = "org.eclipse.sirius.ui.session.decorator"; - - /** - * Default image descriptor for the error overlay. - */ - public static final ImageDescriptor VIEWPOINT_OVERLAY_DESC = AbstractUIPlugin.imageDescriptorFromPlugin(SiriusEditPlugin.ID, "/icons/full/ovr16/SessionDecorator.gif"); //$NON-NLS-1$; - - /** - * {@inheritDoc} - */ - public void addListener(ILabelProviderListener listener) { - } - - /** - * {@inheritDoc} - */ - public void dispose() { - } - - /** - * {@inheritDoc} - */ - public boolean isLabelProperty(Object element, String property) { - return true; - } - - /** - * {@inheritDoc} - */ - public void removeListener(ILabelProviderListener listener) { - - } - - /** - * {@inheritDoc} - */ - public void decorate(Object element, IDecoration decoration) { - - if (element instanceof IFile) { - IFile file = (IFile) element; - IProject project = ((IFile) element).getProject(); - - /* - * do not decorate if the project has the modeling nature as each - * model file in the project will be automatically added to the - * session. We may provide in the future a decorator to indicate a - * file that was not correcty loaded. - */ - if (ModelingProject.hasModelingProjectNature(project)) { - return; - } - - URI fileURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true); - for (Session session : SessionManager.INSTANCE.getSessions()) { - if (session.isOpen() && fileURI != null) { - // Do not decorate main aird with image - Iterable<Resource> handledResources = Iterables.concat(session.getSemanticResources(), session.getReferencedSessionResources()); - if (session instanceof DAnalysisSessionEObject) { - handledResources = Iterables.concat(handledResources, ((DAnalysisSessionEObject) session).getControlledResources()); - } - - for (Resource res : handledResources) { - if (res.getURI().equals(fileURI)) { - decoration.addOverlay(VIEWPOINT_OVERLAY_DESC); - } - } - } - } - } - } -} diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonLabelProvider.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonLabelProvider.java index ded132aeba..51fd66ef08 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonLabelProvider.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonLabelProvider.java @@ -17,11 +17,15 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DecorationOverlayIcon; import org.eclipse.jface.viewers.IColorProvider; +import org.eclipse.jface.viewers.IDecoration; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.sirius.business.api.helper.SiriusUtil; import org.eclipse.sirius.business.api.modelingproject.ModelingProject; +import org.eclipse.sirius.business.api.query.IFileQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionStatus; import org.eclipse.sirius.ext.base.Option; @@ -40,8 +44,10 @@ import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IMemento; +import org.eclipse.ui.model.IWorkbenchAdapter; import org.eclipse.ui.navigator.ICommonContentExtensionSite; import org.eclipse.ui.navigator.ICommonLabelProvider; +import org.eclipse.ui.plugin.AbstractUIPlugin; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; @@ -55,6 +61,11 @@ import com.google.common.collect.Lists; */ public class SiriusCommonLabelProvider implements ICommonLabelProvider, IColorProvider { + /** + * Default image descriptor for the "Sirius Modeling" overlay. + */ + public static final ImageDescriptor SIRIUS_MODELING_OVERLAY_DESC = AbstractUIPlugin.imageDescriptorFromPlugin(SiriusEditPlugin.ID, "/icons/full/ovr16/SessionDecorator.gif"); //$NON-NLS-1$; + private static final String DIRTY = "*"; private ILabelProvider sessionLabelProvider; @@ -87,6 +98,37 @@ public class SiriusCommonLabelProvider implements ICommonLabelProvider, IColorPr // which transaction has just been closed // Nothing to do, null will returned } + } else if (element instanceof IFile) { + // This file is not in a ModelingProject (check in + // <possibleChildren> and <triggerPoints> of + // "org.eclipse.ui.navigator.navigatorContent" of plugin.xml) + IFile file = (IFile) element; + + if (new IFileQuery(file).isResourceHandledByOpenedSession()) { + // Add "Sirius Modeling" overlay on this semantic file. + String fileExtension = file.getFileExtension(); + // Create a key to store/restore the image in image registry of + // SiriusEditPlugin + String imgKey = fileExtension + "Decorated"; + // Get the existing image (if any) + img = SiriusEditPlugin.getPlugin().getImageRegistry().get(imgKey); + // If the image has already been computed, use it. + if (img == null) { + // Get the base image to overlay + ImageDescriptor imageDescriptor = null; + IWorkbenchAdapter wbAdapter = (IWorkbenchAdapter) file.getAdapter(IWorkbenchAdapter.class); + if (wbAdapter != null) { + imageDescriptor = wbAdapter.getImageDescriptor(file); + } + if (imageDescriptor != null) { + // Add an overlay with the "Sirius Modeling" overlay + ImageDescriptor[] imageDescriptors = new ImageDescriptor[5]; + imageDescriptors[IDecoration.TOP_RIGHT] = SIRIUS_MODELING_OVERLAY_DESC; + img = new DecorationOverlayIcon(imageDescriptor.createImage(), imageDescriptors).createImage(); + SiriusEditPlugin.getPlugin().getImageRegistry().put(imgKey, img); + } + } + } } return img; } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/IFileQuery.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/IFileQuery.java new file mode 100644 index 0000000000..e97cfd1381 --- /dev/null +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/IFileQuery.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2014 THALES GLOBAL SERVICES. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.business.api.query; + +import java.util.Iterator; + +import org.eclipse.core.resources.IFile; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.business.api.session.SessionManager; +import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject; + +import com.google.common.collect.Iterables; + +/** + * A class aggregating all the queries (read-only!) having a {@link IFile} as a + * starting point. + * + * @author lredor + * + */ +public class IFileQuery { + + private IFile file; + + /** + * Constructor. + * + * @param file + * the file to check + */ + public IFileQuery(IFile file) { + this.file = file; + } + + /** + * Check if this file is handled by an opened session, ie: + * <UL> + * <LI>a semantic resource of this session,</LI> + * <LI>a referenced sub representations file,</LI> + * <LI>a controlled resource.</LI> + * </UL> + * Tip: This method returns false for the main representations file of a + * session. + * + * @return true if this file is handled by an opened session, false + * otherwise. + */ + public boolean isResourceHandledByOpenedSession() { + boolean result = false; + URI fileURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true); + for (Session session : SessionManager.INSTANCE.getSessions()) { + if (session.isOpen() && fileURI != null) { + + Iterable<Resource> handledResources = Iterables.concat(session.getSemanticResources(), session.getReferencedSessionResources()); + if (session instanceof DAnalysisSessionEObject) { + handledResources = Iterables.concat(handledResources, ((DAnalysisSessionEObject) session).getControlledResources()); + } + + for (Iterator<Resource> iterator = handledResources.iterator(); iterator.hasNext() && !result; /* */) { + Resource res = iterator.next(); + if (fileURI.equals(res.getURI())) { + result = true; + } + } + } + } + return result; + } +} |