[jboss-svn-commits] JBL Code SVN: r33751 - in labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools: src/org/guvnor/tools and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 7 03:23:44 EDT 2010


Author: jervisliu
Date: 2010-07-07 03:23:44 -0400 (Wed, 07 Jul 2010)
New Revision: 33751

Added:
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/EditConnectionAction.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/EditRepLocationWizard.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorConnectionEditPage.java
Modified:
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/messages.properties
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorMainConfigPage.java
Log:
On behalf of Denny Xu: patch for JBIDE-6459: Fact Importing into BRMS


Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml	2010-07-07 05:23:56 UTC (rev 33750)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml	2010-07-07 07:23:44 UTC (rev 33751)
@@ -97,9 +97,18 @@
                 label="%action.popup.openguvnorwebconsoleaction"
                 menubarPath="additions">
         </action>
+        <action
+              class="org.guvnor.tools.actions.EditConnectionAction"
+              enablesFor="1"
+              id="org.guvnor.tools.actions.edticonnectionaction"
+              label="Edit Connection"
+              menubarPath="additions">
+        </action>
   	</objectContribution>
-    <objectContribution id="org.guvnor.tools.contribution1"
-                        objectClass="org.eclipse.core.resources.IFile">
+    <objectContribution
+          adaptable="true"
+          id="org.guvnor.tools.contribution1"
+          objectClass="org.eclipse.core.resources.IFile">
       <menu id="org.guvnor.tools.popupmenu"
             label="%category.name"
             path="additions">

Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/EditConnectionAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/EditConnectionAction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/EditConnectionAction.java	2010-07-07 07:23:44 UTC (rev 33751)
@@ -0,0 +1,148 @@
+package org.guvnor.tools.actions;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.Properties;
+
+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.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.webdav.IResponse;
+import org.guvnor.tools.Activator;
+import org.guvnor.tools.GuvnorRepository;
+import org.guvnor.tools.Messages;
+import org.guvnor.tools.utils.GuvnorMetadataProps;
+import org.guvnor.tools.utils.GuvnorMetadataUtils;
+import org.guvnor.tools.utils.PlatformUtils;
+import org.guvnor.tools.utils.webdav.IWebDavClient;
+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.RepositoryView;
+import org.guvnor.tools.views.ResourceHistoryView;
+import org.guvnor.tools.views.model.TreeObject;
+import org.guvnor.tools.views.model.TreeParent;
+import org.guvnor.tools.wizards.EditRepLocationWizard;
+
+/**
+ * Shows the revision history for a given resource.
+ * @author jgraham
+ */
+public class EditConnectionAction implements IObjectActionDelegate {
+	
+	private GuvnorRepository rep;
+	
+	public EditConnectionAction() {
+		super();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
+	 */
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+	 */
+	public void run(IAction action) {
+		EditRepLocationWizard editWizard = new EditRepLocationWizard(rep);
+		editWizard.init(Activator.getDefault().getWorkbench(), null);
+		WizardDialog dialog = 
+			new WizardDialog(Display.getCurrent().getActiveShell(), editWizard);
+	    dialog.create();
+	    dialog.open();
+	    
+//		String repositoryLoc = null;
+//		String fullPath = null;
+		
+//		if (selectedNode != null) {
+//			repositoryLoc = selectedNode.getGuvnorRepository().getLocation();
+//			fullPath = selectedNode.getFullPath();
+//		} else {
+//			if (selectedFile == null
+//		       || props == null) {
+//				return;
+//			}
+//			repositoryLoc = props.getRepository();
+//			fullPath = props.getFullpath();
+//		}
+//		
+//		IResponse response = null;
+//		try {
+//			IWebDavClient client = WebDavServerCache.getWebDavClient(repositoryLoc);
+//			if (client == null) {
+//				client = WebDavClientFactory.createClient(new URL(repositoryLoc));
+//				WebDavServerCache.cacheWebDavClient(repositoryLoc, client);
+//			}
+//			InputStream ins = null;
+//			try {
+//				response = client.getResourceVersions(fullPath);
+//				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(repositoryLoc, client); 
+//				if (retry) {
+//					response = client.getResourceVersions(fullPath);
+//					ins = response.getInputStream();
+//				}
+//			}
+//			if (ins != null) {
+//				Properties verProps = new Properties();
+//				verProps.load(ins);
+//				ResourceHistoryView view = PlatformUtils.getResourceHistoryView();
+//				if (view != null) {
+//					view.setEntries(repositoryLoc, fullPath, verProps);
+//				}
+//			}
+//		} catch (Exception e) {
+//			Activator.getDefault().displayError(IStatus.ERROR, e.getMessage(), e, true);
+//		} finally {
+//			if (response != null) {
+//				try {
+//					response.close();
+//				} catch (IOException ioe) {
+//					Activator.getDefault().writeLog(IStatus.ERROR, ioe.getMessage(), ioe);
+//				}
+//			}
+//		}
+	}
+
+	/*
+	 * 	(non-Javadoc)
+	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+	 */
+	public void selectionChanged(IAction action, ISelection selection) {
+		// Reset state to default
+		action.setEnabled(false);
+		
+		if (!(selection instanceof IStructuredSelection)) {
+			return;
+		}
+		
+		IStructuredSelection sel = (IStructuredSelection)selection;
+		if (sel.size() != 1) {
+			return;
+		}
+		
+		if (sel.getFirstElement() instanceof TreeParent) {
+				rep = ((TreeParent)sel.getFirstElement()).getGuvnorRepository();
+				action.setEnabled(true);
+		}
+	}
+}


Property changes on: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/EditConnectionAction.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/messages.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/messages.properties	2010-07-07 05:23:56 UTC (rev 33750)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/messages.properties	2010-07-07 07:23:44 UTC (rev 33751)
@@ -24,23 +24,25 @@
 history.author=Author
 history.comment=Comment
 history.date=Date
-history.rep.label=Repository: 
+history.rep.label=Repository\: 
 history.resource.label=Resource: {0}
 history.revision=Revision
 login.dialog.caption=Guvnor Repository Log in
-login.dialog.desc=Authentication required for repository: {0} 
+login.dialog.desc=Authentication required for repository\: {0} 
 login.failure.dialog.caption=Guvnor Repository Log in
 login.failure.dialog.message=Authentication failure
-mainconfig.guvnor.loc=Location: 
-mainconfig.password=Password: 
-mainconfig.port=Port: 
-mainconfig.rep=Repository: 
+mainconfig.guvnor.loc=Location\: 
+mainconfig.password=Password\: 
+mainconfig.port=Port\: 
+mainconfig.rep=Repository\: 
 mainconfig.save.password=Save user name and password
-mainconfig.user.name=User Name: 
+mainconfig.user.name=User Name\: 
 name.conflict=Name Conflict
 name.conflict.request=Enter a new name for {0}
 new.guvnor.loc=New Guvnor connection
+edit.guvnor.loc=Edit Guvnor connection
 new.guvnor.loc.desc=Create a new Guvnor repository connection
+edit.guvnor.loc.desc=Update Guvnor repository connection
 new.guvnor.rep=New Guvnor repository connection
 new.guvnor.rep.desc=Creates a connection to a Guvnor repository
 new.guvnor.rep.loc=New Guvnor repository connection
@@ -49,13 +51,13 @@
 not.guvnor.associated=(Not associated with Guvnor)
 overwrite.confirmation.caption=Revision Conflict
 overwrite.confirmation=The Guvnor revision for {0} is {1}, but the local copy is based on revision {2}.\r\nOverwrite Guvnor repository revision with current local file contents?   
-password=Password:  
+password=Password\:  
 password.warning=NOTE: Saved passwords are stored on your computer in a file that is difficult, but not impossible, for an intruder to read.
 pending=Pending...
-prepage.decoration.location=Icon decoration location: 
+prepage.decoration.location=Icon decoration location\: 
 prepage.decoration.text=Text
 prepage.file.decoration=File Decoration
-prepage.guvnor.url.template=Guvnor URL template: 
+prepage.guvnor.url.template=Guvnor URL template\: 
 prepage.include.change.indicator=Include change indication (>)
 prepage.include.date.time.stamp=Include date/time stamp
 prepage.include.revision=Include revision
@@ -79,8 +81,7 @@
 repository.resource.revision=Revision:
 repository.resource.version=Version:
 save.password=Save user name and password
-select.folder=Select folder
-select.folder=Select folder:
+select.folder=Select folder\:
 select.folder.desc=Select the target folder in the Guvnor repository
 select.guvnor.rep=Select Guvnor repository location
 select.guvnor.rep.desc=Select an existing Guvnor repository connection or create a new one
@@ -89,15 +90,14 @@
 select.location=Select location:
 select.rep.guvnor.loc=Create a new Guvnor repository connection
 select.rep.guvnor.loc.desc=Use an existing Guvnor repository connection
-select.resources=Select resources
-select.resources=Select resources:
+select.resources=Select resources\:
 select.resources.desc=Select resources to copy from the Guvnor repository
 select.target.loc=Select copy location
 select.target.loc.desc=Select the destination location
 select.version=Select version:
 top.left=Top left
 top.right=Top right
-user.name=User Name: 
+user.name=User Name\: 
 version.dialog.caption=Resource Versions
 version.dialog.message=Choose a version for {0}
 warning=Guvnor Repository Warning

Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/EditRepLocationWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/EditRepLocationWizard.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/EditRepLocationWizard.java	2010-07-07 07:23:44 UTC (rev 33751)
@@ -0,0 +1,82 @@
+package org.guvnor.tools.wizards;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.guvnor.tools.Activator;
+import org.guvnor.tools.GuvnorRepository;
+import org.guvnor.tools.Messages;
+import org.guvnor.tools.utils.PlatformUtils;
+
+/**
+ * Wizard page for creating a new Guvnor connection.
+ * @author jgraham
+ *
+ */
+public class EditRepLocationWizard extends Wizard implements INewWizard, IGuvnorWizard {
+	
+	private GuvnorConnectionEditPage mainPage;
+	
+	private GuvnorRepository rep;
+	
+	private GuvWizardModel model = new GuvWizardModel();
+	
+	
+	public EditRepLocationWizard(GuvnorRepository rep){
+		this.rep = rep;
+	}
+	
+	public GuvWizardModel getModel() {
+		return model;
+	}
+	
+	@Override
+	public void addPages() {
+		mainPage = new GuvnorConnectionEditPage(rep, "config_page", Messages.getString("edit.guvnor.loc"),  //$NON-NLS-1$ //$NON-NLS-2$
+										Activator.getImageDescriptor(Activator.IMG_GUVLOCADD));
+		mainPage.setDescription(Messages.getString("edit.guvnor.loc.desc")); //$NON-NLS-1$
+		super.addPage(mainPage);
+		super.addPages();
+	}
+	
+	public boolean canFinish() {
+		return mainPage.isPageComplete();
+	}
+	
+	@Override
+	public boolean performFinish() {
+		if (!(model.getRepLocation().equals(rep.getLocation()))) {
+
+			try {
+				WizardUtils.createGuvnorRepository(model);
+			} catch (Exception e) {
+				Activator.getDefault().displayError(IStatus.ERROR,
+						e.getMessage(), e, true);
+				return false;
+			}
+
+			Activator.getLocationManager().removeRepository(rep.getLocation());
+		}
+		else{
+			
+			Activator.getLocationManager().removeRepository(rep.getLocation());
+			try {
+				WizardUtils.createGuvnorRepository(model);
+			} catch (Exception e) {
+				Activator.getDefault().displayError(IStatus.ERROR,
+						e.getMessage(), e, true);
+				return false;
+			}
+
+		}
+		return true;
+	}
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+	 */
+	public void init(IWorkbench workbench, IStructuredSelection selection) { }
+}


Property changes on: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/EditRepLocationWizard.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorConnectionEditPage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorConnectionEditPage.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorConnectionEditPage.java	2010-07-07 07:23:44 UTC (rev 33751)
@@ -0,0 +1,54 @@
+package org.guvnor.tools.wizards;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.guvnor.tools.Activator;
+import org.guvnor.tools.GuvnorRepository;
+
+/**
+ * Wizard page for entering Guvnor connection details.
+ * @author jgraham
+ */
+public class GuvnorConnectionEditPage extends GuvnorMainConfigPage {
+	
+	private GuvnorRepository rep;
+
+	public GuvnorConnectionEditPage(String pageName) {
+		super(pageName);
+	}
+	
+	public GuvnorConnectionEditPage(GuvnorRepository rep, String pageName, String title, ImageDescriptor titleImage) {
+		super(pageName, title, titleImage);
+		this.rep = rep;
+	}
+	
+	protected String getGuvnorLocation(){
+		return rep.getLocation();
+	}
+	 
+	
+	protected Map getSecurityInfo(){
+		Map info = null;
+		try {
+			info = Platform.getAuthorizationInfo(
+					new URL(rep.getLocation()), "", "basic");
+		} catch (MalformedURLException e) {
+			Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+			
+			return null;
+		} //$NON-NLS-1$ //$NON-NLS-2$
+		
+		return info;
+	}
+	
+	protected boolean shouldSavePasswords(){
+		return getSecurityInfo() != null;
+	}
+
+	
+}


Property changes on: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorConnectionEditPage.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

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	2010-07-07 05:23:56 UTC (rev 33750)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/GuvnorMainConfigPage.java	2010-07-07 07:23:44 UTC (rev 33751)
@@ -2,8 +2,10 @@
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Map;
 
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.wizard.IWizardContainer;
 import org.eclipse.jface.wizard.WizardPage;
@@ -119,7 +121,7 @@
 			
 		});
 		
-		boolean shouldSavePasswords = GuvnorPreferencePage.shouldSavePasswords();
+		boolean shouldSavePasswords = 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 = shouldSavePasswords;
@@ -263,12 +265,42 @@
 	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();
+			String guvnorLocTemplate = getGuvnorLocation();
 			if (guvnorLocTemplate != null && guvnorLocTemplate.trim().length() > 0) {
 				parseCandidateUrl(guvnorLocTemplate);
 			}
 			initialized = true;
+			
+			initializeUserInfo(getSecurityInfo());
 		}
 		super.setVisible(visible);
 	}
+	
+	protected String getGuvnorLocation(){
+		return GuvnorPreferencePage.getGuvnorTemplatePref();
+	}
+	
+	protected Map getSecurityInfo(){
+		return null;
+	}
+	
+	protected boolean shouldSavePasswords(){
+		return GuvnorPreferencePage.shouldSavePasswords();
+	}
+	
+	private void initializeUserInfo(Map info) {
+
+		if (info == null) {
+			return;
+		}
+		String un = (String) info.get("username"); //$NON-NLS-1$
+		if (un != null) {
+			unField.setText(un);
+		}
+		String pw = (String) info.get("password"); //$NON-NLS-1$
+		if (pw != null) {
+			pwField.setText(pw);
+		}
+	}
+	
 }



More information about the jboss-svn-commits mailing list