diff --git a/Eclipse UI/org/eclipse/ui/internal/commands/WorkingSetValues.java b/Eclipse UI/org/eclipse/ui/internal/commands/WorkingSetValues.java new file mode 100644 index 0000000..fd801b0 --- /dev/null +++ b/Eclipse UI/org/eclipse/ui/internal/commands/WorkingSetValues.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2009 Mykola Nikishov + * + * 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 + ******************************************************************************/ + +package org.eclipse.ui.internal.commands; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.IParameterValues; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PlatformUI; + +public abstract class WorkingSetValues implements IParameterValues { + + protected abstract boolean isActionable(IProject project); + + final public Map getParameterValues() { + IWorkingSet[] allWorkingSets = PlatformUI.getWorkbench() + .getWorkingSetManager().getAllWorkingSets(); + final HashMap result = new HashMap(); + for (int i = 0; i < allWorkingSets.length; i++) { + IWorkingSet workingSet = allWorkingSets[i]; + if (!workingSet.isAggregateWorkingSet()) { + IAdaptable[] elements = workingSet.getElements(); + for (int j = 0; j < elements.length; j++) { + IProject project = (IProject) elements[j] + .getAdapter(IProject.class); + if (project != null && isActionable(project)) { + result.put(workingSet.getLabel(), workingSet.getName()); + break; + } + } + } + } + return result; + } + +} diff --git a/Eclipse UI/org/eclipse/ui/internal/handlers/CloseWorkingSetHandler.java b/Eclipse UI/org/eclipse/ui/internal/handlers/CloseWorkingSetHandler.java new file mode 100644 index 0000000..73e95e6 --- /dev/null +++ b/Eclipse UI/org/eclipse/ui/internal/handlers/CloseWorkingSetHandler.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2009 Mykola Nikishov + * + * 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 + ******************************************************************************/ + +package org.eclipse.ui.internal.handlers; + + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; + +public class CloseWorkingSetHandler extends WorkingSetHandler { + + private static final String PARAMETER_ID = "org.eclipse.ui.workingSet.commandParameter1"; //$NON-NLS-1$ + + protected void executeOperation(IProject project) throws CoreException { + project.close(null); + } + + protected boolean isAplicable(IProject project) { + return project.isOpen(); + } + + protected String getParameterId() { + return PARAMETER_ID; + } + +} diff --git a/Eclipse UI/org/eclipse/ui/internal/handlers/CloseWorkingSetValues.java b/Eclipse UI/org/eclipse/ui/internal/handlers/CloseWorkingSetValues.java new file mode 100644 index 0000000..e87df99 --- /dev/null +++ b/Eclipse UI/org/eclipse/ui/internal/handlers/CloseWorkingSetValues.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2009 Mykola Nikishov + * + * 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 + ******************************************************************************/ + +package org.eclipse.ui.internal.handlers; + +import org.eclipse.ui.internal.commands.WorkingSetValues; + +import org.eclipse.core.resources.IProject; + +public class CloseWorkingSetValues extends WorkingSetValues { + + protected boolean isActionable(IProject project) { + return !project.isOpen(); + } + +} diff --git a/Eclipse UI/org/eclipse/ui/internal/handlers/OpenWorkingSetHandler.java b/Eclipse UI/org/eclipse/ui/internal/handlers/OpenWorkingSetHandler.java new file mode 100644 index 0000000..ad30d2a --- /dev/null +++ b/Eclipse UI/org/eclipse/ui/internal/handlers/OpenWorkingSetHandler.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2009 Mykola Nikishov + * + * 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 + ******************************************************************************/ + +package org.eclipse.ui.internal.handlers; + + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; + +public class OpenWorkingSetHandler extends WorkingSetHandler { + + private static final String PARAMETER_ID = "org.eclipse.ui.workingSet.commandParameter2"; //$NON-NLS-1$ + + protected void executeOperation(IProject project) throws CoreException { + project.open(null); + } + + protected String getParameterId() { + return PARAMETER_ID; + } + + protected boolean isAplicable(IProject project) { + return !project.isOpen(); + } + +} diff --git a/Eclipse UI/org/eclipse/ui/internal/handlers/OpenWorkingSetValues.java b/Eclipse UI/org/eclipse/ui/internal/handlers/OpenWorkingSetValues.java new file mode 100644 index 0000000..483322e --- /dev/null +++ b/Eclipse UI/org/eclipse/ui/internal/handlers/OpenWorkingSetValues.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2009 Mykola Nikishov + * + * 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 + ******************************************************************************/ + +package org.eclipse.ui.internal.handlers; + +import org.eclipse.ui.internal.commands.WorkingSetValues; + +import org.eclipse.core.resources.IProject; + +public class OpenWorkingSetValues extends WorkingSetValues { + + protected boolean isActionable(IProject project) { + return project.isOpen(); + } + +} diff --git a/Eclipse UI/org/eclipse/ui/internal/handlers/WorkingSetHandler.java b/Eclipse UI/org/eclipse/ui/internal/handlers/WorkingSetHandler.java new file mode 100644 index 0000000..d5e663d --- /dev/null +++ b/Eclipse UI/org/eclipse/ui/internal/handlers/WorkingSetHandler.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2009 Mykola Nikishov + * + * 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 + ******************************************************************************/ + +package org.eclipse.ui.internal.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PlatformUI; + +public abstract class WorkingSetHandler extends AbstractHandler { + + protected abstract boolean isAplicable(IProject project); + + protected abstract void executeOperation(IProject project) + throws CoreException; + + public final Object execute(ExecutionEvent event) throws ExecutionException { + String parameter = event.getParameter(getParameterId()); + IWorkingSet workingSetToClose = PlatformUI.getWorkbench() + .getWorkingSetManager().getWorkingSet(parameter); + IAdaptable[] elements = workingSetToClose.getElements(); + for (int j = 0; j < elements.length; j++) { + IProject project = (IProject) elements[j] + .getAdapter(IProject.class); + if (project != null && isAplicable(project)) { + try { + executeOperation(project); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return null; + } + + protected abstract String getParameterId(); + +} diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index 67c85f0..42be2d8 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -98,7 +98,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)", org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)", org.eclipse.jface.databinding;bundle-version="[1.3.0,2.0.0)", org.eclipse.core.databinding.property;bundle-version="[1.2.0,2.0.0)", - org.eclipse.core.databinding.observable;bundle-version="[1.2.0,2.0.0)" + org.eclipse.core.databinding.observable;bundle-version="[1.2.0,2.0.0)", + org.eclipse.core.resources;bundle-version="[3.6.0,4.0.0)" Import-Package: com.ibm.icu.text, com.ibm.icu.util, javax.xml.parsers,