From f7e892074b1a34a1ce1eb562f50ac1d61711d480 Mon Sep 17 00:00:00 2001 From: vlorenzo Date: Mon, 3 Sep 2012 14:43:56 +0000 Subject: A save of my work on oep.dev.project.management --- .../META-INF/MANIFEST.MF | 3 +- .../icons/copyright_icon.png | Bin 0 -> 281 bytes .../plugin.xml | 22 +++++ .../features/SetCopyrightNoticeHandler.java | 94 +++++++++++++++++++++ .../dev/project/management/utils/Utils.java | 58 +++++++++++++ 5 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 sandbox/org.eclipse.papyrus.dev.project.management/icons/copyright_icon.png create mode 100644 sandbox/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/features/SetCopyrightNoticeHandler.java (limited to 'sandbox') diff --git a/sandbox/org.eclipse.papyrus.dev.project.management/META-INF/MANIFEST.MF b/sandbox/org.eclipse.papyrus.dev.project.management/META-INF/MANIFEST.MF index 26200032ac9..b707d2b2496 100644 --- a/sandbox/org.eclipse.papyrus.dev.project.management/META-INF/MANIFEST.MF +++ b/sandbox/org.eclipse.papyrus.dev.project.management/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.commands, org.eclipse.core.resources;bundle-version="3.8.0", org.eclipse.papyrus.eclipse.project.editors;bundle-version="0.9.0", - org.eclipse.papyrus.infra.core.log;bundle-version="0.9.0" + org.eclipse.papyrus.infra.core.log;bundle-version="0.9.0", + org.eclipse.pde.ui Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy diff --git a/sandbox/org.eclipse.papyrus.dev.project.management/icons/copyright_icon.png b/sandbox/org.eclipse.papyrus.dev.project.management/icons/copyright_icon.png new file mode 100644 index 00000000000..df9393d4f01 Binary files /dev/null and b/sandbox/org.eclipse.papyrus.dev.project.management/icons/copyright_icon.png differ diff --git a/sandbox/org.eclipse.papyrus.dev.project.management/plugin.xml b/sandbox/org.eclipse.papyrus.dev.project.management/plugin.xml index 2f16d850b36..f87c3828012 100644 --- a/sandbox/org.eclipse.papyrus.dev.project.management/plugin.xml +++ b/sandbox/org.eclipse.papyrus.dev.project.management/plugin.xml @@ -38,6 +38,17 @@ id="org.eclipse.papyrus.dev.project.management.command.feature.add.epl" name="Add EPL file"> + + + + @@ -68,6 +79,17 @@ label="Change Feature Version (no undo)" style="push"> + + + + featureProjects = Utils.getOpenedFeatureProject(); + for(final IProject current : featureProjects) { + try { + setCopyrightNotice(current, dialog.getValue(), dialog.getValue_2()); + } catch (final Throwable e) { + Activator.log.error(e); + } + } + } + return null; + } + + /** + * + * @param featureProject + * @param url + * @param text + * @throws Throwable + * + * TODO : doesn't erase existing value! + * TODO : add a checkbox in the dialog to erase existing value + */ + protected void setCopyrightNotice(final IProject featureProject, final String url, final String text) throws Throwable { + final IFeatureProjectEditor editor = new FeatureProjectEditor(featureProject); + editor.init(); + final String copyrirghtText = editor.getCopyrightText(); + final String copyrightURL = editor.getCopyrightURL(); + String settedURL = null; + String settedText = null; + //TODO improve these tests + if((copyrightURL == null) || copyrightURL.equals("")) { + settedURL = url; + } else { + settedURL = copyrightURL; + } + + if((copyrirghtText == null) || copyrirghtText.equals("")) { + settedText = text; + } + if(settedText.equals(copyrirghtText) && settedURL.equals(copyrightURL)) { + //do nothing + } else { + editor.setCopyright(settedURL, settedText); + editor.save(); + } + + } + +} diff --git a/sandbox/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/utils/Utils.java b/sandbox/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/utils/Utils.java index 7fdb01d0b16..4d97dc41a23 100644 --- a/sandbox/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/utils/Utils.java +++ b/sandbox/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/utils/Utils.java @@ -1,5 +1,23 @@ package org.eclipse.papyrus.dev.project.management.utils; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.dev.project.management.Activator; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.WorkingSet; + public class Utils { @@ -10,4 +28,44 @@ public class Utils { public static final String FEATURE_NATURE = "org.eclipse.pde.FeatureNature"; public static final String PLUGIN_NATURE = "org.eclipse.pde.PluginNature"; + + /** + * + * @return + * the list of opened feature project + */ + public static List getOpenedFeatureProject() { + final List featureProject = new ArrayList(); + final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + for(final IProject current : projects) { + try { + if(current.isOpen() && current.hasNature(FEATURE_NATURE)) { + featureProject.add(current); + } + } catch (final CoreException e) { + Activator.log.error(e); + } + } + return featureProject; + } + + public static Collection getSelectedOpenProject() { + final Set selectedProject = new HashSet(); + final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); + Assert.isTrue(selection instanceof IStructuredSelection); + final Iterator iter = ((IStructuredSelection)selection).iterator(); + while(iter.hasNext()) { + final Object current = iter.next(); + if((current instanceof IProject) && ((IProject)current).isOpen()) { + selectedProject.add((IProject)current); + } else if(current instanceof WorkingSet) { + for(final IAdaptable curr : ((WorkingSet)current).getElements()) { + if((curr instanceof IProject) && ((IProject)curr).isOpen()) { + selectedProject.add((IProject)curr); + } + } + } + } + return selectedProject; + } } -- cgit v1.2.3