diff options
author | apanchenk | 2009-07-07 12:42:20 +0000 |
---|---|---|
committer | apanchenk | 2009-07-07 12:42:20 +0000 |
commit | 81f7d609adf1eb1c22e9257ee6282e2377e028d1 (patch) | |
tree | c68b1e5ad0b64b077908e36e94e47599dba3885e | |
parent | d366bac700965218e28bd4ac991ff522d10f9dd7 (diff) | |
download | org.eclipse.dltk.tcl-R1_0_WAVE_1_5.tar.gz org.eclipse.dltk.tcl-R1_0_WAVE_1_5.tar.xz org.eclipse.dltk.tcl-R1_0_WAVE_1_5.zip |
restore "Fix package dependencies" actionv20090707-2003R1_0_WAVE_1_5
-rw-r--r-- | tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml | 20 | ||||
-rw-r--r-- | tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/packages/FixAllDependenciesActionDelegate.java | 121 |
2 files changed, 141 insertions, 0 deletions
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml b/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml index 85e5395c..6d93b4fe 100644 --- a/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml +++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml @@ -556,6 +556,26 @@ </action> </editorContribution> </extension> +<extension + point="org.eclipse.ui.popupMenus"> + <objectContribution + adaptable="false" + id="org.eclipse.dltk.tcl.ui.fixdeps" + objectClass="org.eclipse.dltk.core.IModelElement"> + <filter + name="org.eclipse.dltk.ui.nature" + value="org.eclipse.dltk.tcl.core.nature"> + </filter> + <action + class="org.eclipse.dltk.tcl.internal.ui.packages.FixAllDependenciesActionDelegate" + icon="icons/etool16/newpack_wiz.gif" + id="org.eclipse.dltk.tcl.ui.fixDependencies" + label="Fix package dependencies" + menubarPath="org.eclipse.dltk.ui.refactoring.menu" + style="push"> + </action> + </objectContribution> +</extension> <!-- =========================================================================== --> <!-- Tcl Compare --> diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/packages/FixAllDependenciesActionDelegate.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/packages/FixAllDependenciesActionDelegate.java new file mode 100644 index 00000000..f585aac5 --- /dev/null +++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/packages/FixAllDependenciesActionDelegate.java @@ -0,0 +1,121 @@ +package org.eclipse.dltk.tcl.internal.ui.packages; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.dltk.core.DLTKCore; +import org.eclipse.dltk.core.IModelElement; +import org.eclipse.dltk.core.IScriptProject; +import org.eclipse.dltk.launching.IInterpreterInstall; +import org.eclipse.dltk.launching.ScriptRuntime; +import org.eclipse.dltk.tcl.core.TclPackagesManager; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PlatformUI; + +public class FixAllDependenciesActionDelegate implements + IWorkbenchWindowActionDelegate { + private ISelection selection; + + public void dispose() { + } + + public void init(IWorkbenchWindow window) { + } + + public void run(IAction action) { + if (this.selection == null) { + return; + } + processSelectionToElements(selection); + } + + public static void processResourcesToElements(Object o, + Set<IProject> projects) { + if (o instanceof IResource) { + projects.add(((IResource) o).getProject()); + } else if (o instanceof IModelElement) { + projects.add(((IModelElement) o).getScriptProject().getProject()); + } + } + + protected void processSelectionToElements(ISelection selection) { + final Set<IProject> projects = new HashSet<IProject>(); + if (this.selection != null + && this.selection instanceof IStructuredSelection) { + final IStructuredSelection sel = (IStructuredSelection) this.selection; + for (Iterator<?> iterator = sel.iterator(); iterator.hasNext();) { + Object o = iterator.next(); + processResourcesToElements(o, projects); + } + } + if (!projects.isEmpty()) { + final ProgressMonitorDialog progressDialog = new ProgressMonitorDialog( + PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getShell()) { + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Fix package dependencies..."); + } + }; + SafeRunner.run(new SafeRunnable() { + public void run() throws Exception { + progressDialog.run(true, true, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) + throws InvocationTargetException, + InterruptedException { + SubMonitor topMonitor = SubMonitor.convert(monitor, + "Fixing dependencies", projects.size()); + final Set<IInterpreterInstall> installs = new HashSet<IInterpreterInstall>(); + for (IProject project : projects) { + IScriptProject scriptProject = DLTKCore + .create(project); + try { + IInterpreterInstall install = ScriptRuntime + .getInterpreterInstall(scriptProject); + if (install != null + && installs.add(install)) { + TclPackagesManager + .removeInterpreterInfo(install); + } + project + .build( + IncrementalProjectBuilder.FULL_BUILD, + SubMonitor + .convert( + topMonitor, + "Building " + + project + .getName(), + 1)); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + } + }); + } + }); + } + } + + public void selectionChanged(IAction action, ISelection selection) { + this.selection = selection; + } +} |