Author: Grid.Qian
Date: 2008-06-10 04:09:11 -0400 (Tue, 10 Jun 2008)
New Revision: 8662
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java
Log:
JBIDE-2261: add validation for changing runtime location name
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java 2008-06-10
07:49:43 UTC (rev 8661)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java 2008-06-10
08:09:11 UTC (rev 8662)
@@ -11,19 +11,23 @@
package org.jboss.tools.ws.core.classpath;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.jboss.tools.ws.core.JbossWSCorePlugin;
+import org.jboss.tools.ws.core.facet.delegate.IJBossWSFacetDataModelProperties;
import org.jboss.tools.ws.core.messages.JbossWSCoreMessages;
/**
@@ -31,217 +35,232 @@
*/
public class JbossWSRuntimeManager {
- private static JbossWSRuntimeListConverter converter = new
JbossWSRuntimeListConverter();
+ private static JbossWSRuntimeListConverter converter = new
JbossWSRuntimeListConverter();
- private Map<String, JbossWSRuntime> runtimes = new HashMap<String,
JbossWSRuntime>();
+ private Map<String, JbossWSRuntime> runtimes = new HashMap<String,
JbossWSRuntime>();
- /**
- * Private constructor
- */
- private JbossWSRuntimeManager() {
- IPreferenceStore ps = JbossWSCorePlugin.getDefault().getPreferenceStore();
-
- String runtimeListString = ps.getString(JbossWSCoreMessages.WS_Location);
+ /**
+ * Private constructor
+ */
+ private JbossWSRuntimeManager() {
+ IPreferenceStore ps = JbossWSCorePlugin.getDefault()
+ .getPreferenceStore();
- runtimes = converter.getMap(runtimeListString);
- }
+ String runtimeListString = ps
+ .getString(JbossWSCoreMessages.WS_Location);
- /**
- * This class make Java Runtime responsible for solving synchronization
- * problems during initialization if there is any
- *
- */
- static class JbossWSRuntimeManagerHolder {
- private static final JbossWSRuntimeManager INSTANCE = new JbossWSRuntimeManager();
- }
+ runtimes = converter.getMap(runtimeListString);
+ }
- /**
- * Return JbossWSRuntimeManaher instance
- *
- * @return
- * JbossWSRuntimeManager instance
- */
- public static JbossWSRuntimeManager getInstance() {
- return JbossWSRuntimeManagerHolder.INSTANCE;
+ /**
+ * This class make Java Runtime responsible for solving synchronization
+ * problems during initialization if there is any
+ *
+ */
+ static class JbossWSRuntimeManagerHolder {
+ private static final JbossWSRuntimeManager INSTANCE = new JbossWSRuntimeManager();
+ }
+
+ /**
+ * Return JbossWSRuntimeManaher instance
+ *
+ * @return JbossWSRuntimeManager instance
+ */
+ public static JbossWSRuntimeManager getInstance() {
+ return JbossWSRuntimeManagerHolder.INSTANCE;
+ }
+
+ /**
+ * Return Array of configured JbossWSRuntimes
+ *
+ * @return JbossWSRuntime[]
+ */
+ public JbossWSRuntime[] getRuntimes() {
+ Collection<JbossWSRuntime> c = runtimes.values();
+ return c.toArray(new JbossWSRuntime[runtimes.size()]);
+ }
+
+ /**
+ * Add new JbossWSRuntime
+ *
+ * @param runtime
+ * JbossWSRuntime
+ */
+ public void addRuntime(JbossWSRuntime runtime) {
+ if (runtimes.size() == 0) {
+ runtime.setDefault(true);
}
- /**
- * Return Array of configured JbossWSRuntimes
- *
- * @return
- * JbossWSRuntime[]
- */
- public JbossWSRuntime[] getRuntimes() {
- Collection<JbossWSRuntime> c = runtimes.values();
- return c.toArray(new JbossWSRuntime[runtimes.size()]);
+ JbossWSRuntime oldDefaultRuntime = getDefaultRuntime();
+ if (oldDefaultRuntime != null && runtime.isDefault()) {
+ oldDefaultRuntime.setDefault(false);
}
+ runtimes.put(runtime.getName(), runtime);
+ save();
+ }
- /**
- * Add new JbossWSRuntime
- *
- * @param runtime
- * JbossWSRuntime
- */
- public void addRuntime(JbossWSRuntime runtime) {
- if (runtimes.size() == 0) {
- runtime.setDefault(true);
- }
+ /**
+ * Add new JbossWSRuntime with given parameters
+ *
+ * @param name
+ * String - runtime name
+ * @param path
+ * String - runtime home folder
+ * @param version
+ * String - string representation of version number
+ * @param defaultRt
+ * boolean - default flag
+ */
+ public void addRuntime(String name, String path, boolean defaultRt) {
+ JbossWSRuntime jbossWSRt = new JbossWSRuntime();
+ jbossWSRt.setHomeDir(path);
+ jbossWSRt.setName(name);
+ jbossWSRt.setDefault(defaultRt);
+ addRuntime(jbossWSRt);
+ }
- JbossWSRuntime oldDefaultRuntime = getDefaultRuntime();
- if (oldDefaultRuntime != null && runtime.isDefault()) {
- oldDefaultRuntime.setDefault(false);
+ /**
+ * Return JbossWSRuntime by given name
+ *
+ * @param name
+ * String - JbossWSRuntime name
+ * @return JbossWSRuntime - found JbossWSRuntime instance or null
+ */
+ public JbossWSRuntime findRuntimeByName(String name) {
+ for (JbossWSRuntime jbossWSRuntime : runtimes.values()) {
+ if (jbossWSRuntime.getName().equals(name)) {
+ return jbossWSRuntime;
}
- runtimes.put(runtime.getName(), runtime);
- save();
}
+ return null;
+ }
- /**
- * Add new JbossWSRuntime with given parameters
- *
- * @param name
- * String - runtime name
- * @param path
- * String - runtime home folder
- * @param version
- * String - string representation of version number
- * @param defaultRt
- * boolean - default flag
- */
- public void addRuntime(String name, String path,
- boolean defaultRt) {
- JbossWSRuntime jbossWSRt = new JbossWSRuntime();
- jbossWSRt.setHomeDir(path);
- jbossWSRt.setName(name);
- jbossWSRt.setDefault(defaultRt);
- addRuntime(jbossWSRt);
- }
+ /**
+ * Remove given JbossWSRuntime from manager
+ *
+ * @param rt
+ * JbossWSRuntime
+ */
+ public void removeRuntime(JbossWSRuntime rt) {
+ runtimes.remove(rt.getName());
+ }
- /**
- * Return JbossWSRuntime by given name
- *
- * @param name
- * String - JbossWSRuntime name
- * @return
- * JbossWSRuntime - found JbossWSRuntime instance or null
- */
- public JbossWSRuntime findRuntimeByName(String name) {
- for (JbossWSRuntime jbossWSRuntime : runtimes.values()) {
- if (jbossWSRuntime.getName().equals(name)) {
- return jbossWSRuntime;
- }
+ /**
+ * Save preference value and force save changes to disk
+ */
+ public void save() {
+ JbossWSCorePlugin.getDefault().getPreferenceStore().setValue(
+ "jbosswsruntimelocation", converter.getString(runtimes));
+ IPreferenceStore store = JbossWSCorePlugin.getDefault()
+ .getPreferenceStore();
+ if (store instanceof IPersistentPreferenceStore) {
+ try {
+ ((IPersistentPreferenceStore) store).save();
+ } catch (IOException e) {
+ e.printStackTrace();
}
- return null;
}
+ }
- /**
- * Remove given JbossWSRuntime from manager
- * @param rt
- * JbossWSRuntime
- */
- public void removeRuntime(JbossWSRuntime rt) {
- runtimes.remove(rt.getName());
+ /**
+ * Marks this runtime as default. Marks other runtimes with the same version
+ * as not default.
+ *
+ * @param runtime
+ */
+ public void setDefaultRuntime(JbossWSRuntime runtime) {
+ JbossWSRuntime[] runtimes = getRuntimes();
+ for (int i = 0; i < runtimes.length; i++) {
+ runtimes[i].setDefault(false);
}
+ runtime.setDefault(true);
+ }
-
- /**
- * Save preference value and force save changes to disk
- */
- public void save() {
- JbossWSCorePlugin.getDefault().getPreferenceStore().setValue(
- "jbosswsruntimelocation",
- converter.getString(runtimes));
- IPreferenceStore store = JbossWSCorePlugin.getDefault().getPreferenceStore();
- if (store instanceof IPersistentPreferenceStore) {
- try {
- ((IPersistentPreferenceStore) store).save();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ /**
+ * Return first default JbossWSRuntime
+ *
+ * @return JbossWSRuntime
+ */
+ public JbossWSRuntime getDefaultRuntime() {
+ for (JbossWSRuntime rt : runtimes.values()) {
+ if (rt.isDefault()) {
+ return rt;
}
}
+ return null;
+ }
- /**
- * Marks this runtime as default. Marks other runtimes with the same version as not
default.
- * @param runtime
- */
- public void setDefaultRuntime(JbossWSRuntime runtime) {
- JbossWSRuntime[] runtimes = getRuntimes();
- for (int i = 0; i < runtimes.length; i++) {
- runtimes[i].setDefault(false);
- }
- runtime.setDefault(true);
+ /**
+ * Return list of available JbossWSRuntime names
+ *
+ * @return List<String>
+ */
+ public List<String> getRuntimeNames() {
+ JbossWSRuntime[] rts = getRuntimes();
+ List<String> result = new ArrayList<String>();
+ for (JbossWSRuntime jbossWSRuntime : rts) {
+ result.add(jbossWSRuntime.getName());
}
+ return result;
+ }
- /**
- * Return first default JbossWSRuntime
- *
- * @return
- * JbossWSRuntime
- */
- public JbossWSRuntime getDefaultRuntime() {
- for (JbossWSRuntime rt : runtimes.values()) {
- if (rt.isDefault()) {
- return rt;
- }
- }
- return null;
+ /**
+ * Return a list of all runtime names
+ *
+ * @return List of all runtime names
+ */
+ public List<String> getAllRuntimeNames() {
+ JbossWSRuntime[] rts = getRuntimes();
+ List<String> result = new ArrayList<String>();
+ for (JbossWSRuntime jbossWSRuntime : rts) {
+ result.add(jbossWSRuntime.getName());
}
+ return result;
+ }
+ /**
+ * TBD
+ *
+ * @param oldName
+ * old runtime name
+ * @param newName
+ * new runtime name
+ */
+ public void changeRuntimeName(String oldName, String newName) {
+ JbossWSRuntime o = findRuntimeByName(oldName);
+ if (o == null) {
+ return;
+ }
+ o.setName(newName);
+ onRuntimeNameChanged(oldName, newName);
+ }
- /**
- * Return list of available JbossWSRuntime names
- *
- * @return
- * List<String>
- */
- public List<String> getRuntimeNames() {
- JbossWSRuntime[] rts = getRuntimes();
- List<String> result = new ArrayList<String>();
- for (JbossWSRuntime jbossWSRuntime : rts) {
- result.add(jbossWSRuntime.getName());
- }
- return result;
+ private void onRuntimeNameChanged(String oldName, String newName) {
+ IProjectFacet facet = ProjectFacetsManager
+ .getProjectFacet("jbossws.core");
+ Set<IFacetedProject> facetedProjects = null;
+ try {
+ facetedProjects = ProjectFacetsManager.getFacetedProjects(facet);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
-
- /**
- * Return a list of all runtime names
- *
- * @return
- * List of all runtime names
- */
- public List<String> getAllRuntimeNames() {
- JbossWSRuntime[] rts = getRuntimes();
- List<String> result = new ArrayList<String>();
- for (JbossWSRuntime jbossWSRuntime : rts) {
- result.add(jbossWSRuntime.getName());
+ for (IFacetedProject facetedProject : facetedProjects) {
+ QualifiedName qRuntimeName = new QualifiedName(
+ IJBossWSFacetDataModelProperties.QUALIFIEDNAME_IDENTIFIER_IS_SERVER_SUPPLIED,
+ IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_ID);
+ String name = null;
+ try {
+ name = facetedProject.getProject().getPersistentProperty(qRuntimeName);
+ if (name != null && name.equals(oldName)) {
+ facetedProject.getProject().setPersistentProperty(qRuntimeName, newName);
+ }
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- return result;
- }
- /**
- * TBD
- *
- * @param oldName
- * old runtime name
- * @param newName
- * new runtime name
- */
- public void changeRuntimeName(String oldName, String newName) {
- JbossWSRuntime o = findRuntimeByName(oldName);
- if (o == null) {
- return;
- }
- o.setName(newName);
- onRuntimeNameChanged(oldName, newName);
}
+ }
- private void onRuntimeNameChanged(String oldName, String newName) {
- IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
-// for (int i = 0; i < ps.length; i++) {
-// ISeamProject sp = SeamCorePlugin.getSeamProject(ps[i], false);
-// if (sp != null && oldName.equals(sp.getRuntimeName())) {
-// sp.setRuntimeName(newName);
-// }
-// }
- }
}
\ No newline at end of file
Show replies by date