Author: snjeza
Date: 2008-12-13 16:54:26 -0500 (Sat, 13 Dec 2008)
New Revision: 12585
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/icons/actions/xpl/explore.gif
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/ExploreAction.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/ExploreUtils.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/JBossServerUISharedImages.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/extensions/ModuleActionProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/wst/server/ui/ServerActionProvider.java
Log:
JBIDE-3087 Add an action to the server entry in the Servers view to open the deploy
folder using the default OS file explorer
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/icons/actions/xpl/explore.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/icons/actions/xpl/explore.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/JBossServerUISharedImages.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/JBossServerUISharedImages.java 2008-12-13
16:24:13 UTC (rev 12584)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/JBossServerUISharedImages.java 2008-12-13
21:54:26 UTC (rev 12585)
@@ -52,6 +52,7 @@
public static final String PUBLISH_IMAGE = "PUBLISH_IMAGE";
public static final String UNPUBLISH_IMAGE = "UNPUBLISH_IMAGE";
public static final String JMX_IMAGE = "JMX_IMAGE";
+ public static final String EXPLORE_IMAGE = "EXPLORE_IMAGE";
private static JBossServerUISharedImages instance;
@@ -76,6 +77,7 @@
descriptors.put(PUBLISH_IMAGE, createImageDescriptor(pluginBundle,
"/icons/publish.gif"));
descriptors.put(UNPUBLISH_IMAGE, createImageDescriptor(pluginBundle,
"/icons/unpublish.gif"));
descriptors.put(JMX_IMAGE, createImageDescriptor(pluginBundle,
"/icons/jmeth_obj.gif"));
+ descriptors.put(EXPLORE_IMAGE, createImageDescriptor(pluginBundle,
"/icons/actions/xpl/explore.gif"));
Iterator<String> iter = descriptors.keySet().iterator();
while (iter.hasNext()) {
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/ExploreAction.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/ExploreAction.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/ExploreAction.java 2008-12-13
21:54:26 UTC (rev 12585)
@@ -0,0 +1,56 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.ide.eclipse.as.ui.actions;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.ui.internal.view.servers.AbstractServerAction;
+import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
+import org.jboss.ide.eclipse.as.ui.JBossServerUISharedImages;
+
+/**
+ * @author snjeza
+ *
+ */
+
+public class ExploreAction extends AbstractServerAction {
+
+ public ExploreAction(Shell shell, ISelectionProvider selectionProvider) {
+ super(shell, selectionProvider, ExploreUtils.EXPLORE);
+ setToolTipText(ExploreUtils.EXPLORE_DESCRIPTION);
+ setImageDescriptor(JBossServerUISharedImages.getImageDescriptor(JBossServerUISharedImages.EXPLORE_IMAGE));
+ try {
+ selectionChanged((IStructuredSelection) selectionProvider
+ .getSelection());
+ } catch (Exception ignore) {
+ }
+ }
+
+ @Override
+ public void perform(IServer server) {
+ String deployDirectory = ExploreUtils.getDeployDirectory(server);
+ if (deployDirectory != null && deployDirectory.length() > 0) {
+ ExploreUtils.explore(deployDirectory);
+ }
+
+ }
+
+ @Override
+ public boolean accept(IServer server) {
+ return ExploreUtils.canExplore(server);
+ }
+
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/ExploreUtils.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/ExploreUtils.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/actions/ExploreUtils.java 2008-12-13
21:54:26 UTC (rev 12585)
@@ -0,0 +1,145 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.ide.eclipse.as.ui.actions;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
+
+/**
+ * @author snjeza
+ *
+ */
+
+public class ExploreUtils {
+
+ public final static String PATH = "{%}";
+ public final static String EXPLORE = "Explore";
+ public final static String EXPLORE_DESCRIPTION = "Explore deploy directory";
+ private static String exploreFolderCommand;
+ private static String exploreFileCommand;
+
+ public static String getExploreCommand() {
+ if (exploreFolderCommand == null) {
+ setExploreCommands();
+ }
+ return exploreFolderCommand;
+ }
+
+ public static String getExploreFileCommand() {
+ if (exploreFileCommand == null) {
+ setExploreCommands();
+ }
+ return exploreFileCommand;
+ }
+
+ private static void setExploreCommands() {
+ if (Platform.OS_MACOSX.equals(Platform.getOS())) {
+ exploreFolderCommand = "/usr/bin/open -a /System/Library/CoreServices/Finder.app
\""
+ + PATH + "\"";
+ exploreFileCommand = exploreFolderCommand;
+ } else if (Platform.OS_WIN32.equals(Platform.getOS())) {
+ exploreFolderCommand = "cmd /C start explorer /root,/e,\""
+ + PATH + "\"";
+ exploreFileCommand = "cmd /C start explorer /select,/e,\""
+ + PATH + "\"";
+ } else if (Platform.OS_LINUX.equals(Platform.getOS())) {
+ if (new File("/usr/bin/nautilus").exists()) {
+ exploreFolderCommand = "/usr/bin/nautilus \"" + PATH +
"\"";
+ } else if (new File("/usr/bin/konqueror").exists()) {
+ exploreFolderCommand = "/usr/bin/konqueror \"" + PATH
+ + "\"";
+ }
+ exploreFileCommand = exploreFolderCommand;
+ }
+ }
+
+ public static String getDeployDirectory(IServer server) {
+ IDeployableServer deployableServer = ServerConverter.getDeployableServer(server);
+ if (deployableServer != null) {
+ return deployableServer.getDeployFolder();
+ }
+ IServerWorkingCopy swc = server.createWorkingCopy();
+ ServerAttributeHelper helper = new ServerAttributeHelper(swc
+ .getOriginal(), swc);
+ String deployDirectory = helper.getAttribute(
+ IDeployableServer.DEPLOY_DIRECTORY, "");
+ return deployDirectory.trim();
+ }
+
+ public static boolean canExplore(IServer server) {
+ String deployDirectory = ExploreUtils.getDeployDirectory(server);
+ if (deployDirectory == null || deployDirectory.length() <= 0) {
+ return false;
+ }
+ if (ExploreUtils.getExploreCommand() == null) {
+ return false;
+ }
+ return true;
+ }
+
+ public static void explore(String name) {
+ File file = new File(name);
+ String command = null;
+ if (file.isFile()) {
+ command = getExploreFileCommand();
+ } else {
+ command = getExploreCommand();
+ }
+ if (command != null) {
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ name = name.replace('/', '\\');
+ }
+ command = command.replace(ExploreUtils.PATH, name);
+ try {
+ Runtime.getRuntime().exec(command);
+ } catch (IOException e) {
+ JBossServerUIPlugin.log(e.getMessage(),e);
+ }
+ }
+ }
+
+ public static IPath getDeployPath(IDeployableServer server,IModule[] moduleTree) {
+ IPath root = new Path( server.getDeployFolder() );
+ String type, name;
+ for( int i = 0; i < moduleTree.length; i++ ) {
+ type = moduleTree[i].getModuleType().getId();
+ name = moduleTree[i].getName();
+ if( new Path(name).segmentCount() > 1 )
+ // we strongly suspect this is a binary object and not a project
+ return root.append(new Path(name).lastSegment());
+ if( "jst.ear".equals(type))
+ root = root.append(name + ".ear");
+ else if( "jst.web".equals(type))
+ root = root.append(name + ".war");
+ else if( "jst.utility".equals(type) && i >= 1 &&
"jst.web".equals(moduleTree[i-1].getModuleType().getId()))
+ root = root.append("WEB-INF").append("lib").append(name +
".jar");
+ else if( "jst.connector".equals(type)) {
+ root = root.append(name + ".rar");
+ } else if( "jst.jboss.esb".equals(type)){
+ root = root.append(name + ".esb");
+ }else
+ root = root.append(name + ".jar");
+ }
+ return root;
+ }
+
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/extensions/ModuleActionProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/extensions/ModuleActionProvider.java 2008-12-13
16:24:13 UTC (rev 12584)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/extensions/ModuleActionProvider.java 2008-12-13
21:54:26 UTC (rev 12585)
@@ -1,10 +1,13 @@
package org.jboss.ide.eclipse.as.ui.views.server.extensions;
+import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -21,12 +24,21 @@
import org.eclipse.wst.server.core.internal.PublishServerJob;
import org.eclipse.wst.server.core.internal.Server;
import org.eclipse.wst.server.ui.internal.view.servers.ModuleServer;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
+import
org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory.SingleDeployableModuleDelegate;
+import org.jboss.ide.eclipse.as.core.publishers.JstPublisher;
+import org.jboss.ide.eclipse.as.core.publishers.SingleFilePublisher;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
import org.jboss.ide.eclipse.as.core.util.ModuleUtil;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.ide.eclipse.as.ui.JBossServerUISharedImages;
import org.jboss.ide.eclipse.as.ui.Messages;
+import org.jboss.ide.eclipse.as.ui.actions.ExploreUtils;
public class ModuleActionProvider extends CommonActionProvider {
private Action deleteModuleAction, fullPublishModuleAction,
incrementalPublishModuleAction;
+ private Action exploreAction;
private ModuleServer[] selection;
private ICommonActionExtensionSite actionSite;
@@ -57,6 +69,15 @@
menu.add(deleteModuleAction);
menu.add(fullPublishModuleAction);
menu.add(incrementalPublishModuleAction);
+ if (selection.size() == 1) {
+ ModuleServer moduleServer = (ModuleServer) selection.getFirstElement();
+ IServer server = moduleServer.getServer();
+ if (ExploreUtils.canExplore(server)) {
+ if (getDeployPath() != null) {
+ menu.add(exploreAction);
+ }
+ }
+ }
}
}
@@ -100,6 +121,20 @@
incrementalPublishModuleAction.setDescription(Messages.PublishModuleDescription);
incrementalPublishModuleAction.setImageDescriptor(JBossServerUISharedImages.getImageDescriptor(JBossServerUISharedImages.PUBLISH_IMAGE));
+ exploreAction = new Action() {
+ public void run() {
+ IPath path = getDeployPath();
+ if (path != null) {
+ File file = path.toFile();
+ if (file.exists()) {
+ ExploreUtils.explore(file.getAbsolutePath());
+ }
+ }
+ }
+ };
+ exploreAction.setText(ExploreUtils.EXPLORE);
+ exploreAction.setDescription(ExploreUtils.EXPLORE_DESCRIPTION);
+ exploreAction.setImageDescriptor(JBossServerUISharedImages.getImageDescriptor(JBossServerUISharedImages.EXPLORE_IMAGE));
}
protected void actionPublish(int type) {
@@ -144,4 +179,32 @@
t.start();
}
}
+
+ private IPath getDeployPath() {
+ ModuleServer ms = selection[0];
+ IModule[] module = ms.module;
+ IJBossServerPublisher publisher = ExtensionManager.getDefault()
+ .getPublisher(ms.getServer(), module);
+ IPath path = null;
+ IDeployableServer deployableServer = ServerConverter
+ .getDeployableServer(ms.server);
+ if (deployableServer != null) {
+ if (publisher instanceof JstPublisher) {
+ path = ExploreUtils.getDeployPath(deployableServer,
+ module);
+ } else if (publisher instanceof SingleFilePublisher) {
+ SingleDeployableModuleDelegate delegate =
(SingleDeployableModuleDelegate)module[0].loadAdapter(SingleDeployableModuleDelegate.class,
new NullProgressMonitor());
+ if (delegate != null) {
+ IPath sourcePath = delegate.getGlobalSourcePath();
+ IPath destFolder = new Path(deployableServer.getDeployFolder());
+ path = destFolder.append(sourcePath.lastSegment());
+ } else {
+ path = new Path(deployableServer.getDeployFolder());
+ }
+ } else {
+ path = new Path(deployableServer.getDeployFolder());
+ }
+ }
+ return path;
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/wst/server/ui/ServerActionProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/wst/server/ui/ServerActionProvider.java 2008-12-13
16:24:13 UTC (rev 12584)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/tools/as/wst/server/ui/ServerActionProvider.java 2008-12-13
21:54:26 UTC (rev 12585)
@@ -57,6 +57,7 @@
import org.eclipse.wst.server.ui.internal.view.servers.StartModuleAction;
import org.eclipse.wst.server.ui.internal.view.servers.StopAction;
import org.eclipse.wst.server.ui.internal.view.servers.StopModuleAction;
+import org.jboss.ide.eclipse.as.ui.actions.ExploreAction;
public class ServerActionProvider extends CommonActionProvider {
private ICommonActionExtensionSite actionSite;
@@ -111,7 +112,7 @@
clipboard = new Clipboard(tableViewer.getTree().getDisplay());
Shell shell = tableViewer.getTree().getShell();
- actions = new Action[6];
+ actions = new Action[7];
// create the start actions
actions[0] = new StartAction(shell, provider, ILaunchManager.DEBUG_MODE);
actions[1] = new StartAction(shell, provider, ILaunchManager.RUN_MODE);
@@ -123,6 +124,7 @@
// create the publish actions
actions[4] = new PublishAction(shell, provider);
actions[5] = new PublishCleanAction(shell, provider);
+ actions[6] = new ExploreAction(shell,provider);
// create the open action
openAction = new OpenAction(provider);