Revision 204

tmp/org.txm.cooccurrence.rcp/build.properties (revision 204)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml
0 6

  
tmp/org.txm.cooccurrence.rcp/plugin.xml (revision 204)
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.txm.rcpapplication.category.txm"
8
            defaultHandler="org.txm.cooccurrence.rcp.handlers.ComputeCooccurrences"
9
            id="ComputeCooccurrences"
10
            name="%command.name.35">
11
      </command>
12
   </extension>
13
   <extension
14
         point="org.eclipse.ui.preferencePages">
15
      <page
16
            category="org.txm.rcpapplication.preferences.UserPreferencePage"
17
            class="org.txm.cooccurrence.rcp.preferences.CoocPreferencePage"
18
            id="org.txm.cooccurrence.rcp.preferences.CoocPreferencePage"
19
            name="%page.name.11">
20
      </page>
21
   </extension>
22
   <extension
23
         point="org.eclipse.core.runtime.adapters">
24
      <factory
25
            adaptableType="org.txm.functions.cooccurrence.Cooccurrence"
26
            class="org.txm.cooccurrence.rcp.adapters.CooccurrenceAdapterFactory">
27
         <adapter
28
               type="org.eclipse.ui.model.IWorkbenchAdapter">
29
         </adapter>
30
      </factory>
31
   </extension>
32
   <extension
33
         point="org.eclipse.ui.menus">
34
      <menuContribution
35
            allPopups="false"
36
            locationURI="popup:org.txm.rcpapplication.views.CorporaView">
37
         <command
38
               commandId="ComputeCooccurrences"
39
               icon="icons/cooccurrences.png"
40
               label="%command.label.96"
41
               style="push"
42
               tooltip="%command.tooltip.57">
43
            <visibleWhen
44
                  checkEnabled="false">
45
               <or>
46
                  <reference
47
                        definitionId="OneCorpusSelected">
48
                  </reference>
49
                  <reference
50
                        definitionId="OneConcordanceSelected">
51
                  </reference>
52
               </or>
53
            </visibleWhen>
54
         </command>
55
      </menuContribution>
56
      <menuContribution
57
            locationURI="menu:menu.tools">
58
         <command
59
               commandId="ComputeCooccurrences"
60
               icon="icons/cooccurrences.png"
61
               label="%command.label.91"
62
               style="push"
63
               tooltip="%command.tooltip.53">
64
            <visibleWhen
65
                  checkEnabled="false">
66
               <or>
67
                  <reference
68
                        definitionId="OneCorpusSelected">
69
                  </reference>
70
                  <reference
71
                        definitionId="OneConcordanceSelected">
72
                  </reference>
73
               </or>
74
            </visibleWhen>
75
         </command>
76
      </menuContribution>
77
      <menuContribution
78
            allPopups="false"
79
            locationURI="toolbar:org.txm.rcpapplication.toolbartools">
80
         <command
81
               commandId="ComputeCooccurrences"
82
               icon="icons/cooccurrences.png"
83
               label="%command.label.96"
84
               style="push"
85
               tooltip="%command.tooltip.57">
86
            <visibleWhen
87
                  checkEnabled="false">
88
               <or>
89
                  <reference
90
                        definitionId="OneCorpusSelected">
91
                  </reference>
92
                  <reference
93
                        definitionId="OneConcordanceSelected">
94
                  </reference>
95
               </or>
96
            </visibleWhen>
97
         </command>
98
      </menuContribution>
99
   </extension>
100
   <extension
101
         point="org.eclipse.ui.editors">
102
      <editor
103
            class="org.txm.cooccurrence.rcp.editors.CooccurrencesEditor"
104
            default="false"
105
            icon="icons/cooccurrences.png"
106
            id="CooccurrencesEditor"
107
            name="%editor.name.9">
108
      </editor>
109
   </extension>
110

  
111
</plugin>
0 112

  
tmp/org.txm.cooccurrence.rcp/.settings/org.eclipse.jdt.core.prefs (revision 204)
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.cooccurrence.rcp/.classpath (revision 204)
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.cooccurrence.rcp/META-INF/MANIFEST.MF (revision 204)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Cooccurence RCP
4
Bundle-SymbolicName: org.txm.cooccurrence.rcp;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
7
Export-Package: org.txm.cooccurrence.rcp.editors
8
Require-Bundle: org.txm.cooccurrence.core;bundle-version="1.0.0",
9
 org.eclipse.core.commands,
10
 org.txm.core,
11
 org.txm.rcp,
12
 org.eclipse.ui;bundle-version="3.106.1",
13
 org.eclipse.core.runtime;bundle-version="3.10.0"
0 14

  
tmp/org.txm.cooccurrence.rcp/.project (revision 204)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.cooccurrence.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.cooccurrence.rcp/src/org/txm/cooccurrence/rcp/handlers/ComputeCooccurrences.java (revision 204)
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.cooccurrence.rcp.handlers;
29

  
30
import java.util.ArrayList;
31
import java.util.List;
32

  
33
import org.eclipse.core.commands.AbstractHandler;
34
import org.eclipse.core.commands.ExecutionEvent;
35
import org.eclipse.core.commands.ExecutionException;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.ui.IWorkbenchPage;
38
import org.eclipse.ui.IWorkbenchWindow;
39
import org.eclipse.ui.handlers.HandlerUtil;
40
import org.txm.Toolbox;
41
import org.txm.cooccurrence.core.preferences.CooccurrencePreferences;
42
import org.txm.cooccurrence.rcp.editors.CooccurrenceEditorInput;
43
import org.txm.cooccurrence.rcp.editors.CooccurrencesEditor;
44
import org.txm.core.preferences.TXMPreferences;
45
import org.txm.functions.concordances.Concordance;
46
import org.txm.functions.cooccurrence.Cooccurrence;
47
import org.txm.rcpapplication.Messages;
48
import org.txm.rcpapplication.StatusLine;
49
import org.txm.rcpapplication.TXMWindows;
50
import org.txm.rcpapplication.views.CorporaView;
51
import org.txm.searchengine.cqp.corpus.Corpus;
52
import org.txm.searchengine.cqp.corpus.Property;
53
import org.txm.searchengine.cqp.corpus.StructuralUnit;
54
import org.txm.searchengine.cqp.corpus.query.Query;
55

  
56
// TODO: Auto-generated Javadoc
57
/**
58
 * if the selection is a corpus, open an empty Cooc editor if the selection is a
59
 * concordance, open a Cooc editor already computed @ author mdecorde.
60
 */
