Author: rob.stryker(a)jboss.com
Date: 2008-05-15 19:51:54 -0400 (Thu, 15 May 2008)
New Revision: 8133
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/internal/ModelTruezipBridge.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/xml/packages.xsd
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ArchivesMenuHandler.java
Log:
JBIDE-2099 - folders turning zipped bug, with tiny other fixes that made archives unusable
to some extent
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/internal/ModelTruezipBridge.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/internal/ModelTruezipBridge.java 2008-05-15
23:47:02 UTC (rev 8132)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/internal/ModelTruezipBridge.java 2008-05-15
23:51:54 UTC (rev 8133)
@@ -1,254 +1,258 @@
-/**
- * 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.archives.core.util.internal;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.eclipse.core.runtime.IPath;
-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.core.model.IArchiveNodeVisitor;
-import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
-
-import de.schlichtherle.io.ArchiveDetector;
-import de.schlichtherle.io.File;
-
-/**
- * This class is meant to bridge between the model
- * and the raw true-zip utility class. It is a higher level
- * API which deals with filesets and packages instead of
- * raw Strings and paths.
- *
- * It will also make sure that a de.schlichtherle.io.File is
- * created with the proper ArchiveDetector for each and every
- * level, rather than the TrueZipUtil class, which not accurately
- * create the proper File type for exploded archives.
- *
- * @author rstryker
- *
- */
-public class ModelTruezipBridge {
- public static void deleteArchive(IArchive archive) {
- final File file = getFile(archive);
- file.deleteAll();
- TrueZipUtil.sync();
- }
-
- public static void cleanFolder(IArchiveFolder folder) {
- cleanFolder(getFile(folder), true);
- }
-
- public static void cleanFolder(java.io.File folder, boolean sync) {
- TrueZipUtil.deleteEmptyChildren(folder);
- if( sync )
- TrueZipUtil.sync();
- }
-
- public static void fullFilesetBuild(IArchiveFileSet fileset) {
- fullFilesetBuild(fileset, true);
- }
- public static void fullFilesetBuild(final IArchiveFileSet fileset, boolean sync) {
- IPath[] paths = fileset.findMatchingPaths();
- copyFiles(fileset, paths, false);
- if( sync )
- TrueZipUtil.sync();
- }
-
- public static void fullFilesetsRemove(IArchiveFileSet[] filesets, boolean sync) {
- for( int i = 0; i < filesets.length; i++ )
- fullFilesetRemove(filesets[i], false);
- if( sync )
- TrueZipUtil.sync();
- }
-
-
- // Let them know which files were removed, for events
- public static IPath[] fullFilesetRemove(final IArchiveFileSet fileset, boolean sync) {
- IPath[] paths = fileset.findMatchingPaths();
- final ArrayList<IPath> list = new ArrayList<IPath>();
- list.addAll(Arrays.asList(paths));
- for( int i = 0; i < paths.length; i++ ) {
- if( !ModelUtil.otherFilesetMatchesPathAndOutputLocation(fileset, paths[i])) {
- // remove
- deleteFiles(fileset, new IPath[] {paths[i]}, false);
- } else {
- list.remove(paths[i]);
- }
- }
-
- // kinda ugly here. delete all empty folders beneath
- cleanFolder(getFile(fileset), false);
-
- // now ensure all mandatory child folders are still there
- fileset.getParent().accept(new IArchiveNodeVisitor() {
- public boolean visit(IArchiveNode node) {
- if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
- createFile(node);
- } else if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER) {
- createFile(node);
- }
- return true;
- }
- } );
-
- if( sync )
- TrueZipUtil.sync();
-
- return list.toArray(new IPath[list.size()]);
- }
-
-
- public static void copyFiles(IArchiveFileSet[] filesets, IPath[] paths) {
- copyFiles(filesets, paths, true);
- }
-
- public static void copyFiles(final IArchiveFileSet[] filesets, final IPath[] paths,
boolean sync) {
- for( int i = 0; i < filesets.length; i++ ) {
- copyFiles(filesets[i], paths, false);
- }
- if( sync )
- TrueZipUtil.sync();
-
- }
-
- public static void copyFiles(IArchiveFileSet fileset, final IPath[] paths) {
- copyFiles(fileset, paths, true);
- }
- public static void copyFiles(IArchiveFileSet fileset, final IPath[] sourcePaths, boolean
sync) {
- final File[] destFiles = getFiles(sourcePaths, fileset);
- for( int i = 0; i < sourcePaths.length; i++ ) {
- TrueZipUtil.copyFile(sourcePaths[i].toOSString(), destFiles[i]);
- }
- if( sync )
- TrueZipUtil.sync();
- }
-
-
- /*
- * Deleting files
- */
- public static void deleteFiles(IArchiveFileSet[] filesets, IPath[] paths ) {
- deleteFiles(filesets, paths, true);
- }
- public static void deleteFiles(final IArchiveFileSet[] filesets, final IPath[] paths,
boolean sync ) {
- for( int i = 0; i < filesets.length; i++ ) {
- deleteFiles(filesets[i], paths, false);
- }
- if( sync )
- TrueZipUtil.sync();
- }
-
- public static void deleteFiles(IArchiveFileSet fileset, final IPath[] paths ) {
- deleteFiles(fileset, paths, true);
- }
- public static void deleteFiles(IArchiveFileSet fileset, final IPath[] paths, boolean
sync ) {
- final File[] destFiles = getFiles(paths, fileset);
- for( int i = 0; i < paths.length; i++ ) {
- TrueZipUtil.deleteAll(destFiles[i]);
- }
-
- if( sync )
- TrueZipUtil.sync();
- }
-
-
- /**
- * Creates the file, folder, or archive represented by the node.
- * Does nothing for filesets
- * @param node
- */
- public static void createFile(final IArchiveNode node) {
- createFile(node, true);
- }
- public static void createFile(final IArchiveNode node, boolean sync) {
- File f = getFile(node);
- if( f != null ) {
- f.mkdirs();
- }
- if( sync )
- TrueZipUtil.sync();
- }
-
-
-
- /**
- * Gets all properly-created de.sch destination files for a fileset
- * @param inputFiles
- * @param fs
- * @return
- */
- private static File[] getFiles(IPath[] inputFiles, IArchiveFileSet fs ) {
- String filesetRelative;
- File fsFile = getFile(fs);
- File[] returnFiles = new File[inputFiles.length];
- int fsLength = fs.getGlobalSourcePath().toOSString().length()+1;
- for( int i = 0; i < inputFiles.length; i++ ) {
- if( fs.isFlattened() )
- filesetRelative = inputFiles[i].lastSegment();
- else
- filesetRelative = inputFiles[i].toOSString().substring(fsLength);
- returnFiles[i] = new File(fsFile, filesetRelative, ArchiveDetector.DEFAULT);
- }
- return returnFiles;
- }
-
-
- /**
- * This should go through the tree and create a file that is
- * correctly perceived at each step of the way.
- *
- * To just create a new File would let the Archive Detector have too
- * much control, and *ALL* war's and jars, including exploded ones,
- * would be treated as archives instead of folders.
- * @param node
- * @return
- */
- private static File getFile(IArchiveNode node) {
- if( node == null ) return null;
-
- if( node.getNodeType() == IArchiveNode.TYPE_MODEL_ROOT ) return null;
-
- if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET)
- return getFile(node.getParent());
-
- File parentFile = getFile(node.getParent());
- if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE ) {
- IArchive node2 = ((IArchive)node);
- boolean exploded = ((IArchive)node).isExploded();
- ArchiveDetector detector = exploded ? ArchiveDetector.NULL :
TrueZipUtil.getJarArchiveDetector();
- if( parentFile == null ) {
- IPath p = node2.getGlobalDestinationPath();
- if( p == null ) return null;
- return new File(p.append(node2.getName()).toOSString(), detector);
- }
- return new File(parentFile, node2.getName(), detector);
- }
- if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER ) {
- return new File(parentFile, ((IArchiveFolder)node).getName(), ArchiveDetector.NULL);
- }
- return null;
- }
-
-}
+/**
+ * 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.archives.core.util.internal;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+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.core.model.IArchiveNodeVisitor;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+
+import de.schlichtherle.io.ArchiveDetector;
+import de.schlichtherle.io.File;
+
+/**
+ * This class is meant to bridge between the model
+ * and the raw true-zip utility class. It is a higher level
+ * API which deals with filesets and packages instead of
+ * raw Strings and paths.
+ *
+ * It will also make sure that a de.schlichtherle.io.File is
+ * created with the proper ArchiveDetector for each and every
+ * level, rather than the TrueZipUtil class, which not accurately
+ * create the proper File type for exploded archives.
+ *
+ * @author rstryker
+ *
+ */
+public class ModelTruezipBridge {
+ public static void deleteArchive(IArchive archive) {
+ final File file = getFile(archive);
+ file.deleteAll();
+ TrueZipUtil.sync();
+ }
+
+ public static void cleanFolder(IArchiveFolder folder) {
+ cleanFolder(getFile(folder), true);
+ }
+
+ public static void cleanFolder(java.io.File folder, boolean sync) {
+ TrueZipUtil.deleteEmptyChildren(folder);
+ if( sync )
+ TrueZipUtil.sync();
+ }
+
+ public static void fullFilesetBuild(IArchiveFileSet fileset) {
+ fullFilesetBuild(fileset, true);
+ }
+ public static void fullFilesetBuild(final IArchiveFileSet fileset, boolean sync) {
+ IPath[] paths = fileset.findMatchingPaths();
+ copyFiles(fileset, paths, false);
+ if( sync )
+ TrueZipUtil.sync();
+ }
+
+ public static void fullFilesetsRemove(IArchiveFileSet[] filesets, boolean sync) {
+ for( int i = 0; i < filesets.length; i++ )
+ fullFilesetRemove(filesets[i], false);
+ if( sync )
+ TrueZipUtil.sync();
+ }
+
+
+ // Let them know which files were removed, for events
+ public static IPath[] fullFilesetRemove(final IArchiveFileSet fileset, boolean sync) {
+ IPath[] paths = fileset.findMatchingPaths();
+ final ArrayList<IPath> list = new ArrayList<IPath>();
+ list.addAll(Arrays.asList(paths));
+ for( int i = 0; i < paths.length; i++ ) {
+ if( !ModelUtil.otherFilesetMatchesPathAndOutputLocation(fileset, paths[i])) {
+ // remove
+ deleteFiles(fileset, new IPath[] {paths[i]}, false);
+ } else {
+ list.remove(paths[i]);
+ }
+ }
+
+ // kinda ugly here. delete all empty folders beneath
+ cleanFolder(getFile(fileset), false);
+
+ // now ensure all mandatory child folders are still there
+ fileset.getParent().accept(new IArchiveNodeVisitor() {
+ public boolean visit(IArchiveNode node) {
+ if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
+ createFile(node);
+ } else if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER) {
+ createFile(node);
+ }
+ return true;
+ }
+ } );
+
+ if( sync )
+ TrueZipUtil.sync();
+
+ return list.toArray(new IPath[list.size()]);
+ }
+
+
+ public static void copyFiles(IArchiveFileSet[] filesets, IPath[] paths) {
+ copyFiles(filesets, paths, true);
+ }
+
+ public static void copyFiles(final IArchiveFileSet[] filesets, final IPath[] paths,
boolean sync) {
+ for( int i = 0; i < filesets.length; i++ ) {
+ copyFiles(filesets[i], paths, false);
+ }
+ if( sync )
+ TrueZipUtil.sync();
+
+ }
+
+ public static void copyFiles(IArchiveFileSet fileset, final IPath[] paths) {
+ copyFiles(fileset, paths, true);
+ }
+ public static void copyFiles(IArchiveFileSet fileset, final IPath[] sourcePaths, boolean
sync) {
+ final File[] destFiles = getFiles(sourcePaths, fileset);
+ for( int i = 0; i < sourcePaths.length; i++ ) {
+ TrueZipUtil.copyFile(sourcePaths[i].toOSString(), destFiles[i]);
+ }
+ if( sync )
+ TrueZipUtil.sync();
+ }
+
+
+ /*
+ * Deleting files
+ */
+ public static void deleteFiles(IArchiveFileSet[] filesets, IPath[] paths ) {
+ deleteFiles(filesets, paths, true);
+ }
+ public static void deleteFiles(final IArchiveFileSet[] filesets, final IPath[] paths,
boolean sync ) {
+ for( int i = 0; i < filesets.length; i++ ) {
+ deleteFiles(filesets[i], paths, false);
+ }
+ if( sync )
+ TrueZipUtil.sync();
+ }
+
+ public static void deleteFiles(IArchiveFileSet fileset, final IPath[] paths ) {
+ deleteFiles(fileset, paths, true);
+ }
+ public static void deleteFiles(IArchiveFileSet fileset, final IPath[] paths, boolean
sync ) {
+ final File[] destFiles = getFiles(paths, fileset);
+ for( int i = 0; i < paths.length; i++ ) {
+ TrueZipUtil.deleteAll(destFiles[i]);
+ }
+
+ if( sync )
+ TrueZipUtil.sync();
+ }
+
+
+ /**
+ * Creates the file, folder, or archive represented by the node.
+ * Does nothing for filesets
+ * @param node
+ */
+ public static void createFile(final IArchiveNode node) {
+ createFile(node, true);
+ }
+ public static void createFile(final IArchiveNode node, boolean sync) {
+ File f = getFile(node);
+ if( f != null ) {
+ f.mkdirs();
+ }
+ if( sync )
+ TrueZipUtil.sync();
+ }
+
+
+
+ /**
+ * Gets all properly-created de.sch destination files for a fileset
+ * @param inputFiles
+ * @param fs
+ * @return
+ */
+ private static File[] getFiles(IPath[] inputFiles, IArchiveFileSet fs ) {
+ String filesetRelative;
+ File fsFile = getFile(fs);
+ File[] returnFiles = new File[inputFiles.length];
+ int fsLength = fs.getGlobalSourcePath().toOSString().length()+1;
+ for( int i = 0; i < inputFiles.length; i++ ) {
+ if( fs.isFlattened() )
+ filesetRelative = inputFiles[i].lastSegment();
+ else
+ filesetRelative = inputFiles[i].toOSString().substring(fsLength);
+
+ String tmp = new Path(filesetRelative).removeLastSegments(1).toString();
+ File parentFile = new File(fsFile, tmp, ArchiveDetector.NULL);
+ returnFiles[i] = new File(parentFile, new Path(filesetRelative).lastSegment(),
ArchiveDetector.DEFAULT);
+ }
+ return returnFiles;
+ }
+
+
+ /**
+ * This should go through the tree and create a file that is
+ * correctly perceived at each step of the way.
+ *
+ * To just create a new File would let the Archive Detector have too
+ * much control, and *ALL* war's and jars, including exploded ones,
+ * would be treated as archives instead of folders.
+ * @param node
+ * @return
+ */
+ private static File getFile(IArchiveNode node) {
+ if( node == null ) return null;
+
+ if( node.getNodeType() == IArchiveNode.TYPE_MODEL_ROOT ) return null;
+
+ if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET)
+ return getFile(node.getParent());
+
+ File parentFile = getFile(node.getParent());
+ if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE ) {
+ IArchive node2 = ((IArchive)node);
+ boolean exploded = ((IArchive)node).isExploded();
+ ArchiveDetector detector = exploded ? ArchiveDetector.NULL :
TrueZipUtil.getJarArchiveDetector();
+ if( parentFile == null ) {
+ IPath p = node2.getGlobalDestinationPath();
+ if( p == null ) return null;
+ return new File(p.append(node2.getName()).toOSString(), detector);
+ }
+ return new File(parentFile, node2.getName(), detector);
+ }
+ if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER ) {
+ return new File(parentFile, ((IArchiveFolder)node).getName(), ArchiveDetector.NULL);
+ }
+ return null;
+ }
+
+}
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/xml/packages.xsd
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/xml/packages.xsd 2008-05-15
23:47:02 UTC (rev 8132)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/xml/packages.xsd 2008-05-15
23:51:54 UTC (rev 8133)
@@ -1,110 +1,110 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- JBoss, Home of Professional Open Source
- Copyright 2006, JBoss Inc., 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.
- -->
-<xsd:schema
xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-
- <xsd:element name="packages" type="packages-type"/>
-
- <xsd:complexType name="packages-type">
- <xsd:annotation>
- <xsd:appinfo>
- <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages"/>
- </xsd:appinfo>
- </xsd:annotation>
-
- <xsd:sequence>
- <xsd:element maxOccurs="unbounded" minOccurs="0"
name="package" type="package-type"/>
- <xsd:element maxOccurs="1" minOccurs="0"
name="properties" type="properties-type"/>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:complexType name="package-type">
- <xsd:annotation>
- <xsd:appinfo>
- <jbxb:class
- impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage"
/>
- <jbxb:addMethod name="addChild" />
- </xsd:appinfo>
- </xsd:annotation>
-
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ JBoss, Home of Professional Open Source
+ Copyright 2006, JBoss Inc., 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.
+ -->
+<xsd:schema
xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:element name="packages" type="packages-type"/>
+
+ <xsd:complexType name="packages-type">
+ <xsd:annotation>
+ <xsd:appinfo>
+ <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages"/>
+ </xsd:appinfo>
+ </xsd:annotation>
+
+ <xsd:sequence>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="package" type="package-type"/>
+ <xsd:element maxOccurs="1" minOccurs="0"
name="properties" type="properties-type"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="package-type">
+ <xsd:annotation>
+ <xsd:appinfo>
+ <jbxb:class
+ impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage"
/>
+ <jbxb:addMethod name="addChild" />
+ </xsd:appinfo>
+ </xsd:annotation>
+
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
- name="buildAction" type="build-action-type" />
- <xsd:element maxOccurs="unbounded" minOccurs="0"
- name="package" type="package-type" />
- <xsd:element maxOccurs="unbounded" minOccurs="0"
- name="fileset" type="fileset-type" />
- <xsd:element maxOccurs="unbounded" minOccurs="0"
- name="folder" type="folder-type" />
- <xsd:element maxOccurs="1" minOccurs="0"
name="properties"
- type="properties-type" />
- </xsd:sequence>
-
- <xsd:attribute name="name" type="xsd:string"
use="required" />
- <xsd:attribute name="type" type="xsd:string"
use="optional" >
- <xsd:annotation>
- <xsd:appinfo>
- <jbxb:property name="packageType" />
- </xsd:appinfo>
- </xsd:annotation>
- </xsd:attribute>
- <xsd:attribute name="todir" type="xsd:string"
use="required">
- <xsd:annotation>
- <xsd:appinfo>
- <jbxb:property name="toDir" />
- </xsd:appinfo>
- </xsd:annotation>
- </xsd:attribute>
- <xsd:attribute name="exploded" type="xsd:boolean"
use="optional" default="false"/>
- <xsd:attribute name="inWorkspace" type="xsd:boolean"
use="optional" default="true"/>
- <xsd:attribute name="id" type="xsd:string"
use="optional" />
- </xsd:complexType>
-
- <xsd:complexType name="properties-type">
- <xsd:annotation>
- <xsd:appinfo>
- <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbProperties"/>
- <jbxb:addMethod name="setProperties"/>
- </xsd:appinfo>
- </xsd:annotation>
-
- <xsd:sequence>
- <xsd:element maxOccurs="unbounded" minOccurs="0"
name="property" type="property-type"/>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:complexType name="property-type">
- <xsd:annotation>
- <xsd:appinfo>
- <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbProperty"/>
- <jbxb:addMethod name="addProperty"/>
- </xsd:appinfo>
- </xsd:annotation>
-
- <xsd:attribute name="name" type="xsd:string"
use="required"/>
- <xsd:attribute name="value" type="xsd:string"
use="required"/>
- </xsd:complexType>
+ name="buildAction" type="build-action-type" />
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
+ name="package" type="package-type" />
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
+ name="fileset" type="fileset-type" />
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
+ name="folder" type="folder-type" />
+ <xsd:element maxOccurs="1" minOccurs="0"
name="properties"
+ type="properties-type" />
+ </xsd:sequence>
+
+ <xsd:attribute name="name" type="xsd:string"
use="required" />
+ <xsd:attribute name="type" type="xsd:string"
use="optional" >
+ <xsd:annotation>
+ <xsd:appinfo>
+ <jbxb:property name="packageType" />
+ </xsd:appinfo>
+ </xsd:annotation>
+ </xsd:attribute>
+ <xsd:attribute name="todir" type="xsd:string"
use="optional">
+ <xsd:annotation>
+ <xsd:appinfo>
+ <jbxb:property name="toDir" />
+ </xsd:appinfo>
+ </xsd:annotation>
+ </xsd:attribute>
+ <xsd:attribute name="exploded" type="xsd:boolean"
use="optional" default="false"/>
+ <xsd:attribute name="inWorkspace" type="xsd:boolean"
use="optional" default="true"/>
+ <xsd:attribute name="id" type="xsd:string"
use="optional" />
+ </xsd:complexType>
+
+ <xsd:complexType name="properties-type">
+ <xsd:annotation>
+ <xsd:appinfo>
+ <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbProperties"/>
+ <jbxb:addMethod name="setProperties"/>
+ </xsd:appinfo>
+ </xsd:annotation>
+
+ <xsd:sequence>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="property" type="property-type"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:complexType name="property-type">
+ <xsd:annotation>
+ <xsd:appinfo>
+ <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbProperty"/>
+ <jbxb:addMethod name="addProperty"/>
+ </xsd:appinfo>
+ </xsd:annotation>
+
+ <xsd:attribute name="name" type="xsd:string"
use="required"/>
+ <xsd:attribute name="value" type="xsd:string"
use="required"/>
+ </xsd:complexType>
+
<xsd:complexType name="build-action-type">
<xsd:annotation>
<xsd:appinfo>
@@ -124,42 +124,42 @@
<xsd:attribute name="type" type="xsd:string"
use="required"/>
</xsd:complexType>
-
- <xsd:complexType name="folder-type">
- <xsd:annotation>
- <xsd:appinfo>
- <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFolder"/>
- <jbxb:addMethod name="addChild"/>
- </xsd:appinfo>
- </xsd:annotation>
-
- <xsd:sequence>
- <xsd:element maxOccurs="unbounded" minOccurs="0"
name="package" type="package-type"/>
- <xsd:element maxOccurs="unbounded" minOccurs="0"
name="fileset" type="fileset-type"/>
- <xsd:element maxOccurs="unbounded" minOccurs="0"
name="folder" type="folder-type"/>
- <xsd:element maxOccurs="1" minOccurs="0"
name="properties" type="properties-type"/>
- </xsd:sequence>
-
- <xsd:attribute name="name" type="xsd:string"
use="required"/>
- </xsd:complexType>
-
- <xsd:complexType name="fileset-type">
- <xsd:annotation>
- <xsd:appinfo>
- <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet"/>
- <jbxb:addMethod name="addChild"/>
- </xsd:appinfo>
- </xsd:annotation>
-
- <xsd:sequence>
- <xsd:element maxOccurs="1" minOccurs="0"
name="properties" type="properties-type"/>
- </xsd:sequence>
-
- <xsd:attribute name="dir" type="xsd:string"
use="required"/>
- <xsd:attribute name="includes" type="xsd:string"
use="required"/>
- <xsd:attribute name="excludes" type="xsd:string"
use="optional"/>
+
+ <xsd:complexType name="folder-type">
+ <xsd:annotation>
+ <xsd:appinfo>
+ <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFolder"/>
+ <jbxb:addMethod name="addChild"/>
+ </xsd:appinfo>
+ </xsd:annotation>
+
+ <xsd:sequence>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="package" type="package-type"/>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="fileset" type="fileset-type"/>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="folder" type="folder-type"/>
+ <xsd:element maxOccurs="1" minOccurs="0"
name="properties" type="properties-type"/>
+ </xsd:sequence>
+
+ <xsd:attribute name="name" type="xsd:string"
use="required"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="fileset-type">
+ <xsd:annotation>
+ <xsd:appinfo>
+ <jbxb:class
impl="org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet"/>
+ <jbxb:addMethod name="addChild"/>
+ </xsd:appinfo>
+ </xsd:annotation>
+
+ <xsd:sequence>
+ <xsd:element maxOccurs="1" minOccurs="0"
name="properties" type="properties-type"/>
+ </xsd:sequence>
+
+ <xsd:attribute name="dir" type="xsd:string"
use="required"/>
+ <xsd:attribute name="includes" type="xsd:string"
use="required"/>
+ <xsd:attribute name="excludes" type="xsd:string"
use="optional"/>
<xsd:attribute name="inWorkspace" type="xsd:boolean"
use="optional" default="true"/>
<xsd:attribute name="flatten" type="xsd:boolean"
use="optional" default="false"/>
- </xsd:complexType>
-
-</xsd:schema>
+ </xsd:complexType>
+
+</xsd:schema>
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-05-15
23:47:02 UTC (rev 8132)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ArchivesMenuHandler.java 2008-05-15
23:51:54 UTC (rev 8133)
@@ -1,433 +1,445 @@
-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.core.model.internal.xb.XMLBinding.XbException;
-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() {
- 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.
- } 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) {
- IArchiveNode parent = (IArchiveNode) node.getParent();
- parent.removeChild(node);
- 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);
- }
-
- }
- }
- }
-
-
-
- /*
- * 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.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.core.model.internal.xb.XMLBinding.XbException;
+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) {
+ IArchiveNode parent = (IArchiveNode) node.getParent();
+ parent.removeChild(node);
+ 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);
+ }
+
+ }
+ }
+ }
+
+
+
+ /*
+ * 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);
+ }
+
+}