Révision 3562

TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/commands/CrossedPartitionBuilderMacro.groovy (revision 3562)
19 19
corpus = corpusViewSelection
20 20

  
21 21
@Field @Option(name="structuralUnit", usage="the structural Unit to use", widget="String", required=true, def="text")
22
String structuralUnit = "text"
22
String structuralUnit
23 23

  
24 24
@Field @Option(name="structuralUnitPropertiesList", usage="the structural Unit properties list separated with commas", widget="String", required=true, def="p1,p2")
25
def structuralUnitPropertiesList = "loc, type";
25
def structuralUnitPropertiesList
26

  
27
@Field @Option(name="propertySeparator", usage="property name separator", widget="String", required=true, def="_") //  ∩ 
28
def propertySeparator
26 29
		
27 30
//@Field @Option(name="expandTarget", usage="Expand structure", widget="String", required=false, def="")
28 31
def expandTarget = "";
......
269 272
			String and = '';
270 273
			String underscore = '';
271 274
			if (tmpQuery != '')	{
272
				underscore = ' ∩ ';
275
				underscore = propertySeparator;
273 276
				and = ' & ';
274 277
			}
275 278

  
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultParameter.java (revision 3562)
1
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
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.core.runtime.SubMonitor;
40
import org.eclipse.jface.viewers.IStructuredSelection;
41
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.widgets.FileDialog;
44
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.ui.handlers.HandlerUtil;
46
import org.txm.core.preferences.TBXPreferences;
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.utils.ExecTimer;
55
import org.txm.utils.logger.Log;
56

  
57
/**
58
 * Exports a result by calling the function toTxt(File f) then opens or not the result in the text editor according to the preferences.
59
 * 
60
 * @author mdecorde, sjacquot
61
 */
62
public class ExportResultParameter extends AbstractHandler {
63
	
64
	private static final String ID = "org.txm.rcp.commands.function.ExportResult"; //$NON-NLS-1$
65
	
66
	/** The selection. */
67
	private IStructuredSelection selection;
68
	
69
	/** The lastopenedfile. */
70
	// private static String lastopenedfile;
71
	
72
	/**
73
	 * Export a TXM result in a CSV file.
74
	 *
75
	 * @param event the event
76
	 * @return the object
77
	 * @throws ExecutionException the execution exception
78
	 */
79
	@Override
80
	public Object execute(ExecutionEvent event) throws ExecutionException {
81
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
82
		final Object s = selection.getFirstElement();
83
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
84
		
85
		// String txmhome = Toolbox.getTxmHomePath();
86
		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
87
		
88
		String extensions[] = { "*.csv" }; //$NON-NLS-1$
89
		if (s instanceof TXMResult) {
90
			extensions = ((TXMResult) s).getExportTXTExtensions();
91
			dialog.setFileName(((TXMResult) s).getValidFileName());
92
		}
93
		dialog.setFilterExtensions(extensions);
94
		
95
		if (LastOpened.getFile(ID) != null) {
96
			dialog.setFilterPath(LastOpened.getFolder(ID));
97
		}
98
		
99
		if (dialog.open() != null) {
100
			StatusLine.setMessage(TXMUIMessages.exportingResults);
101
			String filepath = dialog.getFilterPath() + "/" + dialog.getFileName(); //$NON-NLS-1$
102
			if (!(filepath.endsWith(extensions[0].substring(1))))
103
				filepath += extensions[0].substring(1);
104
			
105
			final File outfile = new File(filepath);
106
			LastOpened.set(ID, outfile.getParent(), outfile.getName());
107
			try {
108
				outfile.createNewFile();
109
			}
110
			catch (IOException e1) {
111
				Log.warning(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1));
112
			}
113
			if (!outfile.canWrite()) {
114
				Log.warning(NLS.bind(TXMUIMessages.impossibleToReadP0, outfile));
115
				return null;
116
			}
117
			if (!outfile.isFile()) {
118
				Log.warning("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
119
				return null;
120
			}
121
			
122
			final String encoding = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_ENCODING);
123
			String _colseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_COL_SEPARATOR);
124
			final String colseparator = _colseparator;
125
			String _txtseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_TXT_SEPARATOR);
126
			final String txtseparator = _txtseparator;
127
			
128
			JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
129
				
130
				@Override
131
				protected IStatus run(IProgressMonitor monitor) {
132
					
133
					// convert the monitor into sub-monitor
134
					SubMonitor subMonitor = SubMonitor.convert(monitor, TXMUIMessages.exporting, 100);
135
					
136
					try {
137
						
138
						this.runInit(subMonitor);
139
						
140
						if (s instanceof TXMResult) {
141
							TXMResult r = (TXMResult) s;
142
							
143
							// compute the result if needed
144
							if (!r.isAltered() && r.isDirty()) {
145
								r.compute(this);
146
							}
147
							Log.info(TXMUIMessages.bind(TXMUIMessages.exportingP0, r.getName()));
148
							ExecTimer.start();
149
							r.toTxt(outfile, encoding, colseparator, txtseparator);
150
							Log.info(TXMUIMessages.bind(TXMUIMessages.doneInP0, ExecTimer.stop()));
151
						}
152
						else {
153
							Log.warning(TXMUIMessages.TheExportedObjectIsNotATXMResultResult);
154
							return Status.CANCEL_STATUS;
155
						}
156
						
157
						if (outfile.exists()) {
158
							// Open internal editor in the UI thread
159
							if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW)) {
160
								this.syncExec(new Runnable() {
161
									
162
									@Override
163
									public void run() {
164
										EditFile.openfile(outfile.getAbsolutePath());
165
									}
166
								});
167
							}
168
						}
169
						else {
170
							Log.warning(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, outfile.getAbsolutePath()));
171
						}
172
					}
173
					catch (ThreadDeath td) {
174
						TXMResult r = (TXMResult) s;
175
						r.resetComputingState();
176
						return Status.CANCEL_STATUS;
177
					}
178
					catch (Exception e) {
179
						Log.warning(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
180
						org.txm.utils.logger.Log.printStackTrace(e);
181
						return Status.CANCEL_STATUS;
182
					}
183
					finally {
184
						subMonitor.done();
185
						JobsTimer.stopAndPrint();
186
					}
187
					return Status.OK_STATUS;
188
				}
189
			};
190
			
191
			jobhandler.startJob();
192
		}
193
		return null;
194
	}
195
}
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultData.java (revision 3562)
1
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
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.core.runtime.SubMonitor;
40
import org.eclipse.jface.viewers.IStructuredSelection;
41
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.widgets.FileDialog;
44
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.ui.handlers.HandlerUtil;
46
import org.txm.core.preferences.TBXPreferences;
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.utils.ExecTimer;
55
import org.txm.utils.logger.Log;
56

  
57
/**
58
 * Exports a result by calling the function toTxt(File f) then opens or not the result in the text editor according to the preferences.
59
 * 
60
 * @author mdecorde, sjacquot
61
 */
62
public class ExportResultData extends AbstractHandler {
63
	
64
	private static final String ID = "org.txm.rcp.commands.function.ExportResult"; //$NON-NLS-1$
65
	
66
	/** The selection. */
67
	private IStructuredSelection selection;
68
	
69
	/** The lastopenedfile. */
70
	// private static String lastopenedfile;
71
	
72
	/**
73
	 * Export a TXM result in a CSV file.
74
	 *
75
	 * @param event the event
76
	 * @return the object
77
	 * @throws ExecutionException the execution exception
78
	 */
79
	@Override
80
	public Object execute(ExecutionEvent event) throws ExecutionException {
81
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
82
		final Object s = selection.getFirstElement();
83
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
84
		
85
		// String txmhome = Toolbox.getTxmHomePath();
86
		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
87
		
88
		String extensions[] = { "*.csv" }; //$NON-NLS-1$
89
		if (s instanceof TXMResult) {
90
			extensions = ((TXMResult) s).getExportTXTExtensions();
91
			dialog.setFileName(((TXMResult) s).getValidFileName());
92
		}
93
		dialog.setFilterExtensions(extensions);
94
		
95
		if (LastOpened.getFile(ID) != null) {
96
			dialog.setFilterPath(LastOpened.getFolder(ID));
97
		}
98
		
99
		if (dialog.open() != null) {
100
			StatusLine.setMessage(TXMUIMessages.exportingResults);
101
			String filepath = dialog.getFilterPath() + "/" + dialog.getFileName(); //$NON-NLS-1$
102
			if (!(filepath.endsWith(extensions[0].substring(1))))
103
				filepath += extensions[0].substring(1);
104
			
105
			final File outfile = new File(filepath);
106
			LastOpened.set(ID, outfile.getParent(), outfile.getName());
107
			try {
108
				outfile.createNewFile();
109
			}
110
			catch (IOException e1) {
111
				Log.warning(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1));
112
			}
113
			if (!outfile.canWrite()) {
114
				Log.warning(NLS.bind(TXMUIMessages.impossibleToReadP0, outfile));
115
				return null;
116
			}
117
			if (!outfile.isFile()) {
118
				Log.warning("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
119
				return null;
120
			}
121
			
122
			final String encoding = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_ENCODING);
123
			String _colseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_COL_SEPARATOR);
124
			final String colseparator = _colseparator;
125
			String _txtseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_TXT_SEPARATOR);