61
public class ComputeCooccurrences extends AbstractHandler {
62

  
63
	
64
	
65
	// adds a double click listener to the Corpus View
66
	static	{
67
		CorporaView.addDoubleClickListener(Cooccurrence.class, "ComputeCooccurrences"); //$NON-NLS-1$
68
	}
69
	
70
	
71
	
72
	
73
	/* (non-Javadoc)
74
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
75
	 */
76
	@Override
77
	public Object execute(ExecutionEvent event) throws ExecutionException {
78
		
79
		if (!Toolbox.isStatEngineInitialized()) {
80
			System.out.println(Messages.ComputeCooccurrences_2);
81
			return null;
82
		}
83

  
84
		
85
		if (!Toolbox.isSearchEngineInitialized()) return null;
86

  
87
		
88
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
89
		Object element = selection.getFirstElement();
90
		
91
		if (element instanceof Concordance) {
92
			Cooccurrence cooc = computeCooc(selection);
93
			if (cooc != null) {
94
				openEditor(cooc);
95
			}
96
		} else if (element instanceof Corpus) {
97
			openEditor((Corpus)element);
98
		} else {
99
			System.out.println(Messages.ComputeCooccurrences_1+ element);
100
		}
101
		
102
		return element;
103
	}
104

  
105
	/**
106
	 * 
107
	 * @param cooc
108
	 * @return
109
	 */
110
	public static CooccurrencesEditor openEditor(Cooccurrence cooc) {
111
		
112
		try {
113
			IWorkbenchWindow window =TXMWindows.getActiveWindow();
114
			IWorkbenchPage page = window.getActivePage();
115

  
116
			StatusLine.setMessage(Messages.ComputeCooccurrences_0);
117
			CooccurrenceEditorInput editorInput = new CooccurrenceEditorInput(cooc);
118

  
119
			CooccurrencesEditor conceditor = (CooccurrencesEditor) page.openEditor(editorInput, CooccurrencesEditor.ID); 
120
			return conceditor;
121
		} catch (Exception e) {
122
			org.txm.rcpapplication.utils.Logger.printStackTrace(e);
123
		}
124
		return null;
125
	}
126
	
127
	/**
128
	 * 
129
	 * @param corpus
130
	 * @return
131
	 */
132
	public static CooccurrencesEditor openEditor(Corpus corpus) {
133
		try {
134
			IWorkbenchWindow window =TXMWindows.getActiveWindow();
135
			IWorkbenchPage page = window.getActivePage();
136

  
137
			StatusLine.setMessage(Messages.ComputeCooccurrences_0);
138
			CooccurrenceEditorInput editorInput = new CooccurrenceEditorInput(corpus);
139

  
140
			CooccurrencesEditor conceditor = (CooccurrencesEditor) page.openEditor(editorInput, CooccurrencesEditor.ID); 
141
			return conceditor;
142
		} catch (Exception e) {
143
			org.txm.rcpapplication.utils.Logger.printStackTrace(e);
144
		}
145
		return null;
146
	}
147

  
148
	/**
149
	 * Compute cooc.
150
	 *
151
	 * @param selection the selection
152
	 * @return the cooccurrence
153
	 */
154
	public static Cooccurrence computeCooc(IStructuredSelection selection) {
155
		if (!Toolbox.isSearchEngineInitialized()) return null;
156
		
157
		Cooccurrence cooc = null;
158
		Object s = selection.getFirstElement();
159

  
160
		int minleft = 1;
161
		int maxleft = 50;
162
		int minright = 1;
163
		int maxright = 50;
164

  
165
		int minf = TXMPreferences.getInt(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MIN_FREQ);
166
		int mincof = TXMPreferences.getInt(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MIN_COUNT);
167
		int minscore = (int) TXMPreferences.getDouble(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MIN_SCORE);
168

  
169
		Corpus corpus = null;
170
		StructuralUnit limit = null;
171
		Query query = null;
172
		List<Property> properties = null;
173

  
174
		if (s instanceof Concordance) {
175
			Concordance conc = (Concordance) s;
176
			corpus = conc.getCorpus();
177
			maxleft = conc.getLeftContextSize();
178
			maxright = conc.getRightContextSize();
179
			properties = new ArrayList<Property>();
180
			properties.addAll(conc.getAnalysisProperty());
181
			query = conc.getQuery();
182
			
183
			boolean buildLexicalTableWithCooccurrents = TXMPreferences.getBoolean(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.PARTIAL_LEXICAL_TABLE);
184

  
185
			try {
186
				cooc = new Cooccurrence(corpus, query, properties, limit,
187
						maxleft, minleft, minright, maxright, minf, mincof,
188
						minscore, false, buildLexicalTableWithCooccurrents);
189

  
190
				cooc.process();
191
			} catch (Exception e) {
192
				// TODO Auto-generated catch block
193
				org.txm.rcpapplication.utils.Logger.printStackTrace(e);
194
				return null;
195
			}
196
		} else if (s instanceof Corpus) {
197
			corpus = (Corpus) s;
198
		} else {
199
			System.out.println(Messages.ComputeCooccurrences_1 + s);
200
			return null;
201
		}
202

  
203
		return cooc;
204
	}
205
}
0 206

  
tmp/org.txm.cooccurrence.rcp/src/org/txm/cooccurrence/rcp/preferences/CoocPreferencePage.java (revision 204)
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.cooccurrence.rcp.preferences;
29

  
30
import org.eclipse.jface.preference.BooleanFieldEditor;
31
import org.eclipse.jface.preference.IntegerFieldEditor;
32
import org.eclipse.jface.preference.StringFieldEditor;
33
import org.eclipse.ui.IWorkbench;
34
import org.txm.cooccurrence.core.preferences.CooccurrencePreferences;
35
import org.txm.cooccurrence.rcp.adapters.CooccurrenceAdapterFactory;
36
import org.txm.rcp.preferences.TXMPreferencePage;
37
import org.txm.rcp.preferences.TXMPreferenceStore;
38
import org.txm.rcpapplication.Messages;
39
import org.txm.rcpapplication.jface.DoubleFieldEditor;
40

  
41
/**
42
 * 
43
 * 
44
 * @author mdecorde
45
 * @author sjacquot
46
 *
47
 */
48
public class CoocPreferencePage extends TXMPreferencePage {
49

  
50

  
51
	@Override
52
	public void createFieldEditors() {
53

  
54
		/** The scoreformatfield. */
55
		StringFieldEditor scoreformatfield = new StringFieldEditor(CooccurrencePreferences.SCORE_FORMAT, Messages.CoocPreferencePage_0, getFieldEditorParent());
56
		scoreformatfield.setTextLimit(15);
57

  
58
		/** The minfreqfield. */
59
		IntegerFieldEditor minfreqfield = new IntegerFieldEditor(CooccurrencePreferences.MIN_FREQ, Messages.CoocPreferencePage_1, getFieldEditorParent());
60
		minfreqfield.setValidRange(0, 9999999);
61

  
62
		/** The mincountfield. */
63
		IntegerFieldEditor mincountfield = new IntegerFieldEditor(CooccurrencePreferences.MIN_COUNT, Messages.CoocPreferencePage_2, getFieldEditorParent());
64
		mincountfield.setValidRange(0, 9999999);
65

  
66
		/** The minscorefield. */
67
		DoubleFieldEditor minscorefield = new DoubleFieldEditor(CooccurrencePreferences.MIN_SCORE, Messages.CoocPreferencePage_3, getFieldEditorParent());
68
		minscorefield.setTextLimit(15);
69
		
70
		IntegerFieldEditor maxleftfield = new IntegerFieldEditor(CooccurrencePreferences.MAX_LEFT, Messages.CoocPreferencePage_4, getFieldEditorParent());
71
		maxleftfield.setValidRange(0, 99999);
72
		
73
		IntegerFieldEditor minleftfield = new IntegerFieldEditor(CooccurrencePreferences.MIN_LEFT, Messages.CoocPreferencePage_6, getFieldEditorParent());
74
		minleftfield.setValidRange(0, 99999);
75
		
76
		IntegerFieldEditor minrightfield = new IntegerFieldEditor(CooccurrencePreferences.MIN_RIGHT, Messages.CoocPreferencePage_11, getFieldEditorParent());
77
		minrightfield.setValidRange(0, 99999);
78
		
79
		IntegerFieldEditor maxrightfield = new IntegerFieldEditor(CooccurrencePreferences.MAX_RIGHT, Messages.CoocPreferencePage_12, getFieldEditorParent());
80
		maxrightfield.setValidRange(0, 99999);
81
		
82
		BooleanFieldEditor partiallexicaltablefield =  new BooleanFieldEditor(CooccurrencePreferences.PARTIAL_LEXICAL_TABLE, Messages.CoocPreferencePage_8, getFieldEditorParent());
83

  
84
		addField(scoreformatfield);
85
		addField(minfreqfield);
86
		addField(mincountfield);
87
		addField(minscorefield);
88
		addField(maxleftfield);
89
		addField(minleftfield);
90
		addField(minrightfield);
91
		addField(maxrightfield);
92
		addField(partiallexicaltablefield);
93
	}
94

  
95
	
96

  
97
	@Override
98
	public void init(IWorkbench workbench) {
99
		this.setPreferenceStore(new TXMPreferenceStore(CooccurrencePreferences.PREFERENCES_NODE));
100
		//setDescription("Cooccurrences");
101
		this.setTitle(Messages.CoocPreferencePage_5);
102
		this.setImageDescriptor(CooccurrenceAdapterFactory.ICON);
103
	}
104
	
105

  
106
}
0 107

  
tmp/org.txm.cooccurrence.rcp/src/org/txm/cooccurrence/rcp/adapters/CooccurrenceAdapterFactory.java (revision 204)
1
// Copyright © 2010-2013 ENS de Lyon.
2
package org.txm.cooccurrence.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.functions.cooccurrence.Cooccurrence;
9
import org.txm.rcp.adapters.BaseAdapterFactory;
10

  
11

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

  
20
	
21
	public static final ImageDescriptor ICON =
22
			AbstractUIPlugin.imageDescriptorFromPlugin(FrameworkUtil.getBundle(CooccurrenceAdapterFactory.class).getSymbolicName(),
23
					"platform:/plugin/"+ FrameworkUtil.getBundle(CooccurrenceAdapterFactory.class).getSymbolicName() + "/icons/cooccurrences.png"); //$NON-NLS-1$
24
	
25
	/**
26
	 * Gets the adapter.
27
	 *
28
	 * @param adaptableObject the adaptable object
29
	 * @param adapterType the adapter type
30
	 * @return the adapter
31
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
32
	 */
33
	@Override
34
	public Object getAdapter(Object adaptableObject, Class adapterType) {
35
		
36
		if(adapterType == IWorkbenchAdapter.class)	{
37
			if(adaptableObject instanceof Cooccurrence)	{
38
				return new IWorkbenchAdapter() {
39

  
40
					@Override
41
					public Object[] getChildren(Object cooccurrence) {
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 cooccurrence) {
52
						return ((Cooccurrence) cooccurrence).getName(); 
53
					}
54

  
55
					@Override
56
					public Object getParent(Object cooccurrence) {
57
						return ((Cooccurrence) cooccurrence).getCorpus();
58
					}
59
				};
60
			}
61
		}
62
		return null;
63
	}
64

  
65

  
66
}
0 67

  
tmp/org.txm.cooccurrence.rcp/src/org/txm/cooccurrence/rcp/editors/CooccurrencesEditor.java (revision 204)
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.cooccurrence.rcp.editors;
29

  
30
import java.lang.reflect.InvocationTargetException;
31
import java.util.ArrayList;
32
import java.util.List;
33

  
34
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.IStatus;
36
import org.eclipse.core.runtime.Status;
37
import org.eclipse.jface.action.MenuManager;
38
import org.eclipse.jface.operation.IRunnableWithProgress;
39
import org.eclipse.jface.viewers.IStructuredSelection;
40
import org.eclipse.jface.viewers.TableViewer;
41
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.custom.ScrolledComposite;
44
import org.eclipse.swt.events.ControlAdapter;
45
import org.eclipse.swt.events.ControlEvent;
46
import org.eclipse.swt.events.KeyEvent;
47
import org.eclipse.swt.events.KeyListener;
48
import org.eclipse.swt.events.MouseAdapter;
49
import org.eclipse.swt.events.MouseEvent;
50
import org.eclipse.swt.events.SelectionEvent;
51
import org.eclipse.swt.events.SelectionListener;
52
import org.eclipse.swt.graphics.Font;
53
import org.eclipse.swt.graphics.FontData;
54
import org.eclipse.swt.graphics.Image;
55
import org.eclipse.swt.graphics.Point;
56
import org.eclipse.swt.graphics.Rectangle;
57
import org.eclipse.swt.layout.FormAttachment;
58
import org.eclipse.swt.layout.FormData;
59
import org.eclipse.swt.layout.FormLayout;
60
import org.eclipse.swt.layout.GridData;
61
import org.eclipse.swt.layout.GridLayout;
62
import org.eclipse.swt.layout.RowLayout;
63
import org.eclipse.swt.widgets.Button;
64
import org.eclipse.swt.widgets.Composite;
65
import org.eclipse.swt.widgets.Display;
66
import org.eclipse.swt.widgets.Event;
67
import org.eclipse.swt.widgets.Label;
68
import org.eclipse.swt.widgets.Listener;
69
import org.eclipse.swt.widgets.Menu;
70
import org.eclipse.swt.widgets.Spinner;
71
import org.eclipse.swt.widgets.TableColumn;
72
import org.eclipse.swt.widgets.Text;
73
import org.eclipse.ui.IEditorInput;
74
import org.eclipse.ui.IEditorSite;
75
import org.eclipse.ui.PartInitException;
76
import org.eclipse.ui.PlatformUI;
77
import org.eclipse.ui.part.EditorPart;
78
import org.txm.Toolbox;
79
import org.txm.cooccurrence.core.preferences.CooccurrencePreferences;
80
import org.txm.core.preferences.TXMPreferences;
81
import org.txm.functions.cooccurrence.Cooccurrence;
82
import org.txm.functions.cooccurrence.comparators.CLineComparator;
83
import org.txm.functions.cooccurrence.comparators.DistComparator;
84
import org.txm.functions.cooccurrence.comparators.FreqComparator;
85
import org.txm.functions.cooccurrence.comparators.NbOccComparator;
86
import org.txm.functions.cooccurrence.comparators.OccComparator;
87
import org.txm.functions.cooccurrence.comparators.ReverseComparator;
88
import org.txm.functions.cooccurrence.comparators.ScoreComparator;
89
import org.txm.rcpapplication.JobsTimer;
90
import org.txm.rcpapplication.Messages;
91
import org.txm.rcpapplication.StatusLine;
92
import org.txm.rcpapplication.TxmPreferences;
93
import org.txm.rcpapplication.commands.editor.CustomizableEditor;
94
import org.txm.rcpapplication.commands.link.CooccurrencesToConcordances;
95
import org.txm.rcpapplication.editors.TableKeyListener;
96
import org.txm.rcpapplication.preferences.UserPreferencePage;
97
import org.txm.rcpapplication.swt.widget.AssistedQueryWidget;
98
import org.txm.rcpapplication.swt.widget.EmpantWidget;
99
import org.txm.rcpapplication.swt.widget.PropertiesSelector;
100
import org.txm.rcpapplication.utils.JobHandler;
101
import org.txm.rcpapplication.utils.Logger;
102
import org.txm.rcpapplication.views.CorporaView;
103
import org.txm.rcpapplication.views.QueriesView;
104
import org.txm.rcpapplication.views.RVariablesView;
105
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
106
import org.txm.searchengine.cqp.corpus.Corpus;
107
import org.txm.searchengine.cqp.corpus.Property;
108
import org.txm.searchengine.cqp.corpus.StructuralUnit;
109
import org.txm.searchengine.cqp.corpus.query.Query;
110
import org.txm.utils.logger.Log;
111

  
112
// TODO: Auto-generated Javadoc
113
/**
114
 * display the cooc parameters and result @ author mdecorde.
115
 */
