Author: rob.stryker(a)jboss.com
Date: 2008-06-12 18:23:39 -0400 (Thu, 12 Jun 2008)
New Revision: 8747
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/WorkspaceChangeListener.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ModelChangeListener.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/ArchivesModelCore.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/DirectoryScannerFactory.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNode.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFileSetImpl.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveImpl.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/internal/ModelTruezipBridge.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/util/composites/ArchiveNodeDestinationComposite.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ProjectArchivesView.java
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/pages/ArchiveInfoWizardPage.java
Log:
JBIDE-2324 on 2.1.x branch
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/WorkspaceChangeListener.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/WorkspaceChangeListener.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/WorkspaceChangeListener.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,98 +1,107 @@
-/*
- * 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;
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-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.IArchiveModel;
-import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
-
-/**
- * Update the model if someone changes the packaging file by hand
- * @author Rob Stryker <rob.stryker(a)redhat.com>
- *
- */
-public class WorkspaceChangeListener implements IResourceChangeListener {
-
- public void resourceChanged(IResourceChangeEvent event) {
- final Set<IProject> projects = new TreeSet<IProject>();
-
- IResourceDelta delta = event.getDelta();
- try {
- if(delta!=null) {
- delta.accept(new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta) throws CoreException {
- if( delta.getResource() != null && delta.getResource().getLocation() !=
null &&
- delta.getResource().getLocation().lastSegment().equals(IArchiveModel.DEFAULT_PACKAGES_FILE))
{
- projects.add(delta.getResource().getProject());
- }
- return true;
- }
- });
- }
- } catch( CoreException ce ) {
- }
- Iterator<IProject> i = projects.iterator();
- while(i.hasNext()) {
- final IProject p = i.next();
- try {
- if( p.getSessionProperty(new QualifiedName(ArchivesCorePlugin.PLUGIN_ID,
"localname")) == null ) {
- try {
- ArchivesModel.instance().registerProject(p.getLocation(), new
NullProgressMonitor());
- new Job("Refresh Project: " + p.getName()) {
- protected IStatus run(IProgressMonitor monitor) {
- try {
- p.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
- } catch( CoreException e ) {
- IStatus status = new Status(IStatus.WARNING, ArchivesCorePlugin.PLUGIN_ID,
"Could not refresh project " + p.getName(), e);
- return status;
- }
- return Status.OK_STATUS;
- }
- }.schedule();
- } catch( ArchivesModelException ame ) {
- ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_ERR, "Could not
register project " + p.getName(), ame);
- }
- }
- } catch( CoreException ce ) {
- }
- }
- }
-
-}
+/*
+ * 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;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+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.IArchiveModel;
+import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
+
+/**
+ * Update the model if someone changes the packaging file by hand
+ * @author Rob Stryker <rob.stryker(a)redhat.com>
+ *
+ */
+public class WorkspaceChangeListener implements IResourceChangeListener {
+
+ public void resourceChanged(IResourceChangeEvent event) {
+ Comparator c = new Comparator() {
+ public int compare(Object o1, Object o2) {
+ if( o1 instanceof IProject && o2 instanceof IProject)
+ return ((IProject)o1).getLocation().toOSString().compareTo(
+ ((IProject)o2).getLocation().toOSString());
+ return 0;
+ }
+ };
+ final Set<IProject> projects = new TreeSet<IProject>(c);
+
+ IResourceDelta delta = event.getDelta();
+ try {
+ if(delta!=null) {
+ delta.accept(new IResourceDeltaVisitor() {
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ if( delta.getResource() != null && delta.getResource().getLocation() !=
null &&
+ delta.getResource().getLocation().lastSegment().equals(IArchiveModel.DEFAULT_PACKAGES_FILE))
{
+ projects.add(delta.getResource().getProject());
+ }
+ return true;
+ }
+ });
+ }
+ } catch( CoreException ce ) {
+ }
+ Iterator<IProject> i = projects.iterator();
+ while(i.hasNext()) {
+ final IProject p = i.next();
+ try {
+ if( p.getSessionProperty(new QualifiedName(ArchivesCorePlugin.PLUGIN_ID,
"localname")) == null ) {
+ try {
+ ArchivesModel.instance().registerProject(p.getLocation(), new
NullProgressMonitor());
+ new Job("Refresh Project: " + p.getName()) {
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ p.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ } catch( CoreException e ) {
+ IStatus status = new Status(IStatus.WARNING, ArchivesCorePlugin.PLUGIN_ID,
"Could not refresh project " + p.getName(), e);
+ return status;
+ }
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ } catch( ArchivesModelException ame ) {
+ ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_ERR, "Could not
register project " + p.getName(), ame);
+ }
+ }
+ } catch( CoreException ce ) {
+ }
+ }
+ }
+
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,182 +1,184 @@
-/*
- * 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.build;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IPath;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
-import org.jboss.ide.eclipse.archives.core.model.EventManager;
-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.IArchiveModelRootNode;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
-import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
-import org.jboss.ide.eclipse.archives.core.util.internal.ModelTruezipBridge;
-import org.jboss.ide.eclipse.archives.core.util.internal.TrueZipUtil;
-
-/**
- * This delegate will either build from the model completely
- * (if the builder has been given a full build request) or
- * incrementally update the changed files in
- * **ANY AND ALL** filesets that they match, regardless of project.
- *
- * @author Rob Stryker (rob.stryker(a)redhat.com)
- *
- */
-public class ArchiveBuildDelegate {
-
- public ArchiveBuildDelegate() {
- }
-
-
- /**
- * A full project build has been requested.
- * @param project The project containing the archive model
- */
- public void fullProjectBuild(IPath project) {
- EventManager.cleanProjectBuild(project);
- EventManager.startedBuild(project);
-
- IArchiveModelRootNode root = ArchivesModel.instance().getRoot(project);
- if( root == null ) return;
- IArchiveNode[] nodes = root.getChildren(IArchiveNode.TYPE_ARCHIVE);
- for( int i = 0; i < nodes.length; i++ ) {
- fullArchiveBuild(((IArchive)nodes[i]));
- }
-
- EventManager.finishedBuild(project);
- }
-
- /**
- * Builds an archive entirely, overwriting whatever was in the output destination.
- * @param pkg The archive to build
- */
- public void fullArchiveBuild(IArchive pkg) {
- EventManager.cleanArchiveBuild(pkg);
- EventManager.startedBuildingArchive(pkg);
-
- ModelTruezipBridge.deleteArchive(pkg);
- if( !pkg.getGlobalDestinationPath().toFile().exists() ) {
- pkg.getGlobalDestinationPath().toFile().mkdirs();
- }
- ModelTruezipBridge.createFile(pkg);
-
- // force create all folders
- IArchiveFolder[] folders = ModelUtil.findAllDescendentFolders(pkg);
- for( int i = 0; i < folders.length; i++ ) {
- ModelTruezipBridge.createFile(folders[i]);
- }
-
- // build the filesets
- IArchiveFileSet[] filesets = ModelUtil.findAllDescendentFilesets(pkg);
- for( int i = 0; i < filesets.length; i++ ) {
- fullFilesetBuild(filesets[i], pkg);
- }
-
- EventManager.finishedBuildingArchive(pkg);
- }
-
- /**
- * Build the given fileset
- * @param fileset The fileset to match
- * @param topLevel The top level archive that the fileset belongs to
- */
- protected void fullFilesetBuild(IArchiveFileSet fileset, IArchive topLevel) {
- EventManager.startedCollectingFileSet(fileset);
-
- // reset the scanner. It *is* a full build afterall
- fileset.resetScanner();
- IPath[] paths = fileset.findMatchingPaths();
- ModelTruezipBridge.fullFilesetBuild(fileset);
-
- EventManager.filesUpdated(topLevel, fileset, paths);
- EventManager.finishedCollectingFileSet(fileset);
- }
-
-
-
-
- /**
- * Incremental Build!!
- * Parameters are instances of changed IPath objects.
- * Will search the entire model for matching filesets.
- *
- * @param addedChanged Set of changed / added resources
- * @param setRemoved Set of removed resources
- */
- public void projectIncrementalBuild(Set<IPath> addedChanged, Set<IPath>
removed) {
- incrementalBuild(null, addedChanged, removed);
- }
-
- /**
- * Incremental build.
- * Parameters are instance sof changed IPath objects
- * Will search only the given node for matching descendent filesets
- * @param archive An archive to limit the scope to, or null if the entire default
model
- * @param addedChanged A list of added or changed resource paths
- * @param removed A list of removed resource paths
- */
- public void incrementalBuild(IArchive archive, Set<IPath> addedChanged,
Set<IPath> removed) {
-
- // find any and all filesets that match each file
- Iterator<IPath> i = addedChanged.iterator();
- IPath path;
- IArchiveFileSet[] matchingFilesets;
- ArrayList<IArchive> topPackagesChanged = new ArrayList<IArchive>();
- while(i.hasNext()) {
- path = i.next();
- matchingFilesets = ModelUtil.getMatchingFilesets(archive, path);
- localFireAffectedTopLevelPackages(topPackagesChanged, matchingFilesets);
- ModelTruezipBridge.copyFiles(matchingFilesets, new IPath[] { path }, false);
- EventManager.fileUpdated(path, matchingFilesets);
- }
-
- i = removed.iterator();
- while(i.hasNext()) {
- path = ((IPath)i.next());
- matchingFilesets = ModelUtil.getMatchingFilesets(archive, path);
- localFireAffectedTopLevelPackages(topPackagesChanged, matchingFilesets);
- ModelTruezipBridge.deleteFiles(matchingFilesets, new IPath[] { path }, false);
- EventManager.fileRemoved(path, matchingFilesets);
- }
-
- TrueZipUtil.sync();
-
- Iterator<IArchive> i2 = topPackagesChanged.iterator();
- while(i2.hasNext()) {
- EventManager.finishedBuildingArchive(i2.next());
- }
- }
-
- private void localFireAffectedTopLevelPackages(ArrayList<IArchive> affected,
IArchiveFileSet[] filesets) {
- for( int i = 0; i < filesets.length; i++ ) {
- if( !affected.contains(filesets[i].getRootArchive())) {
- affected.add(filesets[i].getRootArchive());
- EventManager.startedBuildingArchive(filesets[i].getRootArchive());
- }
- }
- }
-}
+/*
+ * 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.build;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.EventManager;
+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.IArchiveModelRootNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+import org.jboss.ide.eclipse.archives.core.util.internal.ModelTruezipBridge;
+import org.jboss.ide.eclipse.archives.core.util.internal.TrueZipUtil;
+
+/**
+ * This delegate will either build from the model completely
+ * (if the builder has been given a full build request) or
+ * incrementally update the changed files in
+ * **ANY AND ALL** filesets that they match, regardless of project.
+ *
+ * @author Rob Stryker (rob.stryker(a)redhat.com)
+ *
+ */
+public class ArchiveBuildDelegate {
+
+ public ArchiveBuildDelegate() {
+ }
+
+
+ /**
+ * A full project build has been requested.
+ * @param project The project containing the archive model
+ */
+ public void fullProjectBuild(IPath project) {
+ EventManager.cleanProjectBuild(project);
+ EventManager.startedBuild(project);
+
+ IArchiveModelRootNode root = ArchivesModel.instance().getRoot(project);
+ if( root == null ) return;
+ IArchiveNode[] nodes = root.getChildren(IArchiveNode.TYPE_ARCHIVE);
+ for( int i = 0; i < nodes.length; i++ ) {
+ fullArchiveBuild(((IArchive)nodes[i]));
+ }
+
+ EventManager.finishedBuild(project);
+ }
+
+ /**
+ * Builds an archive entirely, overwriting whatever was in the output destination.
+ * @param pkg The archive to build
+ */
+ public void fullArchiveBuild(IArchive pkg) {
+ EventManager.cleanArchiveBuild(pkg);
+ EventManager.startedBuildingArchive(pkg);
+
+ ModelTruezipBridge.deleteArchive(pkg);
+ if( !pkg.getGlobalDestinationPath().toFile().exists() ) {
+ pkg.getGlobalDestinationPath().toFile().mkdirs();
+ }
+ ModelTruezipBridge.createFile(pkg);
+
+ // force create all folders
+ IArchiveFolder[] folders = ModelUtil.findAllDescendentFolders(pkg);
+ for( int i = 0; i < folders.length; i++ ) {
+ ModelTruezipBridge.createFile(folders[i]);
+ }
+
+ // build the filesets
+ IArchiveFileSet[] filesets = ModelUtil.findAllDescendentFilesets(pkg);
+ for( int i = 0; i < filesets.length; i++ ) {
+ fullFilesetBuild(filesets[i], pkg);
+ }
+
+ EventManager.finishedBuildingArchive(pkg);
+ }
+
+ /**
+ * Build the given fileset
+ * @param fileset The fileset to match
+ * @param topLevel The top level archive that the fileset belongs to
+ */
+ protected void fullFilesetBuild(IArchiveFileSet fileset, IArchive topLevel) {
+ EventManager.startedCollectingFileSet(fileset);
+
+ // reset the scanner. It *is* a full build afterall
+ fileset.resetScanner();
+ IPath[] paths = fileset.findMatchingPaths();
+ ModelTruezipBridge.fullFilesetBuild(fileset);
+
+ EventManager.filesUpdated(topLevel, fileset, paths);
+ EventManager.finishedCollectingFileSet(fileset);
+ }
+
+
+
+
+ /**
+ * Incremental Build!!
+ * Parameters are instances of changed IPath objects.
+ * Will search the entire model for matching filesets.
+ *
+ * @param addedChanged Set of changed / added resources
+ * @param setRemoved Set of removed resources
+ */
+ public void projectIncrementalBuild(Set<IPath> addedChanged, Set<IPath>
removed) {
+ incrementalBuild(null, addedChanged, removed);
+ }
+
+ /**
+ * Incremental build.
+ * Parameters are instance sof changed IPath objects
+ * Will search only the given node for matching descendent filesets
+ * @param archive An archive to limit the scope to, or null if the entire default
model
+ * @param addedChanged A list of added or changed resource paths
+ * @param removed A list of removed resource paths
+ */
+ public void incrementalBuild(IArchive archive, Set<IPath> addedChanged,
Set<IPath> removed) {
+
+ // find any and all filesets that match each file
+ Iterator<IPath> i = addedChanged.iterator();
+ IPath path;
+ IArchiveFileSet[] matchingFilesets;
+ ArrayList<IArchive> topPackagesChanged = new ArrayList<IArchive>();
+ while(i.hasNext()) {
+ path = i.next();
+ matchingFilesets = ModelUtil.getMatchingFilesets(archive, path);
+ localFireAffectedTopLevelPackages(topPackagesChanged, matchingFilesets);
+ ModelTruezipBridge.copyFiles(matchingFilesets, new IPath[] { path }, false);
+ EventManager.fileUpdated(path, matchingFilesets);
+ }
+
+ i = removed.iterator();
+ while(i.hasNext()) {
+ path = ((IPath)i.next());
+ matchingFilesets = ModelUtil.getMatchingFilesets(archive, path);
+ localFireAffectedTopLevelPackages(topPackagesChanged, matchingFilesets);
+ ModelTruezipBridge.deleteFiles(matchingFilesets, new IPath[] { path }, false);
+ EventManager.fileRemoved(path, matchingFilesets);
+ }
+
+ TrueZipUtil.sync();
+
+ Iterator<IArchive> i2 = topPackagesChanged.iterator();
+ while(i2.hasNext()) {
+ EventManager.finishedBuildingArchive(i2.next());
+ }
+ }
+
+ private void localFireAffectedTopLevelPackages(ArrayList<IArchive> affected,
IArchiveFileSet[] filesets) {
+ for( int i = 0; i < filesets.length; i++ ) {
+ if( !affected.contains(filesets[i].getRootArchive())) {
+ affected.add(filesets[i].getRootArchive());
+ EventManager.startedBuildingArchive(filesets[i].getRootArchive());
+ }
+ }
+ }
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ModelChangeListener.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ModelChangeListener.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ModelChangeListener.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,222 +1,239 @@
-/**
- * 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.build;
-
-import org.eclipse.core.runtime.IPath;
-import org.jboss.ide.eclipse.archives.core.ArchivesCore;
-import org.jboss.ide.eclipse.archives.core.model.EventManager;
-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.IArchiveModelListener;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
-import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
-import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
-import org.jboss.ide.eclipse.archives.core.util.internal.ModelTruezipBridge;
-
-/**
- * This class responds to model change events.
- * It is given a delta as to what nodes are added, removed, or changed.
- * It then keeps the output file for the top level archive in sync with
- * the changes to the model.
- *
- * If the automatic builder is not enabled for this project, the listener
- * does nothing.
- *
- * @author Rob Stryker (rob.stryker(a)redhat.com)
- *
- */
-public class ModelChangeListener implements IArchiveModelListener {
-
- /**
- * This is the entry point for model change events.
- * It immediately passes the delta to be handled.
- */
- public void modelChanged(IArchiveNodeDelta delta) {
- // if we're not building, get out
- if(
!ArchivesCore.getInstance().getPreferenceManager().isBuilderEnabled(delta.getPostNode().getProjectPath()))
- return;
-
- try {
- handle(delta);
- } catch( Exception e ) {
- ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_ERR, "Error
updating model changes", e);
- }
- }
-
- /**
- * This can handle any type of node / delta, not just
- * root elements. If the node is added or removed, it
- * will handle those segments and return without checking
- * the children at all. IT is the responsibility of the add
- * and remove methods to go through the children.
- *
- * Otherwise, it will simply handle attribute children and then
- * move on to the children.
- *
- * @param delta
- */
- private void handle(IArchiveNodeDelta delta) {
- if( isTopLevelArchive(delta.getPostNode()))
- EventManager.startedBuildingArchive((IArchive)delta.getPostNode());
-
- if( (delta.getKind() & (IArchiveNodeDelta.NODE_REGISTERED |
IArchiveNodeDelta.UNKNOWN_CHANGE)) != 0 ) {
- nodeRemoved(delta.getPreNode());
- nodeAdded(delta.getPostNode());
- } if( (delta.getKind() & IArchiveNodeDelta.REMOVED) != 0 ) {
- nodeRemoved(delta.getPreNode());
- } else if( (delta.getKind() & IArchiveNodeDelta.ADDED) != 0 ) {
- nodeAdded(delta.getPostNode());
- } else if( (delta.getKind() & IArchiveNodeDelta.ATTRIBUTE_CHANGED) != 0) {
- boolean shouldHandleChildren = handleAttributeChange(delta);
- if( shouldHandleChildren ) {
- IArchiveNodeDelta[] children = delta.getAllAffectedChildren();
- for( int i = 0; i < children.length; i++ ) {
- handle(children[i]);
- }
- }
- } else if( descendentChanged(delta.getKind()) ) {
- IArchiveNodeDelta[] children = delta.getAllAffectedChildren();
- for( int i = 0; i < children.length; i++ ) {
- handle(children[i]);
- }
- }
-
- if( isTopLevelArchive(delta.getPostNode()))
- EventManager.finishedBuildingArchive((IArchive)delta.getPostNode());
-
- }
- protected boolean descendentChanged(int kind) {
- return (kind & IArchiveNodeDelta.DESCENDENT_CHANGED) != 0 ||
- (kind & IArchiveNodeDelta.CHILD_ADDED) != 0 ||
- (kind & IArchiveNodeDelta.CHILD_REMOVED) != 0;
- }
- protected boolean isTopLevelArchive(IArchiveNode node) {
- if( node != null && node instanceof IArchive &&
((IArchive)node).isTopLevel())
- return true;
- return false;
- }
- /**
- * Handle changes in this node
- * @param delta
- * @return Whether or not the caller should also handle the children
- */
- private boolean handleAttributeChange(IArchiveNodeDelta delta) {
- switch( delta.getPostNode().getNodeType()) {
- case IArchiveNode.TYPE_ARCHIVE_FOLDER:
- return handleFolderAttributeChanged(delta);
- case IArchiveNode.TYPE_ARCHIVE_FILESET:
- return handleFilesetAttributeChanged(delta);
- case IArchiveNode.TYPE_ARCHIVE:
- return handlePackageAttributeChanged(delta);
- }
- return false;
- }
-
-
- /*
- * These three methods will need to be optimized eventually. Because right now they
suck
- */
- private boolean handleFolderAttributeChanged(IArchiveNodeDelta delta) {
- nodeRemoved(delta.getPreNode());
- nodeAdded(delta.getPostNode());
- return false;
- }
-
- private boolean handleFilesetAttributeChanged(IArchiveNodeDelta delta) {
- nodeRemoved(delta.getPreNode());
- nodeAdded(delta.getPostNode());
- return false;
- }
-
- private boolean handlePackageAttributeChanged(IArchiveNodeDelta delta) {
- nodeRemoved(delta.getPreNode());
- nodeAdded(delta.getPostNode());
- return false;
- }
-
-
-
-
- private void nodeAdded(IArchiveNode added) {
- if( added == null ) return;
-
- if( added.getNodeType() == IArchiveNode.TYPE_MODEL_ROOT) {
- IArchiveNode[] archives =
((IArchiveModelRootNode)added).getChildren(IArchiveNode.TYPE_ARCHIVE);
- for( int i = 0; i < archives.length; i++ ) {
- nodeAdded(archives[i]);
- }
- } else if( added.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
- // create the package
- ModelTruezipBridge.createFile(added);
- } else if( added.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER ) {
- // create the folder
- ModelTruezipBridge.createFile(added);
- }
- IArchiveFileSet[] filesets = ModelUtil.findAllDescendentFilesets(added);
- for( int i = 0; i < filesets.length; i++ ) {
- ModelTruezipBridge.fullFilesetBuild(filesets[i]);
- IPath[] paths = filesets[i].findMatchingPaths();
- EventManager.filesUpdated(filesets[i].getRootArchive(), filesets[i], paths);
- }
- postChange(added);
- }
-
-
- private void nodeRemoved(IArchiveNode removed) {
- if( removed == null ) return;
- if( removed.getNodeType() == IArchiveNode.TYPE_MODEL_ROOT ) {
- // remove all top level items
- IArchiveNode[] kids = removed.getChildren(IArchiveNode.TYPE_ARCHIVE);
- for( int i = 0; i < kids.length; i++ ) {
- nodeRemoved(kids[i]);
- }
- postChange(removed);
- return;
- } else if( removed.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
- ModelTruezipBridge.deleteArchive((IArchive)removed);
- postChange(removed);
- return;
- } else if( removed.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER ){
- IArchiveFileSet[] filesets =
ModelUtil.findAllDescendentFilesets(((IArchiveFolder)removed));
- for( int i = 0; i < filesets.length; i++ ) {
- IPath[] removedPaths = ModelTruezipBridge.fullFilesetRemove(filesets[i], false);
- EventManager.filesRemoved(removedPaths, ((IArchiveFileSet)filesets[i]));
- }
- postChange(removed);
- return;
- }
-
- IArchiveFileSet[] filesets = ModelUtil.findAllDescendentFilesets(removed);
- for( int i = 0; i < filesets.length; i++ ) {
- IPath[] removedPaths =
ModelTruezipBridge.fullFilesetRemove(((IArchiveFileSet)removed), false);
- EventManager.filesRemoved(removedPaths, ((IArchiveFileSet)removed));
- }
- postChange(removed);
- }
-
-
- protected void postChange(IArchiveNode node) {
- }
-}
+/**
+ * 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.build;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.EventManager;
+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.IArchiveModelListener;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
+import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+import org.jboss.ide.eclipse.archives.core.util.internal.ModelTruezipBridge;
+
+/**
+ * This class responds to model change events.
+ * It is given a delta as to what nodes are added, removed, or changed.
+ * It then keeps the output file for the top level archive in sync with
+ * the changes to the model.
+ *
+ * If the automatic builder is not enabled for this project, the listener
+ * does nothing.
+ *
+ * @author Rob Stryker (rob.stryker(a)redhat.com)
+ *
+ */
+public class ModelChangeListener implements IArchiveModelListener {
+
+ /**
+ * This is the entry point for model change events.
+ * It immediately passes the delta to be handled.
+ */
+ public void modelChanged(IArchiveNodeDelta delta) {
+ // if we're not building, get out
+ if(
!ArchivesCore.getInstance().getPreferenceManager().isBuilderEnabled(delta.getPostNode().getProjectPath()))
+ return;
+
+ try {
+ handle(delta);
+ } catch( Exception e ) {
+ ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_ERR, "Error
updating model changes", e);
+ }
+ }
+
+ /**
+ * This can handle any type of node / delta, not just
+ * root elements. If the node is added or removed, it
+ * will handle those segments and return without checking
+ * the children at all. IT is the responsibility of the add
+ * and remove methods to go through the children.
+ *
+ * Otherwise, it will simply handle attribute children and then
+ * move on to the children.
+ *
+ * @param delta
+ */
+ private void handle(IArchiveNodeDelta delta) {
+ if( isTopLevelArchive(delta.getPostNode())) {
+ EventManager.startedBuildingArchive((IArchive)delta.getPostNode());
+ }
+
+ if( (delta.getKind() & (IArchiveNodeDelta.NODE_REGISTERED |
IArchiveNodeDelta.UNKNOWN_CHANGE)) != 0 ) {
+ nodeRemoved(delta.getPreNode());
+ nodeAdded(delta.getPostNode());
+ } if( (delta.getKind() & IArchiveNodeDelta.REMOVED) != 0 ) {
+ nodeRemoved(delta.getPreNode());
+ } else if( (delta.getKind() & IArchiveNodeDelta.ADDED) != 0 ) {
+ nodeAdded(delta.getPostNode());
+ } else if( (delta.getKind() & IArchiveNodeDelta.ATTRIBUTE_CHANGED) != 0) {
+ boolean shouldHandleChildren = handleAttributeChange(delta);
+ if( shouldHandleChildren ) {
+ IArchiveNodeDelta[] children = delta.getAllAffectedChildren();
+ for( int i = 0; i < children.length; i++ ) {
+ handle(children[i]);
+ }
+ }
+ } else if( descendentChanged(delta.getKind()) ) {
+ IArchiveNodeDelta[] children = delta.getAllAffectedChildren();
+ for( int i = 0; i < children.length; i++ ) {
+ handle(children[i]);
+ }
+ }
+
+ if( isTopLevelArchive(delta.getPostNode()))
+ EventManager.finishedBuildingArchive((IArchive)delta.getPostNode());
+
+ }
+ protected boolean descendentChanged(int kind) {
+ return (kind & IArchiveNodeDelta.DESCENDENT_CHANGED) != 0 ||
+ (kind & IArchiveNodeDelta.CHILD_ADDED) != 0 ||
+ (kind & IArchiveNodeDelta.CHILD_REMOVED) != 0;
+ }
+ protected boolean isTopLevelArchive(IArchiveNode node) {
+ if( node != null && node instanceof IArchive &&
((IArchive)node).isTopLevel())
+ return true;
+ return false;
+ }
+ /**
+ * Handle changes in this node
+ * @param delta
+ * @return Whether or not the caller should also handle the children
+ */
+ private boolean handleAttributeChange(IArchiveNodeDelta delta) {
+ switch( delta.getPostNode().getNodeType()) {
+ case IArchiveNode.TYPE_ARCHIVE_FOLDER:
+ return handleFolderAttributeChanged(delta);
+ case IArchiveNode.TYPE_ARCHIVE_FILESET:
+ return handleFilesetAttributeChanged(delta);
+ case IArchiveNode.TYPE_ARCHIVE:
+ return handlePackageAttributeChanged(delta);
+ }
+ return false;
+ }
+
+
+ /*
+ * These three methods will need to be optimized eventually. Because right now they
suck
+ */
+ private boolean handleFolderAttributeChanged(IArchiveNodeDelta delta) {
+ nodeRemoved(delta.getPreNode());
+ nodeAdded(delta.getPostNode());
+ return false;
+ }
+
+ private boolean handleFilesetAttributeChanged(IArchiveNodeDelta delta) {
+ nodeRemoved(delta.getPreNode());
+ nodeAdded(delta.getPostNode());
+ return false;
+ }
+
+ private boolean handlePackageAttributeChanged(IArchiveNodeDelta delta) {
+ nodeRemoved(delta.getPreNode());
+ nodeAdded(delta.getPostNode());
+ return false;
+ }
+
+
+
+
+ private void nodeAdded(IArchiveNode added) {
+ if( added == null ) return;
+
+ if( added.getNodeType() == IArchiveNode.TYPE_MODEL_ROOT) {
+ IArchiveNode[] archives =
((IArchiveModelRootNode)added).getChildren(IArchiveNode.TYPE_ARCHIVE);
+ for( int i = 0; i < archives.length; i++ ) {
+ nodeAdded(archives[i]);
+ }
+ } else if( added.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
+ // create the package
+ if( ((IArchive)added).isTopLevel() && !added.canBuild() ) {
+ logCannotBuildError((IArchive)added);
+ return;
+ }
+ ModelTruezipBridge.createFile(added);
+ } else if( added.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER ) {
+ // create the folder
+ ModelTruezipBridge.createFile(added);
+ }
+ IArchiveFileSet[] filesets = ModelUtil.findAllDescendentFilesets(added);
+ for( int i = 0; i < filesets.length; i++ ) {
+ ModelTruezipBridge.fullFilesetBuild(filesets[i]);
+ IPath[] paths = filesets[i].findMatchingPaths();
+ EventManager.filesUpdated(filesets[i].getRootArchive(), filesets[i], paths);
+ }
+ postChange(added);
+ }
+
+
+ private void nodeRemoved(IArchiveNode removed) {
+ if( removed == null ) return;
+ if( removed.getNodeType() == IArchiveNode.TYPE_MODEL_ROOT ) {
+ // remove all top level items
+ IArchiveNode[] kids = removed.getChildren(IArchiveNode.TYPE_ARCHIVE);
+ for( int i = 0; i < kids.length; i++ ) {
+ nodeRemoved(kids[i]);
+ }
+ postChange(removed);
+ return;
+ } else if( removed.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
+ if( ((IArchive)removed).isTopLevel() && !removed.canBuild() ) {
+ logCannotBuildError((IArchive)removed);
+ return;
+ }
+ ModelTruezipBridge.deleteArchive((IArchive)removed);
+ postChange(removed);
+ return;
+ } else if( removed.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER ){
+ IArchiveFileSet[] filesets =
ModelUtil.findAllDescendentFilesets(((IArchiveFolder)removed));
+ for( int i = 0; i < filesets.length; i++ ) {
+ IPath[] removedPaths = ModelTruezipBridge.fullFilesetRemove(filesets[i], false);
+ EventManager.filesRemoved(removedPaths, ((IArchiveFileSet)filesets[i]));
+ }
+ postChange(removed);
+ return;
+ }
+
+ IArchiveFileSet[] filesets = ModelUtil.findAllDescendentFilesets(removed);
+ for( int i = 0; i < filesets.length; i++ ) {
+ IPath[] removedPaths =
ModelTruezipBridge.fullFilesetRemove(((IArchiveFileSet)removed), false);
+ EventManager.filesRemoved(removedPaths, ((IArchiveFileSet)removed));
+ }
+ postChange(removed);
+ }
+
+
+ protected void postChange(IArchiveNode node) {
+ }
+
+ protected void logCannotBuildError(IArchive archive) {
+ ArchivesCore.getInstance().getLogger().log(IStatus.WARNING,
+ "Cannot Build archive \"" + archive.getName() +
+ "\" due to a problem in the archive's configuration.", null);
+ return;
+ }
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/ArchivesModelCore.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/ArchivesModelCore.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/ArchivesModelCore.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,87 +1,90 @@
-/*
- * 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.model;
-
-import org.apache.tools.ant.DirectoryScanner;
-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.Path;
-import org.jboss.ide.eclipse.archives.core.ArchivesCore;
-import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
-
-/**
- * Utility methods and entry points for model-related APIs
- * @author Rob Stryker (rob.stryker(a)redhat.com)
- *
- */
-public class ArchivesModelCore {
-
- /**
- * Builds all of a project's packages. Note that this does not call any builders
before or after the package builder (i.e. the JDT builder).
- * If you are looking to run all the builders on a project use project.build()
- * @param project The project to build
- * @param buildType FULL_BUILD, INCREMENTAL_BUILD, CLEAN_BUILD, etc
- * @param monitor A progress monitor
- */
- public static void buildProject (IPath project, IProgressMonitor monitor) {
- if (monitor == null) monitor = new NullProgressMonitor();
- new ArchiveBuildDelegate().fullProjectBuild(project);
- }
-
- /**
- * Build the passed-in package.
- * @param pkg The package to build
- */
- public static void buildArchive (IArchive pkg, IProgressMonitor monitor) {
- if (monitor == null) monitor = new NullProgressMonitor();
- new ArchiveBuildDelegate().fullArchiveBuild(pkg);
- }
-
- public static boolean packageFileExists (IPath project) {
- return project.append(IArchiveModel.DEFAULT_PACKAGES_FILE).toFile().exists();
- }
-
- public static boolean projectRegistered(IPath project) {
- return ArchivesModel.instance().getRoot(project) == null ? false : true;
- }
-
- public static IPath[] findMatchingPaths(IPath root, String includes, String excludes) {
- try {
- if(root==null) return new IPath[0];
-
- DirectoryScanner scanner =
- DirectoryScannerFactory.createDirectoryScanner(root, includes, excludes, true);
- String[] files = scanner.getIncludedFiles();
- IPath[] paths = new IPath[files.length];
- for( int i = 0; i < files.length; i++ ) {
- paths[i] = new Path(files[i]);
- }
- return paths;
- } catch( IllegalStateException ise ) {
- ArchivesCore.getInstance().getLogger().log(IStatus.WARNING, "Error creating
directory scanner", ise);
- return new IPath[]{};
- }
- }
-
-}
+/*
+ * 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.model;
+
+import org.apache.tools.ant.DirectoryScanner;
+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.Path;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
+
+/**
+ * Utility methods and entry points for model-related APIs
+ * @author Rob Stryker (rob.stryker(a)redhat.com)
+ *
+ */
+public class ArchivesModelCore {
+
+ /**
+ * Builds all of a project's packages. Note that this does not call any builders
before or after the package builder (i.e. the JDT builder).
+ * If you are looking to run all the builders on a project use project.build()
+ * @param project The project to build
+ * @param buildType FULL_BUILD, INCREMENTAL_BUILD, CLEAN_BUILD, etc
+ * @param monitor A progress monitor
+ */
+ public static void buildProject (IPath project, IProgressMonitor monitor) {
+ if (monitor == null) monitor = new NullProgressMonitor();
+ new ArchiveBuildDelegate().fullProjectBuild(project);
+ }
+
+ /**
+ * Build the passed-in package.
+ * @param pkg The package to build
+ */
+ public static void buildArchive (IArchive pkg, IProgressMonitor monitor) {
+ if (monitor == null) monitor = new NullProgressMonitor();
+ new ArchiveBuildDelegate().fullArchiveBuild(pkg);
+ }
+
+ public static boolean packageFileExists (IPath project) {
+ return project.append(IArchiveModel.DEFAULT_PACKAGES_FILE).toFile().exists();
+ }
+
+ public static boolean projectRegistered(IPath project) {
+ return ArchivesModel.instance().getRoot(project) == null ? false : true;
+ }
+
+ public static IPath[] findMatchingPaths(IPath root, String includes, String excludes) {
+ try {
+ if(root==null) return new IPath[0];
+
+ DirectoryScanner scanner =
+ DirectoryScannerFactory.createDirectoryScanner(root, includes, excludes, true);
+
+ if( scanner == null )
+ return new IPath[] {};
+
+ String[] files = scanner.getIncludedFiles();
+ IPath[] paths = new IPath[files.length];
+ for( int i = 0; i < files.length; i++ ) {
+ paths[i] = new Path(files[i]);
+ }
+ return paths;
+ } catch( IllegalStateException ise ) {
+ return new IPath[]{};
+ }
+ }
+
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/DirectoryScannerFactory.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/DirectoryScannerFactory.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/DirectoryScannerFactory.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,65 +1,67 @@
-/**
- * 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.model;
-
-import java.io.File;
-
-import org.apache.tools.ant.DirectoryScanner;
-import org.eclipse.core.runtime.IPath;
-
-/**
- * Utility methods to create scanners for matching
- * @author rob.stryker(a)jboss.com
- */
-public class DirectoryScannerFactory {
-
- public static DirectoryScannerExtension createDirectoryScanner (IPath filesystemFolder,
String includes, String excludes, boolean scan) {
- if (includes == null) includes = "";
- if (excludes == null) excludes = "";
-
- DirectoryScannerExtension scanner = new DirectoryScannerExtension();
- String excludesList[] = excludes.split(" ?, ?");
- String includesList[] = includes.split(" ?, ?");
-
- File basedir = filesystemFolder.toFile();
- scanner.setBasedir(basedir);
- scanner.setExcludes(excludesList);
- scanner.setIncludes(includesList);
- if (scan) {
- scanner.scan();
- }
-
- return scanner;
- }
-
- /**
- * Exposes the isIncluded method so that entire scans do not need to occur
- * to find matches.
- *
- * Overwrites
- */
- public static class DirectoryScannerExtension extends DirectoryScanner {
- public boolean isUltimatelyIncluded(String name) {
- return super.isIncluded(name) && !super.isExcluded(name);
- }
- }
-}
+/**
+ * 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.model;
+
+import java.io.File;
+
+import org.apache.tools.ant.DirectoryScanner;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * Utility methods to create scanners for matching
+ * @author rob.stryker(a)jboss.com
+ */
+public class DirectoryScannerFactory {
+
+ public static DirectoryScannerExtension createDirectoryScanner (IPath filesystemFolder,
String includes, String excludes, boolean scan) {
+ if (includes == null) includes = "";
+ if (excludes == null) excludes = "";
+ if( filesystemFolder == null )
+ return null;
+
+ DirectoryScannerExtension scanner = new DirectoryScannerExtension();
+ String excludesList[] = excludes.split(" ?, ?");
+ String includesList[] = includes.split(" ?, ?");
+
+ File basedir = filesystemFolder.toFile();
+ scanner.setBasedir(basedir);
+ scanner.setExcludes(excludesList);
+ scanner.setIncludes(includesList);
+ if (scan) {
+ scanner.scan();
+ }
+
+ return scanner;
+ }
+
+ /**
+ * Exposes the isIncluded method so that entire scans do not need to occur
+ * to find matches.
+ *
+ * Overwrites
+ */
+ public static class DirectoryScannerExtension extends DirectoryScanner {
+ public boolean isUltimatelyIncluded(String name) {
+ return super.isIncluded(name) && !super.isExcluded(name);
+ }
+ }
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNode.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNode.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNode.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,191 +1,197 @@
-/*
- * 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.model;
-
-import org.eclipse.core.runtime.IPath;
-
-/**
- * The super type of all package nodes (IPackage, IPackageFileSet, IPackageFolder)
- *
- * Each node in a package may have arbitrary properties that can be reflected upon by
other plug-ins
- *
- * @author <a href="marshall(a)jboss.org">Marshall Culpepper</a>
- * @author <a href="rob.stryker(a)redhat.com">Rob Stryker</a>
- * @version $Revision: 1929 $
- */
-public interface IArchiveNode {
- /**
- * The node type that represents the model
- */
- public static final int TYPE_MODEL_ROOT = -1;
-
- /**
- * The node type that represents an IArchive
- */
- public static final int TYPE_ARCHIVE = 0;
-
- /**
- * The node type that represents an IArchiveReference
- */
- public static final int TYPE_ARCHIVE_REFERENCE = 1;
-
- /**
- * The node type that represents an IArchiveFileSet
- */
- public static final int TYPE_ARCHIVE_FILESET = 2;
-
- /**
- * The node type that represents an IActionFolder
- */
- public static final int TYPE_ARCHIVE_FOLDER = 3;
-
- /**
- * The node type that represents an IArchiveAction
- */
- public static final int TYPE_ARCHIVE_ACTION = 4;
-
-
- /**
- * @return The parent of this package node, or null if this node is top level
- */
- public IArchiveNode getParent();
-
- /**
- * Set the parent of this package node
- * @param parent The new parent of this node
- */
- public void setParent(IArchiveNode parent);
-
- /**
- * @param type TYPE_PACKAGE, TYPE_PACKAGE_FILESET, or TYPE_PACKAGE_FOLDER
- * @return An array of child nodes of the passed in type
- */
- public IArchiveNode[] getChildren(int type);
-
- /**
- * @return An array of all children nodes
- */
- public IArchiveNode[] getAllChildren();
-
- /**
- * @return Whether or not this node has children
- */
- public boolean hasChildren();
-
- /**
- * @param child A possible child node
- * @return Whether or not the passed-in node is a child of this node
- */
- public boolean hasChild(IArchiveNode child);
-
- /**
- * @return The type of this package node
- */
- public int getNodeType();
-
- /**
- * @param property The name of the property to fetch
- * @return The value of the specified property
- */
- public String getProperty(String property);
-
- /**
- * Set a property on this package node
- * @param property The name of the property to set
- * @param value The new value of the property
- */
- public void setProperty(String property, String value);
-
- /**
- * @return The project that this node is defined in (not necessarily the project where
this is based if this is a fileset)
- */
- public IPath getProjectPath();
-
- /**
- * Recursively visit the package node tree below this node with the passed-in package
node visitor.
- * @param visitor A package node visitor
- * @return Whether or not the entire sub-tree was visited
- */
- public boolean accept(IArchiveNodeVisitor visitor);
-
- /**
- * Recursively visit the package node tree below this node with the passed-in package
node visitor, using depth-first ordering
- * @param visitor A package node visitor
- * @return Whether or not the entire sub-tree was visited
- */
- public boolean accept(IArchiveNodeVisitor visitor, boolean depthFirst);
-
- /**
- * Add a child node to this node
- * @param child The child to add
- */
- public void addChild(IArchiveNode child) throws ArchivesModelException;
-
- /**
- * Remove a child node from this node
- * @param child The child to remove
- */
- public void removeChild(IArchiveNode child);
-
- /**
- * Get the highest parent that is not null.
- * @return
- */
- public IArchiveNode getRoot();
-
- /**
- * Get the model this node is attached to, or null if none
- * @return
- */
- public IArchiveModelRootNode getModelRootNode();
-
- /**
- * Get the path relative to the root archive,
- * or null if not applicable.
- * @return
- */
- public IPath getRootArchiveRelativePath();
-
- /**
- * Get the root top-level package for this node
- * @return
- */
- public IArchive getRootArchive();
-
- /**
- * Get the current delta
- * @return
- */
- public IArchiveNodeDelta getDelta();
-
- /**
- * Clear the current delta
- * @return
- */
- public void clearDelta();
-
- /**
- * Validating the model
- * @return true if it's ok, false if it should fail
- */
- public boolean validateModel();
-}
+/*
+ * 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.model;
+
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * The super type of all package nodes (IPackage, IPackageFileSet, IPackageFolder)
+ *
+ * Each node in a package may have arbitrary properties that can be reflected upon by
other plug-ins
+ *
+ * @author <a href="marshall(a)jboss.org">Marshall Culpepper</a>
+ * @author <a href="rob.stryker(a)redhat.com">Rob Stryker</a>
+ * @version $Revision: 1929 $
+ */
+public interface IArchiveNode {
+ /**
+ * The node type that represents the model
+ */
+ public static final int TYPE_MODEL_ROOT = -1;
+
+ /**
+ * The node type that represents an IArchive
+ */
+ public static final int TYPE_ARCHIVE = 0;
+
+ /**
+ * The node type that represents an IArchiveReference
+ */
+ public static final int TYPE_ARCHIVE_REFERENCE = 1;
+
+ /**
+ * The node type that represents an IArchiveFileSet
+ */
+ public static final int TYPE_ARCHIVE_FILESET = 2;
+
+ /**
+ * The node type that represents an IActionFolder
+ */
+ public static final int TYPE_ARCHIVE_FOLDER = 3;
+
+ /**
+ * The node type that represents an IArchiveAction
+ */
+ public static final int TYPE_ARCHIVE_ACTION = 4;
+
+
+ /**
+ * @return The parent of this package node, or null if this node is top level
+ */
+ public IArchiveNode getParent();
+
+ /**
+ * Set the parent of this package node
+ * @param parent The new parent of this node
+ */
+ public void setParent(IArchiveNode parent);
+
+ /**
+ * @param type TYPE_PACKAGE, TYPE_PACKAGE_FILESET, or TYPE_PACKAGE_FOLDER
+ * @return An array of child nodes of the passed in type
+ */
+ public IArchiveNode[] getChildren(int type);
+
+ /**
+ * @return An array of all children nodes
+ */
+ public IArchiveNode[] getAllChildren();
+
+ /**
+ * @return Whether or not this node has children
+ */
+ public boolean hasChildren();
+
+ /**
+ * @param child A possible child node
+ * @return Whether or not the passed-in node is a child of this node
+ */
+ public boolean hasChild(IArchiveNode child);
+
+ /**
+ * @return The type of this package node
+ */
+ public int getNodeType();
+
+ /**
+ * @param property The name of the property to fetch
+ * @return The value of the specified property
+ */
+ public String getProperty(String property);
+
+ /**
+ * Set a property on this package node
+ * @param property The name of the property to set
+ * @param value The new value of the property
+ */
+ public void setProperty(String property, String value);
+
+ /**
+ * @return The project that this node is defined in (not necessarily the project where
this is based if this is a fileset)
+ */
+ public IPath getProjectPath();
+
+ /**
+ * Recursively visit the package node tree below this node with the passed-in package
node visitor.
+ * @param visitor A package node visitor
+ * @return Whether or not the entire sub-tree was visited
+ */
+ public boolean accept(IArchiveNodeVisitor visitor);
+
+ /**
+ * Recursively visit the package node tree below this node with the passed-in package
node visitor, using depth-first ordering
+ * @param visitor A package node visitor
+ * @return Whether or not the entire sub-tree was visited
+ */
+ public boolean accept(IArchiveNodeVisitor visitor, boolean depthFirst);
+
+ /**
+ * Add a child node to this node
+ * @param child The child to add
+ */
+ public void addChild(IArchiveNode child) throws ArchivesModelException;
+
+ /**
+ * Remove a child node from this node
+ * @param child The child to remove
+ */
+ public void removeChild(IArchiveNode child);
+
+ /**
+ * Get the highest parent that is not null.
+ * @return
+ */
+ public IArchiveNode getRoot();
+
+ /**
+ * Get the model this node is attached to, or null if none
+ * @return
+ */
+ public IArchiveModelRootNode getModelRootNode();
+
+ /**
+ * Get the path relative to the root archive,
+ * or null if not applicable.
+ * @return
+ */
+ public IPath getRootArchiveRelativePath();
+
+ /**
+ * Get the root top-level package for this node
+ * @return
+ */
+ public IArchive getRootArchive();
+
+ /**
+ * Get the current delta
+ * @return
+ */
+ public IArchiveNodeDelta getDelta();
+
+ /**
+ * Clear the current delta
+ * @return
+ */
+ public void clearDelta();
+
+ /**
+ * Validating the model
+ * @return true if it's ok, false if it should fail
+ */
+ public boolean validateModel();
+
+ /**
+ * Are all of the fields here accessible to be built?
+ * @throws AssertionFailedException with what's wrong
+ */
+ public boolean canBuild();
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFileSetImpl.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFileSetImpl.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveFileSetImpl.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,293 +1,294 @@
-/*
- * 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.model.internal;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.jboss.ide.eclipse.archives.core.ArchivesCore;
-import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
-import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
-import
org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
-import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
-
-/**
- * An implementation for filesets
- * @author <a href="rob.stryker(a)redhat.com">Rob Stryker</a>
- *
- */
-public class ArchiveFileSetImpl extends ArchiveNodeImpl implements
- IArchiveFileSet {
-
- private DirectoryScannerExtension scanner;
- private ArrayList<IPath> matchingPaths;
- private boolean rescanRequired = true;
-
- public ArchiveFileSetImpl() {
- this(new XbFileSet());
- }
-
- public ArchiveFileSetImpl (XbFileSet delegate) {
- super(delegate);
- }
-
- /*
- * @see IArchiveFileSet#findMatchingPaths()
- */
- public synchronized IPath[] findMatchingPaths () {
- getScanner(); // ensure up to date
- return matchingPaths == null ? new IPath[0] : matchingPaths.toArray(new
IPath[matchingPaths.size()]);
- }
-
- /*
- * @see IArchiveFileSet#getExcludesPattern()
- */
- public String getExcludesPattern() {
- return getFileSetDelegate().getExcludes();
- }
-
- /*
- * @see IArchiveFileSet#isInWorkspace()
- */
- public boolean isInWorkspace() {
- return getFileSetDelegate().isInWorkspace();
- }
-
- /*
- * @see IArchiveFileSet#getIncludesPattern()
- */
- public String getIncludesPattern() {
- return getFileSetDelegate().getIncludes();
- }
-
- /*
- * @see IArchiveFileSet#getGlobalSourcePath()
- */
- public IPath getGlobalSourcePath() {
- IPath ret;
- String path = getFileSetDelegate().getDir();
- if (path == null || path.equals(".") || path.equals("")) {
- ret = getProjectPath();
- } else if( isInWorkspace()){
- ret = ModelUtil.workspacePathToAbsolutePath(new Path(path));
- } else {
- ret = new Path(path);
- }
-
- if( ret == null ) {
- String message = "Error in fileset: " + toString() + "; No global
source path found.";
- ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_WARN, message, new
Exception(message));
- }
-
- return ret;
- }
-
- /*
- * @see IArchiveFileSet#getSourcePath()
- */
- public IPath getSourcePath() {
- return getFileSetDelegate().getDir() == null ?
- null : new Path(getFileSetDelegate().getDir());
- }
-
- /*
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet#isFlattened()
- */
- public boolean isFlattened() {
- return getFileSetDelegate().isFlattened();
- }
-
- /*
- * @see IArchiveFileSet#matchesPath(IPath)
- */
- public boolean matchesPath(IPath path) {
- return matchesPath(getScanner(), path);
- }
-
- private boolean matchesPath(DirectoryScannerExtension scanner, IPath path) {
- IPath global = getGlobalSourcePath();
- if( global != null ) {
- if( global.isPrefixOf(path)) {
- String s =
path.toOSString().substring(getGlobalSourcePath().toOSString().length()+1);
- return scanner.isUltimatelyIncluded(s);
- }
- }
- return false;
- }
-
- /*
- * Will re-scan if required, or use cached scanner
- * @return
- */
- private synchronized DirectoryScannerExtension getScanner() {
- if( scanner == null || rescanRequired) {
- rescanRequired = false;
-
- try {
- // new scanner
- scanner = DirectoryScannerFactory.createDirectoryScanner(
- getGlobalSourcePath(), getIncludesPattern(), getExcludesPattern(), true);
-
- // cache the paths
- ArrayList<IPath> paths = new ArrayList<IPath>();
- IPath sp = getGlobalSourcePath();
- String matched[] = scanner.getIncludedFiles();
- for (int i = 0; i < matched.length; i++) {
- IPath path = sp.append(new Path(matched[i]));
- paths.add(path);
- }
- matchingPaths = paths;
- } catch( IllegalStateException ise ) {
- ArchivesCore.getInstance().getLogger().log(IStatus.WARNING, "Could not create
directory scanner", ise);
- }
- }
- return scanner;
- }
-
- /*
- * @see IArchiveNode#getNodeType()
- */
- public int getNodeType() {
- return TYPE_ARCHIVE_FILESET;
- }
-
- /*
- * @see IArchiveFileSet#setExcludesPattern(String)
- */
- public void setExcludesPattern(String excludes) {
- attributeChanged(EXCLUDES_ATTRIBUTE, getExcludesPattern(), excludes);
- getFileSetDelegate().setExcludes(excludes);
- rescanRequired = true;
- }
-
- /*
- * @see IArchiveFileSet#setIncludesPattern(String)
- */
- public void setIncludesPattern(String includes) {
- attributeChanged(INCLUDES_ATTRIBUTE, getIncludesPattern(), includes);
- getFileSetDelegate().setIncludes(includes);
- rescanRequired = true;
- }
-
- /*
- * @see IArchiveFileSet#setInWorkspace(boolean)
- */
- public void setInWorkspace(boolean isInWorkspace) {
- attributeChanged(IN_WORKSPACE_ATTRIBUTE, new Boolean(isInWorkspace()), new
Boolean(isInWorkspace));
- getFileSetDelegate().setInWorkspace(isInWorkspace);
- rescanRequired = true;
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet#setFlattened(boolean)
- */
- public void setFlattened(boolean flat) {
- attributeChanged(FLATTENED_ATTRIBUTE, new Boolean(isFlattened()), new Boolean(flat));
- getFileSetDelegate().setFlattened(flat);
- //TODO: rescanRequired = true;
- }
-
- /*
- * @see IArchiveFileSet#setSourcePath(IPath, boolean)
- */
- public void setSourcePath (IPath path) {
- Assert.isNotNull(path);
- IPath src = getSourcePath();
- attributeChanged(SOURCE_PATH_ATTRIBUTE, src == null ? null : src.toString(), path ==
null ? null : path.toString());
- getFileSetDelegate().setDir(path.toString());
- rescanRequired = true;
- }
-
- protected XbFileSet getFileSetDelegate () {
- return (XbFileSet)nodeDelegate;
- }
-
-
- /*
- * filesets have no path of their own
- * and should not be the parents of any other node
- * so the parent is their base location
- * @see IArchiveNode#getRootArchiveRelativePath()
- */
- public IPath getRootArchiveRelativePath() {
- return getParent().getRootArchiveRelativePath();
- }
-
- /*
- * @see IArchiveFileSet#getRootArchiveRelativePath(IPath)
- */
- public IPath getRootArchiveRelativePath(IPath inputFile) {
- if( matchesPath(inputFile)) {
- return
getParent().getRootArchiveRelativePath().append(getPathRelativeToParent(inputFile));
- }
- return null;
- }
- /*
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet#getPathRelativeToParent(org.eclipse.core.runtime.IPath)
- */
- public IPath getPathRelativeToParent(IPath inputFile) {
- String s;
- if( isFlattened() )
- s = inputFile.toOSString().substring(getGlobalSourcePath().toOSString().length()+1);
- else
- s = inputFile.lastSegment();
- return new Path(s);
- }
-
-
- /*
- * @see IArchiveFileSet#resetScanner()
- */
- public void resetScanner() {
- rescanRequired = true;
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl#validateChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
- */
- public boolean validateModel() {
- return getAllChildren().length == 0 ? true : false;
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append("{dir=");
- sb.append(getFileSetDelegate().getDir());
- sb.append(",includes=");
- sb.append(getFileSetDelegate().getIncludes());
- sb.append(",excludes=");
- sb.append(getFileSetDelegate().getExcludes());
- sb.append(",inWorkspace=");
- sb.append(getFileSetDelegate().isInWorkspace());
- sb.append(",flatten=");
- sb.append(getFileSetDelegate().isFlattened());
- return sb.toString();
- }
-
-}
+/*
+ * 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.model.internal;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
+import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
+import
org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+
+/**
+ * An implementation for filesets
+ * @author <a href="rob.stryker(a)redhat.com">Rob Stryker</a>
+ *
+ */
+public class ArchiveFileSetImpl extends ArchiveNodeImpl implements
+ IArchiveFileSet {
+
+ private DirectoryScannerExtension scanner;
+ private ArrayList<IPath> matchingPaths;
+ private boolean rescanRequired = true;
+
+ public ArchiveFileSetImpl() {
+ this(new XbFileSet());
+ }
+
+ public ArchiveFileSetImpl (XbFileSet delegate) {
+ super(delegate);
+ }
+
+ /*
+ * @see IArchiveFileSet#findMatchingPaths()
+ */
+ public synchronized IPath[] findMatchingPaths () {
+ getScanner(); // ensure up to date
+ return matchingPaths == null ? new IPath[0] : matchingPaths.toArray(new
IPath[matchingPaths.size()]);
+ }
+
+ /*
+ * @see IArchiveFileSet#getExcludesPattern()
+ */
+ public String getExcludesPattern() {
+ return getFileSetDelegate().getExcludes();
+ }
+
+ /*
+ * @see IArchiveFileSet#isInWorkspace()
+ */
+ public boolean isInWorkspace() {
+ return getFileSetDelegate().isInWorkspace();
+ }
+
+ /*
+ * @see IArchiveFileSet#getIncludesPattern()
+ */
+ public String getIncludesPattern() {
+ return getFileSetDelegate().getIncludes();
+ }
+
+ /*
+ * @see IArchiveFileSet#getGlobalSourcePath()
+ */
+ public IPath getGlobalSourcePath() {
+ IPath ret;
+ String path = getFileSetDelegate().getDir();
+ if (path == null || path.equals(".") || path.equals("")) {
+ ret = getProjectPath();
+ } else if( isInWorkspace()){
+ ret = ModelUtil.workspacePathToAbsolutePath(new Path(path));
+ } else {
+ ret = new Path(path);
+ }
+ return ret;
+ }
+
+ /*
+ * @see IArchiveFileSet#getSourcePath()
+ */
+ public IPath getSourcePath() {
+ return getFileSetDelegate().getDir() == null ?
+ null : new Path(getFileSetDelegate().getDir());
+ }
+
+ /*
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet#isFlattened()
+ */
+ public boolean isFlattened() {
+ return getFileSetDelegate().isFlattened();
+ }
+
+ /*
+ * @see IArchiveFileSet#matchesPath(IPath)
+ */
+ public boolean matchesPath(IPath path) {
+ return matchesPath(getScanner(), path);
+ }
+
+ private boolean matchesPath(DirectoryScannerExtension scanner, IPath path) {
+ IPath global = getGlobalSourcePath();
+ if( global != null ) {
+ if( global.isPrefixOf(path)) {
+ String s =
path.toOSString().substring(getGlobalSourcePath().toOSString().length()+1);
+ return scanner.isUltimatelyIncluded(s);
+ }
+ }
+ return false;
+ }
+
+ /*
+ * Will re-scan if required, or use cached scanner
+ * @return
+ */
+ private synchronized DirectoryScannerExtension getScanner() {
+ if( scanner == null || rescanRequired) {
+ rescanRequired = false;
+
+ try {
+ // new scanner
+ scanner = DirectoryScannerFactory.createDirectoryScanner(
+ getGlobalSourcePath(), getIncludesPattern(), getExcludesPattern(), true);
+
+ ArrayList<IPath> paths = new ArrayList<IPath>();
+ if( scanner != null ) {
+ // cache the paths
+ IPath sp = getGlobalSourcePath();
+ String matched[] = scanner.getIncludedFiles();
+ for (int i = 0; i < matched.length; i++) {
+ IPath path = sp.append(new Path(matched[i]));
+ paths.add(path);
+ }
+ }
+ matchingPaths = paths;
+ } catch( IllegalStateException ise ) {
+ ArchivesCore.getInstance().getLogger().log(IStatus.WARNING, "Could not create
directory scanner", ise);
+ }
+ }
+ return scanner;
+ }
+
+ /*
+ * @see IArchiveNode#getNodeType()
+ */
+ public int getNodeType() {
+ return TYPE_ARCHIVE_FILESET;
+ }
+
+ /*
+ * @see IArchiveFileSet#setExcludesPattern(String)
+ */
+ public void setExcludesPattern(String excludes) {
+ attributeChanged(EXCLUDES_ATTRIBUTE, getExcludesPattern(), excludes);
+ getFileSetDelegate().setExcludes(excludes);
+ rescanRequired = true;
+ }
+
+ /*
+ * @see IArchiveFileSet#setIncludesPattern(String)
+ */
+ public void setIncludesPattern(String includes) {
+ attributeChanged(INCLUDES_ATTRIBUTE, getIncludesPattern(), includes);
+ getFileSetDelegate().setIncludes(includes);
+ rescanRequired = true;
+ }
+
+ /*
+ * @see IArchiveFileSet#setInWorkspace(boolean)
+ */
+ public void setInWorkspace(boolean isInWorkspace) {
+ attributeChanged(IN_WORKSPACE_ATTRIBUTE, new Boolean(isInWorkspace()), new
Boolean(isInWorkspace));
+ getFileSetDelegate().setInWorkspace(isInWorkspace);
+ rescanRequired = true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet#setFlattened(boolean)
+ */
+ public void setFlattened(boolean flat) {
+ attributeChanged(FLATTENED_ATTRIBUTE, new Boolean(isFlattened()), new Boolean(flat));
+ getFileSetDelegate().setFlattened(flat);
+ //TODO: rescanRequired = true;
+ }
+
+ /*
+ * @see IArchiveFileSet#setSourcePath(IPath, boolean)
+ */
+ public void setSourcePath (IPath path) {
+ Assert.isNotNull(path);
+ IPath src = getSourcePath();
+ attributeChanged(SOURCE_PATH_ATTRIBUTE, src == null ? null : src.toString(), path ==
null ? null : path.toString());
+ getFileSetDelegate().setDir(path.toString());
+ rescanRequired = true;
+ }
+
+ protected XbFileSet getFileSetDelegate () {
+ return (XbFileSet)nodeDelegate;
+ }
+
+
+ /*
+ * filesets have no path of their own
+ * and should not be the parents of any other node
+ * so the parent is their base location
+ * @see IArchiveNode#getRootArchiveRelativePath()
+ */
+ public IPath getRootArchiveRelativePath() {
+ return getParent().getRootArchiveRelativePath();
+ }
+
+ /*
+ * @see IArchiveFileSet#getRootArchiveRelativePath(IPath)
+ */
+ public IPath getRootArchiveRelativePath(IPath inputFile) {
+ if( matchesPath(inputFile)) {
+ return
getParent().getRootArchiveRelativePath().append(getPathRelativeToParent(inputFile));
+ }
+ return null;
+ }
+ /*
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet#getPathRelativeToParent(org.eclipse.core.runtime.IPath)
+ */
+ public IPath getPathRelativeToParent(IPath inputFile) {
+ String s;
+ if( isFlattened() )
+ s = inputFile.toOSString().substring(getGlobalSourcePath().toOSString().length()+1);
+ else
+ s = inputFile.lastSegment();
+ return new Path(s);
+ }
+
+
+ /*
+ * @see IArchiveFileSet#resetScanner()
+ */
+ public void resetScanner() {
+ rescanRequired = true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl#validateChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public boolean validateModel() {
+ return getAllChildren().length == 0 ? true : false;
+ }
+
+ public boolean canBuild() {
+ return getGlobalSourcePath() != null
+ && super.canBuild();
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("{dir=");
+ sb.append(getFileSetDelegate().getDir());
+ sb.append(",includes=");
+ sb.append(getFileSetDelegate().getIncludes());
+ sb.append(",excludes=");
+ sb.append(getFileSetDelegate().getExcludes());
+ sb.append(",inWorkspace=");
+ sb.append(getFileSetDelegate().isInWorkspace());
+ sb.append(",flatten=");
+ sb.append(getFileSetDelegate().isFlattened());
+ return sb.toString();
+ }
+
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveImpl.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveImpl.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveImpl.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,272 +1,276 @@
-/*
- * 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.model.internal;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.jboss.ide.eclipse.archives.core.ArchivesCore;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveAction;
-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.IArchiveType;
-import org.jboss.ide.eclipse.archives.core.model.INamedContainerArchiveNode;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
-import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
-
-/**
- * An archive
- *
- * @author Rob stryker
- */
-public class ArchiveImpl extends ArchiveNodeImpl implements IArchive {
-
- private XbPackage packageDelegate;
-
- public ArchiveImpl() {
- this(new XbPackage());
- }
- public ArchiveImpl(XbPackage delegate) {
- super(delegate);
- this.packageDelegate = delegate;
- }
-
- /*
- * @see IArchiveNode#getNodeType()
- */
- public int getNodeType() {
- return TYPE_ARCHIVE;
- }
-
- /*
- * @see IArchive#isDestinationInWorkspace()
- */
- public boolean isDestinationInWorkspace() {
- return packageDelegate.isInWorkspace();
- }
-
- /*
- * @see IArchive#getDestinationPath()
- */
- public IPath getGlobalDestinationPath () {
- if (!isTopLevel() || packageDelegate.getToDir() == null ||
packageDelegate.getToDir().equals(""))
- return Path.EMPTY;
- if( packageDelegate.getToDir().equals("."))
- return getProjectPath() == null ? Path.EMPTY : getProjectPath();
-
- if (isDestinationInWorkspace()) {
- return ModelUtil.workspacePathToAbsolutePath(new Path(packageDelegate.getToDir()));
- } else
- return new Path(packageDelegate.getToDir());
- }
-
- public IPath getDestinationPath() {
- if( !isTopLevel() )
- return Path.EMPTY;
- return packageDelegate.getToDir() == null ? Path.EMPTY : new
Path(packageDelegate.getToDir());
- }
-
- /*
- * @see IArchive#getArchiveFilePath()
- */
- public IPath getArchiveFilePath() {
- return getGlobalDestinationPath().append(getName());
- }
-
- /*
- * @see IArchive#getFileSets()
- */
- public IArchiveFileSet[] getFileSets() {
- IArchiveNode nodes[] = getChildren(TYPE_ARCHIVE_FILESET);
- IArchiveFileSet filesets[] = new IArchiveFileSet[nodes.length];
- System.arraycopy(nodes, 0, filesets, 0, nodes.length);
- return filesets;
- }
-
- /*
- * @see IArchive#getFolders()
- */
- public IArchiveFolder[] getFolders() {
- IArchiveNode nodes[] = getChildren(TYPE_ARCHIVE_FOLDER);
- IArchiveFolder folders[] = new IArchiveFolder[nodes.length];
- System.arraycopy(nodes, 0, folders, 0, nodes.length);
- return folders;
- }
-
- /*
- * @see IArchive#getArchives()
- */
- public IArchive[] getArchives() {
- IArchiveNode nodes[] = getChildren(TYPE_ARCHIVE);
- IArchive pkgs[] = new IArchive[nodes.length];
- System.arraycopy(nodes, 0, pkgs, 0, nodes.length);
- return pkgs;
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchive#getActions()
- */
- public IArchiveAction[] getActions() {
- IArchiveNode nodes[] = getChildren(TYPE_ARCHIVE_ACTION);
- IArchiveAction actions[] = new IArchiveAction[nodes.length];
- System.arraycopy(nodes, 0, actions, 0, nodes.length);
- return actions;
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchive#getPreActions()
- */
- public IArchiveAction[] getPreActions() {
- return new IArchiveAction[0]; // TODO
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchive#getPostActions()
- */
- public IArchiveAction[] getPostActions() {
- return new IArchiveAction[0]; // TODO
- }
-
- /*
- * @see IArchive#getName()
- */
- public String getName() {
- return packageDelegate.getName();
- }
-
- /*
- * @see IArchive#getArchiveType()
- */
- public IArchiveType getArchiveType() {
- return
ArchivesCore.getInstance().getExtensionManager().getArchiveType(packageDelegate.getPackageType());
- }
-
- /*
- * @see IArchive#isExploded()
- */
- public boolean isExploded() {
- return packageDelegate.isExploded();
- }
-
- /*
- * @see IArchive#isTopLevel()
- */
- public boolean isTopLevel() {
- return (packageDelegate.getParent() == null ||
- packageDelegate.getParent() instanceof XbPackages);
- }
-
- /*
- * @see IArchive#setDestinationPath(IPath, boolean)
- */
- public void setDestinationPath(IPath path) {
- IPath destPath = getDestinationPath();
- attributeChanged(DESTINATION_ATTRIBUTE, destPath == null ? null : destPath.toString(),
path == null ? null : path.toString());
- packageDelegate.setToDir(path.toString());
- }
-
- /*
- * @see IArchive#setInWorkspace(boolean)
- */
- public void setInWorkspace(boolean inWorkspace) {
- attributeChanged(IN_WORKSPACE_ATTRIBUTE, new Boolean(isDestinationInWorkspace()), new
Boolean(inWorkspace));
- packageDelegate.setInWorkspace(inWorkspace);
- }
-
- /*
- * @see IArchive#setExploded(boolean)
- */
- public void setExploded(boolean exploded) {
- attributeChanged(EXPLODED_ATTRIBUTE, new Boolean(isExploded()), new
Boolean(exploded));
- packageDelegate.setExploded(exploded);
- }
-
- /*
- * @see IArchive#setName(String)
- */
- public void setName(String name) {
- attributeChanged(NAME_ATTRIBUTE, getName(), name);
- packageDelegate.setName(name);
- }
-
- /*
- * @see IArchive#setArchiveType(IArchiveType)
- */
- public void setArchiveType(IArchiveType type) {
- attributeChanged(PACKAGE_TYPE_ATTRIBUTE, getArchiveTypeId(), type == null ? null :
type.getId());
- packageDelegate.setPackageType(type.getId());
- }
-
- /*
- * @see IArchive#setArchiveType(String)
- */
- public void setArchiveType(String type) {
- attributeChanged(PACKAGE_TYPE_ATTRIBUTE, getArchiveTypeId(), type);
- packageDelegate.setPackageType(type);
- }
-
- public String toString() {
- return getName();
- }
-
- /*
- * @see IArchive#getArchiveTypeId()
- */
- public String getArchiveTypeId() {
- return packageDelegate.getPackageType();
- }
-
- /*
- * @see IArchiveNode#getRootArchiveRelativePath()
- */
- public IPath getRootArchiveRelativePath() {
- if( getParent() == null || getParent().getRootArchiveRelativePath() == null )
- return new Path(getName());
- return getParent().getRootArchiveRelativePath().append(getName());
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl#validateChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
- */
- public boolean validateModel() {
- ArrayList<String> list = new ArrayList<String>();
- IArchiveNode[] children = getAllChildren();
- for( int i = 0; i < children.length; i++ ) {
- if( children[i] instanceof INamedContainerArchiveNode) {
- if( list.contains(((INamedContainerArchiveNode)children[i]).getName()))
- return false;
- else
- list.add(((INamedContainerArchiveNode)children[i]).getName());
- }
- }
- return super.validateModel();
- }
-
-}
+/*
+ * 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.model.internal;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveAction;
+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.IArchiveType;
+import org.jboss.ide.eclipse.archives.core.model.INamedContainerArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+
+/**
+ * An archive
+ *
+ * @author Rob stryker
+ */
+public class ArchiveImpl extends ArchiveNodeImpl implements IArchive {
+
+ private XbPackage packageDelegate;
+
+ public ArchiveImpl() {
+ this(new XbPackage());
+ }
+ public ArchiveImpl(XbPackage delegate) {
+ super(delegate);
+ this.packageDelegate = delegate;
+ }
+
+ /*
+ * @see IArchiveNode#getNodeType()
+ */
+ public int getNodeType() {
+ return TYPE_ARCHIVE;
+ }
+
+ /*
+ * @see IArchive#isDestinationInWorkspace()
+ */
+ public boolean isDestinationInWorkspace() {
+ return packageDelegate.isInWorkspace();
+ }
+
+ /*
+ * @see IArchive#getDestinationPath()
+ */
+ public IPath getGlobalDestinationPath () {
+ if (!isTopLevel() || packageDelegate.getToDir() == null ||
packageDelegate.getToDir().equals(""))
+ return Path.EMPTY;
+ if( packageDelegate.getToDir().equals("."))
+ return getProjectPath() == null ? Path.EMPTY : getProjectPath();
+
+ if (isDestinationInWorkspace()) {
+ return ModelUtil.workspacePathToAbsolutePath(new Path(packageDelegate.getToDir()));
+ } else
+ return new Path(packageDelegate.getToDir());
+ }
+
+ public IPath getDestinationPath() {
+ if( !isTopLevel() )
+ return Path.EMPTY;
+ return packageDelegate.getToDir() == null ? Path.EMPTY : new
Path(packageDelegate.getToDir());
+ }
+
+ /*
+ * @see IArchive#getArchiveFilePath()
+ */
+ public IPath getArchiveFilePath() {
+ return getGlobalDestinationPath().append(getName());
+ }
+
+ /*
+ * @see IArchive#getFileSets()
+ */
+ public IArchiveFileSet[] getFileSets() {
+ IArchiveNode nodes[] = getChildren(TYPE_ARCHIVE_FILESET);
+ IArchiveFileSet filesets[] = new IArchiveFileSet[nodes.length];
+ System.arraycopy(nodes, 0, filesets, 0, nodes.length);
+ return filesets;
+ }
+
+ /*
+ * @see IArchive#getFolders()
+ */
+ public IArchiveFolder[] getFolders() {
+ IArchiveNode nodes[] = getChildren(TYPE_ARCHIVE_FOLDER);
+ IArchiveFolder folders[] = new IArchiveFolder[nodes.length];
+ System.arraycopy(nodes, 0, folders, 0, nodes.length);
+ return folders;
+ }
+
+ /*
+ * @see IArchive#getArchives()
+ */
+ public IArchive[] getArchives() {
+ IArchiveNode nodes[] = getChildren(TYPE_ARCHIVE);
+ IArchive pkgs[] = new IArchive[nodes.length];
+ System.arraycopy(nodes, 0, pkgs, 0, nodes.length);
+ return pkgs;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchive#getActions()
+ */
+ public IArchiveAction[] getActions() {
+ IArchiveNode nodes[] = getChildren(TYPE_ARCHIVE_ACTION);
+ IArchiveAction actions[] = new IArchiveAction[nodes.length];
+ System.arraycopy(nodes, 0, actions, 0, nodes.length);
+ return actions;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchive#getPreActions()
+ */
+ public IArchiveAction[] getPreActions() {
+ return new IArchiveAction[0]; // TODO
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchive#getPostActions()
+ */
+ public IArchiveAction[] getPostActions() {
+ return new IArchiveAction[0]; // TODO
+ }
+
+ /*
+ * @see IArchive#getName()
+ */
+ public String getName() {
+ return packageDelegate.getName();
+ }
+
+ /*
+ * @see IArchive#getArchiveType()
+ */
+ public IArchiveType getArchiveType() {
+ return
ArchivesCore.getInstance().getExtensionManager().getArchiveType(packageDelegate.getPackageType());
+ }
+
+ /*
+ * @see IArchive#isExploded()
+ */
+ public boolean isExploded() {
+ return packageDelegate.isExploded();
+ }
+
+ /*
+ * @see IArchive#isTopLevel()
+ */
+ public boolean isTopLevel() {
+ return (packageDelegate.getParent() == null ||
+ packageDelegate.getParent() instanceof XbPackages);
+ }
+
+ /*
+ * @see IArchive#setDestinationPath(IPath, boolean)
+ */
+ public void setDestinationPath(IPath path) {
+ IPath destPath = getDestinationPath();
+ attributeChanged(DESTINATION_ATTRIBUTE, destPath == null ? null : destPath.toString(),
path == null ? null : path.toString());
+ packageDelegate.setToDir(path.toString());
+ }
+
+ /*
+ * @see IArchive#setInWorkspace(boolean)
+ */
+ public void setInWorkspace(boolean inWorkspace) {
+ attributeChanged(IN_WORKSPACE_ATTRIBUTE, new Boolean(isDestinationInWorkspace()), new
Boolean(inWorkspace));
+ packageDelegate.setInWorkspace(inWorkspace);
+ }
+
+ /*
+ * @see IArchive#setExploded(boolean)
+ */
+ public void setExploded(boolean exploded) {
+ attributeChanged(EXPLODED_ATTRIBUTE, new Boolean(isExploded()), new
Boolean(exploded));
+ packageDelegate.setExploded(exploded);
+ }
+
+ /*
+ * @see IArchive#setName(String)
+ */
+ public void setName(String name) {
+ attributeChanged(NAME_ATTRIBUTE, getName(), name);
+ packageDelegate.setName(name);
+ }
+
+ /*
+ * @see IArchive#setArchiveType(IArchiveType)
+ */
+ public void setArchiveType(IArchiveType type) {
+ attributeChanged(PACKAGE_TYPE_ATTRIBUTE, getArchiveTypeId(), type == null ? null :
type.getId());
+ packageDelegate.setPackageType(type.getId());
+ }
+
+ /*
+ * @see IArchive#setArchiveType(String)
+ */
+ public void setArchiveType(String type) {
+ attributeChanged(PACKAGE_TYPE_ATTRIBUTE, getArchiveTypeId(), type);
+ packageDelegate.setPackageType(type);
+ }
+
+ public String toString() {
+ return getName();
+ }
+
+ /*
+ * @see IArchive#getArchiveTypeId()
+ */
+ public String getArchiveTypeId() {
+ return packageDelegate.getPackageType();
+ }
+
+ /*
+ * @see IArchiveNode#getRootArchiveRelativePath()
+ */
+ public IPath getRootArchiveRelativePath() {
+ if( getParent() == null || getParent().getRootArchiveRelativePath() == null )
+ return new Path(getName());
+ return getParent().getRootArchiveRelativePath().append(getName());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl#validateChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public boolean validateModel() {
+ ArrayList<String> list = new ArrayList<String>();
+ IArchiveNode[] children = getAllChildren();
+ for( int i = 0; i < children.length; i++ ) {
+ if( children[i] instanceof INamedContainerArchiveNode) {
+ if( list.contains(((INamedContainerArchiveNode)children[i]).getName()))
+ return false;
+ else
+ list.add(((INamedContainerArchiveNode)children[i]).getName());
+ }
+ }
+ return super.validateModel();
+ }
+
+ public boolean canBuild() {
+ return getGlobalDestinationPath() != null
+ && super.canBuild();
+ }
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,400 +1,416 @@
-/*
- * 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.model.internal;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-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.IArchiveModelRootNode;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor;
-import
org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeDeltaImpl.NodeDelta;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackageNode;
-import
org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackageNodeWithProperties;
-
-/**
- * Abstract superclass implementation for archive node types
- * @author rob.stryker <rob.stryker(a)redhat.com>
- *
- */
-public abstract class ArchiveNodeImpl implements IArchiveNode {
-
- protected XbPackageNodeWithProperties nodeDelegate;
- protected IArchiveNode parent;
- protected ArrayList<ArchiveNodeImpl> children;
-
- // cached data for deltas
- protected HashMap<String, NodeDelta> attributeChanges;
- protected HashMap<String, NodeDelta> propertyChanges;
- protected HashMap<IArchiveNode, Integer> childChanges;
-
-
- public ArchiveNodeImpl (XbPackageNodeWithProperties delegate) {
- nodeDelegate = delegate;
- children = new ArrayList<ArchiveNodeImpl>();
-
- // for deltas
- attributeChanges = new HashMap<String, NodeDelta>();
- propertyChanges = new HashMap<String, NodeDelta>();
- childChanges = new HashMap<IArchiveNode, Integer>();
- }
-
- public XbPackageNode getNodeDelegate() {
- return nodeDelegate;
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getRoot()
- */
- public IArchiveNode getRoot() {
- return parent == null ? this : parent.getRoot();
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getModel()
- */
- public IArchiveModelRootNode getModelRootNode() {
- Object root = getRoot();
- return root instanceof IArchiveModelRootNode ? (IArchiveModelRootNode)root : null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getRootArchive()
- */
- public IArchive getRootArchive() {
- IArchiveNode parent = this.parent;
- IArchive topArchives = null;
-
- if( getNodeType() == IArchiveNode.TYPE_ARCHIVE ) topArchives = (IArchive)this;
- while( parent != null ) {
- if( parent.getNodeType() == IArchiveNode.TYPE_ARCHIVE )
- topArchives = (IArchive)parent;
- parent = parent.getParent();
- }
- return topArchives;
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getAllChildren()
- */
- public IArchiveNode[] getAllChildren () {
- return children.toArray(new IArchiveNode[children.size()]);
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getChildren(int)
- */
- public IArchiveNode[] getChildren(int type) {
- ArrayList<IArchiveNode> typedChildren = new ArrayList<IArchiveNode>();
- for (Iterator<ArchiveNodeImpl> iter = children.iterator(); iter.hasNext(); ) {
- IArchiveNode child = iter.next();
- if (child.getNodeType() == type) {
- typedChildren.add(child);
- }
- }
-
- return typedChildren.toArray(new IArchiveNode[typedChildren.size()]);
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#hasChildren()
- */
- public boolean hasChildren () {
- return nodeDelegate.hasChildren();
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#hasChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
- */
- public boolean hasChild (IArchiveNode child) {
- ArchiveNodeImpl childImpl = (ArchiveNodeImpl)child;
- return nodeDelegate.getAllChildren().contains(childImpl.nodeDelegate);
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getParent()
- */
- public IArchiveNode getParent() {
- return parent;
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#setParent(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
- */
- public void setParent (IArchiveNode parent) {
- if( getParent() != null && parent != getParent()) {
- getParent().removeChild(this);
- }
-
- this.parent = parent;
- nodeDelegate.setParent(parent == null ? null :
- ((ArchiveNodeImpl)parent).getNodeDelegate());
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getProject()
- */
- public IPath getProjectPath() {
- IArchiveModelRootNode root = getModelRootNode();
- return root == null ? null : root.getProjectPath();
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getProperty(java.lang.String)
- */
- public String getProperty(String property) {
- return getProperties().getProperty(property);
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#setProperty(java.lang.String,
java.lang.String)
- */
- public void setProperty(String property, String value) {
- if( property == null ) return;
- propertyChanged(property, getProperty(property), value);
- if( value == null ) {
- getProperties().remove(property);
- } else {
- getProperties().setProperty(property, value);
- }
- }
-
- /**
- * @return Get the properties for this object
- */
- protected Properties getProperties() {
- return nodeDelegate.getProperties().getProperties();
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#accept(org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor)
- */
- public boolean accept(IArchiveNodeVisitor visitor) {
- return accept(visitor, false);
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#accept(org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor,
boolean)
- */
- public boolean accept(IArchiveNodeVisitor visitor, boolean depthFirst) {
- IArchiveNode children[] = getAllChildren();
- boolean keepGoing = true;
-
- if (!depthFirst)
- keepGoing = visitor.visit(this);
-
- if (keepGoing) {
- for (int i = 0; i < children.length; i++) {
- if (keepGoing) {
- keepGoing = children[i].accept(visitor, depthFirst);
- }
- }
- }
-
- if (depthFirst && keepGoing)
- keepGoing = visitor.visit(this);
-
- return keepGoing;
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#addChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
- */
- public final void addChild(IArchiveNode node) throws ArchivesModelException {
- addChild(node, true);
- }
-
- /**
- * Add a child with the option to skip adding in the delegate
- * @param child
- * @param addInDelegate
- */
- public final void addChild(IArchiveNode child, boolean addInDelegate) throws
ArchivesModelException {
- Assert.isNotNull(child);
- ArchiveNodeImpl childImpl = (ArchiveNodeImpl) child;
- children.add(childImpl);
- childImpl.setParent(this);
- if( addInDelegate )
- nodeDelegate.addChild(childImpl.nodeDelegate);
- childChanges(child, IArchiveNodeDelta.CHILD_ADDED);
- if( !validateModel()) {
- removeChild(child);
- throw new ArchivesModelException("Unable to add child node");
- }
- }
-
- public boolean validateModel() {
- IArchiveNode[] kids = getAllChildren();
- for( int i = 0; i < kids.length; i++ )
- if( !kids[i].validateModel() )
- return false;
- return true;
- }
-
- /*
- * (non-Javadoc)
- * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#removeChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
- */
- public void removeChild(IArchiveNode node) {
- Assert.isNotNull(node);
- ArchiveNodeImpl impl = (ArchiveNodeImpl) node;
- boolean removed = false;
- if (nodeDelegate.getAllChildren().contains(impl.nodeDelegate)) {
- nodeDelegate.removeChild(impl.nodeDelegate);
- removed = true;
- }
-
- if (children.contains(node)) {
- children.remove(node);
- removed = true;
- }
- if( removed )
- childChanges(node, IArchiveNodeDelta.CHILD_REMOVED);
- }
-
- /**
- * An attribute has changed. Save the change so it can be represented in a delta
- */
- protected void attributeChanged(String key, Object beforeValue, Object afterValue) {
- int kind = IArchiveNodeDelta.ATTRIBUTE_CHANGED;
- HashMap<String, NodeDelta> map = attributeChanges;
-
- // short circuit if no change has REALLY occurred
- if( beforeValue != null && beforeValue.equals(afterValue)) return;
-
- if( map.containsKey(key)) {
- Object original = map.get(key).getBefore();
- if( original == null && afterValue == null )
- map.remove(key);
- else if( original == null )
- map.put(key, new NodeDelta(original, afterValue, kind));
- else if( original.equals(afterValue))
- // value was changed from x to y, then back to x. Therefore, no change
- map.remove(key);
- else
- // value was changed from x to y to z.
- // Before should remain x, after should become z
- map.put(key, new NodeDelta(original, afterValue, kind));
- } else {
- // added
- map.put(key, new NodeDelta(beforeValue, afterValue, kind));
- }
- }
-
- /**
- * A property has changed. Save the change so it can be represented in a delta
- */
- protected void propertyChanged(String key, Object beforeValue, Object afterValue) {
- HashMap<String, NodeDelta> changeMap = propertyChanges;
- // short circuit if no change has REALLY occurred
- if( beforeValue != null && beforeValue.equals(afterValue)) return;
-
-
- if( changeMap.containsKey(key)) {
- // element has already been added, removed, or changed since last save
- Object original = changeMap.get(key).getBefore();
- if( original == null && afterValue == null )
- changeMap.remove(key);
- else if( original == null )
- changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_ADDED));
- else if( original.equals(afterValue))
- // value was changed from x to y, then back to x. Therefore, no change
- changeMap.remove(key);
- else if( afterValue == null ) {
- // changed from x to y to null, so removed
- changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_REMOVED));
- } else {
- // changed from x to y to z, so changed
- changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_CHANGED));
- }
- } else {
- int kind;
- if( beforeValue == null ) kind = IArchiveNodeDelta.PROPERTY_ADDED;
- else if( afterValue == null ) kind = IArchiveNodeDelta.PROPERTY_REMOVED;
- else kind = IArchiveNodeDelta.PROPERTY_CHANGED;
- changeMap.put(key, new NodeDelta(beforeValue, afterValue, kind));
- }
- }
-
- /**
- * A child has changed. Save the change
- * @param node
- * @param changeType
- */
- protected void childChanges(IArchiveNode node, int changeType) {
- if( childChanges.containsKey(node)) {
- int lastChange = childChanges.get(node).intValue();
- if( lastChange == IArchiveNodeDelta.CHILD_ADDED && changeType ==
IArchiveNodeDelta.CHILD_REMOVED) {
- childChanges.remove(node);
- } else if( lastChange == IArchiveNodeDelta.CHILD_REMOVED && changeType ==
IArchiveNodeDelta.CHILD_ADDED) {
- childChanges.remove(node);
- }
- } else {
- childChanges.put(node, new Integer(changeType));
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getDelta()
- */
- public IArchiveNodeDelta getDelta() {
- return new ArchiveNodeDeltaImpl(null, this, (HashMap<String,
NodeDelta>)attributeChanges.clone(),
- (HashMap<String, NodeDelta>)propertyChanges.clone(), (HashMap<IArchiveNode,
Integer>)childChanges.clone());
- }
-
- /**
- * Forget all past state
- */
- public void clearDelta() {
- attributeChanges.clear();
- propertyChanges.clear();
- childChanges.clear();
-
- // clear children recursively
- IArchiveNode[] children = getAllChildren();
- for( int i = 0; i < children.length; i++ )
- ((ArchiveNodeImpl)children[i]).clearDelta();
- }
-}
+/*
+ * 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.model.internal;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+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.IArchiveModelRootNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor;
+import
org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeDeltaImpl.NodeDelta;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackageNode;
+import
org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackageNodeWithProperties;
+
+/**
+ * Abstract superclass implementation for archive node types
+ * @author rob.stryker <rob.stryker(a)redhat.com>
+ *
+ */
+public abstract class ArchiveNodeImpl implements IArchiveNode {
+
+ protected XbPackageNodeWithProperties nodeDelegate;
+ protected IArchiveNode parent;
+ protected ArrayList<ArchiveNodeImpl> children;
+
+ // cached data for deltas
+ protected HashMap<String, NodeDelta> attributeChanges;
+ protected HashMap<String, NodeDelta> propertyChanges;
+ protected HashMap<IArchiveNode, Integer> childChanges;
+
+
+ public ArchiveNodeImpl (XbPackageNodeWithProperties delegate) {
+ nodeDelegate = delegate;
+ children = new ArrayList<ArchiveNodeImpl>();
+
+ // for deltas
+ attributeChanges = new HashMap<String, NodeDelta>();
+ propertyChanges = new HashMap<String, NodeDelta>();
+ childChanges = new HashMap<IArchiveNode, Integer>();
+ }
+
+ public XbPackageNode getNodeDelegate() {
+ return nodeDelegate;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getRoot()
+ */
+ public IArchiveNode getRoot() {
+ return parent == null ? this : parent.getRoot();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getModel()
+ */
+ public IArchiveModelRootNode getModelRootNode() {
+ Object root = getRoot();
+ return root instanceof IArchiveModelRootNode ? (IArchiveModelRootNode)root : null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getRootArchive()
+ */
+ public IArchive getRootArchive() {
+ IArchiveNode parent = this.parent;
+ IArchive topArchives = null;
+
+ if( getNodeType() == IArchiveNode.TYPE_ARCHIVE ) topArchives = (IArchive)this;
+ while( parent != null ) {
+ if( parent.getNodeType() == IArchiveNode.TYPE_ARCHIVE )
+ topArchives = (IArchive)parent;
+ parent = parent.getParent();
+ }
+ return topArchives;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getAllChildren()
+ */
+ public IArchiveNode[] getAllChildren () {
+ return children.toArray(new IArchiveNode[children.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getChildren(int)
+ */
+ public IArchiveNode[] getChildren(int type) {
+ ArrayList<IArchiveNode> typedChildren = new ArrayList<IArchiveNode>();
+ for (Iterator<ArchiveNodeImpl> iter = children.iterator(); iter.hasNext(); ) {
+ IArchiveNode child = iter.next();
+ if (child.getNodeType() == type) {
+ typedChildren.add(child);
+ }
+ }
+
+ return typedChildren.toArray(new IArchiveNode[typedChildren.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#hasChildren()
+ */
+ public boolean hasChildren () {
+ return nodeDelegate.hasChildren();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#hasChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public boolean hasChild (IArchiveNode child) {
+ ArchiveNodeImpl childImpl = (ArchiveNodeImpl)child;
+ return nodeDelegate.getAllChildren().contains(childImpl.nodeDelegate);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getParent()
+ */
+ public IArchiveNode getParent() {
+ return parent;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#setParent(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public void setParent (IArchiveNode parent) {
+ if( getParent() != null && parent != getParent()) {
+ getParent().removeChild(this);
+ }
+
+ this.parent = parent;
+ nodeDelegate.setParent(parent == null ? null :
+ ((ArchiveNodeImpl)parent).getNodeDelegate());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getProject()
+ */
+ public IPath getProjectPath() {
+ IArchiveModelRootNode root = getModelRootNode();
+ return root == null ? null : root.getProjectPath();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getProperty(java.lang.String)
+ */
+ public String getProperty(String property) {
+ return getProperties().getProperty(property);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#setProperty(java.lang.String,
java.lang.String)
+ */
+ public void setProperty(String property, String value) {
+ if( property == null ) return;
+ propertyChanged(property, getProperty(property), value);
+ if( value == null ) {
+ getProperties().remove(property);
+ } else {
+ getProperties().setProperty(property, value);
+ }
+ }
+
+ /**
+ * @return Get the properties for this object
+ */
+ protected Properties getProperties() {
+ return nodeDelegate.getProperties().getProperties();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#accept(org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor)
+ */
+ public boolean accept(IArchiveNodeVisitor visitor) {
+ return accept(visitor, false);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#accept(org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor,
boolean)
+ */
+ public boolean accept(IArchiveNodeVisitor visitor, boolean depthFirst) {
+ IArchiveNode children[] = getAllChildren();
+ boolean keepGoing = true;
+
+ if (!depthFirst)
+ keepGoing = visitor.visit(this);
+
+ if (keepGoing) {
+ for (int i = 0; i < children.length; i++) {
+ if (keepGoing) {
+ keepGoing = children[i].accept(visitor, depthFirst);
+ }
+ }
+ }
+
+ if (depthFirst && keepGoing)
+ keepGoing = visitor.visit(this);
+
+ return keepGoing;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#addChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public final void addChild(IArchiveNode node) throws ArchivesModelException {
+ addChild(node, true);
+ }
+
+ /**
+ * Add a child with the option to skip adding in the delegate
+ * @param child
+ * @param addInDelegate
+ */
+ public final void addChild(IArchiveNode child, boolean addInDelegate) throws
ArchivesModelException {
+ Assert.isNotNull(child);
+ ArchiveNodeImpl childImpl = (ArchiveNodeImpl) child;
+ children.add(childImpl);
+ childImpl.setParent(this);
+ if( addInDelegate )
+ nodeDelegate.addChild(childImpl.nodeDelegate);
+ childChanges(child, IArchiveNodeDelta.CHILD_ADDED);
+ if( !validateModel()) {
+ removeChild(child);
+ throw new ArchivesModelException("Unable to add child node");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#validateModel()
+ */
+ public boolean validateModel() {
+ IArchiveNode[] kids = getAllChildren();
+ for( int i = 0; i < kids.length; i++ )
+ if( !kids[i].validateModel() )
+ return false;
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#canBuild()
+ */
+ public boolean canBuild() {
+ IArchiveNode[] kids = getAllChildren();
+ for( int i = 0; i < kids.length; i++ )
+ if( !kids[i].canBuild() )
+ return false;
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#removeChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
+ */
+ public void removeChild(IArchiveNode node) {
+ Assert.isNotNull(node);
+ ArchiveNodeImpl impl = (ArchiveNodeImpl) node;
+ boolean removed = false;
+ if (nodeDelegate.getAllChildren().contains(impl.nodeDelegate)) {
+ nodeDelegate.removeChild(impl.nodeDelegate);
+ removed = true;
+ }
+
+ if (children.contains(node)) {
+ children.remove(node);
+ removed = true;
+ }
+ if( removed )
+ childChanges(node, IArchiveNodeDelta.CHILD_REMOVED);
+ }
+
+ /**
+ * An attribute has changed. Save the change so it can be represented in a delta
+ */
+ protected void attributeChanged(String key, Object beforeValue, Object afterValue) {
+ int kind = IArchiveNodeDelta.ATTRIBUTE_CHANGED;
+ HashMap<String, NodeDelta> map = attributeChanges;
+
+ // short circuit if no change has REALLY occurred
+ if( beforeValue != null && beforeValue.equals(afterValue)) return;
+
+ if( map.containsKey(key)) {
+ Object original = map.get(key).getBefore();
+ if( original == null && afterValue == null )
+ map.remove(key);
+ else if( original == null )
+ map.put(key, new NodeDelta(original, afterValue, kind));
+ else if( original.equals(afterValue))
+ // value was changed from x to y, then back to x. Therefore, no change
+ map.remove(key);
+ else
+ // value was changed from x to y to z.
+ // Before should remain x, after should become z
+ map.put(key, new NodeDelta(original, afterValue, kind));
+ } else {
+ // added
+ map.put(key, new NodeDelta(beforeValue, afterValue, kind));
+ }
+ }
+
+ /**
+ * A property has changed. Save the change so it can be represented in a delta
+ */
+ protected void propertyChanged(String key, Object beforeValue, Object afterValue) {
+ HashMap<String, NodeDelta> changeMap = propertyChanges;
+ // short circuit if no change has REALLY occurred
+ if( beforeValue != null && beforeValue.equals(afterValue)) return;
+
+
+ if( changeMap.containsKey(key)) {
+ // element has already been added, removed, or changed since last save
+ Object original = changeMap.get(key).getBefore();
+ if( original == null && afterValue == null )
+ changeMap.remove(key);
+ else if( original == null )
+ changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_ADDED));
+ else if( original.equals(afterValue))
+ // value was changed from x to y, then back to x. Therefore, no change
+ changeMap.remove(key);
+ else if( afterValue == null ) {
+ // changed from x to y to null, so removed
+ changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_REMOVED));
+ } else {
+ // changed from x to y to z, so changed
+ changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_CHANGED));
+ }
+ } else {
+ int kind;
+ if( beforeValue == null ) kind = IArchiveNodeDelta.PROPERTY_ADDED;
+ else if( afterValue == null ) kind = IArchiveNodeDelta.PROPERTY_REMOVED;
+ else kind = IArchiveNodeDelta.PROPERTY_CHANGED;
+ changeMap.put(key, new NodeDelta(beforeValue, afterValue, kind));
+ }
+ }
+
+ /**
+ * A child has changed. Save the change
+ * @param node
+ * @param changeType
+ */
+ protected void childChanges(IArchiveNode node, int changeType) {
+ if( childChanges.containsKey(node)) {
+ int lastChange = childChanges.get(node).intValue();
+ if( lastChange == IArchiveNodeDelta.CHILD_ADDED && changeType ==
IArchiveNodeDelta.CHILD_REMOVED) {
+ childChanges.remove(node);
+ } else if( lastChange == IArchiveNodeDelta.CHILD_REMOVED && changeType ==
IArchiveNodeDelta.CHILD_ADDED) {
+ childChanges.remove(node);
+ }
+ } else {
+ childChanges.put(node, new Integer(changeType));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getDelta()
+ */
+ public IArchiveNodeDelta getDelta() {
+ return new ArchiveNodeDeltaImpl(null, this, (HashMap<String,
NodeDelta>)attributeChanges.clone(),
+ (HashMap<String, NodeDelta>)propertyChanges.clone(), (HashMap<IArchiveNode,
Integer>)childChanges.clone());
+ }
+
+ /**
+ * Forget all past state
+ */
+ public void clearDelta() {
+ attributeChanges.clear();
+ propertyChanges.clear();
+ childChanges.clear();
+
+ // clear children recursively
+ IArchiveNode[] children = getAllChildren();
+ for( int i = 0; i < children.length; i++ )
+ ((ArchiveNodeImpl)children[i]).clearDelta();
+ }
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/internal/ModelTruezipBridge.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/internal/ModelTruezipBridge.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/internal/ModelTruezipBridge.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,264 +1,267 @@
-/**
- * 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);
- File parentFile;
- if(new Path(filesetRelative).segmentCount() > 1 ) {
- String tmp = new Path(filesetRelative).removeLastSegments(1).toString();
- parentFile = new File(fsFile, tmp, ArchiveDetector.NULL);
- if( parentFile.getEnclArchive() != null )
- parentFile = new File(fsFile, tmp, ArchiveDetector.DEFAULT);
- } else {
- parentFile = fsFile;
- }
- 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 ) {
- // we're a root archive, and so the destination folder must be a real folder
- IPath p = node2.getGlobalDestinationPath();
- if( p == null ) return null;
- parentFile = new File(p.toOSString(), ArchiveDetector.NULL);
- }
- 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);
+ if( fsFile == null )
+ return new File[]{};
+
+ 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);
+ File parentFile;
+ if(new Path(filesetRelative).segmentCount() > 1 ) {
+ String tmp = new Path(filesetRelative).removeLastSegments(1).toString();
+ parentFile = new File(fsFile, tmp, ArchiveDetector.NULL);
+ if( parentFile.getEnclArchive() != null )
+ parentFile = new File(fsFile, tmp, ArchiveDetector.DEFAULT);
+ } else {
+ parentFile = fsFile;
+ }
+ 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 ) {
+ // we're a root archive, and so the destination folder must be a real folder
+ IPath p = node2.getGlobalDestinationPath();
+ if( p == null ) return null;
+ parentFile = new File(p.toOSString(), ArchiveDetector.NULL);
+ }
+ 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:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/util/composites/ArchiveNodeDestinationComposite.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/util/composites/ArchiveNodeDestinationComposite.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/util/composites/ArchiveNodeDestinationComposite.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,157 +1,156 @@
-package org.jboss.ide.eclipse.archives.ui.util.composites;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
-import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
-import org.jboss.ide.eclipse.archives.ui.util.DestinationChangeListener;
-
-public abstract class ArchiveNodeDestinationComposite extends Composite {
-
- protected Composite parent;
- protected Label destinationImage;
- protected Text destinationText;
- protected Object nodeDestination;
- protected ArrayList<DestinationChangeListener> listeners;
-
- public ArchiveNodeDestinationComposite(Composite parent, int style, Object destination)
{
- super(parent, style);
- this.parent = parent;
- this.nodeDestination = destination;
- this.listeners = new ArrayList<DestinationChangeListener>();
-
- createComposite();
- }
-
- protected void createComposite() {
- setLayout(new FormLayout());
-
- // create widgets
- destinationImage = new Label(this, SWT.NONE);
- destinationText = new Text(this, SWT.BORDER);
- Composite browseComposite = new Composite(this, SWT.NONE);
-
- // set up their layout positioning
- destinationImage.setLayoutData(createFormData(0,5,null, 0, 0, 0, null, 0));
- destinationText.setLayoutData(createFormData(0, 5, null, 0, destinationImage, 5,
destinationImage, 205));
-
-
- // set text, add listeners, etc
- destinationText.setEditable(false);
-
- browseComposite.setLayout(new FillLayout());
- browseComposite.setLayoutData(createFormData(0,0,null,0,destinationText,5,100,-5));
- fillBrowseComposite(browseComposite);
-
- // call other functions required for startup
- updateDestinationViewer();
- }
-
- protected abstract void fillBrowseComposite(Composite browseComposite);
-
- private FormData createFormData(Object topStart, int topOffset, Object bottomStart, int
bottomOffset,
- Object leftStart, int leftOffset, Object rightStart, int rightOffset) {
- FormData data = new FormData();
-
- if( topStart != null ) {
- data.top = topStart instanceof Control ? new FormAttachment((Control)topStart,
topOffset) :
- new FormAttachment(((Integer)topStart).intValue(), topOffset);
- }
-
- if( bottomStart != null ) {
- data.bottom = bottomStart instanceof Control ? new
FormAttachment((Control)bottomStart, bottomOffset) :
- new FormAttachment(((Integer)bottomStart).intValue(), bottomOffset);
- }
-
- if( leftStart != null ) {
- data.left = leftStart instanceof Control ? new FormAttachment((Control)leftStart,
leftOffset) :
- new FormAttachment(((Integer)leftStart).intValue(), leftOffset);
- }
-
- if( rightStart != null ) {
- data.right = rightStart instanceof Control ? new FormAttachment((Control)rightStart,
rightOffset) :
- new FormAttachment(((Integer)rightStart).intValue(), rightOffset);
- }
-
- return data;
- }
-
- public void setPackageNodeDestination (Object destination) {
- System.out.println("setting destination to " + destination);
- nodeDestination = destination;
- updateDestinationViewer();
- fireDestinationChanged();
- }
-
- protected void updateDestinationViewer () {
- if (nodeDestination == null) return;
- destinationText.setText("");
-
- if (nodeDestination instanceof IArchive) {
- IArchive pkg = (IArchive) nodeDestination;
- String txt = pkg.isTopLevel() ? pkg.getName() :
pkg.getRootArchiveRelativePath().toOSString();
- String imgKey = pkg.isExploded() ? ArchivesSharedImages.IMG_PACKAGE_EXPLODED :
ArchivesSharedImages.IMG_PACKAGE;
-
- destinationText.setText(txt);
- destinationImage.setImage(ArchivesSharedImages.getImage(imgKey));
- } else if (nodeDestination instanceof IArchiveFolder) {
- IArchiveFolder folder = (IArchiveFolder) nodeDestination;
- destinationText.setText(folder.getRootArchiveRelativePath().toString());
- destinationImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
- } else if (nodeDestination instanceof IProject) {
- IProject project = (IProject) nodeDestination;
- destinationText.setText(project.getName());
- destinationImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT));
- } else if (nodeDestination instanceof IFolder) {
- IFolder folder = (IFolder) nodeDestination;
- destinationText.setText("/" + folder.getProject().getName() + "/"
+ folder.getProjectRelativePath().toString());
- destinationImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
- }
- }
-
-
- /**
- * The current destination
- * @return
- */
-
- public Object getPackageNodeDestination () {
- return nodeDestination;
- }
-
-
- /*
- * Destination change listeners
- */
-
- public void addDestinationChangeListener (DestinationChangeListener listener) {
- listeners.add(listener);
- }
-
- public void removeDestinationChangeListener (DestinationChangeListener listener) {
- listeners.remove(listener);
- }
-
- private void fireDestinationChanged () {
- for (Iterator<DestinationChangeListener> iter = listeners.iterator();
iter.hasNext(); ) {
- ((DestinationChangeListener) iter.next()).destinationChanged(nodeDestination);
- }
- }
-}
+package org.jboss.ide.eclipse.archives.ui.util.composites;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
+import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
+import org.jboss.ide.eclipse.archives.ui.util.DestinationChangeListener;
+
+public abstract class ArchiveNodeDestinationComposite extends Composite {
+
+ protected Composite parent;
+ protected Label destinationImage;
+ protected Text destinationText;
+ protected Object nodeDestination;
+ protected ArrayList<DestinationChangeListener> listeners;
+
+ public ArchiveNodeDestinationComposite(Composite parent, int style, Object destination)
{
+ super(parent, style);
+ this.parent = parent;
+ this.nodeDestination = destination;
+ this.listeners = new ArrayList<DestinationChangeListener>();
+
+ createComposite();
+ }
+
+ protected void createComposite() {
+ setLayout(new FormLayout());
+
+ // create widgets
+ destinationImage = new Label(this, SWT.NONE);
+ destinationText = new Text(this, SWT.BORDER);
+ Composite browseComposite = new Composite(this, SWT.NONE);
+
+ // set up their layout positioning
+ destinationImage.setLayoutData(createFormData(0,5,null, 0, 0, 0, null, 0));
+ destinationText.setLayoutData(createFormData(0, 5, null, 0, destinationImage, 5,
destinationImage, 205));
+
+
+ // set text, add listeners, etc
+ destinationText.setEditable(false);
+
+ browseComposite.setLayout(new FillLayout());
+ browseComposite.setLayoutData(createFormData(0,0,null,0,destinationText,5,100,-5));
+ fillBrowseComposite(browseComposite);
+
+ // call other functions required for startup
+ updateDestinationViewer();
+ }
+
+ protected abstract void fillBrowseComposite(Composite browseComposite);
+
+ private FormData createFormData(Object topStart, int topOffset, Object bottomStart, int
bottomOffset,
+ Object leftStart, int leftOffset, Object rightStart, int rightOffset) {
+ FormData data = new FormData();
+
+ if( topStart != null ) {
+ data.top = topStart instanceof Control ? new FormAttachment((Control)topStart,
topOffset) :
+ new FormAttachment(((Integer)topStart).intValue(), topOffset);
+ }
+
+ if( bottomStart != null ) {
+ data.bottom = bottomStart instanceof Control ? new
FormAttachment((Control)bottomStart, bottomOffset) :
+ new FormAttachment(((Integer)bottomStart).intValue(), bottomOffset);
+ }
+
+ if( leftStart != null ) {
+ data.left = leftStart instanceof Control ? new FormAttachment((Control)leftStart,
leftOffset) :
+ new FormAttachment(((Integer)leftStart).intValue(), leftOffset);
+ }
+
+ if( rightStart != null ) {
+ data.right = rightStart instanceof Control ? new FormAttachment((Control)rightStart,
rightOffset) :
+ new FormAttachment(((Integer)rightStart).intValue(), rightOffset);
+ }
+
+ return data;
+ }
+
+ public void setPackageNodeDestination (Object destination) {
+ nodeDestination = destination;
+ updateDestinationViewer();
+ fireDestinationChanged();
+ }
+
+ protected void updateDestinationViewer () {
+ if (nodeDestination == null) return;
+ destinationText.setText("");
+
+ if (nodeDestination instanceof IArchive) {
+ IArchive pkg = (IArchive) nodeDestination;
+ String txt = pkg.isTopLevel() ? pkg.getName() :
pkg.getRootArchiveRelativePath().toOSString();
+ String imgKey = pkg.isExploded() ? ArchivesSharedImages.IMG_PACKAGE_EXPLODED :
ArchivesSharedImages.IMG_PACKAGE;
+
+ destinationText.setText(txt);
+ destinationImage.setImage(ArchivesSharedImages.getImage(imgKey));
+ } else if (nodeDestination instanceof IArchiveFolder) {
+ IArchiveFolder folder = (IArchiveFolder) nodeDestination;
+ destinationText.setText(folder.getRootArchiveRelativePath().toString());
+ destinationImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
+ } else if (nodeDestination instanceof IProject) {
+ IProject project = (IProject) nodeDestination;
+ destinationText.setText(project.getName());
+ destinationImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT));
+ } else if (nodeDestination instanceof IFolder) {
+ IFolder folder = (IFolder) nodeDestination;
+ destinationText.setText("/" + folder.getProject().getName() + "/"
+ folder.getProjectRelativePath().toString());
+ destinationImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
+ }
+ }
+
+
+ /**
+ * The current destination
+ * @return
+ */
+
+ public Object getPackageNodeDestination () {
+ return nodeDestination;
+ }
+
+
+ /*
+ * Destination change listeners
+ */
+
+ public void addDestinationChangeListener (DestinationChangeListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeDestinationChangeListener (DestinationChangeListener listener) {
+ listeners.remove(listener);
+ }
+
+ private void fireDestinationChanged () {
+ for (Iterator<DestinationChangeListener> iter = listeners.iterator();
iter.hasNext(); ) {
+ ((DestinationChangeListener) iter.next()).destinationChanged(nodeDestination);
+ }
+ }
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ProjectArchivesView.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ProjectArchivesView.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/views/ProjectArchivesView.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,373 +1,382 @@
-package org.jboss.ide.eclipse.archives.ui.views;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.wizard.ProgressMonitorPart;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
-import org.eclipse.ui.INullSelectionListener;
-import org.eclipse.ui.ISelectionListener;
-import org.eclipse.ui.IViewSite;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.PageBook;
-import org.eclipse.ui.part.ViewPart;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModelCore;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveModelListener;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
-import org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages;
-import org.jboss.ide.eclipse.archives.ui.ExtensionManager;
-import org.jboss.ide.eclipse.archives.ui.PackagesUIPlugin;
-import org.jboss.ide.eclipse.archives.ui.PrefsInitializer;
-import org.jboss.ide.eclipse.archives.ui.actions.NewArchiveAction;
-import org.jboss.ide.eclipse.archives.ui.providers.ArchivesContentProvider;
-import org.jboss.ide.eclipse.archives.ui.providers.ArchivesLabelProvider;
-
-public class ProjectArchivesView extends ViewPart implements IArchiveModelListener {
-
- protected static ProjectArchivesView instance;
- public static ProjectArchivesView getInstance() {
- return instance;
- }
-
-
- protected ISelectionListener selectionListener;
- public ProjectArchivesView() {
- instance = this;
- selectionListener = createSelectionListener();
- }
-
- public void init(IViewSite site) throws PartInitException {
- super.init(site);
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener);
- ArchivesModel.instance().addModelListener(this);
- }
-
- public void dispose() {
- super.dispose();
-
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener);
- ArchivesModel.instance().removeModelListener(this);
- }
-
-
- protected ISelectionListener createSelectionListener() {
- return new INullSelectionListener() {
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- if (!(selection instanceof IStructuredSelection))
- return;
-
- Object element = ((IStructuredSelection)selection).getFirstElement();
- IProject project = getProject(element);
- if( project != null ) {
- viewSelectionChanged(project);
- } else {
- if( getCurrentProject() != null && !getCurrentProject().exists() ) {
- viewSelectionChanged(null);
- }
- }
- }
-
- public IProject getProject (Object element) {
- if( element instanceof IStructuredSelection)
- element = ((IStructuredSelection)element).getFirstElement();
-
- if (element instanceof IAdaptable) {
- IAdaptable adaptable = (IAdaptable)element;
- IResource resource = (IResource) adaptable.getAdapter(IResource.class);
- if( resource != null )
- return resource.getProject();
- }
- return null;
- }
-
- };
- }
-
-
- // parts
- private PageBook book;
- private IProject project;
- private ArchivesContentProvider contentProvider = new ArchivesContentProvider();
- private ArchivesLabelProvider labelProvider = new ArchivesLabelProvider();
- private Composite emptyComposite, viewerComposite, loadingPackagesComposite,
noSelectionComposite;
- private IProgressMonitor loadingProgress;
- private TreeViewer packageViewer;
- private ArchivesMenuHandler menuHandler;
- public void createPartControl(Composite parent) {
- book = new PageBook(parent, SWT.NONE);
- addEmptyComposite(book);
- addLoadingComposite(book);
- addViewerComposite(book);
- addNoSelectionComposite(book);
- book.showPage(noSelectionComposite);
- menuHandler = new ArchivesMenuHandler(packageViewer);
- }
-
- protected void addNoSelectionComposite(PageBook book) {
- noSelectionComposite = new Composite(book, SWT.NONE);
- noSelectionComposite.setLayout(new FillLayout());
- Label label = new Label(noSelectionComposite, SWT.NONE);
- label.setText(ArchivesUIMessages.ProjectPackagesView_noProjectSelectedMessage);
- }
- protected void addEmptyComposite(PageBook book) {
- emptyComposite = new Composite(book, SWT.NONE);
- emptyComposite.setLayout(new FormLayout());
- Label l = new Label(emptyComposite, SWT.NONE);
- l.setText(ArchivesUIMessages.ProjectPackagesView_createPackagesMessage);
-
- Composite actionsComposite = new Composite(emptyComposite, SWT.NONE);
-
-
- FormData lData = new FormData();
- lData.left = new FormAttachment(0,5);
- lData.top = new FormAttachment(0,5);
- l.setLayoutData(lData);
-
- FormData actionsData = new FormData();
- actionsData.left = new FormAttachment(0,5);
- actionsData.top = new FormAttachment(l,5);
- actionsData.bottom = new FormAttachment(100,-5);
-
- actionsComposite.setLayoutData(actionsData);
-
- actionsComposite.setLayout(new GridLayout(1, false));
- addNewPackageActions(actionsComposite);
-
- }
-
-
- private void addNewPackageActions (Composite composite) {
- NewArchiveAction[] actions = ExtensionManager.findNewArchiveActions();
- for (int i = 0; i < actions.length; i++) {
- final NewArchiveAction action = actions[i];
-
- Composite linkComposite = new Composite(composite, SWT.NONE);
- linkComposite.setLayout(createGridLayoutWithNoMargins(2));
- linkComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- new Label(linkComposite, SWT.NONE).setImage(action.getIcon());
-
- Link actionLink = new Link(linkComposite, SWT.NONE);
- actionLink.setText("<a href=\"create\">" + action.getLabel()
+ "</a>");
- actionLink.addSelectionListener(new SelectionListener () {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
-
- public void widgetSelected(SelectionEvent e) {
- action.getAction().run(null);
- }
- });
- }
- }
-
- private GridLayout createGridLayoutWithNoMargins (int columns) {
- GridLayout layout = new GridLayout(columns, false);
- layout.marginBottom = layout.marginHeight = layout.marginLeft = 0;
- layout.marginRight = layout.marginTop = layout.marginWidth = 0;
-
- return layout;
- }
-
- protected void addLoadingComposite(PageBook book) {
- loadingPackagesComposite = new Composite(book, SWT.NONE);
- loadingPackagesComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
- loadingProgress = new ProgressMonitorPart(loadingPackagesComposite, null);
-
- }
- protected void addViewerComposite(PageBook book) {
- viewerComposite = new Composite(book, SWT.NONE);
- viewerComposite.setLayout(new FillLayout());
- packageViewer = new TreeViewer(viewerComposite, SWT.NONE);
- packageViewer.setContentProvider(contentProvider);
- packageViewer.setLabelProvider(labelProvider);
- }
-
-
- public void setFocus() {
- }
- public void viewSelectionChanged(IProject project) {
- if( project == null ) {
- this.project = null;
- packageViewer.setInput(null);
- book.showPage(noSelectionComposite);
- return;
- }
-
- IArchiveModelRootNode node = (IArchiveModelRootNode) packageViewer.getInput();
- if (node != null)
- {
- IPath projectPath = node.getProjectPath();
-
- if( project.getLocation().equals(projectPath))
- return;
- }
-
- if( !project.isAccessible() ) {
- book.showPage(noSelectionComposite);
- } else if( ArchivesModelCore.packageFileExists(project.getLocation()) ) {
- if( ArchivesModelCore.projectRegistered(project.getLocation()))
- book.showPage(viewerComposite);
- else {
- this.project = project;
- book.showPage(loadingPackagesComposite);
- if( PrefsInitializer.getBoolean(PrefsInitializer.PREF_SHOW_ALL_PROJECTS, project,
true)) {
- registerProjects(getAllProjectsWithPackages(), this.project);
- } else {
- registerProjects(new IProject[] {this.project}, this.project);
- }
- return;
- }
- } else {
- book.showPage(emptyComposite);
- }
-
- this.project = project;
- packageViewer.setInput(ArchivesModel.instance().getRoot(project.getLocation()));
- }
-
- public IProject getCurrentProject() {
- return project;
- }
-
- /**
- * Registers the projects if and only if a file exists already
- * @param projects
- * @param projectToShow
- */
- protected void registerProjects(final IProject[] projects, final IProject projectToShow)
{
- for( int i = 0; i < projects.length; i++ ) {
- try {
- ArchivesModel.instance().registerProject(projects[i].getLocation(),
loadingProgress);
- } catch( ArchivesModelException ame ) {
- IStatus status = new Status(IStatus.ERROR, PackagesUIPlugin.PLUGIN_ID,
ame.getMessage(), ame);
- PackagesUIPlugin.getDefault().getLog().log(status);
- }
- }
- getSite().getShell().getDisplay().asyncExec(new Runnable () {
- public void run () {
- book.showPage(viewerComposite);
- packageViewer.setInput(ArchivesModel.instance().getRoot(projectToShow.getLocation()));
- }
- });
- }
-
- public IProject[] getAllProjectsWithPackages() {
- IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- ArrayList list = new ArrayList();
- for( int i = 0; i < projects2.length; i++ ) {
- if( projects2[i].isAccessible() &&
ArchivesModelCore.packageFileExists(projects2[i].getLocation())) {
- list.add(projects2[i]);
- }
- }
- return (IProject[]) list.toArray(new IProject[list.size()]);
- }
- public IStructuredSelection getSelection() {
- return (IStructuredSelection)packageViewer.getSelection();
- }
-
-
- public void modelChanged(IArchiveNodeDelta delta) {
- boolean update = true;
- try {
- if( project == null ) return;
- if( delta.getPostNode() == null && delta.getPreNode() == null ) return;
- if( delta.getPreNode() == null ) update =
delta.getPostNode().getProjectPath().equals(project.getLocation());
- else if( delta.getPostNode() == null ) update =
delta.getPreNode().getProjectPath().equals(project.getLocation());
- else update = delta.getPreNode().getProjectPath().equals(project.getLocation()) ||
delta.getPostNode().getProjectPath().equals(project);
- } catch( Exception e ) {}
-
- if( !update ) return;
-
- final IArchiveNode[] topChanges;
- if( delta.getKind() == IArchiveNodeDelta.DESCENDENT_CHANGED)
- topChanges = getChanges(delta);
- else if( delta.getKind() == IArchiveNodeDelta.NO_CHANGE)
- topChanges = new IArchiveNode[]{};
- else
- topChanges = new IArchiveNode[]{delta.getPostNode()};
-
- // now go through and refresh them
- getSite().getShell().getDisplay().asyncExec(new Runnable () {
- public void run () {
- for( int i = 0; i < topChanges.length; i++ ) {
- if( topChanges.length == 1 && topChanges[0] instanceof
IArchiveModelRootNode) {
- // we have a changed IArchiveModelNode. Something's different
- IArchiveModelRootNode inputModel = (IArchiveModelRootNode)
packageViewer.getInput();
- IArchiveModelRootNode newModel = (IArchiveModelRootNode)topChanges[0];
- if( inputModel == null ||
(inputModel.getProjectPath().equals(newModel.getProjectPath()) && inputModel !=
newModel)) {
- // they have the same path but are different objects.
- // Model was probably reloaded from disk and could be completely different
- book.showPage(viewerComposite);
- packageViewer.setInput(newModel);
- packageViewer.expandAll();
- return;
- } else {
- packageViewer.refresh();
- return;
- }
- } else {
- // just refresh whatever is the top changed element (archive probably)
- packageViewer.refresh(topChanges[i]);
- packageViewer.expandToLevel(topChanges[i], 1);
- }
- }
- }
- });
-
- }
- protected IArchiveNode[] getChanges(IArchiveNodeDelta delta) {
-
- IArchiveNodeDelta[] children = delta.getAllAffectedChildren();
- ArrayList list = new ArrayList();
- for( int i = 0; i < children.length; i++ ) {
- if( children[i].getKind() == IArchiveNodeDelta.DESCENDENT_CHANGED)
- list.addAll(Arrays.asList(getChanges(children[i])));
- else
- list.add(children[i].getPostNode());
- }
- return (IArchiveNode[]) list.toArray(new IArchiveNode[list.size()]);
- }
-
- public void refreshViewer(final Object node) {
- getSite().getShell().getDisplay().asyncExec(new Runnable () {
- public void run () {
- if( node == null ) {
- Object[] els = packageViewer.getExpandedElements();
- packageViewer.refresh();
- packageViewer.setExpandedElements(els);
- } else {
- packageViewer.refresh(node);
- }
- }
- });
- }
-}
+package org.jboss.ide.eclipse.archives.ui.views;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.wizard.ProgressMonitorPart;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.ui.INullSelectionListener;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.ViewPart;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelCore;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveModelListener;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
+import org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages;
+import org.jboss.ide.eclipse.archives.ui.ExtensionManager;
+import org.jboss.ide.eclipse.archives.ui.PackagesUIPlugin;
+import org.jboss.ide.eclipse.archives.ui.PrefsInitializer;
+import org.jboss.ide.eclipse.archives.ui.actions.NewArchiveAction;
+import org.jboss.ide.eclipse.archives.ui.providers.ArchivesContentProvider;
+import org.jboss.ide.eclipse.archives.ui.providers.ArchivesLabelProvider;
+
+public class ProjectArchivesView extends ViewPart implements IArchiveModelListener {
+
+ protected static ProjectArchivesView instance;
+ public static ProjectArchivesView getInstance() {
+ return instance;
+ }
+
+
+ protected ISelectionListener selectionListener;
+ public ProjectArchivesView() {
+ instance = this;
+ selectionListener = createSelectionListener();
+ }
+
+ public void init(IViewSite site) throws PartInitException {
+ super.init(site);
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener);
+ ArchivesModel.instance().addModelListener(this);
+ }
+
+ public void dispose() {
+ super.dispose();
+
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener);
+ ArchivesModel.instance().removeModelListener(this);
+ }
+
+
+ protected ISelectionListener createSelectionListener() {
+ return new INullSelectionListener() {
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if (!(selection instanceof IStructuredSelection))
+ return;
+
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+ IProject project = getProject(element);
+ if( project != null ) {
+ viewSelectionChanged(project);
+ } else {
+ if( getCurrentProject() != null && !getCurrentProject().exists() ) {
+ viewSelectionChanged(null);
+ }
+ }
+ }
+
+ public IProject getProject (Object element) {
+ if( element instanceof IStructuredSelection)
+ element = ((IStructuredSelection)element).getFirstElement();
+
+ if (element instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable)element;
+ IResource resource = (IResource) adaptable.getAdapter(IResource.class);
+ if( resource != null )
+ return resource.getProject();
+ }
+ return null;
+ }
+
+ };
+ }
+
+
+ // parts
+ private PageBook book;
+ private IProject project;
+ private ArchivesContentProvider contentProvider = new ArchivesContentProvider();
+ private ArchivesLabelProvider labelProvider = new ArchivesLabelProvider();
+ private Composite emptyComposite, viewerComposite, loadingPackagesComposite,
noSelectionComposite;
+ private IProgressMonitor loadingProgress;
+ private TreeViewer packageViewer;
+ private ArchivesMenuHandler menuHandler;
+ public void createPartControl(Composite parent) {
+ book = new PageBook(parent, SWT.NONE);
+ addEmptyComposite(book);
+ addLoadingComposite(book);
+ addViewerComposite(book);
+ addNoSelectionComposite(book);
+ book.showPage(noSelectionComposite);
+ menuHandler = new ArchivesMenuHandler(packageViewer);
+ }
+
+ protected void addNoSelectionComposite(PageBook book) {
+ noSelectionComposite = new Composite(book, SWT.NONE);
+ noSelectionComposite.setLayout(new FillLayout());
+ Label label = new Label(noSelectionComposite, SWT.NONE);
+ label.setText(ArchivesUIMessages.ProjectPackagesView_noProjectSelectedMessage);
+ }
+ protected void addEmptyComposite(PageBook book) {
+ emptyComposite = new Composite(book, SWT.NONE);
+ emptyComposite.setLayout(new FormLayout());
+ Label l = new Label(emptyComposite, SWT.NONE);
+ l.setText(ArchivesUIMessages.ProjectPackagesView_createPackagesMessage);
+
+ Composite actionsComposite = new Composite(emptyComposite, SWT.NONE);
+
+
+ FormData lData = new FormData();
+ lData.left = new FormAttachment(0,5);
+ lData.top = new FormAttachment(0,5);
+ l.setLayoutData(lData);
+
+ FormData actionsData = new FormData();
+ actionsData.left = new FormAttachment(0,5);
+ actionsData.top = new FormAttachment(l,5);
+ actionsData.bottom = new FormAttachment(100,-5);
+
+ actionsComposite.setLayoutData(actionsData);
+
+ actionsComposite.setLayout(new GridLayout(1, false));
+ addNewPackageActions(actionsComposite);
+
+ }
+
+
+ private void addNewPackageActions (Composite composite) {
+ NewArchiveAction[] actions = ExtensionManager.findNewArchiveActions();
+ for (int i = 0; i < actions.length; i++) {
+ final NewArchiveAction action = actions[i];
+
+ Composite linkComposite = new Composite(composite, SWT.NONE);
+ linkComposite.setLayout(createGridLayoutWithNoMargins(2));
+ linkComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ new Label(linkComposite, SWT.NONE).setImage(action.getIcon());
+
+ Link actionLink = new Link(linkComposite, SWT.NONE);
+ actionLink.setText("<a href=\"create\">" + action.getLabel()
+ "</a>");
+ actionLink.addSelectionListener(new SelectionListener () {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ action.getAction().run(null);
+ }
+ });
+ }
+ }
+
+ private GridLayout createGridLayoutWithNoMargins (int columns) {
+ GridLayout layout = new GridLayout(columns, false);
+ layout.marginBottom = layout.marginHeight = layout.marginLeft = 0;
+ layout.marginRight = layout.marginTop = layout.marginWidth = 0;
+
+ return layout;
+ }
+
+ protected void addLoadingComposite(PageBook book) {
+ loadingPackagesComposite = new Composite(book, SWT.NONE);
+ loadingPackagesComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
+ loadingProgress = new ProgressMonitorPart(loadingPackagesComposite, null);
+
+ }
+ protected void addViewerComposite(PageBook book) {
+ viewerComposite = new Composite(book, SWT.NONE);
+ viewerComposite.setLayout(new FillLayout());
+ packageViewer = new TreeViewer(viewerComposite, SWT.NONE);
+ packageViewer.setContentProvider(contentProvider);
+ packageViewer.setLabelProvider(labelProvider);
+ }
+
+
+ public void setFocus() {
+ }
+ public void viewSelectionChanged(IProject project) {
+ if( project == null ) {
+ this.project = null;
+ packageViewer.setInput(null);
+ book.showPage(noSelectionComposite);
+ return;
+ }
+
+ IArchiveModelRootNode node = (IArchiveModelRootNode) packageViewer.getInput();
+ if (node != null)
+ {
+ IPath projectPath = node.getProjectPath();
+
+ if( project.getLocation().equals(projectPath))
+ return;
+ }
+
+ if( !project.isAccessible() ) {
+ book.showPage(noSelectionComposite);
+ } else if( ArchivesModelCore.packageFileExists(project.getLocation()) ) {
+ if( ArchivesModelCore.projectRegistered(project.getLocation()))
+ book.showPage(viewerComposite);
+ else {
+ this.project = project;
+ book.showPage(loadingPackagesComposite);
+ if( PrefsInitializer.getBoolean(PrefsInitializer.PREF_SHOW_ALL_PROJECTS, project,
true)) {
+ registerProjects(getAllProjectsWithPackages(), this.project);
+ } else {
+ registerProjects(new IProject[] {this.project}, this.project);
+ }
+ return;
+ }
+ } else {
+ book.showPage(emptyComposite);
+ }
+
+ this.project = project;
+ packageViewer.setInput(ArchivesModel.instance().getRoot(project.getLocation()));
+ }
+
+ public IProject getCurrentProject() {
+ return project;
+ }
+
+ /**
+ * Registers the projects if and only if a file exists already
+ * @param projects
+ * @param projectToShow
+ */
+ protected void registerProjects(final IProject[] projects, final IProject projectToShow)
{
+ new Job("Register Project Archives") {
+ protected IStatus run(IProgressMonitor monitor) {
+ // register the projects
+ for( int i = 0; i < projects.length; i++ ) {
+ try {
+ ArchivesModel.instance().registerProject(projects[i].getLocation(),
loadingProgress);
+ } catch( ArchivesModelException ame ) {
+ IStatus status = new Status(IStatus.ERROR, PackagesUIPlugin.PLUGIN_ID,
ame.getMessage(), ame);
+ return status;
+ }
+ }
+
+ // then refresh the view (if no errors)
+ getSite().getShell().getDisplay().asyncExec(new Runnable () {
+ public void run () {
+ book.showPage(viewerComposite);
+ packageViewer.setInput(ArchivesModel.instance().getRoot(projectToShow.getLocation()));
+ }
+ });
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
+
+ public IProject[] getAllProjectsWithPackages() {
+ IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ ArrayList<IProject> list = new ArrayList<IProject>();
+ for( int i = 0; i < projects2.length; i++ ) {
+ if( projects2[i].isAccessible() &&
ArchivesModelCore.packageFileExists(projects2[i].getLocation())) {
+ list.add(projects2[i]);
+ }
+ }
+ return list.toArray(new IProject[list.size()]);
+ }
+ public IStructuredSelection getSelection() {
+ return (IStructuredSelection)packageViewer.getSelection();
+ }
+
+
+ public void modelChanged(IArchiveNodeDelta delta) {
+ boolean update = true;
+ try {
+ if( project == null ) return;
+ if( delta.getPostNode() == null && delta.getPreNode() == null ) return;
+ if( delta.getPreNode() == null ) update =
delta.getPostNode().getProjectPath().equals(project.getLocation());
+ else if( delta.getPostNode() == null ) update =
delta.getPreNode().getProjectPath().equals(project.getLocation());
+ else update = delta.getPreNode().getProjectPath().equals(project.getLocation()) ||
delta.getPostNode().getProjectPath().equals(project);
+ } catch( Exception e ) {}
+
+ if( !update ) return;
+
+ final IArchiveNode[] topChanges;
+ if( delta.getKind() == IArchiveNodeDelta.DESCENDENT_CHANGED)
+ topChanges = getChanges(delta);
+ else if( delta.getKind() == IArchiveNodeDelta.NO_CHANGE)
+ topChanges = new IArchiveNode[]{};
+ else
+ topChanges = new IArchiveNode[]{delta.getPostNode()};
+
+ // now go through and refresh them
+ getSite().getShell().getDisplay().asyncExec(new Runnable () {
+ public void run () {
+ for( int i = 0; i < topChanges.length; i++ ) {
+ if( topChanges.length == 1 && topChanges[0] instanceof
IArchiveModelRootNode) {
+ // we have a changed IArchiveModelNode. Something's different
+ IArchiveModelRootNode inputModel = (IArchiveModelRootNode)
packageViewer.getInput();
+ IArchiveModelRootNode newModel = (IArchiveModelRootNode)topChanges[0];
+ if( inputModel == null ||
(inputModel.getProjectPath().equals(newModel.getProjectPath()) && inputModel !=
newModel)) {
+ // they have the same path but are different objects.
+ // Model was probably reloaded from disk and could be completely different
+ book.showPage(viewerComposite);
+ packageViewer.setInput(newModel);
+ packageViewer.expandAll();
+ return;
+ } else {
+ packageViewer.refresh();
+ return;
+ }
+ } else {
+ // just refresh whatever is the top changed element (archive probably)
+ packageViewer.refresh(topChanges[i]);
+ packageViewer.expandToLevel(topChanges[i], 1);
+ }
+ }
+ }
+ });
+
+ }
+ protected IArchiveNode[] getChanges(IArchiveNodeDelta delta) {
+
+ IArchiveNodeDelta[] children = delta.getAllAffectedChildren();
+ ArrayList<IArchiveNode> list = new ArrayList<IArchiveNode>();
+ for( int i = 0; i < children.length; i++ ) {
+ if( children[i].getKind() == IArchiveNodeDelta.DESCENDENT_CHANGED)
+ list.addAll(Arrays.asList(getChanges(children[i])));
+ else
+ list.add(children[i].getPostNode());
+ }
+ return list.toArray(new IArchiveNode[list.size()]);
+ }
+
+ public void refreshViewer(final Object node) {
+ getSite().getShell().getDisplay().asyncExec(new Runnable () {
+ public void run () {
+ if( node == null ) {
+ Object[] els = packageViewer.getExpandedElements();
+ packageViewer.refresh();
+ packageViewer.setExpandedElements(els);
+ } else {
+ packageViewer.refresh(node);
+ }
+ }
+ });
+ }
+}
Modified:
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/pages/ArchiveInfoWizardPage.java
===================================================================
---
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/pages/ArchiveInfoWizardPage.java 2008-06-12
22:15:26 UTC (rev 8746)
+++
branches/jbosstools-2.1.x/core/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/pages/ArchiveInfoWizardPage.java 2008-06-12
22:23:39 UTC (rev 8747)
@@ -1,294 +1,295 @@
-package org.jboss.ide.eclipse.archives.ui.wizards.pages;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-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.IArchive;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
-import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
-import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
-import org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages;
-import org.jboss.ide.eclipse.archives.ui.util.DestinationChangeListener;
-import org.jboss.ide.eclipse.archives.ui.util.composites.ArchiveDestinationComposite;
-import org.jboss.ide.eclipse.archives.ui.wizards.AbstractArchiveWizard;
-import org.jboss.ide.eclipse.archives.ui.wizards.WizardPageWithNotification;
-import org.jboss.ide.eclipse.archives.ui.wizards.WizardWithNotification;
-
-public class ArchiveInfoWizardPage extends WizardPageWithNotification {
-
- private AbstractArchiveWizard wizard;
- private Text packageNameText;
- private Button compressedButton;
- private Button explodedButton;
- private String packageName;
- private boolean packageExploded;
- private ArchiveDestinationComposite destinationComposite;
- private IArchive archive;
-
- public ArchiveInfoWizardPage (AbstractArchiveWizard wizard, IArchive existingPackage) {
- super (ArchivesUIMessages.PackageInfoWizardPage_title,
ArchivesUIMessages.PackageInfoWizardPage_title, wizard.getImageDescriptor());
- setWizard(wizard);
- this.archive = existingPackage;
- }
-
- public void createControl(Composite parent) {
- setMessage(ArchivesUIMessages.PackageInfoWizardPage_message);
-
- Composite main = new Composite(parent, SWT.NONE);
- main.setLayout(new GridLayout(1, false));
-
- Group infoGroup = new Group(main, SWT.NONE);
- infoGroup.setLayout(new GridLayout(3, false));
- infoGroup.setText(ArchivesUIMessages.PackageInfoWizardPage_infoGroup_label);
- expand(infoGroup);
-
- new Label(infoGroup,
SWT.NONE).setText(ArchivesUIMessages.PackageInfoWizardPage_packageName_label);
- Composite pkgNameComposite = new Composite(infoGroup, SWT.NONE);
- GridLayout pkgNameLayout = new GridLayout(2, false);
- pkgNameLayout.marginHeight = 0;
- pkgNameLayout.marginWidth = 0;
- pkgNameComposite.setLayout(pkgNameLayout);
- pkgNameComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- new Label(pkgNameComposite,
SWT.NONE).setImage(ArchivesSharedImages.getImage(ArchivesSharedImages.IMG_PACKAGE));
-
- packageNameText = new Text(pkgNameComposite, SWT.BORDER);
- packageName = wizard.getProject().getName() + "." +
wizard.getArchiveExtension();
- packageNameText.setText(packageName);
- packageNameText.setSelection(0, wizard.getProject().getName().length());
- expand(packageNameText);
-
- GridData pkgNameData = new GridData(GridData.FILL_HORIZONTAL);
- pkgNameData.horizontalSpan = 2;
- pkgNameComposite.setLayoutData(pkgNameData);
-
- packageNameText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- if (validate())
- {
- packageName = packageNameText.getText();
- }
- }
- });
-
- new Label(infoGroup,
SWT.NONE).setText(ArchivesUIMessages.PackageInfoWizardPage_destination_label);
-
- GridData destinationTextData = new GridData(GridData.FILL_BOTH);
- destinationTextData.horizontalSpan = 2;
- GridData buttonData = new GridData(GridData.FILL_HORIZONTAL);
- buttonData.horizontalSpan = 3;
- buttonData.horizontalAlignment = SWT.END;
-
- Object destination = wizard.getSelectedDestination();
- destinationComposite = new ArchiveDestinationComposite(
- infoGroup, SWT.NONE, destination);
- destinationComposite.addDestinationChangeListener(new DestinationChangeListener () {
- public void destinationChanged(Object newDestination) {
- validate();
- }
- });
- destinationComposite.setLayoutData(destinationTextData);
-
- Group packageTypeGroup = new Group(main, SWT.NONE);
- packageTypeGroup.setLayout(new GridLayout(1, false));
- packageTypeGroup.setText(ArchivesUIMessages.PackageInfoWizardPage_packageTypeGroup_label);
- expand(packageTypeGroup);
-
- packageExploded = false;
- compressedButton = new Button(packageTypeGroup, SWT.RADIO);
- compressedButton.setText(ArchivesUIMessages.PackageInfoWizardPage_compressedButton_label);
- compressedButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- packageExploded = false;
- }
- });
- compressedButton.setSelection(true);
- explodedButton = new Button(packageTypeGroup, SWT.RADIO);
- explodedButton.addSelectionListener(new SelectionAdapter () {
- public void widgetSelected(SelectionEvent e) {
- packageExploded = true;
- }
- });
- explodedButton.setText(ArchivesUIMessages.PackageInfoWizardPage_explodedButton_label);
- setControl(main);
-
- fillDefaults();
- validate();
- }
-
- private void fillDefaults ()
- {
- if (archive != null)
- {
- compressedButton.setSelection(!archive.isExploded());
- explodedButton.setSelection(archive.isExploded());
- packageNameText.setText(archive.getName());
- packageName = archive.getName();
-
- if (archive.isTopLevel()) {
-
- // TODO: FIX THIS
- IContainer container =
ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(archive.getGlobalDestinationPath());
- if( container != null )
- destinationComposite.setPackageNodeDestination(container);
- else
- destinationComposite.setPackageNodeDestination(archive.getGlobalDestinationPath());
- } else {
- destinationComposite.setPackageNodeDestination(archive.getParent());
- }
-
- if (archive.isExploded()) {
- explodedButton.setEnabled(true);
- } else {
- compressedButton.setEnabled(true);
- }
- }
- }
-
- private boolean validate ()
- {
- if (packageNameText.getText() == null || packageNameText.getText().length() == 0)
- {
- setErrorMessage(ArchivesUIMessages.PackageInfoWizardPage_error_noPackageName);
- setPageComplete(false);
- return false;
- }
- else {
- setErrorMessage(null);
- }
-
- Object destination = getPackageDestination();
- if (destination instanceof IArchiveNode)
- {
- IArchiveNode parentNode = (IArchiveNode) destination;
-
- // verify no child has the same name
- IArchiveNode subPackages[] = parentNode.getChildren(IArchiveNode.TYPE_ARCHIVE);
- for (int i = 0; i < subPackages.length; i++)
- {
- IArchive subPackage = (IArchive) subPackages[i];
- if (subPackage.getName().equals(packageNameText.getText())
- && (!subPackage.equals(this.archive)))
- {
- setErrorMessage(
- ArchivesUIMessages.bind(
- ArchivesUIMessages.PackageInfoWizardPage_error_packageAlreadyExists,
packageNameText.getText()));
- setPageComplete(false);
- return false;
- }
- }
- } else if (destination instanceof IContainer) {
- IContainer container = (IContainer) destination;
- IArchive[] packages =
ModelUtil.getProjectArchives(wizard.getProject().getLocation());
- if (packages != null) {
- for( int i = 0; i < packages.length; i++ ) {
- IArchive pkg = (IArchive) packages[i];
- if (pkg.getName().equals(packageNameText.getText())
- && (pkg.getGlobalDestinationPath() != null &&
pkg.getGlobalDestinationPath().equals(container.getFullPath()))
- && (!pkg.equals(this.archive)))
- {
- setErrorMessage(
- ArchivesUIMessages.bind(
- ArchivesUIMessages.PackageInfoWizardPage_error_packageAlreadyExists,
packageNameText.getText()));
- setPageComplete(false);
- return false;
- }
- }
- }
- } else if (destination instanceof IPath) {
- IPath path = (IPath) destination;
- IArchive[] packages =
ModelUtil.getProjectArchives(wizard.getProject().getLocation());
- if (packages != null) {
- for( int i = 0; i < packages.length; i++ ) {
- IArchive pkg = (IArchive) packages[i];
- if (pkg.getName().equals(packageNameText.getText())
- && (pkg.getGlobalDestinationPath() != null &&
pkg.getGlobalDestinationPath().equals(path))
- && (!pkg.equals(this.archive)))
- {
- setErrorMessage(
- ArchivesUIMessages.bind(
- ArchivesUIMessages.PackageInfoWizardPage_error_packageAlreadyExists,
packageNameText.getText()));
- setPageComplete(false);
- return false;
- }
- }
- } else if (destination == null) {
- setErrorMessage(ArchivesUIMessages.PackageInfoWizardPage_error_noDestination);
- setPageComplete(false);
- return false;
- }
- }
-
- setPageComplete(true);
- return true;
- }
-
-
- public void pageExited(int button) {
- if (button == WizardWithNotification.NEXT || button == WizardWithNotification.FINISH)
{
- createPackage();
- }
- }
-
- private void createPackage () {
- Object destContainer = getPackageDestination();
-
-
- if (archive == null) {
- archive = ArchiveNodeFactory.createArchive();
- }
-
- archive.setName(getPackageName());
- archive.setExploded(isPackageExploded());
-
- if (destContainer instanceof IContainer) {
- archive.setDestinationPath(((IContainer)destContainer).getFullPath());
- archive.setInWorkspace(true);
- } else if (destContainer instanceof IPath) {
- archive.setDestinationPath((IPath) destContainer);
- archive.setInWorkspace(false);
- }
- }
-
- private void expand(Control control)
- {
- control.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- }
-
- public String getPackageName() {
- return packageName;
- }
-
- public boolean isPackageExploded() {
- return packageExploded;
- }
-
- public Object getPackageDestination() {
- return destinationComposite.getPackageNodeDestination();
- }
-
- private void setWizard(AbstractArchiveWizard wizard)
- {
- this.wizard = wizard;
- }
-
- public IArchive getArchive ()
- {
- return archive;
- }
-}
+package org.jboss.ide.eclipse.archives.ui.wizards.pages;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+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.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
+import org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages;
+import org.jboss.ide.eclipse.archives.ui.util.DestinationChangeListener;
+import org.jboss.ide.eclipse.archives.ui.util.composites.ArchiveDestinationComposite;
+import org.jboss.ide.eclipse.archives.ui.wizards.AbstractArchiveWizard;
+import org.jboss.ide.eclipse.archives.ui.wizards.WizardPageWithNotification;
+import org.jboss.ide.eclipse.archives.ui.wizards.WizardWithNotification;
+
+public class ArchiveInfoWizardPage extends WizardPageWithNotification {
+
+ private AbstractArchiveWizard wizard;
+ private Text packageNameText;
+ private Button compressedButton;
+ private Button explodedButton;
+ private String packageName;
+ private boolean packageExploded;
+ private ArchiveDestinationComposite destinationComposite;
+ private IArchive archive;
+
+ public ArchiveInfoWizardPage (AbstractArchiveWizard wizard, IArchive existingPackage) {
+ super (ArchivesUIMessages.PackageInfoWizardPage_title,
ArchivesUIMessages.PackageInfoWizardPage_title, wizard.getImageDescriptor());
+ setWizard(wizard);
+ this.archive = existingPackage;
+ }
+
+ public void createControl(Composite parent) {
+ setMessage(ArchivesUIMessages.PackageInfoWizardPage_message);
+
+ Composite main = new Composite(parent, SWT.NONE);
+ main.setLayout(new GridLayout(1, false));
+
+ Group infoGroup = new Group(main, SWT.NONE);
+ infoGroup.setLayout(new GridLayout(3, false));
+ infoGroup.setText(ArchivesUIMessages.PackageInfoWizardPage_infoGroup_label);
+ expand(infoGroup);
+
+ new Label(infoGroup,
SWT.NONE).setText(ArchivesUIMessages.PackageInfoWizardPage_packageName_label);
+ Composite pkgNameComposite = new Composite(infoGroup, SWT.NONE);
+ GridLayout pkgNameLayout = new GridLayout(2, false);
+ pkgNameLayout.marginHeight = 0;
+ pkgNameLayout.marginWidth = 0;
+ pkgNameComposite.setLayout(pkgNameLayout);
+ pkgNameComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ new Label(pkgNameComposite,
SWT.NONE).setImage(ArchivesSharedImages.getImage(ArchivesSharedImages.IMG_PACKAGE));
+
+ packageNameText = new Text(pkgNameComposite, SWT.BORDER);
+ packageName = wizard.getProject().getName() + "." +
wizard.getArchiveExtension();
+ packageNameText.setText(packageName);
+ packageNameText.setSelection(0, wizard.getProject().getName().length());
+ expand(packageNameText);
+
+ GridData pkgNameData = new GridData(GridData.FILL_HORIZONTAL);
+ pkgNameData.horizontalSpan = 2;
+ pkgNameComposite.setLayoutData(pkgNameData);
+
+ packageNameText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if (validate())
+ {
+ packageName = packageNameText.getText();
+ }
+ }
+ });
+
+ new Label(infoGroup,
SWT.NONE).setText(ArchivesUIMessages.PackageInfoWizardPage_destination_label);
+
+ GridData destinationTextData = new GridData(GridData.FILL_BOTH);
+ destinationTextData.horizontalSpan = 2;
+ GridData buttonData = new GridData(GridData.FILL_HORIZONTAL);
+ buttonData.horizontalSpan = 3;
+ buttonData.horizontalAlignment = SWT.END;
+
+ Object destination = wizard.getSelectedDestination();
+ destinationComposite = new ArchiveDestinationComposite(
+ infoGroup, SWT.NONE, destination);
+ destinationComposite.addDestinationChangeListener(new DestinationChangeListener () {
+ public void destinationChanged(Object newDestination) {
+ validate();
+ }
+ });
+ destinationComposite.setLayoutData(destinationTextData);
+
+ Group packageTypeGroup = new Group(main, SWT.NONE);
+ packageTypeGroup.setLayout(new GridLayout(1, false));
+ packageTypeGroup.setText(ArchivesUIMessages.PackageInfoWizardPage_packageTypeGroup_label);
+ expand(packageTypeGroup);
+
+ packageExploded = false;
+ compressedButton = new Button(packageTypeGroup, SWT.RADIO);
+ compressedButton.setText(ArchivesUIMessages.PackageInfoWizardPage_compressedButton_label);
+ compressedButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ packageExploded = false;
+ }
+ });
+ compressedButton.setSelection(true);
+ explodedButton = new Button(packageTypeGroup, SWT.RADIO);
+ explodedButton.addSelectionListener(new SelectionAdapter () {
+ public void widgetSelected(SelectionEvent e) {
+ packageExploded = true;
+ }
+ });
+ explodedButton.setText(ArchivesUIMessages.PackageInfoWizardPage_explodedButton_label);
+ setControl(main);
+
+ fillDefaults();
+ validate();
+ }
+
+ private void fillDefaults ()
+ {
+ if (archive != null)
+ {
+ compressedButton.setSelection(!archive.isExploded());
+ explodedButton.setSelection(archive.isExploded());
+ packageNameText.setText(archive.getName());
+ packageName = archive.getName();
+
+ if (archive.isTopLevel()) {
+
+ // TODO: FIX THIS
+ IPath globalDest = archive.getGlobalDestinationPath();
+ IContainer container = globalDest == null ? null :
ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(globalDest);
+ if( container != null )
+ destinationComposite.setPackageNodeDestination(container);
+ else
+ destinationComposite.setPackageNodeDestination(globalDest);
+ } else {
+ destinationComposite.setPackageNodeDestination(archive.getParent());
+ }
+
+ if (archive.isExploded()) {
+ explodedButton.setEnabled(true);
+ } else {
+ compressedButton.setEnabled(true);
+ }
+ }
+ }
+
+ private boolean validate ()
+ {
+ if (packageNameText.getText() == null || packageNameText.getText().length() == 0)
+ {
+ setErrorMessage(ArchivesUIMessages.PackageInfoWizardPage_error_noPackageName);
+ setPageComplete(false);
+ return false;
+ }
+ else {
+ setErrorMessage(null);
+ }
+
+ Object destination = getPackageDestination();
+ if (destination instanceof IArchiveNode)
+ {
+ IArchiveNode parentNode = (IArchiveNode) destination;
+
+ // verify no child has the same name
+ IArchiveNode subPackages[] = parentNode.getChildren(IArchiveNode.TYPE_ARCHIVE);
+ for (int i = 0; i < subPackages.length; i++)
+ {
+ IArchive subPackage = (IArchive) subPackages[i];
+ if (subPackage.getName().equals(packageNameText.getText())
+ && (!subPackage.equals(this.archive)))
+ {
+ setErrorMessage(
+ ArchivesUIMessages.bind(
+ ArchivesUIMessages.PackageInfoWizardPage_error_packageAlreadyExists,
packageNameText.getText()));
+ setPageComplete(false);
+ return false;
+ }
+ }
+ } else if (destination instanceof IContainer) {
+ IContainer container = (IContainer) destination;
+ IArchive[] packages =
ModelUtil.getProjectArchives(wizard.getProject().getLocation());
+ if (packages != null) {
+ for( int i = 0; i < packages.length; i++ ) {
+ IArchive pkg = (IArchive) packages[i];
+ if (pkg.getName().equals(packageNameText.getText())
+ && (pkg.getGlobalDestinationPath() != null &&
pkg.getGlobalDestinationPath().equals(container.getFullPath()))
+ && (!pkg.equals(this.archive)))
+ {
+ setErrorMessage(
+ ArchivesUIMessages.bind(
+ ArchivesUIMessages.PackageInfoWizardPage_error_packageAlreadyExists,
packageNameText.getText()));
+ setPageComplete(false);
+ return false;
+ }
+ }
+ }
+ } else if (destination instanceof IPath) {
+ IPath path = (IPath) destination;
+ IArchive[] packages =
ModelUtil.getProjectArchives(wizard.getProject().getLocation());
+ if (packages != null) {
+ for( int i = 0; i < packages.length; i++ ) {
+ IArchive pkg = (IArchive) packages[i];
+ if (pkg.getName().equals(packageNameText.getText())
+ && (pkg.getGlobalDestinationPath() != null &&
pkg.getGlobalDestinationPath().equals(path))
+ && (!pkg.equals(this.archive)))
+ {
+ setErrorMessage(
+ ArchivesUIMessages.bind(
+ ArchivesUIMessages.PackageInfoWizardPage_error_packageAlreadyExists,
packageNameText.getText()));
+ setPageComplete(false);
+ return false;
+ }
+ }
+ } else if (destination == null) {
+ setErrorMessage(ArchivesUIMessages.PackageInfoWizardPage_error_noDestination);
+ setPageComplete(false);
+ return false;
+ }
+ }
+
+ setPageComplete(true);
+ return true;
+ }
+
+
+ public void pageExited(int button) {
+ if (button == WizardWithNotification.NEXT || button == WizardWithNotification.FINISH)
{
+ createPackage();
+ }
+ }
+
+ private void createPackage () {
+ Object destContainer = getPackageDestination();
+
+
+ if (archive == null) {
+ archive = ArchiveNodeFactory.createArchive();
+ }
+
+ archive.setName(getPackageName());
+ archive.setExploded(isPackageExploded());
+
+ if (destContainer instanceof IContainer) {
+ archive.setDestinationPath(((IContainer)destContainer).getFullPath());
+ archive.setInWorkspace(true);
+ } else if (destContainer instanceof IPath) {
+ archive.setDestinationPath((IPath) destContainer);
+ archive.setInWorkspace(false);
+ }
+ }
+
+ private void expand(Control control)
+ {
+ control.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ }
+
+ public String getPackageName() {
+ return packageName;
+ }
+
+ public boolean isPackageExploded() {
+ return packageExploded;
+ }
+
+ public Object getPackageDestination() {
+ return destinationComposite.getPackageNodeDestination();
+ }
+
+ private void setWizard(AbstractArchiveWizard wizard)
+ {
+ this.wizard = wizard;
+ }
+
+ public IArchive getArchive ()
+ {
+ return archive;
+ }
+}