Révision 126
tmp/org.txm.textsbalance.rcp/.project (revision 126) | ||
---|---|---|
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 126) | ||
---|---|---|
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 126) | ||
---|---|---|
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.Composite; |
|
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 |
import org.txm.textsbalance.rcp.adapters.TextsBalanceAdapterFactory; |
|
41 |
|
|
42 |
/** |
|
43 |
* Texts balance preference page. |
|
44 |
* @author sjacquot |
|
45 |
* |
|
46 |
*/ |
|
47 |
public class TextsBalancePreferencePage extends TXMPreferencePage { |
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
@Override |
|
52 |
public void createFieldEditors() { |
|
53 |
|
|
54 |
|
|
55 |
// Charts rendering |
|
56 |
Composite chartsTab = SWTChartsComponentsProvider.createChartsRenderingPreferencesTabFolderComposite(this.getFieldEditorParent()); |
|
57 |
|
|
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 |
String[][] methods = new String[2][2]; |
|
67 |
for(int i = 0; i < 2; i++) { |
|
68 |
methods[i][0] = String.valueOf(i + 1); |
|
69 |
methods[i][1] = String.valueOf(i + 1); |
|
70 |
} |
|
71 |
|
|
72 |
this.addField(new ComboFieldEditor(TextsBalancePreferences.METHOD, "Method", methods, chartsTab)); |
|
73 |
this.addField(new BooleanFieldEditor(TextsBalancePreferences.GROUP_BY_WORDS, "Group by words", chartsTab)); |
|
74 |
|
|
75 |
// other shared preferences |
|
76 |
SWTChartsComponentsProvider.createChartsRenderingPreferencesFields(this, chartsTab); |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
/* |
|
83 |
* (non-Javadoc) |
|
84 |
* |
|
85 |
* @see |
|
86 |
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) |
|
87 |
*/ |
|
88 |
@Override |
|
89 |
public void init(IWorkbench workbench) { |
|
90 |
this.setPreferenceStore(new TXMPreferenceStore(TextsBalancePreferences.PREFERENCES_NODE)); |
|
91 |
this.setDescription("Texts balance charts."); |
|
92 |
this.setImageDescriptor(TextsBalanceAdapterFactory.ICON); |
|
93 |
} |
|
94 |
|
|
95 |
} |
|
0 | 96 |
tmp/org.txm.textsbalance.rcp/src/org/txm/textsbalance/rcp/adapters/TextsBalanceAdapterFactory.java (revision 126) | ||
---|---|---|
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 TextsBalanceAdapterFactory extends BaseAdapterFactory { |
|
19 |
|
|
20 |
|
|
21 |
public static final ImageDescriptor ICON = |
|
22 |
AbstractUIPlugin.imageDescriptorFromPlugin(FrameworkUtil.getBundle(TextsBalanceAdapterFactory.class).getSymbolicName(), |
|
23 |
"platform:/plugin/"+ FrameworkUtil.getBundle(TextsBalanceAdapterFactory.class).getSymbolicName() + "/icons/balance.png"); //$NON-NLS-1$ |
|
24 |
|
|
25 |
|
|
26 |
/** |
|
27 |
* Gets the adapter. |
|
28 |
* |
|
29 |
* @param adaptableObject the adaptable object |
|
30 |
* @param adapterType the adapter type |
|
31 |
* @return the adapter |
|
32 |
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) |
|
33 |
*/ |
|
34 |
@Override |
|
35 |
public Object getAdapter(Object adaptableObject, Class adapterType) { |
|
36 |
|
|
37 |
if(adapterType == IWorkbenchAdapter.class) { |
|
38 |
if(adaptableObject instanceof TextsBalance) { |
|
39 |
return new IWorkbenchAdapter() { |
|
40 |
@Override |
|
41 |
public Object[] getChildren(Object resultData) { |
|
42 |
return new Object[0]; |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
47 |
return ICON; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public String getLabel(Object resultData) { |
|
52 |
return ((TextsBalance) resultData).getName(); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public Object getParent(Object resultData) { |
|
57 |
return ((TextsBalance) resultData).getCorpus(); |
|
58 |
} |
|
59 |
}; |
|
60 |
} |
|
61 |
} |
|
62 |
return null; |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
} |
|
0 | 67 |
tmp/org.txm.textsbalance.rcp/src/org/txm/textsbalance/rcp/editors/BalanceEditor.java (revision 126) | ||
---|---|---|
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.core.preferences.TXMPreferences; |
|
24 |
import org.txm.rcpapplication.views.CorporaView; |
|
25 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
26 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
27 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
28 |
import org.txm.searchengine.cqp.corpus.query.Match; |
|
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 126) | ||
---|---|---|
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 126) | ||
---|---|---|
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 126) | ||
---|---|---|
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 |
id="ComputeBalance" |
|
19 |
name="Texts balance"> |
|
20 |
<commandParameter |
|
21 |
id="TextsBalance.createNewEditor" |
|
22 |
name="%commandParameter.name" |
|
23 |
optional="true"> |
|
24 |
</commandParameter> |
|
25 |
</command> |
|
26 |
</extension> |
|
27 |
<extension |
|
28 |
point="org.eclipse.ui.menus"> |
|
29 |
<menuContribution |
|
30 |
allPopups="false" |
|
31 |
locationURI="toolbar:org.txm.rcpapplication.toolbartools"> |
|
32 |
<command |
|
33 |
commandId="ComputeBalance" |
|
34 |
icon="icons/balance.png" |
|
35 |
style="push"> |
|
36 |
<visibleWhen |
|
37 |
checkEnabled="false"> |
|
38 |
<reference |
|
39 |
definitionId="OneCorpusSelected"> |
|
40 |
</reference> |
|
41 |
</visibleWhen> |
|
42 |
</command> |
|
43 |
</menuContribution> |
|
44 |
<menuContribution |
|
45 |
allPopups="false" |
|
46 |
locationURI="popup:org.txm.rcpapplication.views.CorporaView"> |
|
47 |
<command |
|
48 |
commandId="ComputeBalance" |
|
49 |
icon="icons/balance.png" |
|
50 |
style="push"> |
|
51 |
<visibleWhen |
|
52 |
checkEnabled="false"> |
|
53 |
<reference |
|
54 |
definitionId="OneCorpusSelected"> |
|
55 |
</reference> |
|
56 |
</visibleWhen> |
|
57 |
</command> |
|
58 |
</menuContribution> |
|
59 |
<menuContribution |
|
60 |
locationURI="menu:menu.tools"> |
|
61 |
<command |
|
62 |
commandId="ComputeBalance" |
|
63 |
icon="icons/balance.png" |
|
64 |
style="push"> |
|
65 |
<visibleWhen |
|
66 |
checkEnabled="false"> |
|
67 |
<reference |
|
68 |
definitionId="OneCorpusSelected"> |
|
69 |
</reference> |
|
70 |
</visibleWhen> |
|
71 |
</command> |
|
72 |
</menuContribution> |
|
73 |
</extension> |
|
74 |
<extension |
|
75 |
point="org.eclipse.core.expressions.definitions"> |
|
76 |
<definition |
|
77 |
id="InstanceOfBalanceEditor"> |
|
78 |
<with |
|
79 |
variable="activeEditor"> |
|
80 |
<instanceof |
|
81 |
value="org.txm.textsbalance.rcp.editors.BalanceEditor"> |
|
82 |
</instanceof> |
|
83 |
</with> |
|
84 |
</definition> |
|
85 |
</extension> |
|
86 |
<extension |
|
87 |
point="org.eclipse.ui.preferencePages"> |
|
88 |
<page |
|
89 |
category="org.txm.rcpapplication.preferences.UserPreferencePage" |
|
90 |
class="org.txm.textsbalance.rcp.preferences.TextsBalancePreferencePage" |
|
91 |
id="org.txm.rcp.textsbalance.preferences.TextsBalancePreferencePage" |
|
92 |
name="Texts balance"> |
|
93 |
</page> |
|
94 |
</extension> |
|
95 |
<extension |
|
96 |
point="org.eclipse.core.runtime.adapters"> |
|
97 |
<factory |
|
98 |
adaptableType="org.txm.textsbalance.core.functions.TextsBalance" |
|
99 |
class="org.txm.textsbalance.rcp.adapters.TextsBalanceAdapterFactory"> |
|
100 |
<adapter |
|
101 |
type="org.eclipse.ui.model.IWorkbenchAdapter"> |
|
102 |
</adapter> |
|
103 |
</factory> |
|
104 |
</extension> |
|
105 |
|
|
106 |
</plugin> |
|
0 | 107 |
tmp/org.txm.textsbalance.rcp/.settings/org.eclipse.jdt.core.prefs (revision 126) | ||
---|---|---|
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 |
tmp/org.txm.textsbalance.rcp/.classpath (revision 126) | ||
---|---|---|
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 126) | ||
---|---|---|
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.rcp;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.core;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 |
Formats disponibles : Unified diff