Révision 1885

tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/GSERunner.java (revision 1885)
64 64
//			}
65 65
			return defaultGSE;
66 66
		}
67
		
68
		if (rootDir == null) {
69
			rootDir = new File(Toolbox.getTxmHomePath(), "scripts/groovy/");
70
		}
67

  
71 68
		String[] roots = new String[] { 
72 69
				rootDir.getAbsolutePath()+"/user/", //$NON-NLS-1$
73 70
				rootDir.getAbsolutePath()+"/system/", //$NON-NLS-1$
tmp/org.txm.rcp/plugin.xml (revision 1885)
648 648
                  tooltip="%command.tooltip.26">
649 649
            </command>
650 650
            <command
651
                  commandId="org.txm.rcp.commands.ChangeTXMWorkspace"
652
                  style="push">
653
            </command>
654
            <command
651 655
                  commandId="org.eclipse.ui.file.exit"
652 656
                  label="%command.label.6"
653 657
                  style="push"
......
2440 2444
            id="org.txm.rcp.commands.function.RenameResult"
2441 2445
            name="%command.name.4">
2442 2446
      </command>
2447
      <command
2448
            categoryId="org.txm.rcp.category.txm"
2449
            defaultHandler="org.txm.rcp.commands.ChangeTXMWorkspace"
2450
            id="org.txm.rcp.commands.ChangeTXMWorkspace"
2451
            name="Change working directory...">
2452
      </command>
2443 2453
   </extension>
2444 2454
   <extension
2445 2455
         id="commands"
tmp/org.txm.rcp/src/main/java/org/txm/rcp/actions/ImportDialog.java (revision 1885)
174 174
			Label dirLabel = new Label(mainPanel, SWT.NONE);
175 175
			dirLabel.setText(TXMUIMessages.sourceDirectoryColon);
176 176
			dirLabel.setAlignment(SWT.CENTER);
177
			dirLabel.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
178
					false, false));
177
			dirLabel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, false));
179 178

  
180 179
			dirValue = new Text(mainPanel, SWT.SINGLE | SWT.BORDER);
181
			dirValue.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
182
					true, false));
180
			dirValue.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
183 181
			if (lastopenedbase != null)
184 182
				dirValue.setText(lastopenedbase.getPath());
185 183

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/messages/TXMUIMessages.java (revision 1885)
525 525
	
526 526
	public static String updateDone;
527 527

  
528
	public static String gnuLicenceLink;
529

  
530
	public static String gnuLicenceName;
531

  
532
	public static String iAcceptTheLicenceAndAgreeToQuoteTXMInMyWork;
533

  
534
	public static String seeTheQuoteSectionIn;
535

  
536
	public static String TXMisDistributedUnderLicence;
537

  
538
	public static String selectWorkingDirectoryP0;
539
	
