Révision 363

tmp/org.txm.concordance.rcp/.classpath (revision 363)
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.concordance.rcp/META-INF/MANIFEST.MF (revision 363)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Concordances RCP
4
Bundle-SymbolicName: org.txm.concordance.rcp;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-Vendor: Textometrie.org
7
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
8
Require-Bundle: org.txm.concordance.core,
9
 org.txm.rcp,
10
 org.eclipse.ui;bundle-version="3.106.1",
11
 org.eclipse.core.runtime;bundle-version="3.10.0",
12
 org.eclipse.core.expressions;bundle-version="3.4.600",
13
 org.txm.core
14
Export-Package: org.txm.concordance.rcp.adapters,
15
 org.txm.concordance.rcp.editors,
16
 org.txm.concordance.rcp.handlers,
17
 org.txm.concordance.rcp.preferences,
18
 org.txm.concordance.rcp.widgets
0 19

  
tmp/org.txm.concordance.rcp/.project (revision 363)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.concordance.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.concordance.rcp/src/org/txm/concordance/rcp/adapters/ConcordanceAdapterFactory.java (revision 363)
1
// Copyright © 2010-2013 ENS de Lyon.
2
package org.txm.concordance.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.concordance.core.functions.Concordance;
9
import org.txm.rcp.adapters.TXMResultAdapter;
10
import org.txm.rcp.adapters.TXMResultAdapterFactory;
11

  
12

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

  
21
	
22
	public static final ImageDescriptor ICON =
23
			AbstractUIPlugin.imageDescriptorFromPlugin(FrameworkUtil.getBundle(ConcordanceAdapterFactory.class).getSymbolicName(),
24
					"platform:/plugin/"+ FrameworkUtil.getBundle(ConcordanceAdapterFactory.class).getSymbolicName() + "/icons/concordance.png"); //$NON-NLS-1$
25
	
26

  
27
	@Override
28
	public Object getAdapter(Object adaptableObject, Class adapterType) {
29
		if(adapterType == IWorkbenchAdapter.class && adaptableObject instanceof Concordance)	{
30
			return new TXMResultAdapter() {
31
				@Override
32
				public ImageDescriptor getImageDescriptor(Object object) {
33
					return ICON;
34
				}
35
			};
36
		}
37
		return null;
38
	}
39

  
40

  
41
}
0 42

  
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/widgets/ComplexSortSelector.java (revision 363)
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.concordance.rcp.widgets;
29

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

  
34
import org.eclipse.osgi.util.NLS;
35
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.events.SelectionEvent;
37
import org.eclipse.swt.events.SelectionListener;
38
import org.eclipse.swt.layout.GridData;
39
import org.eclipse.swt.layout.GridLayout;
40
import org.eclipse.swt.widgets.Button;
41
import org.eclipse.swt.widgets.Combo;
42
import org.eclipse.swt.widgets.Composite;
43
import org.eclipse.swt.widgets.Label;
44
import org.txm.concordance.core.functions.comparators.CompositeComparator;
45
import org.txm.concordance.core.functions.comparators.LineComparator;
46
import org.txm.concordance.rcp.editors.ConcordanceEditor;
47
import org.txm.rcp.Messages;
48
// TODO: Auto-generated Javadoc
49
/**
50
 * allow to build a Composite sorter of 1 to 4 keys @ author mdecorde.
51
 */
52
public class ComplexSortSelector extends Composite {
53

  
54
	/** The standard comparators. */
55
	HashMap<String, LineComparator> standardComparators = new HashMap<String, LineComparator>();
56
	
57
	/** The comparators names. */
58
	List<String> comparatorsNames;
59

  
60
	/** The editor. */
61
	ConcordanceEditor editor;
62
	
63
	/** The default comparator. */
64
	CompositeComparator defaultComparator;
65

  
66
	/** The first key. */
67
	Combo firstKey;
68
	
69
	/** The second key. */
70
	Combo secondKey;
71
	
72
	/** The third key. */
73
	Combo thirdKey;
74
	
75
	/** The fourth key. */
76
	Combo fourthKey;
77

  
78
	/**
79
	 * Instantiates a new complex sort selector.
80
	 *
81
	 * @param parent the parent
82
	 * @param style the style
83
	 */
84
	public ComplexSortSelector(Composite parent, int style) {
85
		super(parent, style);
86
		GridLayout gl = new GridLayout(10, false);
87
		gl.marginWidth = 0;
88
		gl.marginLeft = 0;
89
		gl.marginRight = 0;
90
		this.setLayout(gl);
91

  
92
		SelectionListener listener = new SelectionListener() {
93
			@Override
94
			public void widgetSelected(SelectionEvent e) {
95
				updateDefaultComparator();
96
			}
97

  
98
			@Override
99
			public void widgetDefaultSelected(SelectionEvent e) {
100
			}
101
		};
102
		new Label(this, SWT.NONE).setText(Messages.ComplexSortSelector_0);
103
		new Label(this, SWT.NONE).setText("#1"); //$NON-NLS-1$
104
		firstKey = new Combo(this, SWT.NONE | SWT.READ_ONLY);
105
		//firstKey.addSelectionListener(listener);
106
		GridData griddata = new GridData(GridData.FILL, GridData.FILL, false,
107
				true);
108
		griddata.widthHint = 100;
109
		firstKey.setLayoutData(griddata);
110

  
111
		new Label(this, SWT.NONE).setText("#2"); //$NON-NLS-1$
112
		secondKey = new Combo(this, SWT.NONE | SWT.READ_ONLY);
113
		//secondKey.addSelectionListener(listener);
114
		secondKey.setLayoutData(griddata);
115

  
116
		new Label(this, SWT.NONE).setText("#3"); //$NON-NLS-1$
117
		thirdKey = new Combo(this, SWT.NONE | SWT.READ_ONLY);
118
		//thirdKey.addSelectionListener(listener);
119
		thirdKey.setLayoutData(griddata);
120

  
121
		new Label(this, SWT.NONE).setText("#4"); //$NON-NLS-1$
122
		fourthKey = new Combo(this, SWT.NONE | SWT.READ_ONLY);
123
		//fourthKey.addSelectionListener(listener);
124
		fourthKey.setLayoutData(griddata);
125
		
126
		Button sortButton = new Button(this, SWT.PUSH);
127
		sortButton.setText(Messages.ComplexSortSelector_2);
128
		sortButton.addSelectionListener(listener);
129
		
130
	}
131

  
132
	/**
133
	 * Update default comparator.
134
	 */
135
	public void updateDefaultComparator() {
136
		try {
137
			ArrayList<LineComparator> comp = new ArrayList<LineComparator>();
138
			comp.add(standardComparators.get(firstKey.getText()));
139
			comp.add(standardComparators.get(secondKey.getText()));
140
			comp.add(standardComparators.get(thirdKey.getText()));
141
			comp.add(standardComparators.get(fourthKey.getText()));
142
			defaultComparator.setComparators(comp);
143
			System.out.println(Messages.ComplexSortSelector_1+comp);
144
			editor.resetSortedColumn(firstKey.getSelectionIndex());
145
			editor.setCurrentComparator(defaultComparator);
146
			editor.sort();
147
		} catch (Exception e) {
148
			System.err.println(NLS.bind(Messages.ComplexSortSelector_5, e));
149
			org.txm.rcp.utils.Logger.printStackTrace(e);
150
		}
151
	}
152
	
153
	/**
154
	 * Sets the key.
155
	 *
156
	 * @param no the new key
157
	 */
158
	public void setKey(int no)
159
	{
160
		firstKey.select(no);
161
		secondKey.select(0);
162
		thirdKey.select(0);
163
		fourthKey.select(0);
164
		
165
	}
166

  
167
	/**
168
	 * Sets the comparators.
169
	 *
170
	 * @param editor the new comparators
171
	 */
172
	public void setComparators(ConcordanceEditor editor) {
173
		this.editor = editor;
174

  
175
		List<LineComparator> standardComparatorslist = editor
176
				.getStandardComparators();
177
		comparatorsNames = new ArrayList<String>(standardComparatorslist.size());
178
		String[] tcomparatorsNames = new String[standardComparatorslist.size()];
179
		for (int i = 0; i < standardComparatorslist.size(); i++) {
180
			LineComparator comparator = standardComparatorslist.get(i);
181
			comparatorsNames.add(comparator.getName());
182
			tcomparatorsNames[i] = comparator.getName();
183
			this.standardComparators.put(comparator.getName(), comparator);
184
		}
185

  
186
		firstKey.setItems(tcomparatorsNames);
187
		secondKey.setItems(tcomparatorsNames);
188
		thirdKey.setItems(tcomparatorsNames);
189
		fourthKey.setItems(tcomparatorsNames);
190

  
191
		List<LineComparator> userDefinedComparators = editor
192
				.getUserDefinedComparators();
193
		for (LineComparator c : userDefinedComparators) {
194
			if (c.getName().equals(Messages.ComplexSortSelector_6)) {
195
				defaultComparator = (CompositeComparator) c;
196
				List<LineComparator> comp = defaultComparator.getComparators();
197
				if (comp.size() >= 4) {
198
					firstKey.select(comparatorsNames.indexOf(comp.get(0)));
199
					secondKey.select(comparatorsNames.indexOf(comp.get(1)));
200
					thirdKey.select(comparatorsNames.indexOf(comp.get(2)));
201
					fourthKey.select(comparatorsNames.indexOf(comp.get(3)));
202
				} else if (comp.size() >= 3) {
203
					firstKey.select(comparatorsNames.indexOf(comp.get(0)));
204
					secondKey.select(comparatorsNames.indexOf(comp.get(1)));
205
					thirdKey.select(comparatorsNames.indexOf(comp.get(2)));
206
					fourthKey.select(comparatorsNames.indexOf(comp.get(2)));
207
				} else if (comp.size() == 2) {
208
					firstKey.select(comparatorsNames.indexOf(comp.get(0)));
209
					secondKey.select(comparatorsNames.indexOf(comp.get(1)));
210
					thirdKey.select(comparatorsNames.indexOf(comp.get(1)));
211
					fourthKey.select(comparatorsNames.indexOf(comp.get(1)));
212
				} else if (comp.size() == 1) {
213
					firstKey.select(comparatorsNames.indexOf(comp.get(0)));
214
					secondKey.select(comparatorsNames.indexOf(comp.get(0)));
215
					thirdKey.select(comparatorsNames.indexOf(comp.get(0)));
216
					fourthKey.select(comparatorsNames.indexOf(comp.get(0)));
217
				}
218
				return;
219
			}
220
		}
221

  
222
		// no default comparator found -> create one
223
		defaultComparator = new CompositeComparator(
224
				Messages.ComplexSortSelector_6, standardComparatorslist);
225
		firstKey.select(0);
226
		secondKey.select(0);
227
		thirdKey.select(0);
228
		fourthKey.select(0);
229
		editor.getUserDefinedComparators().add(defaultComparator);
230
		editor.setCurrentComparator(defaultComparator);
231
		editor.sort();
232
	}
233
}
0 234

  
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordancesEditorContributor.java (revision 363)
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.concordance.rcp.editors;
29

  
30
import org.eclipse.jface.action.IMenuManager;
31
import org.eclipse.jface.action.MenuManager;
32
import org.eclipse.jface.action.Separator;
33
import org.eclipse.ui.part.EditorActionBarContributor;
34
import org.txm.rcp.Messages;
35
// TODO: Auto-generated Javadoc
36
/**
37
 * The Class ConcordancesEditorContributor.
38
 */
39
public class ConcordancesEditorContributor extends EditorActionBarContributor {
40

  
41
	/**
42
	 * Instantiates a new concordances editor contributor.
43
	 */
44
	public ConcordancesEditorContributor() {
45
		// TODO Auto-generated constructor stub
46
	}
47

  
48
	/* (non-Javadoc)
49
	 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
50
	 */
51
	@Override
52
	public void contributeToMenu(IMenuManager menuManager) {
53
		super.contributeToMenu(menuManager);
54
		// IMenuManager fileMenu = (IMenuManager)
55
		// menubar.find(IWorkbenchActionConstants.M_FILE);
56
		MenuManager viewMenu = new MenuManager(
57
				Messages.ConcordancesEditorContributor_0);
58

  
59
		viewMenu.add(new Separator());
60

  
61
		menuManager.add(viewMenu);
62

  
63
	}
64
}
0 65

  
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ErrorAnnotationDialog.java (revision 363)
1
package org.txm.concordance.rcp.editors;
2

  
3
import java.util.List;
4

  
5
import org.eclipse.jface.dialogs.Dialog;
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.events.SelectionAdapter;
8
import org.eclipse.swt.events.SelectionEvent;
9
import org.eclipse.swt.graphics.Point;
10
import org.eclipse.swt.layout.GridData;
11
import org.eclipse.swt.widgets.Button;
12
import org.eclipse.swt.widgets.Composite;
13
import org.eclipse.swt.widgets.Control;
14
import org.eclipse.swt.widgets.Shell;
15
import org.eclipse.ui.IWorkbenchPartSite;
16

  
17
public class ErrorAnnotationDialog extends Dialog {
18

  
19
	
20
  public ErrorAnnotationDialog(IWorkbenchPartSite iWorkbenchPartSite, List<int[]> matchesNotAnnotated) {
21
    super(iWorkbenchPartSite);
22
  }
23

  
24
  @Override
25
  protected Control createDialogArea(Composite parent) {
26
    Composite container = (Composite) super.createDialogArea(parent);
27
    Button button = new Button(container, SWT.PUSH);
28
    button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
29
        false));
30
    button.setText("Press me");
31
    button.addSelectionListener(new SelectionAdapter() {
32
      @Override
33
      public void widgetSelected(SelectionEvent e) {
34
        System.out.println("Pressed");
35
      }
36
    });
37

  
38
    return container;
39
  }
40

  
41
  // overriding this methods allows you to set the
