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.operation.IRunnableWithProgress;
042: import org.eclipse.jface.resource.ImageDescriptor;
043: import org.eclipse.jface.wizard.IWizardPage;
044: import org.eclipse.jface.wizard.Wizard;
045: import org.eclipse.jface.wizard.WizardPage;
046:
047: import org.eclipse.swt.SWT;
048: import org.eclipse.swt.events.ModifyEvent;
049: import org.eclipse.swt.events.ModifyListener;
050: import org.eclipse.swt.layout.GridData;
051: import org.eclipse.swt.layout.GridLayout;
052: import org.eclipse.swt.widgets.Button;
053: import org.eclipse.swt.widgets.Combo;
054: import org.eclipse.swt.widgets.Composite;
055: import org.eclipse.swt.widgets.Label;
056: import org.eclipse.swt.widgets.TabFolder;
057: import org.eclipse.swt.widgets.TabItem;
058: import org.eclipse.swt.widgets.Text;
059:
060: import org.eclipse.team.core.RepositoryProvider;
061: import org.eclipse.team.ui.IConfigurationWizard;
062:
063: import org.eclipse.ui.IWorkbench;
064:
065: import org.libresource.so6.core.Workspace;
066: import org.libresource.so6.core.WsConnection;
067: import org.libresource.so6.core.client.ClientIServletImpl;
068: import org.libresource.so6.core.exec.CreateGenericWsConnection;
069: import org.libresource.so6.plugin.Plugin;
070: import org.libresource.so6.plugin.core.So6TeamProvider;
071: import org.libresource.so6.plugin.core.So6Util;
072: import org.libresource.so6.plugin.ui.So6Images;
073:
074: /**
075: * @author Guillaume Bort
076: * @author Sebastien Jourdain
077: * @author Gerald Oster
078: */
079: import java.io.File;
080:
081: import java.lang.reflect.InvocationTargetException;
082:
083: import java.net.URI;
084: import java.net.URL;
085:
086: import java.util.Properties;
087:
088: /**
089: * DOCUMENT ME!
090: *
091: * @author $author$
092: * @version $Revision: 1.3 $
093: */
094: public class SharingWizard extends Wizard implements
095: IConfigurationWizard {
096: /** DOCUMENT ME! */
097: protected IProject project;
098:
099: /** DOCUMENT ME! */
100: protected IWorkbench workbench;
101:
102: /** DOCUMENT ME! */
103: protected String clientNameValue;
104:
105: /** DOCUMENT ME! */
106: protected String locationValue;
107:
108: /** DOCUMENT ME! */
109: protected String nameValue;
110:
111: /** DOCUMENT ME! */
112: protected String passwordValue;
113:
114: /** DOCUMENT ME! */
115: protected String serverValue;
116:
117: //
118:
119: /** DOCUMENT ME! */
120: protected String uriValue;
121:
122: /** DOCUMENT ME! */
123: protected String usernameValue;
124:
125: //
126:
127: /** DOCUMENT ME! */
128: protected WsConnection[] cxs;
129:
130: /** DOCUMENT ME! */
131: protected boolean connectExistingWorkspace = true;
132:
133: /** DOCUMENT ME! */
134: protected boolean createDefaultIgnoreFileValue = false;
135:
136: /** DOCUMENT ME! */
137: protected int selectedConnection;
138:
139: /**
140: * DOCUMENT ME!
141: */
142: public void addPages() {
143: WizardPage replicaPage = new CreateReplicaPage("createReplica",
144: "Enter So6 queue location informations", So6Images
145: .getSo6WizardImage());
146: replicaPage
147: .setDescription("Connect this project to an existing synchronizer");
148: addPage(replicaPage);
149: }
150:
151: /**
152: * DOCUMENT ME!
153: *
154: * @param pageContainer DOCUMENT ME!
155: */
156: public void createPageControls(Composite pageContainer) {
157: super .createPageControls(pageContainer);
158: setWindowTitle("Connect the project " + project.getName()
159: + " to a So6 queue");
160: }
161:
162: /**
163: * DOCUMENT ME!
164: *
165: * @param page DOCUMENT ME!
166: *
167: * @return DOCUMENT ME!
168: */
169: public IWizardPage getNextPage(IWizardPage page) {
170: return null;
171: }
172:
173: /**
174: * DOCUMENT ME!
175: *
176: * @return DOCUMENT ME!
177: */
178: public IWizardPage getStartingPage() {
179: return getPage("createReplica");
180: }
181:
182: /**
183: * DOCUMENT ME!
184: *
185: * @param workbench DOCUMENT ME!
186: * @param project DOCUMENT ME!
187: */
188: public void init(IWorkbench workbench, IProject project) {
189: this .workbench = workbench;
190: this .project = project;
191: }
192:
193: /**
194: * DOCUMENT ME!
195: *
196: * @return DOCUMENT ME!
197: */
198: public boolean performFinish() {
199: try {
200: String so6Path = null;
201:
202: if (connectExistingWorkspace) {
203: so6Path = (cxs[selectedConnection].getDataPath()
204: + File.separator + WsConnection.SO6_WSC_FILE)
205: .substring(project.getLocation().toString()
206: .length() + 1);
207: } else {
208: if ((serverValue == null) || (uriValue == null)) {
209: throw new Exception("Invalid uri");
210: }
211:
212: CreateReplica createReplica = new CreateReplica(
213: uriValue, locationValue, serverValue,
214: usernameValue, passwordValue, nameValue,
215: clientNameValue, createDefaultIgnoreFileValue,
216: serverValue);
217: getContainer().run(true, true, createReplica);
218: so6Path = (createReplica.connectionPath
219: + File.separator + WsConnection.SO6_WSC_FILE)
220: .substring(project.getLocation().toString()
221: .length() + 1);
222: }
223:
224: So6Util.setSo6PropertiesPath(project, so6Path);
225: RepositoryProvider.map(project, So6TeamProvider.ID);
226:
227: return true;
228: } catch (Exception e) {
229: e.printStackTrace();
230: ErrorDialog.openError(getShell(),
231: "Error in create workspace", e.getMessage(),
232: new Status(IStatus.ERROR, Plugin.ID, IStatus.OK, e
233: .getMessage(), e));
234:
235: return false;
236: }
237: }
238:
239: class CreateReplica implements IRunnableWithProgress {
240: protected String connectionPath;
241: private String clientName;
242: private String location;
243: private String name;
244: private String password;
245: private String server;
246: private String serverHttpURL;
247: private String uri;
248: private String user;
249: private boolean createDefaultIgnoreFile = false;
250:
251: public CreateReplica(String uri, String location,
252: String server, String user, String password,
253: String name, String clientName,
254: boolean createDefaultIgnoreFile, String serverHttpURL) {
255: this .uri = uri;
256: this .location = location;
257: this .server = server;
258: this .user = user;
259: this .password = password;
260: this .name = name;
261: this .clientName = clientName;
262: this .createDefaultIgnoreFile = createDefaultIgnoreFile;
263: this .serverHttpURL = serverHttpURL;
264: }
265:
266: public void run(IProgressMonitor monitor)
267: throws InvocationTargetException, InterruptedException {
268: monitor.beginTask("Creating local workspace", 1);
269:
270: Properties props = new Properties();
271:
272: try {
273: if ((serverHttpURL != null)
274: && (serverHttpURL.trim().length() > 0)) {
275: URL serverURL = new URL(serverHttpURL);
276: int port = serverURL.getPort();
277:
278: if (port == -1) {
279: port = 80;
280: }
281:
282: props.setProperty(
283: ClientIServletImpl.SO6_SERVICE_URL,
284: "http://" + serverURL.getHost() + ":"
285: + port + "/ls-so6/so6");
286: }
287:
288: //
289: CreateGenericWsConnection cgwsc = new CreateGenericWsConnection(
290: location, name, clientName, user, password,
291: uri, props);
292:
293: if (createDefaultIgnoreFile) {
294: cgwsc.execute(":bin$\n:build$\n\\.class$\n");
295: } else {
296: cgwsc.execute();
297: }
298:
299: connectionPath = cgwsc.getWsc().getDataPath();
300: So6Util.refresh(project, monitor);
301: } catch (Exception e) {
302: throw new CreateReplicaException(e.getMessage());
303: }
304:
305: monitor.done();
306: }
307: }
308:
309: class CreateReplicaException extends InvocationTargetException {
310: private String message;
311:
312: public CreateReplicaException(String message) {
313: this .message = "Error during the creation of the workspace : "
314: + message;
315: }
316:
317: public String getMessage() {
318: return message;
319: }
320: }
321:
322: class CreateReplicaPage extends WizardPage implements
323: ModifyListener {
324: private Button createIgnoreFile;
325: private Combo clientName;
326: private Combo connections;
327: private TabFolder tabFolder;
328: private Text name;
329: private Text password;
330: private Text serveurUrl;
331: private Text uri;
332: private Text username;
333:
334: public CreateReplicaPage(String pageName) {
335: super (pageName);
336: }
337:
338: public CreateReplicaPage(String pageName, String title,
339: ImageDescriptor titleImage) {
340: super (pageName, title, titleImage);
341: }
342:
343: public void createControl(Composite composite) {
344: Composite pageContainer = new Composite(composite, SWT.NULL);
345: setControl(pageContainer);
346: setNeedsProgressMonitor(true);
347:
348: GridLayout all = new GridLayout(1, false);
349: pageContainer.setLayout(all);
350: tabFolder = new TabFolder(pageContainer, SWT.NONE);
351:
352: TabItem existingCx = new TabItem(tabFolder, SWT.NONE);
353: existingCx.setText("Existing connection");
354:
355: //Group existingLocation = new Group(tabFolder, SWT.NONE);
356: //existingLocation.setText("Existing connection");
357: Composite existingLocation = new Composite(tabFolder,
358: SWT.NONE);
359: GridLayout somelayout = new GridLayout(1, false);
360: existingLocation.setLayout(somelayout);
361: connections = new Combo(existingLocation, SWT.NONE);
362: connections.addModifyListener(this );
363:
364: if ((new File(project.getLocation().toString() + "/.so6"))
365: .exists()) {
366: try {
367: Workspace tmpws = new Workspace(project
368: .getLocation().toString());
369:
370: //System.out.println(project.getLocation().toString());
371: cxs = tmpws.listConnections();
372:
373: for (int i = 0; i < cxs.length; i++) {
374: connections.add(cxs[i].getWsName() + " ["
375: + cxs[i].getDataPath() + "]");
376: }
377:
378: if (cxs.length == 0) {
379: connections.setEnabled(false);
380: }
381: } catch (Exception e) {
382: //e.printStackTrace();
383: connections.setEnabled(false);
384: }
385:
386: connections
387: .setText("Please choose an existing connection");
388: }
389:
390: existingCx.setControl(existingLocation);
391:
392: // queue location
393: TabItem newCx = new TabItem(tabFolder, SWT.NONE);
394: newCx.setText("Create a new connection");
395:
396: //Group queueLocation = new Group(tabFolder, SWT.NONE);
397: //queueLocation.setText("replica configuration");
398: Composite queueLocation = new Composite(tabFolder, SWT.NONE);
399: GridLayout layout = new GridLayout(2, false);
400: queueLocation.setLayout(layout);
401:
402: Label nameLabel = new Label(queueLocation, SWT.NONE);
403: nameLabel.setText("Workspace name : ");
404: name = new Text(queueLocation, SWT.SINGLE | SWT.BORDER);
405: name.addModifyListener(this );
406:
407: // Synchronizer uri
408: GridData gd = new GridData();
409: gd.widthHint = 300;
410: name.setLayoutData(gd);
411:
412: Label queueURI = new Label(queueLocation, SWT.NONE);
413: queueURI.setText("Synchronizer URI : ");
414: uri = new Text(queueLocation, SWT.SINGLE | SWT.BORDER);
415: uri.addModifyListener(this );
416:
417: // user name
418: gd = new GridData();
419: gd.widthHint = 300;
420: uri.setLayoutData(gd);
421:
422: Label usernameLabel = new Label(queueLocation, SWT.NONE);
423: usernameLabel.setText("Username : ");
424: gd = new GridData();
425: gd.widthHint = 300;
426: username = new Text(queueLocation, SWT.SINGLE | SWT.BORDER);
427: username.addModifyListener(this );
428: username.setLayoutData(gd);
429:
430: // Password
431: Label passwordLabel = new Label(queueLocation, SWT.NONE);
432: passwordLabel.setText("Password : ");
433: gd = new GridData();
434: gd.widthHint = 300;
435: password = new Text(queueLocation, SWT.SINGLE | SWT.BORDER);
436: password.addModifyListener(this );
437: password.setLayoutData(gd);
438: password.setEchoChar('*');
439:
440: // Server host
441: gd = new GridData();
442: gd.widthHint = 300;
443: uri.setLayoutData(gd);
444:
445: Label serveurUrlLabel = new Label(queueLocation, SWT.NONE);
446: serveurUrlLabel.setText("Server address : ");
447: gd = new GridData();
448: gd.widthHint = 300;
449: serveurUrl = new Text(queueLocation, SWT.SINGLE
450: | SWT.BORDER);
451: serveurUrl.addModifyListener(this );
452: serveurUrl.setLayoutData(gd);
453:
454: // Client Name
455: gd = new GridData();
456: gd.widthHint = 300;
457: uri.setLayoutData(gd);
458:
459: Label clientNameLabel = new Label(queueLocation, SWT.NONE);
460: clientNameLabel.setText("Client type : ");
461: gd = new GridData();
462: gd.widthHint = 300;
463: clientName = new Combo(queueLocation, SWT.SINGLE
464: | SWT.BORDER);
465: clientName.add("Local client");
466: clientName.add("LibreSource client");
467: clientName.addModifyListener(this );
468: clientName.setLayoutData(gd);
469: clientName.select(1);
470:
471: // Create ignore file
472: /*
473: gd = new GridData();
474: gd.widthHint = 300;
475: createIgnoreFile = new Button(queueLocation, SWT.SINGLE | SWT.BORDER);
476: createIgnoreFile.setText("Create default ignore file");
477: createIgnoreFile.setLayoutData(gd);
478: */
479: //
480: newCx.setControl(queueLocation);
481: }
482:
483: public void modifyText(ModifyEvent e) {
484: try {
485: connectExistingWorkspace = this .tabFolder
486: .getSelectionIndex() == 0;
487: uriValue = new URI(this .uri.getText()).getPath();
488: usernameValue = this .username.getText();
489: passwordValue = this .password.getText();
490: serverValue = this .serveurUrl.getText();
491: locationValue = project.getLocation().toString();
492: nameValue = this .name.getText();
493:
494: if (this .clientName.getSelectionIndex() == 0) {
495: clientNameValue = CreateGenericWsConnection.FS_CLIENT_NAME;
496: } else {
497: clientNameValue = CreateGenericWsConnection.LS_CLIENT_NAME;
498: }
499:
500: createDefaultIgnoreFileValue = false;
501: selectedConnection = connections.getSelectionIndex();
502: } catch (Exception e1) {
503: //
504: }
505: }
506: }
507: }
|