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
1=== modified file 'org.vcs.bazaar.eclipse.client/.classpath'
2--- org.vcs.bazaar.eclipse.client/.classpath 2009-02-21 23:16:34 +0000
3+++ org.vcs.bazaar.eclipse.client/.classpath 2009-04-16 21:40:23 +0000
4@@ -1,10 +1,10 @@
5 <?xml version="1.0" encoding="UTF-8"?>
6 <classpath>
7- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
8+ <classpathentry exported="true" kind="lib" path="bzr-java-lib-0.5.1-SNAPSHOT.jar" sourcepath="/home/javier/java/bzr-java-lib"/>
9+ <classpathentry exported="true" kind="lib" path="kxml2-min-2.3.0.jar"/>
10+ <classpathentry exported="true" kind="lib" path="xmlrpc-1.1.jar"/>
11+ <classpathentry exported="true" kind="lib" path="xmlrpc-client-1.1.jar"/>
12+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
13 <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
14- <classpathentry exported="true" kind="lib" path="bzr-java-lib-0.5.1-SNAPSHOT.jar" sourcepath="org.vcs.bazaar.eclipse.clientsrc.zip"/>
15- <classpathentry exported="true" kind="lib" path="kxml2-min-2.3.0.jar" sourcepath="org.vcs.bazaar.eclipse.clientsrc.zip"/>
16- <classpathentry exported="true" kind="lib" path="xmlrpc-1.1.jar" sourcepath="org.vcs.bazaar.eclipse.clientsrc.zip"/>
17- <classpathentry exported="true" kind="lib" path="xmlrpc-client-1.1.jar" sourcepath="org.vcs.bazaar.eclipse.clientsrc.zip"/>
18 <classpathentry kind="output" path="bin"/>
19 </classpath>
20
21=== modified file 'org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/CoreTexts.java'
22--- org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/CoreTexts.java 2008-07-17 02:36:37 +0000
23+++ org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/CoreTexts.java 2009-04-16 21:40:23 +0000
24@@ -20,6 +20,8 @@
25 public static String AddCommand_adding;
26
27 public static String AnnotateCommand_annotate;
28+
29+ public static String SendCommand_send;
30
31 public static String CommitCommand_commit;
32
33
34=== added file 'org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/core/commands/SendCommand.java'
35--- org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/core/commands/SendCommand.java 1970-01-01 00:00:00 +0000
36+++ org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/core/commands/SendCommand.java 2009-04-17 13:57:24 +0000
37@@ -0,0 +1,60 @@
38+/**
39+ * LICENSE + COPYRIGHT
40+ */
41+package org.vcs.bazaar.eclipse.core.commands;
42+
43+import org.eclipse.core.runtime.IProgressMonitor;
44+import org.vcs.bazaar.client.IBazaarAnnotation;
45+import org.vcs.bazaar.client.IBazaarClient;
46+import org.vcs.bazaar.client.commandline.commands.options.Option;
47+import org.vcs.bazaar.client.core.BazaarClientException;
48+import org.vcs.bazaar.eclipse.CoreTexts;
49+import org.vcs.bazaar.eclipse.core.model.local.IBzrLocalResource;
50+import org.vcs.bazaar.eclipse.internal.core.BazaarException;
51+import org.vcs.bazaar.client.core.BranchLocation;
52+
53+/**
54+ * @author Javier Der Derian<javierder AT gmail DOT com>
55+ * @BasedOn RevertCommand from BzrEclipse
56+ *
57+ */
58+public class SendCommand extends BazaarCommand {
59+
60+ private final IBzrLocalResource resource;
61+ private IBazaarAnnotation annotation;
62+ private Option[] options;
63+ private String remoteLocation;
64+
65+
66+ public SendCommand(IBzrLocalResource bzrResource, Option[] options, String remoteLocation) {
67+ this.resource = bzrResource;
68+ this.options = options;
69+ this.remoteLocation = remoteLocation;
70+ }
71+
72+ /**
73+ * when this finish you must call {@link #getAnnotation()}
74+ *
75+ * @see org.vcs.bazaar.eclipse.core.commands.IBazaarCommand#run(org.eclipse.core.runtime.IProgressMonitor)
76+ */
77+ public void run(IProgressMonitor monitor) throws BazaarException {
78+ try {
79+ monitor.beginTask(CoreTexts.SendCommand_send, 1000);
80+ IBazaarClient client = getClient(resource.getIResource().getProject());
81+
82+ final BranchLocation branchLocation = new BranchLocation(remoteLocation);
83+
84+ client.send(branchLocation, options);
85+ //annotation = client.annotate(resource.getIResource().getLocation().toFile());
86+ } catch (BazaarClientException e) {
87+ throw BazaarException.wrapException(e, resource.getIResource());
88+ } finally {
89+ monitor.done();
90+ }
91+ }
92+
93+ public IBazaarAnnotation getAnnotation() {
94+ return annotation;
95+ }
96+
97+}
98
99=== modified file 'org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/coretexts.properties'
100--- org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/coretexts.properties 2009-01-01 04:46:34 +0000
101+++ org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/coretexts.properties 2009-04-16 21:40:23 +0000
102@@ -1,6 +1,7 @@
103 AddCommand_adding=Adding files
104 BranchCommand_branching=Executing 'bzr branch'
105 AnnotateCommand_annotate=Getting file annotation
106+SendCommand_send=Sending
107 RemoveCommand_removing=Removing files
108 StatusCommand_status=Executing 'bzr status'
109 DiffCommand_diff=Generating diff
110
111=== modified file 'org.vcs.bazaar.eclipse.ui/plugin.properties'
112--- org.vcs.bazaar.eclipse.ui/plugin.properties 2009-01-18 14:57:50 +0000
113+++ org.vcs.bazaar.eclipse.ui/plugin.properties 2009-04-15 16:36:58 +0000
114@@ -51,6 +51,8 @@
115 ActionResolve_tooltip=Mark a conflict as resolved.
116 ActionRevert_label=&Revert
117 ActionRevert_tooltip=Revert files to a previous revision
118+ActionSend_label=&Send
119+ActionSend_tooltip=Mail or create a merge-directive for submitting changes
120 ActionStatus_label=&Status
121 ActionStatus_tooltip=Display status summary (in the Console)
122 ActionUnCommit_label=UnC&ommit
123
124=== modified file 'org.vcs.bazaar.eclipse.ui/plugin.xml'
125--- org.vcs.bazaar.eclipse.ui/plugin.xml 2009-02-21 23:16:34 +0000
126+++ org.vcs.bazaar.eclipse.ui/plugin.xml 2009-04-15 16:41:07 +0000
127@@ -158,6 +158,14 @@
128 label="%ActionRevert_label" menubarPath="team.main/group4"
129 tooltip="%ActionRevert_tooltip">
130 </action>
131+ <action
132+ class="org.vcs.bazaar.eclipse.ui.actions.SendAction"
133+ definitionId="org.vcs.bazaar.eclipse.ui.actions.ActionSend"
134+ icon="icons/bzrlogo.png"
135+ id="org.vcs.bazaar.eclipse.ui.actions.ActionSend"
136+ label="%ActionSend_label" menubarPath="team.main/group4"
137+ tooltip="%ActionSend_tooltip">
138+ </action>
139 <action
140 class="org.vcs.bazaar.eclipse.ui.actions.AddAction"
141 definitionId="org.vcs.bazaar.eclipse.ui.actions.ActionAdd"
142@@ -748,3 +756,4 @@
143 </extension -->
144
145 </plugin>
146+
147
148=== added file 'org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/actions/SendAction.java'
149--- org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/actions/SendAction.java 1970-01-01 00:00:00 +0000
150+++ org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/actions/SendAction.java 2009-04-17 13:57:24 +0000
151@@ -0,0 +1,86 @@
152+/**
153+ * org.vcs.bazaar.eclipse (c) Vectrace Sep 12, 2006
154+ * Created by zingo
155+ */
156+package org.vcs.bazaar.eclipse.ui.actions;
157+
158+import java.lang.reflect.InvocationTargetException;
159+import java.util.Collection;
160+
161+import org.eclipse.core.resources.IProject;
162+import org.eclipse.core.runtime.IProgressMonitor;
163+import org.eclipse.jface.action.IAction;
164+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
165+import org.eclipse.ui.actions.WorkspaceModifyOperation;
166+import org.vcs.bazaar.eclipse.BzrWorkspaceRoot;
167+import org.vcs.bazaar.eclipse.core.commands.SendCommand;
168+import org.vcs.bazaar.eclipse.core.model.IBzrBranch;
169+import org.vcs.bazaar.eclipse.core.model.local.IBzrLocalResource;
170+import org.vcs.bazaar.eclipse.internal.core.BazaarException;
171+import org.vcs.bazaar.eclipse.ui.dialogs.SendDialog;
172+import org.vcs.bazaar.eclipse.ui.dialogs.SendDialog.SendDialogInfo;
173+
174+/**
175+ * @author Javier Der Derian<javierder AT gmail DOT com>
176+ * @BasedOn RevertAction from BzrEclipse
177+ */
178+public class SendAction extends WorkbenchAction {
179+
180+ /**
181+ * <p>
182+ * The action has been activated. The argument of the method represents the
183+ * 'real' action sitting in the workbench UI.
184+ * </p>
185+ *
186+ * @throws BazaarException
187+ * @see IWorkbenchWindowActionDelegate#run
188+ */
189+ @Override
190+ protected void execute(IAction action) throws BazaarException, InvocationTargetException, InterruptedException {
191+ IProject[] projects = getEnclosingProjectsForSelectedResources();
192+
193+ Collection<IBzrBranch> locations = getAllBranchLocations(projects[0]);
194+
195+ SendDialog dialog = new SendDialog(this.getShell(), locations, new SendDialogInfo());
196+
197+ if(dialog.open() != SendDialog.OK) {
198+ return;
199+ }
200+
201+ final IBzrLocalResource[] resourcesToRevert = BzrWorkspaceRoot.getBzrResourcesFor(projects);
202+
203+ final SendCommand cmd = new SendCommand(resourcesToRevert[0], dialog.getOptions(), dialog.getValue());
204+ run(new WorkspaceModifyOperation() {
205+ public void execute(IProgressMonitor monitor) throws InvocationTargetException {
206+ try {
207+ cmd.run(monitor);
208+ } catch (BazaarException e) {
209+ // FIXME: exception handling
210+ throw new InvocationTargetException(e);
211+ } finally {
212+ monitor.done();
213+ }
214+ }
215+ }, false /* no cancelable */, PROGRESS_DIALOG);
216+
217+ }
218+
219+ protected boolean isEnabledForUnmanagedResources() {
220+ return false;
221+ }
222+
223+ @Override
224+ protected boolean isEnabledForUnmodifiedResources() {
225+ if(getSelectedProjects().length > 1) {
226+ return true;
227+ } else if(getSelectedProjects().length == 1) {
228+ return true;
229+ }
230+ return false;
231+ }
232+
233+ @Override
234+ protected boolean isEnabledForMultipleEclosingProjects() {
235+ return isSameBranchInEnclosingProjects();
236+ }
237+}
238
239=== added file 'org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/dialogs/SendDialog.java'
240--- org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/dialogs/SendDialog.java 1970-01-01 00:00:00 +0000
241+++ org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/dialogs/SendDialog.java 2009-04-17 23:39:17 +0000
242@@ -0,0 +1,281 @@
243+/**
244+ * LICENSE + COPYRIGHT
245+ */
246+package org.vcs.bazaar.eclipse.ui.dialogs;
247+
248+import java.util.ArrayList;
249+import java.util.Collection;
250+import java.util.Collections;
251+import java.util.List;
252+
253+import org.eclipse.jface.dialogs.Dialog;
254+import org.eclipse.jface.dialogs.IDialogConstants;
255+import org.eclipse.swt.SWT;
256+import org.eclipse.swt.events.SelectionAdapter;
257+import org.eclipse.swt.events.SelectionEvent;
258+import org.eclipse.swt.graphics.Point;
259+import org.eclipse.swt.layout.GridData;
260+import org.eclipse.swt.layout.GridLayout;
261+import org.eclipse.swt.widgets.Button;
262+import org.eclipse.swt.widgets.Composite;
263+import org.eclipse.swt.widgets.Display;
264+import org.eclipse.swt.widgets.Group;
265+import org.eclipse.swt.widgets.Label;
266+import org.eclipse.swt.widgets.Shell;
267+import org.eclipse.swt.widgets.Text;
268+import org.vcs.bazaar.client.commandline.commands.options.Option;
269+import org.vcs.bazaar.client.commandline.syntax.ISendOptions;
270+import org.vcs.bazaar.eclipse.core.model.IBzrBranch;
271+import org.vcs.bazaar.eclipse.core.repository.BranchFactory;
272+import org.vcs.bazaar.eclipse.ui.widgets.RevisionNumber;
273+
274+/**
275+ *
276+ * @author Javier Der Derian <javierder AT gmail.com>
277+ * @BasedOn RevertDialog from BzrEclipse
278+ */
279+public class SendDialog extends LocationInputDialog {
280+
281+ private static final String TITLE = "Remote location Dialog";
282+ private static final String MESSAGE = "Please enter the URI of the submit location: ";
283+ private RevisionNumber revision;
284+ private ArrayList<Option> options;
285+ private Button nobundle;
286+ private Button nopatch;
287+ private Button send;
288+ private Button save;
289+
290+ private SendDialogInfo dialogInfo;
291+ private Text submitLocationText;
292+ private Text messageText;
293+ private Text formatText;
294+
295+
296+ /**
297+ * Create the dialog
298+ *
299+ * @param parentShell
300+ * @param selectedResources
301+ * @param commiteableResources
302+ */
303+ public SendDialog(Shell parentShell, Collection<IBzrBranch> locations, SendDialogInfo dialogInfo) {
304+ super(parentShell, TITLE, MESSAGE, "", new BaseURIValidator(), locations, dialogInfo, true, false);
305+ setShellStyle(SWT.RESIZE | SWT.MODELESS | SWT.CLOSE | SWT.BORDER | SWT.TITLE);
306+ setBlockOnOpen(true);
307+ this.dialogInfo = dialogInfo;
308+ }
309+
310+ protected void createOptionsArea(Composite composite) {
311+
312+ final Label label = new Label(composite, SWT.NONE);
313+ label.setText("Enter send location");
314+
315+ Group typeBoxGroup = new Group(composite, SWT.NONE);
316+
317+ GridData typeBoxGrid = new GridData();
318+
319+ typeBoxGrid.horizontalAlignment = SWT.FILL;
320+ typeBoxGroup.setLayout(new GridLayout(2, true));
321+ typeBoxGroup.setLayoutData(typeBoxGrid);
322+
323+ send = new Button(typeBoxGroup, SWT.RADIO);
324+ send.setText("Send to email");
325+ send.setSelection(true); // Start selected.
326+ send.setToolTipText("Send the bundle to a specific email address.");
327+ save = new Button(typeBoxGroup, SWT.RADIO);
328+ save.setText("Save to location");
329+ save.setSelection(false); // Start unselected.
330+ save.setToolTipText("Save bundle to a file in a specific location.");
331+
332+ GridData submitLocationGrid = new GridData();
333+
334+ submitLocationGrid.horizontalAlignment = SWT.FILL;
335+ submitLocationText = new Text(composite, SWT.BORDER | SWT.SINGLE);
336+ submitLocationText.setLayoutData(submitLocationGrid);
337+
338+ final Label label2 = new Label(composite, SWT.NONE);
339+ label2.setText("Message");
340+
341+ GridData messageGrid = new GridData();
342+
343+ messageGrid.horizontalAlignment = SWT.FILL;
344+ messageText = new Text(composite, SWT.BORDER | SWT.SINGLE);
345+ messageText.setLayoutData(messageGrid);
346+
347+ Composite container = new Composite(composite, SWT.NONE);
348+ container.setLayout(new GridLayout(2, false));
349+ container.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false));
350+
351+ Group checkBoxGroup = new Group(container, SWT.NONE);
352+ checkBoxGroup.setLayout(new GridLayout(2, false));
353+ super.createOptionsArea(checkBoxGroup);
354+ nobundle = new Button(checkBoxGroup, SWT.CHECK);
355+ nobundle.setText("No bundle");
356+ nobundle.setSelection(false); // Start unselected.
357+ nobundle.setToolTipText("Do not include a bundle in the merge directive.");
358+ nopatch = new Button(checkBoxGroup, SWT.CHECK);
359+ nopatch.setText("No patch");
360+ nopatch.setSelection(false); // Start unselected.
361+ nopatch.setToolTipText("Do not include a preview patch in the merge directive.");
362+
363+
364+ Composite formatBoxGroup = new Composite(checkBoxGroup, SWT.NONE);
365+
366+ GridData formatBoxGrid = new GridData();
367+
368+ formatBoxGrid.horizontalAlignment = SWT.FILL;
369+ formatBoxGroup.setLayout(new GridLayout(2, false));
370+ formatBoxGroup.setLayoutData(formatBoxGrid);
371+
372+ final Label label3 = new Label(formatBoxGroup, SWT.NONE);
373+ label3.setText("Format");
374+ formatText = new Text(formatBoxGroup, SWT.BORDER | SWT.SINGLE);
375+
376+ Group revisionGroup = new Group(container, SWT.NONE);
377+ revisionGroup.setLayout(new GridLayout());
378+ revision = new RevisionNumber(revisionGroup);
379+
380+ GridData data = new GridData(GridData.FILL, GridData.FILL, true, false);
381+ revisionGroup.setLayoutData(data);
382+ checkBoxGroup.setLayoutData(data);
383+ data = new GridData(GridData.FILL_BOTH);
384+ container.setLayoutData(data);
385+
386+ revision.addShowLogButtonSelectionListener(new SelectionAdapter() {
387+ @Override
388+ public void widgetSelected(SelectionEvent e) {
389+ showLog();
390+ }
391+ });
392+
393+ }
394+
395+ protected void showLog() {
396+ String url = super.getTextInput();
397+ if(url == null || "".equals(url.trim())) {
398+ return;
399+ }
400+ IBzrBranch branch = BranchFactory.getInstance().findOrCreateFor(url);
401+ if(branch != null) {
402+ ShowLogDialog dialog = new ShowLogDialog(getShell(), branch);
403+ if(dialog.open() == Dialog.OK && dialog.getSelectedRevision() != null) {
404+ revision.setRevision(dialog.getSelectedRevision().getValue());
405+ }
406+ }
407+ }
408+
409+ public String getPath() {
410+ return submitLocationText.getText();
411+ }
412+ public String getMessage() {
413+ return messageText.getText();
414+ }
415+
416+ public String getFormat() {
417+ return formatText.getText();
418+ }
419+
420+
421+ public Integer getType(){
422+ // 0 means send by email, 1 means save in file
423+ if(send.getSelection())
424+ return 0;
425+ else
426+ return 1;
427+ }
428+
429+ protected Boolean isNoBundle() {
430+ return nobundle.getSelection();
431+ }
432+
433+ protected Boolean isNoPatch() {
434+ return nopatch.getSelection();
435+ }
436+
437+ public Option[] getOptions() {
438+ return options.toArray(new Option[options.size()]);
439+
440+ }
441+
442+ /**
443+ * Create contents of the button bar
444+ *
445+ * @param parent
446+ */
447+ @Override
448+ protected void createButtonsForButtonBar(Composite parent) {
449+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
450+ true);
451+ createButton(parent, IDialogConstants.CANCEL_ID,
452+ IDialogConstants.CANCEL_LABEL, false);
453+ }
454+
455+ /**
456+ * Return the initial size of the dialog
457+ */
458+ @Override
459+ protected Point getInitialSize() {
460+ return new Point(540, 490);
461+ }
462+
463+ @Override
464+ protected void okPressed() {
465+ this.options = new ArrayList<Option>(0);
466+
467+ if(getPath().length() > 0 && getValue().length() > 0 ) {
468+ if(getType() == 0){
469+ options.add(ISendOptions.MAIL_TO.setArgument(getPath()));
470+ }
471+ else {
472+ options.add(ISendOptions.OUTPUT.setArgument(getPath()));
473+ }
474+ }
475+ else {
476+ //FIXME: give some kind of message
477+ return;
478+ }
479+
480+ options.add(ISendOptions.MESSAGE.setArgument(getMessage()));
481+
482+ if(isRemember()) {
483+ options.add(ISendOptions.REMEMBER);
484+ }
485+
486+ if(isNoBundle()) {
487+ options.add(ISendOptions.NO_BUNDLE);
488+ }
489+
490+ if(isNoPatch()) {
491+ options.add(ISendOptions.NO_PATCH);
492+ }
493+ if(revision.isRevisionSelected()) {
494+ options.add(ISendOptions.REVISION.setArgument(revision.getRevision()));
495+ }
496+
497+ if(getFormat().length() > 0) {
498+ options.add(ISendOptions.FORMAT.setArgument(getFormat()));
499+ }
500+
501+ this.dialogInfo.options = options;
502+ super.okPressed();
503+ }
504+
505+ public static class SendDialogInfo extends LocationDialogInfo {
506+ List<Option> options;
507+
508+ public List<Option> getOptions() {
509+ return options;
510+ }
511+ }
512+
513+ // this main is for test the dialog during development
514+ public static void main(String[] args) {
515+ Display display = new Display();
516+ Shell shell = new Shell(display);
517+ shell.setMinimumSize(280, 400);
518+ SendDialog dialog = new SendDialog(shell, Collections.EMPTY_LIST, new SendDialogInfo());
519+ dialog.setBlockOnOpen(true);
520+ int exit = dialog.open();
521+ System.out.println("exit: " + exit);
522+ }
523+}

Subscribers

People subscribed via source and target branches