Révision 1513

tmp/org.txm.index.core/src/org/txm/index/core/functions/Index.java (revision 1513)
156 156
	public Index(String parametersNodePath)	{
157 157
		super(parametersNodePath);
158 158
	}
159
	
160
	/**
161
	 * 
162
	 * @param parametersNodePath
163
	 */
164
	public Index(String parametersNodePath, TXMResult parent)	{
165
		super(parametersNodePath, parent);
166
	}
159 167

  
160 168

  
161 169
	@Override
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResult.java (revision 1513)
53 53
import org.txm.rcp.utils.JobHandler;
54 54
/**
55 55
 * Exports a result by calling the function toTxt(File f) then opens or not the result in the text editor according to the preferences.
56
 * @author mdecorde
56
 * @author mdecorde, sjacquot
57 57
 */
58 58
public class ExportResult extends AbstractHandler {
59 59

  
......
157 157
							System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, outfile.getAbsolutePath()));
158 158
						}
159 159
					} catch (ThreadDeath td) {
160
						if (s instanceof TXMResult)
161
							((TXMResult)s).clean();
162 160
						return Status.CANCEL_STATUS;
163 161
					} catch (Exception e) {
164 162
						System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultParameters.java (revision 1513)
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.handlers.export;
29

  
30
import java.io.File;
31
import java.io.IOException;
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.jface.viewers.IStructuredSelection;
40
import org.eclipse.osgi.util.NLS;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.widgets.FileDialog;
43
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.ui.handlers.HandlerUtil;
45
import org.txm.core.preferences.TBXPreferences;
46
import org.txm.core.preferences.TXMPreferences;
47
import org.txm.core.results.TXMResult;
48
import org.txm.rcp.JobsTimer;
49
import org.txm.rcp.StatusLine;
50
import org.txm.rcp.handlers.files.EditFile;
51
import org.txm.rcp.messages.TXMUIMessages;
52
import org.txm.rcp.swt.dialog.LastOpened;
53
import org.txm.rcp.utils.JobHandler;
54
// TODO: Auto-generated Javadoc
55
/**
56
 * export a result of a result by calling the function toTxt(File f) then show
57
 * the result in the text editor @ author mdecorde.
58
 */
59
public class ExportResultParameters extends AbstractHandler {
60

  
61
	private static final String ID = ExportResultParameters.class.getName();
62

  
63
	/**
64
	 * Export a TXM result parameters in the preferences format
65
	 *
66
	 * @param event the event
67
	 * @return the object
68
	 * @throws ExecutionException the execution exception
69
	 */
70
	@Override
71
	public Object execute(ExecutionEvent event) throws ExecutionException {
72
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
73
		final Object s = selection.getFirstElement();
74
		if (!(s instanceof TXMResult)) {
75
			return null;
76
		}
77
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
78

  
79
		//String txmhome = Toolbox.getTxmHomePath();
80
		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
81

  
82
		String extensions[] = {"*.parameters"}; //$NON-NLS-1$
83
		dialog.setFilterExtensions(extensions);
84

  
85
		if (LastOpened.getFile(ID) != null) {
86
			dialog.setFilterPath(LastOpened.getFolder(ID));
87
		}
88

  
89
		if (dialog.open() != null) {
90
			StatusLine.setMessage(TXMUIMessages.exportingResults);
91
			String filepath = dialog.getFilterPath()
92
					+ "/" + dialog.getFileName(); //$NON-NLS-1$
93
			if (!(filepath.endsWith(extensions[0].substring(1))))
94
				filepath += extensions[0].substring(1);
95

  
96
			final File outfile = new File(filepath);
97
			LastOpened.set(ID, outfile.getParent(), outfile.getName());
98
			try {
99
				outfile.createNewFile();
100
			} catch (IOException e1) {
101
				System.err.println(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1));
102
			}
103
			if (!outfile.canWrite()) {
104
				System.out.println(NLS.bind(TXMUIMessages.impossibleToReadP0, outfile));
105
				return null;
106
			}
107
			if (!outfile.isFile()) {
108
				System.out.println("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
109
				return null;
110
			}
111

  
112
			JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
113
				@Override
114
				protected IStatus run(IProgressMonitor monitor) {
115
					try {
116
						this.runInit(monitor);
117
						monitor.beginTask(TXMUIMessages.exporting, 100);
118

  
119
							TXMResult r = (TXMResult)s;
120
							if (r.isAltered()) {
121
								System.out.println("Warning: only parameters are exported, manual changes are not transfered.");
122
							} else {
123
								r.compute(this); // refresh result
124
							}
125
							r.setCurrentMonitor(this); // Allows Functions to protect themselves from interruption
126
							if (r.toParametersFile(outfile)) {
127
								System.out.println(NLS.bind("Parameters exported to the {0} file.", outfile));
128
							}
129

  
130
						if (outfile.exists()) {
131
							// Open internal editor in the UI thread
132
							if(TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW))	{
133
								this.syncExec(new Runnable() {
134
									@Override
135
									public void run() {
136
										EditFile.openfile(outfile.getAbsolutePath());
137
									}
138
								});
139
							}
140

  
141
							System.out.println(NLS.bind("", outfile.getAbsolutePath())); //$NON-NLS-1$
142
						} else {
143
							System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, outfile.getAbsolutePath()));
144
						}
145
					} catch (ThreadDeath td) {
146
						if (s instanceof TXMResult)
147
							((TXMResult)s).clean();
148
						return Status.CANCEL_STATUS;
149
					} catch (Exception e) {
150
						System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
151
						org.txm.rcp.utils.Logger.printStackTrace(e);
152
						return Status.CANCEL_STATUS;
153
					} finally {
154
						if (s instanceof TXMResult)
155
							((TXMResult)s).setCurrentMonitor(null);
156
						monitor.done();
157
						JobsTimer.stopAndPrint();
158
					}
159
					return Status.OK_STATUS;
160
				}
161
			};
162

  
163
			jobhandler.startJob();
164
		}
165
		return null;
166
	}
167
}
0 168

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ImportResult.java (revision 1513)
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.handlers.export;
29

  
30
import java.io.File;
31
import java.io.IOException;
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.jface.viewers.IStructuredSelection;
40
import org.eclipse.osgi.util.NLS;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.widgets.FileDialog;
43
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.ui.handlers.HandlerUtil;
45
import org.txm.core.preferences.TBXPreferences;
46
import org.txm.core.preferences.TXMPreferences;
47
import org.txm.core.results.TXMResult;
48
import org.txm.rcp.JobsTimer;
49
import org.txm.rcp.StatusLine;
50
import org.txm.rcp.handlers.files.EditFile;
51
import org.txm.rcp.messages.TXMUIMessages;
52
import org.txm.rcp.swt.dialog.LastOpened;
53
import org.txm.rcp.utils.JobHandler;
54
import org.txm.rcp.views.corpora.CorporaView;
55
// TODO: Auto-generated Javadoc
56
/**
57
 * export a result of a result by calling the function toTxt(File f) then show
58
 * the result in the text editor @ author mdecorde.
59
 */
60
public class ImportResult extends AbstractHandler {
61

  
62
	private static final String ID = ImportResult.class.getName();
63

  
64
	/**
65
	 * Export a TXM result parameters in the preferences format
66
	 *
67
	 * @param event the event
68
	 * @return the object
69
	 * @throws ExecutionException the execution exception
70
	 */
71
	@Override
72
	public Object execute(ExecutionEvent event) throws ExecutionException {
73
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
74
		final Object s = selection.getFirstElement();
75
		if (!(s instanceof TXMResult)) {
76
			return null;
77
		}
78
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
79

  
80
		//String txmhome = Toolbox.getTxmHomePath();
81
		FileDialog dialog = new FileDialog(shell, SWT.OPEN);
82

  
83
		String extensions[] = {"*.parameters"}; //$NON-NLS-1$
84
		dialog.setFilterExtensions(extensions);
85

  
86
		if (LastOpened.getFile(ID) != null) {
87
			dialog.setFilterPath(LastOpened.getFolder(ID));
88
		}
89

  
90
		if (dialog.open() != null) {
91
			StatusLine.setMessage(TXMUIMessages.exportingResults);
92
			String filepath = dialog.getFilterPath()
93
					+ "/" + dialog.getFileName(); //$NON-NLS-1$
94
			if (!(filepath.endsWith(extensions[0].substring(1))))
95
				filepath += extensions[0].substring(1);
96

  
97
			final File outfile = new File(filepath);
98
			LastOpened.set(ID, outfile.getParent(), outfile.getName());
99
			try {
100
				outfile.createNewFile();
101
			} catch (IOException e1) {
102
				System.err.println(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1));
103
			}
104
			if (!outfile.canWrite()) {
105
				System.out.println(NLS.bind(TXMUIMessages.impossibleToReadP0, outfile));
106
				return null;
107
			}
108
			if (!outfile.isFile()) {
109
				System.out.println("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
110
				return null;
111
			}
112

  
113
			JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
114
				@Override
115
				protected IStatus run(IProgressMonitor monitor) {
116
					try {
117
						this.runInit(monitor);
118
						monitor.beginTask(TXMUIMessages.exporting, 100);
119

  
120
						TXMResult parent = (TXMResult)s;
121
						TXMResult r = parent.importResult(outfile);
122
						CorporaView.refreshObject(r);
123
						if (r != null) {
124
							System.out.println(NLS.bind("{0} result imported from the {0} file.", r, outfile));
125
						}
126
					} catch (ThreadDeath td) {
127
						return Status.CANCEL_STATUS;
128
					} catch (Exception e) {
129
						System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
130
						org.txm.rcp.utils.Logger.printStackTrace(e);
131
						return Status.CANCEL_STATUS;
132
					} finally {
133
						if (s instanceof TXMResult)
134
							((TXMResult)s).setCurrentMonitor(null);
135
						monitor.done();
136
						JobsTimer.stopAndPrint();
137
					}
138
					return Status.OK_STATUS;
139
				}
140
			};
141

  
142
			jobhandler.startJob();
143
		}
144
		return null;
145
	}
146
}
0 147

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ImportResultParameters.java (revision 1513)
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.handlers.export;
29

  
30
import java.io.File;
31
import java.io.IOException;
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.jface.viewers.IStructuredSelection;
40
import org.eclipse.osgi.util.NLS;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.widgets.FileDialog;
43
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.ui.handlers.HandlerUtil;
45
import org.txm.core.preferences.TBXPreferences;
46
import org.txm.core.preferences.TXMPreferences;
47
import org.txm.core.results.TXMResult;
48
import org.txm.rcp.JobsTimer;
49
import org.txm.rcp.StatusLine;
50
import org.txm.rcp.editors.TXMEditor;
51
import org.txm.rcp.handlers.files.EditFile;
52
import org.txm.rcp.messages.TXMUIMessages;
53
import org.txm.rcp.swt.dialog.LastOpened;
54
import org.txm.rcp.utils.JobHandler;
55
import org.txm.rcp.utils.SWTEditorsUtils;
56
import org.txm.rcp.views.corpora.CorporaView;
57
// TODO: Auto-generated Javadoc
58
/**
59
 * export a result of a result by calling the function toTxt(File f) then show
60
 * the result in the text editor @ author mdecorde.
61
 */