42
  // title of the custom dialog
43
  @Override
44
  protected void configureShell(Shell newShell) {
45
    super.configureShell(newShell);
46
    newShell.setText("Selection dialog");
47
  }
48

  
49
  @Override
50
  protected Point getInitialSize() {
51
    return new Point(450, 300);
52
  }
53

  
54
} 
0 55

  
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordanceEditor.java (revision 363)
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
// $LastChangedDate:$
23
// $LastChangedRevision:$
24
// $LastChangedBy:$ 
25
//
26
package org.txm.concordance.rcp.editors;
27

  
28
import java.io.File;
29
import java.util.ArrayList;
30
import java.util.HashMap;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Vector;
34
import java.util.logging.Level;
35

  
36
import org.eclipse.core.runtime.CoreException;
37
import org.eclipse.core.runtime.IConfigurationElement;
38
import org.eclipse.core.runtime.IProgressMonitor;
39
import org.eclipse.core.runtime.IStatus;
40
import org.eclipse.core.runtime.Platform;
41
import org.eclipse.core.runtime.Status;
42
import org.eclipse.e4.ui.workbench.modeling.EModelService;
43
import org.eclipse.jface.action.Action;
44
import org.eclipse.jface.action.IMenuListener;
45
import org.eclipse.jface.action.IMenuManager;
46
import org.eclipse.jface.action.MenuManager;
47
import org.eclipse.jface.action.Separator;
48
import org.eclipse.jface.dialogs.InputDialog;
49
import org.eclipse.jface.dialogs.MessageDialog;
50
import org.eclipse.jface.viewers.ArrayContentProvider;
51
import org.eclipse.jface.viewers.ComboViewer;
52
import org.eclipse.jface.viewers.ISelection;
53
import org.eclipse.jface.viewers.ISelectionChangedListener;
54
import org.eclipse.jface.viewers.IStructuredSelection;
55
import org.eclipse.jface.viewers.SelectionChangedEvent;
56
import org.eclipse.jface.viewers.StructuredSelection;
57
import org.eclipse.jface.viewers.TableViewer;
58
import org.eclipse.osgi.util.NLS;
59
import org.eclipse.swt.SWT;
60
import org.eclipse.swt.browser.ProgressListener;
61
import org.eclipse.swt.events.ControlEvent;
62
import org.eclipse.swt.events.ControlListener;
63
import org.eclipse.swt.events.KeyEvent;
64
import org.eclipse.swt.events.KeyListener;
65
import org.eclipse.swt.events.MouseAdapter;
66
import org.eclipse.swt.events.MouseEvent;
67
import org.eclipse.swt.events.MouseListener;
68
import org.eclipse.swt.events.SelectionEvent;
69
import org.eclipse.swt.events.SelectionListener;
70
import org.eclipse.swt.graphics.Font;
71
import org.eclipse.swt.graphics.FontData;
72
import org.eclipse.swt.graphics.GC;
73
import org.eclipse.swt.graphics.Image;
74
import org.eclipse.swt.graphics.Point;
75
import org.eclipse.swt.graphics.Rectangle;
76
import org.eclipse.swt.layout.FormAttachment;
77
import org.eclipse.swt.layout.FormData;
78
import org.eclipse.swt.layout.FormLayout;
79
import org.eclipse.swt.layout.GridData;
80
import org.eclipse.swt.layout.GridLayout;
81
import org.eclipse.swt.widgets.Button;
82
import org.eclipse.swt.widgets.Combo;
83
import org.eclipse.swt.widgets.Composite;
84
import org.eclipse.swt.widgets.Display;
85
import org.eclipse.swt.widgets.Event;
86
import org.eclipse.swt.widgets.Label;
87
import org.eclipse.swt.widgets.Listener;
88
import org.eclipse.swt.widgets.Menu;
89
import org.eclipse.swt.widgets.ScrollBar;
90
import org.eclipse.swt.widgets.TableColumn;
91
import org.eclipse.swt.widgets.Text;
92
import org.eclipse.ui.IEditorInput;
93
import org.eclipse.ui.IEditorSite;
94
import org.eclipse.ui.IWorkbenchPage;
95
import org.eclipse.ui.IWorkbenchPartSite;
96
import org.eclipse.ui.IWorkbenchWindow;
97
import org.eclipse.ui.PartInitException;
98
import org.eclipse.ui.dialogs.ListDialog;
99
import org.eclipse.ui.part.EditorPart;
100
import org.txm.Toolbox;
101
import org.txm.annotation.Annotation;
102
import org.txm.annotation.AnnotationManager;
103
import org.txm.annotation.repository.AnnotationType;
104
import org.txm.annotation.repository.KnowledgeRepository;
105
import org.txm.annotation.repository.KnowledgeRepositoryManager;
106
import org.txm.annotation.repository.LocalKnowledgeRepository;
107
import org.txm.annotation.repository.SQLKnowledgeRepository;
108
import org.txm.annotation.repository.TypedValue;
109
import org.txm.concordance.core.functions.Concordance;
110
import org.txm.concordance.core.functions.Line;
111
import org.txm.concordance.core.functions.comparators.CompositeComparator;
112
import org.txm.concordance.core.functions.comparators.LexicographicKeywordComparator;
113
import org.txm.concordance.core.functions.comparators.LexicographicLeftContextComparator;
114
import org.txm.concordance.core.functions.comparators.LexicographicRightContextComparator;
115
import org.txm.concordance.core.functions.comparators.LineComparator;
116
import org.txm.concordance.core.functions.comparators.NullComparator;
117
import org.txm.concordance.core.functions.comparators.PropertiesReferenceComparator;
118
import org.txm.concordance.core.functions.comparators.ReverseComparator;
119
import org.txm.concordance.core.preferences.ConcordancePreferences;
120
import org.txm.concordance.rcp.actions.DefineSortReferencePattern;
121
import org.txm.concordance.rcp.actions.DefineViewReferencePattern;
122
import org.txm.concordance.rcp.actions.SetContextSize;
123
import org.txm.concordance.rcp.actions.SetLineNumber;
124
import org.txm.concordance.rcp.actions.SortPropertySelection;
125
import org.txm.concordance.rcp.actions.ViewPropertySelection;
126
import org.txm.concordance.rcp.handlers.BackToTextCommand;
127
import org.txm.concordance.rcp.handlers.DeleteLines;
128
import org.txm.concordance.rcp.widgets.ComplexSortSelector;
129
import org.txm.cooccurrence.rcp.messages.CooccurrenceUIMessages;
130
import org.txm.core.messages.TXMCoreMessages;
131
import org.txm.core.preferences.TXMPreferences;
132
import org.txm.functions.ReferencePattern;
133
import org.txm.objects.Page;
134
import org.txm.rcp.IImageKeys;
135
import org.txm.rcp.JobsTimer;
136
import org.txm.rcp.Messages;
137
import org.txm.rcp.StatusLine;
138
import org.txm.rcp.TXMWindows;
139
import org.txm.rcp.commands.OpenBrowser;
140
import org.txm.rcp.commands.annotation.InitializeKnowledgeRepository;
141
import org.txm.rcp.commands.annotation.SaveAnnotations;
142
import org.txm.rcp.commands.editor.CustomizableEditor;
143
import org.txm.rcp.commands.krview.OpenKRView;
144
import org.txm.rcp.editors.TXMBrowser;
145
import org.txm.rcp.editors.TableKeyListener;
146
import org.txm.rcp.editors.input.InternalViewEditorInput;
147
import org.txm.rcp.editors.internal.InternalViewEditor;
148
import org.txm.rcp.preferences.RCPPreferences;
149
import org.txm.rcp.swt.dialog.ConfirmDialog;
150
import org.txm.rcp.swt.dialog.ViewPropertySelectionDialog;
151
import org.txm.rcp.swt.provider.SimpleLabelProvider;
152
import org.txm.rcp.swt.widget.AssistedQueryWidget;
153
import org.txm.rcp.swt.widget.NavigationWidget;
154
import org.txm.rcp.utils.JobHandler;
155
import org.txm.rcp.utils.SWTEditorsUtils;
156
import org.txm.rcp.views.QueriesView;
157
import org.txm.rcp.views.corpora.CorporaView;
158
import org.txm.rcp.views.knowledgerepositories.KRView;
159
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
160
import org.txm.searchengine.cqp.corpus.Corpus;
161
import org.txm.searchengine.cqp.corpus.Property;
162
import org.txm.searchengine.cqp.corpus.query.Match;
163
import org.txm.searchengine.cqp.corpus.query.Query;
164
import org.txm.utils.AsciiUtils;
165
import org.txm.utils.logger.Log;
166
// TODO: Auto-generated Javadoc
167
/**
168
 * display the concordances parameters and results in the same editor
169
 * 
170
 * @author mdecorde.
171
 */
