[jboss-svn-commits] JBL Code SVN: r21072 - in labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools: META-INF and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jul 16 16:29:06 EDT 2008
Author: john.graham at jboss.org
Date: 2008-07-16 16:29:05 -0400 (Wed, 16 Jul 2008)
New Revision: 21072
Added:
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/GuvnorCompareEditorInput.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/GuvnorResourceEdition.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/ActionUtils.java
Modified:
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/AddAction.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CompareVersionAction.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DeleteAction.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DisconnectAction.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavClient.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/RepositoryView.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/CheckoutWizard.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/SelectGuvnorFolderPage.java
Log:
Version compare action, warnings on overwrite
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF 2008-07-16 20:29:05 UTC (rev 21072)
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.guvnor.tools;singleton:=true
-Bundle-Version: 0.6.0.200807141651
+Bundle-Version: 0.6.0.200807161700
Bundle-Activator: org.guvnor.tools.Activator
Bundle-Vendor: %plugin.provider
Bundle-Localization: plugin
@@ -10,5 +10,6 @@
org.eclipse.ui.ide,
org.eclipse.core.resources,
org.eclipse.core.runtime,
+ org.eclipse.compare,
org.eclipse.webdav
Eclipse-LazyStart: true
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml 2008-07-16 20:29:05 UTC (rev 21072)
@@ -117,6 +117,12 @@
label="%action.popup.switchversion"
menubarPath="org.guvnor.tools.popupmenu/group1">
</action>
+ <action class="org.guvnor.tools.actions.CompareVersionAction"
+ enablesFor="1"
+ id="org.guvnor.tools.actions.compareversionaction"
+ label="%action.popup.compareversion"
+ menubarPath="org.guvnor.tools.popupmenu/group1">
+ </action>
<action class="org.guvnor.tools.actions.ShowHistoryAction"
enablesFor="1"
id="org.guvnor.tools.actions.showhistoryaction"
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/AddAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/AddAction.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/AddAction.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -1,19 +1,13 @@
package org.guvnor.tools.actions;
-import java.util.Iterator;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.guvnor.tools.Activator;
-import org.guvnor.tools.utils.GuvnorMetadataProps;
-import org.guvnor.tools.utils.GuvnorMetadataUtils;
+import org.guvnor.tools.utils.ActionUtils;
import org.guvnor.tools.utils.PlatformUtils;
import org.guvnor.tools.wizards.AddResourceWizard;
@@ -29,14 +23,14 @@
super();
}
- /**
+ /*
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
this.targetPart = targetPart;
}
- /**
+ /*
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
@@ -50,37 +44,17 @@
}
}
- /**
+ /*
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
- @SuppressWarnings("unchecked")
public void selectionChanged(IAction action, ISelection selection) {
- // Reset state to default
- selectedItems = null;
- action.setEnabled(true);
- // See if we should enable for the selection
- try {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection sel = (IStructuredSelection)selection;
- for (Iterator<Object> it = sel.iterator(); it.hasNext();) {
- Object oneSelection = it.next();
- if (oneSelection instanceof IFile) {
- GuvnorMetadataProps props = GuvnorMetadataUtils.
- getGuvnorMetadata((IFile)oneSelection);
- if (props != null) {
- action.setEnabled(false);
- break;
- }
- }
- }
- if (action.isEnabled()) {
- selectedItems = sel;
- }
- } else {
- action.setEnabled(false);
- }
- } catch (Exception e) {
- Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ boolean validResourceSet = ActionUtils.checkResourceSet(selection, false);
+ if (validResourceSet) {
+ action.setEnabled(true);
+ selectedItems = (IStructuredSelection)selection;
+ } else {
+ action.setEnabled(false);
+ selectedItems = null;
}
}
}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -8,11 +8,11 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.webdav.IResponse;
import org.guvnor.tools.Activator;
+import org.guvnor.tools.utils.ActionUtils;
import org.guvnor.tools.utils.GuvnorMetadataProps;
import org.guvnor.tools.utils.GuvnorMetadataUtils;
import org.guvnor.tools.utils.PlatformUtils;
@@ -39,7 +39,7 @@
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
- /**
+ /*
* @see IActionDelegate#run(IAction)
*/
@SuppressWarnings("unchecked")
@@ -86,37 +86,18 @@
}
}
- /**
+ /*
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
- @SuppressWarnings("unchecked")
public void selectionChanged(IAction action, ISelection selection) {
- // Reset state to default
- selectedItems = null;
- action.setEnabled(true);
- // See if we should enable for the selection
- try {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection sel = (IStructuredSelection)selection;
- for (Iterator<Object> it = sel.iterator(); it.hasNext();) {
- Object oneSelection = it.next();
- if (oneSelection instanceof IFile) {
- GuvnorMetadataProps props = GuvnorMetadataUtils.
- getGuvnorMetadata((IFile)oneSelection);
- if (props == null) {
- action.setEnabled(false);
- break;
- }
- }
- }
- if (action.isEnabled()) {
- selectedItems = sel;
- }
- } else {
- action.setEnabled(false);
- }
- } catch (Exception e) {
- Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ boolean validResourceSet = ActionUtils.checkResourceSet(selection, true)
+ && ActionUtils.areFilesDirty(selection);
+ if (validResourceSet) {
+ action.setEnabled(true);
+ selectedItems = (IStructuredSelection)selection;
+ } else {
+ action.setEnabled(false);
+ selectedItems = null;
}
}
}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CompareVersionAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CompareVersionAction.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CompareVersionAction.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -1,17 +1,37 @@
package org.guvnor.tools.actions;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+import org.eclipse.compare.CompareUI;
+import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.webdav.IResponse;
import org.guvnor.tools.Activator;
import org.guvnor.tools.utils.GuvnorMetadataProps;
import org.guvnor.tools.utils.GuvnorMetadataUtils;
+import org.guvnor.tools.utils.PlatformUtils;
+import org.guvnor.tools.utils.VersionChooserDialog;
+import org.guvnor.tools.utils.webdav.IWebDavClient;
+import org.guvnor.tools.utils.webdav.StreamProcessingUtils;
+import org.guvnor.tools.utils.webdav.WebDavClientFactory;
+import org.guvnor.tools.utils.webdav.WebDavException;
+import org.guvnor.tools.utils.webdav.WebDavServerCache;
+import org.guvnor.tools.views.model.ResourceHistoryEntry;
+/**
+ * Simple text-based compare editor input.
+ * @author jgraham
+ */
public class CompareVersionAction implements IObjectActionDelegate {
private IFile selectedFile;
@@ -19,6 +39,8 @@
private IWorkbenchPart targetPart;
+ private IWebDavClient client;
+
/**
* Constructor for Action1.
*/
@@ -26,14 +48,14 @@
super();
}
- /**
+ /*
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
this.targetPart = targetPart;
}
- /**
+ /*
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
@@ -42,9 +64,90 @@
|| targetPart == null) {
return;
}
+ VersionChooserDialog dialog =
+ new VersionChooserDialog(targetPart.getSite().getShell(),
+ selectedFile.getName(),
+ getVersionEntries());
+ if (dialog.open() == VersionChooserDialog.OK) {
+ compareWithSelectedVersion(dialog.getSelectedEntry());
+ }
}
- /**
+ private void compareWithSelectedVersion(ResourceHistoryEntry revision) {
+ IResponse response = null;
+ try {
+ IWorkbenchPage page = targetPart.getSite().getPage();
+ String leftContents = StreamProcessingUtils.getStreamContents(selectedFile.getContents());
+ GuvnorResourceEdition left =
+ new GuvnorResourceEdition(selectedFile.getName(),
+ ITypedElement.TEXT_TYPE,
+ leftContents, selectedFile.getCharset());
+ response = client.getResourceVersionInputStream(props.getFullpath(), revision.getRevision());
+ String rightContents = StreamProcessingUtils.getStreamContents(response.getInputStream());
+ //Assuming UTF-8 for Guvnor resources...
+ GuvnorResourceEdition right =
+ new GuvnorResourceEdition(selectedFile.getName() + ", " + revision.getRevision(),
+ ITypedElement.TEXT_TYPE,
+ rightContents, "UTF-8");
+ CompareUI.openCompareEditorOnPage(new GuvnorCompareEditorInput(left, right), page);
+ } catch (Exception e) {
+ Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ } finally {
+ if (response != null) {
+ try {
+ response.close();
+ } catch (IOException ioe) {
+ Activator.getDefault().writeLog(IStatus.ERROR, ioe.getMessage(), ioe);
+ }
+ }
+ }
+ }
+
+ private ResourceHistoryEntry[] getVersionEntries() {
+ ResourceHistoryEntry[] entries = new ResourceHistoryEntry[0];
+ IResponse response = null;
+ try {
+ client = WebDavServerCache.getWebDavClient(props.getRepository());
+ if (client == null) {
+ client = WebDavClientFactory.createClient(new URL(props.getRepository()));
+ WebDavServerCache.cacheWebDavClient(props.getRepository(), client);
+ }
+ InputStream ins = null;
+ try {
+ response = client.getResourceVersions(props.getFullpath());
+ ins = response.getInputStream();
+ } catch (WebDavException wde) {
+ if (wde.getErrorCode() != IResponse.SC_UNAUTHORIZED) {
+ // If not an authentication failure, we don't know what to do with it
+ throw wde;
+ }
+ boolean retry = PlatformUtils.getInstance().
+ authenticateForServer(props.getRepository(), client);
+ if (retry) {
+ response = client.getResourceVersions(props.getFullpath());
+ ins = response.getInputStream();
+ }
+ }
+ if (ins != null) {
+ Properties verProps = new Properties();
+ verProps.load(ins);
+ entries = GuvnorMetadataUtils.parseHistoryProperties(verProps);
+ }
+ } catch (Exception e) {
+ Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ } finally {
+ if (response != null) {
+ try {
+ response.close();
+ } catch (IOException ioe) {
+ Activator.getDefault().writeLog(IStatus.ERROR, ioe.getMessage(), ioe);
+ }
+ }
+ }
+ return entries;
+ }
+
+ /*
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DeleteAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DeleteAction.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DeleteAction.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -6,13 +6,14 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.webdav.IResponse;
import org.guvnor.tools.Activator;
+import org.guvnor.tools.utils.ActionUtils;
import org.guvnor.tools.utils.GuvnorMetadataProps;
import org.guvnor.tools.utils.GuvnorMetadataUtils;
import org.guvnor.tools.utils.PlatformUtils;
@@ -25,6 +26,8 @@
private IStructuredSelection selectedItems;
+ private IWorkbenchPart targetPart;
+
/**
* Constructor for Action1.
*/
@@ -32,13 +35,14 @@
super();
}
- /**
+ /*
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ this.targetPart = targetPart;
}
- /**
+ /*
* @see IActionDelegate#run(IAction)
*/
@SuppressWarnings("unchecked")
@@ -46,6 +50,17 @@
if (selectedItems == null) {
return;
}
+ String msg = null;
+ if (selectedItems.size() == 1) {
+ msg = "Delete " +
+ ((IFile)selectedItems.getFirstElement()).getName() + " in Guvnor?";
+ } else {
+ msg = "Delete these " + selectedItems.size() + " resources in Guvnor?";
+ }
+ if (!MessageDialog.openConfirm(targetPart.getSite().getShell(),
+ "Confirm Delete", msg)) {
+ return;
+ }
for (Iterator it = selectedItems.iterator(); it.hasNext();) {
Object oneItem = it.next();
if (oneItem instanceof IFile) {
@@ -85,37 +100,17 @@
}
}
- /**
+ /*
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
- @SuppressWarnings("unchecked")
public void selectionChanged(IAction action, ISelection selection) {
- // Reset state to default
- selectedItems = null;
- action.setEnabled(true);
- // See if we should enable for the selection
- try {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection sel = (IStructuredSelection)selection;
- for (Iterator<Object> it = sel.iterator(); it.hasNext();) {
- Object oneSelection = it.next();
- if (oneSelection instanceof IFile) {
- GuvnorMetadataProps props = GuvnorMetadataUtils.
- getGuvnorMetadata((IFile)oneSelection);
- if (props == null) {
- action.setEnabled(false);
- break;
- }
- }
- }
- if (action.isEnabled()) {
- selectedItems = sel;
- }
- } else {
- action.setEnabled(false);
- }
- } catch (Exception e) {
- Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ boolean validResourceSet = ActionUtils.checkResourceSet(selection, true);
+ if (validResourceSet) {
+ action.setEnabled(true);
+ selectedItems = (IStructuredSelection)selection;
+ } else {
+ action.setEnabled(false);
+ selectedItems = null;
}
}
}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DisconnectAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DisconnectAction.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DisconnectAction.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -11,11 +11,10 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.guvnor.tools.Activator;
-import org.guvnor.tools.utils.GuvnorMetadataProps;
+import org.guvnor.tools.utils.ActionUtils;
import org.guvnor.tools.utils.GuvnorMetadataUtils;
import org.guvnor.tools.utils.PlatformUtils;
@@ -30,13 +29,13 @@
super();
}
- /**
+ /*
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
- /**
+ /*
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
@@ -69,37 +68,17 @@
}
}
- /**
+ /*
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
- @SuppressWarnings("unchecked")
public void selectionChanged(IAction action, ISelection selection) {
- // Reset state to default
- selectedItems = null;
- action.setEnabled(true);
- // See if we should enable for the selection
- try {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection sel = (IStructuredSelection)selection;
- for (Iterator<Object> it = sel.iterator(); it.hasNext();) {
- Object oneSelection = it.next();
- if (oneSelection instanceof IFile) {
- GuvnorMetadataProps props = GuvnorMetadataUtils.
- getGuvnorMetadata((IFile)oneSelection);
- if (props == null) {
- action.setEnabled(false);
- break;
- }
- }
- }
- if (action.isEnabled()) {
- selectedItems = sel;
- }
- } else {
- action.setEnabled(false);
- }
- } catch (Exception e) {
- Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ boolean validResourceSet = ActionUtils.checkResourceSet(selection, true);
+ if (validResourceSet) {
+ action.setEnabled(true);
+ selectedItems = (IStructuredSelection)selection;
+ } else {
+ action.setEnabled(false);
+ selectedItems = null;
}
}
}
Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/GuvnorCompareEditorInput.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/GuvnorCompareEditorInput.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/GuvnorCompareEditorInput.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -0,0 +1,31 @@
+package org.guvnor.tools.actions;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.structuremergeviewer.Differencer;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * A simple compare editor input for text files.
+ * @author jgraham
+ */
+public class GuvnorCompareEditorInput extends CompareEditorInput {
+
+ private GuvnorResourceEdition left;
+ private GuvnorResourceEdition right;
+
+ public GuvnorCompareEditorInput(GuvnorResourceEdition left, GuvnorResourceEdition right) {
+ super(new CompareConfiguration());
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ protected Object prepareInput(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ Differencer diff = new Differencer();
+ return diff.findDifferences(false, null, null, null, left, right);
+ }
+}
Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/GuvnorResourceEdition.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/GuvnorResourceEdition.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/GuvnorResourceEdition.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -0,0 +1,57 @@
+package org.guvnor.tools.actions;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.compare.IStreamContentAccessor;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.swt.graphics.Image;
+import org.guvnor.tools.Activator;
+
+/**
+ * Represents compare input contents.
+ * @author jgraham
+ *
+ */
+public class GuvnorResourceEdition implements IStreamContentAccessor, ITypedElement {
+
+ private String contents;
+ private Image image;
+ private String name;
+ private String type;
+ private String encoding;
+
+ public GuvnorResourceEdition(String name, String type, String contents, String encoding) {
+ this.name = name;
+ this.type = type;
+ this.contents = contents;
+ this.encoding = encoding;
+ }
+
+ public InputStream getContents() throws CoreException {
+ byte[] bytes = null;
+ try {
+ bytes = contents.getBytes(encoding);
+ } catch (UnsupportedEncodingException e) {
+ Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ // Better than nothing?
+ bytes = contents.getBytes();
+ }
+ return new ByteArrayInputStream(bytes);
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -10,11 +10,11 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.webdav.IResponse;
import org.guvnor.tools.Activator;
+import org.guvnor.tools.utils.ActionUtils;
import org.guvnor.tools.utils.GuvnorMetadataProps;
import org.guvnor.tools.utils.GuvnorMetadataUtils;
import org.guvnor.tools.utils.PlatformUtils;
@@ -35,13 +35,13 @@
super();
}
- /**
+ /*
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
- /**
+ /*
* @throws Exception
* @see IActionDelegate#run(IAction)
*/
@@ -104,37 +104,18 @@
}
}
- /**
+ /*
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
- @SuppressWarnings("unchecked")
public void selectionChanged(IAction action, ISelection selection) {
- // Reset state to default
- selectedItems = null;
- action.setEnabled(true);
- // See if we should enable for the selection
- try {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection sel = (IStructuredSelection)selection;
- for (Iterator<Object> it = sel.iterator(); it.hasNext();) {
- Object oneSelection = it.next();
- if (oneSelection instanceof IFile) {
- GuvnorMetadataProps props = GuvnorMetadataUtils.
- getGuvnorMetadata((IFile)oneSelection);
- if (props == null) {
- action.setEnabled(false);
- break;
- }
- }
- }
- if (action.isEnabled()) {
- selectedItems = sel;
- }
- } else {
- action.setEnabled(false);
- }
- } catch (Exception e) {
- Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ boolean validResourceSet = ActionUtils.checkResourceSet(selection, true)
+ && ActionUtils.areFilesDirty(selection);
+ if (validResourceSet) {
+ action.setEnabled(true);
+ selectedItems = (IStructuredSelection)selection;
+ } else {
+ action.setEnabled(false);
+ selectedItems = null;
}
}
}
Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/ActionUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/ActionUtils.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/ActionUtils.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -0,0 +1,65 @@
+package org.guvnor.tools.utils;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.guvnor.tools.Activator;
+
+public class ActionUtils {
+
+ @SuppressWarnings("unchecked")
+ public static boolean checkResourceSet(ISelection selection, boolean guvnorControlled) {
+ boolean res = true;
+ try {
+ if (!(selection instanceof IStructuredSelection)) {
+ return false;
+ }
+ IStructuredSelection sel = (IStructuredSelection)selection;
+ for (Iterator<Object> it = sel.iterator(); it.hasNext();) {
+ Object oneSelection = it.next();
+ if (oneSelection instanceof IFile) {
+ GuvnorMetadataProps props =
+ GuvnorMetadataUtils.getGuvnorMetadata((IFile)oneSelection);
+ if ((guvnorControlled && props == null)
+ || (!guvnorControlled && props != null)) {
+ res = false;
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ res = false;
+ }
+ return res;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static boolean areFilesDirty(ISelection selection) {
+ boolean res = true;
+ try {
+ if (!(selection instanceof IStructuredSelection)) {
+ return false;
+ }
+ IStructuredSelection sel = (IStructuredSelection)selection;
+ for (Iterator<Object> it = sel.iterator(); it.hasNext();) {
+ Object oneSelection = it.next();
+ if (oneSelection instanceof IFile) {
+ boolean isCurrent =
+ GuvnorMetadataUtils.isGuvnorResourceCurrent((IFile)oneSelection);
+ if (isCurrent) {
+ res = false;
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ res = false;
+ }
+ return res;
+ }
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavClient.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavClient.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavClient.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -122,13 +122,8 @@
resProps.setLastModifiedDate(dateStamp);
resProps.setRevision(revision);
}
-// else {
-// Exception nfe = new Exception("Failed to get Guvnor properties for " + oneKey);
-// Activator.getDefault().writeLog(IStatus.WARNING, nfe.getMessage(), nfe);
-// }
}
} catch (Exception e) {
- //TODO: Getting some server internal errors here. Why?
Activator.getDefault().writeLog(IStatus.WARNING, e.getMessage(), e);
} finally {
if (response != null) {
@@ -200,7 +195,6 @@
Activator.getDefault().writeLog(IStatus.WARNING, nfe.getMessage(), nfe);
}
} catch (Exception e) {
- //TODO: Getting some server internal errors here. Why?
Activator.getDefault().writeLog(IStatus.WARNING, e.getMessage(), e);
} finally {
if (response != null) {
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/RepositoryView.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/RepositoryView.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/RepositoryView.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -60,6 +60,7 @@
private Action deleteRepositoryLocAction;
private Action addRepositoryLocAction;
private Action doubleClickAction;
+ private Action refreshAction;
class NameSorter extends ViewerSorter {
}
@@ -213,11 +214,14 @@
manager.add(deleteRepositoryLocAction);
manager.add(new Separator());
manager.add(addRepositoryLocAction);
+ manager.add(new Separator());
+ manager.add(refreshAction);
}
private void fillContextMenu(IMenuManager manager) {
manager.add(deleteRepositoryLocAction);
manager.add(addRepositoryLocAction);
+ manager.add(refreshAction);
manager.add(new Separator());
drillDownAdapter.addNavigationActions(manager);
// Other plug-ins can contribute there actions here
@@ -265,6 +269,7 @@
addRepositoryLocAction.setToolTipText("Add a Guvnor respository location");
addRepositoryLocAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD));
+
doubleClickAction = new Action() {
public void run() {
ISelection selection = viewer.getSelection();
@@ -274,6 +279,22 @@
}
}
};
+
+ refreshAction = new Action() {
+ public void run() {
+ ISelection selection = viewer.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection strucSel = (IStructuredSelection)selection;
+ if (!strucSel.isEmpty()) {
+ viewer.refresh(strucSel.getFirstElement());
+ }
+ }
+ }
+ };
+ refreshAction.setText("Refresh");
+ refreshAction.setToolTipText("Refreshes the current node and its children");
+ refreshAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+ getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
}
private void hookDoubleClickAction() {
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/CheckoutWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/CheckoutWizard.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/CheckoutWizard.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -3,9 +3,12 @@
import java.io.ByteArrayInputStream;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
@@ -104,13 +107,19 @@
}
String contents = webdav.getResourceContents(oneResource);
IPath targetLocation = new Path(model.getTargetLocation());
- IFile targetFile = Activator.getDefault().getWorkspace().
- getRoot().getFile(targetLocation.append(
+ IWorkspaceRoot root = Activator.getDefault().getWorkspace().getRoot();
+ IFile targetFile = root.getFile(
+ targetLocation.append(
oneResource.substring(oneResource.lastIndexOf('/'))));
+ if (targetFile.exists()) {
+ targetFile = resolveNameConflict(targetFile);
+ }
+ if (targetFile == null) {
+ continue;
+ }
ByteArrayInputStream bis =
new ByteArrayInputStream(contents.getBytes(targetFile.getCharset()));
if (targetFile.exists()) {
- //TODO: Prompt for overwrite
targetFile.setContents(bis, true, true, null);
} else {
targetFile.create(bis, true, null);
@@ -128,10 +137,33 @@
}
return true;
}
-
- public void init(IWorkbench workbench, IStructuredSelection selection) {
-
+
+ public IFile resolveNameConflict(IFile conflictingFile) {
+ final IWorkspaceRoot root = Activator.getDefault().getWorkspace().getRoot();
+ final IPath basePath = conflictingFile.getFullPath().removeLastSegments(1);
+ InputDialog dialog = new InputDialog(super.getShell(),
+ "Name Conflict",
+ "Enter a new name for " + conflictingFile.getName(),
+ "CopyOf" + conflictingFile.getName(),
+ new IInputValidator() {
+ public String isValid(String newText) {
+ IFile temp = root.getFile(basePath.append(newText));
+ if (temp == null
+ || !temp.exists()) {
+ return null;
+ } else {
+ return newText + " already exists";
+ }
+ }
+ });
+ if (dialog.open() == InputDialog.OK) {
+ return root.getFile(basePath.append(dialog.getValue()));
+ } else {
+ return null;
+ }
}
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) { }
@Override
public boolean canFinish() {
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/SelectGuvnorFolderPage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/SelectGuvnorFolderPage.java 2008-07-16 17:39:52 UTC (rev 21071)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/SelectGuvnorFolderPage.java 2008-07-16 20:29:05 UTC (rev 21072)
@@ -6,6 +6,8 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
@@ -44,6 +46,18 @@
updateModel();
}
});
+ viewer.addFilter(new ViewerFilter() {
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ // The snapshots directory in Guvnor is read-only for Eclipse tools
+ if (element instanceof TreeObject) {
+ TreeObject o = (TreeObject)element;
+ return o.getFullPath().indexOf("/snapshots/") == -1;
+ } else {
+ return true;
+ }
+ }
+ });
super.setControl(composite);
}
More information about the jboss-svn-commits
mailing list