Révision 27

tmp/org.txm.textsbalance.rcp/.classpath (revision 27)
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.7"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
5
		<accessrules>
6
			<accessrule kind="accessible" pattern="**"/>
7
		</accessrules>
8
	</classpathentry>
9
	<classpathentry kind="src" path="src"/>
10
	<classpathentry kind="output" path="bin"/>
11
</classpath>
0 12

  
tmp/org.txm.textsbalance.rcp/META-INF/MANIFEST.MF (revision 27)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Texts Balance RCP
4
Bundle-SymbolicName: org.txm.textsbalance.rcp;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-Vendor: TXM
7
Require-Bundle: org.txm.rcpapplication;bundle-version="0.7.7",
8
 org.eclipse.core.runtime;bundle-version="3.10.0",
9
 org.eclipse.ui;bundle-version="3.106.1",
10
 org.eclipse.jface.text,
11
 org.eclipse.ui.editors,
12
 org.txm.toolbox;bundle-version="0.7.0",
13
 org.txm.chartsengine.r.core,
14
 org.eclipse.core.expressions;bundle-version="3.4.600",
15
 org.txm.textsbalance.core;bundle-version="1.0.0",
16
 org.txm.chartsengine.jfreechart.core;bundle-version="1.0.0",
17
 org.txm.chartsengine.rcp;bundle-version="1.0.0"
18
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
19
Export-Package: org.txm.textsbalance.rcp.adapters,
20
 org.txm.textsbalance.rcp.editors,
21
 org.txm.textsbalance.rcp.handlers,
22
 org.txm.textsbalance.rcp.preferences
0 23

  
tmp/org.txm.textsbalance.rcp/.project (revision 27)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.textsbalance.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.textsbalance.rcp/src/org/txm/textsbalance/rcp/handlers/ComputeBalance.java (revision 27)
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.textsbalance.rcp.handlers;
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.jface.viewers.ISelection;
34
import org.eclipse.jface.viewers.IStructuredSelection;
35
import org.eclipse.ui.handlers.HandlerUtil;
36
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider;
37
import org.txm.rcpapplication.Application;
38
import org.txm.rcpapplication.views.CorporaView;
39
import org.txm.searchengine.cqp.corpus.Corpus;
40
import org.txm.textsbalance.core.functions.TextsBalance;
41
import org.txm.textsbalance.rcp.editors.BalanceEditorInput;
42

  
43
/**
44
 * Computes and opens a texts balance editor.
45
 * 
46
 * @author mdecorde
47
 * @author sjacquot
48
 * 
49
 */