528 540
	static {
529 541
		// initialize resource bundle
530 542
		Utf8NLS.initializeMessages(BUNDLE_NAME, TXMUIMessages.class);
tmp/org.txm.rcp/src/main/java/org/txm/rcp/messages/messages.properties (revision 1885)
996 996

  
997 997
importDone=Import done.
998 998

  
999
updateDone=Update done.
999
updateDone=Update done.
1000

  
1001
TXMisDistributedUnderLicence=TXM is released under the 
1002
gnuLicenceLink=https://www.gnu.org/licenses/gpl-2.0.en.html
1003
gnuLicenceName=GNU General Public License version 2
1004
iAcceptTheLicenceAndAgreeToQuoteTXMInMyWork=I accept TXM license terms and I accept to quote TXM in my publications.
1005
seeTheQuoteSectionIn=(see the "How to Cite the Textometry project" section in the textometrie.org web site: 
1006
selectWorkingDirectoryP0=Working directory
1007
options=Options...
tmp/org.txm.rcp/src/main/java/org/txm/rcp/messages/messages_fr.properties (revision 1885)
775 775

  
776 776
sVGGraphic = Graphique SVG 
777 777

  
778
sampleCorporaOfCurrentTXMP0 = Corpus d'exemple de la version courante de TXM {0}
778
sampleCorporaOfCurrentTXMP0 = Corpus exemples de la version courante de TXM {0}
779 779

  
780 780
saveAndRun = Sauver et lancer
781 781

  
......
893 893

  
894 894
tXMiniColon = TXM.ini : 
895 895

  
896
termsOfService = Veuillez    accepter la licence d'utilisation
896
termsOfService = Veuillez accepter la licence d'utilisation
897 897

  
898 898
textEditorColonP0EncodingFoundP1 = Editeur de Texte: l'encodage de {0} est {1}
899 899

  
......
907 907

  
908 908
theCorpusAndTheCorpusP0WillBeDeleted = Le corpus {0} va être supprimé.
909 909

  
910
theErrorIsColon = L'erreur est :  
910
theErrorIsColon = L'erreur est : 
911 911

  
912 912
theFileP0DoesNotExist = Le fichier {0} est introuvable.
913 913

  
......
992 992

  
993 993
importDone=Import terminé.
994 994

  
995
updateDone=Mise à jour terminée.
995
updateDone=Mise à jour terminée.
996

  
997
TXMisDistributedUnderLicence=TXM est diffusé sous licence 
998
gnuLicenceLink=https://www.gnu.org/licenses/gpl-2.0.fr.html
999
gnuLicenceName=GNU General Public License version 2
1000
iAcceptTheLicenceAndAgreeToQuoteTXMInMyWork=J'accepte les termes de la licence et je m'engage à citer TXM dans mes publications
1001
seeTheQuoteSectionIn=(voir la section 'Citer le logiciel TXM' de la page d'accueil du site 
1002
selectWorkingDirectoryP0=Répertoire de travail
1003
options=Options...
tmp/org.txm.rcp/src/main/java/org/txm/rcp/IImageKeys.java (revision 1885)
225 225
	public static final String OPEN_DECORATOR = "icons/decorators/bullet_arrow_down.png";
226 226
	public static final String CLOSE_DECORATOR = "icons/decorators/bullet_arrow_up.png";
227 227

  
228
	public static final String TXM_FLAT_LOGO = "icons/logo/TXM_flat_logo.png";
229

  
228 230
	/**
229 231
	 * Gets the image.
230 232
	 *
tmp/org.txm.rcp/src/main/java/org/txm/rcp/Activator.java (revision 1885)
65 65
		super.start(context);
66 66

  
67 67
		System.out.println("TXM ACTIVATED. ALL SYSTEMS GO!");
68
		try {
69
			preventbrokenTXMINI();
70
		} catch(Exception e) {
71
			System.out.println("Error while fixing TXM.ini file: "+e.getLocalizedMessage());
72
		}
68
//		try {
69
//			preventBrokenTXMINI();
70
//		} catch(Exception e) {
71
//			System.out.println("Error while fixing TXM.ini file: "+e);
72
//		}
73 73
	}
74 74

  
75 75
	//TODO: this method is temporary to fix the TXM.ini file -startup and --launcher.library properties
76
	private void preventbrokenTXMINI() throws Exception {
76
	private void preventBrokenTXMINI() throws Exception {
77 77
		
78 78
		File dataDir = new File(Platform.getInstanceLocation().getURL().getFile());
79 79
		File txmDir = dataDir.getParentFile();
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/SelectDirectoryWidget.java (revision 1885)
1
package org.txm.rcp.swt;
2

  
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.events.SelectionEvent;
5
import org.eclipse.swt.events.SelectionListener;
6
import org.eclipse.swt.layout.GridData;
7
import org.eclipse.swt.widgets.Button;
8
import org.eclipse.swt.widgets.Composite;
9
import org.eclipse.swt.widgets.DirectoryDialog;
10
import org.eclipse.swt.widgets.Label;
11
import org.eclipse.swt.widgets.Text;
12

  
13
public class SelectDirectoryWidget extends GLComposite {
14

  
15
	Text t;
16
	String path;
17
	
18
	public SelectDirectoryWidget(Composite parent, int style, String initialDefault, String label) {
19
		super(parent, style, "CGU");
20
		this.path = initialDefault;
21
		
22
		this.getLayout().numColumns = 2;
23
		this.getLayout().marginBottom = 2;
24
		this.getLayout().horizontalSpacing = 4;
25
		if (label != null) {
26
			this.getLayout().numColumns = this.getLayout().numColumns + 1;
27
			
28
			new Label(this, SWT.NONE).setText(label);
29
		}
30
		
31
		t = new Text(this, SWT.BORDER);
32
		t.setText(initialDefault);
33
		t.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
34
		
35
		Button selectDirectoryButton = new Button(this, SWT.PUSH);
36
		selectDirectoryButton.setText("...");
37
		selectDirectoryButton.addSelectionListener(new SelectionListener() {
38

  
39
			@Override
40
			public void widgetSelected(SelectionEvent e) {
41
				
42
				DirectoryDialog dialog = new DirectoryDialog(e.display.getActiveShell());
43
				dialog.setMessage("Select working directory");
44
				dialog.setText(t.getText());
45
				String tpath = dialog.open();
46
				if (tpath != null) {
47
					t.setText(tpath);
48
					path = tpath;
49
				}
50
			}
51

  
52
			@Override
53
			public void widgetDefaultSelected(SelectionEvent e) { }
54
		});
55
	}
56
	
57
	public String getPath() {
58
		return path;
59
	}
60
}
0 61

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/dialog/CGUMessageDialog.java (revision 1885)
1 1
package org.txm.rcp.swt.dialog;
2 2

  
3
import java.io.IOException;
4
import java.net.URI;
5
import java.net.URISyntaxException;
6

  
3 7
import org.eclipse.jface.dialogs.Dialog;
4 8
import org.eclipse.jface.window.Window;
9
import org.eclipse.osgi.util.NLS;
5 10
import org.eclipse.swt.SWT;
6 11
import org.eclipse.swt.events.MouseEvent;
7 12
import org.eclipse.swt.events.MouseListener;
......
10 15
import org.eclipse.swt.graphics.Color;
11 16
import org.eclipse.swt.graphics.Cursor;
12 17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.layout.GridLayout;
13 19
import org.eclipse.swt.layout.RowLayout;
14 20
import org.eclipse.swt.widgets.Button;
15 21
import org.eclipse.swt.widgets.Composite;
16 22
import org.eclipse.swt.widgets.Control;
17 23
import org.eclipse.swt.widgets.Display;
24
import org.eclipse.swt.widgets.ExpandBar;
25
import org.eclipse.swt.widgets.ExpandItem;
26
import org.eclipse.swt.widgets.Group;
18 27
import org.eclipse.swt.widgets.Label;
19 28
import org.eclipse.swt.widgets.Shell;
29
import org.eclipse.swt.widgets.Text;
30
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
20 31
import org.txm.rcp.IImageKeys;
21 32
import org.txm.rcp.commands.OpenBrowser;
22 33
import org.txm.rcp.messages.TXMUIMessages;
34
import org.txm.rcp.swt.SelectDirectoryWidget;
23 35

  
24 36
public class CGUMessageDialog extends Dialog {
25 37

  
26 38
	boolean checked = false;
27 39

  
28 40
	Button checkMessageButton = null;
41
	ChooseWorkspaceData launchData;
29 42

  
30
	protected CGUMessageDialog(Shell shell) {
43
	private SelectDirectoryWidget w;
44
	 
45
	protected CGUMessageDialog(Shell shell, ChooseWorkspaceData launchData) {
31 46
		super(shell);
47
		this.launchData = launchData;
32 48
	}
33 49

  
34 50
	protected void configureShell(Shell newShell) {
35 51
		super.configureShell(newShell);
36
		newShell.setText(TXMUIMessages.termsOfService);
37

  
52
		newShell.setText("Premier lancement de TXM/First launch of TXM");
38 53
	}
39 54

  
40 55
	@Override
41 56
	protected Control createDialogArea(Composite parent) {
42 57
		Control c = super.createDialogArea(parent);
43 58

  
59
		GridLayout parentLayout = (GridLayout) parent.getLayout();
60
		parentLayout.marginLeft = 5;
61
		parentLayout.marginRight = 5;
44 62
		Display display = Display.getCurrent();
45 63

  
46 64
		//new Label(messageComposite, SWT.NONE).setImage(IImageKeys.getImage(IImageKeys.TXM_ICON));
47 65
		Label logo = new Label(parent, SWT.NONE);
48
		logo.setImage(IImageKeys.getImage(IImageKeys.TXM_ICON));//new Image(display, "/home/mdecorde/workspace047/org.txm.rcp/icons/logo/TXM_logo_64x64.png"));
66
		logo.setImage(IImageKeys.getImage(IImageKeys.TXM_FLAT_LOGO));//new Image(display, "/home/mdecorde/workspace047/org.txm.rcp/icons/logo/TXM_logo_64x64.png"));
49 67
		logo.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, false));
68
		
69
		new Label(parent, SWT.NONE);
70
		
71
		Composite licenceGroup = new Composite(parent, SWT.NONE);
72
		//licenceGroup.setText("Licence d'utilisation/Licence agreement");
73
		licenceGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
74
		GridLayout glayout = new GridLayout(1, true);
75
		glayout.verticalSpacing = 0;
76
		licenceGroup.setLayout(glayout);
50 77

  
51
		Composite messageComposite = new Composite(parent, SWT.NONE);
78
		Composite messageComposite = new Composite(licenceGroup, SWT.NONE);
52 79
		messageComposite.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, false));
53 80
		messageComposite.setLayout(new RowLayout());
81
		
82
		new Label(messageComposite, SWT.NONE).setText(TXMUIMessages.TXMisDistributedUnderLicence);
54 83

  
55

  
56
		new Label(messageComposite, SWT.NONE).setText("TXM est diffusé sous licence ");
57

  
58
		final String gnuLicenseLink = "https://www.gnu.org/licenses/gpl-2.0.en.html"; //$NON-NLS-1$
84
		final String gnuLicenseLink = TXMUIMessages.gnuLicenceLink;
59 85
		Label gnuLicense = new Label(messageComposite, SWT.NONE);
60
		gnuLicense.setText("GNU GPL 2");
86
		gnuLicense.setText(TXMUIMessages.gnuLicenceName); // GNU GPL 2
61 87
		gnuLicense.setToolTipText(gnuLicenseLink);
62 88
		gnuLicense.addMouseListener(new MouseListener() {
63 89

  
64 90
			@Override
65 91
			public void mouseUp(MouseEvent e) { 
66
				OpenBrowser.openExternalBrowser(gnuLicenseLink);
92
				//OpenBrowser.openExternalBrowser(gnuLicenseLink);
93
				try {
94
					java.awt.Desktop.getDesktop().browse(new URI(gnuLicenseLink));
95
				} catch (Exception e1) {
96
					e1.printStackTrace();
97
				}
67 98
			}
68 99

  
69 100
			@Override
......
78 109
		gnuLicense.setForeground(blue);
79 110
		gnuLicense.setCursor(cursor);
80 111

  
81
		new Label(parent, SWT.NONE);
82

  
83
		checkMessageButton = new Button(parent, SWT.CHECK);
84
		checkMessageButton.setText("J'accepte la licence et je m'engage à citer TXM dans mes travaux de recherche.");
112
		checkMessageButton = new Button(licenceGroup, SWT.CHECK);
113
		checkMessageButton.setText(TXMUIMessages.iAcceptTheLicenceAndAgreeToQuoteTXMInMyWork);
85 114
		checkMessageButton.addSelectionListener(new SelectionListener() {
86 115

  
87 116
			@Override
......
93 122
			public void widgetDefaultSelected(SelectionEvent e) { }
94 123
		});
95 124

  
96
		Composite seeComposite = new Composite(parent, SWT.NONE);
125
		Composite seeComposite = new Composite(licenceGroup, SWT.NONE);
97 126
		seeComposite.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, false));
98 127
		seeComposite.setLayout(new RowLayout());
99 128

  
100
		new Label(seeComposite, SWT.NONE).setText("Voir la section 'Citation de TXM' de la page de ");
101

  
129
		new Label(seeComposite, SWT.NONE).setText(TXMUIMessages.seeTheQuoteSectionIn);
102 130
		
103
		final String txmDownloadLink = "http://textometrie.ens-lyon.fr/spip.php?rubrique61"; //$NON-NLS-1$
131
		final String txmDownloadLink = "http://www.textometrie.org"; //$NON-NLS-1$
104 132
		Label txmDownload = new Label(seeComposite, SWT.NONE);
105
		txmDownload.setText("Téléchargement");
133
		txmDownload.setText("http://www.textometrie.org");
106 134
		txmDownload.setToolTipText(txmDownloadLink);
107 135
		txmDownload.setForeground(blue);
108 136
		txmDownload.setCursor(cursor);
......
110 138

  
111 139
			@Override
112 140
			public void mouseUp(MouseEvent e) {
113
				OpenBrowser.openExternalBrowser(txmDownloadLink);
141
				//OpenBrowser.openExternalBrowser(txmDownloadLink);
142
				try {
143
					java.awt.Desktop.getDesktop().browse(new URI(txmDownloadLink));
144
				} catch (Exception e1) {
145
					e1.printStackTrace();
146
				}
114 147
			}
115 148

  
116 149
			@Override
......
120 153
			public void mouseDoubleClick(MouseEvent e) { }
121 154
		});
122 155

  
156
		new Label(seeComposite, SWT.NONE).setText(")"); //$NON-NLS-1$
157
		
158
		ExpandBar bar = new ExpandBar (parent, SWT.V_SCROLL);
159
		GridData gdata = new GridData(GridData.FILL, GridData.FILL, true, true);
160
		bar.setLayoutData(gdata);
161
		
162
		w = new SelectDirectoryWidget(bar, SWT.NONE, launchData.getInitialDefault(), TXMUIMessages.selectWorkingDirectoryP0);
163
		//w.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
164
		
165
		// "Options"
166
		ExpandItem item1 = new ExpandItem (bar, SWT.NONE);
167
		item1.setText("Options...");
168
		item1.setHeight(w.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
169
		item1.setControl(w);
170
		item1.setExpanded(false);
171
		gdata.heightHint = item1.getHeight()*2;
172
		gdata.minimumHeight = item1.getHeight();
173
		//item1.setExpanded(false);
174
//		Group dirGroup = new Group(parent, SWT.NONE);
175
//		dirGroup.setText(NLS.bind(TXMUIMessages.selectWorkingDirectoryP0, launchData.getInitialDefault())); 
176
//		dirGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
177
//		dirGroup.setLayout(new GridLayout(1, true));
178
//		
179
		
180
		
123 181
		return c;
124 182
	}
125 183

  
......
137 195
	@Override
138 196
	protected void buttonPressed(int buttonId) {
139 197
		checked = checkMessageButton.getSelection();
198
		launchData.workspaceSelected(w.getPath());
140 199
		super.buttonPressed(buttonId);
141 200
	}
142 201

  
......
146 205

  
147 206
		return checked;
148 207
	}
149
	
150
	
151 208

  
152 209
	public static void main(String[] args) {
153
		CGUMessageDialog dialog = new CGUMessageDialog(Display.getDefault().getActiveShell());
154
		/**
155
		 * CGUMessageDialog dialog = new CGUMessageDialog(Display.getCurrent().getActiveShell(), 
156
					TXMUIMessages.termsOfService, 
157
					IImageKeys.getImage(IImageKeys.TXM_ICON), 
158
					TXMUIMessages.infpSupTXMIsPublishedUnderTheGNUGPL2LicenseAmpltInfaHrefEqualshttpsColonwwwgnuorglicensesgpl20enhtmlSuphttpsColonwwwgnuorglicensesgpl20enhtmlInfaSupAmpgt,
159
					IImageKeys.getImage(IImageKeys.TXM), 
160
					TXMUIMessages.iAcceptTheLicenceAndIUndertakeToCiteTXMForAcknowledgingMyUseOfTXMInMyResearchWorkSeeTheCitationSectionOfTheInfhttpColontextometrieenslyonfrspipphprubrique61SupPage, 
161
					dialogButtonLabels, 0) {
162
			};
163
		 */
164
		dialog.open();
210
//		CGUMessageDialog dialog = new CGUMessageDialog(Display.getDefault().getActiveShell());
211
//		/**
212
//		 * CGUMessageDialog dialog = new CGUMessageDialog(Display.getCurrent().getActiveShell(), 
213
//					TXMUIMessages.termsOfService, 
214
//					IImageKeys.getImage(IImageKeys.TXM_ICON), 
215
//					TXMUIMessages.infpSupTXMIsPublishedUnderTheGNUGPL2LicenseAmpltInfaHrefEqualshttpsColonwwwgnuorglicensesgpl20enhtmlSuphttpsColonwwwgnuorglicensesgpl20enhtmlInfaSupAmpgt,
216
//					IImageKeys.getImage(IImageKeys.TXM), 
217
//					TXMUIMessages.iAcceptTheLicenceAndIUndertakeToCiteTXMForAcknowledgingMyUseOfTXMInMyResearchWorkSeeTheCitationSectionOfTheInfhttpColontextometrieenslyonfrspipphprubrique61SupPage, 
218
//					dialogButtonLabels, 0) {
219
//			};
220
//		 */
221
//		dialog.open();
165 222
	}
166 223

  
167 224
	//	protected Control createMessageArea(Composite composite) {
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/ChangeTXMWorkspace.java (revision 1885)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.rcp.commands;
29

  
30
import java.net.MalformedURLException;
31
import java.net.URL;
32

  
33
import org.eclipse.core.commands.AbstractHandler;
34
import org.eclipse.core.commands.ExecutionEvent;
35
import org.eclipse.core.commands.ExecutionException;
36
import org.eclipse.core.runtime.IProgressMonitor;
37
import org.eclipse.core.runtime.IStatus;
38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.equinox.app.IApplication;
40
import org.eclipse.osgi.util.NLS;
41
import org.eclipse.swt.widgets.Display;
42
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.ui.PlatformUI;
44
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
45
import org.eclipse.ui.internal.ide.ChooseWorkspaceDialog;
46
import org.txm.Toolbox;
47
import org.txm.rcp.Application;
48
import org.txm.rcp.JobsTimer;
49
import org.txm.rcp.messages.TXMUIMessages;
50
import org.txm.rcp.utils.JobHandler;
51
import org.txm.rcp.views.SummaryView;
52
import org.txm.rcp.views.fileexplorer.MacroExplorer;
53
import org.txm.utils.logger.Log;
54

  
55
// TODO: Auto-generated Javadoc
56
/**
57
 * restart TXM: restart searchengine, statengine, workspace... 
58
 * @author mdecorde
59
 * 
60
 */
61
public class ChangeTXMWorkspace extends AbstractHandler {
62

  
63
	/** The ID. */
64
	static public String ID = "org.txm.rcp.commands.RestartTXM"; //$NON-NLS-1$
65

  
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
68
	 */
69
	@Override
70
	public Object execute(ExecutionEvent event) throws ExecutionException {
71

  
72
		JobHandler jobhandler = new JobHandler("Changing working directory...") { 
73
			@Override
74
			protected IStatus run(IProgressMonitor monitor) {
75
				JobsTimer.start();
76
				try {
77

  
78
					monitor.worked(95);
79
					syncExec(new Runnable() {
80
						@Override
81
						public void run() {
82
							change();
83
						}
84
					});
85

  
86
				} catch (Exception e) {
87
					System.out.println(NLS.bind(TXMUIMessages.errorWhileRunningScriptColonP0, e));
88
					org.txm.utils.logger.Log.printStackTrace(e);
89
				} finally {
90
					monitor.done();
91
				}
92
				JobsTimer.stopAndPrint();
93
				return Status.OK_STATUS;
94
			}
95
		};
96
		jobhandler.startJob();
97
		return event;
98
	}
99

  
100
	public static boolean change() {
101
		
102
		ChooseWorkspaceData launchData = new ChooseWorkspaceData("");
103
		ChooseWorkspaceDialog dialog =
104
				new ChooseWorkspaceDialog(Display.getCurrent().getActiveShell(), launchData, true, true);
105
		dialog.setTitle("Select TXM working directory to use. This will restart TXM.");
106
		// don't force prompt : setShowDialogValue is set on error
107
		dialog.prompt(true);
108

  
109
		// check choosen path
110
		String selWS = launchData.getSelection();
111
		if (selWS == null)
112
			return false;// user cancelled (no restart)
113

  
114
		// Switch workspace :
115
		URL url = null;
116
		try {
117
			url = new URL("file", "", selWS);
118
			launchData.writePersistedData();
119
			ChooseWorkspaceData.setShowDialogValue(false);
120
			PlatformUI.getWorkbench().restart(); // need to restart TXM to apply changes
121
		} catch (MalformedURLException e1) {
122
			Log.warning("Workspace path could not be found.");
123
			return false;
124
		}
125
		
126
		return false;
127
	}
128
}
0 129

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/ApplicationWorkbenchAdvisor.java (revision 1885)
189 189
		engine.setTheme(theme, true);
190 190
	}
191 191

  
192
	private void openCGU() {
193
		try {
194
			if (!TBXPreferences.getInstance().getBoolean(RCPPreferences.CGU)) {
195

  
196
				//System.out.println("Opening CGU...");
197
				//Display.getCurrent() works because this code is run during the splash screen
198
				//String[] dialogButtonLabels = {TXMCoreMessages.common_ok, TXMCoreMessages.common_cancel};
199
				CGUMessageDialog dialog = new CGUMessageDialog(Display.getCurrent().getActiveShell()) {
200
				};
201
				boolean ret = (dialog.open() == MessageDialog.OK) && dialog.hasCheckBeenPressed();
202
				if (ret) {
203
					TBXPreferences.getInstance().put(RCPPreferences.CGU, true);
204
				} else {
205
					System.exit(0);
206
				}
207
			}
208
		} catch(Exception e) {
209
			Log.severe("Error: can't open CGU dialog: "+e);
210
			Log.printStackTrace(e);
211
			System.exit(0);
212
		}
213
	}
214

  
215 192
	/**
216 193
	 * initialization code done after the splash screen call a job which does the
217 194
	 * post installation the TXMHOME, checks the TreeTagger and finally
......
229 206
					this.runInit(monitor);
230 207
					try {
231 208

  
232
						// CGU popup
233
						this.syncExec(new Runnable() {
234
							@Override
235
							public void run() {
236
								openCGU();
237
								printTXMVersion(); // print TXM version in the console
238
							}
239
						});
240

  
241 209
						monitor.beginTask("Starting TXM", 100);
242 210

  
243 211
						monitor.setTaskName(TXMUIMessages.loadingTXMInstallPreferences);
......
719 687
						return false;
720 688
					}
721 689
					String version = v.getMajor()+"."+v.getMinor()+"."+v.getMicro();
722
					if ("qualifier".equals(v.getQualifier())) { //$NON-NLS-1$
690
					if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) { //$NON-NLS-1$
723 691
						System.out.println("RUNNING TXM FROM ECLIPSE - DEV MODE ACTIVATED");
724 692
						version += "-dev";
725 693
					}
......
792 760
		corporaDirs.add(V080);
793 761
		corporaDirs.add(V079);
794 762
		
795
		
796 763
		Display.getDefault().syncExec(new Runnable() {
797 764
			@Override
798 765
			public void run() {
tmp/org.txm.rcp/src/main/java/org/txm/rcp/Application.java (revision 1885)
28 28
package org.txm.rcp;
29 29

  
30 30
import java.io.File;
31
import java.io.IOException;
32
import java.net.MalformedURLException;
33
import java.net.URL;
34
import java.nio.file.attribute.UserPrincipalLookupService;
31 35
import java.util.Arrays;
32 36
import java.util.List;
33 37
import java.util.Map;
......
35 39

  
36 40
import org.eclipse.core.net.proxy.IProxyService;
37 41
import org.eclipse.core.runtime.Platform;
42
import org.eclipse.core.runtime.preferences.ConfigurationScope;
38 43
import org.eclipse.equinox.app.IApplication;
39 44
import org.eclipse.equinox.app.IApplicationContext;
45
import org.eclipse.jface.dialogs.MessageDialog;
40 46
import org.eclipse.jface.util.Util;
47
import org.eclipse.osgi.util.TextProcessor;
48
import org.eclipse.swt.SWT;
41 49
import org.eclipse.swt.widgets.Display;
50
import org.eclipse.swt.widgets.MessageBox;
51
import org.eclipse.swt.widgets.Shell;
42 52
import org.eclipse.ui.PlatformUI;
53
import org.eclipse.ui.ide.IDE;
54
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
55
import org.eclipse.ui.internal.ide.ChooseWorkspaceDialog;
56
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
43 57
import org.osgi.framework.Bundle;
44 58
import org.osgi.framework.ServiceReference;
59
import org.osgi.framework.Version;
60
import org.osgi.service.prefs.Preferences;
45 61
import org.txm.Toolbox;
46 62
import org.txm.core.messages.TXMCoreMessages;
47 63
import org.txm.core.preferences.TBXPreferences;
48 64
import org.txm.rcp.messages.TXMUIMessages;
65
import org.txm.rcp.preferences.RCPPreferences;
66
import org.txm.rcp.swt.dialog.CGUMessageDialog;
67
import org.txm.utils.BundleUtils;
49 68
import org.txm.utils.logger.Log;
50 69

  
51
// TODO: Auto-generated Javadoc
52 70
/**
53 71
 * This class controls all aspects of the application's execution.
54 72
 */
......
71 89
	@Override
72 90
	public Object start(IApplicationContext context) throws Exception {
73 91

  
92
		Display display = PlatformUI.createDisplay();
93

  
94
		//		if (Platform.inDevelopmentMode() || Platform.inDebugMode()) {
95
		//			// this can not work in development environment
96
		//			// as it need to have a default workspace set to none
97
		//			// see product configuration :
98
		//			// osgi.instance.area=@noDefault
99
		//			// ignored in development
100
		//			// -------------------------------------
101
		//
102
		//		} else {
103
		// in Release mode only : platform workspace selection on startup
104
		// then restart if needed (on workspace error...)
105
		Integer ret = openCGU();
106
		if (ret == IApplication.EXIT_RESTART) {
107
			System.out.println("** Working directory set by user.");
108
			return IApplication.EXIT_RESTART;
109
		} else if (ret == IApplication.EXIT_OK) {
110
			System.out.println("** Fail to open CGU or set working directory.");
111
			return IApplication.EXIT_OK; // an error occurred or user canceled
112
		} else {
113
			// OK
114
		}
115
		//		}
116

  
117
		// Die if platform WS not set (user cancel)
118
		// ---------------------------
119

  
120
		if (Platform.getInstanceLocation().getURL() == null) {
121
			System.out.println("** Working directory not set.");
122
			return IApplication.EXIT_OK;
123
		}
124

  
125

  
74 126
		// load JVM fonts in SWT env
75 127
		if (System.getProperty("os.name").contains("Linux")) { // $NON-NLS-1$ $NON-NLS-2$
76 128
			File javaFontsPath = new File(System.getProperty("java.home")
......
105 157
			Toolbox.setPreference(TBXPreferences.LOG_STACKTRACE, true);
106 158
		}
107 159
		if (argsList.contains("-run")) { //$NON-NLS-1$
108
			//System.out.println("Running TXM");
160
			System.out.println("Running TXM");
109 161
			// FIXME: need to check that all has been well moved in Workspace class or build.properties
110 162
			//		} else if (argsList.contains("-standalone")) { //$NON-NLS-1$
111 163
			//			File userhomeDirectory = new File("workspace").getAbsoluteFile(); // eclipse default workspace directory
......
156 208
			return IApplication.EXIT_OK;
157 209
		}
158 210

  
159
		Display display = PlatformUI.createDisplay();
211

  
160 212
		//display.addListener(SWT.OpenDocument, openDocProcessor);
161 213

  
162
		//Lock the RCP workspace, thus there is only one TXM instance running
163
		Log.warning(TXMUIMessages.lockRCPWorkspace);
164
		if (!Platform.getInstanceLocation().lock()){
165
			//Shell shell = display.getActiveShell();
166
			System.out.println("TXM is already running. Exiting...");
167
			return IApplication.EXIT_OK;
168
		}
214
		//		//Lock the RCP workspace, thus there is only one TXM instance running
215
		//		Log.warning(TXMUIMessages.lockRCPWorkspace);
216
		//		if (!Platform.getInstanceLocation().lock()){
217
		//			//Shell shell = display.getActiveShell();
218
		//			System.out.println("TXM is already running. Exiting...");
219
		//			return IApplication.EXIT_OK;
220
		//		}
169 221

  
170 222
		try {
171 223
			Log.warning(TXMUIMessages.activateProxyService);
......
180 232

  
181 233
			//run the application mainloop
182 234
			awa = new ApplicationWorkbenchAdvisor();
235
			System.out.println("Running TXM workbench.");
183 236
			int returnCode = PlatformUI.createAndRunWorkbench(display, awa);
184 237

  
185 238
			if (returnCode == PlatformUI.RETURN_RESTART) {
239
				System.out.println("Restarting TXM.");
186 240
				return IApplication.EXIT_RESTART;
187 241
			}
188 242

  
243
			System.out.println("Exiting TXM.");
189 244
			return IApplication.EXIT_OK;
190 245
		} finally {
191 246
			// System.out.println(Messages.Application_2);
......
193 248
		}
194 249
	}
195 250

  
251
	private Integer openCGU() {
252
		try {
253
			
254
			Version v = BundleUtils.getBundleVersion("org.txm.rcp");//$NON-NLS-1$
255
			if (v == null) {
256
				System.out.println("Error: no 'org.txm.rcp' version found.");
257
				return IApplication.EXIT_OK;
258
			}
259
			String version = v.getMajor()+"."+v.getMinor()+"."+v.getMicro();
260
			if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) { //$NON-NLS-1$
261
				System.out.println("RUNNING TXM FROM ECLIPSE - DEV MODE ACTIVATED");
262
				version += "-dev";
263
			}
264
			System.out.println("Version="+version);
265
			
266
			File txmhomedir = new File(System.getProperty("user.home"), "TXM-"+version); //$NON-NLS-1$ //$NON-NLS-2$
267

  
268
			
269
			
270
			//System.out.println("CGU="+ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH).getBoolean(RCPPreferences.CGU, false));
271
			if (!ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH).getBoolean(RCPPreferences.CGU, false)) {
272
				ChooseWorkspaceData launchData = new ChooseWorkspaceData(txmhomedir.getAbsolutePath());
273
				System.out.println("Opening CGU dialog...");
274
				CGUMessageDialog dialog = new CGUMessageDialog(Display.getCurrent().getActiveShell(), launchData) {};
275
				boolean ret = (dialog.open() == MessageDialog.OK) && dialog.hasCheckBeenPressed();
276
				if (ret) {
277
					//TBXPreferences.getInstance().put(RCPPreferences.CGU, true);
278

  
279
					// check choosen path
280
					Integer ret2 = setInstanceLocation(launchData);
281
					if (ret2 != -1) {
282
						return ret2;
283
					}
284

  
285
					// validate Current as default Workspace, save configuration & history
286

  
287
					launchData.writePersistedData();
288
					System.out.println("save workspace location: "+launchData.getSelection());
289
					ChooseWorkspaceData.setShowDialogValue(false);
290

  
291
					Preferences node = ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH);
292
					node.putBoolean(RCPPreferences.CGU, true);
293
					node.flush();
294

  
295
					return -1;
296

  
297
				} else {
298
					return IApplication.EXIT_OK;
299
				}
300
			} else {
301
				ChooseWorkspaceData launchData = new ChooseWorkspaceData(txmhomedir.getAbsolutePath());
302
				String[] recent = launchData.getRecentWorkspaces();
303

  
304
		        // If the selection dialog was not used then the workspace to use is either the
305
		        // most recent selection or the initialDefault (if there is no history).
306
		        String workspace = null;
307
		        if (recent != null && recent.length > 0) {
308
					workspace = recent[0];
309
				}
310
		        if (workspace == null || workspace.length() == 0) {
311
					workspace = launchData.getInitialDefault();
312
				}
313
		        launchData.workspaceSelected(TextProcessor.deprocess(workspace));
314
				
315
				return setInstanceLocation(launchData);
316
			}
317
		} catch(Exception e) {
318
			System.out.println("Error: can't open CGU dialog: "+e);
319
			e.printStackTrace();
320
			return IApplication.EXIT_OK;
321
		}
