Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers')
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/ISubresourceFileActionProvider.java76
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/OneFileDecorator.java173
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/OneFileModelProvider.java62
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusContentProvider.java268
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusLabelProvider.java67
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusModelActionProvider.java316
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusViewerSorter.java54
7 files changed, 1016 insertions, 0 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/ISubresourceFileActionProvider.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/ISubresourceFileActionProvider.java
new file mode 100644
index 00000000000..4150e690090
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/ISubresourceFileActionProvider.java
@@ -0,0 +1,76 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin Integration.
+ *
+ * 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:
+ * Tristan Faure (Atos Origin) tristan.faure@ato.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.providers;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider;
+
+
+/**
+ * An edit action provider to provide Copy/Paste/Delete on sub resources
+ *
+ * @author Tristan Faure
+ *
+ */
+@SuppressWarnings("restriction")
+public class ISubresourceFileActionProvider extends EditActionProvider {
+
+ @Override
+ public void setContext(ActionContext context) {
+ // TODO Auto-generated method stub
+ List<Object> resources = new LinkedList<Object>();
+ if(context.getSelection() instanceof IStructuredSelection) {
+ IStructuredSelection contextSelec = (IStructuredSelection)context.getSelection();
+ for(Iterator<?> i = contextSelec.iterator(); i.hasNext();) {
+ Object o = i.next();
+ IResource res = adapt(o, IResource.class);
+ if(res != null) {
+ resources.add(res);
+ }
+ }
+ }
+ if(!resources.isEmpty()) {
+ ISelection selec = new StructuredSelection(resources);
+ super.setContext(new ActionContext(selec));
+ } else {
+ super.setContext(context);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T adapt(Object o, Class<T> aClass) {
+ T result = null;
+ if(aClass.isInstance(o)) {
+ result = (T)o;
+ }
+ if(o instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable)o;
+ result = (T)adaptable.getAdapter(aClass);
+ }
+ if(result == null) {
+ result = (T)Platform.getAdapterManager().getAdapter(o, aClass);
+ }
+
+ return result;
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/OneFileDecorator.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/OneFileDecorator.java
new file mode 100644
index 00000000000..07192e3e340
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/OneFileDecorator.java
@@ -0,0 +1,173 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin Integration.
+ *
+ * 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:
+ * Tristan FAURE (Atos) tristan.faure@atos.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.providers;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IDecoration;
+import org.eclipse.jface.viewers.IDecorationContext;
+import org.eclipse.jface.viewers.ILightweightLabelDecorator;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.eclipse.ui.internal.decorators.DecorationBuilder;
+
+
+/**
+ * This decorator computes decoration of related files
+ * for each decoration an intersection is made
+ * and the {@link IPapyrusFile} will have the same decoration of the set
+ *
+ * @author tfaure
+ *
+ */
+@SuppressWarnings("restriction")
+public class OneFileDecorator extends LabelProvider implements ILightweightLabelDecorator {
+
+ public void decorate(Object element, IDecoration decoration) {
+ if(element instanceof IPapyrusFile) {
+ IPapyrusFile papy = (IPapyrusFile)element;
+ IResource[] associatedResources = papy.getAssociatedResources();
+ FilteredDecorationBuilder builder = new FilteredDecorationBuilder(decoration.getDecorationContext(), associatedResources.length);
+ for(IResource r : associatedResources) {
+ WorkbenchPlugin.getDefault().getDecoratorManager().getLightweightManager().getDecorations(r, builder);
+ }
+ builder.handleDecoration(decoration);
+ }
+ }
+
+ /**
+ * The builder which intercepts decoration
+ *
+ * @author tfaure
+ *
+ */
+ protected class FilteredDecorationBuilder extends DecorationBuilder {
+
+ /** overlay, prefix and suffixes can be several so the number of occurences is saved */
+ private Map<ImageDescriptor, Integer> overlay = new HashMap<ImageDescriptor, Integer>();
+
+
+ private Map<String, Integer> prefixString = new HashMap<String, Integer>();
+
+
+ private Map<String, Integer> suffixString = new HashMap<String, Integer>();
+
+
+ private Color bgColor = null;
+
+ private boolean flagBgColor = false;
+
+ private Font newFont = null;
+
+ private boolean flagNewFont = false;
+
+ private Color fgColor = null;
+
+ private boolean flagFgColor = false;
+
+ private final int nbResource;
+
+ public FilteredDecorationBuilder(IDecorationContext context, int nbResource) {
+ super(context);
+ this.nbResource = nbResource;
+ }
+
+ public void addOverlay(ImageDescriptor overlay) {
+ Integer result = this.overlay.get(overlay);
+ if(result == null) {
+ result = 0;
+ }
+ result++;
+ this.overlay.put(overlay, result);
+ }
+
+ public void addPrefix(String prefixString) {
+ Integer result = this.prefixString.get(prefixString);
+ if(result == null) {
+ result = 0;
+ }
+ result++;
+ this.prefixString.put(prefixString, result);
+ }
+
+ public void addSuffix(String suffixString) {
+ Integer result = this.suffixString.get(suffixString);
+ if(result == null) {
+ result = 0;
+ }
+ result++;
+ this.suffixString.put(suffixString, result);
+ }
+
+ public void setBackgroundColor(Color bgColor) {
+ if(this.bgColor == null && !flagBgColor) {
+ this.bgColor = bgColor;
+ flagBgColor = true;
+ } else if(this.bgColor != null && !this.bgColor.equals(bgColor)) {
+ this.bgColor = null;
+ }
+ }
+
+ public void setFont(Font newFont) {
+ if(this.newFont == null && !flagNewFont) {
+ this.newFont = newFont;
+ flagNewFont = true;
+ } else if(this.newFont != null && !this.newFont.equals(newFont)) {
+ this.newFont = null;
+ }
+ }
+
+ public void setForegroundColor(Color fgColor) {
+ if(this.fgColor == null && !flagFgColor) {
+ this.fgColor = fgColor;
+ flagFgColor = true;
+ } else if(this.fgColor != null && !this.fgColor.equals(fgColor)) {
+ this.fgColor = null;
+ }
+ }
+
+ public void handleDecoration(IDecoration decoration) {
+ if(fgColor != null) {
+ decoration.setForegroundColor(fgColor);
+ }
+ if(bgColor != null) {
+ decoration.setBackgroundColor(bgColor);
+ }
+ if(newFont != null) {
+ decoration.setFont(newFont);
+ }
+ for(ImageDescriptor desc : overlay.keySet()) {
+ if(overlay.get(desc) == nbResource) {
+ decoration.addOverlay(desc);
+ }
+ }
+ for(String s : prefixString.keySet()) {
+ if(prefixString.get(s) == nbResource) {
+ decoration.addPrefix(s);
+ }
+ }
+ for(String s : suffixString.keySet()) {
+ if(suffixString.get(s) == nbResource) {
+ decoration.addSuffix(s);
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/OneFileModelProvider.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/OneFileModelProvider.java
new file mode 100644
index 00000000000..d5be4b85394
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/OneFileModelProvider.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin Integration.
+ *
+ * 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:
+ * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.providers;
+
+import org.eclipse.core.internal.resources.mapping.SimpleResourceMapping;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ModelProvider;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.resources.mapping.ResourceMappingContext;
+import org.eclipse.core.resources.mapping.ResourceTraversal;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.papyrus.infra.onefile.model.mapping.PapyrusResourceMapping;
+import org.eclipse.papyrus.infra.onefile.utils.OneFileUtils;
+
+@SuppressWarnings("restriction")
+public class OneFileModelProvider extends ModelProvider {
+
+ public static String MODEL_PROVIDER_ID = "org.eclipse.papyrus.infra.onefile.modelProvider";
+
+ public OneFileModelProvider() {
+ }
+
+ public ResourceMapping[] getMappings(IResource resource, ResourceMappingContext context, IProgressMonitor monitor) {
+ if(OneFileUtils.isDi(resource)) {
+ return new ResourceMapping[]{ new PapyrusResourceMapping((IFile)resource) };
+ }
+ return new ResourceMapping[]{ new SimpleResourceMapping(resource) };
+ }
+
+ @Override
+ public ResourceMapping[] getMappings(IResource[] resources, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ return super.getMappings(resources, context, monitor);
+ }
+
+ @Override
+ public ResourceTraversal[] getTraversals(ResourceMapping[] mappings, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ return super.getTraversals(mappings, context, monitor);
+ }
+
+ @Override
+ public ResourceMapping[] getMappings(ResourceTraversal[] traversals, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
+ return super.getMappings(traversals, context, monitor);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Object getAdapter(Class adapter) {
+ return super.getAdapter(adapter);
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusContentProvider.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusContentProvider.java
new file mode 100644
index 00000000000..ff36d321448
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusContentProvider.java
@@ -0,0 +1,268 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin Integration.
+ *
+ * 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:
+ * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.providers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.onefile.matcher.OnlyDiFilter;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.papyrus.infra.onefile.model.PapyrusModelHelper;
+import org.eclipse.papyrus.infra.onefile.utils.OneFileUtils;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * Content provider able to retrieve Papyrus children from an {@link IContainer}
+ *
+ * @author Tristan FAURE
+ *
+ */
+public class PapyrusContentProvider extends WorkbenchContentProvider {
+
+
+ private CommonViewer common;
+
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ super.inputChanged(viewer, oldInput, newInput);
+ if(viewer instanceof CommonViewer) {
+ common = (CommonViewer)viewer;
+ }
+ }
+
+ /**
+ * Determine if the current navigator is filtered or not
+ *
+ * @return true if the viewer is filtered
+ */
+ public boolean isFiltered() {
+ return common != null && common.getNavigatorContentService() != null && common.getNavigatorContentService().getFilterService() != null && common.getNavigatorContentService().getFilterService().isActive(OnlyDiFilter.FILTER_ID);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof IWorkspaceRoot) {
+ return null;
+ }
+ List<Object> result = new LinkedList<Object>();
+ try {
+ if(isFiltered()) {
+ if(inputElement instanceof IPapyrusFile) {
+ IPapyrusFile file = (IPapyrusFile)inputElement;
+ for(IResource r : file.getAssociatedResources()) {
+ result.add(PapyrusModelHelper.getPapyrusModelFactory().createISubResourceFile(file, (IFile)r));
+ }
+ } else {
+ IResource[] members = null;
+ if(inputElement instanceof IContainer) {
+ members = ((IContainer)inputElement).members();
+ }
+ if(members != null) {
+ for(IResource r : members) {
+ if(r instanceof IContainer && !(r instanceof IProject)) {
+ IContainer cont = (IContainer)r;
+ result.add(cont);
+ } else if(r instanceof IFile) {
+ if(OneFileUtils.isDi(r)) {
+ IPapyrusFile createIPapyrusFile = PapyrusModelHelper.getPapyrusModelFactory().createIPapyrusFile((IFile)r);
+ result.add(createIPapyrusFile);
+ } else {
+ if(!OneFileUtils.diExists(r.getName(), r.getParent())) {
+ result.add(r);
+ }
+ }
+ } else {
+ result.add(r);
+ }
+ }
+ }
+ }
+
+ }
+ } catch (CoreException e) {
+ }
+ return result.isEmpty() ? null : result.toArray();
+ }
+
+ public Object[] getChildren(Object inputElement) {
+ return getElements(inputElement);
+ }
+
+ public Object getParent(Object element) {
+ if(element instanceof IPapyrusFile) {
+ IPapyrusFile papyFile = (IPapyrusFile)element;
+ return papyFile.getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return OneFileUtils.hasChildren(element);
+ }
+
+ @Override
+ protected void processDelta(IResourceDelta delta) {
+ super.processDelta(delta);
+ if(!isFiltered()) {
+ return;
+ }
+ Control ctrl = common.getControl();
+ if(ctrl == null || ctrl.isDisposed()) {
+ return;
+ }
+
+
+ final Collection<Runnable> runnables = new ArrayList<Runnable>();
+ processPapyrusDelta(delta, runnables);
+
+ if(runnables.isEmpty()) {
+ return;
+ }
+
+ //Are we in the UIThread? If so spin it until we are done
+ ctrl.getDisplay().asyncExec(new Runnable() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ //Abort if this happens after disposes
+ Control ctrl = common.getControl();
+ if(ctrl == null || ctrl.isDisposed()) {
+ return;
+ }
+ runUpdates(runnables);
+ }
+ });
+
+ }
+
+ private void runUpdates(Collection<?> runnables) {
+ Iterator<?> runnableIterator = runnables.iterator();
+ while(runnableIterator.hasNext()) {
+ ((Runnable)runnableIterator.next()).run();
+ }
+
+ }
+
+ protected void processPapyrusDelta(IResourceDelta delta, Collection<Runnable> runnables) {
+ IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED);
+
+ // Handle changed children .
+ for(int i = 0; i < affectedChildren.length; i++) {
+ processPapyrusDelta(affectedChildren[i], runnables);
+ }
+
+ IResourceDelta[] addedChildren = delta.getAffectedChildren(IResourceDelta.ADDED);
+
+ final Object[] addedObjects;
+
+ // Process additions before removals as to not cause selection
+ // preservation prior to new objects being added
+ // Handle added children. Issue one update for all insertions.
+ if(addedChildren.length > 0) {
+ addedObjects = new Object[addedChildren.length];
+ for(int i = 0; i < addedChildren.length; i++) {
+ addedObjects[i] = addedChildren[i].getResource();
+ }
+ } else {
+ addedObjects = new Object[0];
+ }
+
+ // Handle removed children. Issue one update for all removals.
+ // heuristic test for items moving within same folder (i.e. renames)
+ Runnable addAndRemove = new Runnable() {
+
+ public void run() {
+ if(common instanceof AbstractTreeViewer) {
+ AbstractTreeViewer treeViewer = (AbstractTreeViewer)common;
+ // Disable redraw until the operation is finished so we don't
+ // get a flash of both the new and old item (in the case of
+ // rename)
+ // Only do this if we're both adding and removing files (the
+ // rename case)
+ try {
+ // need to handle resource addition
+ if(addedObjects.length > 0) {
+ ArrayList<IPapyrusFile> elements = new ArrayList<IPapyrusFile>(addedObjects.length);
+ ArrayList<IPapyrusFile> toAdd = new ArrayList<IPapyrusFile>(addedObjects.length);
+ for(Object r : addedObjects) {
+ if(r instanceof IResource) {
+ IResource current = (IResource)r;
+ if(OneFileUtils.diExists(current.getName(), current.getParent())) {
+ elements.add(PapyrusModelHelper.getPapyrusModelFactory().createIPapyrusFile(OneFileUtils.getDi(current.getName(), current.getParent())));
+ }
+ if(OneFileUtils.isDi(current)) {
+ toAdd.add(PapyrusModelHelper.getPapyrusModelFactory().createIPapyrusFile((IFile)current));
+ }
+ }
+ }
+ for(Object o : elements) {
+ common.refresh(o);
+ }
+ for(IPapyrusFile o : toAdd) {
+ common.add(o.getParent(), o);
+ }
+ }
+ } finally {
+
+ }
+ }
+ }
+ };
+ runnables.add(addAndRemove);
+ }
+
+ // @Override
+ // protected ITreeContentProvider getDelegateContentProvider() {
+ // if(provider == null) {
+ // provider = new WorkbenchContentProvider();
+ // }
+ // return provider;
+ // }
+ //
+ // @Override
+ // protected String getModelProviderId() {
+ // return OneFileModelProvider.MODEL_PROVIDER_ID;
+ // }
+ //
+ // @Override
+ // protected Object getModelRoot() {
+ // return null;
+ // }
+
+ // @Override
+ // protected ResourceTraversal[] getTraversals(ISynchronizationContext context, Object object) {
+ // return null;
+ // }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusLabelProvider.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusLabelProvider.java
new file mode 100644
index 00000000000..b1b4a45581f
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusLabelProvider.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin Integration.
+ *
+ * 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:
+ * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.providers;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.papyrus.infra.onefile.model.ISubResourceFile;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Label Provider for Papyrus Model Elements
+ *
+ * @author tristan.faure@atosorigin.com
+ *
+ */
+public class PapyrusLabelProvider implements ILabelProvider {
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return true;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ public Image getImage(Object element) {
+ if (element instanceof IPapyrusFile) {
+ IPapyrusFile papyFile = (IPapyrusFile) element;
+ return papyFile.getImage();
+ }
+ if (element instanceof ISubResourceFile) {
+ return ((ISubResourceFile) element).getImage();
+ }
+ return null;
+ }
+
+ public String getText(Object element) {
+ if (element instanceof IPapyrusFile) {
+ IPapyrusFile papyFile = (IPapyrusFile) element;
+ return papyFile.getText();
+ }
+ if (element instanceof ISubResourceFile) {
+ return ((ISubResourceFile) element).getText();
+ }
+ if (element instanceof IResource) {
+ return ((IResource) element).getName();
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusModelActionProvider.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusModelActionProvider.java
new file mode 100644
index 00000000000..82654f67490
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusModelActionProvider.java
@@ -0,0 +1,316 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin Integration.
+ *
+ * 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:
+ * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.providers;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.papyrus.infra.onefile.utils.OneFileUtils;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchCommandConstants;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.CopyResourceAction;
+import org.eclipse.ui.actions.DeleteResourceAction;
+import org.eclipse.ui.actions.MoveResourceAction;
+import org.eclipse.ui.actions.RefreshAction;
+import org.eclipse.ui.actions.RenameResourceAction;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
+import org.eclipse.ui.navigator.CommonActionProvider;
+import org.eclipse.ui.navigator.ICommonActionConstants;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.eclipse.ui.navigator.ICommonMenuConstants;
+import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
+
+/**
+ * Actions available through an {@link IPapyrusFile}
+ *
+ * @author tfaure
+ *
+ */
+@SuppressWarnings({ "restriction", "rawtypes" })
+public class PapyrusModelActionProvider extends CommonActionProvider {
+
+ private boolean fInViewPart = false;
+
+ private ICommonViewerWorkbenchSite workbenchSite;
+
+ private Action openAction;
+
+ private Action deleteAction;
+
+ private Action copyAction;
+
+ private Action renameAction;
+
+ private Action refreshAction;
+
+ private Action moveAction;
+
+ public PapyrusModelActionProvider() {
+
+ }
+
+ @Override
+ protected boolean filterAction(IAction action) {
+ return super.filterAction(action);
+ }
+
+ @Override
+ public void fillActionBars(IActionBars actionBars) {
+ if(fInViewPart) {
+ actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, openAction);
+ actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteAction);
+ actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);
+ actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), moveAction);
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
+ actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
+
+ }
+ super.fillActionBars(actionBars);
+ }
+
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ super.fillContextMenu(menu);
+ appendToGroup(menu, openAction, ICommonMenuConstants.GROUP_OPEN);
+ appendToGroup(menu, deleteAction, ICommonMenuConstants.GROUP_EDIT);
+ appendToGroup(menu, moveAction, ICommonMenuConstants.GROUP_EDIT);
+ appendToGroup(menu, copyAction, ICommonMenuConstants.GROUP_EDIT);
+ appendToGroup(menu, renameAction, ICommonMenuConstants.GROUP_EDIT);
+ appendToGroup(menu, refreshAction, ICommonMenuConstants.GROUP_EDIT);
+ }
+
+ private void appendToGroup(IMenuManager menu, IAction action, String id) {
+ if(action != null && action.isEnabled()) {
+ menu.appendToGroup(id, action);
+ }
+ }
+
+ @Override
+ public void init(ICommonActionExtensionSite site) {
+ if(site.getViewSite() instanceof ICommonViewerWorkbenchSite) {
+ workbenchSite = (ICommonViewerWorkbenchSite)site.getViewSite();
+ }
+ if(workbenchSite != null) {
+ if(workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
+ fInViewPart = true;
+ }
+ makeActions();
+ }
+ }
+
+ private void makeActions() {
+ final IWorkbenchPartSite provider = workbenchSite.getSite();
+ final ActionHelper helper = new ActionHelper();
+ openAction = new Action() {
+
+ @Override
+ public void run() {
+ if(getIFile() != null) {
+ try {
+ IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), getIFile(), true);
+ } catch (WorkbenchException e) {
+ }
+ }
+ }
+
+ public IFile getIFile() {
+ return helper.getIFile(getContext());
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return getIFile() != null;
+ }
+
+ @Override
+ public String getText() {
+ return IDEWorkbenchMessages.OpenFileAction_text;
+ }
+ };
+
+ deleteAction = new DeleteResourceAction(provider) {
+
+ @Override
+ public boolean isEnabled() {
+ return getSelectedResources() != null && getSelectedResources().size() > 0 && OneFileUtils.isDi((IResource)getSelectedResources().get(0));
+
+ }
+
+ @Override
+ public IStructuredSelection getStructuredSelection() {
+ return helper.getOneStructuredSelection(getContext());
+ }
+
+ @Override
+ protected List getSelectedResources() {
+ return helper.getOneSelectedResources(getContext());
+ }
+ };
+
+ moveAction = new MoveResourceAction(provider) {
+
+ @Override
+ public IStructuredSelection getStructuredSelection() {
+ return helper.getStructuredSelection(getContext());
+ }
+
+ @Override
+ protected List getSelectedResources() {
+ return helper.getSelectedResources(getContext());
+ }
+ };
+
+ copyAction = new CopyResourceAction(provider) {
+
+ @Override
+ public IStructuredSelection getStructuredSelection() {
+ return helper.getStructuredSelection(getContext());
+ }
+
+ @Override
+ protected List getSelectedResources() {
+ return helper.getSelectedResources(getContext());
+ }
+ };
+
+ renameAction = new RenameResourceAction(provider) {
+
+ @Override
+ public IStructuredSelection getStructuredSelection() {
+ IStructuredSelection selec = helper.getOneStructuredSelection(getContext());
+ return selec != null ? selec : super.getStructuredSelection();
+ }
+
+ @Override
+ protected List getSelectedResources() {
+ return helper.getOneSelectedResources(getContext());
+ }
+
+ };
+
+ refreshAction = new RefreshAction(provider) {
+
+ @Override
+ public void run() {
+ super.run();
+ }
+
+ };
+
+ makeAction(openAction, ICommonActionConstants.OPEN, ISharedImages.IMG_TOOL_COPY, ISharedImages.IMG_TOOL_COPY_DISABLED);
+ makeAction(deleteAction, IWorkbenchCommandConstants.EDIT_DELETE, ISharedImages.IMG_TOOL_DELETE, ISharedImages.IMG_TOOL_DELETE_DISABLED);
+ makeAction(moveAction, ActionFactory.MOVE.getId(), null, null);
+ makeAction(copyAction, IWorkbenchCommandConstants.EDIT_CUT, ISharedImages.IMG_TOOL_CUT, ISharedImages.IMG_TOOL_CUT_DISABLED);
+ makeAction(copyAction, IWorkbenchCommandConstants.EDIT_COPY, ISharedImages.IMG_TOOL_COPY, ISharedImages.IMG_TOOL_COPY_DISABLED);
+ makeAction(refreshAction, ActionFactory.REFRESH.getCommandId(), null, null);
+ }
+
+ protected void makeAction(Action action, String id, String imgTool, String imgToolDisabled) {
+ if(action != null) {
+ ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
+ if(id != null) {
+ action.setId(id);
+ action.setActionDefinitionId(id);
+ }
+ if(imgTool != null) {
+ action.setImageDescriptor(images.getImageDescriptor(imgTool));
+ }
+ if(imgToolDisabled != null) {
+ action.setDisabledImageDescriptor(images.getImageDescriptor(imgToolDisabled));
+ }
+ }
+ }
+
+ public static class ActionHelper {
+
+ public IStructuredSelection getStructuredSelection(ActionContext context) {
+ return new StructuredSelection(getSelectedResources(context));
+ }
+
+ public List getOneSelectedResources(ActionContext context) {
+ List selectedResources = getSelectedResources(context);
+ if(selectedResources.size() > 0) {
+ for(Iterator<?> i = selectedResources.iterator(); i.hasNext();) {
+ Object o = i.next();
+ if(o instanceof IFile) {
+ IFile file = (IFile)o;
+ if(!OneFileUtils.isDi(file)) {
+ i.remove();
+ }
+ }
+ }
+ return selectedResources;
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ public IStructuredSelection getOneStructuredSelection(ActionContext context) {
+ List selectedResources = getOneSelectedResources(context);
+ if(selectedResources.size() > 0) {
+ return new StructuredSelection(selectedResources);
+ }
+ return null;
+ }
+
+ protected List getSelectedResources(ActionContext context) {
+ ISelection selec = context.getSelection();
+ List<IResource> resources = new ArrayList<IResource>();
+ if(selec instanceof IStructuredSelection) {
+ IStructuredSelection struc = (IStructuredSelection)selec;
+ for(Iterator<Object> i = struc.iterator(); i.hasNext();) {
+ Object o = i.next();
+ if(o instanceof IPapyrusFile) {
+ IPapyrusFile papy = (IPapyrusFile)o;
+ resources.addAll(Arrays.asList(papy.getAssociatedResources()));
+ }
+ }
+ }
+ return resources;
+ }
+
+ public IFile getIFile(ActionContext context) {
+ ISelection selec = context.getSelection();
+ if(selec instanceof IStructuredSelection) {
+ IStructuredSelection struc = (IStructuredSelection)selec;
+ Object firstElement = struc.getFirstElement();
+ if(firstElement instanceof IFile) {
+ IFile file = (IFile)firstElement;
+ return file;
+ } else if(firstElement instanceof IPapyrusFile) {
+ return (IFile)((IPapyrusFile)firstElement).getMainFile();
+ }
+ }
+ return null;
+ }
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusViewerSorter.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusViewerSorter.java
new file mode 100644
index 00000000000..d23d9d1acb5
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/providers/PapyrusViewerSorter.java
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin Integration.
+ *
+ * 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:
+ * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.providers;
+
+import java.text.Collator;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.ui.views.navigator.ResourceComparator;
+
+/**
+ * Sort Papyrus Files according to their Main File
+ *
+ * @author tristan.faure@atosorigin.com
+ */
+public class PapyrusViewerSorter extends ViewerSorter {
+
+ /**
+ * {@link ResourceComparator} for comparison delegation
+ */
+ ResourceComparator comp = new ResourceComparator(ResourceComparator.TYPE);
+
+ public PapyrusViewerSorter() {
+ super();
+ }
+
+ public PapyrusViewerSorter(Collator collator) {
+ super(collator);
+ }
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ if (e1 instanceof IPapyrusFile) {
+ IPapyrusFile papyrusFile = (IPapyrusFile) e1;
+ e1 = papyrusFile.getMainFile();
+ }
+ if (e2 instanceof IPapyrusFile) {
+ IPapyrusFile papyrusFile = (IPapyrusFile) e2;
+ e2 = papyrusFile.getMainFile();
+ }
+ return comp.compare(viewer, e1, e2);
+ }
+
+}

Back to the top