50
public class ComputeBalance extends AbstractHandler {
51

  
52

  
53
	
54
	// FIXME: should be put in an Activator? or better in an extension point loaded by the corpora view?
55
	// adds a double click listener to the Corpus View
56
	static	{
57
		CorporaView.addDoubleClickListener(TextsBalance.class, "ComputeBalance"); //$NON-NLS-1$
58
	}
59
	
60
	
61

  
62
	@Override
63
	public Object execute(ExecutionEvent event) throws ExecutionException {
64

  
65
		
66
		ISelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
67
		if(!(sel instanceof IStructuredSelection)) {
68
			return null;
69
		}
70
		IStructuredSelection selection = (IStructuredSelection) sel;
71

  
72
		Object selectedObject = selection.getFirstElement();
73

  
74
		TextsBalance balance = null;
75
		boolean newResult = false;
76
		
77
		// creates new result
78
		if(selectedObject instanceof Corpus) {
79
			balance = new TextsBalance((Corpus) selectedObject);
80
			newResult = true;
81
		}
82
		// opens existing result
83
		else if(selectedObject instanceof TextsBalance) {
84
			balance = (TextsBalance) selectedObject;
85
		}
86
		
87
		if(balance != null)	{
88
			BalanceEditorInput editorInput = new BalanceEditorInput(balance);
89
			SWTChartsComponentsProvider.getCurrent().openEditor(editorInput);
90

  
91
			if(newResult)	{
92
				CorporaView.storeResult(balance.getCorpus(), balance);
93
			}
94
		}
95
		else	{
96
			System.err.println("Cannot open Balance editor with " + selectedObject);
97
		}
98
		
99

  
100

  
101
		// FIXME: test d'utilisation de la même commande pour la création d'un nouvel éditeur et pour la mise à jour d'un graphique, avec une commande paramétrée (voir plugin.xml)
102
//		if(event.getParameter("TextsBalance.createNewEditor") == null)	{
103
//			ISelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
104
//			if (!(sel instanceof IStructuredSelection)) return null;
105
//			selection = (IStructuredSelection) sel;
106
//	
107
//			Object s = selection.getFirstElement();
108
//			if (s instanceof Corpus) {
109
//				Corpus corpus = (Corpus) s;
110
//				if (!openEditor(corpus)) {
111
//					System.out.println("Cannot open Balance editor with "+s);
112
//				}
113
//			}
114
//		}
115
//		else	{
116
//			//System.out.println("ComputeBalance.execute() " + ((Event)event.getTrigger()).widget);
117
//			((BalanceEditor)((ChartEditorToolBar)((ToolItem)((Event)event.getTrigger()).widget).getParent()).getEditorPart()).compute();
118
//			((BalanceEditor)((ChartEditorToolBar)((ToolItem)((Event)event.getTrigger()).widget).getParent()).getEditorPart()).reloadChart();
119
//			
120
//		}
121
		
122
		
123
		
124
		return null;
125
	}
126

  
127

  
128

  
129

  
130
}
0 131

  
tmp/org.txm.textsbalance.rcp/src/org/txm/textsbalance/rcp/preferences/TextsBalancePreferencePage.java (revision 27)
1
package org.txm.textsbalance.rcp.preferences;
2

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

  
31

  
32
import org.eclipse.jface.preference.BooleanFieldEditor;
33
import org.eclipse.jface.preference.ComboFieldEditor;
34
import org.eclipse.swt.widgets.Group;
35
import org.eclipse.ui.IWorkbench;
36
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider;
37
import org.txm.rcp.preferences.TXMPreferencePage;
38
import org.txm.rcp.preferences.TXMPreferenceStore;
39
import org.txm.textsbalance.core.preferences.TextsBalancePreferences;
40

  
41
/**
42
 * Texts balance preference page.
43
 * @author sjacquot
44
 *
45
 */
46
public class TextsBalancePreferencePage extends TXMPreferencePage {
47

  
48

  
49
	/**
50
	 * 
51
	 */
52
	public TextsBalancePreferencePage() {
53
		super();
54
	}
55

  
56
	@Override
57
	public void createFieldEditors() {
58

  
59
		// FIXME: input text
60
//		IntegerFieldEditor method = new IntegerFieldEditor(TextsBalancePreferencesInitializer.METHOD, "Method", this.getFieldEditorParent());
61
//		method.setValidRange(1, 2);
62
//		method.setTextLimit(1);
63
//		method.getTextControl(getFieldEditorParent()).setToolTipText("Method (1: uses CQL to solve matches, 2 uses corpus struct indexes, 2 is faster!)");
64
//		this.addField(method);
65
		
66
		
67
		// Charts rendering
68
		Group chartsGroup = SWTChartsComponentsProvider.createChartsRenderingPreferencesGroup(this.getFieldEditorParent());
69

  
70
		String[][] methods = new String[2][2];
71
		for(int i = 0; i < 2; i++) {
72
			methods[i][0] = String.valueOf(i + 1);
73
			methods[i][1] = String.valueOf(i + 1);
74
		}
75

  
76
		this.addField(new ComboFieldEditor(TextsBalancePreferences.METHOD, "Method", methods, chartsGroup));
77
		this.addField(new BooleanFieldEditor(TextsBalancePreferences.GROUP_BY_WORDS, "Group by words", chartsGroup));
78
		
79
	}
80
	
81
	
82

  
83
	/**
84
	 * 
85
	 * @return
86
	 */
87
	public static TXMPreferenceStore getNewPreferenceStore()	{
88
		return new TXMPreferenceStore(TextsBalancePreferences.PREFERENCES_NODE);
89
	}
90

  
91
	/*
92
	 * (non-Javadoc)
93
	 * 
94
	 * @see
95
	 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
96
	 */
97
	@Override
98
	public void init(IWorkbench workbench) {
99
		this.setPreferenceStore(getNewPreferenceStore());
100
		this.setDescription("Texts balance charts.");
101
	}
102

  
103
}
0 104

  
tmp/org.txm.textsbalance.rcp/src/org/txm/textsbalance/rcp/adapters/AdapterFactory.java (revision 27)
1
// Copyright © 2010-2013 ENS de Lyon.
2
package org.txm.textsbalance.rcp.adapters;
3

  
4
import org.eclipse.jface.resource.ImageDescriptor;
5
import org.eclipse.ui.model.IWorkbenchAdapter;
6
import org.eclipse.ui.plugin.AbstractUIPlugin;
7
import org.osgi.framework.FrameworkUtil;
8
import org.txm.rcp.adapters.BaseAdapterFactory;
9
import org.txm.textsbalance.core.functions.TextsBalance;
10

  
11

  
12
/**
13
 * A factory for creating Adapter objects.
14
 *  
15
 * @author mdecorde
16
 * @author sjacquot
17
 */
18
public class AdapterFactory extends BaseAdapterFactory {
19

  
20
	
21
	/**
22
	 * Gets the adapter.
23
	 *
24
	 * @param adaptableObject the adaptable object
25
	 * @param adapterType the adapter type
26
	 * @return the adapter
27
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
28
	 */
29
	@Override
30
	public Object getAdapter(Object adaptableObject, Class adapterType) {
31
		
32
		if(adapterType == IWorkbenchAdapter.class)	{
33
			if(adaptableObject instanceof TextsBalance)	{
34
				return new IWorkbenchAdapter() {
35
					@Override
36
					public Object[] getChildren(Object resultData) {
37
						return new Object[0];
38
					}
39
	
40
					@Override
41
					public ImageDescriptor getImageDescriptor(Object object) {
42
						return AbstractUIPlugin.imageDescriptorFromPlugin(FrameworkUtil.getBundle(AdapterFactory.class).getSymbolicName(), "platform:/plugin/org.txm.textsbalance.rcp/icons/balance.png"); //$NON-NLS-1$
43
					}
44
	
45
					@Override
46
					public String getLabel(Object resultData) {
47
						return ((TextsBalance) resultData).getName();
48
					}
49
	
50
					@Override
51
					public Object getParent(Object resultData) {
52
						return ((TextsBalance) resultData).getCorpus();
53
					}
54
				};
55
			}
56
		}
57
		return null;
58
	}
59

  
60

  
61
}
0 62

  
tmp/org.txm.textsbalance.rcp/src/org/txm/textsbalance/rcp/editors/BalanceEditor.java (revision 27)
1
package org.txm.textsbalance.rcp.editors;
2

  
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6

  
7
import org.eclipse.core.runtime.IProgressMonitor;
8
import org.eclipse.core.runtime.IStatus;
9
import org.eclipse.core.runtime.Status;
10
import org.eclipse.core.runtime.jobs.Job;
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.events.SelectionEvent;
13
import org.eclipse.swt.events.SelectionListener;
14
import org.eclipse.swt.layout.RowLayout;
15
import org.eclipse.swt.widgets.Button;
16
import org.eclipse.swt.widgets.Combo;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Group;
19
import org.eclipse.ui.IEditorInput;
20
import org.eclipse.ui.IEditorSite;
21
import org.eclipse.ui.PartInitException;
22
import org.txm.chartsengine.rcp.editors.ChartEditorPart;
23
import org.txm.rcpapplication.views.CorporaView;
24
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
25
import org.txm.searchengine.cqp.corpus.StructuralUnit;
26
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
27
import org.txm.searchengine.cqp.corpus.query.Match;
28
import org.txm.tbx.preferences.TXMPreferences;
29
import org.txm.textsbalance.core.functions.TextsBalance;
30
import org.txm.textsbalance.core.preferences.TextsBalancePreferences;
31

  
32
/**
33
 * Texts balance editor.
34
 * 
35
 * @author mdecorde
36
 * @author sjacquot
37
 *
38
 */
39
public class BalanceEditor extends ChartEditorPart {
40

  
41
	private Combo supCombo;
42

  
43
	private Button groupByTexts;
44

  
45
	private Button groupByWords;
46

  
47
	private Combo suCombo;
48

  
49
	/**
50
	 * Structural unit properties to not display.
51
	 */
52
	protected String[] supsToSkip;
53
	
54
	
55
	/**
56
	 * 
57
	 */
58
	public BalanceEditor() {
59
		
60
		this.supsToSkip = new String[] {"id", "base", "project"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
61

  
62
	}
63

  
64
	
65
	@Override
66
	public void createPartControl(Composite parent) {
67
		super.createPartControl(parent);
68
		
69
		if (((TextsBalance)this.getResultData()).getCorpus() == null) {
70
			System.out.println("Error: no corpus");
71
			return;
72
		}
73

  
74
		Group group = new Group(this.getParametersGroup(), SWT.NONE);
75

  
76
		group.setText("Group by:");
77
		//group.setLayout(new RowLayout(SWT.VERTICAL));
78
		group.setLayout(new RowLayout());
79
		
80
//		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
81
//		gridData.horizontalSpan = 2;
82
//		gridData.verticalIndent = 10;
83
//		group.setLayoutData(gridData);
84

  
85
		
86
		groupByTexts = new Button(group, SWT.RADIO);
87
		groupByTexts.setText("text");
88
		groupByTexts.setSelection(!TXMPreferences.getBoolean(TextsBalancePreferences.PREFERENCES_NODE, this.getResultData(), TextsBalancePreferences.GROUP_BY_WORDS));	
89
		
90
		
91
		groupByWords = new Button(group, SWT.RADIO);
92
		groupByWords.setText("word");
93
		groupByWords.setSelection(!groupByTexts.getSelection());
94

  
95
		
96
		suCombo = new Combo(this.getParametersGroup(), SWT.READ_ONLY);
97
		supCombo = new Combo(this.getParametersGroup(), SWT.READ_ONLY);
98

  
99
		try {
100
			loadSU();
101
		}
102
		catch (CqiClientException e) {
103
			e.printStackTrace();
104
		}
105

  
106
		
107
		
108
		suCombo.addSelectionListener(new SelectionListener() {
109
			
110
			@Override
111
			public void widgetSelected(SelectionEvent e) {
112
				// persistence
113
				TXMPreferences.putLocalString(getResultData(), TextsBalancePreferences.STRUCTURAL_UNIT, suCombo.getText());
114
				TXMPreferences.putLocalInt(getResultData(), TextsBalancePreferences.STRUCTURAL_UNIT_PROPERTY_INDEX, 0);
115
				
116
				try {
117
					loadSUP(((TextsBalance)getResultData()).getCorpus().getStructuralUnit(suCombo.getText()));
118

  
119
					compute();
120
					loadChart();
121
				}
122
				catch(CqiClientException e1) {
123
					// TODO Auto-generated catch block
124
					e1.printStackTrace();
125
				}
126

  
127
			}
128
			
129
			@Override
130
			public void widgetDefaultSelected(SelectionEvent e) {
131
				// TODO Auto-generated method stub
132
				
133
			}
134
		});
135
		
136

  
137
		
138
		SelectionListener listener = new SelectionListener() {
139
			@Override
140
			public void widgetSelected(SelectionEvent e) {
141
				
142
			
143
				// persistence
144
				TXMPreferences.putLocalInt(getResultData(), TextsBalancePreferences.STRUCTURAL_UNIT_PROPERTY_INDEX, supCombo.getSelectionIndex());
145
				TXMPreferences.putLocalBoolean(getResultData(), TextsBalancePreferences.GROUP_BY_WORDS, !groupByTexts.getSelection());
146
				
147
				compute();
148
				loadChart();
149

  
150
			}
151

  
152
			@Override
153
			public void widgetDefaultSelected(SelectionEvent e) {
154
				
155
			}
156
		};
157
		
158
		supCombo.addSelectionListener(listener);
159
		groupByTexts.addSelectionListener(listener);
160
		groupByWords.addSelectionListener(listener);
161
		
162
		
163
		this.compute();
164
		
165
	}
166

  
167
	
168
	/**
169
	 * Computes the balance using local or default parameters.
170
	 */
171
	public void compute()	{
172
		try {
173
			
174
			String suName = TXMPreferences.getString(TextsBalancePreferences.PREFERENCES_NODE, (TextsBalance) getEditorInput().getResultData(), TextsBalancePreferences.STRUCTURAL_UNIT);
175

  
176
			// gets the structural unit property name
177
			String supName = null;
178
			int i = 0;
179
			for(StructuralUnitProperty p : ((TextsBalance) this.getResultData()).getCorpus().getStructuralUnit(suName).getOrderedProperties()) {
180
				if(Arrays.asList(this.supsToSkip).contains(p.getName()))	{ 
181
					continue;
182
				}
183
				if(i == TXMPreferences.getInt(TextsBalancePreferences.PREFERENCES_NODE, this.getResultData(), TextsBalancePreferences.STRUCTURAL_UNIT_PROPERTY_INDEX))	{
184
					supName = p.getName();
185
					break;
186
				}
187
				i++;
188
			}
189
			
190
			this.compute(TXMPreferences.getInt(TextsBalancePreferences.PREFERENCES_NODE, TextsBalancePreferences.METHOD),
191
					((TextsBalance) this.getResultData()).getCorpus().getStructuralUnit(suName), supName,
192
					!TXMPreferences.getBoolean(TextsBalancePreferences.PREFERENCES_NODE, this.getResultData(), TextsBalancePreferences.GROUP_BY_WORDS)
193
					);
194
			
195
			
196
		}
197
		catch(CqiClientException e) {
198
			// TODO Auto-generated catch block
199
			e.printStackTrace();
200
		}
201
	}
202
	
203
	
204
	/**
205
	 * 
206
	 * @param method 1: use CQL to solve matches, 2 uses corpus struct indexes, 2 is faster !
207
	 * @throws CqiClientException
208
	 */
209
	public void compute(final int method, final StructuralUnit su, final String propertyName, final boolean groupByTexts) {
210

  
211
		
212
		
213
		Job job = new Job("Compute Texts Balance") {
214

  
215
		    @Override
216
		    protected IStatus run(IProgressMonitor monitor) {
217

  
218
		    	// creating
219
				monitor.beginTask("Computing", IProgressMonitor.UNKNOWN);
220
				
221
				TextsBalance textsBalance = (TextsBalance)getResultData();
222
				try {
223
					textsBalance.compute(method, su, propertyName, groupByTexts);
224
				}
225
				catch(CqiClientException e) {
226
					// TODO Auto-generated catch block
227
					e.printStackTrace();
228
				}
229
				createChart();
230
				
231
				// cancel
232
				if(monitor.isCanceled())	{
233
					close();
234
					return Status.CANCEL_STATUS;
235
				}
236
				
237
				
238
				// loading
239
				monitor.setTaskName("Loading");
240
				loadChart();
241

  
242
				
243
				setPartName(textsBalance.getCorpus().getName() + " - " + textsBalance.getName());
244
				
245
				
246
				// FIXME: persistence test, saving local preferences/parameters to file
247
				//TextsBalancePreferences.flush((TextsBalance) getEditorInput().getResultData());
248

  
249
				// refreshes the view to update the node label
250
				getSite().getShell().getDisplay().syncExec(new Runnable() {
251
					@Override
252
					public void run() {
253
						CorporaView.refresh();
254
					}
255
				});
256

  
257
				
258
				// done
259
				monitor.done(); 
260
				return Status.OK_STATUS;
261
	    }
262

  
263
		};
264
		//job.setUser(true); // show progress bar, without that the progress is located to bottom right
265
		job.schedule();
266
	}
267

  
268
	
269
	
270
	/**
271
	 * Fills the SU combo box from the corpus.
272
	 * @throws CqiClientException
273
	 */
274
	private void loadSU() throws CqiClientException {
275
		
276
		String selectedSuName = TextsBalancePreferences.getString(TextsBalancePreferences.PREFERENCES_NODE, (TextsBalance) this.getResultData(), TextsBalancePreferences.STRUCTURAL_UNIT);
277
		int selectedIndex = 0;
278
		int i = 0;
279
		
280
		for (StructuralUnit p : ((TextsBalance) this.getResultData()).getCorpus().getOrderedStructuralUnits()) {
281
			if (p.getName().equals("txmcorpus"))	{ //$NON-NLS-1$
282
				continue;
283
			}
284
			suCombo.add(p.getName());
285
			if (selectedSuName.equals(p.getName()))	{
286
				selectedIndex = i;
287
			}
288
			i++;
289
		}
290
		suCombo.select(selectedIndex);
291
		loadSUP(((TextsBalance)this.getResultData()).getCorpus().getStructuralUnit(suCombo.getText()));
292
	}
293

  
294
	/**
295
	 * Fills the SUP combo box from the specified structural unit.
296
	 * @param su
297
	 * @throws CqiClientException
298
	 */
299
	private void loadSUP(StructuralUnit su) throws CqiClientException {
300
		supCombo.removeAll();
301
		for (StructuralUnitProperty p : su.getOrderedProperties()) {
302
			if (Arrays.asList(this.supsToSkip).contains(p.getName()))	{ 
303
				continue;
304
			}
305
			supCombo.add(p.getName());
306
		}
307
		if (supCombo.getItemCount() > 0) {
308
			supCombo.select(TextsBalancePreferences.getInt(TextsBalancePreferences.PREFERENCES_NODE, this.getResultData(), TextsBalancePreferences.STRUCTURAL_UNIT_PROPERTY_INDEX));
309
		}
310
	}
311
	
312
	/**
313
	 * 
314
	 * @param corpus
315
	 * @param structs
316
	 * @return
317
	 */
318
	public ArrayList<Integer> intersect(List<Match> corpus, List<Match> structs) {
319
		int ai=0, bi=0;
320
		ArrayList<Integer> result = new ArrayList<Integer>();
321

  
322
		while (ai < corpus.size() && bi < structs.size() ) {
323
			if (structs.get(bi).contains(corpus.get(ai))) { 
324
				result.add(bi);
325
				ai++; 
326
			} else if (corpus.get(ai).contains(structs.get(bi))) { 
327
				result.add(bi);
328
				bi++; 
329
			} else { 
330
				if (structs.get(bi).getStart() < corpus.get(ai).getStart()) {
331
					bi++;
332
				} else {
333
					ai++;	
334
				}
335
			} 
336
		}
337

  
338
		return result;
339
	}
340

  
341
	@Override
342
	public void doSave(IProgressMonitor monitor) {
343
		// Do the Save operation
344
	}
345

  
346
	@Override
347
	public void doSaveAs() {
348
		// Do the Save As operation
349
	}
350

  
351

  
352
	@Override
353
	public boolean isDirty() {
354
		return false;
355
	}
356

  
357
	@Override
358
	public boolean isSaveAsAllowed() {
359
		return false;
360
	}
361

  
362

  
363
}
0 364

  
tmp/org.txm.textsbalance.rcp/src/org/txm/textsbalance/rcp/editors/BalanceEditorInput.java (revision 27)
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.textsbalance.rcp.editors;
29

  
30
import org.eclipse.jface.resource.ImageDescriptor;
31
import org.eclipse.ui.IPersistableElement;
32
import org.txm.chartsengine.rcp.editors.ChartEditorInput;
33
import org.txm.searchengine.cqp.corpus.Corpus;
34
import org.txm.textsbalance.core.functions.TextsBalance;
35
import org.txm.textsbalance.core.preferences.TextsBalancePreferences;
36
/**
37
 * Editor input for TextBalance.
38
 *
39
 * @author mdecorde
40
 * @author sjacquot
41
 */
42
public class BalanceEditorInput extends ChartEditorInput {
43
	
44
	/** The corpus. */
45
	private Corpus corpus;
46
	
47
	/**
48
	 * Instantiates a new index editor input.
49
	 *
50
	 * @param corpus the corpus
51
	 */
52
	public BalanceEditorInput(TextsBalance textBalance) {
53
		super(textBalance, TextsBalancePreferences.PREFERENCES_NODE);
54
		this.corpus = textBalance.getCorpus();
55
	}
56

  
57
	/**
58
	 * Exists.
59
	 *
60
	 * @return true, if successful
61
	 * @see org.eclipse.ui.IEditorInput#exists()
62
	 */
63
	@Override
64
	public boolean exists() {
65
		return false;
66
	}
67

  
68
	/**
69
	 * Gets the image descriptor.
70
	 *
71
	 * @return the image descriptor
72
	 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
73
	 */
74
	@Override
75
	public ImageDescriptor getImageDescriptor() {
76
		return null;
77
	}
78

  
79
	/**
80
	 * Gets the persistable.
81
	 *
82
	 * @return the persistable
83
	 * @see org.eclipse.ui.IEditorInput#getPersistable()
84
	 */
85
	@Override
86
	public IPersistableElement getPersistable() {
87
		return null;
88
	}
89

  
90
	/**
91
	 * Gets the tool tip text.
92
	 *
93
	 * @return the tool tip text
94
	 * @see org.eclipse.ui.IEditorInput#getToolTipText()
95
	 */
96
	@Override
97
	public String getToolTipText() {
98
		return getName();
99
	}
100
	
101
	/**
102
	 * Gets the adapter.
103
	 *
104
	 * @param arg0 the arg0
105
	 * @return the adapter
106
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
107
	 */
108
	@Override
109
	@SuppressWarnings("unchecked") //$NON-NLS-1$
110
	public Object getAdapter(Class arg0) {
111
		return null;
112
	}
113

  
114
	/**
115
	 * Gets the corpus.
116
	 *
117
	 * @return the corpus
118
	 */
119
	public Corpus getCorpus() {
120
		return corpus;
121
	}
122

  
123

  
124
}
0 125

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

  
tmp/org.txm.textsbalance.rcp/plugin.xml (revision 27)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4

  
5
   <extension
6
         point="org.eclipse.ui.editors">
7
      <editor
8
            class="org.txm.textsbalance.rcp.editors.BalanceEditor"
9
            icon="icons/balance.png"
10
            id="org.txm.textsbalance.core.functions.TextsBalance"
11
            name="Texts Balance">
12
      </editor>
13
   </extension>
14
   <extension
15
         point="org.eclipse.ui.commands">
16
      <command
17
            defaultHandler="org.txm.textsbalance.rcp.handlers.ComputeBalance"
18
            description="Texts balance"
19
            id="ComputeBalance"
20
            name="Texts balance">
21
         <commandParameter
22
               id="TextsBalance.createNewEditor"
23
               name="%commandParameter.name"
24
               optional="true">
25
         </commandParameter>
26
      </command>
27
   </extension>
28
   <extension
29
         point="org.eclipse.ui.menus">
30
      <menuContribution
31
            allPopups="false"
32
            locationURI="toolbar:org.txm.rcpapplication.toolbartools">
33
         <command
34
               commandId="ComputeBalance"
35
               icon="icons/balance.png"
36
               label="Texts balance"
37
               style="push"
38
               tooltip="%command.tooltip">
39
            <visibleWhen
40
                  checkEnabled="false">
41
               <reference
42
                     definitionId="OneCorpusSelected">
43
               </reference>
44
            </visibleWhen>
45
         </command>
46
      </menuContribution>
47
      <menuContribution
48
            allPopups="false"
49
            locationURI="popup:org.txm.rcpapplication.views.CorporaView">
50
         <command
51
               commandId="ComputeBalance"
52
               icon="icons/balance.png"
53
               label="Texts balance"
54
               style="push"
55
               tooltip="%command.tooltip.0">
56
            <visibleWhen
57
                  checkEnabled="false">
58
               <reference
59
                     definitionId="OneCorpusSelected">
60
               </reference>
61
            </visibleWhen>
62
         </command>
63
      </menuContribution>
64
      <menuContribution
65
            locationURI="menu:menu.tools">
66
         <command
67
               commandId="ComputeBalance"
68
               icon="icons/balance.png"
69
               label="Texts balance"
70
               style="push"
71
               tooltip="%command.tooltip.1">
72
            <visibleWhen
73
                  checkEnabled="false">
74
               <reference
75
                     definitionId="OneCorpusSelected">
76
               </reference>
77
            </visibleWhen>
78
         </command>
79
      </menuContribution>
80
   </extension>
81
   <extension
82
         point="org.eclipse.core.expressions.definitions">
83
      <definition
84
            id="InstanceOfBalanceEditor">
85
         <with
86
               variable="activeEditor">
87
            <instanceof
88
                  value="org.txm.textsbalance.rcp.editors.BalanceEditor">
89
            </instanceof>
90
         </with>
91
      </definition>
92
   </extension>
93
   <extension
94
         point="org.eclipse.ui.preferencePages">
95
      <page
96
            category="org.txm.rcpapplication.preferences.UserPreferencePage"
97
            class="org.txm.textsbalance.rcp.preferences.TextsBalancePreferencePage"
98
            id="org.txm.rcp.textsbalance.preferences.TextsBalancePreferencePage"
99
            name="Texts balance">
100
      </page>
101
   </extension>
102
   <extension
103
         point="org.eclipse.core.runtime.adapters">
104
      <factory
105
            adaptableType="org.txm.textsbalance.core.functions.TextsBalance"
106
            class="org.txm.textsbalance.rcp.adapters.AdapterFactory">
107
         <adapter
108
               type="org.eclipse.ui.model.IWorkbenchAdapter">
109
         </adapter>
110
      </factory>
111
   </extension>
112

  
113
</plugin>
0 114

  
tmp/org.txm.textsbalance.rcp/.settings/org.eclipse.jdt.core.prefs (revision 27)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4
org.eclipse.jdt.core.compiler.compliance=1.7
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.7
0 8

  

Formats disponibles : Unified diff