Revision 2589

tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorpusViewContentProvider.java (revision 2589)
53 53

  
54 54
/**
55 55
 * Content provider of the Corpus view.
56
 *  
56
 * 
57 57
 * @author mdecorde
58 58
 */
59 59
public class CorpusViewContentProvider implements ITreeContentProvider {
60

  
60
	
61 61
	private CorporaView view;
62

  
62
	
63 63
	public CorpusViewContentProvider(CorporaView view) {
64 64
		this.view = view;
65 65
	}
66

  
66
	
67 67
	/**
68 68
	 * Gets the adapter.
69 69
	 *
......
72 72
	 */
73 73
	protected IWorkbenchAdapter getAdapter(Object element) {
74 74
		IWorkbenchAdapter adapter = null;
75

  
75
		
76 76
		if (element instanceof IAdaptable) {
77
			adapter = (IWorkbenchAdapter) ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class);
77
			adapter = ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class);
78 78
		}
79 79
		if (element != null && adapter == null) {
80 80
			adapter = (IWorkbenchAdapter) Platform.getAdapterManager().loadAdapter(element, IWorkbenchAdapter.class.getName());
81 81
		}
82 82
		return adapter;
83 83
	}
84

  
85
	/* (non-Javadoc)
84
	
85
	/*
86
	 * (non-Javadoc)
86 87
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
87 88
	 */
88 89
	@Override
......
91 92
		if (adapter != null) {
92 93
			Object[] children = adapter.getChildren(element);
93 94
			// FIXME: sort here the TXM result according to current sorting preference order, eg. getWeight(), getDate(), getName(), getClass()
94
			//			Arrays.sort(children, new Comparator<Object>() {
95
			//				@Override
96
			//				public int compare(Object o1, Object o2) {
97
			//					if (o1 == null) return -1;
98
			//					if (o2 == null) return 1;
99
			//					return o1.toString().compareTo(o2.toString());
100
			//				}
101
			//			});
95
			// Arrays.sort(children, new Comparator<Object>() {
96
			// @Override
97
			// public int compare(Object o1, Object o2) {
98
			// if (o1 == null) return -1;
99
			// if (o2 == null) return 1;
100
			// return o1.toString().compareTo(o2.toString());
101
			// }
102
			// });
102 103
			return children;
103 104
		}
104 105
		else if (element instanceof TXMResult) {
105 106
			if (element instanceof Project) {
106
				Project p = (Project)element;
107
				Project p = (Project) element;
107 108
				if (p.getRCPProject().isOpen()) {
108 109
					return p.getChildren().toArray();
109 110
				}
110
			} else {
111
				return ((TXMResult)element).getChildren().toArray();
112 111
			}
112
			else {
113
				return ((TXMResult) element).getChildren().toArray();
114
			}
113 115
		}
114 116
		return new Object[0];
115 117
	}
116

  
117
	/* (non-Javadoc)
118
	
119
	/*
120
	 * (non-Javadoc)
118 121
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
119 122
	 */
120 123
	@Override
121 124
	public Object[] getElements(Object element) {
122
		//		return element;
123
		//		
124
		//		if (element instanceof Workspace) {
125
		//			ArrayList<MainCorpus> elements = new ArrayList<MainCorpus>();
126
		//			Workspace p = (Workspace) element;
125
		// return element;
127 126
		//
128
		//			for (Project b : p.getProjects()) {
129
		//				for (TXMResult o : b.getChildren(MainCorpus.class)) {
130
		//					elements.add((MainCorpus)o);
131
		//				}
132
		//			}
133
		//			//System.out.println("get elements: "+elements);
134
		//			Collections.sort(elements, new Comparator<MainCorpus>() {
127
		// if (element instanceof Workspace) {
128
		// ArrayList<MainCorpus> elements = new ArrayList<MainCorpus>();
129
		// Workspace p = (Workspace) element;
135 130
		//
136
		//				@Override
137
		//				public int compare(MainCorpus o1, MainCorpus o2) {
138
		//					if (o1 == null) return -1;
139
		//					if (o2 == null) return 1;
140
		//					return o1.getName().compareTo(o2.getName());
141
		//				}
142
		//			});
143
		//			//System.out.println("corpora view content: "+elements);
144
		//			return elements.toArray();
145
		//		} else 
131
		// for (Project b : p.getProjects()) {
132
		// for (TXMResult o : b.getChildren(MainCorpus.class)) {
133
		// elements.add((MainCorpus)o);
134
		// }
135
		// }
136
		// //System.out.println("get elements: "+elements);
137
		// Collections.sort(elements, new Comparator<MainCorpus>() {
138
		//
139
		// @Override
140
		// public int compare(MainCorpus o1, MainCorpus o2) {
141
		// if (o1 == null) return -1;
142
		// if (o2 == null) return 1;
143
		// return o1.getName().compareTo(o2.getName());
144
		// }
145
		// });
146
		// //System.out.println("corpora view content: "+elements);
147
		// return elements.toArray();
148
		// } else
146 149
		if (element instanceof Workspace && !TBXPreferences.getInstance().getBoolean(TBXPreferences.SHOW_ALL_RESULT_NODES)) {
147
			Workspace w = (Workspace)element;
148
			ArrayList<Object> elements = new ArrayList<Object>();
150
			Workspace w = (Workspace) element;
151
			ArrayList<Object> elements = new ArrayList<>();
149 152
			for (Project p : w.getProjects()) {
150 153
				if (p.getRCPProject().isOpen()) {
151 154
					elements.addAll(p.getCorpora());
152 155
				}
153 156
			}
154

  
157
			
158
			// add projects of corpora projects & not the corpora project & not open
155 159
			IWorkspace rcpWorkspace = ResourcesPlugin.getWorkspace();
156 160
			IProject corporaDirectory = rcpWorkspace.getRoot().getProject("corpora");
157 161
			String path = corporaDirectory.getLocation().toOSString();
......
159 163
			projects = rcpWorkspace.getRoot().getProjects();
160 164
			for (IProject project : projects) {
161 165
				String path2 = project.getLocation().toOSString();
162
				if (!project.isOpen() && path2.startsWith(path)) {
166
				if (!project.isOpen() && path2.startsWith(path) && !path2.equals(path)) {
163 167
					elements.add(project);
164 168
				}
165 169
			}
166

  
167

  
170
			
168 171
			return elements.toArray();
169 172
		}
170 173
		else if (element instanceof TXMResult) {
171
			return ((TXMResult)element).getChildren().toArray();
174
			return ((TXMResult) element).getChildren().toArray();
172 175
		}
173 176
		else if (element instanceof List) {
174
			List list = (List)element;
177
			List list = (List) element;
175 178
			return list.toArray();
176 179
		}
177 180
		return new Object[0];
178 181
	}
179

  
180
	/* (non-Javadoc)
182
	
183
	/*
184
	 * (non-Javadoc)
181 185
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
182 186
	 */
183 187
	@Override
184 188
	public Object getParent(Object element) {
185
		//		IWorkbenchAdapter adapter = getAdapter(element);
186
		//		if (adapter != null) {
187
		//			return adapter.getParent(element);
188
		//		}
189
		//		else
189
		// IWorkbenchAdapter adapter = getAdapter(element);
190
		// if (adapter != null) {
191
		// return adapter.getParent(element);
192
		// }
193
		// else
190 194
		if (element instanceof TXMResult) {
191
			return ((TXMResult)element).getParent();
195
			return ((TXMResult) element).getParent();
192 196
		}
193 197
		return null;
194 198
	}
195

  
196
	/* (non-Javadoc)
199
	
200
	/*
201
	 * (non-Javadoc)
197 202
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
198 203
	 */
199 204
	@Override
200 205
	public boolean hasChildren(Object element) {
201 206
		if (element instanceof TXMResult) {
202 207
			return getChildren(element).length > 0;
203
		} else {
208
		}
209
		else {
204 210
			int n = getChildren(element).length;
205 211
			return n > 0;
206 212
		}
207 213
	}
208

  
209
	/* (non-Javadoc)
214
	
215
	/*
216
	 * (non-Javadoc)
210 217
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
211 218
	 */
212 219
	@Override
213
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
214
	}
215

  
216
	/* (non-Javadoc)
220
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
221
	
222
	/*
223
	 * (non-Javadoc)
217 224
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
218 225
	 */
219 226
	@Override
220
	public void dispose() {
221
	}
227
	public void dispose() {}
222 228
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/preferences/UserPreferencePage.java (revision 2589)
51 51
	protected void createFieldEditors() {
52 52
		this.addField(new BooleanFieldEditor(RCPPreferences.USER_ALERT_DELETE, TXMUIMessages.doNotConfirmToDeleteAnObject, BooleanFieldEditor.SEPARATE_LABEL, this.getFieldEditorParent()));
53 53
		
54
		this.addField(new BooleanFieldEditor(RCPPreferences.SHOW_NOTIFICATIONS, "Show a notification window when TXM ends a long task", BooleanFieldEditor.SEPARATE_LABEL, this.getFieldEditorParent()));
54
		// this.addField(new BooleanFieldEditor(RCPPreferences.SHOW_NOTIFICATIONS, "Show a notification window when TXM ends a long task", BooleanFieldEditor.SEPARATE_LABEL,
55
		// this.getFieldEditorParent()));
55 56
		
56 57
		// Auto compute the result when a parameter changes
57 58
		this.addField(new BooleanFieldEditor(RCPPreferences.AUTO_UPDATE_EDITOR, TXMUIMessages.automaticRecomputingWhenChangingAParameter, BooleanFieldEditor.SEPARATE_LABEL, this
tmp/org.txm.rcp/src/main/java/org/txm/rcp/Application.java (revision 2589)
36 36
import java.util.Map;
37 37
import java.util.logging.Level;
38 38

  
39
import org.eclipse.core.commands.ExecutionException;
40 39
import org.eclipse.core.net.proxy.IProxyService;
41 40
import org.eclipse.core.runtime.Platform;
42 41
import org.eclipse.core.runtime.preferences.ConfigurationScope;
......
47 46
import org.eclipse.osgi.util.TextProcessor;
48 47
import org.eclipse.swt.SWT;
49 48
import org.eclipse.swt.widgets.Display;
50
import org.eclipse.swt.widgets.Event;
51
import org.eclipse.swt.widgets.Listener;
52 49
import org.eclipse.swt.widgets.MessageBox;
53 50
import org.eclipse.swt.widgets.Shell;
54 51
import org.eclipse.ui.PlatformUI;
......
61 58
import org.txm.Toolbox;
62 59
import org.txm.core.messages.TXMCoreMessages;
63 60
import org.txm.core.preferences.TBXPreferences;
64
import org.txm.rcp.commands.workspace.LoadBinaryCorpus;
65 61
import org.txm.rcp.messages.TXMUIMessages;
66 62
import org.txm.rcp.preferences.RCPPreferences;
67 63
import org.txm.rcp.swt.dialog.CGUMessageDialog;
......
72 68
 * This class controls all aspects of the application's execution.
73 69
 */
74 70
public class Application implements IApplication {
75

  
71
	
76 72
	/** The Constant PLUGIN_ID. */
77 73
	public static final String PLUGIN_ID = "org.txm.rcp"; //$NON-NLS-1$
78

  
74
	
79 75
	/** The Constant FIRST_LAUNCH. */
80 76
	public static final String FIRST_LAUNCH = "first_launch"; //$NON-NLS-1$
81

  
77
	
82 78
	private static ApplicationWorkbenchAdvisor awa;
83

  
84
	//public static OpenDocumentEventProcessor openDocProcessor = new OpenDocumentEventProcessor();	
79
	
80
	// public static OpenDocumentEventProcessor openDocProcessor = new OpenDocumentEventProcessor();
85 81
	/*
86 82
	 * (non-Javadoc)
87
	 * 
88 83
	 * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
89 84
	 */
90 85
	@Override
91 86
	public Object start(IApplicationContext context) throws Exception {
92

  
87
		
93 88
		Display display = PlatformUI.createDisplay();
94

  
95 89
		
96
		
97
		//		if (Platform.inDevelopmentMode() || Platform.inDebugMode()) {
98
		//			// this can not work in development environment
99
		//			// as it need to have a default workspace set to none
100
		//			// see product configuration :
101
		//			// osgi.instance.area=@noDefault
102
		//			// ignored in development
103
		//			// -------------------------------------
90
		// if (Platform.inDevelopmentMode() || Platform.inDebugMode()) {
91
		// // this can not work in development environment
92
		// // as it need to have a default workspace set to none
93
		// // see product configuration :
94
		// // osgi.instance.area=@noDefault
95
		// // ignored in development
96
		// // -------------------------------------
104 97
		//
105
		//		} else {
98
		// } else {
106 99
		// in Release mode only : platform workspace selection on startup
107 100
		// then restart if needed (on workspace error...)
108

  
109
		System.out.println("instance location="+Platform.getInstanceLocation().getURL());
101
		
102
		System.out.println("instance location=" + Platform.getInstanceLocation().getURL());
110 103
		if (Platform.getInstanceLocation().getURL() == null) {
111

  
104
			
112 105
			Integer ret = openCGU();
113 106
			if (ret == IApplication.EXIT_RESTART) {
114 107
				System.out.println("** Working directory set by user.");
115 108
				return IApplication.EXIT_RESTART;
116
			} else if (ret == IApplication.EXIT_OK) {
109
			}
110
			else if (ret == IApplication.EXIT_OK) {
117 111
				System.out.println("** Fail to open CGU or set working directory.");
118 112
				return IApplication.EXIT_OK; // an error occurred or user canceled
119
			} else {
113
			}
114
			else {
120 115
				// OK
121 116
			}
122 117
		}
123

  
118
		
124 119
		// Die if platform WS not set (user cancel)
125 120
		// ---------------------------
126

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

  
132

  
126
		
127
		
133 128
		// load JVM fonts in SWT env
134 129
		if (System.getProperty("os.name").contains("Linux")) { // $NON-NLS-1$ $NON-NLS-2$
135 130
			File javaFontsPath = new File(System.getProperty("java.home")
136 131
					+ System.getProperty("file.separator") + "lib"
137 132
					+ System.getProperty("file.separator") + "fonts"
138 133
					+ System.getProperty("file.separator"));
139

  
134
			
140 135
			String[] fontFiles = javaFontsPath.list();
141 136
			if (fontFiles != null) {
142 137
				for (int i = 0; i < fontFiles.length; i++) {
143
					if(fontFiles[i].endsWith(".ttf"))    { //$NON-NLS-1$
138
					if (fontFiles[i].endsWith(".ttf")) { //$NON-NLS-1$
144 139
						File fontFile = new File(javaFontsPath, fontFiles[i]);
145 140
						Log.finest("Loading Java font to SWT Device from file " + fontFile + "...");
146 141
						// Load the font in SWT
......
149 144
				}
150 145
			}
151 146
		}
152

  
147
		
153 148
		Map args = context.getArguments();
154

  
155
		List<String> argsList = Arrays.asList((String[])(args.get("application.args"))); //$NON-NLS-1$
156

  
149
		
150
		List<String> argsList = Arrays.asList((String[]) (args.get("application.args"))); //$NON-NLS-1$
151
		
157 152
		System.out.println(TXMCoreMessages.bind(TXMUIMessages.argsColon, argsList));
158

  
153
		
159 154
		if (argsList.contains("-log")) { //$NON-NLS-1$
160 155
			System.out.println(TXMUIMessages.logOptionDetected);
161 156
			Log.setPrintInConsole(true);
......
168 163
		if (argsList.contains("-run")) { //$NON-NLS-1$
169 164
			System.out.println("Running TXM");
170 165
			// FIXME: need to check that all has been well moved in Workspace class or build.properties
171
			//		} else if (argsList.contains("-standalone")) { //$NON-NLS-1$
172
			//			File userhomeDirectory = new File("workspace").getAbsoluteFile(); // eclipse default workspace directory
173
			//			File defaultWorkspaceFile = new File("workspace/corpora/default.xml");
174
			//			if (!defaultWorkspaceFile.exists()) {
175
			//				System.out.println("Stand alone launch, creating minimal TXM user home directory in "+userhomeDirectory.getAbsolutePath());
176
			//				System.out.println("Sample corpora, scripts, import scripts and macros files are not yet installed.");
177
			//				
178
			//				TBXPreferences.getInstance().put(TBXPreferences.USER_TXM_HOME, userhomeDirectory.getAbsolutePath());
179
			//				TBXPreferences.getInstance().put(TBXPreferences.INSTALL_DIR, userhomeDirectory.getParentFile().getAbsolutePath());
180
			//				
181
			//				File corpusworkspaceDirectory = new File(userhomeDirectory, "workspaces");
182
			//				corpusworkspaceDirectory.mkdirs();
166
			// } else if (argsList.contains("-standalone")) { //$NON-NLS-1$
167
			// File userhomeDirectory = new File("workspace").getAbsoluteFile(); // eclipse default workspace directory
168
			// File defaultWorkspaceFile = new File("workspace/corpora/default.xml");
169
			// if (!defaultWorkspaceFile.exists()) {
170
			// System.out.println("Stand alone launch, creating minimal TXM user home directory in "+userhomeDirectory.getAbsolutePath());
171
			// System.out.println("Sample corpora, scripts, import scripts and macros files are not yet installed.");
183 172
			//
184
			//				String createfolders[] = {
185
			//						"corpora", "clipboard", //$NON-NLS-1$ //$NON-NLS-2$
186
			//						"workspaces", "css", "scripts", "scripts/lib", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
187
			//						"scripts/macro", "scripts/user", "xsl", "samples", "schema", "R"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
173
			// TBXPreferences.getInstance().put(TBXPreferences.USER_TXM_HOME, userhomeDirectory.getAbsolutePath());
174
			// TBXPreferences.getInstance().put(TBXPreferences.INSTALL_DIR, userhomeDirectory.getParentFile().getAbsolutePath());
188 175
			//
189
			//				for (String folder : createfolders) {
190
			//					new File(userhomeDirectory, folder).mkdir();
191
			//				}
176
			// File corpusworkspaceDirectory = new File(userhomeDirectory, "workspaces");
177
			// corpusworkspaceDirectory.mkdirs();
192 178
			//
193
			//				Workspace.createEmptyWorkspaceDefinition(new File(corpusworkspaceDirectory, "default.xml")); //$NON-NLS-1$
194
			//				BundleUtils.copyFiles("org.txm.core",  "res", "org/txm", "css", new File(userhomeDirectory, "css"));
195
			//				BundleUtils.copyFiles("org.txm.core",  "res", "org/txm/xml", "xsl", new File(userhomeDirectory, "xsl"));
196
			//				BundleUtils.copyFiles("org.txm.core",  "res", "org/txm/xml", "schema", new File(userhomeDirectory, "schema"));
197
			//				File scriptsDirectory = new File(userhomeDirectory, "scripts");
198
			//				new File(scriptsDirectory, "user").mkdir();
199
			//				new File(scriptsDirectory, "import").mkdir();
200
			//				new File(scriptsDirectory, "lib").mkdir();
201
			//				new File(scriptsDirectory, "macro").mkdir();
202
			//				new File(scriptsDirectory, "samples").mkdir();
203
			//			}
204
		} else {
179
			// String createfolders[] = {
180
			// "corpora", "clipboard", //$NON-NLS-1$ //$NON-NLS-2$
181
			// "workspaces", "css", "scripts", "scripts/lib", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
182
			// "scripts/macro", "scripts/user", "xsl", "samples", "schema", "R"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
183
			//
184
			// for (String folder : createfolders) {
185
			// new File(userhomeDirectory, folder).mkdir();
186
			// }
187
			//
188
			// Workspace.createEmptyWorkspaceDefinition(new File(corpusworkspaceDirectory, "default.xml")); //$NON-NLS-1$
189
			// BundleUtils.copyFiles("org.txm.core", "res", "org/txm", "css", new File(userhomeDirectory, "css"));
190
			// BundleUtils.copyFiles("org.txm.core", "res", "org/txm/xml", "xsl", new File(userhomeDirectory, "xsl"));
191
			// BundleUtils.copyFiles("org.txm.core", "res", "org/txm/xml", "schema", new File(userhomeDirectory, "schema"));
192
			// File scriptsDirectory = new File(userhomeDirectory, "scripts");
193
			// new File(scriptsDirectory, "user").mkdir();
194
			// new File(scriptsDirectory, "import").mkdir();
195
			// new File(scriptsDirectory, "lib").mkdir();
196
			// new File(scriptsDirectory, "macro").mkdir();
197
			// new File(scriptsDirectory, "samples").mkdir();
198
			// }
199
		}
200
		else {
205 201
			System.err.println("TXM must be launch with the argument '-run' to start."); //$NON-NLS-1$
206 202
			System.err.println(TXMUIMessages.thisFileIsNotMeantToRunTXMPleaseConsultTXMUserManual);
207

  
203
			
208 204
			javax.swing.JOptionPane.showMessageDialog(null, TXMUIMessages.thisFileIsNotMeantToRunTXMPleaseConsultTXMUserManual);
209 205
			return IApplication.EXIT_OK;
210 206
		}
211 207
		// test if Java 1.6 is installed
212 208
		String version = System.getProperty("java.version"); //$NON-NLS-1$
213 209
		Log.warning("java.version : " + version); //$NON-NLS-1$
214

  
210
		
215 211
		boolean exit = false;// parseCommandLine();
216 212
		if (exit) {
217 213
			return IApplication.EXIT_OK;
218 214
		}
219

  
220

  
221
		//display.addListener(SWT.OpenDocument, openDocProcessor);
222

  
223
		//		//Lock the RCP workspace, thus there is only one TXM instance running
224
		//		Log.warning(TXMUIMessages.lockRCPWorkspace);
225
		//		if (!Platform.getInstanceLocation().lock()){
226
		//			//Shell shell = display.getActiveShell();
227
		//			System.out.println("TXM is already running. Exiting...");
228
		//			return IApplication.EXIT_OK;
229
		//		}
230

  
215
		
216
		
217
		// display.addListener(SWT.OpenDocument, openDocProcessor);
218
		
219
		// //Lock the RCP workspace, thus there is only one TXM instance running
220
		// Log.warning(TXMUIMessages.lockRCPWorkspace);
221
		// if (!Platform.getInstanceLocation().lock()){
222
		// //Shell shell = display.getActiveShell();
223
		// System.out.println("TXM is already running. Exiting...");
224
		// return IApplication.EXIT_OK;
225
		// }
226
		
231 227
		try {
232 228
			Log.warning(TXMUIMessages.activateProxyService);
233 229
			activateProxyService();
234
		} catch (Exception e) {
230
		}
231
		catch (Exception e) {
235 232
			Log.warning(TXMCoreMessages.bind(TXMUIMessages.couldNotStartProxyConfigurationColon, e));
236 233
		}
237

  
234
		
238 235
		try {
239 236
			// initialization code has been put in ApplicationWorkbenchAdvisor
240 237
			// as it should
241

  
242
			// add listener to catch --launcher.openFile 
243
			display.addListener(SWT.OpenDocument, new Listener() {
244

  
245
				@Override
246
				public void handleEvent(Event event) {
247
					if (event.text != null && event.text.endsWith(".txm")) {
248
						File f = new File(event.text);
249
						
250
						try {
251
							LoadBinaryCorpus.loadBinaryCorpusArchive(f);
252
						} catch (ExecutionException e) {
253
							// TODO Auto-generated catch block
254
							e.printStackTrace();
255
						}
256
					}
257
				}
258
			});
259 238
			
260
			//run the application mainloop
239
			// add listener to catch --launcher.openFile
240
			// display.addListener(SWT.OpenDocument, new Listener() {
241
			//
242
			// @Override
243
			// public void handleEvent(Event event) {
244
			// if (event.text != null && event.text.endsWith(".txm")) {
245
			// File f = new File(event.text);
246
			//
247
			// try {
248
			// LoadBinaryCorpus.loadBinaryCorpusArchive(f);
249
			// } catch (ExecutionException e) {
250
			// // TODO Auto-generated catch block
251
			// e.printStackTrace();
252
			// }
253
			// }
254
			// }
255
			// });
256
			
257
			// run the application mainloop
261 258
			awa = new ApplicationWorkbenchAdvisor();
262 259
			System.out.println("Running TXM workbench.");
263 260
			int returnCode = PlatformUI.createAndRunWorkbench(display, awa);
264

  
261
			
265 262
			if (returnCode == PlatformUI.RETURN_RESTART) {
266 263
				System.out.println("Restarting TXM.");
267 264
				return IApplication.EXIT_RESTART;
268 265
			}
269

  
266
			
270 267
			System.out.println("Exiting TXM.");
271 268
			return IApplication.EXIT_OK;
272
		} finally {
269
		}
270
		finally {
273 271
			// System.out.println(Messages.Application_2);
274 272
			display.dispose();
275 273
		}
276 274
	}
277

  
275
	
278 276
	private Integer openCGU() {
279 277
		try {
280

  
278
			
281 279
			Version v = BundleUtils.getBundleVersion("org.txm.rcp");//$NON-NLS-1$
282 280
			if (v == null) {
283 281
				System.out.println("Error: no 'org.txm.rcp' version found.");
284 282
				return IApplication.EXIT_OK;
285 283
			}
286
			String version = v.getMajor()+"."+v.getMinor()+"."+v.getMicro();
287
			if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) { //$NON-NLS-1$
284
			String version = v.getMajor() + "." + v.getMinor() + "." + v.getMicro();
285
			if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) {
288 286
				System.out.println("RUNNING TXM FROM ECLIPSE - DEV MODE ACTIVATED");
289 287
				version += "-dev";
290 288
			}
291
			System.out.println("Version="+version);
292

  
293
			File txmhomedir = new File(System.getProperty("user.home"), "TXM-"+version); //$NON-NLS-1$ //$NON-NLS-2$
294

  
295

  
296

  
297
			//System.out.println("CGU="+ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH).getBoolean(RCPPreferences.CGU, false));
289
			System.out.println("Version=" + version);
290
			
291
			File txmhomedir = new File(System.getProperty("user.home"), "TXM-" + version); //$NON-NLS-1$ //$NON-NLS-2$
292
			
293
			
294
			
295
			// System.out.println("CGU="+ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH).getBoolean(RCPPreferences.CGU, false));
298 296
			if (!ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH).getBoolean(RCPPreferences.CGU, false)) {
299 297
				ChooseWorkspaceData launchData = new ChooseWorkspaceData(txmhomedir.getAbsolutePath());
300 298
				System.out.println("Opening CGU dialog...");
301
				CGUMessageDialog dialog = new CGUMessageDialog(Display.getCurrent().getActiveShell(), launchData) {};
299
				CGUMessageDialog dialog = new CGUMessageDialog(Display.getCurrent().getActiveShell(), launchData) {
300
				};
302 301
				boolean ret = (dialog.open() == MessageDialog.OK) && dialog.hasCheckBeenPressed();
303 302
				if (ret) {
304
					//TBXPreferences.getInstance().put(RCPPreferences.CGU, true);
305

  
303
					// TBXPreferences.getInstance().put(RCPPreferences.CGU, true);
304
					
306 305
					// check choosen path
307 306
					String path = launchData.getSelection();
308 307
					if (path != null) { // reset the letadata file
......
315 314
					if (ret2 != -1) {
316 315
						return ret2;
317 316
					}
318

  
317
					
319 318
					// validate Current as default Workspace, save configuration & history
320

  
319
					
321 320
					launchData.writePersistedData();
322
					System.out.println("save workspace location: "+launchData.getSelection());
321
					System.out.println("save workspace location: " + launchData.getSelection());
323 322
					ChooseWorkspaceData.setShowDialogValue(false);
324

  
323
					
325 324
					Preferences node = ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH);
326 325
					node.putBoolean(RCPPreferences.CGU, true);
327 326
					node.flush();
328

  
327
					
329 328
					return -1;
330

  
331
				} else {
329
					
330
				}
331
				else {
332 332
					return IApplication.EXIT_OK;
333 333
				}
334
			} else {
334
			}
335
			else {
335 336
				ChooseWorkspaceData launchData = new ChooseWorkspaceData(txmhomedir.getAbsolutePath());
336 337
				String[] recent = launchData.getRecentWorkspaces();
337

  
338
				
338 339
				// If the selection dialog was not used then the workspace to use is either the
339 340
				// most recent selection or the initialDefault (if there is no history).
340 341
				String workspace = null;
......
345 346
					workspace = launchData.getInitialDefault();
346 347
				}
347 348
				launchData.workspaceSelected(TextProcessor.deprocess(workspace));
348

  
349
				
349 350
				return setInstanceLocation(launchData);
350 351
			}
351
		} catch(Exception e) {
352
			System.out.println("Error: can't open CGU dialog: "+e);
352
		}
353
		catch (Exception e) {
354
			System.out.println("Error: can't open CGU dialog: " + e);
353 355
			e.printStackTrace();
354 356
			return IApplication.EXIT_OK;
355 357
		}
356 358
	}
357

  
359
	
358 360
	private Integer setInstanceLocation(ChooseWorkspaceData launchData) {
359 361
		String selWS = launchData.getSelection();
360 362
		if (selWS == null) {
361 363
			System.out.println("** No workspace set in configuration scope.");
362 364
			return IApplication.EXIT_OK;// user cancelled (no restart)
363 365
		}
364

  
366
		
365 367
		// Switch workspace :
366 368
		URL url = null;
367 369
		try {
368 370
			url = new URL("file", "", selWS);
369
		} catch (MalformedURLException e1) {
371
		}
372
		catch (MalformedURLException e1) {
370 373
			showWorkspaceError("Workspace path could not be found.");
371 374
			return IApplication.EXIT_OK;
372 375
		}
373

  
376
		
374 377
		try {
375 378
			if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) {
376 379
				return -1; // can't call Platform.getInstanceLocation().set(...) in dev mode
377 380
			}
378

  
381
			
379 382
			if (!Platform.getInstanceLocation().set(url, true)) {
380 383
				showWorkspaceError("TXM is already running. Exiting...");
381 384
				ChooseWorkspaceData.setShowDialogValue(false);
382 385
				return IApplication.EXIT_OK;
383
			} else {
386
			}
387
			else {
384 388
				return -1; // OK !!
385 389
			}
386
		} catch (IllegalStateException e) {
387
			showWorkspaceError("Workspace is in an illegal state: "+e);
390
		}
391
		catch (IllegalStateException e) {
392
			showWorkspaceError("Workspace is in an illegal state: " + e);
388 393
			ChooseWorkspaceData.setShowDialogValue(true);
389 394
			return IApplication.EXIT_OK;
390
		} catch (IOException e) {
391
			showWorkspaceError("Workspace could not be found on disk: "+e);
395
		}
396
		catch (IOException e) {
397
			showWorkspaceError("Workspace could not be found on disk: " + e);
392 398
			ChooseWorkspaceData.setShowDialogValue(true);
393 399
			return IApplication.EXIT_OK;
394 400
		}
395

  
396

  
401
		
402
		
397 403
	}
398

  
399
	//	/**
400
	//	 * Open choose workspace dialog and validate the user's choice. Returns true
401
	//	 * if restart needed.
402
	//	 */
403
	//	private static Integer chooseWorkspaceUrl(Shell shell) {
404
	//		ChooseWorkspaceData launchData = new ChooseWorkspaceData("");
405
	////		if (!launchData.getShowDialog()) {
406
	////			launchData.toggleShowDialog();
407
	////		}
408
	//		ChooseWorkspaceDialog dialog =
409
	//				new ChooseWorkspaceDialog(shell, launchData, true, true);
404
	
405
	// /**
406
	// * Open choose workspace dialog and validate the user's choice. Returns true
407
	// * if restart needed.
408
	// */
409
	// private static Integer chooseWorkspaceUrl(Shell shell) {
410
	// ChooseWorkspaceData launchData = new ChooseWorkspaceData("");
411
	//// if (!launchData.getShowDialog()) {
412
	//// launchData.toggleShowDialog();
413
	//// }
414
	// ChooseWorkspaceDialog dialog =
415
	// new ChooseWorkspaceDialog(shell, launchData, true, true);
410 416
	//
411
	//		// don't force prompt : setShowDialogValue is set on error
412
	//		dialog.prompt(false);
417
	// // don't force prompt : setShowDialogValue is set on error
418
	// dialog.prompt(false);
413 419
	//
414
	//		// check choosen path
415
	//		String selWS = launchData.getSelection();
416
	//		if (selWS == null)
417
	//			return IApplication.EXIT_OK;// user cancelled (no restart)
420
	// // check choosen path
421
	// String selWS = launchData.getSelection();
422
	// if (selWS == null)
423
	// return IApplication.EXIT_OK;// user cancelled (no restart)
418 424
	//
419
	//		// Switch workspace :
420
	//		URL url = null;
421
	//		try {
422
	//			url = new URL("file", "", selWS);
423
	//		} catch (MalformedURLException e1) {
424
	//			showWorkspaceError("Workspace path could not be found.");
425
	//			return IApplication.EXIT_OK;
426
	//		}
425
	// // Switch workspace :
426
	// URL url = null;
427
	// try {
428
	// url = new URL("file", "", selWS);
429
	// } catch (MalformedURLException e1) {
430
	// showWorkspaceError("Workspace path could not be found.");
431
	// return IApplication.EXIT_OK;
432
	// }
427 433
	//
428
	//		try {
429
	//			if (!Platform.getInstanceLocation().set(url, true)) {
430
	//				showWorkspaceError("TXM is already running. Exiting...");
431
	//				ChooseWorkspaceData.setShowDialogValue(false);
432
	//				return IApplication.EXIT_OK;
433
	//			}
434
	// try {
435
	// if (!Platform.getInstanceLocation().set(url, true)) {
436
	// showWorkspaceError("TXM is already running. Exiting...");
437
	// ChooseWorkspaceData.setShowDialogValue(false);
438
	// return IApplication.EXIT_OK;
439
	// }
434 440
	//
435
	//		} catch (IllegalStateException e) {
436
	//			showWorkspaceError("Workspace is in an illegal state: "+e);
437
	//			ChooseWorkspaceData.setShowDialogValue(true);
438
	//			return IApplication.EXIT_OK;
439
	//		} catch (IOException e) {
440
	//			showWorkspaceError("Workspace could not be found on disk: "+e);
441
	//			ChooseWorkspaceData.setShowDialogValue(true);
442
	//			return IApplication.EXIT_OK;
443
	//		}
441
	// } catch (IllegalStateException e) {
442
	// showWorkspaceError("Workspace is in an illegal state: "+e);
443
	// ChooseWorkspaceData.setShowDialogValue(true);
444
	// return IApplication.EXIT_OK;
445
	// } catch (IOException e) {
446
	// showWorkspaceError("Workspace could not be found on disk: "+e);
447
	// ChooseWorkspaceData.setShowDialogValue(true);
448
	// return IApplication.EXIT_OK;
449
	// }
444 450
	//
445
	//		// validate Current as default Workspace, save configuration & history
446
	//		
447
	//		launchData.writePersistedData();
448
	//		ChooseWorkspaceData.setShowDialogValue(false);
449
	//		return -1;// user cancelled (no restart)
450
	//	}
451

  
451
	// // validate Current as default Workspace, save configuration & history
452
	//
453
	// launchData.writePersistedData();
454
	// ChooseWorkspaceData.setShowDialogValue(false);
455
	// return -1;// user cancelled (no restart)
456
	// }
457
	
452 458
	private static void showWorkspaceError(String message) {
453 459
		MessageBox messageBox = new MessageBox(new Shell(), SWT.DIALOG_TRIM | SWT.ERROR);
454 460
		messageBox.setText("TXM starting error");
455 461
		messageBox.setMessage(message);
456 462
		messageBox.open();
457 463
	}
458

  
464
	
459 465
	public ApplicationWorkbenchAdvisor getApplicationWorkbenchAdvisor() {
460 466
		return awa;
461 467
	}
462

  
468
	
463 469
	@Override
464 470
	public void stop() {
465 471
		// TODO Auto-generated method stub
466

  
472
		
467 473
	}
468

  
474
	
469 475
	/**
470 476
	 * Activates the proxy service and sets the network connection active provider as native.
471 477
	 */
472
	private void  activateProxyService() {
478
	private void activateProxyService() {
473 479
		String systemProxyHost = System.getProperty("http.proxyHost"); // must be called before IProxyService is used
474

  
480
		
475 481
		Bundle bundle = Platform.getBundle("org.eclipse.ui.ide"); //$NON-NLS-1$
476
		IProxyService  proxyService = null;
482
		IProxyService proxyService = null;
477 483
		if (bundle != null) {
478 484
			ServiceReference ref = bundle.getBundleContext().getServiceReference(IProxyService.class.getName());
479 485
			if (ref != null)
......
481 487
		}
482 488
		if (proxyService == null) {
483 489
			Log.warning("Proxy service could not be found."); //$NON-NLS-1$
484
		} else {
485
			//System.out.println("FIRST RUN TEST RESULT: "+ApplicationWorkbenchAdvisor.firstLaunchAfterInstallation());
490
		}
491
		else {
492
			// System.out.println("FIRST RUN TEST RESULT: "+ApplicationWorkbenchAdvisor.firstLaunchAfterInstallation());
486 493
			// force active provider as "Manual" on Mac OS X
487
			if (Util.isMac() && systemProxyHost != null && ApplicationWorkbenchAdvisor.testTXMHOMEPreferenceAndDirectory()) {  
494
			if (Util.isMac() && systemProxyHost != null && ApplicationWorkbenchAdvisor.testTXMHOMEPreferenceAndDirectory()) {
488 495
				System.out.println("System proxy detected. Force network provider to manual with proxy_host=" + systemProxyHost);
489
				proxyService.setProxiesEnabled(true); 
496
				proxyService.setProxiesEnabled(true);
490 497
			}
491

  
492
//			if (Util.isMac()) { // configure only for Mac OS X
493
//				//				String proxy_conf = "";
494
//				//				ProxyConf conf = new ProxyConf(this);
495
//				//				if (conf.mustSetProxyConfiguration()) { // there is a system proxy configured
496
//				//					System.out.println(Messages.bind(Messages.Application_11, proxy_conf));
497
//				//					proxyService.setProxiesEnabled(true);
498
//				//					//proxyService.setSystemProxiesEnabled(false);
499
//				//					
500
//				//					// prepare a new proxy configuration
501
//				//					boolean requiresAuthentication = conf.proxy_user != null && conf.proxy_user.length() > 0;
502
//				//					IProxyData[] proxies = new IProxyData[1];
503
//				//					proxies[0] = new ProxyData(IProxyData.HTTP_PROXY_TYPE, conf.proxy_host, conf.proxy_port, requiresAuthentication, "");
504
//				//					proxies[0].setPassword(conf.proxy_password);
505
//				//					proxies[0].setUserid(conf.proxy_user);
506
//				//					
507
//				//					try {
508
//				//						proxyService.setProxyData(proxies); // apply the new proxy configuration
509
//				//						System.out.println("TXM proxy configuration set: "+Arrays.toString(proxies));
510
//				//					} catch (Exception e) {
511
//				//						System.out.println("Failed to set TXM proxy configuration: "+Arrays.toString(proxies));
512
//				//						Log.printStackTrace(e);
513
//				//					}
514
//				//				}
515
//			}
516
		}	
498
			
499
			// if (Util.isMac()) { // configure only for Mac OS X
500
			// // String proxy_conf = "";
501
			// // ProxyConf conf = new ProxyConf(this);
502
			// // if (conf.mustSetProxyConfiguration()) { // there is a system proxy configured
503
			// // System.out.println(Messages.bind(Messages.Application_11, proxy_conf));
504
			// // proxyService.setProxiesEnabled(true);
505
			// // //proxyService.setSystemProxiesEnabled(false);
506
			// //
507
			// // // prepare a new proxy configuration
508
			// // boolean requiresAuthentication = conf.proxy_user != null && conf.proxy_user.length() > 0;
509
			// // IProxyData[] proxies = new IProxyData[1];
510
			// // proxies[0] = new ProxyData(IProxyData.HTTP_PROXY_TYPE, conf.proxy_host, conf.proxy_port, requiresAuthentication, "");
511
			// // proxies[0].setPassword(conf.proxy_password);
512
			// // proxies[0].setUserid(conf.proxy_user);
513
			// //
514
			// // try {
515
			// // proxyService.setProxyData(proxies); // apply the new proxy configuration
516
			// // System.out.println("TXM proxy configuration set: "+Arrays.toString(proxies));
517
			// // } catch (Exception e) {
518
			// // System.out.println("Failed to set TXM proxy configuration: "+Arrays.toString(proxies));
519
			// // Log.printStackTrace(e);
520
			// // }
521
			// // }
522
			// }
523
		}
517 524
	}
518

  
519
	//	/**
520
	//	 * Parses the command line.
521
	//	 *
522
	//	 * @return true, if successful
523
	//	 * @deprecated, parse the command line the list optionsForPreferences must
524
	//	 * be edited too add options
525
	//	 */
526
	//	private boolean parseCommandLine() {
527
	//		boolean exit = false;
528
	//		String[] optionsForPreferences = {
529
	//				CQPLibPreferences.CQI_SERVER_PATH_TO_EXECUTABLE,
530
	//				CQPLibPreferences.CQI_SERVER_PATH_TO_INIT_FILE,
531
	//				//				TBXPreferences.CQI_SERVER_PATH_TO_REGISTRY,
532
	//				RPreferences.PATH_TO_EXECUTABLE,
533
	//				TBXPreferences.INSTALL_DIR };
534
	//		String setPrefAndExit = "setPrefAndExit"; //$NON-NLS-1$
525
	
526
	// /**
527
	// * Parses the command line.
528
	// *
529
	// * @return true, if successful
530
	// * @deprecated, parse the command line the list optionsForPreferences must
531
	// * be edited too add options
532
	// */
533
	// private boolean parseCommandLine() {
534
	// boolean exit = false;
535
	// String[] optionsForPreferences = {
536
	// CQPLibPreferences.CQI_SERVER_PATH_TO_EXECUTABLE,
537
	// CQPLibPreferences.CQI_SERVER_PATH_TO_INIT_FILE,
538
	// // TBXPreferences.CQI_SERVER_PATH_TO_REGISTRY,
539
	// RPreferences.PATH_TO_EXECUTABLE,
540
	// TBXPreferences.INSTALL_DIR };
541
	// String setPrefAndExit = "setPrefAndExit"; //$NON-NLS-1$
535 542
	//
536
	//		Options options = new Options();
537
	//		options.addOption(OptionBuilder.create("product")); //option passed here when run as an eclipse application. Recognized to prevent a UnrecognizedOptionException //$NON-NLS-1$
538
	//		options.addOption(OptionBuilder.create(setPrefAndExit));
539
	//		for (String preference : optionsForPreferences)
540
	//			options.addOption(OptionBuilder.withValueSeparator().hasArgs()
541
	//					.create(preference));
543
	// Options options = new Options();
544
	// options.addOption(OptionBuilder.create("product")); //option passed here when run as an eclipse application. Recognized to prevent a UnrecognizedOptionException //$NON-NLS-1$
545
	// options.addOption(OptionBuilder.create(setPrefAndExit));
546
	// for (String preference : optionsForPreferences)
547
	// options.addOption(OptionBuilder.withValueSeparator().hasArgs()
548
	// .create(preference));
542 549
	//
543
	//		Parser parser = new GnuParser();
544
	//		CommandLine cl;
545
	//		try {
546
	//			cl = parser.parse(options, Platform.getCommandLineArgs());
547
	//		} catch (ParseException e) {
550
	// Parser parser = new GnuParser();
551
	// CommandLine cl;
552
	// try {
553
	// cl = parser.parse(options, Platform.getCommandLineArgs());
554
	// } catch (ParseException e) {
548 555
	//
549
	//			System.err.println(NLS.bind(TXMUIMessages.FAILED_TO_PARSE_OPTIONS,
550
	//					StringUtils.join(Platform.getCommandLineArgs(), " "), e)); //$NON-NLS-1$
551
	//			org.txm.utils.logger.Log.printStackTrace(e);
552
	//			exit = true;
553
	//			return exit;
554
	//		}
556
	// System.err.println(NLS.bind(TXMUIMessages.FAILED_TO_PARSE_OPTIONS,
557
	// StringUtils.join(Platform.getCommandLineArgs(), " "), e)); //$NON-NLS-1$
558
	// org.txm.utils.logger.Log.printStackTrace(e);
559
	// exit = true;
560
	// return exit;
561
	// }
555 562
	//
556
	//		ScopedPreferenceStore preferences = new ScopedPreferenceStore(
557
	//				org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE, Application.PLUGIN_ID);
558
	//		for (String preference : optionsForPreferences)
559
	//			if (cl.hasOption(preference)) {
560
	//				preferences.setValue(preference, cl.getOptionValue(preference));
561
	//			}
563
	// ScopedPreferenceStore preferences = new ScopedPreferenceStore(
564
	// org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE, Application.PLUGIN_ID);
565
	// for (String preference : optionsForPreferences)
566
	// if (cl.hasOption(preference)) {
567
	// preferences.setValue(preference, cl.getOptionValue(preference));
568
	// }
562 569
	//
563
	//		try {
564
	//			preferences.save();
565
	//		} catch (IOException e) {
566
	//			System.err.println(NLS.bind(TXMUIMessages.failedToSavePreferencesColonP0, e));
567
	//			exit = true;
568
	//			return exit;
569
	//		}
570
	// try {
571
	// preferences.save();
572
	// } catch (IOException e) {
573
	// System.err.println(NLS.bind(TXMUIMessages.failedToSavePreferencesColonP0, e));
574
	// exit = true;
575
	// return exit;
576
	// }
570 577
	//
571
	//		if (cl.hasOption(setPrefAndExit))
572
	//			exit = true;
573
	//		return exit;
574
	//	}
575
}
578
	// if (cl.hasOption(setPrefAndExit))
579
	// exit = true;
580
	// return exit;
581
	// }
582
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteImportScript.java (revision 2589)
65 65
 * Execute an import module (Groovy script).
66 66
 * Binds parameters to the script :
67 67
 * project: the corpus project
68
 * monitor= the job	
68
 * monitor= the job
69 69
 * debug=true|false
70
 * readyToLoad=tested after the script. If true then the process went OK. 
70
 * readyToLoad=tested after the script. If true then the process went OK.
71 71
 *
72 72
 * @author mdecorde
73 73
 */
74 74
public class ExecuteImportScript extends AbstractHandler {
75

  
75
	
76 76
	/** The lastopenedbase. */
77 77
	public static File lastopenedbase;
78
	
78 79
	protected static GroovyScriptEngine gse;
79

  
80
	/* (non-Javadoc)
80
	
81
	/*
82
	 * (non-Javadoc)
81 83
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
82 84
	 */
83 85
	@Override
......
86 88
		if (event.getParameters().containsKey("org.txm.rcp.commands.commandParameter3")) {
87 89
			filename = event.getParameter("org.txm.rcp.commands.commandParameter3"); //$NON-NLS-1$
88 90
			filepath = "scripts/groovy/user/org/txm/scripts/importer/" + filename; //$NON-NLS-1$
89
		} else {
91
		}
92
		else {
90 93
			Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
91 94
			FileDialog dialog = new FileDialog(shell, SWT.SAVE);
92
			dialog.setFilterPath(Toolbox.getTxmHomePath()+"/scripts/groovy/user/org/txm/scripts/importer");
95
			dialog.setFilterPath(Toolbox.getTxmHomePath() + "/scripts/groovy/user/org/txm/scripts/importer");
93 96
			filepath = dialog.open();
94 97
		}
95

  
98
		
96 99
		if (filepath == null) return null;
97

  
100
		
98 101
		OpenImportForm.openfile(filepath);
99 102
		return null;
100 103
	}
101

  
102
	//	@Deprecated
103
	//	public static JobHandler executeScript(String scriptFilePath,
104
	//			File paramFile) {
105
	//		BaseOldParameters params = null;
106
	//		try {
107
	//			params = new BaseOldParameters(paramFile);
108
	//		} catch (Exception e1) {
109
	//			org.txm.utils.logger.Log.printStackTrace(e1);
110
	//			System.out.println("Error while reading import parameters from: "+paramFile);
111
	//			return null;
112
	//		}
113
	//		return executeScript(scriptFilePath, params);
114
	//	}
115

  
104
	
105
	// @Deprecated
106
	// public static JobHandler executeScript(String scriptFilePath,
107
	// File paramFile) {
108
	// BaseOldParameters params = null;
109
	// try {
110
	// params = new BaseOldParameters(paramFile);
111
	// } catch (Exception e1) {
112
	// org.txm.utils.logger.Log.printStackTrace(e1);
113
	// System.out.println("Error while reading import parameters from: "+paramFile);
114
	// return null;
115
	// }
116
	// return executeScript(scriptFilePath, params);
117
	// }
118
	
116 119
	/**
117 120
	 * 
118
	 * @param scriptFilePath 
121
	 * @param scriptFilePath
119 122
	 * @param params
120 123
	 * @return
121 124
	 */
122 125
	public static JobHandler executeScript(final Project project) {
123

  
126
		
124 127
		if (project.getImportModuleName() == null) {
125 128
			return null;
126 129
		}
127

  
130
		
128 131
		Display.getDefault().syncExec(new Runnable() {
129
			public void run() {	StatusLine.setMessage(TXMUIMessages.importStarted); }
132
			
133
			@Override
134
			public void run() {
135
				StatusLine.setMessage(TXMUIMessages.importStarted);
136
			}
130 137
		});
131

  
138
		
132 139
		final String txmhome = Toolbox.getTxmHomePath();
133
		final File corporadir = new File(txmhome,"corpora"); //$NON-NLS-1$
140
		final File corporadir = new File(txmhome, "corpora"); //$NON-NLS-1$
134 141
		corporadir.mkdir(); // the binary corpus are stored here
135 142
		if (!corporadir.exists()) {
136
			System.out.println(TXMUIMessages.errorColonCorporaDirectoryDoesntExistColon+corporadir);
137
			Log.severe(TXMUIMessages.errorColonCorporaDirectoryDoesntExistColon+corporadir);
143
			System.out.println(TXMUIMessages.errorColonCorporaDirectoryDoesntExistColon + corporadir);
144
			Log.severe(TXMUIMessages.errorColonCorporaDirectoryDoesntExistColon + corporadir);
138 145
			return null;
139 146
		}
140

  
141
		//		if (CQPSearchEngine.isInitialized()) {
142
		//			Toolbox.getEngineManager(EngineType.SEARCH).stopEngines();
143
		//		}
147
		
148
		// if (CQPSearchEngine.isInitialized()) {
149
		// Toolbox.getEngineManager(EngineType.SEARCH).stopEngines();
150
		// }
144 151
		final long time = System.currentTimeMillis();
145 152
		JobHandler jobhandler = new JobHandler(TXMUIMessages.scriptExecution + " " + project.getImportModuleName()) { //$NON-NLS-1$
153
			
146 154
			@Override
147 155
			protected IStatus run(IProgressMonitor monitor) {
148 156
				this.runInit(monitor);
......
150 158
					boolean doUpdate = project.getDoUpdate();
151 159
					
152 160
					if (project.compute(monitor)) {
153

  
161
						
154 162
						this.releaseSemaphore();
155

  
156

  
157

  
163
						
164
						
165
						
158 166
						monitor.done();
159 167
						if (doUpdate) {
160 168
							Log.info(TXMUIMessages.updateDone);
161
						} else {
169
						}
170
						else {
162 171
							Log.info(TXMUIMessages.importDone);
163 172
						}
164 173
						return Status.OK_STATUS;
165 174
					}
166
				} catch (Exception e) {
175
				}
176
				catch (Exception e) {
167 177
					// TODO Auto-generated catch block
168 178
					e.printStackTrace();
169
				} finally {
179
				}
180
				finally {
170 181
					System.gc();
171
					//					if (!CQPSearchEngine.isInitialized()) {
172
					//						try {
173
					//							SearchEnginesManager.getCQPSearchEngine().start(monitor);
174
					//						} catch (Exception e) {
175
					//							// TODO Auto-generated catch block
176
					//							e.printStackTrace();
177
					//						}
178
					//					}
182
					// if (!CQPSearchEngine.isInitialized()) {
183
					// try {
184
					// SearchEnginesManager.getCQPSearchEngine().start(monitor);
185
					// } catch (Exception e) {
186
					// // TODO Auto-generated catch block
187
					// e.printStackTrace();
188
					// }
189
					// }
179 190
					syncExec(new Runnable() {
191
						
180 192
						@Override
181 193
						public void run() {
182
							if (RCPPreferences.getInstance().getBoolean(RCPPreferences.SHOW_NOTIFICATIONS) 
183
									&& (System.currentTimeMillis() - time) > 60000) {
184
								String message = NLS.bind("The {0} corpus was succesfully imported", project.getName());
185
								if (project.isDirty()) {
186
									message = NLS.bind("The {0} corpus was not imported correctly. Please check console messages.", project.getName());
187
								}
188
								new SimpleNotification(Display.getCurrent(), "Import done", message).open();
189
							}
194
							// if (RCPPreferences.getInstance().getBoolean(RCPPreferences.SHOW_NOTIFICATIONS)
195
							// && (System.currentTimeMillis() - time) > 0) { // 10 mins
196
							// String message = NLS.bind("The {0} corpus was succesfully imported", project.getName());
197
							// if (project.isDirty()) {
198
							// message = NLS.bind("The {0} corpus was not imported correctly. Please check console messages.", project.getName());
199
							// }
200
							// new SimpleNotification(Display.getCurrent(), "Import done", message).open();
201
							// }
190 202
							RestartTXM.reloadViews();
191 203
							CorporaView.select(project.getChildren(MainCorpus.class));
192 204
						}
193 205
					});
194 206
				}
195

  
207
				
196 208
				return Status.CANCEL_STATUS;
197 209
			}
198 210
		};
......
200 212
		jobhandler.startJob(true);
201 213
		return jobhandler;
202 214
	}
203

  
215
	
204 216
	/**
205 217
	 * Allow to retrieve an import script from the Toolbox plugin.
206 218
	 * 
......
210 222
	 * @return
211 223
	 */
212 224
	public static boolean getImportScriptFromToolboxPlugin(File script) {
213
		Log.fine("Retriving "+script+" from Toolbox plugin if script.date < toolbox_script.date...");
214

  
225
		Log.fine("Retriving " + script + " from Toolbox plugin if script.date < toolbox_script.date...");
226
		
215 227
		// retrieve the script relative path "quickLoader" -> "quick"
216 228
		String scriptPackage = script.getName();
217 229
		int idx = scriptPackage.indexOf("Loader");
218 230
		scriptPackage = "org/txm/scripts/importer/" + scriptPackage.substring(0, idx);
219

  
220
		return BundleUtils.replaceFilesIfNewer("org.txm.groovy.core", "src/groovy", scriptPackage, 
231
		
232
		return BundleUtils.replaceFilesIfNewer("org.txm.groovy.core", "src/groovy", scriptPackage,
221 233
				script.getName(), script);
222 234
	}
223
}
235
}
tmp/org.txm.rcp/META-INF/MANIFEST.MF (revision 2589)
147 147
 org.txm.groovy.core;visibility:=reexport,
148 148
 org.txm.treetagger.core;visibility:=reexport,
149 149
 org.eclipse.equinox.p2.discovery.compatibility;bundle-version="1.0.201";visibility:=reexport,
150
 org.eclipse.e4.ui.workbench.renderers.swt;visibility:=reexport
150
 org.eclipse.e4.ui.workbench.renderers.swt;visibility:=reexport,
151
 javax.annotation;bundle-version="1.2.0";visibility:=reexport
151 152
Bundle-ActivationPolicy: lazy
152 153
Bundle-ManifestVersion: 2
153 154
Bundle-Activator: org.txm.rcp.Activator
tmp/org.txm.rcp.feature/build.properties (revision 2589)
4 4
root.folder.redist/xsl=../org.txm.core/res/org/txm/xml/xsl/
5 5
root.folder.redist/schema=../org.txm.core/res/org/txm/xml/schema/
6 6
root.folder.redist/css=../org.txm.core/res/org/txm/css/
7
root.macosx.cocoa.x86_64=mac/
7

  
8 8
root=../org.txm.setups/shared/all
9

  
9 10
root.linux.gtk.x86_64.permissions.755=jre/bin/java,plugins/org.txm.libs.cqp.linux/res/linux32/,plugins/org.txm.libs.cqp.linux/res/linux64/,plugins/org.txm.statsengine.r.core.linux/res/linux64/bin/R,plugins/org.txm.statsengine.r.core.linux/res/linux64/bin/exec/R
10 11
root.linux.gtk.x86_64=linux/
12

  
11 13
root.macosx.cocoa.x86_64.permissions.755=jre/bin/java,plugins/org.txm.libs.cqp.macosx/res/macosx/,plugins/org.txm.statsengine.r.core.macosx/res/macosx/bin/R,plugins/org.txm.statsengine.r.core.macosx/res/macosx/bin/exec/R
14
root.macosx.cocoa.x86_64=mac/
tmp/org.txm.rcp.feature/feature.xml (revision 2589)
281 281
      <import plugin="org.txm.treetagger.core"/>
282 282
      <import plugin="org.eclipse.equinox.p2.discovery.compatibility" version="1.0.201" match="greaterOrEqual"/>
283 283
      <import plugin="org.eclipse.e4.ui.workbench.renderers.swt"/>
284
      <import plugin="org.txm.rcp" version="0.8.0" match="greaterOrEqual"/>
285 284
      <import feature="org.eclipse.babel.nls_eclipse_fr" version="4.7.0.v20190126095834"/>
285
      <import plugin="javax.annotation" version="1.2.0" match="greaterOrEqual"/>
286 286
   </requires>
287 287

  
288 288
   <plugin
tmp/org.txm.core/src/java/org/txm/xml/StaxDomConstructor.java (revision 2589)
1
package org.txm.xml;
2

  
3
import java.io.Reader;
4
import java.io.StringReader;
5

  
6
import javax.xml.parsers.ParserConfigurationException;
7
import javax.xml.stream.XMLInputFactory;
8
import javax.xml.stream.XMLStreamConstants;
9
import javax.xml.stream.XMLStreamException;
10
import javax.xml.stream.XMLStreamReader;
11

  
12
import org.txm.utils.xml.DomUtils;
13
import org.w3c.dom.CDATASection;
14
import org.w3c.dom.Comment;
15
import org.w3c.dom.Document;
16
import org.w3c.dom.Element;
17
import org.w3c.dom.EntityReference;
18
import org.w3c.dom.ProcessingInstruction;
19
import org.w3c.dom.Text;
20

  
21
public class StaxDomConstructor {
22
	
23
	XMLStreamReader parser = null;
24
	
25
	public StaxDomConstructor(XMLStreamReader parser) {
26
		this.parser = parser;
27
	}
28
	
29
	/**
30
	 * consumes the parser events to create a DOM. start consuming after the current Stax event
31
	 * 
32
	 * stop consuming when the current parser element is closed
33
	 * 
34
	 * @return
35
	 * @throws ParserConfigurationException
36
	 * @throws XMLStreamException
37
	 * @throws IllegalAccessException
38
	 */
39
	public Element getDom() throws ParserConfigurationException, XMLStreamException, IllegalAccessException {
40
		
41
		if (parser.getEventType() != XMLStreamConstants.START_ELEMENT) {
42
			throw new IllegalAccessException("The Dom constructor must be called from the XMLStreamConstants.START_ELEMENT event");
43
		}
44
		
45
		Document doc = DomUtils.emptyDocument();
46
		Element currentElement = null;
47
		
48
		int elements = 0;
49
		String localname = null;
50
		
51
		for (int event = parser.getEventType(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
52
			switch (event) {
53
				case XMLStreamConstants.START_ELEMENT:
54
					localname = parser.getLocalName();
55
					
56
					String ns = parser.getNamespaceURI();
57
					Element e = null;
58
					if (ns != null) {
59
						e = doc.createElementNS(ns, localname);
60
					}
61
					else {
62
						e = doc.createElement(localname);
63
					}
64
					
65
					for (int i = 0; i < parser.getAttributeCount(); i++) {
66
						ns = parser.getAttributeNamespace(i);
67
						if (ns != null) {
68
							e.setAttributeNS(ns, parser.getAttributeLocalName(i), parser.getAttributeValue(i));
69
						}
70
						else {
71
							e.setAttribute(parser.getAttributeLocalName(i), parser.getAttributeValue(i));
72
						}
73
					}
74
					
75
					if (currentElement == null) {
76
						doc.appendChild(e);
77
					}
78
					else {
79
						currentElement.appendChild(e);
80
					}
81
					currentElement = e;
82
					elements++;
83
					break;
84
				case XMLStreamConstants.CHARACTERS:
85
					Text textNode = doc.createTextNode(parser.getText());
86
					currentElement.appendChild(textNode);
87
					break;
88
				case XMLStreamConstants.END_ELEMENT:
89
					
90
					elements--;
91
					if (elements == 0) return doc.getDocumentElement();
92
					
93
					currentElement = (Element) currentElement.getParentNode();
94
					
95
					break;
96
				case XMLStreamConstants.PROCESSING_INSTRUCTION:
97
					ProcessingInstruction piNode = doc.createProcessingInstruction(parser.getPITarget(), parser.getPIData());
98
					currentElement.appendChild(piNode);
99
					break;
100
				case XMLStreamConstants.CDATA:
101
					CDATASection cDataNode = doc.createCDATASection(parser.getText());
102
					currentElement.appendChild(cDataNode);
103
					break;
104
				case XMLStreamConstants.COMMENT:
105
					Comment commentNode = doc.createComment(parser.getText());
106
					currentElement.appendChild(commentNode);
107
					break;
108
				case XMLStreamConstants.END_DOCUMENT:
109
					return doc.getDocumentElement();
110
				case XMLStreamConstants.ENTITY_REFERENCE:
111
					EntityReference entityNode = doc.createEntityReference(parser.getText());
112
					currentElement.appendChild(entityNode);
113
					break;
114
			}
115
		}
116
		return null;
117
	}
118
	
119
	public static void main(String[] args) throws Exception {
120
		Reader inputData = new StringReader("<test><ceci><est><un></un></est></ceci></test>");
121
		XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(inputData);
122
		parser.next();
123
		System.out.println("E=" + parser.getLocalName());
124
		parser.next();
125
		System.out.println("E=" + parser.getLocalName());
126
		System.out.println(new StaxDomConstructor(parser).getDom());
127
		parser.close();
128
		inputData.close();
129
	}
130
}
0 131

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff