Author: rob.stryker(a)jboss.com
Date: 2007-10-25 18:04:40 -0400 (Thu, 25 Oct 2007)
New Revision: 4523
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/WorkspaceChangeListener.java
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/ArchivesCorePlugin.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ModelChangeListener.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/ArchivesModel.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNodeDelta.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeDeltaImpl.java
Log:
JBIDE-1165
Awesome impl ;)
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/ArchivesCorePlugin.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/ArchivesCorePlugin.java 2007-10-25
18:32:27 UTC (rev 4522)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/ArchivesCorePlugin.java 2007-10-25
22:04:40 UTC (rev 4523)
@@ -22,6 +22,7 @@
package org.jboss.ide.eclipse.archives.core;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Plugin;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
import org.osgi.framework.BundleContext;
@@ -30,7 +31,8 @@
* The activator class controls the plug-in life cycle
* @author rstryker
*
- */public class ArchivesCorePlugin extends Plugin {
+ */
+public class ArchivesCorePlugin extends Plugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.ide.eclipse.archives.core";
@@ -54,6 +56,7 @@
// Load the workspace version of ArchivesCore
ArchivesCore core = new WorkspaceArchivesCore();
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(new
WorkspaceChangeListener());
}
/*
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/WorkspaceChangeListener.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/WorkspaceChangeListener.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/WorkspaceChangeListener.java 2007-10-25
22:04:40 UTC (rev 4523)
@@ -0,0 +1,82 @@
+/*
+ * 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.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+
+/**
+ * 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 projects = new TreeSet();
+
+ IResourceDelta delta = event.getDelta();
+ try {
+ delta.accept(new IResourceDeltaVisitor() {
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ if( delta.getResource() != null &&
delta.getResource().getLocation().lastSegment().equals(ArchivesModel.PROJECT_PACKAGES_FILE))
{
+ projects.add(delta.getResource().getProject());
+ }
+ return true;
+ }
+ });
+ } catch( CoreException ce ) {
+ }
+ Iterator i = projects.iterator();
+ while(i.hasNext()) {
+ final IProject p = (IProject)i.next();
+ 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();
+ }
+ }
+
+}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ModelChangeListener.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ModelChangeListener.java 2007-10-25
18:32:27 UTC (rev 4522)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ModelChangeListener.java 2007-10-25
22:04:40 UTC (rev 4523)
@@ -6,6 +6,7 @@
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.IArchiveModelNode;
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.events.EventManager;
@@ -59,9 +60,11 @@
if( isTopLevelArchive(delta.getPostNode()))
EventManager.startedBuildingArchive((IArchive)delta.getPostNode());
-
- if( (delta.getKind() & IArchiveNodeDelta.REMOVED) != 0 ) {
+ if( (delta.getKind() & 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) {
@@ -136,11 +139,18 @@
private void nodeAdded(IArchiveNode added) {
- if( added.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
+ if( added == null ) return;
+
+ if( added.getNodeType() == IArchiveNode.TYPE_MODEL) {
+ IArchiveNode[] archives =
((IArchiveModelNode)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 hte folder
+ // create the folder
ModelTruezipBridge.createFile(added);
}
IArchiveFileSet[] filesets = ModelUtil.findAllDescendentFilesets(added);
@@ -154,7 +164,16 @@
private void nodeRemoved(IArchiveNode removed) {
- if( removed.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
+ if( removed == null ) return;
+ if( removed.getNodeType() == IArchiveNode.TYPE_MODEL ) {
+ // remove all top level items
+ IArchiveNode[] kids = removed.getChildren(IArchiveNode.TYPE_ARCHIVE);
+ for( int i = 0; i < kids.length; i++ ) {
+ ModelTruezipBridge.deleteArchive((IArchive)kids[i]);
+ }
+ postChange(removed);
+ return;
+ } else if( removed.getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
ModelTruezipBridge.deleteArchive((IArchive)removed);
postChange(removed);
return;
@@ -166,7 +185,7 @@
}
postChange(removed);
return;
- }
+ }
IArchiveFileSet[] filesets = ModelUtil.findAllDescendentFilesets(removed);
for( int i = 0; i < filesets.length; i++ ) {
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/ArchivesModel.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/ArchivesModel.java 2007-10-25
18:32:27 UTC (rev 4522)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/ArchivesModel.java 2007-10-25
22:04:40 UTC (rev 4523)
@@ -243,10 +243,12 @@
return;
}
root = new ArchiveModelNode(project, packages, this);
+ ArchiveModelNode oldRoot = (ArchiveModelNode)archivesRoot.get(project);
xbPackages.put(project, packages);
archivesRoot.put(project, root);
createPackageNodeImpl(project, packages, null);
root.clearDeltas();
+ fireRegisterProjectEvent(oldRoot, root);
monitor.worked(1);
} catch (FileNotFoundException e) {
Trace.trace(getClass(), e);
@@ -259,6 +261,23 @@
}
}
+ protected void fireRegisterProjectEvent(final ArchiveModelNode oldRoot, final
ArchiveModelNode newRoot) {
+ IArchiveNodeDelta delta = new IArchiveNodeDelta() {
+ public IArchiveNodeDelta[] getAddedChildrenDeltas() {return null;}
+ public IArchiveNodeDelta[] getAllAffectedChildren() {return null;}
+ public INodeDelta getAttributeDelta(String key) {return null;}
+ public String[] getAttributesWithDeltas() {return null;}
+ public IArchiveNodeDelta[] getChangedDescendentDeltas() {return null;}
+ public int getKind() {return IArchiveNodeDelta.UNKNOWN_CHANGE;}
+ public IArchiveNode getPostNode() {return newRoot;}
+ public IArchiveNode getPreNode() { return oldRoot; }
+ public String[] getPropertiesWithDeltas() {return null;}
+ public INodeDelta getPropertyDelta(String key) {return null;}
+ public IArchiveNodeDelta[] getRemovedChildrenDeltas() {return null;}
+ };
+ EventManager.fireDelta(delta);
+ }
+
public ArchiveNodeImpl createPackageNodeImpl (IPath project, XbPackageNode node,
IArchiveNode parent) {
if( node instanceof XbPackages ) {
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNodeDelta.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNodeDelta.java 2007-10-25
18:32:27 UTC (rev 4522)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IArchiveNodeDelta.java 2007-10-25
22:04:40 UTC (rev 4523)
@@ -86,6 +86,11 @@
public static final int DESCENDENT_CHANGED = 0x400;
/**
+ * An unknown change has occurred. Best to reshow the entire module
+ */
+ public static final int UNKNOWN_CHANGE = 0x800;
+
+ /**
* Return the delta kind
* @return
*/
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeDeltaImpl.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeDeltaImpl.java 2007-10-25
18:32:27 UTC (rev 4522)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeDeltaImpl.java 2007-10-25
22:04:40 UTC (rev 4523)
@@ -26,7 +26,6 @@
import java.util.HashMap;
import java.util.Iterator;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveModelListenerManager;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;