172
public class ConcordanceEditor extends EditorPart implements CustomizableEditor {
173

  
174
	/**
175
	 * the limit number of annotation when a confirm dialog box is shown
176
	 */
177
	private static final int NALERTAFFECTANNOTATIONS = 100;
178

  
179
	String locale = TXMPreferences.getString(RCPPreferences.PREFERENCES_NODE, RCPPreferences.UI_LOCALE, "en");
180
	
181
	/** The lineids. */
182
	List<String> lineids;
183

  
184
	/** The standard comparators. */
185
	private List<LineComparator> standardComparators;
186

  
187
	/** The user defined comparators. */
188
	private List<LineComparator> userDefinedComparators;
189

  
190
	/** The complexsorter. */
191
	ComplexSortSelector complexsorter;
192
	org.eclipse.swt.widgets.Text cqlSeparator;
193

  
194
	/** The available view keyword properties. */
195
	private List<Property> availableKeywordViewProperties;
196
	/** The available view left properties. */
197
	private List<Property> availableLeftViewProperties;
198
	/** The available view right properties. */
199
	private List<Property> availableRightViewProperties;
200

  
201
	/** The selected left view properties. */
202
	private List<Property> selectedLeftViewProperties;
203
	/** The selected right view properties. */
204
	private List<Property> selectedRightViewProperties;
205
	/** The selected keyword view properties. */
206
	private List<Property> selectedKeywordViewProperties;
207

  
208
	/** The available sort properties. */
209
	private List<Property> availableKeywordSortProperties;
210

  
211
	/** The selected keyword sort property. */
212
	private List<Property> selectedKeywordSortProperties;
213
	/** The selected left sort property. */
214
	private List<Property> selectedLeftSortProperties;
215
	/** The selected right sort property. */
216
	private List<Property> selectedRightSortProperties;
217

  
218
	/** The reference pattern. */
219
	private ReferencePattern refViewPattern;
220
	private ReferencePattern refSortPattern;
221

  
222
	/** The concordance. */
223
	private Concordance concordance;
224

  
225
	/** The annotation service */
226
	private AnnotationManager  annotManager;
227
	
228
	//boolean annotation_expert_mode = TxmPreferences.getBoolean(AnnotationPreferencePage.MODE, false);
229

  
230
	/** The standard comparator class name. */
231
	private LineComparator[] standardComparatorClassName = {
232
			new NullComparator(), new LexicographicKeywordComparator(),
233
			new LexicographicLeftContextComparator(),
234
			new LexicographicRightContextComparator(),
235
			new PropertiesReferenceComparator() };
236

  
237
	/** The corpus. */
238
	private Corpus corpus;
239

  
240
	/** The n line per page. */
241
	private int nLinePerPage;
242

  
243
	/** The top line. */
244
	private int topLine;
245

  
246
	/** The bottom line. */
247
	private int bottomLine;
248

  
249
	/** The current comparator. */
250
	protected LineComparator currentComparator;
251

  
252
	/** The left context size. */
253
	private int leftContextSize;
254

  
255
	/** The right context size. */
256
	private int rightContextSize;
257

  
258
	/** The mouseposition. */
259
	private Point mouseposition;
260

  
261
	/** The query widget. */
262
	private AssistedQueryWidget queryWidget;
263

  
264
	/** The line table viewer. */
265
	private TableViewer viewer;
266

  
267
	/** The reference column. */
268
	private TableColumn referenceColumn;
269

  
270
	/** The first column. */
271
	private TableColumn firstColumn; // due to a restriction on some platforms
272
	// (actually, MS Windows), the first
273
	// column is always left aligned. The
274
	// work around is to have a 0 width
275
	// first column
276
	/** The left context column. */
277
	private TableColumn leftContextColumn;
278
	/** The keyword column. */
279
	private TableColumn keywordColumn;
280
	/** The right context column. */
281
	private TableColumn rightContextColumn;
282

  
283
	/** The view properties label. */
284
	private Label viewPropertiesLabel;
285

  
286
	/** The set sort property action. */
287
	private Action setSortPropertyAction;
288

  
289
	/** The set context size action. */
290
	private Action setContextSizeAction;
291

  
292
	/** The set line number action. */
293
	private Action setLineNumberAction;
294

  
295
	/** The define view reference pattern action. */
296
	protected Action defineViewReferencePatternAction;
297

  
298
	/** The define sort reference pattern action. */
299
	protected Action defineSortReferencePatternAction;	
300

  
301
	/** The set view property action. */
302
	protected Action setViewPropertyAction;
303

  
304
	/** The attached browser editor. */
305
	protected TXMBrowser attachedBrowserEditor;
306

  
307
	/** The progresslistener. */
308
	protected ProgressListener progresslistener;
309

  
310
	/** The textid. */
311
	protected String textid;
312

  
313
	/** The opened page. */
314
	Page openedPage;
315

  
316
	/** The query area. */
317
	private Composite queryArea;
318

  
319
	/** The annotation area. */
320
	private Composite annotationArea;
321

  
322
	/** The navigation area. */
323
	private NavigationWidget navigationArea;
324

  
325
	/** The is setup shown. */
326
	private boolean isSetupShown = true;
327
	
328

  
329
	/** The hide btn. */
330
	private Button hideBtn;
331
	private Button deleteLineButton;
332

  
333
	/** The query size. */
334
	protected Point querySize;
335
	
336
	protected Point annotationSize;
337
	
338
	/** The annot btn. */
339
	private Button annotationButton;
340

  
341
	//	/** The selected typed value for new annotations **/
342
	//	private TypedValue annotSelectedTypedValue;
343
	//	private AnnotationType annotSelectedType;
344

  
345
	private Text annotationValuesText;
346
	private ComboViewer annotationTypesCombo;
347

  
348
	/** The parent. */
349
	private Composite parent;
350

  
351
	private ArrayList<Property> availableLeftSortProperties;
352

  
353
	private ArrayList<Property> availableRightSortProperties;
354

  
355
	private List<TypedValue> typeValuesList;
356

  
357
	protected Point annotSize;
358

  
359
	private TableColumn annotationColumn;
360

  
361
	//	private Button addAnnotationButton;
362
	//	private Button deleteAnnotationButton;
363
	private Combo addRemoveCombo;
364
	private Combo affectCombo;
365
	private Button affectAnnotationButton;
366
	//	private Button affectAnnotationToSelectionButton;
367
	//	private Button affectAnnotationToConcordanceButton;
368
	//	private Button affectAnnotationToPageButton;
369

  
370
	private Label aLabel;
371

  
372
	private Button infosAnnotTypeSelectedLink;
373

  
374
	//	private TableColumnLayout tableLayout;
375

  
376

  
377
	/* (non-Javadoc)
378
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
379
	 */
380
	@Override
381
	public void doSave(IProgressMonitor monitor) {
382
	}
383

  
384
	/* (non-Javadoc)
385
	 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
386
	 */
387
	@Override
388
	public void doSaveAs() {
389
	}
390

  
391
	/* (non-Javadoc)
392
	 * @see org.eclipse.ui.part.EditorPart#isDirty()
393
	 */
394
	@Override
395
	public boolean isDirty() {
396
		return false;
397
	}
398

  
399
	/* (non-Javadoc)
400
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
401
	 */
402
	@Override
403
	public boolean isSaveAsAllowed() {
404
		return false;
405
	}
406

  
407
	/**
408
	 * Sets the standard comparators.
409
	 */
410
	private void setStandardComparators() {
411
		for (int i = 0; i < standardComparatorClassName.length; i++)
412
			standardComparators.add(standardComparatorClassName[i]);
413
	}
414

  
415
	/* (non-Javadoc)
416
	 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
417
	 */
418
	@Override
419
	public void init(IEditorSite site, IEditorInput input)
420
			throws PartInitException {
421
		setSite(site);
422
		setInput(input);
423

  
424
		initializeEditor();
425
	}
426

  
427
	private void initializeEditor() {
428
		this.corpus = ((ConcordanceEditorInput) getEditorInput()).getCorpus();
429
		this.annotManager = corpus.getAnnotationManager();
430

  
431
		this.standardComparators = new ArrayList<LineComparator>();
432
		this.userDefinedComparators = new ArrayList<LineComparator>();
433
		new ArrayList<LineComparator>();
434
		setStandardComparators();
435
		this.nLinePerPage = TXMPreferences.getInt(ConcordancePreferences.PREFERENCES_NODE, ConcordancePreferences.N_LINE_PER_PAGE);
436
		try {
437
			this.availableKeywordViewProperties = new ArrayList<Property>(
438
					corpus.getOrderedProperties());
439
			this.availableLeftViewProperties = new ArrayList<Property>(corpus
440
					.getOrderedProperties());
441
			this.availableRightViewProperties = new ArrayList<Property>(corpus
442
					.getOrderedProperties());
443
			this.availableLeftSortProperties = new ArrayList<Property>(corpus
444
					.getOrderedProperties());
445
			this.availableKeywordSortProperties = new ArrayList<Property>(corpus
446
					.getOrderedProperties());
447
			this.availableRightSortProperties = new ArrayList<Property>(corpus
448
					.getOrderedProperties());
449
		} catch (CqiClientException e) {
450
			//System.err.println(Messages.CorporaView_3+" : "+Log.toString(e)); //$NON-NLS-1$
451
			try {
452
				System.out.println(Messages.ConcordancesEditor_0+Toolbox.getCqiClient().getLastCQPError());
453
				Log.severe(Messages.ConcordancesEditor_0+Toolbox.getCqiClient().getLastCQPError());
454
			} catch (Exception e1) {
455
				org.txm.rcp.utils.Logger.printStackTrace(e1);
456
				Log.severe("Error while computing concordance: "+e.getLocalizedMessage());
457
			} 
458
			
459
			return;
460
		}
461

  
462
		this.concordance = ((ConcordanceEditorInput) getEditorInput()).getConcordance();
463

  
464
		if (this.concordance == null) {
465
			leftContextSize = TXMPreferences.getInt(ConcordancePreferences.PREFERENCES_NODE, ConcordancePreferences.LEFT_CONTEXT_SIZE);
466
			rightContextSize = TXMPreferences.getInt(ConcordancePreferences.PREFERENCES_NODE, ConcordancePreferences.RIGHT_CONTEXT_SIZE);
467

  
468
			selectedLeftViewProperties = new ArrayList<Property>();
469
			selectedRightViewProperties = new ArrayList<Property>();
470
			selectedKeywordViewProperties = new ArrayList<Property>();
471

  
472
			//set default view property
473
			Property defaultViewProperty = availableKeywordViewProperties.get(0);
474
			if(!defaultViewProperty.getName().equals("word")) //$NON-NLS-1$
475
				for(int i = 0 ; i < availableKeywordViewProperties.size() ; i++ )
476
					if (availableKeywordViewProperties.get(i).getName().equals("word")) //$NON-NLS-1$
477
					{
478
						defaultViewProperty = availableKeywordViewProperties.get(i);
479
						break;
480
					}
481

  
482
			availableKeywordViewProperties.remove(defaultViewProperty);
483
			availableLeftViewProperties.remove(defaultViewProperty);
484
			availableRightViewProperties.remove(defaultViewProperty);
485
			selectedLeftViewProperties.add(defaultViewProperty);
486
			selectedRightViewProperties.add(defaultViewProperty);
487
			selectedKeywordViewProperties.add(defaultViewProperty);
488

  
489
			//set default sort property
490
			selectedLeftSortProperties = new ArrayList<Property>();
491
			selectedRightSortProperties = new ArrayList<Property>();
492
			selectedKeywordSortProperties = new ArrayList<Property>();
493

  
494
			Property defaultSortProperty = availableKeywordSortProperties.get(0);
495
			if(!defaultSortProperty.getName().equals("word")) //$NON-NLS-1$
496
				for(int i = 0 ; i < availableKeywordSortProperties.size() ; i++ )
497
					if (availableKeywordSortProperties.get(i).getName().equals("word")) //$NON-NLS-1$
498
					{
499
						defaultSortProperty = availableKeywordSortProperties.get(i);
500
						break;
501
					}
502

  
503
			availableKeywordSortProperties.remove(defaultSortProperty);
504
			availableLeftSortProperties.remove(defaultSortProperty);
505
			availableRightSortProperties.remove(defaultSortProperty);
506
			selectedLeftSortProperties.add(defaultSortProperty);
507
			selectedRightSortProperties.add(defaultSortProperty);
508
			selectedKeywordSortProperties.add(defaultSortProperty);
509

  
510
			this.refViewPattern = new ReferencePattern();
511
			this.refSortPattern = new ReferencePattern();
512
			try { // set the default reference is there is one
513
				if (corpus.getProperty("ref") != null) //$NON-NLS-1$
514
				{
515
					refViewPattern.addProperty(corpus.getProperty("ref")); //$NON-NLS-1$
516
					refSortPattern.addProperty(corpus.getProperty("ref")); //$NON-NLS-1$
517
				} else {
518
					if (corpus.getStructuralUnit("text") != null) //$NON-NLS-1$
519
						if (corpus.getStructuralUnit("text").getProperty("id") != null) //$NON-NLS-1$ //$NON-NLS-2$
520
						{
521
							refViewPattern.addProperty(corpus.getStructuralUnit("text").getProperty("id")); //$NON-NLS-1$ //$NON-NLS-2$
522
							refSortPattern.addProperty(corpus.getStructuralUnit("text").getProperty("id")); //$NON-NLS-1$ //$NON-NLS-2$
523
						}
524
				}
525
			} catch (CqiClientException e) {
526
				System.out.println(NLS.bind(Messages.ConcordancesEditor_43, corpus.getName(), e));
527
			}
528
		} else {
529
			leftContextSize = concordance.getLeftContextSize();
530
			rightContextSize = concordance.getRightContextSize();
531

  
532
			selectedLeftViewProperties = concordance.getLeftViewProperties();
533
			selectedRightViewProperties = concordance.getRightViewProperties();
534
			selectedKeywordViewProperties = concordance.getKeywordViewProperties();
535
			availableKeywordViewProperties.remove(selectedKeywordViewProperties);
536
			availableLeftViewProperties.remove(selectedLeftViewProperties);
537
			availableRightViewProperties.remove(selectedRightViewProperties);
538

  
539
			selectedLeftSortProperties = concordance.getLeftAnalysisProperties();
540
			selectedRightSortProperties = concordance.getRightAnalysisProperties();
541
			selectedKeywordSortProperties = concordance.getKeywordAnalysisProperties();
542
			availableKeywordSortProperties.remove(selectedKeywordSortProperties);
543
			availableLeftSortProperties.remove(selectedLeftSortProperties);
544
			availableRightSortProperties.remove(selectedRightSortProperties);
545

  
546
			this.refViewPattern = concordance.getRefViewPattern();
547
			this.refSortPattern = concordance.getRefAnalysePattern();
548
		}
549

  
550

  
551

  
552
		if (concordance != null)
553
			setPartName(concordance.getName());
554
		else
555
			setPartName(corpus.getName());
556
	}
557

  
558
	/* (non-Javadoc)
559
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
560
	 */
561
	@Override
562
	public void createPartControl(Composite parent) {
563
		this.parent = parent;
564
		//		GridLayout layout = new GridLayout(1, false);
565
		//		layout.horizontalSpacing = 0;
566
		//		layout.verticalSpacing = 0;
567
		//		parent.setLayout(layout);
568

  
569
		parent.setLayout(new FormLayout());
570

  
571
		Composite controlArea = new Composite(parent, SWT.NONE); // the form
572
		FormData formdata1 = new FormData();
573
		formdata1.top = new FormAttachment(0);
574
		//formdata1.bottom = new FormAttachment(100);
575
		formdata1.left = new FormAttachment(0);
576
		formdata1.right = new FormAttachment(100);
577
		controlArea.setLayoutData(formdata1);
578

  
579

  
580
		Composite displayArea = new Composite(parent, SWT.NONE); // the lines
581
		FormData formdata2 = new FormData();
582
		formdata2.top = new FormAttachment(controlArea);
583
		formdata2.bottom = new FormAttachment(100);
584
		formdata2.left = new FormAttachment(0);
585
		formdata2.right = new FormAttachment(100);
586
		displayArea.setLayoutData(formdata2);
587

  
588
		composeControlArea(controlArea);
589
		composeDisplayArea(displayArea);
590

  
591
		//if (concordance != null)
592
		//	fillDisplayArea(0, nLinePerPage);
593
	}
594

  
595
	/**
596
	 * Compose display area.
597
	 *
598
	 * @param displayArea the display area
599
	 */
600
	private void composeDisplayArea(final Composite displayArea) {
601
		//		tableLayout = new TableColumnLayout();
602
		displayArea.setLayout(new GridLayout(1, true));
603

  
604
		viewer = new TableViewer(displayArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
605
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
606
		viewer.setLabelProvider(new LineLabelProvider(this));
607
		viewer.setContentProvider(new ConcordancesProvider());
608
		viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
609

  
610
		if (corpus != null && corpus.getFont() != null && corpus.getFont().length() > 0) {
611
			Font old = viewer.getTable().getFont();
612
			FontData fD = old.getFontData()[0];
613
			Font font = new Font(Display.getCurrent(), corpus.getFont(), fD.getHeight(), fD.getStyle()); 
614
			viewer.getTable().setFont(font);
615
		}
616

  
617
		viewer.getTable().addListener(SWT.Resize, new Listener() {
618
			@Override
619
			public void handleEvent(Event event) {
620
				ScrollBar bar = viewer.getTable().getHorizontalBar();
621
				float l=leftContextColumn.getWidth();
622
				float k=keywordColumn.getWidth();
623
				float r=rightContextColumn.getWidth();
624
				float t=viewer.getTable().getClientArea().width;//the width of the visible part of the table; l+k+r>=t
625
				float x=l+k/2-t/2; //the abcisse the visible rectangle must have for the keyword column to be centered
626
				float M=bar.getMaximum();
627
				float T=bar.getThumb();
628
				bar.setSelection(Math.round(x*(M-T)/(l+k+r-t)));//this is how x translate in terms of bar selection
629
			}
630
		});
631

  
632
		//TODO: to enable line deletion, Concordance code must updated 
633
		viewer.getTable().addKeyListener(new KeyListener() {
634

  
635
			@Override
636
			public void keyReleased(KeyEvent e) {	}
637

  
638
			@Override
639
			public void keyPressed(KeyEvent e) {
640
				if (e.keyCode != SWT.DEL ) { // CTRL + C
641
					return;
642
				}
643

  
644
				DeleteLines.deleteConcordanceLines(ConcordanceEditor.this);
645
			}
646
		});
647

  
648

  
649
		firstColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
650
		firstColumn.setWidth(0);
651

  
652
		referenceColumn = new TableColumn(viewer.getTable(), SWT.V_SCROLL | SWT.H_SCROLL);
653
		refreshReferenceColumnTitle();
654
		referenceColumn.setToolTipText(Messages.ConcordancesEditor_1);
655
		referenceColumn.setAlignment(SWT.LEFT);
656
		referenceColumn.addSelectionListener(new SelectionListener() {
657
			@Override
658
			public void widgetSelected(SelectionEvent e) {
659
				StatusLine.setMessage(Messages.ConcordancesEditor_37);
660
				LineComparator comparator = new PropertiesReferenceComparator();
661
				if (viewer.getTable().getSortColumn() != referenceColumn) {
662
					viewer.getTable().setSortColumn(null);
663
					viewer.getTable().setSortColumn(referenceColumn);
664
					viewer.getTable().setSortDirection(SWT.UP);
665
				} else if (viewer.getTable().getSortDirection() == SWT.UP) {
666
					viewer.getTable().setSortDirection(SWT.DOWN);
667
					comparator = new ReverseComparator(comparator);
668
				} else {
669
					viewer.getTable().setSortDirection(SWT.UP);
670
				}
671
				comparator.initialize(corpus);
672
				currentComparator = comparator;
673
				complexsorter.setKey(4);//set ref key
674
				sort();
675
				StatusLine.setMessage(""); //$NON-NLS-1$
676
			}
677

  
678
			@Override
679
			public void widgetDefaultSelected(SelectionEvent e) {
680
			}
681
		});
682

  
683
		leftContextColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
684
		leftContextColumn.setText(Messages.ConcordancesEditor_2);
685
		leftContextColumn.setToolTipText(Messages.ConcordancesEditor_2);
686
		leftContextColumn.setAlignment(SWT.RIGHT);
687
		leftContextColumn.addSelectionListener(new SelectionListener() {
688
			@Override
689
			public void widgetSelected(SelectionEvent e) {
690
				StatusLine.setMessage(Messages.ConcordancesEditor_41);
691
				LineComparator comparator = new LexicographicLeftContextComparator();
692
				if (viewer.getTable().getSortColumn() != leftContextColumn) {
693
					viewer.getTable().setSortColumn(leftContextColumn);
694
					viewer.getTable().setSortDirection(SWT.UP);
695
				} else if (viewer.getTable().getSortDirection() == SWT.UP) {
696
					viewer.getTable().setSortDirection(SWT.DOWN);
697
					comparator = new ReverseComparator(comparator);
698
				} else
699
					viewer.getTable().setSortDirection(SWT.UP);
700
				comparator.initialize(corpus);
701
				currentComparator = comparator;
702
				complexsorter.setKey(2);//set ref key
703
				sort();
704
				StatusLine.setMessage(""); //$NON-NLS-1$
705
			}
706

  
707
			@Override
708
			public void widgetDefaultSelected(SelectionEvent e) {
709
			}
710
		});
711

  
712
		keywordColumn = new TableColumn(viewer.getTable(), SWT.CENTER);
713
		keywordColumn.setText(Messages.ConcordancesEditor_3);
714
		keywordColumn.setToolTipText(Messages.ConcordancesEditor_3);
715
		keywordColumn.setAlignment(SWT.CENTER);
716
		keywordColumn.addSelectionListener(new SelectionListener() {
717
			@Override
718
			public void widgetSelected(SelectionEvent e) {
719
				StatusLine.setMessage(Messages.ConcordancesEditor_45);
720
				LineComparator comparator = new LexicographicKeywordComparator();
721
				if (viewer.getTable().getSortColumn() != keywordColumn) {
722
					viewer.getTable().setSortColumn(keywordColumn);
723
					viewer.getTable().setSortDirection(SWT.UP);
724
				} else if (viewer.getTable().getSortDirection() == SWT.UP) {
725
					viewer.getTable().setSortDirection(SWT.DOWN);
726
					comparator = new ReverseComparator(comparator);
727
				} else
728
					viewer.getTable().setSortDirection(SWT.UP);
729
				comparator.initialize(corpus);
730
				currentComparator = comparator;
731
				complexsorter.setKey(1);//set ref key
732
				sort();
733
				StatusLine.setMessage(""); //$NON-NLS-1$
734
			}
735

  
736
			@Override
737
			public void widgetDefaultSelected(SelectionEvent e) {
738
			}
739
		});
740

  
741
		annotationColumn = new TableColumn(viewer.getTable(), SWT.CENTER);
742
		annotationColumn.setText(Messages.ConcordancesEditor_15);
743
		annotationColumn.setToolTipText(Messages.ConcordancesEditor_17);
744
		annotationColumn.setAlignment(SWT.CENTER);
745

  
746
		rightContextColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
747
		rightContextColumn.setText(Messages.ConcordancesEditor_4);
748
		rightContextColumn.setToolTipText(Messages.ConcordancesEditor_4);
749
		rightContextColumn.setAlignment(SWT.LEFT);
750
		rightContextColumn.addSelectionListener(new SelectionListener() {
751
			@Override
752
			public void widgetSelected(SelectionEvent e) {
753
				StatusLine.setMessage(Messages.ConcordancesEditor_48);
754
				LineComparator comparator = new LexicographicRightContextComparator();
755

  
756
				if (viewer.getTable().getSortColumn() != rightContextColumn) {
757
					viewer.getTable().setSortColumn(rightContextColumn);
758
				} else if (viewer.getTable().getSortDirection() == SWT.UP) {
759
					viewer.getTable().setSortDirection(SWT.DOWN);
760
					comparator = new ReverseComparator(comparator);
761
				} else {
762
					viewer.getTable().setSortDirection(SWT.UP);
763
				}
764
				comparator.initialize(corpus);
765
				currentComparator = comparator;
766
				complexsorter.setKey(3); //set ref key
767
				sort();
768
				StatusLine.setMessage(""); //$NON-NLS-1$
769
			}
770

  
771
			@Override
772
			public void widgetDefaultSelected(SelectionEvent e) {
773
			}
774
		});
775

  
776
		resetColumnWidths(); // set column widths
777

  
778
		viewer.getTable().setLinesVisible(true);
779
		viewer.getTable().setHeaderVisible(true);
780

  
781
		createContextMenu();
782

  
783
		// And now, a sweet piece of code :)
784
		// When the window is resized, the scrollbar is adjusted so that the
785
		// keywords remain centered
786
		viewer.getTable().addListener(SWT.Resize, new Listener() {
787
			@Override
788
			public void handleEvent(Event event) {
789
				ScrollBar bar = viewer.getTable().getHorizontalBar();
790
				//float l = leftContextColumn.getWidth();
791
				//float k = keywordColumn.getWidth();
792
				rightContextColumn.getWidth();
793
				//float t = lineTableViewer.getTable().getClientArea().width;
794
				bar.getMaximum();
795
				bar.getThumb();
796
			}
797
		});
798

  
799
		// back to text mouse listener
800
		viewer.getTable().addMouseListener(new MouseListener() {
801
			@Override
802
			public void mouseDoubleClick(MouseEvent e) {
803
				StatusLine.setMessage(Messages.ConcordancesEditor_50);
804
				backToText();
805
				StatusLine.setMessage(""); //$NON-NLS-1$
806
			}
807

  
808
			@Override
809
			public void mouseDown(MouseEvent e) { }
810
			@Override
811
			public void mouseUp(MouseEvent e) {	}
812
		});
813

  
814
		// On Windows, the selection is gray if the table does not have focus.
815
		// To make both tables appear in focus, draw the selection background
816
		// here.
817
		// This part only works on version 3.2 or later.
818
		Listener eraseListener = new Listener() {
819
			@Override
820
			public void handleEvent(Event event) {
821
				event.detail &= ~SWT.HOT;
822
				if ((event.detail & SWT.SELECTED) != 0) {
823
					GC gc = event.gc;
824
					Rectangle rect = event.getBounds();
825
					gc.setForeground(displayArea.getDisplay().getSystemColor(
826
							SWT.COLOR_LIST_SELECTION_TEXT));
827
					gc.setBackground(displayArea.getDisplay().getSystemColor(
828
							SWT.COLOR_LIST_SELECTION));
829
					gc.fillRectangle(rect);
830
					event.detail &= ~SWT.SELECTED;
831
				}
832
			}
833
		};
834

  
835
		// Listeners to avoid 0 width clumns
836
		referenceColumn.addControlListener(new ControlListener() {
837
			@Override
838
			public void controlMoved(ControlEvent e) { }
839
			@Override
840
			public void controlResized(ControlEvent e) {
841
				if (referenceColumn.getWidth() < 5) referenceColumn.setWidth(5);
842

  
843
			}
844
		});
845
		leftContextColumn.addControlListener(new ControlListener() {
846
			@Override
847
			public void controlMoved(ControlEvent e) { }
848
			@Override
849
			public void controlResized(ControlEvent e) {
850
				if (leftContextColumn.getWidth() < 5) leftContextColumn.setWidth(5);
851

  
852
			}
853
		});
854
		keywordColumn.addControlListener(new ControlListener() {
855
			@Override
856
			public void controlMoved(ControlEvent e) { }
857
			@Override
858
			public void controlResized(ControlEvent e) {
859
				if (keywordColumn.getWidth() < 5) keywordColumn.setWidth(5);
860

  
861
			}
862
		});
863
		annotationColumn.addControlListener(new ControlListener() {
864
			@Override
865
			public void controlMoved(ControlEvent e) { }
866
			@Override
867
			public void controlResized(ControlEvent e) {
868
				if (annotationArea != null && annotationColumn.getWidth() < 5) annotationColumn.setWidth(5);
869

  
870
			}
871
		});
872
		rightContextColumn.addControlListener(new ControlListener() {
873
			@Override
874
			public void controlMoved(ControlEvent e) { }
875
			@Override
876
			public void controlResized(ControlEvent e) {
877
				if (rightContextColumn.getWidth() < 5) rightContextColumn.setWidth(5);
878

  
879
			}
880
		});
881

  
882
		viewer.getTable().addListener(SWT.EraseItem, eraseListener);
883

  
884
		//		tableLayout.setColumnData(firstColumn, new ColumnWeightData(0, false));
885
		//		tableLayout.setColumnData(referenceColumn, new ColumnWeightData(1, true)); 
886
		//		tableLayout.setColumnData(keywordColumn, new ColumnWeightData(1, true));
887
		//		tableLayout.setColumnData(leftContextColumn, new ColumnWeightData(1, true));
888
		//		tableLayout.setColumnData(annotationColumn, new ColumnWeightData(0, true));
889
		//		tableLayout.setColumnData(rightContextColumn, new ColumnWeightData(1, true));
890
	}
891

  
892
	/**
893
	 * Sort.
894
	 */
895
	public void sort() {
896
		if (concordance != null && currentComparator != null) {
897

  
898
			//System.out.println("concordance sort props: "+concordance.getLeftCAnalysisProperty()+", "+concordance.getKeywordAnalysisProperty()+", "+concordance.getRightCAnalysisProperty());
899
			concordance.setLeftAnalysisProperties(selectedLeftSortProperties);
900
			concordance.setKeywordAnalysisProperties(selectedKeywordSortProperties);
901
			concordance.setRightAnalysisProperties(selectedRightSortProperties);
902
			
903
			try {
904
				Log.info(NLS.bind(CooccurrenceUIMessages.CooccurrencesEditor_0, currentComparator.getName()));
905
				if (currentComparator instanceof CompositeComparator)
906
					Log.info(((CompositeComparator) currentComparator).getComparators().toString());
907
				JobHandler jobhandler = new JobHandler("Sorting...") { //$NON-NLS-1$
908
					@Override
909
					protected IStatus run(IProgressMonitor monitor) {
910
						this.runInit(monitor);
911
						JobsTimer.start();
912
						try {
913
							monitor.beginTask(Messages.ConcordancesEditor_6, concordance.getNLines());
914
							concordance.setCurrentMonitor(this);
915
							concordance.sort(currentComparator);
916
							concordance.setCurrentMonitor(null);
917
							syncExec(new Runnable() {
918
								@Override
919
								public void run() {
920
									StatusLine.setMessage(Messages.SORT_DONE);
921
									fillDisplayArea(topLine, topLine + nLinePerPage - 1);
922
								}
923
							});
924

  
925
						} catch (ThreadDeath td) {
926
							return Status.CANCEL_STATUS;
927
						} catch (Exception e) {
928
							System.err.println(NLS.bind(Messages.ERROR_WHILE_LOADING_CONCORDANCE_LINE, e));
929
							org.txm.rcp.utils.Logger.printStackTrace(e);
930
						} finally {
931
							monitor.done();
932
							JobsTimer.stopAndPrint();
933
						}
934
						return Status.OK_STATUS;
935
					}
936
				};
937

  
938
				jobhandler.startJob();
939
			} catch (Exception e) {
940
				System.err.println(NLS.bind(Messages.ERROR_WHILE_LOADING_CONCORDANCE_LINE, e));
941
				org.txm.rcp.utils.Logger.printStackTrace(e);
942
			}
943
		}
944
	}
945

  
946
	/**
947
	 * Lazy loads the concordance lines range and fills the display area.
948
	 *
949
	 * @param from the from
950
	 * @param to the to
951
	 */
952
	public void fillDisplayArea(int from, int to) {
953
		if (viewer == null)
954
			return;
955
		
956
		viewer.getControl().setRedraw(false);
957
		
958
		from = Math.max(from, 0);
959
		to = Math.min(to, concordance.getNLines() - 1);
960
		List<Line> lines = null;
961
		if (concordance.getNLines() > 0) {
962
			try {
963
				lines = concordance.getLines(from, to);
964
			} catch (Exception e) {
965
				System.err.println(Messages.ERROR_WHILE_LOADING_CONCORDANCE_LINE+ e);
966
				org.txm.rcp.utils.Logger.printStackTrace(e);
967
			}
968
		} else
969
			lines = new ArrayList<Line>();
970

  
971
		viewer.setInput(lines);
972
		referenceColumn.pack();
973
		leftContextColumn.pack();
974
		keywordColumn.pack();
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff