### Eclipse Workspace Patch 1.0
#P org.eclipse.mtj.core
Index: plugin.xml
===================================================================
--- plugin.xml (revision 475)
+++ plugin.xml (working copy)
@@ -139,6 +139,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
changeList = new ArrayList();
+ ILaunchConfiguration[] configs = getRelatedJadLaunchConfigs(fJavaProject
+ .getElementName());
+ // create changes
+ for (ILaunchConfiguration config : configs) {
+ changeList.add(new JadLaunchConfigProjectRenameChange(config,
+ getArguments().getNewName()));
+ }
+ // return changes
+ int numOfChanges = changeList.size();
+ if (numOfChanges == 0) {
+ return null;
+ } else if (numOfChanges == 1) {
+ return changeList.get(0);
+ } else {
+ return new CompositeChange(
+ RefactoringMessages.JadLaunchConfigCompositeChange_name,
+ changeList.toArray(new Change[changeList.size()]));
+ }
+ }
+
+ /**
+ * Returns a listing of JAD launch configurations that have a specific
+ * project name attribute in them
+ *
+ * @param projectName
+ * the project attribute to compare against
+ * @return the list of "MTJ.emulatorLaunchConfigurationType" type launch
+ * configurations that have the specified project attribute
+ */
+ private ILaunchConfiguration[] getRelatedJadLaunchConfigs(String projectName) {
+ if (projectName == null || projectName.trim().length() == 0) {
+ return new ILaunchConfiguration[0];
+ }
+ try {
+ ILaunchConfiguration[] configs = DebugPlugin.getDefault()
+ .getLaunchManager().getLaunchConfigurations(
+ getEmulatorConfigType());
+ ArrayList list = new ArrayList();
+ // collect relative configs
+ for (int i = 0; i < configs.length; i++) {
+ String projectNameAttribute = configs[i].getAttribute(
+ IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
+ (String) null);
+ boolean doJadLaunch = configs[i].getAttribute(
+ ILaunchConstants.DO_JAD_LAUNCH, false);
+ boolean projectNameEqual = projectName
+ .equals(projectNameAttribute);
+ if (doJadLaunch && projectNameEqual) {
+ list.add(configs[i]);
+ }
+ }
+
+ return list.toArray(new ILaunchConfiguration[list.size()]);
+ } catch (CoreException e) {
+ MTJCorePlugin.log(IStatus.ERROR, e);
+ }
+ return new ILaunchConfiguration[0];
+ }
+
+ /**
+ * Get the launch configuration type for wireless toolkit emulator.
+ *
+ * @return
+ */
+ private ILaunchConfigurationType getEmulatorConfigType() {
+ ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType configType = lm
+ .getLaunchConfigurationType(ILaunchConstants.LAUNCH_CONFIG_TYPE);
+ return configType;
+ }
+}
Index: src/org/eclipse/mtj/core/internal/refactoring/messages.properties
===================================================================
--- src/org/eclipse/mtj/core/internal/refactoring/messages.properties (revision 0)
+++ src/org/eclipse/mtj/core/internal/refactoring/messages.properties (revision 0)
@@ -0,0 +1,16 @@
+###############################################################################
+# Copyright (c) 2008 Sybase Inc. and others.
+#
+# 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
+#
+# Contributors:
+# Feng Wang (Sybase) - Initial implementation
+###############################################################################
+
+JadLaunchConfigParticipant_name = JAD Launch configuration participant
+JadLaunchConfigCompositeChange_name = JAD Launch configuration updates
+JadLaunchConfigProjectRenameChange_name = Update the JAD URL of launch configuration ''{0}''
+JadLaunchConfig_doNotExist = The launch configuration ''{0}'' no longer exists.
Index: src/org/eclipse/mtj/core/internal/refactoring/RefactoringMessages.java
===================================================================
--- src/org/eclipse/mtj/core/internal/refactoring/RefactoringMessages.java (revision 0)
+++ src/org/eclipse/mtj/core/internal/refactoring/RefactoringMessages.java (revision 0)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sybase Inc. and others.
+ *
+ * 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
+ *
+ * Contributors:
+ * Feng Wang (Sybase) - initial implementation
+ *******************************************************************************/
+package org.eclipse.mtj.core.internal.refactoring;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author wangf
+ *
+ */
+public class RefactoringMessages {
+ private static final String BUNDLE_NAME = "org.eclipse.mtj.core.internal.refactoring.messages";//$NON-NLS-1$
+
+ public static String JadLaunchConfigParticipant_name;
+
+ public static String JadLaunchConfigCompositeChange_name;
+
+ public static String JadLaunchConfigProjectRenameChange_name;
+
+ public static String JadLaunchConfig_doNotExist;
+
+ static {
+ // load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, RefactoringMessages.class);
+ }
+}
Index: src/org/eclipse/mtj/core/internal/refactoring/JadLaunchConfigProjectRenameChange.java
===================================================================
--- src/org/eclipse/mtj/core/internal/refactoring/JadLaunchConfigProjectRenameChange.java (revision 0)
+++ src/org/eclipse/mtj/core/internal/refactoring/JadLaunchConfigProjectRenameChange.java (revision 0)
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sybase Inc. and others.
+ *
+ * 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
+ *
+ * Contributors:
+ * Feng Wang (Sybase) - initial implementation
+ *******************************************************************************/
+package org.eclipse.mtj.core.internal.refactoring;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.mtj.core.launching.ILaunchConstants;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * This class update the JAD file URL attribute in the JAD launch configurations
+ * according the project name change.
+ *
+ * @author wangf
+ *
+ */
+public class JadLaunchConfigProjectRenameChange extends Change {
+ /**
+ * The Jad launch configuration to be refactored
+ */
+ private ILaunchConfiguration launchConfiguration;
+ /**
+ * The new project name
+ */
+ private String newProjectName;
+
+ public JadLaunchConfigProjectRenameChange(
+ ILaunchConfiguration launchConfiguration, String newProjectName) {
+ this.launchConfiguration = launchConfiguration;
+ this.newProjectName = newProjectName;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
+ */
+ @Override
+ public Object getModifiedElement() {
+ return launchConfiguration;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
+ @Override
+ public String getName() {
+ return NLS.bind(
+ RefactoringMessages.JadLaunchConfigProjectRenameChange_name,
+ launchConfiguration.getName());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.
+ * eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void initializeValidationData(IProgressMonitor pm) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime
+ * .IProgressMonitor)
+ */
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ if (!launchConfiguration.exists()) {
+ return RefactoringStatus.createFatalErrorStatus(NLS.bind(
+ RefactoringMessages.JadLaunchConfig_doNotExist,
+ launchConfiguration.getName()));
+ }
+ return new RefactoringStatus();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime
+ * .IProgressMonitor)
+ */
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ ILaunchConfigurationWorkingCopy wc = launchConfiguration
+ .getWorkingCopy();
+ String oldJadFileLocation = wc.getAttribute(
+ ILaunchConstants.SPECIFIED_JAD_URL, "");
+
+ String newJadFileLocation = getNewJadFileLocation(oldJadFileLocation,
+ newProjectName);
+ wc.setAttribute(ILaunchConstants.SPECIFIED_JAD_URL, newJadFileLocation);
+
+ if (wc.isDirty()) {
+ wc.doSave();
+ }
+ // return null makes the rename operation cannot undo, what is we expect
+ return null;
+ }
+
+ /**
+ * Return the new launching Jad file location according the new project
+ * name.
+ *
+ * @param oldJadFileLocation
+ * @return
+ */
+ private String getNewJadFileLocation(String oldJadFileLocation,
+ String newProjectName) {
+ IPath newProjectPath = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(newProjectName).getLocation();
+ IPath oldJadPath = new Path(oldJadFileLocation);
+ // The relative Jad file path relative against the project path
+ IPath relativeJadPath = oldJadPath.removeFirstSegments(newProjectPath
+ .segmentCount());
+ IPath newJadPath = newProjectPath.append(relativeJadPath);
+ return newJadPath.toPortableString();
+ }
+}