001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.plugin.wizards;
034:
035: import org.eclipse.compare.CompareUI;
036:
037: import org.eclipse.core.resources.IProject;
038: import org.eclipse.core.runtime.IProgressMonitor;
039: import org.eclipse.core.runtime.IStatus;
040: import org.eclipse.core.runtime.Status;
041:
042: import org.eclipse.jface.dialogs.ErrorDialog;
043: import org.eclipse.jface.dialogs.MessageDialog;
044: import org.eclipse.jface.operation.IRunnableWithProgress;
045: import org.eclipse.jface.resource.ImageDescriptor;
046: import org.eclipse.jface.wizard.IWizardPage;
047: import org.eclipse.jface.wizard.Wizard;
048: import org.eclipse.jface.wizard.WizardPage;
049:
050: import org.eclipse.swt.SWT;
051: import org.eclipse.swt.events.ModifyEvent;
052: import org.eclipse.swt.events.ModifyListener;
053: import org.eclipse.swt.events.MouseEvent;
054: import org.eclipse.swt.events.MouseListener;
055: import org.eclipse.swt.layout.GridData;
056: import org.eclipse.swt.layout.GridLayout;
057: import org.eclipse.swt.widgets.Button;
058: import org.eclipse.swt.widgets.Composite;
059: import org.eclipse.swt.widgets.Label;
060: import org.eclipse.swt.widgets.Text;
061:
062: import org.libresource.so6.core.WsConnection;
063: import org.libresource.so6.core.client.WorkspaceListener;
064: import org.libresource.so6.core.engine.log.MessageWriter;
065: import org.libresource.so6.plugin.Plugin;
066: import org.libresource.so6.plugin.compare.So6RefCopyCompareInput;
067: import org.libresource.so6.plugin.core.So6Util;
068: import org.libresource.so6.plugin.ui.So6Images;
069:
070: /**
071: * @author Guillaume Bort
072: * @author Sebastien Jourdain
073: */
074: import java.lang.reflect.InvocationTargetException;
075:
076: import java.util.Observable;
077: import java.util.Observer;
078:
079: /**
080: * DOCUMENT ME!
081: *
082: * @author $author$
083: * @version $Revision: 1.3 $
084: */
085: public class CommitWizard extends Wizard {
086: /** DOCUMENT ME! */
087: protected String commitMessage;
088: private IProject project;
089:
090: /**
091: * Creates a new CommitWizard object.
092: *
093: * @param project DOCUMENT ME!
094: */
095: public CommitWizard(IProject project) {
096: this .project = project;
097: }
098:
099: /**
100: * DOCUMENT ME!
101: */
102: public void addPages() {
103: WizardPage commentPage = new CommentPage("comment", "Commit",
104: So6Images.getSo6WizardImage());
105: commentPage
106: .setDescription("Please enter your commit message"
107: + "\n\nThis plugin has been written by the LibreSource consortium. (www.libresource.org)");
108:
109: WizardPage reportPage = new ReportPage("report", "Report",
110: So6Images.getSo6WizardImage());
111: reportPage.setDescription("Commit report");
112: addPage(commentPage);
113: addPage(reportPage);
114: }
115:
116: /**
117: * DOCUMENT ME!
118: *
119: * @return DOCUMENT ME!
120: */
121: public boolean canFinish() {
122: IWizardPage page = getContainer().getCurrentPage();
123:
124: if (page instanceof ReportPage) {
125: return true;
126: }
127:
128: return false;
129: }
130:
131: /**
132: * DOCUMENT ME!
133: *
134: * @param pageContainer DOCUMENT ME!
135: */
136: public void createPageControls(Composite pageContainer) {
137: setWindowTitle("Commit");
138: }
139:
140: /**
141: * DOCUMENT ME!
142: *
143: * @return DOCUMENT ME!
144: */
145: public IWizardPage getStartingPage() {
146: return getPage("comment");
147: }
148:
149: /**
150: * DOCUMENT ME!
151: *
152: * @return DOCUMENT ME!
153: */
154: public boolean performFinish() {
155: try {
156: return true;
157: } catch (Exception e) {
158: MessageDialog
159: .openError(getShell(), "Error", e.getMessage());
160:
161: return false;
162: }
163: }
164:
165: class CommentPage extends WizardPage implements ModifyListener {
166: private Text comment;
167:
168: public CommentPage(String pageName) {
169: super (pageName);
170: }
171:
172: public CommentPage(String pageName, String title,
173: ImageDescriptor titleImage) {
174: super (pageName, title, titleImage);
175: }
176:
177: public void createControl(Composite pageContainer) {
178: Composite composite = new Composite(pageContainer, SWT.NULL);
179: setControl(composite);
180: setNeedsProgressMonitor(true);
181:
182: GridLayout layout = new GridLayout(1, false);
183: composite.setLayout(layout);
184:
185: Label commentLabel = new Label(composite, SWT.NONE);
186: commentLabel.setText("Commit message : ");
187: comment = new Text(composite, SWT.MULTI | SWT.BORDER);
188: comment.addModifyListener(this );
189:
190: GridData gd = new GridData();
191: gd.widthHint = 450;
192: gd.heightHint = 200;
193: comment.setLayoutData(gd);
194:
195: Button seeDiff = new Button(composite, SWT.NONE);
196: seeDiff.setText("See changes...");
197: seeDiff.addMouseListener(new MouseListener() {
198: public void mouseDoubleClick(MouseEvent e) {
199: }
200:
201: public void mouseDown(MouseEvent e) {
202: }
203:
204: public void mouseUp(MouseEvent e) {
205: try {
206: CompareUI
207: .openCompareDialog(new So6RefCopyCompareInput(
208: project));
209: } catch (Exception ex) {
210: ex.printStackTrace();
211: }
212: }
213: });
214: }
215:
216: public IWizardPage getNextPage() {
217: return getPage("report");
218: }
219:
220: public void modifyText(ModifyEvent e) {
221: commitMessage = comment.getText();
222: }
223: }
224:
225: class Commit implements IRunnableWithProgress {
226: protected String report;
227: private IProject project;
228: private String comment;
229: private WsConnection connection;
230:
231: public Commit(String comment, IProject project)
232: throws Exception {
233: this .comment = comment;
234: this .project = project;
235: connection = new WsConnection(So6Util
236: .getAbsoluteSo6PropertiesPath(project));
237: }
238:
239: public void run(IProgressMonitor monitor)
240: throws InvocationTargetException, InterruptedException {
241: monitor.beginTask("Commiting", 100);
242:
243: try {
244: CommitObserver observer = new CommitObserver(monitor);
245: connection.commit(comment);
246:
247: if (connection.getClient() instanceof WorkspaceListener) {
248: ((WorkspaceListener) connection.getClient())
249: .notifyQueue(connection.getNs());
250: }
251:
252: monitor.subTask("Refreshing project");
253: So6Util.refresh(project, monitor);
254: report = connection.getReport();
255: } catch (Exception e) {
256: throw new CommitException(e.getMessage());
257: }
258:
259: monitor.done();
260: }
261:
262: class CommitObserver implements Observer, MessageWriter {
263: private IProgressMonitor monitor;
264:
265: public CommitObserver(IProgressMonitor monitor) {
266: this .monitor = monitor;
267: }
268:
269: public void printMessage(boolean b, String message) {
270: }
271:
272: public void update(Observable obs, Object arg) {
273: }
274: }
275: }
276:
277: class CommitException extends InvocationTargetException {
278: private String message;
279:
280: public CommitException(String message) {
281: this .message = "Error during the commit : " + message;
282: }
283:
284: public String getMessage() {
285: return message;
286: }
287: }
288:
289: class ReportPage extends WizardPage {
290: protected Text report;
291:
292: public ReportPage(String pageName) {
293: super (pageName);
294: }
295:
296: public ReportPage(String pageName, String title,
297: ImageDescriptor titleImage) {
298: super (pageName, title, titleImage);
299: }
300:
301: public void createControl(Composite pageContainer) {
302: Composite composite = new Composite(pageContainer, SWT.NULL);
303: setControl(composite);
304: setNeedsProgressMonitor(true);
305:
306: GridLayout layout = new GridLayout(1, false);
307: composite.setLayout(layout);
308: report = new Text(composite, SWT.MULTI | SWT.NONE);
309: report.setEditable(false);
310:
311: GridData gd = new GridData();
312: gd.widthHint = 450;
313: gd.heightHint = 200;
314: report.setLayoutData(gd);
315: }
316:
317: public IWizardPage getPreviousPage() {
318: return null;
319: }
320:
321: public void setVisible(boolean visible) {
322: super .setVisible(visible);
323:
324: try {
325: Commit commit = new Commit(commitMessage, project);
326: getContainer().run(true, true, commit);
327: report.setText(commit.report);
328: } catch (Exception e) {
329: ErrorDialog.openError(getShell(), "Error in commit", e
330: .getMessage(), new Status(IStatus.ERROR,
331: Plugin.ID, IStatus.OK, e.getMessage(), e));
332: }
333: }
334: }
335: }
|