Author: rob.stryker(a)jboss.com
Date: 2008-05-21 20:32:22 -0400 (Wed, 21 May 2008)
New Revision: 8285
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/SingleDeployableFactory.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/DeployAction.java
Log:
JBIDE-1458 - changes suggested by max
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/SingleDeployableFactory.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/SingleDeployableFactory.java 2008-05-21
21:47:33 UTC (rev 8284)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/SingleDeployableFactory.java 2008-05-22
00:32:22 UTC (rev 8285)
@@ -38,6 +38,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
@@ -288,21 +289,28 @@
}
}
- public class UndeployFromServerJob extends Job {
+ public static class UndeployFromServerJob extends Job {
private ArrayList<IPath> paths;
+ private boolean removeFromFactory;
public UndeployFromServerJob(ArrayList<IPath> paths) {
+ this(paths,true);
+ }
+ public UndeployFromServerJob(ArrayList<IPath> paths, boolean removeFromFactory)
{
super("Undeploy Single Files From Server");
this.paths = paths;
+ this.removeFromFactory = removeFromFactory;
}
protected IStatus run(IProgressMonitor monitor) {
IPath next;
IModule mod;
IServer[] allServers = ServerCore.getServers();
+ MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IStatus.ERROR,
"Failed to undeploy modules from all servers", null);
for( Iterator i = paths.iterator(); i.hasNext(); ) {
next = (IPath)i.next();
- mod = getModule(next);
+ mod = getFactory().getModule(next);
if( mod != null ) {
+ boolean removedFromAllServers = true;
for( int j = 0; j < allServers.length; j++ ) {
List l = Arrays.asList(allServers[j].getModules());
if( l.contains(mod)) {
@@ -312,12 +320,18 @@
IServer s = copy.save(false, new NullProgressMonitor());
new PublishServerJob(s).schedule();
} catch( CoreException ce ) {
+ removedFromAllServers = false;
+ IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Failed to remove " + next + " from " + allServers[j].getName(), ce);
+ ms.add(s);
}
}
}
+ if( removeFromFactory && removedFromAllServers )
+ SingleDeployableFactory.unmakeDeployable(next);
+
}
}
- return Status.OK_STATUS;
+ return ms.getChildren().length == 0 ? Status.OK_STATUS : ms;
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/DeployAction.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/DeployAction.java 2008-05-21
21:47:33 UTC (rev 8284)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/DeployAction.java 2008-05-22
00:32:22 UTC (rev 8285)
@@ -21,8 +21,13 @@
*/
package org.jboss.ide.eclipse.as.ui.actions;
+import java.util.ArrayList;
+import java.util.Iterator;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
@@ -55,6 +60,7 @@
import org.eclipse.wst.server.core.internal.PublishServerJob;
import org.eclipse.wst.server.ui.internal.ImageResource;
import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory;
+import
org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory.UndeployFromServerJob;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
@@ -71,6 +77,48 @@
public DeployAction() {
}
+ public void selectionChanged(IAction action, ISelection selection) {
+ this.selection = selection;
+ action.setEnabled(verifyEnablement());
+ action.setText(getText(verifyType()));
+ }
+
+ protected boolean verifyEnablement() {
+ if( selection instanceof IStructuredSelection ) {
+ IStructuredSelection sel = (IStructuredSelection)selection;
+ if( sel.isEmpty())
+ return false;
+ Iterator i = sel.iterator();
+ while(i.hasNext())
+ if( !(i.next() instanceof IFile ))
+ return false;
+ }
+ return true;
+ }
+
+ protected String getText(boolean type) {
+ if( type )
+ return "Unmake Deployable";
+ return "Make Deployable";
+ }
+
+ // True if we want to unpublish, false if we wantt to publish
+ protected boolean verifyType() {
+ if( selection instanceof IStructuredSelection ) {
+ IStructuredSelection sel = (IStructuredSelection)selection;
+ if( sel.isEmpty())
+ return false;
+ Iterator i = sel.iterator();
+ Object o;
+ while(i.hasNext()) {
+ o = i.next();
+ if( !(o instanceof IFile) ||
SingleDeployableFactory.findModule(((IFile)o).getFullPath()) == null)
+ return false;
+ }
+ }
+ return true;
+ }
+
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
if(targetPart!=null && targetPart.getSite()!=null) {
shell = targetPart.getSite().getShell();
@@ -78,6 +126,35 @@
}
public void run(IAction action) {
+ if( verifyType())
+ makeUndeployable();
+ else
+ makeDeployable();
+ }
+
+ protected void makeDeployable() {
+ IStructuredSelection sel2 = (IStructuredSelection)selection;
+ Object[] objs = sel2.toArray();
+ IModule[] modules = new IModule[objs.length];
+ for( int i = 0; i < objs.length; i++ ) {
+ SingleDeployableFactory.makeDeployable(((IFile)objs[i]).getFullPath());
+ modules[i] = SingleDeployableFactory.findModule(((IFile)objs[i]).getFullPath());
+ }
+
+ tryToPublish();
+ }
+
+ protected void makeUndeployable() {
+ IStructuredSelection sel2 = (IStructuredSelection)selection;
+ Object[] objs = sel2.toArray();
+ ArrayList<IPath> paths = new ArrayList<IPath>();
+ for( int i = 0; i < objs.length; i++ )
+ if(objs[i] instanceof IFile )
+ paths.add(((IFile)objs[i]).getFullPath());
+ new UndeployFromServerJob(paths).schedule();
+ }
+
+ protected void tryToPublish() {
IServer[] deployableServersAsIServers =
ServerConverter.getDeployableServersAsIServers();
if(deployableServersAsIServers.length==0) {
MessageDialog.openInformation(shell, "No deployable servers found",
"There are no servers that support deploying single files.");
@@ -104,7 +181,6 @@
} else {
IModule[] modules = new IModule[objs.length];
for( int i = 0; i < objs.length; i++ ) {
- SingleDeployableFactory.makeDeployable(((IFile)objs[i]).getFullPath());
modules[i] = SingleDeployableFactory.findModule(((IFile)objs[i]).getFullPath());
}
try {
@@ -148,11 +224,6 @@
return null;
}
- public void selectionChanged(IAction action, ISelection selection) {
- this.selection = selection;
- }
-
-
public class SelectServerDialog extends Dialog {
private Object selected;
private final class LabelProviderExtension extends BaseLabelProvider implements
ILabelProvider {
Show replies by date