322
	}
323

  
324
	private Integer setInstanceLocation(ChooseWorkspaceData launchData) {
325
		String selWS = launchData.getSelection();
326
		if (selWS == null) {
327
			System.out.println("** No workspace set in configuration scope.");
328
			return IApplication.EXIT_OK;// user cancelled (no restart)
329
		}
330

  
331
		// Switch workspace :
332
		URL url = null;
333
		try {
334
			url = new URL("file", "", selWS);
335
		} catch (MalformedURLException e1) {
336
			showWorkspaceError("Workspace path could not be found.");
337
			return IApplication.EXIT_OK;
338
		}
339

  
340
		try {
341
			if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) {
342
				return -1; // can't call Platform.getInstanceLocation().set(...) in dev mode
343
			}
344

  
345
			if (!Platform.getInstanceLocation().set(url, true)) {
346
				showWorkspaceError("TXM is already running. Exiting...");
347
				ChooseWorkspaceData.setShowDialogValue(false);
348
				return IApplication.EXIT_OK;
349
			} else {
350
				return -1; // OK !!
351
			}
352
		} catch (IllegalStateException e) {
353
			showWorkspaceError("Workspace is in an illegal state: "+e);
354
			ChooseWorkspaceData.setShowDialogValue(true);
355
			return IApplication.EXIT_OK;
356
		} catch (IOException e) {
357
			showWorkspaceError("Workspace could not be found on disk: "+e);
358
			ChooseWorkspaceData.setShowDialogValue(true);
359
			return IApplication.EXIT_OK;
360
		}
