Author: max.andersen(a)jboss.com
Date: 2009-06-15 07:29:26 -0400 (Mon, 15 Jun 2009)
New Revision: 15949
Added:
trunk/workingset/
trunk/workingset/features/
trunk/workingset/features/org.jboss.tools.workingset.feature/
trunk/workingset/features/org.jboss.tools.workingset.feature/.project
trunk/workingset/features/org.jboss.tools.workingset.feature/build.properties
trunk/workingset/features/org.jboss.tools.workingset.feature/feature.xml
trunk/workingset/plugins/
trunk/workingset/plugins/org.jboss.tools.workingset.core/
trunk/workingset/plugins/org.jboss.tools.workingset.core/.classpath
trunk/workingset/plugins/org.jboss.tools.workingset.core/.project
trunk/workingset/plugins/org.jboss.tools.workingset.core/META-INF/
trunk/workingset/plugins/org.jboss.tools.workingset.core/META-INF/MANIFEST.MF
trunk/workingset/plugins/org.jboss.tools.workingset.core/build.properties
trunk/workingset/plugins/org.jboss.tools.workingset.core/plugin.xml
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/Activator.java
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/PreferenceConstants.java
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/NameToWorkingSet.java
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/PreferenceInitializer.java
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/StartupHook.java
trunk/workingset/plugins/org.jboss.tools.workingset.ui/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/.classpath
trunk/workingset/plugins/org.jboss.tools.workingset.ui/.project
trunk/workingset/plugins/org.jboss.tools.workingset.ui/.settings/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/.settings/org.eclipse.jdt.core.prefs
trunk/workingset/plugins/org.jboss.tools.workingset.ui/META-INF/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/META-INF/MANIFEST.MF
trunk/workingset/plugins/org.jboss.tools.workingset.ui/build.properties
trunk/workingset/plugins/org.jboss.tools.workingset.ui/plugin.xml
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/internal/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/internal/ui/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/internal/ui/WorkingsetPreferencePage.java
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/ui/
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/ui/Activator.java
trunk/workingset/tests/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/.classpath
trunk/workingset/tests/org.jboss.tools.workingset.core.test/.project
trunk/workingset/tests/org.jboss.tools.workingset.core.test/META-INF/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/META-INF/MANIFEST.MF
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/jboss/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/jboss/tools/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/jboss/tools/workingset/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/jboss/tools/workingset/core/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/jboss/tools/workingset/core/test/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/jboss/tools/workingset/core/test/GroupingTest.class
trunk/workingset/tests/org.jboss.tools.workingset.core.test/build.properties
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/tools/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/tools/workingset/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/tools/workingset/core/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/tools/workingset/core/test/
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/tools/workingset/core/test/GroupingTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4483
automatic grouping of working sets
Added: trunk/workingset/features/org.jboss.tools.workingset.feature/.project
===================================================================
--- trunk/workingset/features/org.jboss.tools.workingset.feature/.project
(rev 0)
+++ trunk/workingset/features/org.jboss.tools.workingset.feature/.project 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.workingset.feature</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.pde.FeatureBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.FeatureNature</nature>
+ </natures>
+</projectDescription>
Added: trunk/workingset/features/org.jboss.tools.workingset.feature/build.properties
===================================================================
--- trunk/workingset/features/org.jboss.tools.workingset.feature/build.properties
(rev 0)
+++
trunk/workingset/features/org.jboss.tools.workingset.feature/build.properties 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1 @@
+bin.includes = feature.xml
Added: trunk/workingset/features/org.jboss.tools.workingset.feature/feature.xml
===================================================================
--- trunk/workingset/features/org.jboss.tools.workingset.feature/feature.xml
(rev 0)
+++ trunk/workingset/features/org.jboss.tools.workingset.feature/feature.xml 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feature
+ id="org.jboss.tools.workingset.feature"
+ label="JBoss Tools Working Set "
+ version="1.0.0.qualifier"
+ provider-name="JBoss by Red Hat">
+
+ <description
url="http://www.example.com/description">
+ [Enter Feature Description here.]
+ </description>
+
+ <copyright
url="http://www.example.com/copyright">
+ [Enter Copyright Description here.]
+ </copyright>
+
+ <license
url="http://www.example.com/license">
+ [Enter License Description here.]
+ </license>
+
+ <plugin
+ id="org.jboss.tools.workingset.core"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.jboss.tools.workingset.ui"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+</feature>
Added: trunk/workingset/plugins/org.jboss.tools.workingset.core/.classpath
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.core/.classpath
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.core/.classpath 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/workingset/plugins/org.jboss.tools.workingset.core/.project
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.core/.project
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.core/.project 2009-06-15 11:29:26
UTC (rev 15949)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.workingset.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/workingset/plugins/org.jboss.tools.workingset.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.core/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.core/META-INF/MANIFEST.MF 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Working set
+Bundle-SymbolicName: org.jboss.tools.workingset.core;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.jboss.tools.workingset.core.Activator
+Bundle-Vendor: JBoss by Red Hat
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.5.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Export-Package: org.jboss.tools.workingset.core,
+ org.jboss.tools.workingset.internal.core
Added: trunk/workingset/plugins/org.jboss.tools.workingset.core/build.properties
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.core/build.properties
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.core/build.properties 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
Added: trunk/workingset/plugins/org.jboss.tools.workingset.core/plugin.xml
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.core/plugin.xml
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.core/plugin.xml 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.startup">
+ <startup
+ class="org.jboss.tools.workingset.internal.core.StartupHook">
+ </startup>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+
class="org.jboss.tools.workingset.internal.core.PreferenceInitializer">
+ </initializer>
+ </extension>
+
+</plugin>
Added:
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/Activator.java
===================================================================
---
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/Activator.java
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/Activator.java 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,256 @@
+package org.jboss.tools.workingset.core;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.jboss.tools.workingset.internal.core.NameToWorkingSet;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.workingset.core";
+
+ // The shared instance
+ private static Activator plugin;
+
+ private class ResourceChangeListener implements IResourceChangeListener {
+ public void resourceChanged(IResourceChangeEvent event) {
+ if (ntws == null ||
!getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_ENABLE)) {
+ return;
+ }
+
+ IResourceDelta delta = event.getDelta();
+ IResourceDelta[] affectedChildren = delta.getAffectedChildren(
+ IResourceDelta.ADDED, IResource.PROJECT);
+ if (affectedChildren.length > 0) {
+ IResource[] res = new IResource[affectedChildren.length];
+ for (int i = 0; i < affectedChildren.length; i++) {
+ res[i] = affectedChildren[i].getResource();
+ }
+ updateWorkingsets(res);
+ } /*
+ * else { Since projects can change name and we don't know the
+ * previous 'grouping' we don't update this. Maybe solvable by
+ * simply keeping track on where we put them ? affectedChildren=
+ * delta.getAffectedChildren(IResourceDelta.CHANGED,
+ * IResource.PROJECT); for (int i= 0; i < affectedChildren.length;
+ * i++) { IResourceDelta projectDelta= affectedChildren[i]; if
+ * ((projectDelta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
+ * updateWorkingsets(new IResourceDelta[] { projectDelta }); // one
+ * is enough return; } } }
+ */
+ }
+ }
+
+ private IResourceChangeListener resourceChangeListener;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ NameToWorkingSet ntws = null;
+
+ protected void updateWorkingsets() {
+ updateWorkingsets(ResourcesPlugin.getWorkspace().getRoot().getProjects());
+
+ }
+ public void updateWorkingsets(IResource[] affectedChildren) {
+ if (ntws == null) {
+ return;
+ }
+
+
+ Map<String, Set<IProject>> groupings = findGroupings(affectedChildren);
+
+ IWorkingSetManager wsManager = getWorkbench().getWorkingSetManager();
+
+ for (String name : groupings.keySet()) {
+ final IWorkingSet workingSet = wsManager.getWorkingSet(name);
+ final Set<IProject> projects = groupings.get(name);
+
+ if (workingSet != null) {
+ IAdaptable[] elements = workingSet.getElements();
+ for (int j = 0; j < elements.length; j++) {
+ IAdaptable element = elements[j];
+ if (element == null) {
+ continue;
+ }
+ IResource resource = (IResource) element
+ .getAdapter(IResource.class);
+ if (resource != null
+ && resource.getType() == IResource.PROJECT) {
+ projects.remove(resource);
+ if (projects.isEmpty()) {
+ break;
+ }
+ }
+ }
+ if (!projects.isEmpty()) {
+ System.out.println("Adding " + projects + " to "
+ + workingSet.getName());
+ SafeRunner.run(new ISafeRunnable() {
+
+ public void run() throws Exception {
+ IAdaptable[] adaptedNewElements = workingSet
+ .adaptElements(projects
+ .toArray(new IAdaptable[projects
+ .size()]));
+ if (adaptedNewElements.length > 0) {
+ IAdaptable[] elements = workingSet
+ .getElements();
+ workingSet.setElements(concat(elements,
+ adaptedNewElements));
+ }
+ }
+
+ public void handleException(Throwable exception) {
+ StatusManager.getManager().handle(
+ new Status(IStatus.WARNING, PLUGIN_ID,
+ "Problem creating workingset "
+ + exception.toString()));
+
+ }
+ });
+
+ }
+ } else {
+ System.out.println("Adding " + projects + " to new" + name);
+
+ IWorkingSet newWs = wsManager.createWorkingSet(name, projects
+ .toArray(new IProject[projects.size()]));
+ newWs.setId("org.eclipse.jdt.ui.JavaWorkingSetPage");
+ wsManager.addWorkingSet(newWs);
+ }
+ }
+ }
+
+ private Map<String, Set<IProject>> findGroupings(
+ IResource[] affectedResources) {
+ Map<String, Set<IProject>> groupings = new HashMap<String,
Set<IProject>>();
+
+ for (int i = 0; i < affectedResources.length; i++) {
+
+ IProject prj = (IProject) affectedResources[i];
+
+ String projectName = prj.getName();
+ System.out.println("Examing " + projectName);
+ String[] candidates = ntws.getWorkingSetNames(projectName);
+
+ for (String candidate : candidates) {
+ Set<IProject> set = groupings.get(candidate);
+ if (set == null)
+ set = new HashSet<IProject>();
+ set.add(prj);
+ groupings.put(candidate, set);
+ }
+ }
+ return groupings;
+ }
+
+ @SuppressWarnings("unchecked")
+ static <T> T[] concat(T[] a, T[] b) {
+ final int alen = a.length;
+ final int blen = b.length;
+ final T[] result = (T[]) java.lang.reflect.Array.newInstance(a
+ .getClass().getComponentType(), alen + blen);
+ System.arraycopy(a, 0, result, 0, alen);
+ System.arraycopy(b, 0, result, alen, blen);
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+
+ IPropertyChangeListener propertyListener = new IPropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if(event.getProperty().equals(PreferenceConstants.P_PATTERNS)) {
+ ntws = null;
+
+ NameToWorkingSet x = new NameToWorkingSet();
+
+ String newValue = (String) event.getNewValue();
+
+ String[] lines = newValue.split(";");
+ for (int i = 0; i < lines.length; i++) {
+ String[] string = lines[i].split(",");
+ try {
+ x.add(string[0], string[1], Boolean.parseBoolean(string[2]));
+ } catch(Exception e) {
+ // ignore
+ }
+ }
+ ntws = x;
+
+ updateWorkingsets();
+ }
+
+ }
+ };
+
+ getDefault().getPreferenceStore().addPropertyChangeListener(propertyListener);
+
+ resourceChangeListener = new ResourceChangeListener();
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(
+ resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
+
+
+ }
+
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
Added:
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/PreferenceConstants.java
===================================================================
---
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/PreferenceConstants.java
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/core/PreferenceConstants.java 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,11 @@
+package org.jboss.tools.workingset.core;
+
+/**
+ * Constant definitions for plug-in preferences
+ */
+public class PreferenceConstants {
+
+ public static final String P_ENABLE = "enable_automatic_workingsets";
+ public static final String P_PATTERNS = "workingset_patterns";
+
+}
Added:
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/NameToWorkingSet.java
===================================================================
---
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/NameToWorkingSet.java
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/NameToWorkingSet.java 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,70 @@
+package org.jboss.tools.workingset.internal.core;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class NameToWorkingSet {
+
+ final private List<PatternInfo> patterns = new ArrayList<PatternInfo>();
+
+ static class PatternInfo {
+
+ PatternInfo(String patternString, String replacePattern, boolean exclusive) {
+ this.patternString = patternString;
+ this.replacePattern = replacePattern;
+ this.exclusive = exclusive;
+ this.pattern = Pattern.compile(patternString);
+ }
+
+ public String getPatternString() {
+ return patternString;
+ }
+ public String getReplacePattern() {
+ return replacePattern;
+ }
+ public boolean isExclusive() {
+ return exclusive;
+ }
+ public Pattern getPattern() {
+ return pattern;
+ }
+ String patternString;
+ String replacePattern;
+ boolean exclusive;
+ Pattern pattern;
+ }
+ public NameToWorkingSet() {
+
+ }
+
+ public void add(String pattern, String replacePattern, boolean exclusive) {
+ patterns.add(new PatternInfo(pattern, replacePattern, exclusive));
+ }
+
+ public void clear() {
+ patterns.clear();
+ }
+
+ public String[] getWorkingSetNames(String name) {
+
+ Set<String> names = new HashSet<String>();
+
+ for (PatternInfo pattern : patterns) {
+ Matcher matcher = pattern.pattern.matcher(name);
+ boolean matchFound = matcher.find();
+
+ if (matchFound) {
+ names.add(matcher.replaceFirst(pattern.replacePattern));
+ if(pattern.exclusive) { break; }
+ }
+ }
+
+ return names.toArray(new String[names.size()]);
+ }
+
+
+}
Added:
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/PreferenceInitializer.java
===================================================================
---
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/PreferenceInitializer.java
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/PreferenceInitializer.java 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,34 @@
+package org.jboss.tools.workingset.internal.core;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import org.jboss.tools.workingset.core.Activator;
+import org.jboss.tools.workingset.core.PreferenceConstants;
+
+/**
+ * Class used to initialize default preference values.
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
+ * initializeDefaultPreferences()
+ */
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ store.setDefault(PreferenceConstants.P_ENABLE, false);
+ store
+ .setDefault(
+ PreferenceConstants.P_PATTERNS,
+ "org\\.([^\\.]+).*,$1,false" // major group, eclipse, jboss, hibernate,
etc.
+ //+ ";org\\.hibernate\\.eclipse\\.([^\\.]+).*,hibernate,true" // put
hibernate tools in hibernate, not needed when grouping globally
+ + ";org\\.jboss\\.ide\\.eclipse\\.([^\\.]+).*,$1,true" // put as and
archives in their own group
+ //+ ";org\\.jbpm\\.gd\\.([^\\.]+).*,jbpm,true"
+ + ";org\\.jboss\\.tools\\.([^\\.]+).*,$1-jbt,true" // split out group
for jboss tools
+ + ";org\\.eclipse\\.([^\\.]+).*,$1-eclipse,true"); // split out group
for eclipse
+
+ }
+}
Added:
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/StartupHook.java
===================================================================
---
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/StartupHook.java
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.core/src/org/jboss/tools/workingset/internal/core/StartupHook.java 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,12 @@
+package org.jboss.tools.workingset.internal.core;
+
+import org.eclipse.ui.IStartup;
+
+public class StartupHook implements IStartup {
+
+ public void earlyStartup() {
+ System.out.println("Started...");
+
+ }
+
+}
Added: trunk/workingset/plugins/org.jboss.tools.workingset.ui/.classpath
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.ui/.classpath
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.ui/.classpath 2009-06-15 11:29:26
UTC (rev 15949)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/workingset/plugins/org.jboss.tools.workingset.ui/.project
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.ui/.project
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.ui/.project 2009-06-15 11:29:26
UTC (rev 15949)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.workingset.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added:
trunk/workingset/plugins/org.jboss.tools.workingset.ui/.settings/org.eclipse.jdt.core.prefs
===================================================================
---
trunk/workingset/plugins/org.jboss.tools.workingset.ui/.settings/org.eclipse.jdt.core.prefs
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.ui/.settings/org.eclipse.jdt.core.prefs 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,8 @@
+#Mon Jun 15 12:39:29 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Added: trunk/workingset/plugins/org.jboss.tools.workingset.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.ui/META-INF/MANIFEST.MF
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.ui/META-INF/MANIFEST.MF 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Working set tools
+Bundle-SymbolicName: org.jboss.tools.workingset.ui;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.jboss.tools.workingset.ui.Activator
+Bundle-Vendor: JBoss by Red Hat
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.jboss.tools.workingset.core;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
Added: trunk/workingset/plugins/org.jboss.tools.workingset.ui/build.properties
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.ui/build.properties
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.ui/build.properties 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
Added: trunk/workingset/plugins/org.jboss.tools.workingset.ui/plugin.xml
===================================================================
--- trunk/workingset/plugins/org.jboss.tools.workingset.ui/plugin.xml
(rev 0)
+++ trunk/workingset/plugins/org.jboss.tools.workingset.ui/plugin.xml 2009-06-15 11:29:26
UTC (rev 15949)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+
class="org.jboss.tools.workingset.internal.ui.WorkingsetPreferencePage"
+
id="org.jboss.tools.workingsets.internal.ui.preferences.WorkingsetPreferencePage"
+ name="Automatic WorkingSets">
+ </page>
+ </extension>
+</plugin>
Added:
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/internal/ui/WorkingsetPreferencePage.java
===================================================================
---
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/internal/ui/WorkingsetPreferencePage.java
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/internal/ui/WorkingsetPreferencePage.java 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,96 @@
+package org.jboss.tools.workingset.internal.ui;
+
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.ListEditor;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.jboss.tools.workingset.core.PreferenceConstants;
+import org.jboss.tools.workingset.ui.Activator;
+
+public class WorkingsetPreferencePage
+ extends FieldEditorPreferencePage
+ implements IWorkbenchPreferencePage {
+
+ public WorkingsetPreferencePage() {
+ super(GRID);
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ setDescription("Setup automatic grouping of projects into working sets that
matches a regular expression.");
+ }
+
+ public void createFieldEditors() {
+
+ addField(new ListEditor(PreferenceConstants.P_PATTERNS,"Grouping patterns",
getFieldEditorParent()) {
+
+ @Override
+ protected String[] parseString(String stringList) {
+ if(stringList.trim().length()>0) {
+ return stringList.split(";");
+ } else {
+ return new String[0];
+ }
+ }
+
+ @Override
+ protected String getNewInputObject() {
+
+ InputDialog dialog = new InputDialog(getShell(), "Add new pattern",
"Syntax: <pattern>, <replace pattern>,
<exclusive:true|false>", "org\\.jboss\\.tools\\.([^\\.]+).*,$1,true",
new IInputValidator() {
+
+ public String isValid(String newText) {
+ String[] split = newText.split(",");
+ if(split.length!=3) {
+ return "Pattern does not consist 3 parts separated by commas";
+ }
+ try {
+ Pattern.compile(split[0]);
+ } catch(PatternSyntaxException pse) {
+ return "Pattern does not compile: " + pse.getDescription();
+ }
+ if(!split[2].equals("true") &&
!split[2].equals("false")) {
+ return "Exclusive needs to be true or false";
+ }
+
+ return null;
+ }
+ });
+
+ if(dialog.open()==InputDialog.OK) {
+ return dialog.getValue();
+ } else {
+ return null;
+ }
+
+ }
+
+ @Override
+ protected String createList(String[] items) {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < items.length; i++) {
+ String string = items[i];
+ sb.append(string);
+ if(i<items.length) sb.append(";");
+ }
+ return sb.toString();
+ }
+ });
+
+ addField(
+ new BooleanFieldEditor(
+ PreferenceConstants.P_ENABLE,
+ "Automatic grouping of projects",
+ getFieldEditorParent()));
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init(IWorkbench workbench) {
+ }
+
+}
\ No newline at end of file
Added:
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/ui/Activator.java
===================================================================
---
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/ui/Activator.java
(rev 0)
+++
trunk/workingset/plugins/org.jboss.tools.workingset.ui/src/org/jboss/tools/workingset/ui/Activator.java 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,50 @@
+package org.jboss.tools.workingset.ui;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.workingset.ui";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
Added: trunk/workingset/tests/org.jboss.tools.workingset.core.test/.classpath
===================================================================
--- trunk/workingset/tests/org.jboss.tools.workingset.core.test/.classpath
(rev 0)
+++ trunk/workingset/tests/org.jboss.tools.workingset.core.test/.classpath 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/workingset/tests/org.jboss.tools.workingset.core.test/.project
===================================================================
--- trunk/workingset/tests/org.jboss.tools.workingset.core.test/.project
(rev 0)
+++ trunk/workingset/tests/org.jboss.tools.workingset.core.test/.project 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.workingset.core.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/workingset/tests/org.jboss.tools.workingset.core.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/workingset/tests/org.jboss.tools.workingset.core.test/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/workingset/tests/org.jboss.tools.workingset.core.test/META-INF/MANIFEST.MF 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Working set tests
+Bundle-SymbolicName: org.jboss.tools.workingset.core.test
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: JBoss by Red Hat
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.junit4;bundle-version="4.5.0",
+ org.jboss.tools.workingset.core;bundle-version="1.0.0",
+ org.jboss.tools.workingset.ui;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
Added:
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/jboss/tools/workingset/core/test/GroupingTest.class
===================================================================
(Binary files differ)
Property changes on:
trunk/workingset/tests/org.jboss.tools.workingset.core.test/bin/org/jboss/tools/workingset/core/test/GroupingTest.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/workingset/tests/org.jboss.tools.workingset.core.test/build.properties
===================================================================
--- trunk/workingset/tests/org.jboss.tools.workingset.core.test/build.properties
(rev 0)
+++
trunk/workingset/tests/org.jboss.tools.workingset.core.test/build.properties 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
Added:
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/tools/workingset/core/test/GroupingTest.java
===================================================================
---
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/tools/workingset/core/test/GroupingTest.java
(rev 0)
+++
trunk/workingset/tests/org.jboss.tools.workingset.core.test/src/org/jboss/tools/workingset/core/test/GroupingTest.java 2009-06-15
11:29:26 UTC (rev 15949)
@@ -0,0 +1,63 @@
+package org.jboss.tools.workingset.core.test;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.tools.workingset.internal.core.NameToWorkingSet;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class GroupingTest {
+
+ static NameToWorkingSet nws = new NameToWorkingSet();
+
+ @BeforeClass
+ static public void setup() {
+
+ nws.add("org\\.jboss\\.tools\\.([^\\.]+).*", "$1", true);
+ nws.add("org\\.eclipse\\.([^\\.]+).*", "eclipse", false);
+ nws.add("org\\.eclipse\\.([^\\.]+).*", "$1", true);
+ nws.add("org\\.eclipse\\.([^\\.]+).*", "shouldnotbeseen", false);
+
+ }
+
+ @Test
+ public void testNoMatch() {
+
+ assertEquals(nws.getWorkingSetNames("org.jboss.tools").length,0);
+ String[] ws = nws.getWorkingSetNames("org.jboss.tools.vpe");
+ assertEquals(1,ws.length);
+ assertEquals("vpe",ws[0]);
+
+ }
+
+ @Test
+ public void testSingleMatch() {
+ String[] ws = nws.getWorkingSetNames("org.jboss.tools.vpe.test");
+ assertEquals(1,ws.length);
+ assertEquals("vpe",ws[0]);
+
+ ws = nws.getWorkingSetNames("org.jboss.tools.vpe.ui.test");
+ assertEquals(1,ws.length);
+ assertEquals("vpe",ws[0]);
+
+ ws = nws.getWorkingSetNames("org.jboss.tools.hibernate.ui.test");
+ assertEquals(1,ws.length);
+ assertEquals("hibernate",ws[0]);
+
+ ws = nws.getWorkingSetNames("org.eclipse.jdt");
+ assertEquals(2,ws.length);
+ assertEquals("eclipse",ws[0]);
+ assertEquals("jdt",ws[1]);
+
+ }
+
+ @Test
+ public void testMultiMatch() {
+ String[] ws = nws.getWorkingSetNames("org.eclipse.jdt.ui");
+ assertEquals(2,ws.length);
+ assertEquals("eclipse",ws[0]);
+ assertEquals("jdt",ws[1]);
+
+ }
+
+ }