Author: rob.stryker(a)jboss.com
Date: 2008-06-16 14:29:05 -0400 (Mon, 16 Jun 2008)
New Revision: 8802
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/build/SaveArchivesJob.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/ArchivesModelModuleContributor.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/packages/ArchivePublishWizard.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ArchivesMenuHandler.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/AbstractArchiveWizard.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/FilesetWizard.java
Log:
JBIDE-2319 - also in trunk
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/ArchivesModelModuleContributor.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/ArchivesModelModuleContributor.java 2008-06-16
18:19:03 UTC (rev 8801)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/ArchivesModelModuleContributor.java 2008-06-16
18:29:05 UTC (rev 8802)
@@ -1,186 +1,185 @@
-/**
- * JBoss, a Division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
-* This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.as.core.modules;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.wst.server.core.IModule;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.modules.PackageModuleFactory.IModuleContributor;
-import
org.jboss.ide.eclipse.as.core.modules.PackageModuleFactory.PackagedModuleDelegate;
-
-/**
- *
- * @author Rob Stryker rob.stryker(a)jboss.com
- *
- */
-public class ArchivesModelModuleContributor implements IModuleContributor {
-
- private static ArchivesModelModuleContributor instance;
- public static ArchivesModelModuleContributor getInstance() {
- if( instance == null ) {
- instance = new ArchivesModelModuleContributor(PackageModuleFactory.getFactory());
- }
- return instance;
- }
-
- private PackageModuleFactory factory;
- protected ArrayList<IModule> modules = null;
- protected HashMap<IPath, ArrayList<IModule>> projectToModules = new
HashMap<IPath, ArrayList<IModule>>(5); //IPath to IModule
- protected HashMap<IModule, Object> moduleDelegates = new HashMap<IModule,
Object>(5);
- protected HashMap<IArchive, IModule> packageToModule = new HashMap<IArchive,
IModule>(5);
-
- private ArchivesModelModuleContributor(PackageModuleFactory factory) {
- this.factory = factory;
- }
-
- public IModule[] getModules() {
- if( modules == null ) {
- modules = new ArrayList<IModule>();
- IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- int size = projects2.length;
- for (int i = 0; i < size; i++) {
- if (projects2[i].isAccessible()) {
-
- if( !ArchivesModel.instance().isProjectRegistered(projects2[i].getLocation())) {
- if( ArchivesModel.instance().canReregister(projects2[i].getLocation()))
- // registration should also add this to the factory manually, so do not create the
module
- ArchivesModel.instance().registerProject(projects2[i].getLocation(), new
NullProgressMonitor());
- } else {
- try {
- // project is already registered. create the module
- createModules(projects2[i]);
- } catch(ArchivesModelException ame) {
- IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
ame.getMessage(), ame);
- JBossServerCorePlugin.getDefault().getLog().log(status);
- }
- }
- }
- }
- }
- return modules.toArray(new IModule[modules.size()]);
- }
-
- protected void createModules(IProject project) throws ArchivesModelException {
- IArchive[] packages = ModelUtil.getProjectArchives(project.getLocation());
- if( packages != null && packages.length > 0 ) {
- IModule module;
- boolean requiresSave = ensureArchivesHaveIDs(project, packages);
- ArrayList<IModule> mods = new ArrayList<IModule>();
- for( int i = 0; i < packages.length; i++ ) {
- module = factory.createModule2(packages[i], project);
- modules.add(module);
- Object moduleDelegate = new PackagedModuleDelegate(packages[i]);
- packageToModule.put(packages[i], module);
- moduleDelegates.put(module, moduleDelegate);
- mods.add(module);
- }
- projectToModules.put(project.getLocation(), mods);
- if( requiresSave ) {
- try {
- ArchivesModel.instance().save(project.getLocation(),
- new NullProgressMonitor());
- } catch( ArchivesModelException ame ) {
-
- }
- }
- }
- }
-
- public boolean containsModule(IModule module) {
- return moduleDelegates.containsKey(module);
- }
-
- public PackagedModuleDelegate getModuleDelegate(IModule module) {
- return (PackagedModuleDelegate)moduleDelegates.get(module);
- }
-
- public void refreshProject(IPath projectLoc) {
- // prime, make sure all are found
- if( modules == null )
- getModules();
-
- // remove old mods
- ArrayList<IModule> mods = projectToModules.get(projectLoc);
- IModule mod;
- PackagedModuleDelegate delegate;
- if (mods != null) {
- for( Iterator<IModule> i = mods.iterator(); i.hasNext();) {
- mod = (IModule)i.next();
- if( modules.contains(mod)) {
- delegate = ((PackagedModuleDelegate)moduleDelegates.get(mod));
- moduleDelegates.remove(mod);
- modules.remove(mod);
- if( delegate != null )
- packageToModule.remove(delegate.getPackage());
- }
- }
- }
- try {
- createModules(findProject(projectLoc));
- } catch( ArchivesModelException ame ) {
- IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
ame.getMessage(), ame);
- JBossServerCorePlugin.getDefault().getLog().log(status);
- }
- }
-
- protected IProject findProject(IPath projectLoc) {
- IProject proj = null;
- IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- int size = projects2.length;
- for (int i = 0; i < size; i++) {
- if( projects2[i].getLocation().equals(projectLoc))
- proj = projects2[i];
- }
- return proj;
- }
-
- /**
- * Set a property so that each module that's here in the factory
- * has a unique ID other than it's name (which is not unique)
- * @param archives
- * @return returns whether a save has occurred
- */
- protected boolean ensureArchivesHaveIDs(IProject project, IArchive[] archives) {
- boolean requiresSave = false;
- for( int i = 0; i < archives.length; i++ ) {
- if( PackageModuleFactory.getID(archives[i]) == null ) {
- requiresSave = true;
- archives[i].setProperty(PackageModuleFactory.MODULE_ID_PROPERTY_KEY,
- PackageModuleFactory.getID(archives[i], true));
- }
- }
- return requiresSave;
- }
-}
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+* This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.core.modules;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.modules.PackageModuleFactory.IModuleContributor;
+import
org.jboss.ide.eclipse.as.core.modules.PackageModuleFactory.PackagedModuleDelegate;
+
+/**
+ *
+ * @author Rob Stryker rob.stryker(a)jboss.com
+ *
+ */
+public class ArchivesModelModuleContributor implements IModuleContributor {
+
+ private static ArchivesModelModuleContributor instance;
+ public static ArchivesModelModuleContributor getInstance() {
+ if( instance == null ) {
+ instance = new ArchivesModelModuleContributor(PackageModuleFactory.getFactory());
+ }
+ return instance;
+ }
+
+ private PackageModuleFactory factory;
+ protected ArrayList<IModule> modules = null;
+ protected HashMap<IPath, ArrayList<IModule>> projectToModules = new
HashMap<IPath, ArrayList<IModule>>(5); //IPath to IModule
+ protected HashMap<IModule, Object> moduleDelegates = new HashMap<IModule,
Object>(5);
+ protected HashMap<IArchive, IModule> packageToModule = new HashMap<IArchive,
IModule>(5);
+
+ private ArchivesModelModuleContributor(PackageModuleFactory factory) {
+ this.factory = factory;
+ }
+
+ public IModule[] getModules() {
+ if( modules == null ) {
+ modules = new ArrayList<IModule>();
+ IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ int size = projects2.length;
+ for (int i = 0; i < size; i++) {
+ if (projects2[i].isAccessible()) {
+
+ if( !ArchivesModel.instance().isProjectRegistered(projects2[i].getLocation())) {
+ if( ArchivesModel.instance().canReregister(projects2[i].getLocation()))
+ // registration should also add this to the factory manually, so do not create the
module
+ ArchivesModel.instance().registerProject(projects2[i].getLocation(), new
NullProgressMonitor());
+ } else {
+ try {
+ // project is already registered. create the module
+ createModules(projects2[i]);
+ } catch(ArchivesModelException ame) {
+ IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
ame.getMessage(), ame);
+ JBossServerCorePlugin.getDefault().getLog().log(status);
+ }
+ }
+ }
+ }
+ }
+ return modules.toArray(new IModule[modules.size()]);
+ }
+
+ protected void createModules(IProject project) throws ArchivesModelException {
+ IArchive[] packages = ModelUtil.getProjectArchives(project.getLocation());
+ if( packages != null && packages.length > 0 ) {
+ IModule module;
+ boolean requiresSave = ensureArchivesHaveIDs(project, packages);
+ ArrayList<IModule> mods = new ArrayList<IModule>();
+ for( int i = 0; i < packages.length; i++ ) {
+ module = factory.createModule2(packages[i], project);
+ modules.add(module);
+ Object moduleDelegate = new PackagedModuleDelegate(packages[i]);
+ packageToModule.put(packages[i], module);
+ moduleDelegates.put(module, moduleDelegate);
+ mods.add(module);
+ }
+ projectToModules.put(project.getLocation(), mods);
+ if( requiresSave ) {
+ try {
+ ArchivesModel.instance().save(project.getLocation(),
+ new NullProgressMonitor());
+ } catch( ArchivesModelException ame ) {
+ }
+ }
+ }
+ }
+
+ public boolean containsModule(IModule module) {
+ return moduleDelegates.containsKey(module);
+ }
+
+ public PackagedModuleDelegate getModuleDelegate(IModule module) {
+ return (PackagedModuleDelegate)moduleDelegates.get(module);
+ }
+
+ public void refreshProject(IPath projectLoc) {
+ // prime, make sure all are found
+ if( modules == null )
+ getModules();
+
+ // remove old mods
+ ArrayList<IModule> mods = projectToModules.get(projectLoc);
+ IModule mod;
+ PackagedModuleDelegate delegate;
+ if (mods != null) {
+ for( Iterator<IModule> i = mods.iterator(); i.hasNext();) {
+ mod = (IModule)i.next();
+ if( modules.contains(mod)) {
+ delegate = ((PackagedModuleDelegate)moduleDelegates.get(mod));
+ moduleDelegates.remove(mod);
+ modules.remove(mod);
+ if( delegate != null )
+ packageToModule.remove(delegate.getPackage());
+ }
+ }
+ }
+ try {
+ createModules(findProject(projectLoc));
+ } catch( ArchivesModelException ame ) {
+ IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
ame.getMessage(), ame);
+ JBossServerCorePlugin.getDefault().getLog().log(status);
+ }
+ }
+
+ protected IProject findProject(IPath projectLoc) {
+ IProject proj = null;
+ IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ int size = projects2.length;
+ for (int i = 0; i < size; i++) {
+ if( projects2[i].getLocation().equals(projectLoc))
+ proj = projects2[i];
+ }
+ return proj;
+ }
+
+ /**
+ * Set a property so that each module that's here in the factory
+ * has a unique ID other than it's name (which is not unique)
+ * @param archives
+ * @return returns whether a save has occurred
+ */
+ protected boolean ensureArchivesHaveIDs(IProject project, IArchive[] archives) {
+ boolean requiresSave = false;
+ for( int i = 0; i < archives.length; i++ ) {
+ if( PackageModuleFactory.getID(archives[i]) == null ) {
+ requiresSave = true;
+ archives[i].setProperty(PackageModuleFactory.MODULE_ID_PROPERTY_KEY,
+ PackageModuleFactory.getID(archives[i], true));
+ }
+ }
+ return requiresSave;
+ }
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/packages/ArchivePublishWizard.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/packages/ArchivePublishWizard.java 2008-06-16
18:19:03 UTC (rev 8801)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/packages/ArchivePublishWizard.java 2008-06-16
18:29:05 UTC (rev 8802)
@@ -27,6 +27,7 @@
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.jboss.ide.eclipse.archives.core.build.SaveArchivesJob;
import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
@@ -48,16 +49,7 @@
pack.setProperty(ArchivesBuildListener.DEPLOY_SERVERS, alwaysPublish ? getServers() :
null);
pack.setProperty(ArchivesBuildListener.DEPLOY_AFTER_BUILD, getAutoDeploy());
final IPath p = pack.getProjectPath();
- new Job("Saving Archives Preferences") {
- protected IStatus run(IProgressMonitor monitor) {
- try {
- ArchivesModel.instance().save(p, null);
- return Status.OK_STATUS;
- } catch( ArchivesModelException ame ) {
- return new Status(IStatus.ERROR, JBossServerUIPlugin.PLUGIN_ID, "Unable to save
archive preferences", ame);
- }
- }
- }.schedule();
+ new SaveArchivesJob(p).schedule();
return true;
}
public void addPages() {
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/build/SaveArchivesJob.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/build/SaveArchivesJob.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/build/SaveArchivesJob.java 2008-06-16
18:29:05 UTC (rev 8802)
@@ -0,0 +1,43 @@
+package org.jboss.ide.eclipse.archives.core.build;
+
+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;
+import org.eclipse.core.runtime.jobs.Job;
+import org.jboss.ide.eclipse.archives.core.ArchivesCorePlugin;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+
+public class SaveArchivesJob extends Job {
+ private Runnable runnable;
+ private IPath projectPath;
+ public SaveArchivesJob(IPath projectPath) {
+ this(projectPath, null, null);
+ }
+ public SaveArchivesJob(IPath projectPath,Runnable runnable, String jobName) {
+ super(jobName == null ? "Save Archives Job" : jobName);
+ this.runnable = runnable;
+ this.projectPath = projectPath;
+ }
+
+ protected IStatus run(IProgressMonitor monitor) {
+ if( runnable != null ) {
+ try {
+ runnable.run();
+ } catch( Exception e ) {
+ IStatus status = new Status(IStatus.ERROR, ArchivesCorePlugin.PLUGIN_ID,
"Problem executing pre-save runnable", e);
+ return status;
+ }
+ }
+ try {
+ ArchivesModel.instance().save(projectPath, new NullProgressMonitor());
+ } catch( ArchivesModelException ame ) {
+ IStatus status = new Status(IStatus.ERROR, ArchivesCorePlugin.PLUGIN_ID, "Problem
saving archives model", ame);
+ return status;
+ }
+ return Status.OK_STATUS;
+ }
+
+}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ArchivesMenuHandler.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ArchivesMenuHandler.java 2008-06-16
18:19:03 UTC (rev 8801)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ArchivesMenuHandler.java 2008-06-16
18:29:05 UTC (rev 8802)
@@ -1,449 +1,405 @@
-package org.jboss.ide.eclipse.archives.ui.views;
-
-import java.util.Arrays;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.GroupMarker;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.IViewSite;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.PlatformUI;
-import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
-import org.jboss.ide.eclipse.archives.core.model.ArchiveNodeFactory;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
-import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
-import org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages;
-import org.jboss.ide.eclipse.archives.ui.ExtensionManager;
-import org.jboss.ide.eclipse.archives.ui.NodeContribution;
-import org.jboss.ide.eclipse.archives.ui.PackagesUIPlugin;
-import org.jboss.ide.eclipse.archives.ui.actions.ActionWithDelegate;
-import org.jboss.ide.eclipse.archives.ui.actions.NewArchiveAction;
-import org.jboss.ide.eclipse.archives.ui.actions.NewJARAction;
-import
org.jboss.ide.eclipse.archives.ui.providers.ArchivesContentProvider.WrappedProject;
-import org.jboss.ide.eclipse.archives.ui.wizards.FilesetWizard;
-import org.jboss.ide.eclipse.archives.ui.wizards.NewJARWizard;
-
-/**
- * Manages the actions associated with the view
- * @author rstryker
- *
- */
-public class ArchivesMenuHandler {
- public static final String NEW_PACKAGE_MENU_ID =
"org.jboss.ide.eclipse.archives.ui.newPackageMenu";
- public static final String NODE_CONTEXT_MENU_ID =
"org.jboss.ide.eclipse.archives.ui.nodeContextMenu";
- public static final String NEW_PACKAGE_ADDITIONS = "newPackageAdditions";
-
- private MenuManager newPackageManager, contextMenuManager;
- private NodeContribution[] nodePopupMenuContributions;
- private NewArchiveAction[] newPackageActions;
- private Menu treeContextMenu;
- private TreeViewer packageTree;
-
- private Action editAction, deleteAction, newFolderAction, newFilesetAction;
- private NewJARAction newJARAction;
- private Action buildAction;
-
- public ArchivesMenuHandler(TreeViewer viewer) {
- this.packageTree = viewer;
-
- // load from extensions
- newPackageActions = ExtensionManager.findNewArchiveActions();
- nodePopupMenuContributions = ExtensionManager.findNodePopupMenuContributions();
- Arrays.sort(nodePopupMenuContributions);
-
-
- createActions();
- createMenu();
- createContextMenu();
- addToActionBars();
- }
-
- private void addToActionBars() {
- IActionBars bars = getSite().getActionBars();
- bars.getToolBarManager().add(buildAction);
- }
-
- /**
- * Creates the primary menu as well as adds the package actions to it
- *
- */
- private void createMenu () {
- newPackageManager = new
MenuManager(ArchivesUIMessages.ProjectPackagesView_newPackageMenu_label,
NEW_PACKAGE_MENU_ID);
- addNewPackageActions(newPackageManager);
- newPackageManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
- }
-
- private void createContextMenu () {
- contextMenuManager = new MenuManager(NODE_CONTEXT_MENU_ID); //$NON-NLS-1$
- contextMenuManager.setRemoveAllWhenShown(true);
- contextMenuManager.addMenuListener(new IMenuListener () {
- public void menuAboutToShow(IMenuManager manager) {
- IStructuredSelection selection = (IStructuredSelection) packageTree.getSelection();
- if (selection != null && !selection.isEmpty()) {
- Object element = selection.getFirstElement();
-
- if (element instanceof WrappedProject) {
- newJARAction.setEnabled(true);
- manager.add(newPackageManager);
- manager.add(buildAction);
- buildAction.setText(ArchivesUIMessages.ProjectPackagesView_buildProjectAction_label);
- } else if( element instanceof IArchiveNode ){
- IArchiveNode node = (IArchiveNode)element;
-
- switch(node.getNodeType()) {
- case IArchiveNode.TYPE_ARCHIVE:
- newJARAction.setEnabled(true);
- manager.add(newPackageManager);
- manager.add(newFolderAction);
- manager.add(newFilesetAction);
- manager.add(new Separator());
- editAction.setText(ArchivesUIMessages.ProjectPackagesView_editPackageAction_label);
//$NON-NLS-1$
- deleteAction.setText(ArchivesUIMessages.ProjectPackagesView_deletePackageAction_label);
//$NON-NLS-1$
- editAction.setImageDescriptor(ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_PACKAGE_EDIT));
- buildAction.setText(ArchivesUIMessages.ProjectPackagesView_buildArchiveAction_label);
- manager.add(buildAction);
- break;
- case IArchiveNode.TYPE_ARCHIVE_FOLDER:
- newJARAction.setEnabled(true);
- manager.add(newPackageManager);
- manager.add(newFolderAction);
- manager.add(newFilesetAction);
- manager.add(new Separator());
- editAction.setText(ArchivesUIMessages.ProjectPackagesView_editFolderAction_label);
//$NON-NLS-1$
- deleteAction.setText(ArchivesUIMessages.ProjectPackagesView_deleteFolderAction_label);
//$NON-NLS-1$
- editAction.setImageDescriptor(platformDescriptor(ISharedImages.IMG_OBJ_FOLDER));
- break;
- case IArchiveNode.TYPE_ARCHIVE_FILESET:
- editAction.setText(ArchivesUIMessages.ProjectPackagesView_editFilesetAction_label);
//$NON-NLS-1$
- deleteAction.setText(ArchivesUIMessages.ProjectPackagesView_deleteFilesetAction_label);
//$NON-NLS-1$
- editAction.setImageDescriptor(ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_MULTIPLE_FILES));
- break;
- case IArchiveNode.TYPE_ARCHIVE_ACTION:
- editAction.setText(ArchivesUIMessages.ProjectPackagesView_editActionAction_label);
//$NON-NLS-1$
- deleteAction.setText(ArchivesUIMessages.ProjectPackagesView_deleteActionAction_label);
//$NON-NLS-1$
- //editAction.setImageDescriptor(ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_MULTIPLE_FILES));
- editAction.setImageDescriptor(null);
- break;
- default:
- // TODO unknown?
- break;
- }
- manager.add(editAction);
- manager.add(deleteAction);
- addContextMenuContributions(node);
- }
- } else {
- manager.add(newPackageManager);
- }
- }
- });
-
- treeContextMenu = contextMenuManager.createContextMenu(packageTree.getTree());
- packageTree.getTree().setMenu(treeContextMenu);
-
- getSite().registerContextMenu(NEW_PACKAGE_MENU_ID, newPackageManager, packageTree);
- }
-
- protected void createActions() {
- newJARAction = new NewJARAction();
- newJARAction.setEnabled(false);
-
- newFolderAction = new
Action(ArchivesUIMessages.ProjectPackagesView_newFolderAction_label,
platformDescriptor(ISharedImages.IMG_OBJ_FOLDER)) { //$NON-NLS-1$
- public void run () {
- createFolder();
- }
- };
-
- newFilesetAction = new
Action(ArchivesUIMessages.ProjectPackagesView_newFilesetAction_label,
ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_MULTIPLE_FILES)) {
//$NON-NLS-1$
- public void run () {
- createFileset();
- }
- };
-
- deleteAction = new Action
(ArchivesUIMessages.ProjectPackagesView_deletePackageAction_label,
platformDescriptor(ISharedImages.IMG_TOOL_DELETE)) { //$NON-NLS-1$
- public void run () {
- deleteSelectedNode();
- }
- };
-
- editAction = new Action
(ArchivesUIMessages.ProjectPackagesView_editPackageAction_label,
ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_PACKAGE_EDIT)) {
//$NON-NLS-1$
- public void run () {
- editSelectedNode();
- }
- };
-
- buildAction = new ActionWithDelegate("",
ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_BUILD_PACKAGES)) {
- public void run() {
- final Object selected = getSelectedObject();
- new Job("Build Archive Node") {
- protected IStatus run(IProgressMonitor monitor) {
- buildSelectedNode(selected);
- return Status.OK_STATUS;
- }
- }.schedule();
- }
-
- public IStructuredSelection getSelection() {
- return ProjectArchivesView.getInstance().getSelection();
- }
- };
- }
-
- private void addContextMenuContributions (final IArchiveNode context) {
-
- for( int i = 0; i < nodePopupMenuContributions.length; i++ ) {
- try {
-
- final NodeContribution contribution = nodePopupMenuContributions[i];
- if ( contribution.getActionDelegate().isEnabledFor(context)) {
- Action action = new Action () {
- public String getId() {
- return contribution.getId();
- }
-
- public ImageDescriptor getImageDescriptor() {
- return contribution.getIcon();
- }
-
- public String getText() {
- return contribution.getLabel();
- }
-
- public void run() {
- contribution.getActionDelegate().run(context);
- }
- };
- contextMenuManager.add(action);
- }
- } catch( Exception e) { System.out.println(e.getMessage()); }
- }
-
- }
-
-
- /**
- * Adds the new package type actions (which come from an extension point)
- * to the menu.
- * @param manager
- */
- private void addNewPackageActions (IMenuManager manager) {
- for( int i = 0; i < newPackageActions.length; i++ ) {
- final NewArchiveAction action = newPackageActions[i];
-
- Action actionWrapper = new Action () {
- public String getId() {
- return action.getId();
- }
-
- public ImageDescriptor getImageDescriptor() {
- return action.getIconDescriptor();
- }
-
- public String getText() {
- return action.getLabel();
- }
-
- public void run() {
- action.getAction().run(this);
- }
- };
-
- manager.add(actionWrapper);
- }
- }
-
-
-
-
- /*
- * Methods below are called from the standard actions,
- * the implementations of the action, where the action does its work etc
- */
-
- private void createFolder ()
- {
- IInputValidator validator = new IInputValidator () {
- public String isValid(String newText) {
- IArchiveNode selected = getSelectedNode();
-
- boolean folderExists = false;
- IArchiveNode[] folders = selected.getChildren(IArchiveNode.TYPE_ARCHIVE_FOLDER);
- for (int i = 0; i < folders.length; i++) {
- IArchiveFolder folder = (IArchiveFolder) folders[i];
- if (folder.getName().equals(newText)) {
- folderExists = true; break;
- }
- }
-
- if (folderExists) {
- return ArchivesUIMessages.bind(
- ArchivesUIMessages.ProjectPackagesView_createFolderDialog_warnFolderExists,
newText);
-
- }
- return null;
- }
- };
-
- InputDialog dialog = new InputDialog(getSite().getShell(),
- ArchivesUIMessages.ProjectPackagesView_createFolderDialog_title,
- ArchivesUIMessages.ProjectPackagesView_createFolderDialog_message, "",
validator);
-
- int response = dialog.open();
- if (response == Dialog.OK) {
- try {
- String[] folderPaths = dialog.getValue().split("[\\\\/]");
- IArchiveNode selected = getSelectedNode();
- IArchiveFolder current = null;
- IArchiveFolder temp = null;
-
- for(int i = folderPaths.length-1; i >= 0 ; i-- ) {
- temp = ArchiveNodeFactory.createFolder();
- temp.setName(folderPaths[i]);
- if( current == null )
- current = temp;
- else {
- temp.addChild(current);
- current = temp;
- }
- }
-
- selected.addChild(current);
- ArchivesModel.instance().save(selected.getProjectPath(), new NullProgressMonitor());
- } catch( ArchivesModelException ame ) {
- IStatus status = new Status(IStatus.ERROR, PackagesUIPlugin.PLUGIN_ID, "Error
Attaching Archives Node", ame);
- PackagesUIPlugin.getDefault().getLog().log(status);
- }
- }
- }
-
- private void createFileset () {
- try {
- IArchiveNode selected = getSelectedNode();
- WizardDialog dialog = new WizardDialog(getSite().getShell(), new FilesetWizard(null,
selected));
-
- dialog.open();
- } catch( Exception e ) {
- e.printStackTrace();
- }
- }
-
- private void editSelectedNode () {
- IArchiveNode node = getSelectedNode();
- if (node != null) {
- if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET) {
- IArchiveFileSet fileset = (IArchiveFileSet) node;
- WizardDialog dialog = new WizardDialog(getSite().getShell(), new
FilesetWizard(fileset, node.getParent()));
- try {
- dialog.open();
- } catch( Exception e ) { e.printStackTrace(); }
- } else if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
- IArchive pkg = (IArchive) node;
- WizardDialog dialog = new WizardDialog(getSite().getShell(), new NewJARWizard(pkg));
- dialog.open();
- } else if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER) {
- // folder can do the model save here.
- IArchiveFolder folder = (IArchiveFolder) node;
- InputDialog dialog = new InputDialog(getSite().getShell(),
- ArchivesUIMessages.ProjectPackagesView_createFolderDialog_title,
- ArchivesUIMessages.ProjectPackagesView_createFolderDialog_message, folder.getName(),
null);
-
- int response = dialog.open();
- if (response == Dialog.OK) {
- folder.setName(dialog.getValue());
- try {
- ArchivesModel.instance().save(folder.getProjectPath(), new NullProgressMonitor());
- } catch( ArchivesModelException ame ) {
- IStatus status = new Status(IStatus.ERROR, PackagesUIPlugin.PLUGIN_ID,
"Problem saving archives model", ame);
- PackagesUIPlugin.getDefault().getLog().log(status);
- }
- }
- }
- }
- }
-
- private void buildSelectedNode(Object selected) {
- if( selected == null ) return;
- if (selected instanceof IArchiveNode &&
- ((IArchiveNode)selected).getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
- new ArchiveBuildDelegate().fullArchiveBuild((IArchive)selected);
- } else if( selected != null && selected instanceof WrappedProject ){
- new
ArchiveBuildDelegate().fullProjectBuild(((WrappedProject)selected).getProject().getLocation());
- } else {
- new
ArchiveBuildDelegate().fullArchiveBuild(((IArchiveNode)selected).getRootArchive());
- }
-
- }
-
- private void deleteSelectedNode () {
- IArchiveNode node = getSelectedNode();
- if (node != null) {
- final IArchiveNode parent = (IArchiveNode) node.getParent();
- parent.removeChild(node);
- new Job("Delete Archives Node") {
- protected IStatus run(IProgressMonitor monitor) {
- if( parent.getProjectPath() != null ) {
- try {
- ArchivesModel.instance().save(parent.getProjectPath(), new
NullProgressMonitor());
- } catch( ArchivesModelException ame ) {
- IStatus status = new Status(IStatus.ERROR, PackagesUIPlugin.PLUGIN_ID,
"Problem saving archives model", ame);
- PackagesUIPlugin.getDefault().getLog().log(status);
- }
- }
- return Status.OK_STATUS;
- }
-
- }.schedule();
- }
- }
-
-
-
- /*
- * Utility methods below
- */
-
- private IViewSite getSite() {
- return (IViewSite) ProjectArchivesView.getInstance().getSite();
- }
-
- private IArchiveNode getSelectedNode () {
- Object selected = getSelectedObject();
- if( selected instanceof IArchiveNode )
- return ((IArchiveNode)selected);
- return null;
- }
- private Object getSelectedObject() {
- IStructuredSelection selection = (IStructuredSelection)
ProjectArchivesView.getInstance().getSelection();
- if (selection != null && !selection.isEmpty())
- return selection.getFirstElement();
- return null;
- }
-
- private ImageDescriptor platformDescriptor(String desc) {
- return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(desc);
- }
-
-}
+package org.jboss.ide.eclipse.archives.ui.views;
+
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
+import org.jboss.ide.eclipse.archives.core.build.SaveArchivesJob;
+import org.jboss.ide.eclipse.archives.core.model.ArchiveNodeFactory;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
+import org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages;
+import org.jboss.ide.eclipse.archives.ui.ExtensionManager;
+import org.jboss.ide.eclipse.archives.ui.NodeContribution;
+import org.jboss.ide.eclipse.archives.ui.PackagesUIPlugin;
+import org.jboss.ide.eclipse.archives.ui.actions.ActionWithDelegate;
+import org.jboss.ide.eclipse.archives.ui.actions.NewArchiveAction;
+import org.jboss.ide.eclipse.archives.ui.actions.NewJARAction;
+import
org.jboss.ide.eclipse.archives.ui.providers.ArchivesContentProvider.WrappedProject;
+import org.jboss.ide.eclipse.archives.ui.wizards.FilesetWizard;
+import org.jboss.ide.eclipse.archives.ui.wizards.NewJARWizard;
+
+/**
+ * Manages the actions associated with the view
+ * @author rstryker
+ *
+ */
+public class ArchivesMenuHandler {
+ public static final String NEW_PACKAGE_MENU_ID =
"org.jboss.ide.eclipse.archives.ui.newPackageMenu";
+ public static final String NODE_CONTEXT_MENU_ID =
"org.jboss.ide.eclipse.archives.ui.nodeContextMenu";
+ public static final String NEW_PACKAGE_ADDITIONS = "newPackageAdditions";
+
+ private MenuManager newPackageManager, contextMenuManager;
+ private NodeContribution[] nodePopupMenuContributions;
+ private NewArchiveAction[] newPackageActions;
+ private Menu treeContextMenu;
+ private TreeViewer packageTree;
+
+ private Action editAction, deleteAction, newFolderAction, newFilesetAction;
+ private NewJARAction newJARAction;
+ private Action buildAction;
+
+ public ArchivesMenuHandler(TreeViewer viewer) {
+ this.packageTree = viewer;
+
+ // load from extensions
+ newPackageActions = ExtensionManager.findNewArchiveActions();
+ nodePopupMenuContributions = ExtensionManager.findNodePopupMenuContributions();
+ Arrays.sort(nodePopupMenuContributions);
+
+
+ createActions();
+ createMenu();
+ createContextMenu();
+ addToActionBars();
+ }
+
+ private void addToActionBars() {
+ IActionBars bars = getSite().getActionBars();
+ bars.getToolBarManager().add(buildAction);
+ }
+
+ /**
+ * Creates the primary menu as well as adds the package actions to it
+ *
+ */
+ private void createMenu () {
+ newPackageManager = new
MenuManager(ArchivesUIMessages.ProjectPackagesView_newPackageMenu_label,
NEW_PACKAGE_MENU_ID);
+ addNewPackageActions(newPackageManager);
+ newPackageManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ private void createContextMenu () {
+ contextMenuManager = new MenuManager(NODE_CONTEXT_MENU_ID); //$NON-NLS-1$
+ contextMenuManager.setRemoveAllWhenShown(true);
+ contextMenuManager.addMenuListener(new IMenuListener () {
+ public void menuAboutToShow(IMenuManager manager) {
+ IStructuredSelection selection = (IStructuredSelection) packageTree.getSelection();
+ if (selection != null && !selection.isEmpty()) {
+ Object element = selection.getFirstElement();
+
+ if (element instanceof WrappedProject) {
+ newJARAction.setEnabled(true);
+ manager.add(newPackageManager);
+ manager.add(buildAction);
+ buildAction.setText(ArchivesUIMessages.ProjectPackagesView_buildProjectAction_label);
+ } else if( element instanceof IArchiveNode ){
+ IArchiveNode node = (IArchiveNode)element;
+
+ if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE
+ || node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER)
+ {
+ newJARAction.setEnabled(true);
+ manager.add(newPackageManager);
+
+ manager.add(newFolderAction);
+ manager.add(newFilesetAction);
+ manager.add(new Separator());
+ }
+
+ if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
+ editAction.setText(ArchivesUIMessages.ProjectPackagesView_editPackageAction_label);
//$NON-NLS-1$
+ deleteAction.setText(ArchivesUIMessages.ProjectPackagesView_deletePackageAction_label);
//$NON-NLS-1$
+ editAction.setImageDescriptor(ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_PACKAGE_EDIT));
+ buildAction.setText(ArchivesUIMessages.ProjectPackagesView_buildArchiveAction_label);
+ manager.add(buildAction);
+ } else if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER) {
+ editAction.setText(ArchivesUIMessages.ProjectPackagesView_editFolderAction_label);
//$NON-NLS-1$
+ deleteAction.setText(ArchivesUIMessages.ProjectPackagesView_deleteFolderAction_label);
//$NON-NLS-1$
+ editAction.setImageDescriptor(platformDescriptor(ISharedImages.IMG_OBJ_FOLDER));
+ } else if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET) {
+ editAction.setText(ArchivesUIMessages.ProjectPackagesView_editFilesetAction_label);
//$NON-NLS-1$
+ deleteAction.setText(ArchivesUIMessages.ProjectPackagesView_deleteFilesetAction_label);
//$NON-NLS-1$
+ editAction.setImageDescriptor(ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_MULTIPLE_FILES));
+ }
+ manager.add(editAction);
+ manager.add(deleteAction);
+ addContextMenuContributions(node);
+ }
+ } else {
+ manager.add(newPackageManager);
+ }
+ }
+ });
+
+ treeContextMenu = contextMenuManager.createContextMenu(packageTree.getTree());
+ packageTree.getTree().setMenu(treeContextMenu);
+
+ getSite().registerContextMenu(NEW_PACKAGE_MENU_ID, newPackageManager, packageTree);
+ }
+
+ protected void createActions() {
+ newJARAction = new NewJARAction();
+ newJARAction.setEnabled(false);
+
+ newFolderAction = new
Action(ArchivesUIMessages.ProjectPackagesView_newFolderAction_label,
platformDescriptor(ISharedImages.IMG_OBJ_FOLDER)) { //$NON-NLS-1$
+ public void run () {
+ createFolder();
+ }
+ };
+
+ newFilesetAction = new
Action(ArchivesUIMessages.ProjectPackagesView_newFilesetAction_label,
ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_MULTIPLE_FILES)) {
//$NON-NLS-1$
+ public void run () {
+ createFileset();
+ }
+ };
+
+ deleteAction = new Action
(ArchivesUIMessages.ProjectPackagesView_deletePackageAction_label,
platformDescriptor(ISharedImages.IMG_TOOL_DELETE)) { //$NON-NLS-1$
+ public void run () {
+ deleteSelectedNode();
+ }
+ };
+
+ editAction = new Action
(ArchivesUIMessages.ProjectPackagesView_editPackageAction_label,
ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_PACKAGE_EDIT)) {
//$NON-NLS-1$
+ public void run () {
+ editSelectedNode();
+ }
+ };
+
+ buildAction = new ActionWithDelegate("",
ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_BUILD_PACKAGES)) {
+ public void run() {
+ buildSelectedNode(getSelectedObject());
+ }
+
+ public IStructuredSelection getSelection() {
+ return ProjectArchivesView.getInstance().getSelection();
+ }
+ };
+ }
+
+ private void addContextMenuContributions (final IArchiveNode context) {
+
+ for( int i = 0; i < nodePopupMenuContributions.length; i++ ) {
+ try {
+
+ final NodeContribution contribution = nodePopupMenuContributions[i];
+ if ( contribution.getActionDelegate().isEnabledFor(context)) {
+ Action action = new Action () {
+ public String getId() {
+ return contribution.getId();
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return contribution.getIcon();
+ }
+
+ public String getText() {
+ return contribution.getLabel();
+ }
+
+ public void run() {
+ contribution.getActionDelegate().run(context);
+ }
+ };
+ contextMenuManager.add(action);
+ }
+ } catch( Exception e) {}
+ }
+
+ }
+
+
+ /**
+ * Adds the new package type actions (which come from an extension point)
+ * to the menu.
+ * @param manager
+ */
+ private void addNewPackageActions (IMenuManager manager) {
+ for( int i = 0; i < newPackageActions.length; i++ ) {
+ final NewArchiveAction action = newPackageActions[i];
+
+ Action actionWrapper = new Action () {
+ public String getId() {
+ return action.getId();
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return action.getIconDescriptor();
+ }
+
+ public String getText() {
+ return action.getLabel();
+ }
+
+ public void run() {
+ action.getAction().run(this);
+ }
+ };
+
+ manager.add(actionWrapper);
+ }
+ }
+
+
+
+
+ /*
+ * Methods below are called from the standard actions,
+ * the implementations of the action, where the action does its work etc
+ */
+
+ private void createFolder ()
+ {
+ IInputValidator validator = new IInputValidator () {
+ public String isValid(String newText) {
+ IArchiveNode selected = getSelectedNode();
+
+ boolean folderExists = false;
+ IArchiveNode[] folders = selected.getChildren(IArchiveNode.TYPE_ARCHIVE_FOLDER);
+ for (int i = 0; i < folders.length; i++) {
+ IArchiveFolder folder = (IArchiveFolder) folders[i];
+ if (folder.getName().equals(newText)) {
+ folderExists = true; break;
+ }
+ }
+
+ if (folderExists) {
+ return ArchivesUIMessages.bind(
+ ArchivesUIMessages.ProjectPackagesView_createFolderDialog_warnFolderExists,
newText);
+
+ }
+ return null;
+ }
+ };
+
+ InputDialog dialog = new InputDialog(getSite().getShell(),
+ ArchivesUIMessages.ProjectPackagesView_createFolderDialog_title,
+ ArchivesUIMessages.ProjectPackagesView_createFolderDialog_message, "",
validator);
+
+ int response = dialog.open();
+ if (response == Dialog.OK) {
+ String[] folderPaths = dialog.getValue().split("[\\\\/]");
+ IArchiveNode selected = getSelectedNode();
+ IArchiveFolder current = null;
+ IArchiveFolder temp = null;
+
+ for(int i = folderPaths.length-1; i >= 0 ; i-- ) {
+ temp = ArchiveNodeFactory.createFolder();
+ temp.setName(folderPaths[i]);
+ if( current == null )
+ current = temp;
+ else {
+ temp.addChild(current);
+ current = temp;
+ }
+ }
+
+ selected.addChild(current);
+ new SaveArchivesJob(selected.getProjectPath()).schedule();
+ }
+ }
+
+ private void createFileset () {
+ IArchiveNode selected = getSelectedNode();
+ WizardDialog dialog = new WizardDialog(getSite().getShell(), new FilesetWizard(null,
selected));
+ dialog.open();
+ }
+
+ private void editSelectedNode () {
+ IArchiveNode node = getSelectedNode();
+ if (node != null) {
+ if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET) {
+ IArchiveFileSet fileset = (IArchiveFileSet) node;
+ WizardDialog dialog = new WizardDialog(getSite().getShell(), new
FilesetWizard(fileset, node.getParent()));
+ dialog.open();
+ } else if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
+ IArchive pkg = (IArchive) node;
+ WizardDialog dialog = new WizardDialog(getSite().getShell(), new NewJARWizard(pkg));
+ dialog.open();
+ } else if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER) {
+ // folder can do the model save here.
+ IArchiveFolder folder = (IArchiveFolder) node;
+ InputDialog dialog = new InputDialog(getSite().getShell(),
+ ArchivesUIMessages.ProjectPackagesView_createFolderDialog_title,
+ ArchivesUIMessages.ProjectPackagesView_createFolderDialog_message,
folder.getName(), null);
+
+ int response = dialog.open();
+ if (response == Dialog.OK) {
+ folder.setName(dialog.getValue());
+ new SaveArchivesJob(folder.getProjectPath()).schedule();
+ }
+ }
+ }
+ }
+
+ private void buildSelectedNode(final Object selected) {
+ new Job("Build Archive Node") {
+ protected IStatus run(IProgressMonitor monitor) {
+ if( selected == null ) return Status.OK_STATUS;
+ if (selected instanceof IArchiveNode &&
+ ((IArchiveNode)selected).getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
+ new ArchiveBuildDelegate().fullArchiveBuild((IArchive)selected);
+ } else if( selected != null && selected instanceof WrappedProject ){
+ new
ArchiveBuildDelegate().fullProjectBuild(((WrappedProject)selected).getProject().getLocation());
+ } else {
+ new
ArchiveBuildDelegate().fullArchiveBuild(((IArchiveNode)selected).getRootArchive());
+ }
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
+
+ private void deleteSelectedNode () {
+ IArchiveNode node = getSelectedNode();
+ if (node != null) {
+ final IArchiveNode parent = (IArchiveNode) node.getParent();
+ parent.removeChild(node);
+ SaveArchivesJob job = new SaveArchivesJob(parent.getProjectPath());
+ job.schedule();
+ }
+ }
+
+ /*
+ * Utility methods below
+ */
+
+ private IViewSite getSite() {
+ return (IViewSite) ProjectArchivesView.getInstance().getSite();
+ }
+
+ private IArchiveNode getSelectedNode () {
+ Object selected = getSelectedObject();
+ if( selected instanceof IArchiveNode )
+ return ((IArchiveNode)selected);
+ return null;
+ }
+ private Object getSelectedObject() {
+ IStructuredSelection selection = (IStructuredSelection)
ProjectArchivesView.getInstance().getSelection();
+ if (selection != null && !selection.isEmpty())
+ return selection.getFirstElement();
+ return null;
+ }
+
+ private ImageDescriptor platformDescriptor(String desc) {
+ return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(desc);
+ }
+
+}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/AbstractArchiveWizard.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/AbstractArchiveWizard.java 2008-06-16
18:19:03 UTC (rev 8801)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/AbstractArchiveWizard.java 2008-06-16
18:29:05 UTC (rev 8802)
@@ -82,7 +82,7 @@
if (performed) {
try {
- getContainer().run(false, false, new IRunnableWithProgress () {
+ getContainer().run(true, false, new IRunnableWithProgress () {
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
IArchiveNode parent = null;
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/FilesetWizard.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/FilesetWizard.java 2008-06-16
18:19:03 UTC (rev 8801)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/FilesetWizard.java 2008-06-16
18:29:05 UTC (rev 8802)
@@ -37,11 +37,11 @@
fillFilesetFromPage(fileset);
try {
- getContainer().run(false, false, new IRunnableWithProgress () {
+ getContainer().run(true, false, new IRunnableWithProgress () {
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
+ if (createFileset)
+ parentNode.addChild(fileset);
try {
- if (createFileset)
- parentNode.addChild(fileset);
ArchivesModel.instance().save(fileset.getProjectPath(), monitor);
} catch( ArchivesModelException ame ) {
IStatus status = new Status(IStatus.ERROR, PackagesUIPlugin.PLUGIN_ID, "Error
Completing Wizard", ame);