Author: scabanovich
Date: 2007-09-21 10:19:43 -0400 (Fri, 21 Sep 2007)
New Revision: 3756
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/server/ChangeTimeStampActionDelegate.java
Log:
JBIDE-929
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/server/ChangeTimeStampActionDelegate.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/server/ChangeTimeStampActionDelegate.java 2007-09-21
13:51:48 UTC (rev 3755)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/server/ChangeTimeStampActionDelegate.java 2007-09-21
14:19:43 UTC (rev 3756)
@@ -10,23 +10,52 @@
******************************************************************************/
package org.jboss.tools.jst.web.ui.action.server;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.*;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
import org.eclipse.ui.*;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
import org.jboss.tools.common.meta.action.*;
import org.jboss.tools.common.model.*;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.model.ui.ModelUIPlugin;
import org.jboss.tools.jst.web.messages.xpl.WebUIMessages;
import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
import org.jboss.tools.jst.web.ui.WebUiPlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.NullProgressMonitor;
public class ChangeTimeStampActionDelegate implements IWorkbenchWindowActionDelegate {
- protected XModelObject object = null;
+ static Set<String> warFilesToTouch = new HashSet<String>();
+ static Set<String> earFilesToTouch = new HashSet<String>();
+
+ static {
+ warFilesToTouch.add("web.xml");
+ earFilesToTouch.add("manifest.mf");
+ }
+
protected IWorkbenchWindow window;
String tooltip = null;
+
+ IProject project = null;
protected String getActionPath() {
return "SaveActions.ChangeTimeStamp"; //$NON-NLS-1$
@@ -37,26 +66,71 @@
}
public void selectionChanged(IAction action, ISelection selection) {
- if(object == null && action.isEnabled()) action.setEnabled(false);
+ if(project == null && action.isEnabled()) action.setEnabled(false);
if(tooltip == null) tooltip = action.getToolTipText();
if(!(selection instanceof IStructuredSelection)) return;
Object o = ((IStructuredSelection)selection).getFirstElement();
- XModelObject adapter = (o instanceof XModelObject) ? (XModelObject)o : null;
- if(adapter == null) return;
- object = adapter;
+ IProject p = getProject(o);
+ if(p == null) return;
+ project = p;
action.setEnabled(computeEnabled());
- if(object == null) {
+ if(project == null) {
action.setToolTipText(tooltip);
} else {
- IResource r = EclipseResourceUtil.getResource(object);
- if(r != null && r.exists())
action.setToolTipText(WebUIMessages.CHANGE_TIME_STAMP + r.getLocation().toString());
+ action.setToolTipText(WebUIMessages.CHANGE_TIME_STAMP + project.getName());
}
+
}
+ IProject getProject(Object selection) {
+ if(selection instanceof IResource) {
+ return ((IResource)selection).getProject();
+ } else if(selection instanceof IAdaptable) {
+ Object r = ((IAdaptable)selection).getAdapter(IResource.class);
+ return r instanceof IResource ? ((IResource)r).getProject() : null;
+ }
+ return null;
+ }
+
protected boolean computeEnabled() {
- object = (object == null) ? null : WebAppHelper.getWebApp(object.getModel());
- return object != null;
+ if(project == null || !project.isAccessible()) return false;
+ boolean isWar = J2EEProjectUtilities.isDynamicWebProject(project);
+ boolean isEar = J2EEProjectUtilities.isEARProject(project);
+ boolean isEJB = J2EEProjectUtilities.isEJBProject(project);
+ return isEar || isEJB || isWar;
}
+
+ List<IFile> getFilesToTouch(IProject project) {
+ List<IFile> fs = new ArrayList<IFile>();
+ if(project == null || !project.isAccessible()) return fs;
+ boolean isWar = J2EEProjectUtilities.isDynamicWebProject(project);
+ boolean isEar = J2EEProjectUtilities.isEARProject(project);
+ boolean isEJB = J2EEProjectUtilities.isEJBProject(project);
+
+ if(!isEar) {
+ IProject[] ps = J2EEProjectUtilities.getReferencingEARProjects(project);
+ for (int i = 0; i < ps.length; i++) {
+ fs.addAll(getFilesToTouch(ps[i]));
+ }
+ }
+ if(isEar) {
+ List l = J2EEProjectUtilities.getAllProjectFiles(project);
+ for (int i = 0; i < l.size(); i++) {
+ IFile f = (IFile)l.get(i);
+ String n = f.getName().toLowerCase();
+ if(earFilesToTouch.contains(n)) fs.add(f);
+ }
+ }
+ if(isWar) {
+ List l = J2EEProjectUtilities.getAllProjectFiles(project);
+ for (int i = 0; i < l.size(); i++) {
+ IFile f = (IFile)l.get(i);
+ String n = f.getName().toLowerCase();
+ if(warFilesToTouch.contains(n)) fs.add(f);
+ }
+ }
+ return fs;
+ }
public void run(IAction action) {
try {
@@ -67,9 +141,16 @@
}
protected void doRun() throws Exception {
- XActionInvoker.invoke(getActionPath(), object, null);
+ if(project == null || !project.isAccessible()) return;
+ List<IFile> fs = getFilesToTouch(project);
+ for (int i = 0; i < fs.size(); i++) {
+ IFile f = (IFile)fs.get(i);
+ f.touch(new NullProgressMonitor());
+ }
}
- public void dispose() {}
+ public void dispose() {
+ window = null;
+ }
}
Show replies by date