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.core.resources.IProject;
036: import org.eclipse.core.runtime.IProgressMonitor;
037: import org.eclipse.core.runtime.IStatus;
038: import org.eclipse.core.runtime.Status;
039:
040: import org.eclipse.jface.dialogs.ErrorDialog;
041: import org.eclipse.jface.dialogs.MessageDialog;
042: import org.eclipse.jface.operation.IRunnableWithProgress;
043: import org.eclipse.jface.resource.ImageDescriptor;
044: import org.eclipse.jface.wizard.IWizardPage;
045: import org.eclipse.jface.wizard.Wizard;
046: import org.eclipse.jface.wizard.WizardPage;
047:
048: import org.eclipse.swt.SWT;
049: import org.eclipse.swt.layout.GridData;
050: import org.eclipse.swt.layout.GridLayout;
051: import org.eclipse.swt.widgets.Composite;
052: import org.eclipse.swt.widgets.Label;
053: import org.eclipse.swt.widgets.Text;
054:
055: import org.libresource.so6.core.WsConnection;
056: import org.libresource.so6.core.client.WorkspaceListener;
057: import org.libresource.so6.core.engine.log.MessageWriter;
058: import org.libresource.so6.plugin.Plugin;
059: import org.libresource.so6.plugin.core.So6Util;
060: import org.libresource.so6.plugin.ui.So6Images;
061:
062: /**
063: * @author Guillaume Bort
064: * @author Sebastien Jourdain
065: */
066: import java.lang.reflect.InvocationTargetException;
067:
068: import java.util.Observable;
069: import java.util.Observer;
070:
071: /**
072: * DOCUMENT ME!
073: *
074: * @author $author$
075: * @version $Revision: 1.3 $
076: */
077: public class UpdateWizard extends Wizard {
078: private IProject project;
079:
080: /**
081: * Creates a new UpdateWizard object.
082: *
083: * @param project DOCUMENT ME!
084: */
085: public UpdateWizard(IProject project) {
086: this .project = project;
087: }
088:
089: /**
090: * DOCUMENT ME!
091: */
092: public void addPages() {
093: WizardPage infosPage = new InfosPage("infos", "Update",
094: So6Images.getSo6WizardImage());
095: infosPage.setDescription("Click next to start update");
096:
097: WizardPage reportPage = new ReportPage("report", "Report",
098: So6Images.getSo6WizardImage());
099: reportPage.setDescription("Update report");
100: addPage(infosPage);
101: addPage(reportPage);
102: }
103:
104: /**
105: * DOCUMENT ME!
106: *
107: * @return DOCUMENT ME!
108: */
109: public boolean canFinish() {
110: IWizardPage page = getContainer().getCurrentPage();
111:
112: if (page instanceof ReportPage) {
113: return true;
114: }
115:
116: return false;
117: }
118:
119: /**
120: * DOCUMENT ME!
121: *
122: * @param pageContainer DOCUMENT ME!
123: */
124: public void createPageControls(Composite pageContainer) {
125: setWindowTitle("Udpate");
126: }
127:
128: /**
129: * DOCUMENT ME!
130: *
131: * @return DOCUMENT ME!
132: */
133: public IWizardPage getStartingPage() {
134: return getPage("infos");
135: }
136:
137: /**
138: * DOCUMENT ME!
139: *
140: * @return DOCUMENT ME!
141: */
142: public boolean performFinish() {
143: try {
144: return true;
145: } catch (Exception e) {
146: MessageDialog
147: .openError(getShell(), "Error", e.getMessage());
148:
149: return false;
150: }
151: }
152:
153: class InfosPage extends WizardPage {
154: public InfosPage(String pageName) {
155: super (pageName);
156: }
157:
158: public InfosPage(String pageName, String title,
159: ImageDescriptor titleImage) {
160: super (pageName, title, titleImage);
161: }
162:
163: public void createControl(Composite pageContainer) {
164: Composite composite = new Composite(pageContainer, SWT.NULL);
165: setControl(composite);
166: setNeedsProgressMonitor(true);
167:
168: GridLayout layout = new GridLayout(1, false);
169: composite.setLayout(layout);
170:
171: Label commentLabel = new Label(composite, SWT.NONE);
172: commentLabel
173: .setText("Click next to start the update process"
174: + "\n\nThis plugin has been written by the LibreSource consortium. (www.libresource.org)");
175: }
176:
177: public IWizardPage getNextPage() {
178: return getPage("report");
179: }
180: }
181:
182: class ReportPage extends WizardPage {
183: protected Text report;
184:
185: public ReportPage(String pageName) {
186: super (pageName);
187: }
188:
189: public ReportPage(String pageName, String title,
190: ImageDescriptor titleImage) {
191: super (pageName, title, titleImage);
192: }
193:
194: public void createControl(Composite pageContainer) {
195: Composite composite = new Composite(pageContainer, SWT.NULL);
196: setControl(composite);
197: setNeedsProgressMonitor(true);
198:
199: GridLayout layout = new GridLayout(1, false);
200: composite.setLayout(layout);
201: report = new Text(composite, SWT.MULTI | SWT.READ_ONLY
202: | SWT.V_SCROLL);
203: report.setEditable(false);
204:
205: GridData gd = new GridData();
206: gd.widthHint = 450;
207: gd.heightHint = 200;
208: report.setLayoutData(gd);
209: }
210:
211: public IWizardPage getPreviousPage() {
212: return null;
213: }
214:
215: public void setVisible(boolean visible) {
216: super .setVisible(visible);
217:
218: try {
219: Update update = new Update(project);
220: getContainer().run(true, true, update);
221:
222: if ("".equals(update.report)) {
223: report.setText("Replica is already up-to-date.");
224: } else {
225: report.setText(update.report);
226: }
227: } catch (Exception e) {
228: ErrorDialog.openError(getShell(), "Error in update", e
229: .getMessage(), new Status(IStatus.ERROR,
230: Plugin.ID, IStatus.OK, e.getMessage(), e));
231: }
232: }
233: }
234:
235: class Update implements IRunnableWithProgress {
236: protected String report;
237: private IProject project;
238: private WsConnection connection;
239:
240: public Update(IProject project) throws Exception {
241: this .project = project;
242: connection = new WsConnection(So6Util
243: .getAbsoluteSo6PropertiesPath(project));
244: }
245:
246: public void run(IProgressMonitor monitor)
247: throws InvocationTargetException, InterruptedException {
248: monitor.beginTask("Updating", 100);
249:
250: try {
251: CommitObserver observer = new CommitObserver(monitor);
252: connection.update();
253:
254: if (connection.getClient() instanceof WorkspaceListener) {
255: ((WorkspaceListener) connection.getClient())
256: .notifyQueue(connection.getNs());
257: }
258:
259: monitor.subTask("Refreshing project");
260: So6Util.refresh(project, monitor);
261: report = connection.getReport();
262: } catch (Exception e) {
263: throw new UpdateException(e.getMessage());
264: }
265:
266: monitor.done();
267: }
268:
269: class CommitObserver implements Observer, MessageWriter {
270: private IProgressMonitor monitor;
271:
272: public CommitObserver(IProgressMonitor monitor) {
273: this .monitor = monitor;
274: }
275:
276: public void printMessage(boolean b, String message) {
277: }
278:
279: public void update(Observable obs, Object arg) {
280: }
281: }
282: }
283:
284: class UpdateException extends InvocationTargetException {
285: private String message;
286:
287: public UpdateException(String message) {
288: this .message = "Error during the update : " + message;
289: }
290:
291: public String getMessage() {
292: return message;
293: }
294: }
295: }
|