126
			final String txtseparator = _txtseparator;
127
			
128
			JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
129
				
130
				@Override
131
				protected IStatus run(IProgressMonitor monitor) {
132
					
133
					// convert the monitor into sub-monitor
134
					SubMonitor subMonitor = SubMonitor.convert(monitor, TXMUIMessages.exporting, 100);
135
					
136
					try {
137
						
138
						this.runInit(subMonitor);
139
						
140
						if (s instanceof TXMResult) {
141
							TXMResult r = (TXMResult) s;
142
							
143
							// compute the result if needed
144
							if (!r.isAltered() && r.isDirty()) {
145
								r.compute(this);
146
							}
147
							Log.info(TXMUIMessages.bind(TXMUIMessages.exportingP0, r.getName()));
148
							ExecTimer.start();
149
							r.toTxt(outfile, encoding, colseparator, txtseparator);
150
							Log.info(TXMUIMessages.bind(TXMUIMessages.doneInP0, ExecTimer.stop()));
151
						}
152
						else {
153
							Log.warning(TXMUIMessages.TheExportedObjectIsNotATXMResultResult);
154
							return Status.CANCEL_STATUS;
155
						}
156
						
157
						if (outfile.exists()) {
158
							// Open internal editor in the UI thread
159
							if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW)) {
160
								this.syncExec(new Runnable() {
161
									
162
									@Override
163
									public void run() {
164
										EditFile.openfile(outfile.getAbsolutePath());
165
									}
166
								});
167
							}
168
						}
169
						else {
170
							Log.warning(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, outfile.getAbsolutePath()));
171
						}
172
					}
173
					catch (ThreadDeath td) {
174
						TXMResult r = (TXMResult) s;
175
						r.resetComputingState();
176
						return Status.CANCEL_STATUS;
177
					}
178
					catch (Exception e) {
179
						Log.warning(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
180
						org.txm.utils.logger.Log.printStackTrace(e);
181
						return Status.CANCEL_STATUS;
182
					}
183
					finally {
184
						subMonitor.done();
185
						JobsTimer.stopAndPrint();
186
					}
187
					return Status.OK_STATUS;
188
				}
189
			};
190
			
191
			jobhandler.startJob();
192
		}
193
		return null;
194
	}
195
}
0 196

  
TXM/trunk/org.txm.rcp/plugin.xml (revision 3562)
2808 2808
         point="org.eclipse.ui.commands">
2809 2809

  
2810 2810
      <command
2811
            defaultHandler="org.txm.rcp.handlers.export.ExportResultParameter"
2811
            defaultHandler="org.txm.rcp.handlers.export.ExportResultData"
2812 2812
            id="org.txm.rcp.commands.function.ExportResult"
2813 2813
            name="%command.name.24">
2814 2814
      </command>
TXM/trunk/org.txm.partition.core/src/org/txm/partition/core/functions/PartitionDimensions.java (revision 3562)
22 22
import org.txm.searchengine.cqp.corpus.Partition;
23 23
import org.txm.utils.TXMProgressMonitor;
24 24
import org.txm.utils.io.IOUtils;
25
import org.txm.utils.logger.Log;
25 26

  
26 27
/**
27 28
 * Partition dimensions.
......
57 58
	
58 59
	
59 60
	
60
	
61 61
	/**
62 62
	 * Creates a not computed partition dimensions.
63 63
	 * 
......
108 108
		return true;
109 109
	}
110 110
	
111
	/**
112
	 * Gets a string representing the result that can be used as a file name (eg. for exporting in file).
113
	 * 
114
	 * @return a valid filename without unexpected characters
115
	 */
116
	// FIXME: to discuss and/or to move in export layer
117
	public String getValidFileName() {
118
		
119
		return parent.getValidFileName()+" "+super.getValidFileName(); //$NON-NLS-1$
120
	}
111 121
	
112
	
113 122
	@Override
114 123
	protected boolean __compute(TXMProgressMonitor monitor) throws Exception {
115 124
		// retrieve the parts
......
236 245
	public boolean _toTxt(File file, String encoding, String colseparator, String txtseparator) throws Exception {
237 246
		PrintWriter writer = IOUtils.getWriter(file, encoding);
238 247
		
248
		writer.println("id"+colseparator+"F");
249
		
239 250
		for (Part b : this.parts) {
240 251
			writer.println(txtseparator+b.getName().replaceAll(txtseparator, txtseparator+txtseparator)+txtseparator+colseparator+txtseparator+b.getSize()+txtseparator);
241 252
		}

Formats disponibles : Unified diff