Revision 505

tmp/org.txm.searchengine.cqp.rcp/build.properties (revision 505)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml,\
6
               OSGI-INF/l10n/bundle.properties
0 7

  
tmp/org.txm.searchengine.cqp.rcp/OSGI-INF/l10n/bundle.properties (revision 505)
1
#Properties file for org.txm.searchengine.cqp.rcp
2
Bundle-Name = CQP RCP
3
command.label.36=Add Project
4
command.label.37=Add Base
5
command.label.65=Delete
6
command.label.148=Open biblio
7
command.name.52=Corpus in binary format...
8
command.label.8=Partition
9
command.name.63=Open Biblio
10
command.name.2=Create Partition
11
command.tooltip.4=Divide the selected item in several parts
12
command.tooltip.71=Export as a binary file
0 13

  
tmp/org.txm.searchengine.cqp.rcp/plugin.xml (revision 505)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.ui.commands">
6
         <command
7
            categoryId="org.eclipse.ui.category.navigate"
8
            defaultHandler="org.txm.rcp.commands.base.OpenBiblio"
9
            id="org.txm.rcp.commands.base.OpenBiblio"
10
            name="%command.name.63">
11
      </command>
12
            <command
13
            defaultHandler="org.txm.rcp.commands.base.ExportCorpus"
14
            id="org.txm.rcp.commands.base.ExportCorpus"
15
            name="%command.name.52">
16
      </command>
17
      <command
18
            defaultHandler="org.txm.rcp.commands.base.CreatePartition"
19
            id="org.txm.rcp.commands.base.CreatePartition"
20
            name="%command.name.2">
21
         <commandParameter
22
               id="CorpusParameter"
23
               name="%commandParameter.name.0"
24
               optional="true">
25
         </commandParameter>
26
      </command>
27
      <command
28
            defaultHandler="org.txm.rcp.commands.base.CreateSubCorpus"
29
            id="org.txm.rcp.commands.base.CreateSubCorpus"
30
            name="Subcorpus">
31
         <commandParameter
32
               id="CorpusParameter"
33
               name="%commandParameter.name.0"
34
               optional="true">
35
         </commandParameter>
36
      </command>
37
   </extension>
38
   <extension
39
         point="org.eclipse.ui.menus">
40
            <menuContribution
41
            locationURI="popup:org.txm.rcp.views.BasesView">
42
         <command
43
               commandId="HIDEorg.txm.rcp2.commands.workspace.AddProject"
44
               label="%command.label.36"
45
               style="push">
46
            <visibleWhen
47
                  checkEnabled="false">
48
               <reference
49
                     definitionId="OneProjectSelected">
50
               </reference>
51
            </visibleWhen>
52
         </command>
53
         <command
54
               commandId="org.txm.rcp.commands.workspace.AddBase"
55
               label="%command.label.37"
56
               style="push">
57
            <visibleWhen
58
                  checkEnabled="false">
59
               <reference
60
                     definitionId="OneProjectSelected">
61
               </reference>
62
            </visibleWhen>
63
         </command>       
64
         <separator
65
               name="org.txm.rcp.separator1">
66
         </separator>
67
         <command
68
               commandId="org.txm.rcp.commands.base.DeleteInCorpora"
69
               icon="icons/functions/Delete.png"
70
               label="%command.label.65"
71
               style="push"
72
               tooltip="%command.tooltip.33">
73
            <visibleWhen
74
                  checkEnabled="false">
75
               <or>
76
                  <reference
77
                        definitionId="OnePartitionSelected">
78
                  </reference>
79
                  <reference
80
                        definitionId="OneSubCorpusSelected">
81
                  </reference>
82
                  <reference
83
                        definitionId="OneBaseSelected">
84
                  </reference>
85
                  <reference
86
                        definitionId="OneIndexSelected">
87
                  </reference>
88
                  <reference
89
                        definitionId="OneLexiconSelected">
90
                  </reference>
91
                  <reference
92
                        definitionId="OneConcordanceSelected">
93
                  </reference>
94
                  <reference