361

  
362

  
363
	}
364

  
365
	//	/**
366
	//	 * Open choose workspace dialog and validate the user's choice. Returns true
367
	//	 * if restart needed.
368
	//	 */
369
	//	private static Integer chooseWorkspaceUrl(Shell shell) {
370
	//		ChooseWorkspaceData launchData = new ChooseWorkspaceData("");
371
	////		if (!launchData.getShowDialog()) {
372
	////			launchData.toggleShowDialog();
373
	////		}
374
	//		ChooseWorkspaceDialog dialog =
375
	//				new ChooseWorkspaceDialog(shell, launchData, true, true);
376
	//
377
	//		// don't force prompt : setShowDialogValue is set on error
378
	//		dialog.prompt(false);
379
	//
380
	//		// check choosen path
381
	//		String selWS = launchData.getSelection();
382
	//		if (selWS == null)
383
	//			return IApplication.EXIT_OK;// user cancelled (no restart)
384
	//
385
	//		// Switch workspace :
386
	//		URL url = null;
387
	//		try {
388
	//			url = new URL("file", "", selWS);
389
	//		} catch (MalformedURLException e1) {
390
	//			showWorkspaceError("Workspace path could not be found.");
391
	//			return IApplication.EXIT_OK;
392
	//		}
393
	//
394
	//		try {
395
	//			if (!Platform.getInstanceLocation().set(url, true)) {
396
	//				showWorkspaceError("TXM is already running. Exiting...");
397
	//				ChooseWorkspaceData.setShowDialogValue(false);
398
	//				return IApplication.EXIT_OK;
399
	//			}
400
	//
401
	//		} catch (IllegalStateException e) {
402
	//			showWorkspaceError("Workspace is in an illegal state: "+e);
403
	//			ChooseWorkspaceData.setShowDialogValue(true);
404
	//			return IApplication.EXIT_OK;
405
	//		} catch (IOException e) {
406
	//			showWorkspaceError("Workspace could not be found on disk: "+e);
407
	//			ChooseWorkspaceData.setShowDialogValue(true);
408
	//			return IApplication.EXIT_OK;
409
	//		}
410
	//
411
	//		// validate Current as default Workspace, save configuration & history
412
	//		
413
	//		launchData.writePersistedData();
414
	//		ChooseWorkspaceData.setShowDialogValue(false);
415
	//		return -1;// user cancelled (no restart)
416
	//	}
417

  
418
	private static void showWorkspaceError(String message) {
419
		MessageBox messageBox = new MessageBox(new Shell(), SWT.DIALOG_TRIM | SWT.ERROR);
420
		messageBox.setText("TXM start Error");
421
		messageBox.setMessage(message);
422
		messageBox.open();
423
	}