62
public class ImportResultParameters extends AbstractHandler {
63

  
64
	private static final String ID = ImportResultParameters.class.getName();
65

  
66
	/**
67
	 * Export a TXM result parameters in the preferences format
68
	 *
69
	 * @param event the event
70
	 * @return the object
71
	 * @throws ExecutionException the execution exception
72
	 */
73
	@Override
74
	public Object execute(ExecutionEvent event) throws ExecutionException {
75
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
76
		final Object s = selection.getFirstElement();
77
		if (!(s instanceof TXMResult)) {
78
			return null;
79
		}
80
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
81

  
82
		//String txmhome = Toolbox.getTxmHomePath();
83
		FileDialog dialog = new FileDialog(shell, SWT.OPEN);
84

  
85
		String extensions[] = {"*.parameters"}; //$NON-NLS-1$
86
		dialog.setFilterExtensions(extensions);
87

  
88
		if (LastOpened.getFile(ID) != null) {
89
			dialog.setFilterPath(LastOpened.getFolder(ID));
90
		}
91

  
92
		if (dialog.open() != null) {
93
			StatusLine.setMessage(TXMUIMessages.exportingResults);
94
			String filepath = dialog.getFilterPath()
95
					+ "/" + dialog.getFileName(); //$NON-NLS-1$
96
			if (!(filepath.endsWith(extensions[0].substring(1))))
97
				filepath += extensions[0].substring(1);
98

  
99
			final File outfile = new File(filepath);
100
			LastOpened.set(ID, outfile.getParent(), outfile.getName());
101
			try {
102
				outfile.createNewFile();
103
			} catch (IOException e1) {
104
				System.err.println(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1));
105
			}
106
			if (!outfile.canWrite()) {
107
				System.out.println(NLS.bind(TXMUIMessages.impossibleToReadP0, outfile));
108
				return null;
109
			}
110
			if (!outfile.isFile()) {
111
				System.out.println("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
112
				return null;
113
			}
114

  
115
			JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
116
				@Override
117
				protected IStatus run(IProgressMonitor monitor) {
118
					try {
119
						this.runInit(monitor);
120
						monitor.beginTask(TXMUIMessages.exporting, 100);
121

  
122
						TXMResult r = (TXMResult)s;
123
						if (r.importParameters(outfile)) {
124
							r.setDirty();
125
							CorporaView.refreshObject(r);
126
							System.out.println(NLS.bind("Parameter imported from the {0} file.", outfile));
127
							SWTEditorsUtils.refreshEditor(r);
128
						}
129
					} catch (ThreadDeath td) {
130
						return Status.CANCEL_STATUS;
131
					} catch (Exception e) {
132
						System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
133
						org.txm.rcp.utils.Logger.printStackTrace(e);
134
						return Status.CANCEL_STATUS;
135
					} finally {
136
						if (s instanceof TXMResult)
137
							((TXMResult)s).setCurrentMonitor(null);
138
						monitor.done();
139
						JobsTimer.stopAndPrint();
140
					}
141
					return Status.OK_STATUS;
142
				}
143
			};
144

  
145
			jobhandler.startJob();
146
		}
147
		return null;
148
	}
149
}
0 150

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/utils/SWTEditorsUtils.java (revision 1513)
34 34
 *
35 35
 */
36 36
public class SWTEditorsUtils {
37
	
38
	
37

  
38

  
39 39
	/**
40 40
	 * Gets an editor for the specified result if its opened.
41 41
	 * @param result the result used by the editor to find
......
43 43
	 */
44 44
	public static IEditorPart getEditor(TXMResult result)	{
45 45

  
46
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
47
		IWorkbenchPage page = window.getActivePage();
48
		
49
		return page.findEditor(new TXMResultEditorInput<TXMResult>(result));
46
		for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
47
			for (IWorkbenchPage page : window.getPages()) {
48
				return page.findEditor(new TXMResultEditorInput<TXMResult>(result));
49
			}
50
		}
51
		return null;
50 52
	}
51 53

  
52 54
	/**
......
83 85

  
84 86
					}
85 87
				}
86
				
88

  
87 89
			}
88 90
		}
89
		
91

  
90 92
		return editors;
91
		
93

  
92 94
	}
93
	
95

  
94 96
	/**
95 97
	 * Gets the current active editor.
96 98
	 * @param event
97 99
	 * @return
98 100
	 */
99 101
	public static TXMEditor getActiveEditor(ExecutionEvent event)	{
100
		
102

  
101 103
		IEditorPart editor = null;
102
		
104

  
103 105
		if(event != null)	{
104 106
			editor = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActiveEditor();
105 107
		}
106 108
		else	{
107 109
			editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
108 110
		}
109
		
111

  
110 112
		if(editor instanceof TXMMultiPageEditor)	{
111 113
			editor = ((TXMMultiPageEditor)editor).getMainEditorPart();
112
			
114

  
113 115
		}
114
		
116

  
115 117
		if(!(editor instanceof TXMEditor))	{
116 118
			return null;
117 119
		}
118
		
120

  
119 121
		return (TXMEditor)editor;
120 122
	}
121 123

  
122
	
123
//	// FIXME: SJ: seems useless since page.findEditor() seem to return the multipage editor if a nested editor exists? 
124
//	/***
125
//	 * Gets an editor for the specified result if its opened inside a TXMMultiPageEditor.
126
//	 * @param result the result used by the editor to find
127
//	 * @return the editor if its opened otherwise null
128
//	 */
129
//	public static IEditorPart getEditorInMultiPageEditor(TXMResult result)	{
130
//		
131
//		IEditorPart editor = null;
132
//		
133
//		for (IEditorReference reference : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()) {
134
//			IEditorPart tmpEditor = reference.getEditor(false);
135
//
136
//			if(tmpEditor instanceof TXMMultiPageEditor)	{
137
//				TXMMultiPageEditor txmMultipageEditor = ((TXMMultiPageEditor)tmpEditor);
138
//				for (int i = 0; i < txmMultipageEditor.getEditors().size(); i++) {
139
//					if(txmMultipageEditor.getEditors().get(i) instanceof TXMEditor)	{
140
//						TXMEditor txmEditor = ((TXMEditor)txmMultipageEditor.getEditors().get(i));
141
//						if(txmEditor.getResult() == result)	{
142
//							editor = txmEditor;
143
//							break;
144
//						}
145
//					}
146
//				}
147
//				
148
//			}
149
//		}
150
//		
151
//		return editor;
152
//	}
153
	
124

  
125
	//	// FIXME: SJ: seems useless since page.findEditor() seem to return the multipage editor if a nested editor exists? 
126
	//	/***
127
	//	 * Gets an editor for the specified result if its opened inside a TXMMultiPageEditor.
128
	//	 * @param result the result used by the editor to find
129
	//	 * @return the editor if its opened otherwise null
130
	//	 */
131
	//	public static IEditorPart getEditorInMultiPageEditor(TXMResult result)	{
132
	//		
133
	//		IEditorPart editor = null;
134
	//		
135
	//		for (IEditorReference reference : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()) {
136
	//			IEditorPart tmpEditor = reference.getEditor(false);
137
	//
138
	//			if(tmpEditor instanceof TXMMultiPageEditor)	{
139
	//				TXMMultiPageEditor txmMultipageEditor = ((TXMMultiPageEditor)tmpEditor);
140
	//				for (int i = 0; i < txmMultipageEditor.getEditors().size(); i++) {
141
	//					if(txmMultipageEditor.getEditors().get(i) instanceof TXMEditor)	{
142
	//						TXMEditor txmEditor = ((TXMEditor)txmMultipageEditor.getEditors().get(i));
143
	//						if(txmEditor.getResult() == result)	{
144
	//							editor = txmEditor;
145
	//							break;
146
	//						}
147
	//					}
148
	//				}
149
	//				
150
	//			}
151
	//		}
152
	//		
153
	//		return editor;
154
	//	}
155

  
154 156
	/**
155 157
	 * Checks if the editor specified by its editor input is already open in the active page.
156 158
	 * @param editorInput
......
174 176
		}
175 177
		return null;
176 178
	}
177
	
178
//	/**
179
//	 * Checks if the specified editor is already open in the active page.
180
//	 * @param editor
181
//	 * @return
182
//	 */
183
//	public static boolean isOpenEditor(EditorPart editor)	{
184
//		return isOpenEditor(editor.getEditorInput());
185
//	}
186 179

  
180
	//	/**
181
	//	 * Checks if the specified editor is already open in the active page.
182
	//	 * @param editor
183
	//	 * @return
184
	//	 */
185
	//	public static boolean isOpenEditor(EditorPart editor)	{
186
	//		return isOpenEditor(editor.getEditorInput());
187
	//	}
188

  
187 189
	/**
188 190
	 * Splits the parent area of an editor and add another one in this area by splitting it. 
189 191
	 * (Same behavior than the splitting drag and drop event on editor.)
......
210 212
	public static void addEditor(EditorPart parentEditor, EditorPart editorToAdd, int position) {
211 213
		addEditor(parentEditor, editorToAdd, position, 0.5f);
212 214
	}
213
	
215

  
214 216
	/**
215 217
	 * Splits the parent area of a part and add another one in this area by splitting it. 
216 218
	 * (Same behavior than the splitting drag and drop event on editor.)
......
232 234
		}
233 235
		service.insert(stackToInsert, (MPartSashContainerElement) parent, position, percent);
234 236
	}
235
	
237

  
236 238
	/**
237 239
	 * Creates a part stack for the specified part.
238 240
	 * @param part
......
245 247
		stack.setSelectedElement(stackElement);
246 248
		return stack;
247 249
	}
250

  
251
	/**
252
	 * close a TXMEditor from its result
253
	 * 
254
	 * @param r
255
	 */
256
	public static boolean closeEditor(TXMResult r) {
257
		IEditorPart e = getEditor(r);
258
		if (e != null && e instanceof TXMEditor && ((TXMEditor)e).getResult() == r) {
259
			((TXMEditor)e).close();
260
			return true;
261
		}
262
		return false;
263
	}
264

  
265
	public static boolean refreshEditor(TXMResult r) {
266
		IEditorPart e = getEditor(r);
267
		if (e != null && e instanceof TXMEditor && ((TXMEditor)e).getResult() == r) {
268
			try {
269
				((TXMEditor)e).refresh(true);
270
				return true;
271
			} catch (Exception e1) {
272
				// TODO Auto-generated catch block
273
				e1.printStackTrace();
274
			}
275
		}
276
		return false;
277
	}
278
	
279
	public static boolean activateEditor(TXMResult r) {
280
		IEditorPart e = getEditor(r);
281
		if (e != null && e instanceof TXMEditor && ((TXMEditor)e).getResult() == r) {
282
			try {
283
				((TXMEditor)e).getSite().getPage().activate(e);
284
				return true;
285
			} catch (Exception e1) {
286
				// TODO Auto-generated catch block
287
				e1.printStackTrace();
288
			}
289
		}
290
		return false;
291
	}
248 292
}
tmp/org.txm.rcp/plugin.xml (revision 1513)
550 550
                     style="push">
551 551
                  <visibleWhen
552 552
                        checkEnabled="false">
553
                     <or>
553
                     <and>
554 554
                        <reference
555
                              definitionId="OneLexiconSelected">
555
                              definitionId="OneTXMResultSelected">
556 556
                        </reference>
557
                        <not>
558
                           <or>
559
                              <reference
560
                                    definitionId="OnePartitionSelected">
561
                              </reference>
562
                              <reference
563
                                    definitionId="OneCorpusSelected">
564
                              </reference>
565
                           </or>
566
                        </not>
567
                     </and>
568
                  </visibleWhen>
569
               </command>
570
               <command
571
                     commandId="org.txm.rcp.handlers.export.ExportResultParameters"
572
                     icon="icons/functions/export_parameters.png"
573
                     style="push">
574
                  <visibleWhen
575
                        checkEnabled="false">
576
                     <and>
557 577
                        <reference
558
                              definitionId="OneConcordanceSelected">
559
                        </reference>