95
                        definitionId="OneCASelected">
96
                  </reference>
97
                  <reference
98
                        definitionId="OneSpecificitiesResultSelected">
99
                  </reference>
100
                  <reference
101
                        definitionId="OneMainCorpusSelected">
102
                  </reference>
103
               </or>
104
            </visibleWhen>
105
         </command>
106
         <command
107
               commandId="org.txm.rcp.commands.base.OpenBiblio"
108
               icon="icons/functions/Biblio.png"
109
               label="%command.label.148"
110
               style="push"
111
               tooltip="%command.tooltip.91">
112
            <visibleWhen
113
                  checkEnabled="false">
114
               <or>
115
                  <reference
116
                        definitionId="OneBaseSelected">
117
                  </reference>
118
                  <reference
119
                        definitionId="OneTextSelected">
120
                  </reference>
121
               </or>
122
            </visibleWhen>
123
         </command>
124
      </menuContribution>
125
      <menuContribution
126
            locationURI="popup:corporaview.menu.file.export">
127
         <command
128
               commandId="org.txm.rcp.commands.base.ExportCorpus"
129
               icon="icons/functions/Compress.png"
130
               label="%command.name.52"
131
               style="push"
132
               tooltip="%command.tooltip.71">
133
            <visibleWhen
134
                  checkEnabled="false">
135
               <reference
136
                     definitionId="OneMainCorpusSelected">
137
               </reference>
138
            </visibleWhen>
139
         </command>
140
            </menuContribution>
141
      <menuContribution
142
            locationURI="menu:menu.file.export">
143
         <command
144
               commandId="org.txm.rcp.commands.base.ExportCorpus"
145
               icon="icons/functions/Compress.png"
146
               label="%command.name.52"
147
               style="push"
148
               tooltip="%command.tooltip.67">
149
            <visibleWhen
150
                  checkEnabled="false">
151
               <reference
152
                     definitionId="OneMainCorpusSelected">
153
               </reference>
154
            </visibleWhen>
155
         </command>
156
      </menuContribution>
157
      <menuContribution
158
            allPopups="true"
159
            locationURI="toolbar:org.txm.rcp.toolbarfile">
160
            <command
161
                  commandId="org.txm.rcp.commands.base.ExportCorpus"
162
                  icon="icons/functions/Compress.png"
163
                  label="%command.name.52"
164
                  style="push"
165
                  tooltip="%command.tooltip.71">
166
               <visibleWhen
167
                     checkEnabled="false">
168
                  <reference
169
                        definitionId="OneMainCorpusSelected">
170
                  </reference>
171
               </visibleWhen>
172
            </command>
173
      </menuContribution>
174
      <menuContribution
175
            locationURI="toolbar:org.txm.rcp.toolbarcorpus">
176
         <command
177
               commandId="org.txm.rcp.commands.base.CreateSubCorpus"
178
               icon="icons/functions/SubCorpus.png"
179
               label="Subcorpus"
180
               style="push">
181
            <visibleWhen
182
                  checkEnabled="false">
183
               <reference
184
                     definitionId="OneCorpusSelected">
185
               </reference>
186
            </visibleWhen>
187
         </command>
188
                        <command
189
                  commandId="org.txm.rcp.commands.base.CreatePartition"
190
                  icon="icons/functions/Partition.png"
191
                  label="%command.label.8"
192
                  style="push"
193
                  tooltip="%command.tooltip.4">
194
               <visibleWhen
195
                     checkEnabled="false">
196
                  <reference
197
                        definitionId="OneCorpusSelected">
198
                  </reference>
199
               </visibleWhen>
200
            </command>
201
      </menuContribution>
202
      <menuContribution
203
            locationURI="popup:org.txm.rcp.views.corpora.CorporaView">
204
         <command
205
               commandId="org.txm.rcp.commands.base.CreateSubCorpus"
206
               icon="icons/functions/SubCorpus.png"
207
               label="Subcorpus"
208
               style="push">
209
            <visibleWhen
210
                  checkEnabled="false">
211
               <reference
212
                     definitionId="OneCorpusSelected">
213
               </reference>
214
            </visibleWhen>
215
         </command>
216
         <command
217
               commandId="org.txm.rcp.commands.base.CreatePartition"
218
               icon="icons/functions/Partition.png"
219
               label="%command.label.8"
220
               style="push"
221
               tooltip="%command.tooltip.4">
222
            <visibleWhen
223
                  checkEnabled="false">
224
               <reference
225
                     definitionId="OneCorpusSelected">
226
               </reference>
227
            </visibleWhen>
228
         </command>
229
      </menuContribution>
230
      <menuContribution
231
            locationURI="menu:menu.corpus">
232
         <command
233
               commandId="org.txm.rcp.commands.base.CreateSubCorpus"
234
               icon="icons/functions/SubCorpus.png"
235
               label="Subcorpus"
236
               style="push">
237
            <visibleWhen
238
                  checkEnabled="false">
239
               <reference
240
                     definitionId="OneCorpusSelected">
241
               </reference>
242
            </visibleWhen>
243
         </command>
244
         <command
245
               commandId="org.txm.rcp.commands.base.CreatePartition"
246
               icon="icons/functions/Partition.png"
247
               label="%command.label.8"
248
               style="push"
249
               tooltip="%command.tooltip.4">
250
            <visibleWhen
251
                  checkEnabled="false">
252
               <reference
253
                     definitionId="OneCorpusSelected">
254
               </reference>
255
            </visibleWhen>
256
         </command>
257
      </menuContribution>
258
   </extension>
259

  
260
</plugin>
0 261

  
tmp/org.txm.searchengine.cqp.rcp/.settings/org.eclipse.jdt.core.prefs (revision 505)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.6
0 8

  
tmp/org.txm.searchengine.cqp.rcp/.classpath (revision 505)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
0 8

  
tmp/org.txm.searchengine.cqp.rcp/META-INF/MANIFEST.MF (revision 505)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %Bundle-Name
4
Bundle-SymbolicName: org.txm.searchengine.cqp.rcp;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
7
Require-Bundle: org.txm.searchengine.core;bundle-version="1.0.0",
8
 org.txm.searchengine.cqp.core;bundle-version="1.1.0",
9
 org.txm.core;bundle-version="0.8.0",
10
 org.txm.rcp;bundle-version="0.8.0",
11
 org.eclipse.core.commands;bundle-version="3.6.100",
12
 org.eclipse.ui.workbench;bundle-version="3.106.2",
13
 org.eclipse.ui
0 14

  
tmp/org.txm.searchengine.cqp.rcp/.project (revision 505)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.searchengine.cqp.rcp</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

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

  
30
import org.eclipse.core.commands.AbstractHandler;
31
import org.eclipse.core.commands.ExecutionEvent;
32
import org.eclipse.core.commands.ExecutionException;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.Status;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.window.Window;
38
import org.eclipse.osgi.util.NLS;
39
import org.eclipse.swt.widgets.Shell;
40
import org.eclipse.ui.IWorkbenchWindow;
41
import org.eclipse.ui.handlers.HandlerUtil;
42
import org.txm.Toolbox;
43
import org.txm.rcp.JobsTimer;
44
import org.txm.rcp.Messages;
45
import org.txm.rcp.actions.CreateSubcorpusDialog;
46
import org.txm.rcp.utils.JobHandler;
47
import org.txm.rcp.views.corpora.CorporaView;
48
import org.txm.searchengine.cqp.CQPEngine;
49
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
50
import org.txm.searchengine.cqp.corpus.Corpus;
51
import org.txm.searchengine.cqp.corpus.Subcorpus;
52
import org.txm.searchengine.cqp.corpus.query.Query;
53
import org.txm.utils.logger.Log;
54

  
55
// TODO: Auto-generated Javadoc
56
/**
57
 * Command which creates a subcorpus from a Corpus @ author mdecorde.
58
 */
59
public class CreateSubCorpus extends AbstractHandler {
60

  
61
	/** The selection. */
62
	private IStructuredSelection selection;
63

  
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
66
	 */
67
	@Override
68
	public Object execute(ExecutionEvent event) throws ExecutionException {
69
		
70
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
71
		if (selection == null) {
72
			System.out.println(Messages.CreateSubCorpus_1+HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActiveEditor());
73
			return null;
74
		}
75
		Object firstElement = selection.getFirstElement();
76
		
77
		if (!(firstElement instanceof Corpus)) {
78
			System.out.println(Messages.CreateSubCorpus_3+firstElement);
79
			return null;
80
		}
81
		
82
		final Corpus corpus = (Corpus) firstElement;
83
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
84
				.getShell();
85
		final CreateSubcorpusDialog d = new CreateSubcorpusDialog(shell, corpus);
86
		int code = d.open();
87
		if (code == Window.OK) {
88
			JobHandler jobhandler = new JobHandler(NLS.bind(
89
					Messages.CreateSubCorpus_create, corpus.getName())) {
90
				@Override
91
				protected IStatus run(IProgressMonitor monitor) {		
92
					this.runInit(monitor);
93
					JobsTimer.start();
94
					try {
95
						monitor.beginTask(Messages.CreateSubCorpus_begin, 100);
96
						final Subcorpus subcorpus;
97

  
98
						if (d.isAdvancedSelected() || d.isAssistedSelected()) {
99
							Query q = new Query(d.getQuery());
100
							System.out.println(NLS.bind(Messages.CreateSubcorpus_9,
101
								corpus.getName(), q.getQueryString())); 
102
							subcorpus = corpus.createSubcorpus(q, d.getName());
103
						} 
104
						else {
105
							System.out.println(NLS.bind(Messages.CreateSubcorpus_7,
106
							new Object[]{corpus.getName(), d.getStructuralUnit(),
107
									d.getStructuralUnitProperty(), d.getValues()}));
108
							
109
							//Escape regex char of prop values
110
							//List<String> values = d.getValues();
111
							//for(int i = 0 ; i < values.size() ; i++)
112
							//	values.set(i, Query.addBackSlash(values.get(i)));
113
							
114
							subcorpus = corpus.createSubcorpus(d
115
									.getStructuralUnit(), d
116
									.getStructuralUnitProperty(),
117
									d.getValues(), d.getName());
118

  
119
						}
120
						
121
						if(subcorpus == null)
122
						{
123
							monitor.done();
124
							System.out.println(Messages.CreateSubCorpus_0);
125
							return Status.CANCEL_STATUS;
126
						}
127
						
128
						System.out.println(NLS.bind(Messages.CreateSubcorpus_8
129
								, subcorpus.getName()));
130
						monitor.worked(50);
131

  
132
						monitor.subTask(Messages.RefreshingCorporaView);
133
						syncExec(new Runnable() {
134
							@Override
135
							public void run() {
136
								CorporaView.refresh();
137
								//System.out.println("expand");
138
								CorporaView.expand(subcorpus.getParent());
139
							}
140
						});
141

  
142
						monitor.worked(100);
143
					} catch (ThreadDeath td) {
144
						return Status.CANCEL_STATUS;
145
					} catch (CqiClientException e) {
146
						org.txm.rcp.utils.Logger.printStackTrace(e);
147
						Log.severe(e.toString());
148
						
149
						try {
150
							System.out.println(Messages.LastCQPError+CQPEngine.getCqiClient().getLastCQPError());
151
						} catch (Exception e1) {
152
							System.out.println(Messages.CreateSubCorpus_2+e1);
153
							org.txm.rcp.utils.Logger.printStackTrace(e1);
154
						}
155
					} finally {
156
						monitor.done();
157
						JobsTimer.stopAndPrint();
158
					}				
159
					return Status.OK_STATUS;
160
				}
161
			};
162
			jobhandler.startJob();
163
		}
164
		return null;
165
	}
166

  
167
}
0 168

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

  
30
import org.eclipse.core.commands.AbstractHandler;
31
import org.eclipse.core.commands.ExecutionEvent;
32
import org.eclipse.core.commands.ExecutionException;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.Status;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.window.Window;
38
import org.eclipse.osgi.util.NLS;
39
import org.eclipse.swt.widgets.Shell;
40
import org.eclipse.ui.IWorkbenchWindow;
41
import org.eclipse.ui.handlers.HandlerUtil;
42
import org.txm.rcp.JobsTimer;
43
import org.txm.rcp.Messages;
44
import org.txm.rcp.actions.CreatePartitionDialog;
45
import org.txm.rcp.utils.JobHandler;
46
import org.txm.rcp.views.corpora.CorporaView;
47
import org.txm.searchengine.cqp.corpus.Corpus;
48
import org.txm.searchengine.cqp.corpus.Partition;
49

  
50
// TODO: Auto-generated Javadoc
51
/**
52
 * Command which creates a Partition from a Corpus @ author mdecorde.
53
 */
54
public class CreatePartition extends AbstractHandler {
55

  
56
	/** The window. */
57
	private IWorkbenchWindow window;
58

  
59
	/** The selection. */
60
	private IStructuredSelection selection;
61

  
62
	/*
63
	 * (non-Javadoc)
64
	 * 
65
	 * @see
66
	 * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
67
	 * .ExecutionEvent)
68
	 */
69
	@Override
70
	public Object execute(ExecutionEvent event) throws ExecutionException {
71
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
72

  
73
		final Corpus corpus = (Corpus) selection.getFirstElement();
74
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
75
				.getShell();
76
		final CreatePartitionDialog d = new CreatePartitionDialog(shell, corpus);
77
		int code = d.open();
78
		if (code == Window.OK) {
79
			try {
80
				JobHandler jobhandler = new JobHandler(NLS.bind(
81
						Messages.CreatePartition_0, corpus.getName())) {
82
					@Override
83
					protected IStatus run(IProgressMonitor monitor) {
84
						this.runInit(monitor);
85
						try {
86
							JobsTimer.start();
87
							monitor.beginTask(
88
									NLS.bind(Messages.CreatePartition_0,
89
											corpus.getName()), 100);
90
							System.out.println(NLS.bind(
91
									Messages.CreatePartition_0,
92
									corpus.getName()));
93
							final Partition partition = d.getPartition();
94
							if (partition == null) {
95
								monitor.done();
96
								System.out.println(Messages.CreatePartition_2);
97
								return Status.CANCEL_STATUS;
98
							}
99
							System.out.println(NLS.bind(
100
									Messages.CreatePartition_6,
101
									partition.getNPart()));
102
							monitor.worked(95);
103

  
104
							monitor.subTask(Messages.RefreshingCorporaView);
105
							syncExec(new Runnable() {
106
								@Override
107
								public void run() {
108
									CorporaView.refresh();
109
									CorporaView.expand(partition.getParent());
110
								}
111
							});
112
							monitor.worked(100);
113
						} catch (ThreadDeath td) {
114
							return Status.CANCEL_STATUS;
115
						} finally {
116
							monitor.done();
117
							JobsTimer.stopAndPrint();
118
						}
119
						return Status.OK_STATUS;
120
					}
121
				};
122
				jobhandler.startJob();
123

  
124
			} catch (Exception e) {
125
				System.err.println(NLS.bind(Messages.Error_creating_partition,
126
						e));
127
			}
128
		}
129
		return null;
130
	}
131
}
0 132

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

  
30
import java.io.File;
31

  
32
import org.eclipse.core.commands.AbstractHandler;
33
import org.eclipse.core.commands.ExecutionEvent;
34
import org.eclipse.core.commands.ExecutionException;
35
import org.eclipse.core.runtime.IProgressMonitor;
36
import org.eclipse.core.runtime.IStatus;
37
import org.eclipse.core.runtime.Status;
38
import org.eclipse.jface.dialogs.MessageDialog;
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.Toolbox;
46
import org.txm.core.preferences.TBXPreferences;
47
import org.txm.rcp.Messages;
48
import org.txm.rcp.swt.dialog.LastOpened;
49
import org.txm.rcp.utils.JobHandler;
50
import org.txm.searchengine.cqp.corpus.MainCorpus;
51

  
52
// TODO: Auto-generated Javadoc
53
/**
54
 * Call the function Information on a MainCorpus, a SubCorpus and a Partition
55
 * show basic stats and give some properties values @ author mdecorde.
56
 */
57
public class ExportCorpus extends AbstractHandler {
58

  
59
	public final static String ID = "org.txm.rcp.commands.base.ExportCorpus"; //$NON-NLS-1$
60
	/** The selection. */
61
	private IStructuredSelection selection;
62

  
63
	/** The lastopenedfile. */
64
	private static String lastopenedfile;
65

  
66
	/*
67
	 * (non-Javadoc)
68
	 * 
69
	 * @see
70
	 * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
71
	 * .ExecutionEvent)
72
	 */
73
	@Override
74
	public Object execute(ExecutionEvent event) throws ExecutionException {
75
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
76

  
77
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
78
				.getShell();
79

  
80
		String txmhome = Toolbox.getParam(TBXPreferences.USER_TXM_HOME);
81
		if (!(selection.getFirstElement() instanceof MainCorpus))
82
			return null;
83

  
84
		final MainCorpus corpus = (MainCorpus) selection.getFirstElement();
85

  
86
		if (corpus.isModified()) {
87
			boolean ret = MessageDialog.openConfirm(shell, "Export - "+corpus.getName()+" annotations not saved", "Do you wish to export without the current annotations?\n\n(to include the current annotations in the exported corpus, you need to save them before calling the \"Export\" command)");
88
			if (!ret) return null;
89
		}
90
		
91
		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
92
		String[] exts = {"*.txm", "*.zip"}; //$NON-NLS-1$ //$NON-NLS-2$
93
		dialog.setFilterExtensions(exts);
94
		if (LastOpened.getFile(ID) != null) {
95
			lastopenedfile = LastOpened.getFolder(ID)
96
					+ "/" + LastOpened.getFile(ID); //$NON-NLS-1$
97
		} else if (lastopenedfile != null) {
98
			dialog.setFilterPath(new File(lastopenedfile).getAbsolutePath());
99
		} else {
100
			dialog.setFilterPath(txmhome + "/samples"); //$NON-NLS-1$
101
		}
102

  
103
		dialog.setFileName(corpus.getName()+".txm");
104
		
105
		if (dialog.open() != null) {
106
			String filepath = dialog.getFilterPath()
107
					+ "/" + dialog.getFileName(); //$NON-NLS-1$
108
			if (!(filepath.endsWith(".txm") || filepath.endsWith(".zip"))) { //$NON-NLS-1$ //$NON-NLS-2$
109
				filepath += ".txm"; //$NON-NLS-1$
110
			}
111
			LastOpened.set(ID, dialog.getFilterPath(), dialog.getFileName());
112
			lastopenedfile = filepath;
113
			final File outfile = new File(filepath);
114
			JobHandler jobhandler = new JobHandler(NLS.bind(
115
					Messages.ExportCorpus_3, corpus.getName())) {
116
				@Override
117
				protected IStatus run(IProgressMonitor monitor) {
118
					this.runInit(monitor);
119
					try {
120
						monitor.beginTask(
121
								NLS.bind(Messages.ExportCorpus_3,
122
										corpus.getName()), 100);
123
						
124

  
125
						if (!corpus.export(outfile, this)) {
126
							System.out.println(NLS.bind(
127
									Messages.ExportCorpus_0, corpus.getName()));
128
						}
129

  
130
						System.out.println(Messages.bind(Messages.ExportCorpus_4,outfile.getAbsolutePath()));
131
						monitor.worked(100);
132
					} catch (ThreadDeath td) {
133
						return Status.CANCEL_STATUS;
134
					} finally {
135
						monitor.done();
136
					}
137
					return Status.OK_STATUS;
138
				}
139
			};
140
			jobhandler.startJob();
141
		}
142

  
143
		return null;
144
	}
145
}
0 146

  
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/rcp/commands/base/package.html (revision 505)
1
<html>
2
<body>
3
	<p>Commands which deals with the CWB corpora view</p>
4
</body>
5
</html>
0 6

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

  
30
import java.util.ArrayList;
31

  
32
import org.eclipse.core.commands.AbstractHandler;
33
import org.eclipse.core.commands.ExecutionEvent;
34
import org.eclipse.core.commands.ExecutionException;
35
import org.eclipse.jface.viewers.IStructuredSelection;
36
import org.eclipse.jface.window.Window;
37
import org.eclipse.osgi.util.NLS;
38
import org.eclipse.swt.widgets.Shell;
39
import org.eclipse.ui.handlers.HandlerUtil;
40
import org.txm.objects.Text;
41
import org.txm.rcp.Messages;
42
import org.txm.rcp.commands.OpenBrowser;
43
import org.txm.rcp.editors.TXMBrowser;
44
import org.txm.rcp.swt.dialog.ComboDialog;
45
import org.txm.searchengine.cqp.corpus.Corpus;
46
/**
47
 * Open a text edition from: a main corpus : the first text of the maincorpus a
48
 * sub-corpus : the first text of the subcorpus a partition : the user must
49
 * choose one of the text used in the partition
50
 * 
51
 * note: unplugged for now
52
 *  
53
 * @author mdecorde.
54
 */
55
public class OpenBiblio extends AbstractHandler {
56

  
57
	/** The Constant ID. */
58
	public final static String ID = "org.txm.rcp.commands.base.OpenBiblio"; //$NON-NLS-1$
59

  
60
	/** The lastopenedfile. */
61
	public static String lastopenedfile;
62

  
63
	/** The textids. */
64
	private ArrayList<String> textids;
65

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

  
72
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
73

  
74
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
75

  
76
		if (selection.getFirstElement() instanceof Corpus) {
77
			Corpus corpus = (Corpus) selection.getFirstElement();
78

  
79
			textids = new ArrayList<String>(corpus.getTextsID());
80
			if (textids.size() == 0)
81
			{
82
				System.out.println(NLS.bind(Messages.OpenBiblio_1, corpus.getName()));
83
				return null;
84
			}
85

  
86
			ComboDialog dialog = new ComboDialog(shell, Messages.OpenBiblio_2, textids, textids.get(0));
87
			if (dialog.open() == Window.OK)
88
			{
89
				String textid = dialog.getSelectedValue();
90
				openBiblio(corpus, textid);
91
			}
92
		}
93
		else if (selection.getFirstElement() instanceof Text)
94
		{
95
			Text text = (Text) selection.getFirstElement();
96
			openBiblio(text);
97
		}
98
		return null;
99
	}
100

  
101
	/**
102
	 * Open biblio.
103
	 *
104
	 * @param base the base
105
	 * @param textid the textid
106
	 * @return the object
107
	 */
108
	public Object openBiblio(Corpus corpus, String textid ) {
109

  
110
		Text text = corpus.getMainCorpus().getText(textid);
111
		if (text == null) {
112
			System.out.println(NLS.bind(Messages.OpenBiblio_7, textid, corpus.getName()));
113
			return null;
114
		}
115

  
116
		return openBiblio(text);
117
	}
118

  
119
	/**
120
	 * Open biblio.
121
	 *
122
	 * @param text the text
123
	 * @return the object
124
	 */
125
	public Object openBiblio(Text text) {
126

  
127
		if (text == null)
128
		{
129
			return null;
130
		}
131
		if (text.getBiblioPath() == null) {
132
			System.out.println(NLS.bind(Messages.OpenBiblio_9, text.getName()));
133
			return null;
134
		}
135
		String url = text.getBiblioPath().toString();
136
		if (url.trim().length() == 0) {
137
			System.out.println(NLS.bind(Messages.OpenBiblio_9, text.getName()));
138
			return null;
139
		}
140
		TXMBrowser attachedBrowserEditor = OpenBrowser.openEdition(url);
141
		//attachedBrowserEditor.setCorpus(text.getCorpus());
142
		return null;
143
	}
144

  
145
}
0 146

  

Also available in: Unified diff