424

  
196 425
	public ApplicationWorkbenchAdvisor getApplicationWorkbenchAdvisor() {
197 426
		return awa;
198 427
	}
tmp/org.txm.rcp/rcpapplication.product (revision 1885)
318 318
      <plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="2" />
319 319
      <plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="2" />
320 320
      <plugin id="org.eclipse.equinox.simpleconfigurator" autoStart="true" startLevel="1" />
321
      <property name="osgi.instance.area" value="@noDefault" />
321 322
   </configurations>
322 323

  
323 324
   <preferencesInfo>
tmp/org.txm.core/src/java/org/txm/Toolbox.java (revision 1885)
587 587
			return false;
588 588
		}
589 589

  
590
		File workspaceFile = new File(txmhomedir, "corpora/.metadata");
591 590
		Version currentVersion = BundleUtils.getBundleVersion("org.txm.core");
592 591
		Log.fine(TXMCoreMessages.bind("Current toolbox version: {0}.", currentVersion));
593 592
		String installedVersionString = getPreference(TBXPreferences.VERSION);
......
601 600

  
602 601
			boolean doUpdateworkspace = currentVersion.compareTo(installedVersion) > 0;
603 602

  
604
			// no directory
605
			if (!workspaceFile.exists()) {
606

  
607
				Log.severe(NLS.bind(TXMCoreMessages.noWorkspaceFoundCreatingANewOneP0, workspaceFile)); 
608

  
609
				// create or update the workspace & create TXM default.xml workspace file
610
				Toolbox.workspace = createOrUpdate(new File(txmhomedir)); //$NON-NLS-1$
611

  
612
				// test
613
				if (Toolbox.workspace == null) {
614
					Log.severe("Error: workspace not created (is null).");
615
					return false;
616
				}
617

  
618
				setPreference(TBXPreferences.VERSION, currentVersion.toString());
619
			} else if (doUpdateworkspace) { // newer install
603
			if (doUpdateworkspace) { // newer install
620 604
				Log.fine("Updating Toolbox workspace...");
621 605

  
622 606
				// create or update the workspace & create TXM default.xml workspace file
......
632 616
				workspace = Workspace.getInstance();
633 617
			}
634 618

  
635
			Log.fine(NLS.bind(TXMCoreMessages.loadingWorkspaceFromFileColonP0, workspaceFile)); 
619
			Log.fine(NLS.bind(TXMCoreMessages.loadingWorkspaceFromFileColonP0, txmhomedir)); 
636 620
			state = true;
637 621

  
638 622
			if (workspace == null) { //$NON-NLS-1$
639
				Log.severe(NLS.bind(TXMCoreMessages.errorLoadingWorkspaceFromFileColonP0, workspaceFile)); 
623
				Log.severe(NLS.bind(TXMCoreMessages.errorLoadingWorkspaceFromFileColonP0, txmhomedir)); 
640 624
				state = false;
641 625
				//System.out.println(TXMCoreMessages.FAILED);
642 626
				return false;
......
660 644
				}
661 645
			}
662 646
		} catch (Exception e) {
663
			Log.severe(NLS.bind(TXMCoreMessages.errorDuringWorkspaceInitializationColonP0, workspaceFile)); 
647
			Log.severe(NLS.bind(TXMCoreMessages.errorDuringWorkspaceInitializationColonP0, txmhomedir)); 
664 648
			Log.severe(NLS.bind(TXMCoreMessages.errorColonP0, Log.toString(e)));
665 649
			Log.printStackTrace(e);
666 650
			state = false;
......
720 704
	 * @return the workspace
721 705
	 */
722 706
	public static Workspace createOrUpdate(File txmhomedir) {
723
		//TODO replace this old directory&file with the ".project" Eclipse project configuration file
724
		File workspaceDirectory = new File(txmhomedir, "corpora");
725
		//		File xmlfile = new File(workspaceDirectory, "default.xml");
726

  
727 707
		try {
728 708
			txmhomedir.mkdirs();
729 709

  
......
736 716
			String createfolders[] = {
737 717
					"corpora", "clipboard", //$NON-NLS-1$ //$NON-NLS-2$
738 718
					"css", "xsl", "schema", "scripts"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
739
			String deletefolders[] = {"clipboard"}; //$NON-NLS-1$ //$NON-NLS-2$
719
			String deletefolders[] = {"clipboard"}; //$NON-NLS-1$
740 720

  
741 721
			for (String folder : deletefolders) {
742 722
				DeleteDir.deleteDirectory(new File(txmhomedir, folder));
......
761 741

  
762 742
			File redistDirectory = new File(installDirectory, "redist");
763 743
			if (!redistDirectory.exists()) {
764
				Log.severe("Warning: Workspace cannot found redist directory: "+redistDirectory.getAbsolutePath());
744
				Log.warning("Warning: Workspace cannot found redist directory: "+redistDirectory.getAbsolutePath());
765 745
			} else {
766 746
				FileCopy.copyFiles(redistDirectory, txmhomedir);
767 747
			}
......
771 751
			//			BundleUtils.copyFiles("org.txm.core", "res", "org/txm/xml", "schema", txmhomedir);
772 752
			//			BundleUtils.copyFiles("org.txm.core", "res", "org/txm", "css", txmhomedir);
773 753

  
774
			Workspace workspace = Workspace.getInstance();
754
			workspace = Workspace.getInstance();
775 755

  
776 756
			return workspace;
777 757
		} catch (Exception e) {
tmp/org.txm.core/src/java/org/txm/objects/Project.java (revision 1885)
40 40

  
41 41
import org.eclipse.core.resources.IFolder;
42 42
import org.eclipse.core.resources.IProject;
43
import org.eclipse.core.resources.IProjectDescription;
43 44
import org.eclipse.core.resources.IResource;
44 45
import org.eclipse.core.resources.IWorkspace;
45 46
import org.eclipse.core.resources.ProjectScope;
......
76 77
 */
77 78
public class Project extends TXMResult {
78 79

  
80
	public static final String TXMCORPUSNATURE = "org.txm.core.CorpusNature";
81

  
79 82
	//private ArrayList<String> pEditionNames = new ArrayList<String>();
80 83
	private IProject rcpProject;
81 84

  
......
351 354
	}
352 355

  
353 356
	private void createRCPProject() throws CoreException {
354
		rcpProject.create(monitor);
357
		
358
		IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(rcpProject.getName());
359
		IFolder folder = Workspace.getInstance().corporaProject.getFolder(rcpProject.getName());
360
		
361
		description.setLocation(folder.getLocation());
362
		description.setNatureIds(new String[] {TXMCORPUSNATURE});
363
		
364
		rcpProject.create(description, monitor);
355 365
		rcpProject.open(monitor);
356
		rcpProject.getDescription().setNatureIds(new String[] {"org.txm.core.CorpusNature"});
357

  
366
		
358 367
		IFolder srcFolder = rcpProject.getFolder("src");
359 368
		if (pSrcDirectory != null && !pSrcDirectory.getName().isEmpty()) {
360 369
			IPath path = new Path(pSrcDirectory.getAbsolutePath());
......
818 827
	 */
819 828
	public File getProjectDirectory() {
820 829
		if (this.rcpProject == null || this.rcpProject.getLocation() == null) {
821
			return new File(Toolbox.workspace.getLocation(), this.userName);
830
			return new File(Toolbox.workspace.getLocation(), "corpora/"+this.userName);
822 831
		}
823 832
		return this.rcpProject.getLocation().toFile();
824 833
	}
......
1264 1273
					continue;
1265 1274
				}
1266 1275

  
1267
				Log.fine("Toolbox.initialize(): creating project " + rcpProject.getName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
1276
				Log.fine("Toolbox.initialize(): creating TXM corpus project " + rcpProject.getName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
1268 1277
				Class<?> cl = bundle.loadClass(className);
1269 1278
				Constructor<?> cons = cl.getConstructor(String.class);
1270 1279
				TXMResult result = (TXMResult) cons.newInstance(parametersNodePath);
tmp/org.txm.core/src/java/org/txm/objects/Workspace.java (revision 1885)
33 33
import java.io.OutputStreamWriter;
34 34
import java.lang.reflect.Constructor;
35 35
import java.util.ArrayList;
36
import java.util.Arrays;
36 37
import java.util.List;
37 38

  
38 39
import org.eclipse.core.resources.IFile;
40
import org.eclipse.core.resources.IFolder;
39 41
import org.eclipse.core.resources.IProject;
40 42
import org.eclipse.core.resources.IWorkspace;
43
import org.eclipse.core.resources.IWorkspaceRoot;
41 44
import org.eclipse.core.resources.ResourcesPlugin;
42 45
import org.eclipse.core.runtime.CoreException;
43 46
import org.eclipse.core.runtime.IConfigurationElement;
44 47
import org.eclipse.core.runtime.IPath;
48
import org.eclipse.core.runtime.Path;
45 49
import org.eclipse.core.runtime.Platform;
46 50
import org.eclipse.osgi.util.NLS;
47 51
import org.osgi.framework.Bundle;
......
69 73

  
70 74
	private static final String NAME = "name";
71 75
	
76
	IWorkspace rcpWorkspace;
77
	IWorkspaceRoot root;
78
	IProject corporaProject;
72 79
//	/** The xmlfile. */
73 80
//	File xmlDefinitionFile;
74 81
//
......
126 133
	private Workspace() {
127 134
		super("ROOT");
128 135
		
129
		IWorkspace rcpWorkspace = ResourcesPlugin.getWorkspace();
136
		rcpWorkspace = ResourcesPlugin.getWorkspace();
137
		root = rcpWorkspace.getRoot();
138
		corporaProject = root.getProject("corpora");
139
		
140
		if (!corporaProject.exists()) {
141
			try {
142
				corporaProject.create(null);
143
			} catch (CoreException e) {
144
				// TODO Auto-generated catch block
145
				e.printStackTrace();
146
			}
147
		}
148
		
130 149
		this.internalPersistable = true;
131
		this.userName = rcpWorkspace.getRoot().getName(); // corpora
150
		this.userName = corporaProject.getName(); // corpora
132 151
		//		this.setPath("/"+pName); 
133 152
//		this.xmlDefinitionFile = xmlfile;
134 153
	}
......
213 232
		File PARAMS = new File(binCorpusDir, ".settings"); //$NON-NLS-1$
214 233
		File PROJECT = new File(binCorpusDir, ".project"); //$NON-NLS-1$
215 234
		binCorpusDir = new File(this.getLocation(), binCorpusDir.getName()); // this is to ensure the project is in the workspace files
216
		
217
		
218
		
235

  
219 236
		if (binCorpusDir.exists() && HTMLs.exists() && DATAs.exists()
220 237
				&& REGISTRY.exists() && PARAMS.exists() && PROJECT.exists())// && correspfile.exists())
221 238
		{// minimal base data
......
383 400
		Log.fine("Toolbox.initialize(): reloading projects...");
384 401
		
385 402
		IWorkspace rcpWorkspace = ResourcesPlugin.getWorkspace();
403
		IProject corporaDirectory = rcpWorkspace.getRoot().getProject("corpora");
404
		
405
		if (!corporaDirectory.exists()) {
406
			Log.severe("Can't load corpora projects: 'corpora' not found in workspace.");
407
			return;
408
		}
386 409
		IProject projects[] = rcpWorkspace.getRoot().getProjects();
387 410
		
388 411
		Log.fine("Toolbox.initialize(): " + projects.length + " project(s) found in workspace.");
389 412
		LogMonitor monitor = new LogMonitor("Workspace projects initialization.");
413
		
390 414
		for (IProject project : projects) {
415
			
391 416
			try {
392 417
				project.open(monitor);
418
				String[] natures = project.getDescription().getNatureIds();
419
				if (Arrays.binarySearch(natures, Project.TXMCORPUSNATURE) < 0) continue;
420
				
393 421
				Project.loadProjectFromProjectScope(project);
394 422
			} catch (CoreException e) {
395 423
				// TODO Auto-generated catch block

Formats disponibles : Unified diff