116
public class CooccurrencesEditor extends EditorPart implements CustomizableEditor{
117
	
118
	/** The Constant ID. */
119
	public static final String ID = "CooccurrencesEditor"; //$NON-NLS-1$
120

  
121
	/** The cooc. */
122
	Cooccurrence cooc;
123
	
124
	/** The self. */
125
	CooccurrencesEditor self;
126
	// params
127
	/** The query widget. */
128
	AssistedQueryWidget queryWidget;
129
	
130
	/** The props area. */
131
	PropertiesSelector propsArea;
132
	
133
	/** The empant panel. */
134
	EmpantWidget empantPanel;
135
	
136
	/** The T score. */
137
	Text TScore;
138
	
139
	/** The T count. */
140
	Spinner TCount;
141
	
142
	/** The T freq. */
143
	Spinner TFreq;
144

  
145
	/** The line table viewer. */
146
	TableViewer viewer;
147
	
148
	/** The n column. */
149
	TableColumn nColumn;
150
	
151
	/** The occ column. */
152
	TableColumn occColumn;
153
	
154
	/** The freq column. */
155
	TableColumn freqColumn;
156
	
157
	/** The nbocc column. */
158
	TableColumn nboccColumn;
159
	
160
	/** The score column. */
161
	TableColumn scoreColumn;
162
	
163
	/** The dist column. */
164
	TableColumn distColumn;
165

  
166
	/** The current comparator. */
167
	CLineComparator currentComparator;
168

  
169
	/** The corpus. */
170
	private Corpus corpus;
171
	
172
	/** The query. */
173
	private Query query;
174
	
175
	/** The properties. */
176
	private List<Property> properties;
177
	
178
	/** The structure. */
179
	private StructuralUnit structure;
180
	
181
	/** The leftmin. */
182
	private int leftmin;
183
	
184
	/** The leftmax. */
185
	private int leftmax;
186
	
187
	/** The rightmin. */
188
	private int rightmin;
189
	
190
	/** The rightmax. */
191
	private int rightmax;
192
	
193
	/** The minfreq. */
194
	private int minfreq;
195
	
196
	/** The mincount. */
197
	private int mincount;
198
	
199
	/** The minscore. */
200
	private double minscore;
201

  
202
	/** The scroll composite. */
203
	private ScrolledComposite scrollComposite;
204

  
205
	/** The include xpivot. */
206
	private boolean includeXpivot;
207
	
208
	private boolean buildLexicalTableWithCooccurrents;
209

  
210
	/** The source. */
211
	private Object source;
212

  
213
	/**
214
	 * Instantiates a new cooccurrences editor.
215
	 */
216
	public CooccurrencesEditor() {
217
		super();
218
		self = this;
219
	}
220

  
221
	/**
222
	 * Do save.
223
	 *
224
	 * @param arg0 the arg0
225
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
226
	 */
227
	@Override
228
	public void doSave(IProgressMonitor arg0) {
229

  
230
	}
231

  
232
	/**
233
	 * Do save as.
234
	 *
235
	 * @see org.eclipse.lyon gournd zeroui.part.EditorPart#doSaveAs()
236
	 */
237
	@Override
238
	public void doSaveAs() {
239

  
240
	}
241

  
242
	/**
243
	 * Inits the.
244
	 *
245
	 * @param site the site
246
	 * @param input the input
247
	 * @throws PartInitException the part init exception
248
	 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
249
	 * org.eclipse.ui.IEditorInput)
250
	 */
251
	@Override
252
	public void init(IEditorSite site, IEditorInput input)
253
	throws PartInitException {
254
		setSite(site);
255
		setInput(input);
256

  
257
		this.cooc = ((CooccurrenceEditorInput) input).getCooc();
258
		if (cooc != null)
259
		{
260
			this.corpus = cooc.getCorpus();
261
			setPartName(cooc.getCorpus().getName()+": "+cooc.getName()); //$NON-NLS-1$
262
		}
263
		else
264
			this.corpus = ((CooccurrenceEditorInput) input).getCorpus();
265
	}
266

  
267
	/**
268
	 * Checks if is dirty.
269
	 *
270
	 * @return true, if is dirty
271
	 * @see org.eclipse.ui.part.EditorPart#isDirty()
272
	 */
273
	@Override
274
	public boolean isDirty() {
275
		return false;
276
	}
277

  
278
	/**
279
	 * Checks if is save as allowed.
280
	 *
281
	 * @return true, if is save as allowed
282
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
283
	 */
284
	@Override
285
	public boolean isSaveAsAllowed() {
286
		return false;
287
	}
288

  
289
	/**
290
	 * Sort.
291
	 */
292
	public void sort() {
293
		if (cooc != null && currentComparator != null) {
294

  
295
			try {
296
				Log.info(NLS.bind(Messages.CooccurrencesEditor_0, currentComparator.getName()));
297

  
298
				PlatformUI.getWorkbench().getProgressService().busyCursorWhile(
299
						new IRunnableWithProgress() {
300
							@Override
301
							public void run(IProgressMonitor monitor)
302
							throws InvocationTargetException,
303
							InterruptedException {
304
								try {
305
									cooc.sort(currentComparator);
306
								} catch (CqiClientException e) {
307
									System.err.println(NLS.bind(
308
										Messages.ERROR_WHILE_LOADING_CONCORDANCE_LINE, e));
309
								}
310
							}
311
						});
312
			} catch (Exception e) {
313
				System.err.println(NLS.bind(
314
						Messages.ERROR_WHILE_LOADING_CONCORDANCE_LINE, e));
315
				org.txm.rcpapplication.utils.Logger.printStackTrace(e);
316
			}
317
			viewer.refresh();
318
		}
319
	}
320

  
321
	/**
322
	 * Creates the part control.
323
	 *
324
	 * @param parent the parent
325
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
326
	 */
327
	@Override
328
	public void createPartControl(final Composite parent) {
329
		FormLayout parentLayout = new FormLayout();
330
		parent.setLayout(parentLayout);
331

  
332
		scrollComposite = new ScrolledComposite(parent, SWT.H_SCROLL
333
				| SWT.BORDER);
334
		FormData paramLayoutData = new FormData();
335
		paramLayoutData.top = new FormAttachment(0);
336
		paramLayoutData.left = new FormAttachment(0);
337
		paramLayoutData.right = new FormAttachment(100);
338
		scrollComposite.setLayoutData(paramLayoutData);
339

  
340
		final Composite paramArea = new Composite(scrollComposite, SWT.NONE);
341
		FormLayout paramLayout = new FormLayout();
342
		paramArea.setLayout(paramLayout);
343

  
344
		scrollComposite.setContent(paramArea);
345
		scrollComposite.setExpandVertical(true);
346
		scrollComposite.setExpandHorizontal(true);
347
		scrollComposite.addControlListener(new ControlAdapter() {
348
			@Override
349
			public void controlResized(ControlEvent e) {
350
				Rectangle r = scrollComposite.getClientArea();
351
				scrollComposite.setMinSize(paramArea.computeSize(SWT.DEFAULT,
352
						SWT.DEFAULT));
353
			}
354
		});
355

  
356
		// Label infos = new Label(paramArea, SWT.NONE);
357
		// infos.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true,
358
		// true));
359

  
360
		Composite queryArea = new Composite(paramArea, SWT.NONE);
361

  
362
		FormData queryLayoutData = new FormData();
363
		queryLayoutData.top = new FormAttachment(0);
364
		queryLayoutData.left = new FormAttachment(0);
365
		queryLayoutData.right = new FormAttachment(100);
366
		queryArea.setLayoutData(queryLayoutData);
367

  
368
		queryArea.setLayout(new GridLayout(3, false));
369

  
370
		Label queryLabel = new Label(queryArea, SWT.NONE);
371
		queryLabel.setText(Messages.IndexEditor_3);
372
		queryLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
373
				true));
374

  
375
		// [ (v)]
376
		queryWidget = new AssistedQueryWidget(queryArea, SWT.DROP_DOWN,
377
				this.corpus);
378
		GridData layoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
379
		layoutData.horizontalAlignment = GridData.FILL;
380
		layoutData.grabExcessHorizontalSpace = true;
381
		queryWidget.setLayoutData(layoutData);
382
		queryWidget.addKeyListener(new KeyListener() {
383
			@Override
384
			public void keyPressed(KeyEvent e) {
385
				// System.out.println("key pressed : "+e.keyCode);
386
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
387
					compute();
388
				}
389
			}
390

  
391
			@Override
392
			public void keyReleased(KeyEvent e) {
393
			}
394

  
395
		});
396

  
397
		final Button go = new Button(queryArea, SWT.BOLD);
398
		go.setText(Messages.CooccurrencesEditor_2);
399

  
400
		Font f = go.getFont();
401
		FontData defaultFont = f.getFontData()[0];
402
		defaultFont.setStyle(SWT.BOLD);
403
		Font newf = new Font(go.getDisplay(), defaultFont);
404
		go.setFont(newf);
405

  
406
		layoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
407
		layoutData.horizontalAlignment = GridData.FILL;
408
		layoutData.grabExcessHorizontalSpace = false;
409
		go.setLayoutData(layoutData);
410

  
411
		go.addSelectionListener(new SelectionListener() {
412
			@Override
413
			public void widgetSelected(SelectionEvent e) {
414
				compute();
415
			}
416

  
417
			@Override
418
			public void widgetDefaultSelected(SelectionEvent e) {
419
			}
420
		});
421

  
422
		// Filters
423
		Composite filtercontrols = new Composite(paramArea, SWT.NONE);
424
		FormData filtersLayoutData = new FormData();
425
		filtersLayoutData.top = new FormAttachment(queryArea, 0);
426
		// filtersLayoutData.bottom = new FormAttachment (100);
427
		filtersLayoutData.left = new FormAttachment(0);
428
		filtersLayoutData.right = new FormAttachment(100);
429
		filtercontrols.setLayoutData(filtersLayoutData);
430
		RowLayout layout = new RowLayout();
431
		layout.wrap = true;
432
		layout.center = true;
433
		filtercontrols.setLayout(layout);
434

  
435
		// | Properties: word_pos [Edit] |
436
		propsArea = new PropertiesSelector(filtercontrols, SWT.NONE);
437
		propsArea.setLayout(new GridLayout(4, false));
438
		propsArea.setCorpus(this.getCorpus());
439
		propsArea.setText(Messages.CooccurrencesEditor_3);
440
		propsArea.addValueChangeListener(new Listener() {
441
			@Override
442
			public void handleEvent(Event event) {
443
				if (TxmPreferences.getBoolean(UserPreferencePage.AUTO_UPDATE_EDITOR))
444
					compute();
445
			}
446
		});
447
		/*
448
		 * FormData propsLayoutData = new FormData(); propsLayoutData.top = new
449
		 * FormAttachment (queryArea, 0); propsLayoutData.left = new
450
		 * FormAttachment (0); propsLayoutData.right = new FormAttachment (100);
451
		 * propsArea.setLayoutData(propsLayoutData);
452
		 */
453

  
454
		/*
455
		 * GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 9;
456
		 * gridLayout.makeColumnsEqualWidth = false;
457
		 * filtercontrols.setLayout(gridLayout);
458
		 */
459

  
460
		Label seuilLabel = new Label(filtercontrols, SWT.NONE);
461
		seuilLabel.setText(Messages.CooccurrencesEditor_4);
462

  
463
		TFreq = new Spinner(filtercontrols, SWT.BORDER);
464
		TFreq.setMinimum(1);
465
		TFreq.setMaximum(99999);
466
		TFreq.setIncrement(1);
467
		TFreq.setPageIncrement(100);
468
		int defaultFmin = TXMPreferences.getInt(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MIN_FREQ);
469
		TFreq.setSelection(defaultFmin);
470

  
471
		seuilLabel = new Label(filtercontrols, SWT.NONE);
472
		seuilLabel.setText(Messages.CooccurrencesEditor_5);
473
		TCount = new Spinner(filtercontrols, SWT.BORDER);
474
		TCount.setMinimum(1);
475
		TCount.setMaximum(99999);
476
		TCount.setIncrement(1);
477
		TCount.setPageIncrement(100);
478
		int defaultCountmin = TXMPreferences.getInt(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MIN_COUNT);
479
		TCount.setSelection(defaultCountmin);
480

  
481
		seuilLabel = new Label(filtercontrols, SWT.NONE);
482
		seuilLabel.setText(Messages.CooccurrencesEditor_6);
483
		TScore = new Text(filtercontrols, SWT.BORDER);
484
		TScore.setText("0.0"); //$NON-NLS-1$
485
		String defaultScoremin = TXMPreferences.getString(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MIN_SCORE);
486
		TScore.setText(defaultScoremin);
487

  
488
		// empant
489
		empantPanel = new EmpantWidget(paramArea, SWT.NONE, this.getCorpus());
490
		
491
		FormData empantLayoutData = new FormData();
492
		empantLayoutData.top = new FormAttachment(filtercontrols, 0);
493
		empantLayoutData.bottom = new FormAttachment(100);
494
		empantLayoutData.left = new FormAttachment(0);
495
		empantLayoutData.right = new FormAttachment(100);
496
		empantPanel.setLayoutData(empantLayoutData);
497
		empantPanel.setMinLeft(TXMPreferences.getInt(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MIN_LEFT));
498
		empantPanel.setMaxLeft(TXMPreferences.getInt(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MAX_LEFT));
499
		empantPanel.setMinRight(TXMPreferences.getInt(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MIN_RIGHT));
500
		empantPanel.setMaxRight(TXMPreferences.getInt(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.MAX_RIGHT));
501
		
502
		// result
503
		Composite resultArea = new Composite(parent, SWT.NONE);
504
		FormData resultLayoutData = new FormData();
505
		resultLayoutData.top = new FormAttachment(scrollComposite, 0);
506
		resultLayoutData.left = new FormAttachment(0);
507
		resultLayoutData.right = new FormAttachment(100);
508
		resultLayoutData.bottom = new FormAttachment(100);
509
		resultArea.setLayoutData(resultLayoutData);
510

  
511
		FormLayout resultLayout = new FormLayout();
512
		resultArea.setLayout(resultLayout);
513

  
514
		viewer = new TableViewer(resultArea, SWT.MULTI
515
				| SWT.FULL_SELECTION | SWT.BORDER);
516
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
517
		viewer.getTable().setLinesVisible(true);
518
		viewer.getTable().setHeaderVisible(true);
519
		
520
		if (corpus != null && corpus.getFont() != null && corpus.getFont().length() > 0) {
521
			Font old = viewer.getTable().getFont();
522
			FontData fD = old.getFontData()[0];
523
			//Font f = new Font(old.getDevice(), corpus.getFont(), fD.getHeight(), fD.getStyle());
524
			Font font = new Font(Display.getCurrent(), corpus.getFont(), fD.getHeight(), fD.getStyle()); 
525
			viewer.getTable().setFont(font);
526
		}
527

  
528
		viewer.getTable().addMouseListener(new MouseAdapter() {
529
			@Override
530
			public void mouseDoubleClick(MouseEvent e) {
531
				Point mouseposition = new Point(e.x
532
						+ viewer.getTable().getHorizontalBar()
533
						.getSelection(), e.y);
534
				int col = getPointedColumn(mouseposition);
535
				//System.out.println("col "+col);
536
				switch(col)
537
				{
538
				default:
539
					IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
540
					CooccurrencesToConcordances.link(CooccurrencesEditor.this, selection);
541
				}
542
			}
543
		});
544

  
545
		FormData tableLayoutData = new FormData();
546
		tableLayoutData.top = new FormAttachment(0);
547
		tableLayoutData.bottom = new FormAttachment(100);
548
		tableLayoutData.left = new FormAttachment(0);
549
		tableLayoutData.right = new FormAttachment(100);
550
		viewer.getTable().setLayoutData(tableLayoutData);
551

  
552
		viewer.setLabelProvider(new LineLabelProvider());
553
		viewer.setContentProvider(new LineContentProvider());
554
		if (cooc != null)
555
			viewer.setInput(cooc.getLines());
556

  
557
		nColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
558
		nColumn.setText(" "); //$NON-NLS-1$
559
		nColumn.pack();
560

  
561
		occColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
562
		occColumn.setText(Messages.CooccurrencesEditor_8);
563
		occColumn.setToolTipText(Messages.CooccurrencesEditor_8);
564
		occColumn.setWidth(200);
565
		occColumn.addSelectionListener(new SelectionListener() {
566
			@Override
567
			public void widgetSelected(SelectionEvent e) {
568
				setColComparator(new OccComparator(), occColumn);
569
				sort();
570
			}
571

  
572
			@Override
573
			public void widgetDefaultSelected(SelectionEvent e) {
574
			}
575
		});
576

  
577
		freqColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
578
		freqColumn.setText(Messages.FrequencyListEditorInput_4);
579
		freqColumn.setToolTipText(Messages.FrequencyListEditorInput_4);
580
		freqColumn.setWidth(100);
581
		freqColumn.addSelectionListener(new SelectionListener() {
582
			@Override
583
			public void widgetSelected(SelectionEvent e) {
584
				setColComparator(new FreqComparator(), freqColumn);
585
				sort();
586
			}
587

  
588
			@Override
589
			public void widgetDefaultSelected(SelectionEvent e) {
590
			}
591
		});
592

  
593
		nboccColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
594
		nboccColumn.setText(Messages.CooccurrencesEditor_10);
595
		nboccColumn.setToolTipText(Messages.CooccurrencesEditor_10);
596
		nboccColumn.setWidth(130);
597
		nboccColumn.addSelectionListener(new SelectionListener() {
598
			@Override
599
			public void widgetSelected(SelectionEvent e) {
600
				setColComparator(new NbOccComparator(), nboccColumn);
601
				sort();
602
			}
603

  
604
			@Override
605
			public void widgetDefaultSelected(SelectionEvent e) {
606
			}
607
		});
608

  
609
		scoreColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
610
		scoreColumn.setText(Messages.CooccurrencesEditor_17);
611
		scoreColumn.setToolTipText(Messages.CooccurrencesEditor_17);
612
		scoreColumn.setWidth(100);
613
		scoreColumn.addSelectionListener(new SelectionListener() {
614
			@Override
615
			public void widgetSelected(SelectionEvent e) {
616
				setColComparator(new ScoreComparator(), scoreColumn);
617
				sort();
618
			}
619

  
620
			@Override
621
			public void widgetDefaultSelected(SelectionEvent e) {
622
			}
623
		});
624

  
625
		distColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
626
		distColumn.setText(Messages.CooccurrencesEditor_9);
627
		distColumn.setToolTipText(Messages.CooccurrencesEditor_9);
628
		distColumn.setWidth(130);
629
		distColumn.addSelectionListener(new SelectionListener() {
630
			@Override
631
			public void widgetSelected(SelectionEvent e) {
632
				setColComparator(new DistComparator(), distColumn);
633
				sort();
634
			}
635

  
636
			@Override
637
			public void widgetDefaultSelected(SelectionEvent e) {
638
			}
639
		});
640

  
641
		TableColumn n2Column = new TableColumn(viewer.getTable(),
642
				SWT.RIGHT);
643
		n2Column.setText(""); //$NON-NLS-1$
644
		n2Column.pack();
645

  
646
		viewer.refresh();
647
		currentComparator = new ScoreComparator();
648
		setColComparator(new ScoreComparator(), scoreColumn);
649
		sort();
650
		setColComparator(new ScoreComparator(), scoreColumn);
651
		sort();
652
		createContextMenu(viewer);
653
		setParametersFromCooc();
654

  
655
		for (TableColumn col : viewer.getTable().getColumns())
656
			col.pack();
657
	}
658

  
659
	/**
660
	 * Gets the pointed column.
661
	 *
662
	 * @param mouseposition the mouseposition
663
	 * @return the pointed column
664
	 */
665
	public int getPointedColumn(Point mouseposition) {
666
		int x = mouseposition.x; // + lineTableViewer.getTable().get;
667
		int sumWidthColumn = this.nColumn.getWidth();
668
		if (x < sumWidthColumn)
669
			return 0;
670

  
671
		sumWidthColumn += this.occColumn.getWidth();
672
		if (x < sumWidthColumn)
673
			return 1;
674

  
675
		sumWidthColumn += this.freqColumn.getWidth();
676
		if (x < sumWidthColumn)
677
			return 2;
678

  
679
		sumWidthColumn += this.nboccColumn.getWidth();
680
		if (x < sumWidthColumn)
681
			return 3;
682

  
683
		sumWidthColumn += this.scoreColumn.getWidth();
684
		if (x < sumWidthColumn)
685
			return 4;
686

  
687
		sumWidthColumn += this.distColumn.getWidth();
688
		if (x < sumWidthColumn)
689
			return 5;
690

  
691
		return 5;
692
	}
693

  
694
	/**
695
	 * Compute.
696
	 */
697
	public void compute() {
698
		StatusLine.setMessage(Messages.CooccurrencesEditor_33);
699
		if (this.queryWidget.getQueryString().trim().length() == 0
700
				|| this.queryWidget.getQueryString().trim().equals("\"\"")) //$NON-NLS-1$
701
			return;
702
		this.query = new Query(this.queryWidget.getQueryString());
703
		queryWidget.memorize();
704
		
705
		if (this.empantPanel.getMinLeft() == -1 && this.empantPanel.getMinRight() == -1)
706
		{
707
			if (this.empantPanel.getStruct() == null) {
708
				System.out.println(Messages.CooccurrencesEditor_16);
709
				return;
710
			} else if (!this.empantPanel.getXPivot()) {
711
				System.out.println(Messages.CooccurrencesEditor_16);
712
				return;
713
			}
714
		}
715
		this.properties = this.propsArea.getProperties();
716
		this.structure = this.empantPanel.getStruct();
717
		this.leftmin = this.empantPanel.getMinLeft() + 1;
718
		this.leftmax = this.empantPanel.getMaxLeft() + 1;
719
		this.rightmin = this.empantPanel.getMinRight() + 1;
720
		this.rightmax = this.empantPanel.getMaxRight() + 1;
721
		this.minfreq = this.TFreq.getSelection();
722
		this.mincount = this.TCount.getSelection();
723
		this.includeXpivot = this.empantPanel.getXPivot();
724
		/*if (!this.empantPanel.getXPivot() && this.structure != null) {
725
			if (this.leftmin == 1) {
726
				this.leftmin = 2;
727
				if (this.leftmax == 1)
728
					this.leftmax = 2;
729
			}
730
			if (this.rightmin == 1) {
731
				this.rightmin = 2;
732
				if (this.rightmax == 1)
733
					this.rightmax = 2;
734
			}
735
		}*/
736

  
737
		try {
738
			Double d = Double.parseDouble(TScore.getText());
739
			this.minscore = d;
740
		} catch (Exception e) {
741
			System.out.println(NLS.bind(Messages.CooccurrencesEditor_18, TScore.getText()));
742
			this.minscore = 0.0;
743
		}
744
		
745
		buildLexicalTableWithCooccurrents = TXMPreferences.getBoolean(CooccurrencePreferences.PREFERENCES_NODE, CooccurrencePreferences.PARTIAL_LEXICAL_TABLE);
746

  
747
		JobHandler jobhandler = new JobHandler(NLS.bind(Messages.CooccurrencesEditor_12, corpus)) {
748
			@Override
749
			protected IStatus run(IProgressMonitor monitor) {
750
				this.runInit(monitor);
751
				JobsTimer.start();
752
				monitor.beginTask(Messages.CooccurrencesEditor_13, 100);
753
				try {
754
					System.out.println(NLS.bind(Messages.CooccurrencesEditor_20, query.getQueryString(), corpus.getName()));
755
					cooc = new Cooccurrence(corpus, query, properties,
756
							structure, leftmax, leftmin, rightmin, rightmax,
757
							minfreq, mincount, minscore, includeXpivot, buildLexicalTableWithCooccurrents);
758
					//System.out.println("cooc: "+corpus+" "+query+" "+properties+" "+structure+" "+leftmax+" "+leftmin+" "+rightmin+" "+rightmax+" "+minfreq+" "+mincount+" "+minscore+" "+includeXpivot);
759
					monitor.worked(5);
760
					
761
					monitor.subTask(Messages.CooccurrencesEditor_27);
762
					if (!cooc.stepQueryLimits()) {
763
						return Status.CANCEL_STATUS;
764
					}	
765
					
766
					monitor.subTask(Messages.CooccurrencesEditor_28);
767
					if (!cooc.stepGetMatches()) {
768
						return Status.CANCEL_STATUS;
769
					}
770
					monitor.worked(10);
771
					
772
					monitor.subTask(Messages.CooccurrencesEditor_29);
773
					if (!cooc.stepBuildSignatures())
774
						return Status.CANCEL_STATUS;
775
					monitor.worked(10);
776
					
777
					monitor.subTask(Messages.CooccurrencesEditor_30);
778
					if (!cooc.stepCount())
779
						return Status.CANCEL_STATUS;
780
					monitor.worked(10);
781
					
782
					monitor.subTask(Messages.CooccurrencesEditor_31);
783
					this.acquireSemaphore();
784
					if (!cooc.stepBuildLexicalTable())
785
						return Status.CANCEL_STATUS;
786
					monitor.worked(10);
787
					this.releaseSemaphore();
788
					
789
					monitor.subTask(Messages.CooccurrencesEditor_32);
790
					this.acquireSemaphore();
791
					if (!cooc.stepGetScores())
792
						return Status.CANCEL_STATUS;
793
					monitor.worked(10);
794
					this.releaseSemaphore();
795
					
796
					if (cooc != null) cooc.clearMemory();
797
					
798
					
799
					
800
					final String message;
801
					if (cooc.getLines().size() == 0) {
802
						message = (Messages.CooccurrencesEditor_23);
803
					} else if (cooc.getLines().size() == 1) {
804
						message = (Messages.CooccurrencesEditor_24);
805
					} else {
806
						message = (Messages.bind(Messages.CooccurrencesEditor_34, cooc.getNumberOfKeyword(), cooc.getNumberOfDifferentCooccurrents()));
807
					}
808
					
809
					System.out.println(message);
810
					this.syncExec(new Runnable() {
811
						@Override
812
						public void run() {
813
							String txt = "tp "+cooc.getNumberOfKeyword()+", vc "+cooc.getNumberOfDifferentCooccurrents()+", tc "+cooc.getNumberOfCooccurrents(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
814
							try { txt += ", T "+cooc.getCorpus().getSize();} //$NON-NLS-1$
815
							catch(Exception e) {System.out.println(Messages.CooccurrencesEditor_25);}
816
							String tooltip = "- " + txt.replaceAll(", ", "\n- "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
817
							
818
							empantPanel.setInfo(txt, tooltip);
819
							StatusLine.setMessage(message);
820
						}
821
					});
822

  
823
					corpus.storeResult(cooc);
824
				} catch(ThreadDeath e) {
825
					if (cooc != null) cooc.clearMemory();
826
					return Status.CANCEL_STATUS;
827
				} catch (Exception e) {
828
					if (cooc != null) cooc.clearMemory();
829
					Logger.severe(Messages.CooccurrencesEditor_1 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff