[jboss-svn-commits] JBL Code SVN: r21093 - in labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools: META-INF and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 17 17:02:16 EDT 2008
Author: john.graham at jboss.org
Date: 2008-07-17 17:02:16 -0400 (Thu, 17 Jul 2008)
New Revision: 21093
Added:
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/GuvnorPreferencePage.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/IGuvnorPreferenceConstants.java
Modified:
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/build.properties
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.properties
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/GuvnorDecorator.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/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/RepositoryElementPropsAction.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/SwitchVersionAction.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/properties/RepositoryElementPropsDialog.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/AuthenticationPromptDialog.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/AddResourceWizard.java
labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorMainConfigPage.java
Log:
Preference page, Guvnor domain rules
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-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF 2008-07-17 21:02:16 UTC (rev 21093)
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.guvnor.tools;singleton:=true
-Bundle-Version: 0.6.0.200807161700
+Bundle-Version: 0.6.0.200807171645
Bundle-Activator: org.guvnor.tools.Activator
Bundle-Vendor: %plugin.provider
Bundle-Localization: plugin
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/build.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/build.properties 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/build.properties 2008-07-17 21:02:16 UTC (rev 21093)
@@ -5,6 +5,7 @@
.,\
icons/,\
about.html,\
- plugin.properties
+ plugin.properties,\
+ .options
src.includes = about.html,\
src/
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.properties 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.properties 2008-07-17 21:02:16 UTC (rev 21093)
@@ -17,6 +17,8 @@
persp.name = Guvnor Repository Exploring
+preferences.guvnor.page = Guvnor
+
decorator.desc = Guvnor resource decorator
action.properties = Properties
action.properties.tooltip = Show properties for the selected element
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml 2008-07-17 21:02:16 UTC (rev 21093)
@@ -155,7 +155,11 @@
name="%category.name"
class="org.guvnor.tools.properties.GuvnorWorkspaceFilePage"/>
</extension>
-
+ <extension point="org.eclipse.ui.preferencePages">
+ <page name="%preferences.guvnor.page"
+ class="org.guvnor.tools.preferences.GuvnorPreferencePage"
+ id="org.guvnor.tools.preferences.guvnorpreferencepage"/>
+ </extension>
<extension point="org.eclipse.ui.decorators">
<decorator lightweight="true" adaptable="true"
label="%category.name" state="true"
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/GuvnorDecorator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/GuvnorDecorator.java 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/GuvnorDecorator.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -2,13 +2,19 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
+import org.guvnor.tools.preferences.GuvnorPreferencePage;
+import org.guvnor.tools.preferences.IGuvnorPreferenceConstants;
import org.guvnor.tools.utils.GuvnorMetadataProps;
import org.guvnor.tools.utils.GuvnorMetadataUtils;
-
+/**
+ * Handles decorating Guvnor resources with an icon overlay and label text.
+ * @author jgraham
+ */
public class GuvnorDecorator implements ILightweightLabelDecorator {
public static final String DECORATOR_ID = "org.guvnor.tools.decorator";
@@ -23,21 +29,53 @@
private void decorateResource(IResource resource, IDecoration decoration) {
try {
- if (resource instanceof IFile) {
- decoration.addOverlay(Activator.getImageDescriptor(Activator.IMG_GUVCONTROLLED),
- IDecoration.TOP_RIGHT);
- if (!GuvnorMetadataUtils.isGuvnorResourceCurrent(resource)) {
- decoration.addSuffix(" >");
- }
- GuvnorMetadataProps props = GuvnorMetadataUtils.getGuvnorMetadata(resource);
- if (props.getVersion() != null) {
- decoration.addSuffix(" " + props.getRevision() + ", " + props.getVersion());
- }
+ if (resource instanceof IFile) {
+ addGuvnorOverlay(decoration);
+ addChangeIndicator(resource, decoration);
+ addResourceDetails(resource, decoration);
}
} catch (Exception e) {
Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
}
}
+
+ private void addGuvnorOverlay(IDecoration decoration) {
+ int overlayLoc = GuvnorPreferencePage.getOverlayLocationPref();
+ if (overlayLoc != IGuvnorPreferenceConstants.NO_OVERLAY) {
+ decoration.addOverlay(Activator.getImageDescriptor(Activator.IMG_GUVCONTROLLED),
+ overlayLoc);
+ }
+ }
+
+ private void addResourceDetails(IResource resource, IDecoration decoration)
+ throws Exception {
+ GuvnorMetadataProps props = GuvnorMetadataUtils.getGuvnorMetadata(resource);
+ if (props.getVersion() != null) {
+ boolean showRevision = GuvnorPreferencePage.shouldShowRevision();
+ boolean showDateTime = GuvnorPreferencePage.shouldShowTimeDateStamp();
+ if (showRevision || showDateTime) {
+ decoration.addSuffix(" ");
+ }
+ if (showRevision) {
+ decoration.addSuffix(props.getRevision());
+ }
+ if (showDateTime) {
+ if (showRevision) {
+ decoration.addSuffix(", " + props.getVersion());
+ } else {
+ decoration.addSuffix(props.getVersion());
+ }
+ }
+ }
+ }
+
+ private void addChangeIndicator(IResource resource, IDecoration decoration)
+ throws CoreException {
+ if (!GuvnorMetadataUtils.isGuvnorResourceCurrent(resource)
+ && GuvnorPreferencePage.shouldShowChangeIndicator()) {
+ decoration.addSuffix(" >");
+ }
+ }
public void decorate(Object element, IDecoration decoration) {
if (isGuvnorResource(element)) {
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-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -6,6 +6,7 @@
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.IObjectActionDelegate;
@@ -25,6 +26,7 @@
public class CommitAction implements IObjectActionDelegate {
private IStructuredSelection selectedItems;
+ private IWorkbenchPart targetPart;
/**
* Constructor for Action1.
@@ -37,6 +39,7 @@
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ this.targetPart = targetPart;
}
/*
@@ -51,6 +54,7 @@
processCommit((IFile)oneSelection);
}
}
+ PlatformUtils.updateDecoration();
}
private void processCommit(IFile selectedFile) {
@@ -61,8 +65,9 @@
client = WebDavClientFactory.createClient(new URL(props.getRepository()));
WebDavServerCache.cacheWebDavClient(props.getRepository(), client);
}
+ ResourceProperties remoteProps = null;
try {
- client.putResource(props.getFullpath(), selectedFile.getContents());
+ remoteProps = client.queryProperties(props.getFullpath());
} catch (WebDavException wde) {
if (wde.getErrorCode() != IResponse.SC_UNAUTHORIZED) {
// If not an authentication failure, we don't know what to do with it
@@ -71,16 +76,33 @@
boolean retry = PlatformUtils.getInstance().
authenticateForServer(props.getRepository(), client);
if (retry) {
- client.putResource(props.getFullpath(), selectedFile.getContents());
+ remoteProps = client.queryProperties(props.getFullpath());
}
}
- GuvnorMetadataUtils.markCurrentGuvnorResource(selectedFile);
- ResourceProperties resProps = client.queryProperties(props.getFullpath());
- GuvnorMetadataProps mdProps = GuvnorMetadataUtils.getGuvnorMetadata(selectedFile);
- mdProps.setVersion(resProps.getLastModifiedDate());
- mdProps.setRevision(resProps.getRevision());
- GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
- PlatformUtils.updateDecoration();
+ if (remoteProps == null) {
+ throw new Exception("Could not retrieve server version of " + props.getFullpath());
+ }
+ // Check to make sure that the version in the repository is the same as the base
+ // version for the local copy
+ boolean proceed = true;
+ if (!props.getRevision().equals(remoteProps.getRevision())) {
+ String msg = "The Guvnor revision for " + selectedFile.getName() + " is " +
+ remoteProps.getRevision() + ", but the local copy is based on revision " +
+ props.getRevision() +
+ ".\r\nOverwrite Guvnor repository revision with current local file contents?";
+ proceed = MessageDialog.openQuestion(targetPart.getSite().getShell(),
+ "Revision Conflict", msg);
+
+ }
+ if (proceed) {
+ client.putResource(props.getFullpath(), selectedFile.getContents());
+ GuvnorMetadataUtils.markCurrentGuvnorResource(selectedFile);
+ ResourceProperties resProps = client.queryProperties(props.getFullpath());
+ GuvnorMetadataProps mdProps = GuvnorMetadataUtils.getGuvnorMetadata(selectedFile);
+ mdProps.setVersion(resProps.getLastModifiedDate());
+ mdProps.setRevision(resProps.getRevision());
+ GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
+ }
} catch (Exception e) {
Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
}
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-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DeleteAction.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -69,6 +69,7 @@
}
DisconnectAction dsAction = new DisconnectAction();
dsAction.disconnect(selectedItems);
+ PlatformUtils.updateDecoration();
PlatformUtils.refreshRepositoryView();
}
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-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/DisconnectAction.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -43,6 +43,7 @@
return;
}
disconnect(selectedItems);
+ PlatformUtils.updateDecoration();
}
@SuppressWarnings("unchecked")
@@ -62,7 +63,6 @@
toDelete.toArray(mdFiles);
IWorkspace ws = Activator.getDefault().getWorkspace();
ws.delete(mdFiles, true, null);
- PlatformUtils.updateDecoration();
} catch (CoreException e) {
Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/RepositoryElementPropsAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/RepositoryElementPropsAction.java 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/RepositoryElementPropsAction.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -1,19 +1,19 @@
package org.guvnor.tools.actions;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
-import org.guvnor.tools.Activator;
import org.guvnor.tools.properties.RepositoryElementPropsDialog;
-import org.guvnor.tools.utils.PlatformUtils;
import org.guvnor.tools.views.model.TreeObject;
+/**
+ * Action for showing properties for a Guvnor repository element.
+ * @author jgraham
+ */
public class RepositoryElementPropsAction implements IViewActionDelegate {
private TreeObject node;
@@ -28,17 +28,7 @@
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().
getActivePage().getActivePart().getSite().getShell();
RepositoryElementPropsDialog diag = new RepositoryElementPropsDialog(shell, node);
- if (diag.open() == Dialog.OK
- && diag.wereSecuritySettingModified()) {
- // Have to update security settings for this repository
- try {
- PlatformUtils.getInstance().
- updateAuthentication(node.getGuvnorRepository().getLocation(),
- diag.getUsername(), diag.getPassword(), diag.saveAuthenInfo());
- } catch (Exception e) {
- Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
- }
- }
+ diag.open();
}
public void selectionChanged(IAction action, ISelection selection) {
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/SwitchVersionAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/SwitchVersionAction.java 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/SwitchVersionAction.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -63,6 +63,7 @@
getVersionEntries());
if (dialog.open() == VersionChooserDialog.OK) {
updateSelectedFile(dialog.getSelectedEntry());
+ PlatformUtils.updateDecoration();
}
}
@@ -78,7 +79,6 @@
mdProps.setVersion(verInfo.getDate());
mdProps.setRevision(verInfo.getRevision());
GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
- PlatformUtils.updateDecoration();
}
} catch (Exception e) {
Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
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-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -38,8 +38,7 @@
/*
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- }
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) { }
/*
* @throws Exception
@@ -54,6 +53,7 @@
processUpdate((IFile)oneItem);
}
}
+ PlatformUtils.updateDecoration();
}
private void processUpdate(IFile selectedFile) {
@@ -89,7 +89,6 @@
mdProps.setVersion(resProps.getLastModifiedDate());
mdProps.setRevision(resProps.getRevision());
GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
- PlatformUtils.updateDecoration();
}
} catch (Exception e) {
Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
@@ -104,12 +103,78 @@
}
}
+ private ResourceProperties getRemoteResourceProps(IFile file, GuvnorMetadataProps localProps) {
+ ResourceProperties remoteProps = null;
+ try {
+ IWebDavClient client = WebDavServerCache.getWebDavClient(localProps.getRepository());
+ if (client == null) {
+ client = WebDavClientFactory.createClient(new URL(localProps.getRepository()));
+ WebDavServerCache.cacheWebDavClient(localProps.getRepository(), client);
+ }
+ try {
+ remoteProps = client.queryProperties(localProps.getFullpath());
+ } 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(localProps.getRepository(), client);
+ if (retry) {
+ remoteProps = client.queryProperties(localProps.getFullpath());
+ }
+ }
+ } catch (Exception e) {
+ Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ }
+ return remoteProps;
+ }
+
+ @SuppressWarnings("unchecked")
+ private boolean hasChangedRevision(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) {
+ GuvnorMetadataProps localProps =
+ GuvnorMetadataUtils.getGuvnorMetadata((IFile)oneSelection);
+ if (localProps != null) {
+ ResourceProperties remoteProps =
+ getRemoteResourceProps((IFile)oneSelection, localProps);
+ if (remoteProps == null) {
+ res = false;
+ break;
+ }
+ if (remoteProps.getRevision().equals(localProps.getRevision())) {
+ res = false;
+ break;
+ }
+ } else {
+ res = false;
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+ res = false;
+ }
+ return res;
+ }
+
/*
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
- boolean validResourceSet = ActionUtils.checkResourceSet(selection, true)
- && ActionUtils.areFilesDirty(selection);
+ boolean validResourceSet =
+ (ActionUtils.checkResourceSet(selection, true) && ActionUtils.areFilesDirty(selection))
+ || hasChangedRevision(selection);
+
if (validResourceSet) {
action.setEnabled(true);
selectedItems = (IStructuredSelection)selection;
Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/GuvnorPreferencePage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/GuvnorPreferencePage.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/GuvnorPreferencePage.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -0,0 +1,245 @@
+package org.guvnor.tools.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+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.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.guvnor.tools.Activator;
+import org.guvnor.tools.utils.PlatformUtils;
+
+/**
+ * Page for setting Guvnor preferences.
+ * @author jgraham
+ */
+public class GuvnorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+ private Text guvnorURLTemplate;
+ private Button savePassword;
+ private Combo decorationIconLoc;
+ private Button incChangeIndicator;
+ private Button incRevision;
+ private Button incDateStamp;
+
+ public GuvnorPreferencePage() {
+ }
+
+ public GuvnorPreferencePage(String title) {
+ super(title);
+ }
+
+ public GuvnorPreferencePage(String title, ImageDescriptor image) {
+ super(title, image);
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite composite = PlatformUtils.createComposite(parent, 1);
+
+ Group group = new Group(composite, SWT.NONE);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ group.setLayoutData(data);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ group.setLayout(layout);
+ group.setText("Repository Connections");
+
+ Composite doubleLine = PlatformUtils.createComposite(group, 2);
+ new Label(doubleLine, SWT.NONE).setText("Guvnor URL template: ");
+ guvnorURLTemplate = new Text(doubleLine, SWT.BORDER);
+ guvnorURLTemplate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ guvnorURLTemplate.setText(getGuvnorTemplatePref());
+
+ savePassword = new Button(group, SWT.CHECK);
+ savePassword.setText("Save passwords in platform key-ring");
+ savePassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ savePassword.setSelection(true);
+
+ group = new Group(composite, SWT.NONE);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ group.setLayoutData(data);
+ layout = new GridLayout();
+ layout.numColumns = 1;
+ group.setLayout(layout);
+ group.setText("File Decoration");
+
+ doubleLine = PlatformUtils.createComposite(group, 2);
+ new Label(doubleLine, SWT.NONE).setText("Icon decoration location: ");
+ decorationIconLoc = new Combo(doubleLine, SWT.BORDER | SWT.DROP_DOWN);
+ String[] locs = IGuvnorPreferenceConstants.OVERLAY_LOCATIONS;
+ for (int i = 0; i < locs.length; i++) {
+ decorationIconLoc.add(locs[i]);
+ }
+ decorationIconLoc.select(getOverlayLocationPref());
+
+ Group textDec = new Group(group, SWT.NONE);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ textDec.setLayoutData(data);
+ layout = new GridLayout();
+ layout.numColumns = 1;
+ textDec.setLayout(layout);
+ textDec.setText("Text");
+
+ incChangeIndicator = new Button(textDec, SWT.CHECK);
+ incChangeIndicator.setText("Include change indication (>)");
+ incChangeIndicator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ incChangeIndicator.setSelection(shouldShowChangeIndicator());
+
+ incRevision = new Button(textDec, SWT.CHECK);
+ incRevision.setText("Include revision");
+ incRevision.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ incRevision.setSelection(shouldShowRevision());
+
+ incDateStamp = new Button(textDec, SWT.CHECK);
+ incDateStamp.setText("Include date/time stamp");
+ incDateStamp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ incDateStamp.setSelection(shouldShowTimeDateStamp());
+
+ return composite;
+ }
+
+
+ @Override
+ protected IPreferenceStore doGetPreferenceStore() {
+ return Activator.getDefault().getPreferenceStore();
+ }
+
+ public void init(IWorkbench workbench) { }
+
+ @Override
+ protected void performDefaults() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ store.putValue(IGuvnorPreferenceConstants.GUVNOR_LOC_TEMPLATE_PREF,
+ IGuvnorPreferenceConstants.GUVNOR_LOC_TEMPLATE_DEFAULT);
+ guvnorURLTemplate.setText(IGuvnorPreferenceConstants.GUVNOR_LOC_TEMPLATE_DEFAULT);
+
+ store.putValue(IGuvnorPreferenceConstants.SAVE_PASSWORDS_PREF,
+ String.valueOf(true));
+ savePassword.setSelection(true);
+
+ store.putValue(IGuvnorPreferenceConstants.OVERLAY_LOCATION_PREF,
+ String.valueOf(IGuvnorPreferenceConstants.OVERLAY_LOCATION_DEFAULT));
+ decorationIconLoc.select(IGuvnorPreferenceConstants.OVERLAY_LOCATION_DEFAULT);
+
+ store.putValue(IGuvnorPreferenceConstants.SHOW_CHANGE_INDICATOR_PREF,
+ String.valueOf(true));
+ incChangeIndicator.setSelection(true);
+
+ store.putValue(IGuvnorPreferenceConstants.SHOW_REVISION_PREF,
+ String.valueOf(true));
+ incRevision.setSelection(true);
+
+ store.putValue(IGuvnorPreferenceConstants.SHOW_DATETIME_PREF,
+ String.valueOf(true));
+ incDateStamp.setSelection(true);
+
+ PlatformUtils.updateDecoration();
+ super.performDefaults();
+ }
+
+ @Override
+ public boolean performOk() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ store.putValue(IGuvnorPreferenceConstants.GUVNOR_LOC_TEMPLATE_PREF,
+ guvnorURLTemplate.getText());
+
+ store.putValue(IGuvnorPreferenceConstants.SAVE_PASSWORDS_PREF,
+ String.valueOf(savePassword.getSelection()));
+
+ store.putValue(IGuvnorPreferenceConstants.OVERLAY_LOCATION_PREF,
+ String.valueOf(decorationIconLoc.getSelectionIndex()));
+
+ store.putValue(IGuvnorPreferenceConstants.SHOW_CHANGE_INDICATOR_PREF,
+ String.valueOf(incChangeIndicator.getSelection()));
+
+ store.putValue(IGuvnorPreferenceConstants.SHOW_REVISION_PREF,
+ String.valueOf(incRevision.getSelection()));
+
+ store.putValue(IGuvnorPreferenceConstants.SHOW_DATETIME_PREF,
+ String.valueOf(incDateStamp.getSelection()));
+
+ PlatformUtils.updateDecoration();
+ return super.performOk();
+ }
+
+ public static String getGuvnorTemplatePref() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ String res = null;
+ if (!store.contains(IGuvnorPreferenceConstants.GUVNOR_LOC_TEMPLATE_PREF)) {
+ res = IGuvnorPreferenceConstants.GUVNOR_LOC_TEMPLATE_DEFAULT;
+ store.putValue(IGuvnorPreferenceConstants.GUVNOR_LOC_TEMPLATE_PREF, res);
+ } else {
+ res = store.getString(IGuvnorPreferenceConstants.GUVNOR_LOC_TEMPLATE_PREF);
+ }
+ return res;
+ }
+
+ public static boolean shouldSavePasswords() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ boolean res = true;
+ if (!store.contains(IGuvnorPreferenceConstants.SAVE_PASSWORDS_PREF)) {
+ store.putValue(IGuvnorPreferenceConstants.SAVE_PASSWORDS_PREF, String.valueOf(true));
+ } else {
+ res = store.getBoolean(IGuvnorPreferenceConstants.SAVE_PASSWORDS_PREF);
+ }
+ return res;
+ }
+
+ public static int getOverlayLocationPref() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ int res = 0;
+ if (!store.contains(IGuvnorPreferenceConstants.OVERLAY_LOCATION_PREF)) {
+ store.putValue(IGuvnorPreferenceConstants.OVERLAY_LOCATION_PREF,
+ String.valueOf(IGuvnorPreferenceConstants.OVERLAY_LOCATION_DEFAULT));
+ res = IGuvnorPreferenceConstants.OVERLAY_LOCATION_DEFAULT;
+ } else {
+ res = store.getInt(IGuvnorPreferenceConstants.OVERLAY_LOCATION_PREF);
+ }
+ return res;
+ }
+
+ public static boolean shouldShowChangeIndicator() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ boolean res = true;
+ if (!store.contains(IGuvnorPreferenceConstants.SHOW_CHANGE_INDICATOR_PREF)) {
+ store.putValue(IGuvnorPreferenceConstants.SHOW_CHANGE_INDICATOR_PREF, String.valueOf(true));
+ } else {
+ res = store.getBoolean(IGuvnorPreferenceConstants.SHOW_CHANGE_INDICATOR_PREF);
+ }
+ return res;
+ }
+
+ public static boolean shouldShowRevision() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ boolean res = true;
+ if (!store.contains(IGuvnorPreferenceConstants.SHOW_REVISION_PREF)) {
+ store.putValue(IGuvnorPreferenceConstants.SHOW_REVISION_PREF, String.valueOf(true));
+ } else {
+ res = store.getBoolean(IGuvnorPreferenceConstants.SHOW_REVISION_PREF);
+ }
+ return res;
+ }
+
+ public static boolean shouldShowTimeDateStamp() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ boolean res = true;
+ if (!store.contains(IGuvnorPreferenceConstants.SHOW_DATETIME_PREF)) {
+ store.putValue(IGuvnorPreferenceConstants.SHOW_DATETIME_PREF, String.valueOf(true));
+ } else {
+ res = store.getBoolean(IGuvnorPreferenceConstants.SHOW_DATETIME_PREF);
+ }
+ return res;
+ }
+}
Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/IGuvnorPreferenceConstants.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/IGuvnorPreferenceConstants.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/preferences/IGuvnorPreferenceConstants.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -0,0 +1,38 @@
+package org.guvnor.tools.preferences;
+/**
+ * Constants for Guvnor tools preference names and values.
+ * @author jgraham
+ */
+public interface IGuvnorPreferenceConstants {
+
+ // Value is a string, specified in GUVNOR_LOC_TEMPLATE_DEFAULT
+ public String GUVNOR_LOC_TEMPLATE_PREF = "guvnor_loc_template";
+
+ public String GUVNOR_LOC_TEMPLATE_DEFAULT = "http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/webdav";
+
+ public String SAVE_PASSWORDS_PREF = "save_passwords";
+
+ // Value it an integer, specified in OVERLAY_LOCATIONS
+ public String OVERLAY_LOCATION_PREF = "overlay_location";
+
+ // Text for the corresponding IDecoration overlay locations, 0 -> 3. 4 is for "don't display"
+ public String[] OVERLAY_LOCATIONS = { "Top left",
+ "Top right",
+ "Bottom left",
+ "Bottom right",
+ "<None>" };
+
+ public int NO_OVERLAY = 4;
+
+ // The default location is top right
+ public int OVERLAY_LOCATION_DEFAULT = 1;
+
+ // Value is a boolean, true by default
+ public String SHOW_CHANGE_INDICATOR_PREF = "show_change_indicator";
+
+ // Value is a boolean, true by default
+ public String SHOW_REVISION_PREF = "show_revision";
+
+ // Value is a boolean, true by default
+ public String SHOW_DATETIME_PREF = "show_datetime";
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/properties/RepositoryElementPropsDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/properties/RepositoryElementPropsDialog.java 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/properties/RepositoryElementPropsDialog.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -8,13 +8,8 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
@@ -28,7 +23,10 @@
import org.guvnor.tools.Activator;
import org.guvnor.tools.utils.PlatformUtils;
import org.guvnor.tools.views.model.TreeObject;
-
+/**
+ * Shows properties for a Guvnor repository element.
+ * @author jgraham
+ */
public class RepositoryElementPropsDialog extends TitleAreaDialog {
private static final int INITIAL_WIDTH = 780;
@@ -37,13 +35,7 @@
private TreeObject node;
private Text unField;
private Text pwField;
- private Button cbSavePassword;
- private String username;
- private String password;
- private boolean saveInfo;
- private Label warningLabel;
-
public RepositoryElementPropsDialog(Shell parentShell, TreeObject node) {
super(parentShell);
super.setShellStyle(getShellStyle() | SWT.RESIZE);
@@ -94,52 +86,13 @@
new Label(composite, SWT.NONE).setText("User Name: ");
unField = new Text(composite, SWT.SINGLE | SWT.BORDER);
unField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- unField.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- username = unField.getText();
- }
- });
+ unField.setEditable(false);
new Label(composite, SWT.NONE).setText("Password: ");
pwField = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
pwField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- pwField.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- password = pwField.getText();
- }
- });
-
- new Label(composite, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- Composite pwgroup = PlatformUtils.createComposite(composite, 2);
- cbSavePassword = new Button(pwgroup, SWT.CHECK);
- cbSavePassword.addSelectionListener(new SelectionListener() {
-
- public void widgetDefaultSelected(SelectionEvent e) { }
-
- public void widgetSelected(SelectionEvent e) {
- saveInfo = cbSavePassword.getSelection();
- warningLabel.setEnabled(saveInfo);
- }
-
- });
-
- new Label(pwgroup, SWT.NONE).setText("Save user name and password");
-
- new Label(composite, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- warningLabel = new Label(composite, SWT.WRAP);
- warningLabel.setText("NOTE: Saved passwords are stored on your computer in a file that is difficult, but not impossible, for an intruder to read.");
-
+ pwField.setEditable(false);
populateSecuritySettings();
- if (unField.getText().trim().length() == 0) {
- cbSavePassword.setSelection(false);
- warningLabel.setEnabled(false);
- } else {
- // WTF? setSelection(true) is not picked up by the control, so we have to set
- // this initial value explicitly. After that toggle seems to work...
- saveInfo = true;
- cbSavePassword.setSelection(true);
- }
}
@SuppressWarnings("unchecked")
@@ -168,23 +121,4 @@
// Try to set a reasonable default size.
return new Point(INITIAL_WIDTH, INITIAL_HEIGHT);
}
-
- public String getUsername() {
- return username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public boolean saveAuthenInfo() {
- return saveInfo;
- }
-
- public boolean wereSecuritySettingModified() {
- // If username or password is not null,
- // then the user changed the text in at least
- // one of those boxes.
- return username != null || password != null;
- }
}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/AuthenticationPromptDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/AuthenticationPromptDialog.java 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/AuthenticationPromptDialog.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -15,6 +15,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.guvnor.tools.Activator;
+import org.guvnor.tools.preferences.GuvnorPreferencePage;
/**
* A dialog for collecting user authentication information
@@ -85,14 +86,16 @@
});
// WTF? setSelection(true) is not picked up by the control, so we have to set
// this initial value explicitly. After that toggle seems to work...
- saveInfo = true;
- cbSavePassword.setSelection(true);
+ boolean shouldSavePasswords = GuvnorPreferencePage.shouldSavePasswords();
+ saveInfo = shouldSavePasswords;
+ cbSavePassword.setSelection(shouldSavePasswords);
new Label(pwgroup, SWT.NONE).setText("Save user name and password");
new Label(composite, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
warningLabel = new Label(composite, SWT.WRAP);
warningLabel.setText("NOTE: Saved passwords are stored on your computer in a file that is difficult, but not impossible, for an intruder to read.");
+ warningLabel.setEnabled(shouldSavePasswords);
return super.createDialogArea(parent);
}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/AddResourceWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/AddResourceWizard.java 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/AddResourceWizard.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -123,7 +123,6 @@
fullPath, resProps.getLastModifiedDate(),
resProps.getRevision());
GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
- PlatformUtils.updateDecoration();
}
} catch (Exception e) {
Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
@@ -145,6 +144,7 @@
}
}
}
+ PlatformUtils.updateDecoration();
return res;
}
Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorMainConfigPage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorMainConfigPage.java 2008-07-17 20:34:39 UTC (rev 21092)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorMainConfigPage.java 2008-07-17 21:02:16 UTC (rev 21093)
@@ -5,6 +5,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
@@ -23,6 +24,7 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.guvnor.tools.Activator;
+import org.guvnor.tools.preferences.GuvnorPreferencePage;
import org.guvnor.tools.utils.PlatformUtils;
public class GuvnorMainConfigPage extends WizardPage {
@@ -111,15 +113,18 @@
}
});
+
+ boolean shouldSavePasswords = GuvnorPreferencePage.shouldSavePasswords();
// WTF? setSelection(true) is not picked up by the control, so we have to set
// this initial value explicitly. After that toggle seems to work...
- saveAuthInfo = true;
- cbSavePassword.setSelection(true);
+ saveAuthInfo = shouldSavePasswords;
+ cbSavePassword.setSelection(shouldSavePasswords);
new Label(pwgroup, SWT.NONE).setText("Save user name and password");
new Label(composite, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
warningLabel = new Label(composite, SWT.WRAP);
warningLabel.setText("NOTE: Saved passwords are stored on your computer in a file that is difficult, but not impossible, for an intruder to read.");
+ warningLabel.setEnabled(shouldSavePasswords);
super.setControl(composite);
}
@@ -192,7 +197,10 @@
} catch (Exception e) {
model.setRepLocation(null);
}
- super.getWizard().getContainer().updateButtons();
+ IWizardContainer container = super.getWizard().getContainer();
+ if (container != null) {
+ container.updateButtons();
+ }
}
private URL validateUrl() throws Exception {
@@ -243,4 +251,19 @@
GuvWizardModel model = ((IGuvnorWizard)super.getWizard()).getModel();
return model.getRepLocation() != null;
}
+
+ private boolean initialized = false;
+
+ @Override
+ public void setVisible(boolean visible) {
+ if (visible && !initialized) {
+ // See if there is a preference setting for the default values and, if so, use it
+ String guvnorLocTemplate = GuvnorPreferencePage.getGuvnorTemplatePref();
+ if (guvnorLocTemplate != null && guvnorLocTemplate.trim().length() > 0) {
+ parseCandidateUrl(guvnorLocTemplate);
+ }
+ initialized = true;
+ }
+ super.setVisible(visible);
+ }
}
More information about the jboss-svn-commits
mailing list