diff options
author | Mickael ADAM | 2014-08-20 09:01:21 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2017-01-16 16:38:26 +0000 |
commit | b6bf94acbac462c65cac7f13a5ebbe5e5416fbc1 (patch) | |
tree | 75a9368bc8f7c6776bedc11515b98ccc6b623dd6 /plugins/uml | |
parent | a07c402973c17a0b33cc4eec37daa6cbe4f40820 (diff) | |
download | org.eclipse.papyrus-b6bf94acbac462c65cac7f13a5ebbe5e5416fbc1.tar.gz org.eclipse.papyrus-b6bf94acbac462c65cac7f13a5ebbe5e5416fbc1.tar.xz org.eclipse.papyrus-b6bf94acbac462c65cac7f13a5ebbe5e5416fbc1.zip |
Bug 409555: [Profile] Apply profiles in a folder
https://bugs.eclipse.org/bugs/show_bug.cgi?id=409555
- Modify dedicated dialog selector to extract only filtered files
according to selection
- Add behavior for Project and Folder of workspace to extract internal
files.
Change-Id: Icae68b08c77364e9676d1a0c8ea39baea55cc6c4
Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/uml')
2 files changed, 234 insertions, 38 deletions
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/importsources/PackageImportReferenceSelector.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/importsources/PackageImportReferenceSelector.java new file mode 100644 index 00000000000..103af6c1ada --- /dev/null +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/importsources/PackageImportReferenceSelector.java @@ -0,0 +1,207 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST. + * + * 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: + * CEA LIST - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 409555 + *****************************************************************************/ + +package org.eclipse.papyrus.uml.tools.importsources; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider; +import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; +import org.eclipse.papyrus.uml.tools.Activator; +import org.eclipse.swt.widgets.Composite; + +/** + * Selector for Package import source. + */ +class PackageImportReferenceSelector extends ReferenceSelector { + + /** The source. */ + private IPackageImportSource source; + + + /** + * Instantiates a new package import reference selector. + */ + public PackageImportReferenceSelector() { + super(); + } + + /** + * Sets the import source. + * + * @param source + * the new import source + */ + void setImportSource(IPackageImportSource source) { + this.source = source; + } + + + /** + * Gets the elements to move. + * + * @param selection + * the selection + * @return the elements to move + * @see org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector#getElementsToMove(java.lang.Object[]) + */ + @Override + protected Object[] getElementsToMove(Object[] selection) { + + final List<Object> elementsToMove = new LinkedList<Object>(); + + // Parse all selected elements + for (Object element : selection) { + + // Case 1 : element is a folder + if (element instanceof IFolder || element instanceof IProject) { + + // Try to visit containing of folder to find elements to move + elementsToMove.addAll(extractFiltered((IResource) element)); + + } else if (contentProvider.isValidValue(element)) { + + elementsToMove.add(element); + } + } + + notifyCommitListeners(); + + return elementsToMove.toArray(); + } + + + /** + * Extract filtered. + * + * @param element + * the element + * @return the collection<? extends object> + */ + private Collection<? extends Object> extractFiltered(IResource element) { + FilteredChildrenResourceVisitor childrenVisitor = new FilteredChildrenResourceVisitor(contentProvider); + + try { + element.accept(childrenVisitor); + } catch (CoreException e) { + Activator.log.error(e); + } + return childrenVisitor.getResult(); + } + + + + /** + * Creates the controls. + * + * @param parent + * the parent + * @see org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector#createControls(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createControls(Composite parent) { + super.createControls(parent); + + if (source instanceof CompositePackageImportSource) { + // expand to the second level to show projects in the workspace + // and whatever is contributed by other sources + treeViewer.expandToLevel(2); + } + + } + + /** + * The Class FilteredChildrenResourceVisitor. + */ + private class FilteredChildrenResourceVisitor implements IResourceVisitor { + + /** The content provider. */ + private EncapsulatedContentProvider contentProvider; + + /** The elements list. */ + private List<Object> elementsList = new LinkedList<Object>(); + + /** + * Instantiates a new filtered children resource visitor. + * + * @param contentProvider + * the content provider + */ + public FilteredChildrenResourceVisitor(EncapsulatedContentProvider contentProvider) { + this.contentProvider = contentProvider; + } + + /** + * @see org.eclipse.core.resources.IResourceVisitor#visit(org.eclipse.core.resources.IResource) + * + * @param resource + * @return + * @throws CoreException + */ + + public boolean visit(IResource resource) throws CoreException { + + if (resource instanceof IFile) { + + // Check before with the content provider + if (contentProvider.isValidValue(resource)) { + + /* + * Initialise element to filter the resource with + * tree viewer filters. + */ + boolean filtered = true; + ViewerFilter[] filtersArray = treeViewer.getFilters(); + int amountFilters = filtersArray.length; + + int i = 0; + while (filtered && i < amountFilters) { + // Check if the visited resource passes all filters + filtered = filtersArray[i].select(treeViewer, resource.getParent(), resource); + i++; + } + + if (filtered) { + elementsList.add(resource); + } + } + + return false; + } + + return true; + + } + + /** + * Gets the result. + * + * @return the result + */ + public Collection<? extends Object> getResult() { + return elementsList; + } + } + + + +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/importsources/PackageImportSourceDialog.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/importsources/PackageImportSourceDialog.java index 8a355e7276c..b8fe1bdb9a7 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/importsources/PackageImportSourceDialog.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/importsources/PackageImportSourceDialog.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013 CEA LIST. + * Copyright (c) 2016 CEA LIST. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,8 @@ * * Contributors: * CEA LIST - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 409555 + * Mickaƫl ADAM (ALL4TEC) mickael.adam@all4tec.net - extends by MultipleValueSelectionDialog *****************************************************************************/ package org.eclipse.papyrus.uml.tools.importsources; @@ -20,10 +22,9 @@ import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; -import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog; -import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; +import org.eclipse.papyrus.infra.widgets.editors.IElementSelector; +import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectionDialog; import org.eclipse.papyrus.uml.extensionpoints.utils.Util; -import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.services.IEvaluationService; @@ -33,9 +34,9 @@ import org.eclipse.ui.statushandlers.StatusManager; import org.eclipse.uml2.uml.Package; /** - * This is the PackageImportSourceDialog type. Enjoy. + * Dialog for Package import source. */ -public class PackageImportSourceDialog extends MultipleValueSelectorDialog { +public class PackageImportSourceDialog extends MultipleValueSelectionDialog { private IPackageImportSource source; @@ -43,6 +44,9 @@ public class PackageImportSourceDialog extends MultipleValueSelectorDialog { private List<Package> selectedPackages; + + protected Map<String, String> extensionFilters; + /** * Initializes me. * @@ -52,9 +56,16 @@ public class PackageImportSourceDialog extends MultipleValueSelectorDialog { * the dialog title */ public PackageImportSourceDialog(Shell parentShell, String title) { - super(parentShell, new MyReferenceSelector(), title, true, true); + super(parentShell, getPackageImportSourceSelector(), title, true, true); + } - setTitle(title); + /** + * Gets the package import source selector. + * + * @return the package import source selector + */ + private static IElementSelector getPackageImportSourceSelector() { + return new PackageImportReferenceSelector(); } /** @@ -65,7 +76,6 @@ public class PackageImportSourceDialog extends MultipleValueSelectorDialog { * user cancelled */ public static Collection<Package> open(Shell parentShell, String title, IStructuredSelection selection) { - return open(parentShell, title, selection.toList()); } @@ -97,22 +107,22 @@ public class PackageImportSourceDialog extends MultipleValueSelectorDialog { return dlg.getSelectedPackages(); } - protected Map<String, String> extensionFilters; - protected void setExtensionFilters(Map<String, String> extensionFilters) { this.extensionFilters = extensionFilters; } public void initialize(Collection<?> selection) { - IEvaluationService evaluationService = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class); + IEvaluationService evaluationService = PlatformUI.getWorkbench().getService(IEvaluationService.class); source = new PackageImportSourceRegistry(evaluationService).createImportSourceFor(selection); source.initialize(selection); - MyReferenceSelector selector = (MyReferenceSelector) this.selector; + PackageImportReferenceSelector selector = (PackageImportReferenceSelector) getPackageImportSourceSelector(); + setSelector(selector); + ILabelProvider labelProvider = source.getModelHierarchyLabelProvider(); - selector.setLabelProvider(labelProvider); - selector.setContentProvider(source.getModelHierarchyContentProvider(extensionFilters)); - selector.setImportSource(source); + ((PackageImportReferenceSelector) selector).setLabelProvider(labelProvider); + ((PackageImportReferenceSelector) selector).setContentProvider(source.getModelHierarchyContentProvider(extensionFilters)); + ((PackageImportReferenceSelector) selector).setImportSource(source); setLabelProvider(labelProvider); @@ -169,30 +179,9 @@ public class PackageImportSourceDialog extends MultipleValueSelectorDialog { } } } - } - - // - // Nested types - // - - private static class MyReferenceSelector extends ReferenceSelector { - - private IPackageImportSource source; - void setImportSource(IPackageImportSource source) { - this.source = source; - } + } - @Override - public void createControls(Composite parent) { - super.createControls(parent); - if (source instanceof CompositePackageImportSource) { - // expand to the second level to show projects in the workspace - // and whatever is contributed by other sources - treeViewer.expandToLevel(2); - } - } - } } |