560
                        <reference
561
                              definitionId="OneSpecificitiesResultSelected">
562
                        </reference>
563
                        <reference
564
                              definitionId="OneIndexSelected">
565
                        </reference>
566
                        <reference
567
                              definitionId="OneCooccurrenceSelected">
568
                        </reference>
569
                        <reference
570
                              definitionId="OneReferencerSelected">
571
                        </reference>
572
                        <reference
573
                              definitionId="OneProgressionSelected">
574
                        </reference>
575
                        <reference
576
                              definitionId="OneLexicalTableSelected">
577
                        </reference>
578
                        <reference
579
                              definitionId="OneCASelected">
580
                        </reference>
581
                        <reference
582
                              definitionId="OneCAHSelected">
583
                        </reference>
584
                        <reference
585 578
                              definitionId="OneTXMResultSelected">
586 579
                        </reference>
587
                     </or>
580
                        <not>
581
                           <or>
582
                              <reference
583
                                    definitionId="OnePartitionSelected">
584
                              </reference>
585
                              <reference
586
                                    definitionId="OneCorpusSelected">
587
                              </reference>
588
                           </or>
589
                        </not>
590
                     </and>
588 591
                  </visibleWhen>
589 592
               </command>
590 593
            </menu>
......
690 693
         <menu
691 694
               id="menu.edit"
692 695
               label="%menu.label.3">
696
               
697
               <command
698
                  commandId="org.txm.rcp.handlers.results.SetTXMResultPersistentState"
699
                  mode="FORCE_TEXT"
700
                  style="toggle">
701
               <visibleWhen
702
                     checkEnabled="false">
703
                  <and>
704
                     <reference
705
                           definitionId="OneTXMResultSelected">
706
                     </reference>
707
                     <test
708
                           property="org.txm.rcp.testers.persistable"
709
                           value="true">
710
                     </test>
711
                     <test
712
                           property="org.txm.rcp.testers.AutoPersistenceDisabled">
713
                     </test>
714
                  </and>
715
               </visibleWhen>
716
            </command>
693 717
            <command
718
                  commandId="org.txm.rcp.commands.function.RenameResult"
719
                  label="%command.label.26"
720
                  style="push">
721
               <visibleWhen
722
                     checkEnabled="false">
723
                  <reference
724
                        definitionId="OneTXMResultSelected">
725
                  </reference>
726
               </visibleWhen>
727
            </command>
728
            <command
729
                  commandId="org.txm.rcp.handlers.results.CloneTXMResult"
730
                  label="Clone"
731
                  style="push">
732
               <visibleWhen
733
                     checkEnabled="false">
734
                  <and>
735
                     <reference
736
                           definitionId="OneTXMResultSelected">
737
                     </reference>
738
                     <not>
739
                        <reference
740
                              definitionId="OneMainCorpusSelected">
741
                        </reference>
742
                     </not>
743
                  </and>
744
               </visibleWhen>
745
            </command>
746
            <command
747
                  commandId="org.txm.rcp.handlers.results.CloneTXMResultTree"
748
                  label="Clone all"
749
                  style="push">
750
               <visibleWhen
751
                     checkEnabled="false">
752
                  <and>
753
                     <reference
754
                           definitionId="OneTXMResultSelected">
755
                     </reference>
756
                     <not>
757
                        <reference
758
                              definitionId="OneMainCorpusSelected">
759
                        </reference>
760
                     </not>
761
                  </and>
762
               </visibleWhen>
763
            </command>
764
            <command
765
                  commandId="org.txm.rcp.handlers.results.ShowHiddenParents"
766
                  label="Show hidden parents"
767
                  style="push">
768
               <visibleWhen
769
                     checkEnabled="false">
770
                  <and>
771
                     <reference
772
                           definitionId="OneTXMResultSelected">
773
                     </reference>
774
                     <test
775
                           property="org.txm.rcp.testers.IsParentHidden">
776
                     </test>
777
                  </and>
778
               </visibleWhen>
779
            </command>
780
            <command
781
                  commandId="org.txm.rcp.handlers.results.HideIntermediateParents"
782
                  label="Hide intermediate parents"
783
                  style="push">
784
               <visibleWhen
785
                     checkEnabled="false">
786
                  <and>
787
                     <reference
788
                           definitionId="OneTXMResultSelected">
789
                     </reference>
790
                     <test
791
                           property="org.txm.rcp.testers.IsParentVisible"
792
                           value="true">
793
                     </test>
794
                  </and>
795
               </visibleWhen>
796
            </command>
797
            <separator
798
                  name="org.txm.rcp.separator1">
799
            </separator>
800
            
801
            <command
694 802
                  commandId="org.eclipse.ui.edit.findReplace"
695 803
                  label="%command.label.15">
696 804
               <visibleWhen
......
1267 1375
            <command
1268 1376
                  commandId="org.txm.rcp.commands.function.ExportResult"
1269 1377
                  icon="icons/functions/export_data.png"
1378
                  label="%command.label.51"
1270 1379
                  style="push">
1271 1380
               <visibleWhen
1272 1381
                     checkEnabled="false">
1273
                  <or>
1382
                  <and>
1274 1383
                     <reference
1275
                           definitionId="OneLexiconSelected">
1384
                           definitionId="OneTXMResultSelected">
1276 1385
                     </reference>
1386
                     <not>
1387
                        <or>
1388
                           <reference
1389
                                 definitionId="OnePartitionSelected">
1390
                           </reference>
1391
                           <reference
1392
                                 definitionId="OneCorpusSelected">
1393
                           </reference>
1394
                        </or>
1395
                     </not>
1396
                  </and>
1397
               </visibleWhen>
1398
            </command>
1399
            <command
1400
                  commandId="org.txm.rcp.handlers.export.ExportResultParameters"
1401
                  icon="icons/functions/export_parameters.png"
1402
                  style="push">
1403
               <visibleWhen
1404
                     checkEnabled="false">
1405
                  <and>
1277 1406
                     <reference
1278
                           definitionId="OneIndexSelected">
1407
                           definitionId="OneTXMResultSelected">
1279 1408
                     </reference>
1280
                     <reference
1281
                           definitionId="OneConcordanceSelected">
1282
                     </reference>
1283
                     <reference
1284
                           definitionId="OneSpecificitiesResultSelected">
1285
                     </reference>
1286
                     <reference
1287
                           definitionId="OneReferencerSelected">
1288
                     </reference>
1289
                     <reference
1290
                           definitionId="OneProgressionSelected">
1291
                     </reference>
1292
                     <reference
1293
                           definitionId="OneCooccurrenceSelected">
1294
                     </reference>
1295
                     <reference
1296
                           definitionId="OneLexicalTableSelected">
1297
                     </reference>
1298
                     <reference
1299
                           definitionId="OneCASelected">
1300
                     </reference>
1301
                     <reference
1302
                           definitionId="OneCAHSelected">
1303
                     </reference>
1304
                  </or>
1409
                     <not>
1410
                        <or>
1411
                           <reference
1412
                                 definitionId="OnePartitionSelected">
1413
                           </reference>
1414
                           <reference
1415
                                 definitionId="OneCorpusSelected">
1416
                           </reference>
1417
                        </or>
1418
                     </not>
1419
                  </and>
1305 1420
               </visibleWhen>
1306 1421
            </command>
1307 1422
         </toolbar>
......
1832 1947
                     icon="icons/functions/export.png"
1833 1948
                     id="org.txm.rcp.corporaview.export"
1834 1949
                     label="%menu.label.13">
1835
                     <command
1836
                  commandId="org.txm.rcp.commands.function.ExportResult"
1837
                  icon="icons/functions/export_data.png"
1838
                  label="%command.label.51"
1839
                  style="push">
1840
               <visibleWhen
1841
                     checkEnabled="false">
1842
                  <or>
1843
                     <reference
1844
                           definitionId="OneLexiconSelected">
1845
                     </reference>
1846
                     <reference
1847
                           definitionId="OneConcordanceSelected">
1848
                     </reference>
1849
                     <reference
1850
                           definitionId="OneSpecificitiesResultSelected">
1851
                     </reference>
1852
                     <reference
1853
                           definitionId="OneIndexSelected">
1854
                     </reference>
1855
                     <reference
1856
                           definitionId="OneReferencerSelected">
1857
                     </reference>
1858
                     <reference
1859
                           definitionId="OneProgressionSelected">
1860
                     </reference>
1861
                     <reference
1862
                           definitionId="OneCooccurrenceSelected">
1863
                     </reference>
1864
                     <reference
1865
                           definitionId="OneLexicalTableSelected">
1866
                     </reference>
1867
                     <reference
1868
                           definitionId="OneCASelected">
1869
                     </reference>
1870
                     <reference
1871
                           definitionId="OneCAHSelected">
1872
                     </reference>
1873
                     <reference
1874
                           definitionId="OneTXMResultSelected">
1875
                     </reference>
1876
                  </or>
1877
               </visibleWhen>
1878
            </command>
1950
                  <command
1951
                        commandId="org.txm.rcp.commands.function.ExportResult"
1952
                        icon="icons/functions/export_data.png"
1953
                        label="%command.label.51"
1954
                        style="push">
1955
                     <visibleWhen
1956
                           checkEnabled="false">
1957
                        <and>
1958
                           <reference
1959
                                 definitionId="OneTXMResultSelected">
1960
                           </reference>
1961
                           <not>
1962
                              <or>
1963
                                 <reference
1964
                                       definitionId="OnePartitionSelected">
1965
                                 </reference>
1966
                                 <reference
1967
                                       definitionId="OneCorpusSelected">
1968
                                 </reference>
1969
                              </or>
1970
                           </not>
1971
                        </and>
1972
                     </visibleWhen>
1973
                  </command>
1974
                  <command
1975
                        commandId="org.txm.rcp.handlers.export.ExportResultParameters"
1976
                        icon="icons/functions/export_parameters.png"
1977
                        style="push">
1978
                     <visibleWhen
1979
                           checkEnabled="false">
1980
                        <and>
1981
                           <reference
1982
                                 definitionId="OneTXMResultSelected">
1983
                           </reference>
1984
                           <not>
1985
                              <or>
1986
                                 <reference
1987
                                       definitionId="OneMainCorpusSelected">
1988
                                 </reference>
1989
                              </or>
1990
                           </not>
1991
                        </and>
1992
                     </visibleWhen>
1993
                  </command>
1994
                  <command
1995
                        commandId="org.txm.rcp.handlers.export.ImportResult"
1996
                        icon="icons/functions/import_data.png"
1997
                        style="push">
1998
                     <visibleWhen
1999
                           checkEnabled="false">
2000
                        <and>
2001
                           <reference
2002
                                 definitionId="OneTXMResultSelected">
2003
                           </reference>
2004
                        </and>
2005
                     </visibleWhen>
2006
                  </command>
2007
                  <command
2008
                        commandId="org.txm.rcp.handlers.export.ImportResultParameters"
2009
                        icon="icons/functions/import_parameters.png"
2010
                        style="push">
2011
                     <visibleWhen
2012
                           checkEnabled="false">
2013
                        <and>
2014
                           <reference
2015
                                 definitionId="OneTXMResultSelected">
2016
                           </reference>
2017
                           <not>
2018
                              <or>
2019
                                 <reference
2020
                                       definitionId="OneMainCorpusSelected">
2021
                                 </reference>
2022
                              </or>
2023
                           </not>
2024
                        </and>
2025
                     </visibleWhen>
2026
                  </command>
1879 2027
               </menu>
1880 2028
            
1881 2029
            <separator
......
2402 2550
            id="org.txm.rcp.commands.function.ExportResult"
2403 2551
            name="%command.name.24">
2404 2552
      </command>
2553
            <command
2554
                  defaultHandler="org.txm.rcp.handlers.export.ExportResultParameters"
2555
                  id="org.txm.rcp.handlers.export.ExportResultParameters"
2556
                  name="Parameters...">
2557
      </command>
2405 2558
      <command
2406 2559
            defaultHandler="org.txm.rcp.handlers.export.ExportSVG"
2407 2560
            id="org.txm.rcp.commands.function.ExportSVG"
2408 2561
            name="%command.name.34">
2409 2562
      </command>
2563
      <command
2564
            defaultHandler="org.txm.rcp.handlers.export.ImportResultParameters"
2565
            id="org.txm.rcp.handlers.export.ImportResultParameters"
2566
            name="Result...">
2567
      </command>
2568
      <command
2569
            defaultHandler="org.txm.rcp.handlers.export.ImportResult"
2570
            id="org.txm.rcp.handlers.export.ImportResult"
2571
            name="Import result...">
2572
      </command>
2573
      <command
2574
            defaultHandler="org.txm.rcp.handlers.export.ImportResultParameters"
2575
            id="org.txm.rcp.handlers.export.ImportResultParameters"
2576
            name="Import result parameters...">
2577
      </command>
2410 2578
   </extension>
2411 2579
   <extension
2412 2580
         id="links"
tmp/org.txm.core/src/java/org/txm/core/preferences/TXMPreferences.java (revision 1513)
2 2

  
3 3
import java.io.ByteArrayInputStream;
4 4
import java.io.ByteArrayOutputStream;
5
import java.io.File;
5 6
import java.io.IOException;
6 7
import java.io.ObjectInputStream;
7 8
import java.io.ObjectOutputStream;
......
14 15
import java.util.HashMap;
15 16
import java.util.Map;
16 17

  
18
import org.eclipse.core.resources.IFile;
17 19
import org.eclipse.core.runtime.Platform;
18 20
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
19 21
import org.eclipse.core.runtime.preferences.DefaultScope;
20 22
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
21 23
import org.eclipse.core.runtime.preferences.IScopeContext;
22 24
import org.eclipse.core.runtime.preferences.InstanceScope;
25
import org.eclipse.osgi.util.NLS;
23 26
import org.osgi.framework.FrameworkUtil;
24 27
import org.osgi.service.prefs.BackingStoreException;
25 28
import org.osgi.service.prefs.Preferences;
26 29
import org.txm.Toolbox;
27 30
import org.txm.core.results.TXMParameters;
28 31
import org.txm.core.results.TXMResult;
32
import org.txm.objects.Project;
33
import org.txm.utils.io.FileCopy;
29 34
import org.txm.utils.logger.Log;
30 35

  
31 36

  
......
1712 1717
		this.put(key, TXMResult.ID_TIME_FORMAT.format(date));
1713 1718
	}
1714 1719

  
1720
	/**
1721
	 * Saves the local preferences to a file.
1722
	 * @param result
1723
	 * @throws IOException 
1724
	 */
1725
	public static boolean flush(TXMResult result, File parametersFile) throws IOException	{
1726
		try {
1727
			preferencesRootNode.node(result.getParametersNodePath()).flush();
1728
			
1729
			Project p = result.getProject();
1730
			String store = p.getPreferencesScope().getLocation().toString();
1731
			String internalPath = result.getParametersNodePath();
1732
			String prefix = "/project/"+p.getRCPProject().getName();
1733
			if (internalPath.startsWith(prefix)) {
1734
				internalPath = internalPath.substring(prefix.length());
1735
			}
1736
			File prefFile = new File(store, internalPath+".prefs");
1737
			if (prefFile.exists()) {
1738
				parametersFile.delete();
1739
				FileCopy.copy(prefFile, parametersFile);
1740
				if (parametersFile.exists()) {
1741
					return true;
1742
				} else {
1743
					System.out.println(NLS.bind("** Error: could not write parameters to {0} file.", parametersFile));
1744
				}
1745
			} else {
1746
				System.out.println(NLS.bind("** Error: internal preference {0} file not found.", prefFile));
1747
			}
1748
		} catch(BackingStoreException e) {
1749
			System.out.println(NLS.bind("Parameters exported to the {0} file: {1}.", parametersFile, e));
1750
			e.printStackTrace();
1751
			Log.severe(e.getMessage());
1752
		}
1753
		return false;
1754
	}
1755
	
1715 1756
	//FIXME: this code is dedicated to dynamically retrieve the static field PREFERENCES_NODE of the runtime subclass and use it super class to avoid to pass it to all methods.
1716 1757
	// eg. to use ProgressionPreferences.getBoolean("test") instead of TXMPreferences.getBoolean(ProgressionPreferences.PREFERENCES_NODE, "test")
1717 1758
	// but it doesn"t work, need to continue the tests...
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 1513)
2 2

  
3 3
import java.io.File;
4 4
import java.io.IOException;
5
import java.lang.reflect.Constructor;
5 6
import java.lang.reflect.Field;
6 7
import java.text.DateFormat;
7 8
import java.text.SimpleDateFormat;
......
11 12
import java.util.Date;
12 13
import java.util.HashMap;
13 14
import java.util.List;
15
import java.util.Properties;
14 16
import java.util.concurrent.Semaphore;
15 17
import java.util.regex.Pattern;
16 18

  
17 19
import org.apache.commons.lang.StringUtils;
20
import org.apache.xmlbeans.impl.common.IOUtil;
18 21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.Platform;
19 23
import org.eclipse.core.runtime.preferences.DefaultScope;
20 24
import org.eclipse.osgi.util.NLS;
25
import org.osgi.framework.Bundle;
21 26
import org.osgi.framework.FrameworkUtil;
22 27
import org.osgi.service.prefs.BackingStoreException;
23 28
import org.txm.Toolbox;
......
28 33
import org.txm.objects.Workspace;
29 34
import org.txm.stat.utils.LogMonitor;
30 35
import org.txm.utils.AsciiUtils;
36
import org.txm.utils.io.IOUtils;
31 37
import org.txm.utils.logger.Log;
32 38

  
33 39
// FIXME: At this moment, an empty list is created for children, to not return
......
200 206
		this(null, parent);
201 207
	}
202 208

  
203
	public Date getComputeDate() {
204
		return this.lastComputingDate;
205
	}
206

  
207
	public Date getCreationDate() {
208
		return this.creationDate;
209
	}
210
	
211 209
	/**
212 210
	 * Creates a new TXMResult with no parent.
213 211
	 * If a local node exist with the parent_uuid, the parent will be retrieved and this result will be added to it. 
......
314 312
		}
315 313
	}
316 314

  
315
	public Date getComputeDate() {
316
		return this.lastComputingDate;
317
	}
318

  
319
	public Date getCreationDate() {
320
		return this.creationDate;
321
	}
322
	
323
	
317 324
	/**
318 325
	 * Sets the user name.
319 326
	 * @param name
......
1926 1933
		return clone;
1927 1934
	}
1928 1935

  
1936
	public boolean importParameters(File parameters) {
1937
		try {
1938
			Properties props = new Properties();
1939
			props.load(IOUtils.getReader(parameters));
1940
			
1941
			// some tests before...
1942
			String className = props.getProperty("class");
1943
			if (className == null || className.length() == 0) {
1944
				System.out.println("** Error: No class internal parameter set.");
1945
				return false;
1946
			}
1947
			
1948
			if (this.getClass().getName().equals(className)) {
1949
				for (Object p : props.keySet()) {
1950
					String ps = p.toString();
1951
					if (TXMPreferences.PARENT_PARAMETERS_NODE_PATH.equals(ps)) continue;
1952
					if (TXMPreferences.RESULT_PARAMETERS_NODE_PATH.equals(ps)) continue;
1953
					TXMPreferences.put(this.getParametersNodePath(), ps, props.getProperty(ps, ""));
1954
				}
1955
				this.autoLoadParametersFromAnnotations(); // update java parameters
1956
				this.loadParameters();
1957
			} else {
1958
				System.out.println(NLS.bind("Cannot import parameters of {0} in a {1} result.", className, this.getClass().getName()));
1959
				return false;
1960
			}
1961
		} catch(Exception e) {
1962
			Log.printStackTrace(e);
1963
		}
1964
		return true;
1965
	}
1966
	
1929 1967
	/**
1968
	 * import a result from a parameter file
1969
	 * @param allparameters the parameters file
1970
	 * @return the created result
1971
	 */
1972
	public TXMResult importResult(File parameters) {
1973
		try {
1974
			Properties props = new Properties();
1975
			props.load(IOUtils.getReader(parameters));
1976
			
1977
			// some tests before...
1978
			String className = props.getProperty("class");
1979
			if (className == null || className.length() == 0) {
1980
				System.out.println("** Error: No class internal parameter set.");
1981
				return null;
1982
			}
1983
			
1984
			String bundleId = props.getProperty("bundle_id");
1985
			if (bundleId == null || bundleId.length() == 0) {
1986
				System.out.println("** Error: No bundle_id internal parameter set.");
1987
				return null;
1988
			}
1989
			
1990
			Bundle bundle = Platform.getBundle(bundleId);
1991
			if (bundle == null) {
1992
				Log.finest("** Error: can not restore object with bundle name " + bundleId); //$NON-NLS-1$
1993
				return null;
1994
			}
1995
			
1996
			// copy parameters
1997
			String newNodePath = this.getProject().getParametersNodeRootPath()+ createUUID() + "_" + className;
1998
			TXMPreferences.put(newNodePath, TXMPreferences.PARENT_PARAMETERS_NODE_PATH, this.getParametersNodePath());
1999
			for (Object p : props.keySet()) {
2000
				String ps = p.toString();
2001
				if (TXMPreferences.PARENT_PARAMETERS_NODE_PATH.equals(ps)) continue;
2002
				if (TXMPreferences.RESULT_PARAMETERS_NODE_PATH.equals(ps)) continue;
2003
				TXMPreferences.put(newNodePath, ps, props.getProperty(ps, ""));
2004
			}
2005
			
2006
			// create instance
2007
			Class<?> cl = bundle.loadClass(className);
2008
			Constructor<?> cons = null;
2009
			Class clazz = this.getClass();
2010
			while (cons == null) {
2011
				if (clazz.getSimpleName().equals("TXMResult")) {
2012
					continue; // no luck
2013
				}
2014
				try {
2015
					cons = cl.getConstructor(clazz);
2016
				} catch (Exception ce) {
2017
					clazz = clazz.getSuperclass();
2018
				}
2019
			}
2020
			
2021
			if (cons == null) {
2022
				System.out.println(NLS.bind("Cannot import {0} in {1}", parameters, this));
2023
			} else {
2024
				cons = cl.getConstructor(String.class);
2025
				TXMResult result = (TXMResult) cons.newInstance(newNodePath);
2026
				System.out.println(NLS.bind("{0} imported", result));
2027
				return result;
2028
			}
2029
			
2030
		} catch (Exception e) {
2031
			System.out.println(NLS.bind("Fail to import result from {0}: {1}", parameters, e));
2032
			Log.printStackTrace(e);
2033
		}
2034
		return null;
2035
	}
2036
	
2037
	/**
1930 2038
	 * Set the TXMResult parameters
1931 2039
	 * 
1932 2040
	 * @param parameters
......
2471 2579
	public ArrayList<HashMap<String, Object>> getParametersHistory() {
2472 2580
		return parametersHistory;
2473 2581
	}
2582

  
2583
	public boolean toParametersFile(File outfile) throws IOException {
2584
		return TXMPreferences.flush(this, outfile);
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff