Merge lp:~javierder/bzr-eclipse/send_command into lp:~verterok/bzr-eclipse/trunk

Proposed by Javier Derderyan
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: no longer in the revision history of the source branch.
Merged at revision: not available
Proposed branch: lp:~javierder/bzr-eclipse/send_command
Merge into: lp:~verterok/bzr-eclipse/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~javierder/bzr-eclipse/send_command
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+5676@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Javier Derderyan (javierder) wrote :

Send command implementation.

The dialog, action and command are based on merge and uncommit.

Hope it merges!

Revision history for this message
Martin Albisetti (beuno) wrote :

Copyright headers look odd, no?

Revision history for this message
Javier Derderyan (javierder) wrote :

> Copyright headers look odd, no?

yes they do. They're the same in lots of original BzrEclipse files, like LocationInputDialog.java

what should be there?

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Hi Javier!

On Fri, Apr 17, 2009 at 8:45 PM, Javier Derderian <email address hidden> wrote:
> Javier Derderian has proposed merging lp:~javierder/bzr-eclipse/send_command into lp:bzr-eclipse.
>
> Requested reviews:
>    Guillermo Gonzalez (verterok)
>
> Send command implementation.
>
> The dialog, action and command are based on merge and uncommit.
>
Great!

> Hope it merges!

I'm sure it 'll merge :)

I'm reviewing the branch, but having some network outages.

I'll have the full review for tomorrow.

Cheers,
> --
> https://code.launchpad.net/~javierder/bzr-eclipse/send_command/+merge/5676
> You are requested to review the proposed merge of lp:~javierder/bzr-eclipse/send_command into lp:bzr-eclipse.
>

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Hi Javier,

On Sat, Apr 18, 2009 at 9:29 PM, Javier Derderian <email address hidden> wrote:
>> Copyright headers look odd, no?
>
> yes they do. They're the same in lots of original BzrEclipse files, like LocationInputDialog.java

I think Martin is talking about the copyright in SendAction.java, as
it might be a similar copyright in other files of bzr-eclipse, it's
wrong (my fault, sorry for the confusion). Looks like that a search &
replace didn't worked as expected.

Most of the files have a placeholder for the LICENSE/COPYRIGHT, that I
should complete.

>
>
> what should be there?

I think that as Canonical is the sponsor of this work, the copyright
belongs to them, but that depends on the arrangement/contract you
signed.

About the license, I know it's not clear. I think that using EPL it's
ok. but don't know if a specific license should be used (as part of
your contract with them).

Cheers,

> --
> https://code.edge.launchpad.net/~javierder/bzr-eclipse/send_command/+merge/5676
> You are requested to review the proposed merge of lp:~javierder/bzr-eclipse/send_command into lp:bzr-eclipse.
>

Revision history for this message
Guillermo Gonzalez (verterok) wrote :
Download full text (4.4 KiB)

Hi Javier,

On Fri, Apr 17, 2009 at 8:45 PM, Javier Derderian <email address hidden> wrote:
> Javier Derderian has proposed merging lp:~javierder/bzr-eclipse/send_command into lp:bzr-eclipse.
>
> Send command implementation.
>
> The dialog, action and command are based on merge and uncommit.

The branch looks good, but I have some comments regarding minor issues
I'ld like to see solved before merging.

1) please revert the changes to
org.vcs.bazaar.eclipse.client/.classpath as this reflects your
configuration of the project, but not the current default in order to
be able build the update-site.

2) org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/core/commands/SendCommand.java:

 + public void run(IProgressMonitor monitor) throws BazaarException {
 + try {
 + monitor.beginTask(CoreTexts.SendCommand_send, 1000);
 + IBazaarClient client = getClient(resource.getIResource().getProject());
 +
 + final BranchLocation branchLocation = new BranchLocation(remoteLocation);
 +
 + client.send(branchLocation, options);
 + //annotation =
client.annotate(resource.getIResource().getLocation().toFile());

    The remoteLocation variable is handled as a plain string, this is
really discouraged, as it's a value provided by the user, also the
overall idea is that the core don't know about locations as strings
but as instances of BranchLocation class.
    The SendAction or the Dialog should do some work to validate the
user input and pass a BranchLocation to SendCommand (see below).
    Also, please remove the commented code at line 48.

* org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/actions/SendAction.java:
 - Please fix the header of the file.
 - in isEnabledForUnmodifiedResources:
 + protected boolean isEnabledForUnmodifiedResources() {
 + if(getSelectedProjects().length > 1) {
 + return true;
 + } else if(getSelectedProjects().length == 1) {
 + return true;
 + }
 + return false;
 + }
   here you'r checking for getSelectedProjects().length > 1 and
getSelectedProjects().length == 1 and returng true in both conditions.
Ir order to make clear the intention of the code there should be only
one check: >= 1. Also take into account the side effects of this, as
the action 'll be enabled with multiple projects selected. This Might
be valid in the case that two projects are in the same branch, but are
two different projects in bzr-eclipse (This feature is supported by
bzr-eclipse but not directly available to the regular user due to
limitations in the Eclipse Team integration framework)

 * in the execute method:
 + final IBzrLocalResource[] resourcesToRevert =
BzrWorkspaceRoot.getBzrResourcesFor(projects);
 +

 (line 50): you'r naming a variable resourcesToRevert when it should
be resourcesToSend maybe, or just resources?

 + final SendCommand cmd = new SendCommand(resourcesToRevert[0],
dialog.getOptions(), dialog.getValue());

  (line 52) only the first resource is used, but as in
isEnabledForUnmodifiedResources the action is enabled for multiple
projects.

 + run(new WorkspaceModifyOperation() {
 + public void execute(IProgressMonitor monitor) throws
InvocationTargetException {
 + try {
 + cmd.run(monitor);
 + ...

Read more...

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Oops, I missed the vote command

review: Needs Fixing
Revision history for this message
Javier Derderyan (javierder) wrote :

Ok, thanks!!!!!!!!

I'll work on this tomorrow.

Revision history for this message
Javier Derderyan (javierder) wrote :

Ok,
Based on your input I fixed the issues you mentioned.

About the cancel, I just changed the variable to allow cancel, is that enough or I have to do something else?

About the browse button, I'll add it to my list of things for the next month, because I'm still trying to be friend with Java and Eclipse and I have no idea how to do it.
It's first in my to-do list.

I'll check with canonical about the Copyright headers.

Thanks again!

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

On Mon, Apr 20, 2009 at 4:00 PM, Javier Derderian <email address hidden> wrote:
> Ok,
> Based on your input I fixed the issues you mentioned.
>

Great!

> About the cancel, I just changed the variable to allow cancel, is that enough or I have to do something else?
>

regarding how to fire some work/command as a Job take a look to the
PushAction class (or do a search for Job class in bzr-eclipse) ;)

> About the browse button, I'll add it to my list of things for the next month, because I'm still trying to be friend with Java and Eclipse and I have no idea how to do it.
> It's first in my to-do list.

Ok, you could take a look to
/org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/wizards/project/BranchWizardBranchLocationPage.java,
lines: 90-101
that's an example of using the org.eclipse.swt.widgets.DirectoryDialog
class bound to a button (in this case should be the
org.eclipse.swt.widgets.FileDialog class)

>
> I'll check with canonical about the Copyright headers

I just talked with Martin Pool about this, and the copyright should be
for Canonical.

>
> Thanks again!

Thanks,

Cheers,

> --
> https://code.edge.launchpad.net/~javierder/bzr-eclipse/send_command/+merge/5676
> You are reviewing the proposed merge of lp:~javierder/bzr-eclipse/send_command into lp:bzr-eclipse.
>

Revision history for this message
Javier Derderyan (javierder) wrote :

Hi!

I managed to get the copyright headers and added a SendOperation to make it work as a Job.

I'm working right now with the browse dialog, but if you think it's ok I'll love to get this merged ASAP and then help you make a new release tomorrow (maybe a intermedial version before 1.2.0? or some beta?)

Revision history for this message
Javier Derderyan (javierder) wrote :

> Hi!
>
> I managed to get the copyright headers and added a SendOperation to make it
> work as a Job.
>
> I'm working right now with the browse dialog, but if you think it's ok I'll
> love to get this merged ASAP and then help you make a new release tomorrow
> (maybe a intermedial version before 1.2.0? or some beta?)

ok, browse button is there!!!!!!!!

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Hi

On Mon, Apr 20, 2009 at 9:26 PM, Javier Derderian <email address hidden> wrote:
>> Hi!
>>
>> I managed to get the copyright headers and added a SendOperation to make it
>> work as a Job.
>>
Great!

maybe missed to bzr add it? ;)

btw, The code looks ok.

Just one more thing, please remove the commented block on SendAction:

  /*final SendCommand cmd = new SendCommand(resourcesToSend[0],
dialog.getOptions(), new BranchLocation(dialog.getValue()));
  run(new WorkspaceModifyOperation() {
   public void execute(IProgressMonitor monitor) throws
InvocationTargetException {
    try {
     cmd.run(monitor);
    } catch (BazaarException e) {
     // FIXME: exception handling
     throw new InvocationTargetException(e);
    } finally {
     monitor.done();
    }
   }
  }, true / * cancelable * /, PROGRESS_DIALOG);*/

Thanks!

>> I'm working right now with the browse dialog, but if you think it's ok I'll
>> love to get this merged ASAP and then help you make a new release tomorrow
>> (maybe a intermedial version before 1.2.0? or some beta?)
>
>
> ok, browse button is there!!!!!!!!

Cool!

Cheers,

--
Guillermo Gonzalez
<http://launchpad.net/~verterok>

Revision history for this message
Javier Derderyan (javierder) wrote :

Ok,

done and done.

I ALWAYS miss bzr add......=(

Thanks!

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Great!

I'll land this ASAP!

On Tue, Apr 21, 2009 at 1:38 AM, Javier Derderian <email address hidden> wrote:
> Ok,
>
> done and done.
>
> I ALWAYS miss bzr add......=(
>
> Thanks!
>
>
> --
> https://code.launchpad.net/~javierder/bzr-eclipse/send_command/+merge/5676
> You are reviewing the proposed merge of lp:~javierder/bzr-eclipse/send_command into lp:bzr-eclipse.
>

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

looks good now!

review: Approve
208. By Guillermo Gonzalez

 merge with Javier's send_command branch

209. By Guillermo Gonzalez

 minor fix & cleanup

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'org.vcs.bazaar.eclipse.client/.classpath'
--- org.vcs.bazaar.eclipse.client/.classpath 2009-02-21 23:16:34 +0000
+++ org.vcs.bazaar.eclipse.client/.classpath 2009-04-16 21:40:23 +0000
@@ -1,10 +1,10 @@
1<?xml version="1.0" encoding="UTF-8"?>1<?xml version="1.0" encoding="UTF-8"?>
2<classpath>2<classpath>
3 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>3 <classpathentry exported="true" kind="lib" path="bzr-java-lib-0.5.1-SNAPSHOT.jar" sourcepath="/home/javier/java/bzr-java-lib"/>
4 <classpathentry exported="true" kind="lib" path="kxml2-min-2.3.0.jar"/>
5 <classpathentry exported="true" kind="lib" path="xmlrpc-1.1.jar"/>
6 <classpathentry exported="true" kind="lib" path="xmlrpc-client-1.1.jar"/>
7 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4 <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>8 <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5 <classpathentry exported="true" kind="lib" path="bzr-java-lib-0.5.1-SNAPSHOT.jar" sourcepath="org.vcs.bazaar.eclipse.clientsrc.zip"/>
6 <classpathentry exported="true" kind="lib" path="kxml2-min-2.3.0.jar" sourcepath="org.vcs.bazaar.eclipse.clientsrc.zip"/>
7 <classpathentry exported="true" kind="lib" path="xmlrpc-1.1.jar" sourcepath="org.vcs.bazaar.eclipse.clientsrc.zip"/>
8 <classpathentry exported="true" kind="lib" path="xmlrpc-client-1.1.jar" sourcepath="org.vcs.bazaar.eclipse.clientsrc.zip"/>
9 <classpathentry kind="output" path="bin"/>9 <classpathentry kind="output" path="bin"/>
10</classpath>10</classpath>
1111
=== modified file 'org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/CoreTexts.java'
--- org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/CoreTexts.java 2008-07-17 02:36:37 +0000
+++ org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/CoreTexts.java 2009-04-16 21:40:23 +0000
@@ -20,6 +20,8 @@
20 public static String AddCommand_adding;20 public static String AddCommand_adding;
2121
22 public static String AnnotateCommand_annotate;22 public static String AnnotateCommand_annotate;
23
24 public static String SendCommand_send;
2325
24 public static String CommitCommand_commit;26 public static String CommitCommand_commit;
2527
2628
=== added file 'org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/core/commands/SendCommand.java'
--- org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/core/commands/SendCommand.java 1970-01-01 00:00:00 +0000
+++ org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/core/commands/SendCommand.java 2009-04-17 13:57:24 +0000
@@ -0,0 +1,60 @@
1/**
2 * LICENSE + COPYRIGHT
3 */
4package org.vcs.bazaar.eclipse.core.commands;
5
6import org.eclipse.core.runtime.IProgressMonitor;
7import org.vcs.bazaar.client.IBazaarAnnotation;
8import org.vcs.bazaar.client.IBazaarClient;
9import org.vcs.bazaar.client.commandline.commands.options.Option;
10import org.vcs.bazaar.client.core.BazaarClientException;
11import org.vcs.bazaar.eclipse.CoreTexts;
12import org.vcs.bazaar.eclipse.core.model.local.IBzrLocalResource;
13import org.vcs.bazaar.eclipse.internal.core.BazaarException;
14import org.vcs.bazaar.client.core.BranchLocation;
15
16/**
17 * @author Javier Der Derian<javierder AT gmail DOT com>
18 * @BasedOn RevertCommand from BzrEclipse
19 *
20 */
21public class SendCommand extends BazaarCommand {
22
23 private final IBzrLocalResource resource;
24 private IBazaarAnnotation annotation;
25 private Option[] options;
26 private String remoteLocation;
27
28
29 public SendCommand(IBzrLocalResource bzrResource, Option[] options, String remoteLocation) {
30 this.resource = bzrResource;
31 this.options = options;
32 this.remoteLocation = remoteLocation;
33 }
34
35 /**
36 * when this finish you must call {@link #getAnnotation()}
37 *
38 * @see org.vcs.bazaar.eclipse.core.commands.IBazaarCommand#run(org.eclipse.core.runtime.IProgressMonitor)
39 */
40 public void run(IProgressMonitor monitor) throws BazaarException {
41 try {
42 monitor.beginTask(CoreTexts.SendCommand_send, 1000);
43 IBazaarClient client = getClient(resource.getIResource().getProject());
44
45 final BranchLocation branchLocation = new BranchLocation(remoteLocation);
46
47 client.send(branchLocation, options);
48 //annotation = client.annotate(resource.getIResource().getLocation().toFile());
49 } catch (BazaarClientException e) {
50 throw BazaarException.wrapException(e, resource.getIResource());
51 } finally {
52 monitor.done();
53 }
54 }
55
56 public IBazaarAnnotation getAnnotation() {
57 return annotation;
58 }
59
60}
061
=== modified file 'org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/coretexts.properties'
--- org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/coretexts.properties 2009-01-01 04:46:34 +0000
+++ org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/coretexts.properties 2009-04-16 21:40:23 +0000
@@ -1,6 +1,7 @@
1AddCommand_adding=Adding files1AddCommand_adding=Adding files
2BranchCommand_branching=Executing 'bzr branch'2BranchCommand_branching=Executing 'bzr branch'
3AnnotateCommand_annotate=Getting file annotation3AnnotateCommand_annotate=Getting file annotation
4SendCommand_send=Sending
4RemoveCommand_removing=Removing files5RemoveCommand_removing=Removing files
5StatusCommand_status=Executing 'bzr status'6StatusCommand_status=Executing 'bzr status'
6DiffCommand_diff=Generating diff7DiffCommand_diff=Generating diff
78
=== modified file 'org.vcs.bazaar.eclipse.ui/plugin.properties'
--- org.vcs.bazaar.eclipse.ui/plugin.properties 2009-01-18 14:57:50 +0000
+++ org.vcs.bazaar.eclipse.ui/plugin.properties 2009-04-15 16:36:58 +0000
@@ -51,6 +51,8 @@
51ActionResolve_tooltip=Mark a conflict as resolved.51ActionResolve_tooltip=Mark a conflict as resolved.
52ActionRevert_label=&Revert52ActionRevert_label=&Revert
53ActionRevert_tooltip=Revert files to a previous revision53ActionRevert_tooltip=Revert files to a previous revision
54ActionSend_label=&Send
55ActionSend_tooltip=Mail or create a merge-directive for submitting changes
54ActionStatus_label=&Status56ActionStatus_label=&Status
55ActionStatus_tooltip=Display status summary (in the Console)57ActionStatus_tooltip=Display status summary (in the Console)
56ActionUnCommit_label=UnC&ommit58ActionUnCommit_label=UnC&ommit
5759
=== modified file 'org.vcs.bazaar.eclipse.ui/plugin.xml'
--- org.vcs.bazaar.eclipse.ui/plugin.xml 2009-02-21 23:16:34 +0000
+++ org.vcs.bazaar.eclipse.ui/plugin.xml 2009-04-15 16:41:07 +0000
@@ -158,6 +158,14 @@
158 label="%ActionRevert_label" menubarPath="team.main/group4"158 label="%ActionRevert_label" menubarPath="team.main/group4"
159 tooltip="%ActionRevert_tooltip">159 tooltip="%ActionRevert_tooltip">
160 </action>160 </action>
161 <action
162 class="org.vcs.bazaar.eclipse.ui.actions.SendAction"
163 definitionId="org.vcs.bazaar.eclipse.ui.actions.ActionSend"
164 icon="icons/bzrlogo.png"
165 id="org.vcs.bazaar.eclipse.ui.actions.ActionSend"
166 label="%ActionSend_label" menubarPath="team.main/group4"
167 tooltip="%ActionSend_tooltip">
168 </action>
161 <action169 <action
162 class="org.vcs.bazaar.eclipse.ui.actions.AddAction"170 class="org.vcs.bazaar.eclipse.ui.actions.AddAction"
163 definitionId="org.vcs.bazaar.eclipse.ui.actions.ActionAdd"171 definitionId="org.vcs.bazaar.eclipse.ui.actions.ActionAdd"
@@ -748,3 +756,4 @@
748 </extension -->756 </extension -->
749757
750</plugin>758</plugin>
759
751760
=== added file 'org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/actions/SendAction.java'
--- org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/actions/SendAction.java 1970-01-01 00:00:00 +0000
+++ org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/actions/SendAction.java 2009-04-17 13:57:24 +0000
@@ -0,0 +1,86 @@
1/**
2 * org.vcs.bazaar.eclipse (c) Vectrace Sep 12, 2006
3 * Created by zingo
4 */
5package org.vcs.bazaar.eclipse.ui.actions;
6
7import java.lang.reflect.InvocationTargetException;
8import java.util.Collection;
9
10import org.eclipse.core.resources.IProject;
11import org.eclipse.core.runtime.IProgressMonitor;
12import org.eclipse.jface.action.IAction;
13import org.eclipse.ui.IWorkbenchWindowActionDelegate;
14import org.eclipse.ui.actions.WorkspaceModifyOperation;
15import org.vcs.bazaar.eclipse.BzrWorkspaceRoot;
16import org.vcs.bazaar.eclipse.core.commands.SendCommand;
17import org.vcs.bazaar.eclipse.core.model.IBzrBranch;
18import org.vcs.bazaar.eclipse.core.model.local.IBzrLocalResource;
19import org.vcs.bazaar.eclipse.internal.core.BazaarException;
20import org.vcs.bazaar.eclipse.ui.dialogs.SendDialog;
21import org.vcs.bazaar.eclipse.ui.dialogs.SendDialog.SendDialogInfo;
22
23/**
24 * @author Javier Der Derian<javierder AT gmail DOT com>
25 * @BasedOn RevertAction from BzrEclipse
26 */
27public class SendAction extends WorkbenchAction {
28
29 /**
30 * <p>
31 * The action has been activated. The argument of the method represents the
32 * 'real' action sitting in the workbench UI.
33 * </p>
34 *
35 * @throws BazaarException
36 * @see IWorkbenchWindowActionDelegate#run
37 */
38 @Override
39 protected void execute(IAction action) throws BazaarException, InvocationTargetException, InterruptedException {
40 IProject[] projects = getEnclosingProjectsForSelectedResources();
41
42 Collection<IBzrBranch> locations = getAllBranchLocations(projects[0]);
43
44 SendDialog dialog = new SendDialog(this.getShell(), locations, new SendDialogInfo());
45
46 if(dialog.open() != SendDialog.OK) {
47 return;
48 }
49
50 final IBzrLocalResource[] resourcesToRevert = BzrWorkspaceRoot.getBzrResourcesFor(projects);
51
52 final SendCommand cmd = new SendCommand(resourcesToRevert[0], dialog.getOptions(), dialog.getValue());
53 run(new WorkspaceModifyOperation() {
54 public void execute(IProgressMonitor monitor) throws InvocationTargetException {
55 try {
56 cmd.run(monitor);
57 } catch (BazaarException e) {
58 // FIXME: exception handling
59 throw new InvocationTargetException(e);
60 } finally {
61 monitor.done();
62 }
63 }
64 }, false /* no cancelable */, PROGRESS_DIALOG);
65
66 }
67
68 protected boolean isEnabledForUnmanagedResources() {
69 return false;
70 }
71
72 @Override
73 protected boolean isEnabledForUnmodifiedResources() {
74 if(getSelectedProjects().length > 1) {
75 return true;
76 } else if(getSelectedProjects().length == 1) {
77 return true;
78 }
79 return false;
80 }
81
82 @Override
83 protected boolean isEnabledForMultipleEclosingProjects() {
84 return isSameBranchInEnclosingProjects();
85 }
86}
087
=== added file 'org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/dialogs/SendDialog.java'
--- org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/dialogs/SendDialog.java 1970-01-01 00:00:00 +0000
+++ org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/dialogs/SendDialog.java 2009-04-17 23:39:17 +0000
@@ -0,0 +1,281 @@
1/**
2 * LICENSE + COPYRIGHT
3 */
4package org.vcs.bazaar.eclipse.ui.dialogs;
5
6import java.util.ArrayList;
7import java.util.Collection;
8import java.util.Collections;
9import java.util.List;
10
11import org.eclipse.jface.dialogs.Dialog;
12import org.eclipse.jface.dialogs.IDialogConstants;
13import org.eclipse.swt.SWT;
14import org.eclipse.swt.events.SelectionAdapter;
15import org.eclipse.swt.events.SelectionEvent;
16import org.eclipse.swt.graphics.Point;
17import org.eclipse.swt.layout.GridData;
18import org.eclipse.swt.layout.GridLayout;
19import org.eclipse.swt.widgets.Button;
20import org.eclipse.swt.widgets.Composite;
21import org.eclipse.swt.widgets.Display;
22import org.eclipse.swt.widgets.Group;
23import org.eclipse.swt.widgets.Label;
24import org.eclipse.swt.widgets.Shell;
25import org.eclipse.swt.widgets.Text;
26import org.vcs.bazaar.client.commandline.commands.options.Option;
27import org.vcs.bazaar.client.commandline.syntax.ISendOptions;
28import org.vcs.bazaar.eclipse.core.model.IBzrBranch;
29import org.vcs.bazaar.eclipse.core.repository.BranchFactory;
30import org.vcs.bazaar.eclipse.ui.widgets.RevisionNumber;
31
32/**
33 *
34 * @author Javier Der Derian <javierder AT gmail.com>
35 * @BasedOn RevertDialog from BzrEclipse
36 */
37public class SendDialog extends LocationInputDialog {
38
39 private static final String TITLE = "Remote location Dialog";
40 private static final String MESSAGE = "Please enter the URI of the submit location: ";
41 private RevisionNumber revision;
42 private ArrayList<Option> options;
43 private Button nobundle;
44 private Button nopatch;
45 private Button send;
46 private Button save;
47
48 private SendDialogInfo dialogInfo;
49 private Text submitLocationText;
50 private Text messageText;
51 private Text formatText;
52
53
54 /**
55 * Create the dialog
56 *
57 * @param parentShell
58 * @param selectedResources
59 * @param commiteableResources
60 */
61 public SendDialog(Shell parentShell, Collection<IBzrBranch> locations, SendDialogInfo dialogInfo) {
62 super(parentShell, TITLE, MESSAGE, "", new BaseURIValidator(), locations, dialogInfo, true, false);
63 setShellStyle(SWT.RESIZE | SWT.MODELESS | SWT.CLOSE | SWT.BORDER | SWT.TITLE);
64 setBlockOnOpen(true);
65 this.dialogInfo = dialogInfo;
66 }
67
68 protected void createOptionsArea(Composite composite) {
69
70 final Label label = new Label(composite, SWT.NONE);
71 label.setText("Enter send location");
72
73 Group typeBoxGroup = new Group(composite, SWT.NONE);
74
75 GridData typeBoxGrid = new GridData();
76
77 typeBoxGrid.horizontalAlignment = SWT.FILL;
78 typeBoxGroup.setLayout(new GridLayout(2, true));
79 typeBoxGroup.setLayoutData(typeBoxGrid);
80
81 send = new Button(typeBoxGroup, SWT.RADIO);
82 send.setText("Send to email");
83 send.setSelection(true); // Start selected.
84 send.setToolTipText("Send the bundle to a specific email address.");
85 save = new Button(typeBoxGroup, SWT.RADIO);
86 save.setText("Save to location");
87 save.setSelection(false); // Start unselected.
88 save.setToolTipText("Save bundle to a file in a specific location.");
89
90 GridData submitLocationGrid = new GridData();
91
92 submitLocationGrid.horizontalAlignment = SWT.FILL;
93 submitLocationText = new Text(composite, SWT.BORDER | SWT.SINGLE);
94 submitLocationText.setLayoutData(submitLocationGrid);
95
96 final Label label2 = new Label(composite, SWT.NONE);
97 label2.setText("Message");
98
99 GridData messageGrid = new GridData();
100
101 messageGrid.horizontalAlignment = SWT.FILL;
102 messageText = new Text(composite, SWT.BORDER | SWT.SINGLE);
103 messageText.setLayoutData(messageGrid);
104
105 Composite container = new Composite(composite, SWT.NONE);
106 container.setLayout(new GridLayout(2, false));
107 container.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false));
108
109 Group checkBoxGroup = new Group(container, SWT.NONE);
110 checkBoxGroup.setLayout(new GridLayout(2, false));
111 super.createOptionsArea(checkBoxGroup);
112 nobundle = new Button(checkBoxGroup, SWT.CHECK);
113 nobundle.setText("No bundle");
114 nobundle.setSelection(false); // Start unselected.
115 nobundle.setToolTipText("Do not include a bundle in the merge directive.");
116 nopatch = new Button(checkBoxGroup, SWT.CHECK);
117 nopatch.setText("No patch");
118 nopatch.setSelection(false); // Start unselected.
119 nopatch.setToolTipText("Do not include a preview patch in the merge directive.");
120
121
122 Composite formatBoxGroup = new Composite(checkBoxGroup, SWT.NONE);
123
124 GridData formatBoxGrid = new GridData();
125
126 formatBoxGrid.horizontalAlignment = SWT.FILL;
127 formatBoxGroup.setLayout(new GridLayout(2, false));
128 formatBoxGroup.setLayoutData(formatBoxGrid);
129
130 final Label label3 = new Label(formatBoxGroup, SWT.NONE);
131 label3.setText("Format");
132 formatText = new Text(formatBoxGroup, SWT.BORDER | SWT.SINGLE);
133
134 Group revisionGroup = new Group(container, SWT.NONE);
135 revisionGroup.setLayout(new GridLayout());
136 revision = new RevisionNumber(revisionGroup);
137
138 GridData data = new GridData(GridData.FILL, GridData.FILL, true, false);
139 revisionGroup.setLayoutData(data);
140 checkBoxGroup.setLayoutData(data);
141 data = new GridData(GridData.FILL_BOTH);
142 container.setLayoutData(data);
143
144 revision.addShowLogButtonSelectionListener(new SelectionAdapter() {
145 @Override
146 public void widgetSelected(SelectionEvent e) {
147 showLog();
148 }
149 });
150
151 }
152
153 protected void showLog() {
154 String url = super.getTextInput();
155 if(url == null || "".equals(url.trim())) {
156 return;
157 }
158 IBzrBranch branch = BranchFactory.getInstance().findOrCreateFor(url);
159 if(branch != null) {
160 ShowLogDialog dialog = new ShowLogDialog(getShell(), branch);
161 if(dialog.open() == Dialog.OK && dialog.getSelectedRevision() != null) {
162 revision.setRevision(dialog.getSelectedRevision().getValue());
163 }
164 }
165 }
166
167 public String getPath() {
168 return submitLocationText.getText();
169 }
170 public String getMessage() {
171 return messageText.getText();
172 }
173
174 public String getFormat() {
175 return formatText.getText();
176 }
177
178
179 public Integer getType(){
180 // 0 means send by email, 1 means save in file
181 if(send.getSelection())
182 return 0;
183 else
184 return 1;
185 }
186
187 protected Boolean isNoBundle() {
188 return nobundle.getSelection();
189 }
190
191 protected Boolean isNoPatch() {
192 return nopatch.getSelection();
193 }
194
195 public Option[] getOptions() {
196 return options.toArray(new Option[options.size()]);
197
198 }
199
200 /**
201 * Create contents of the button bar
202 *
203 * @param parent
204 */
205 @Override
206 protected void createButtonsForButtonBar(Composite parent) {
207 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
208 true);
209 createButton(parent, IDialogConstants.CANCEL_ID,
210 IDialogConstants.CANCEL_LABEL, false);
211 }
212
213 /**
214 * Return the initial size of the dialog
215 */
216 @Override
217 protected Point getInitialSize() {
218 return new Point(540, 490);
219 }
220
221 @Override
222 protected void okPressed() {
223 this.options = new ArrayList<Option>(0);
224
225 if(getPath().length() > 0 && getValue().length() > 0 ) {
226 if(getType() == 0){
227 options.add(ISendOptions.MAIL_TO.setArgument(getPath()));
228 }
229 else {
230 options.add(ISendOptions.OUTPUT.setArgument(getPath()));
231 }
232 }
233 else {
234 //FIXME: give some kind of message
235 return;
236 }
237
238 options.add(ISendOptions.MESSAGE.setArgument(getMessage()));
239
240 if(isRemember()) {
241 options.add(ISendOptions.REMEMBER);
242 }
243
244 if(isNoBundle()) {
245 options.add(ISendOptions.NO_BUNDLE);
246 }
247
248 if(isNoPatch()) {
249 options.add(ISendOptions.NO_PATCH);
250 }
251 if(revision.isRevisionSelected()) {
252 options.add(ISendOptions.REVISION.setArgument(revision.getRevision()));
253 }
254
255 if(getFormat().length() > 0) {
256 options.add(ISendOptions.FORMAT.setArgument(getFormat()));
257 }
258
259 this.dialogInfo.options = options;
260 super.okPressed();
261 }
262
263 public static class SendDialogInfo extends LocationDialogInfo {
264 List<Option> options;
265
266 public List<Option> getOptions() {
267 return options;
268 }
269 }
270
271 // this main is for test the dialog during development
272 public static void main(String[] args) {
273 Display display = new Display();
274 Shell shell = new Shell(display);
275 shell.setMinimumSize(280, 400);
276 SendDialog dialog = new SendDialog(shell, Collections.EMPTY_LIST, new SendDialogInfo());
277 dialog.setBlockOnOpen(true);
278 int exit = dialog.open();
279 System.out.println("exit: " + exit);
280 }
281}

Subscribers

People subscribed via source and target branches