Révision 206
tmp/org.txm.lexicaltable.rcp/.project (revision 206) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.lexicaltable.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.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/preferences/LexicalTablePreferencePage.java (revision 206) | ||
---|---|---|
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.lexicaltable.rcp.preferences; |
|
29 |
|
|
30 |
import org.eclipse.jface.preference.IntegerFieldEditor; |
|
31 |
import org.eclipse.ui.IWorkbench; |
|
32 |
import org.txm.lexicaltable.core.preferences.LexicalTablePreferences; |
|
33 |
import org.txm.lexicaltable.rcp.adapters.LexicalTableAdapterFactory; |
|
34 |
import org.txm.rcp.preferences.TXMPreferencePage; |
|
35 |
import org.txm.rcp.preferences.TXMPreferenceStore; |
|
36 |
import org.txm.rcpapplication.Messages; |
|
37 |
|
|
38 |
/** |
|
39 |
* Lexical Table preference page. |
|
40 |
* @author mdecorde |
|
41 |
* @author sjacquot |
|
42 |
* |
|
43 |
*/ |
|
44 |
public class LexicalTablePreferencePage extends TXMPreferencePage { |
|
45 |
|
|
46 |
|
|
47 |
@Override |
|
48 |
public void createFieldEditors() { |
|
49 |
|
|
50 |
IntegerFieldEditor fmin = new IntegerFieldEditor(LexicalTablePreferences.F_MIN, Messages.LexicalTablePreferencePage_1, this.getFieldEditorParent()); |
|
51 |
fmin.setValidRange(1, 999999999); |
|
52 |
|
|
53 |
IntegerFieldEditor vmax = new IntegerFieldEditor(LexicalTablePreferences.V_MAX, "vmax", this.getFieldEditorParent()); |
|
54 |
vmax.setValidRange(1, 999999999); |
|
55 |
|
|
56 |
this.addField(fmin); |
|
57 |
this.addField(vmax); |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public void init(IWorkbench workbench) { |
|
63 |
this.setPreferenceStore(new TXMPreferenceStore(LexicalTablePreferences.PREFERENCES_NODE)); |
|
64 |
//this.setDescription(Messages.LexicalTablePreferencePage_0); |
|
65 |
this.setTitle(Messages.LexicalTablePreferencePage_0); |
|
66 |
this.setImageDescriptor(LexicalTableAdapterFactory.ICON); |
|
67 |
} |
|
68 |
|
|
69 |
} |
|
0 | 70 |
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/adapters/LexicalTableAdapterFactory.java (revision 206) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
package org.txm.lexicaltable.rcp.adapters; |
|
3 |
|
|
4 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
5 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
|
6 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
7 |
import org.osgi.framework.FrameworkUtil; |
|
8 |
import org.txm.rcp.adapters.BaseAdapterFactory; |
|
9 |
import org.txm.stat.data.LexicalTable; |
|
10 |
|
|
11 |
|
|
12 |
/** |
|
13 |
* A factory for creating Adapter objects. |
|
14 |
* |
|
15 |
* @author mdecorde |
|
16 |
* @author sjacquot |
|
17 |
*/ |
|
18 |
public class LexicalTableAdapterFactory extends BaseAdapterFactory { |
|
19 |
|
|
20 |
|
|
21 |
public static final ImageDescriptor ICON = |
|
22 |
AbstractUIPlugin.imageDescriptorFromPlugin(FrameworkUtil.getBundle(LexicalTableAdapterFactory.class).getSymbolicName(), |
|
23 |
"platform:/plugin/"+ FrameworkUtil.getBundle(LexicalTableAdapterFactory.class).getSymbolicName() + "/icons/lexicaltable.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 LexicalTable) { |
|
38 |
return new IWorkbenchAdapter() { |
|
39 |
@Override |
|
40 |
public Object[] getChildren(Object lexicaltable) { |
|
41 |
// FIXME: useless? |
|
42 |
// List<Object> children = ((LexicalTable) |
|
43 |
// lexicaltable).getResults(); |
|
44 |
// System.out.println("PARTITION RESULTS "+children); |
|
45 |
return ((LexicalTable)lexicaltable).getResults().toArray(); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
50 |
return ICON; |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public String getLabel(Object lexicaltable) { |
|
55 |
return "" + ((LexicalTable) lexicaltable).getProperty(); //$NON-NLS-1$ |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public Object getParent(Object lexicaltable) { |
|
60 |
return ((LexicalTable) lexicaltable).getPartition(); |
|
61 |
} |
|
62 |
}; |
|
63 |
} |
|
64 |
} |
|
65 |
return null; |
|
66 |
} |
|
67 |
|
|
68 |
|
|
69 |
} |
|
0 | 70 |
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditor.java (revision 206) | ||
---|---|---|
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.lexicaltable.rcp.editors; |
|
29 |
|
|
30 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
31 |
import org.eclipse.jface.action.MenuManager; |
|
32 |
import org.eclipse.jface.viewers.TableViewer; |
|
33 |
import org.eclipse.swt.SWT; |
|
34 |
import org.eclipse.swt.layout.GridData; |
|
35 |
import org.eclipse.swt.layout.GridLayout; |
|
36 |
import org.eclipse.swt.widgets.Composite; |
|
37 |
import org.eclipse.swt.widgets.Label; |
|
38 |
import org.eclipse.swt.widgets.Menu; |
|
39 |
import org.eclipse.swt.widgets.Table; |
|
40 |
import org.eclipse.ui.IEditorInput; |
|
41 |
import org.eclipse.ui.IEditorSite; |
|
42 |
import org.eclipse.ui.PartInitException; |
|
43 |
import org.eclipse.ui.part.EditorPart; |
|
44 |
import org.txm.rcpapplication.Messages; |
|
45 |
import org.txm.rcpapplication.editors.TableKeyListener; |
|
46 |
import org.txm.searchengine.cqp.corpus.Lexicon; |
|
47 |
import org.txm.searchengine.cqp.corpus.Property; |
|
48 |
|
|
49 |
/** |
|
50 |
* The Class LexicalTableEditor. |
|
51 |
*/ |
|
52 |
public class LexicalTableEditor extends EditorPart { |
|
53 |
|
|
54 |
/** |
|
55 |
* Instantiates a new lexical table editor. |
|
56 |
*/ |
|
57 |
public LexicalTableEditor() { |
|
58 |
// TODO Auto-generated constructor stub |
|
59 |
} |
|
60 |
|
|
61 |
/** The Constant ID. */ |
|
62 |
public static final String ID = "LexicalTableEditor"; //$NON-NLS-1$ |
|
63 |
|
|
64 |
/** |
|
65 |
* Do save. |
|
66 |
* |
|
67 |
* @param arg0 the arg0 |
|
68 |
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor) |
|
69 |
*/ |
|
70 |
@Override |
|
71 |
public void doSave(IProgressMonitor arg0) { |
|
72 |
// TODO Auto-generated method stub |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Do save as. |
|
77 |
* |
|
78 |
* @see org.eclipse.lyon gournd zeroui.part.EditorPart#doSaveAs() |
|
79 |
*/ |
|
80 |
@Override |
|
81 |
public void doSaveAs() { |
|
82 |
// TODO Auto-generated method stub |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* Inits the. |
|
87 |
* |
|
88 |
* @param site the site |
|
89 |
* @param input the input |
|
90 |
* @throws PartInitException the part init exception |
|
91 |
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, |
|
92 |
* org.eclipse.ui.IEditorInput) |
|
93 |
*/ |
|
94 |
@Override |
|
95 |
public void init(IEditorSite site, IEditorInput input) |
|
96 |
throws PartInitException { |
|
97 |
setSite(site); |
|
98 |
setInput(input); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Checks if is dirty. |
|
103 |
* |
|
104 |
* @return true, if is dirty |
|
105 |
* @see org.eclipse.ui.part.EditorPart#isDirty() |
|
106 |
*/ |
|
107 |
@Override |
|
108 |
public boolean isDirty() { |
|
109 |
return false; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Checks if is save as allowed. |
|
114 |
* |
|
115 |
* @return true, if is save as allowed |
|
116 |
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() |
|
117 |
*/ |
|
118 |
@Override |
|
119 |
public boolean isSaveAsAllowed() { |
|
120 |
return false; |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Creates the part control. |
|
125 |
* |
|
126 |
* @param parent the parent |
|
127 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
128 |
*/ |
|
129 |
@Override |
|
130 |
public void createPartControl(Composite parent) { |
|
131 |
GridLayout parentLayout = new GridLayout(1, false); |
|
132 |
parent.setLayout(parentLayout); |
|
133 |
|
|
134 |
Lexicon lexicon = null; // ((LexicalTableEditorInput)getEditorInput()).getLexicon(); |
|
135 |
Property property = ((LexicalTableEditorInput) getEditorInput()) |
|
136 |
.getProperty(); |
|
137 |
|
|
138 |
Composite corpusInfo = new Composite(parent, SWT.NONE); |
|
139 |
GridLayout corpusInfoLayout = new GridLayout(1, false); |
|
140 |
corpusInfo.setLayout(corpusInfoLayout); |
|
141 |
|
|
142 |
Label propertyLabel = new Label(corpusInfo, SWT.NONE); |
|
143 |
propertyLabel.setText(Messages.LexicalTable_1 + property.getName()); |
|
144 |
propertyLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, |
|
145 |
false, false)); |
|
146 |
|
|
147 |
Label numberOfTypeLabel = new Label(corpusInfo, SWT.NONE); |
|
148 |
//numberOfTypeLabel.setText(Messages.bind(Messages.LexicalTable_2, lexicon.nbrOfType())); |
|
149 |
numberOfTypeLabel.setLayoutData(new GridData(GridData.END, |
|
150 |
GridData.CENTER, false, false)); |
|
151 |
|
|
152 |
Label numberOfTokenLabel = new Label(corpusInfo, SWT.NONE); |
|
153 |
// int numberOfToken = lexicon.nbrOfToken(); |
|
154 |
// numberOfTokenLabel.setText(Messages.LexicalTable_3 + numberOfToken); |
|
155 |
numberOfTokenLabel.setLayoutData(new GridData(GridData.END, |
|
156 |
GridData.CENTER, false, false)); |
|
157 |
|
|
158 |
TableViewer viewer = new TableViewer(parent, SWT.VIRTUAL | SWT.BORDER |
|
159 |
| SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); |
|
160 |
viewer.getTable().addKeyListener(new TableKeyListener(viewer)); |
|
161 |
Table table = viewer.getTable(); |
|
162 |
table.setHeaderVisible(true); |
|
163 |
table.setLinesVisible(true); |
|
164 |
/*TableColumn nameColumn = new TableColumn(table, SWT.LEFT); |
|
165 |
nameColumn.setText(Messages.IndexEditor_27 |
|
166 |
+ lexicon.getProperty().toString()); |
|
167 |
nameColumn.setWidth(320); |
|
168 |
TableColumn sizeColumn = new TableColumn(table, SWT.RIGHT); |
|
169 |
sizeColumn.setText(Messages.FrequencyListEditorInput_4); |
|
170 |
sizeColumn.setWidth(80); |
|
171 |
int[] freqs = lexicon.getFreq(); |
|
172 |
String[] types = lexicon.getForms(); |
|
173 |
for (int i = 0; i < lexicon.nbrOfType(); i++) { |
|
174 |
TableItem item = new TableItem(table, SWT.NONE); |
|
175 |
item.setText(new String[] { types[i], String.valueOf(freqs[i]) }); |
|
176 |
} |
|
177 |
*/ |
|
178 |
createContextMenu(viewer); |
|
179 |
} |
|
180 |
|
|
181 |
/** |
|
182 |
* Creates the context menu. |
|
183 |
* |
|
184 |
* @param tableViewer the table viewer |
|
185 |
*/ |
|
186 |
private void createContextMenu(TableViewer tableViewer) { |
|
187 |
MenuManager menuManager = new MenuManager(); |
|
188 |
Menu menu = menuManager.createContextMenu(tableViewer.getTable()); |
|
189 |
|
|
190 |
// Set the MenuManager |
|
191 |
tableViewer.getTable().setMenu(menu); |
|
192 |
getSite().registerContextMenu(menuManager, tableViewer); |
|
193 |
// Make the selection available |
|
194 |
getSite().setSelectionProvider(tableViewer); |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Sets the focus. |
|
199 |
* |
|
200 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
201 |
*/ |
|
202 |
@Override |
|
203 |
public void setFocus() { |
|
204 |
} |
|
205 |
} |
|
0 | 206 |
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditorInput.java (revision 206) | ||
---|---|---|
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.lexicaltable.rcp.editors; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
34 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
35 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
36 |
import org.eclipse.jface.viewers.LabelProvider; |
|
37 |
import org.eclipse.jface.viewers.Viewer; |
|
38 |
import org.eclipse.osgi.util.NLS; |
|
39 |
import org.eclipse.swt.graphics.Image; |
|
40 |
import org.eclipse.ui.IEditorInput; |
|
41 |
import org.eclipse.ui.IPersistableElement; |
|
42 |
import org.eclipse.ui.part.EditorPart; |
|
43 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
44 |
import org.txm.rcpapplication.Application; |
|
45 |
import org.txm.rcpapplication.IImageKeys; |
|
46 |
import org.txm.rcpapplication.Messages; |
|
47 |
import org.txm.rcpapplication.editors.Tablable; |
|
48 |
import org.txm.rcpapplication.editors.TableEditor; |
|
49 |
import org.txm.rcpapplication.editors.input.AbstractTablable; |
|
50 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
51 |
import org.txm.searchengine.cqp.corpus.Property; |
|
52 |
import org.txm.stat.StatException; |
|
53 |
import org.txm.stat.data.LexicalTable; |
|
54 |
// TODO: Auto-generated Javadoc |
|
55 |
/** |
|
56 |
* The Class LexicalTableEditorInput. |
|
57 |
* |
|
58 |
* @author sloiseau |
|
59 |
*/ |
|
60 |
public class LexicalTableEditorInput implements IEditorInput { |
|
61 |
|
|
62 |
/** The lexical table. */ |
|
63 |
private LexicalTable lexicalTable; |
|
64 |
|
|
65 |
/** The property. */ |
|
66 |
private Property property; |
|
67 |
|
|
68 |
/** The editors. */ |
|
69 |
private List<EditorPart> editors; |
|
70 |
|
|
71 |
/** The inputs. */ |
|
72 |
private List<IEditorInput> inputs; |
|
73 |
|
|
74 |
/** |
|
75 |
* Instantiates a new lexical table editor input. |
|
76 |
* |
|
77 |
* @param table the table |
|
78 |
* @param partition the partition |
|
79 |
* @param property the property |
|
80 |
*/ |
|
81 |
public LexicalTableEditorInput(final LexicalTable table, |
|
82 |
Partition partition, Property property) { |
|
83 |
this.lexicalTable = table; |
|
84 |
this.property = property; |
|
85 |
|
|
86 |
editors = new ArrayList<EditorPart>(); |
|
87 |
editors.add(new TableEditor()); |
|
88 |
|
|
89 |
inputs = new ArrayList<IEditorInput>(); |
|
90 |
|
|
91 |
class LexicalTableLabelProvider extends LabelProvider implements |
|
92 |
ITableLabelProvider { |
|
93 |
|
|
94 |
@Override |
|
95 |
public Image getColumnImage(Object element, int columnIndex) { |
|
96 |
return null; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public String getColumnText(Object element, int columnIndex) { |
|
101 |
int[] val = (int[]) element; |
|
102 |
return String.valueOf(val[columnIndex]); |
|
103 |
} |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
Tablable asTable = new AbstractTablable() { |
|
108 |
|
|
109 |
@Override |
|
110 |
public String[] getColumnTitles() { |
|
111 |
return new String[] { Messages.FrequencyListEditorInput_3, |
|
112 |
Messages.FrequencyListEditorInput_4 }; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public String[] getColumnTypes() { |
|
117 |
return new String[] { Messages.FrequencyListEditorInput_5, |
|
118 |
Messages.FrequencyListEditorInput_6 }; |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public IStructuredContentProvider getContentProvider() { |
|
123 |
return new IStructuredContentProvider() { |
|
124 |
@Override |
|
125 |
public Object[] getElements(Object inputElement) { |
|
126 |
LexicalTable res = (LexicalTable) inputElement; |
|
127 |
List<int[]> row = new ArrayList<int[]>(); |
|
128 |
for (int i = 0; i < res.getNRows(); i++) { |
|
129 |
int[] v = null; |
|
130 |
try { |
|
131 |
v = res.getRow(i).asIntArray(); |
|
132 |
} catch (StatException e) { |
|
133 |
System.err.println(NLS.bind( |
|
134 |
Messages.GraphicalLogger_0, e)); |
|
135 |
} |
|
136 |
row.add(v); |
|
137 |
} |
|
138 |
return row.toArray(); |
|
139 |
} |
|
140 |
|
|
141 |
@Override |
|
142 |
public void dispose() { |
|
143 |
// TODO Auto-generated method stub |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public void inputChanged(Viewer viewer, Object oldInput, |
|
148 |
Object newInput) { |
|
149 |
// TODO Auto-generated method stub |
|
150 |
} |
|
151 |
|
|
152 |
}; |
|
153 |
} |
|
154 |
|
|
155 |
@Override |
|
156 |
public Object getInput() { |
|
157 |
return table; |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
public LabelProvider getLabelProvider() { |
|
162 |
return new LexicalTableLabelProvider(); |
|
163 |
} |
|
164 |
|
|
165 |
}; |
|
166 |
inputs.add(asTable); |
|
167 |
|
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Instantiates a new lexical table editor input. |
|
172 |
* |
|
173 |
* @param lt the lt |
|
174 |
*/ |
|
175 |
public LexicalTableEditorInput(LexicalTable lt) { |
|
176 |
this(lt, lt.getPartition(), lt.getProperty()); |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* Exists. |
|
181 |
* |
|
182 |
* @return true, if successful |
|
183 |
* @see org.eclipse.ui.IEditorInput#exists() |
|
184 |
*/ |
|
185 |
@Override |
|
186 |
public boolean exists() { |
|
187 |
return false; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* Gets the image descriptor. |
|
192 |
* |
|
193 |
* @return the image descriptor |
|
194 |
* @see org.eclipse.ui.IEditorInput#getImageDescriptor() |
|
195 |
*/ |
|
196 |
@Override |
|
197 |
public ImageDescriptor getImageDescriptor() { |
|
198 |
return AbstractUIPlugin.imageDescriptorFromPlugin( |
|
199 |
Application.PLUGIN_ID, IImageKeys.LEXICALTABLE); |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Gets the name. |
|
204 |
* |
|
205 |
* @return the name |
|
206 |
* @see org.eclipse.ui.IEditorInput#getName() |
|
207 |
*/ |
|
208 |
@Override |
|
209 |
public String getName() { |
|
210 |
return this.lexicalTable.getProperty().toString(); |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Gets the persistable. |
|
215 |
* |
|
216 |
* @return the persistable |
|
217 |
* @see org.eclipse.ui.IEditorInput#getPersistable() |
|
218 |
*/ |
|
219 |
@Override |
|
220 |
public IPersistableElement getPersistable() { |
|
221 |
return null; |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* Gets the tool tip text. |
|
226 |
* |
|
227 |
* @return the tool tip text |
|
228 |
* @see org.eclipse.ui.IEditorInput#getToolTipText() |
|
229 |
*/ |
|
230 |
@Override |
|
231 |
public String getToolTipText() { |
|
232 |
return getName(); |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* Gets the adapter. |
|
237 |
* |
|
238 |
* @param arg0 the arg0 |
|
239 |
* @return the adapter |
|
240 |
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) |
|
241 |
*/ |
|
242 |
@Override |
|
243 |
@SuppressWarnings("unchecked") //$NON-NLS-1$ |
|
244 |
public Object getAdapter(Class arg0) { |
|
245 |
return null; |
|
246 |
} |
|
247 |
|
|
248 |
/** |
|
249 |
* Gets the lexical table. |
|
250 |
* |
|
251 |
* @return the lexicon |
|
252 |
*/ |
|
253 |
public LexicalTable getLexicalTable() { |
|
254 |
return lexicalTable; |
|
255 |
} |
|
256 |
|
|
257 |
/** |
|
258 |
* Gets the property. |
|
259 |
* |
|
260 |
* @return the property |
|
261 |
*/ |
|
262 |
public Property getProperty() { |
|
263 |
return property; |
|
264 |
} |
|
265 |
|
|
266 |
} |
|
0 | 267 |
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditor2.java (revision 206) | ||
---|---|---|
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.lexicaltable.rcp.editors; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Arrays; |
|
33 |
import java.util.Collections; |
|
34 |
import java.util.Comparator; |
|
35 |
import java.util.List; |
|
36 |
|
|
37 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
38 |
import org.eclipse.jface.action.MenuManager; |
|
39 |
import org.eclipse.jface.viewers.TableViewer; |
|
40 |
import org.eclipse.jface.viewers.TableViewerColumn; |
|
41 |
import org.eclipse.jface.window.Window; |
|
42 |
import org.eclipse.osgi.util.NLS; |
|
43 |
import org.eclipse.swt.SWT; |
|
44 |
import org.eclipse.swt.events.SelectionEvent; |
|
45 |
import org.eclipse.swt.events.SelectionListener; |
|
46 |
import org.eclipse.swt.graphics.Image; |
|
47 |
import org.eclipse.swt.layout.FormAttachment; |
|
48 |
import org.eclipse.swt.layout.FormData; |
|
49 |
import org.eclipse.swt.layout.FormLayout; |
|
50 |
import org.eclipse.swt.layout.GridData; |
|
51 |
import org.eclipse.swt.layout.GridLayout; |
|
52 |
import org.eclipse.swt.widgets.Button; |
|
53 |
import org.eclipse.swt.widgets.Combo; |
|
54 |
import org.eclipse.swt.widgets.Composite; |
|
55 |
import org.eclipse.swt.widgets.Label; |
|
56 |
import org.eclipse.swt.widgets.Menu; |
|
57 |
import org.eclipse.swt.widgets.MessageBox; |
|
58 |
import org.eclipse.swt.widgets.Spinner; |
|
59 |
import org.eclipse.swt.widgets.TableColumn; |
|
60 |
import org.eclipse.swt.widgets.Text; |
|
61 |
import org.eclipse.ui.IEditorInput; |
|
62 |
import org.eclipse.ui.IEditorSite; |
|
63 |
import org.eclipse.ui.PartInitException; |
|
64 |
import org.eclipse.ui.part.EditorPart; |
|
65 |
import org.txm.lexicaltable.rcp.handlers.MergeLines; |
|
66 |
import org.txm.rcpapplication.Messages; |
|
67 |
import org.txm.rcpapplication.StatusLine; |
|
68 |
import org.txm.rcpapplication.commands.editor.CustomizableEditor; |
|
69 |
import org.txm.rcpapplication.editors.TableKeyListener; |
|
70 |
import org.txm.rcpapplication.swt.widget.ObjectSelector; |
|
71 |
import org.txm.rcpapplication.swt.widget.PropertiesSelector; |
|
72 |
import org.txm.rcpapplication.swt.widget.QueryWidget; |
|
73 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
74 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
75 |
import org.txm.stat.StatException; |
|
76 |
import org.txm.stat.data.LexicalTable; |
|
77 |
import org.txm.stat.data.Vector; |
|
78 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
79 |
// TODO: Auto-generated Javadoc |
|
80 |
/** |
|
81 |
* display the lexical table tools to merge/delete lines or columns and display |
|
82 |
* the lexical table too |
|
83 |
* @author mdecorde |
|
84 |
*/ |
|
85 |
public class LexicalTableEditor2 extends EditorPart implements CustomizableEditor{ |
|
86 |
|
|
87 |
|
|
88 |
public static final String ID = "LexicalTableEditor"; //$NON-NLS-1$ |
|
89 |
|
|
90 |
/** The table. */ |
|
91 |
LexicalTable table; |
|
92 |
|
|
93 |
// params |
|
94 |
/** The query widget. */ |
|
95 |
QueryWidget queryWidget; |
|
96 |
|
|
97 |
/** The props area. */ |
|
98 |
PropertiesSelector propsArea; |
|
99 |
|
|
100 |
/** The line table viewer. */ |
|
101 |
TableViewer viewer; |
|
102 |
|
|
103 |
/** The part columns. */ |
|
104 |
List<TableViewerColumn> partColumns = new ArrayList<TableViewerColumn>(); |
|
105 |
|
|
106 |
/** The part column. */ |
|
107 |
TableViewerColumn partColumn; |
|
108 |
|
|
109 |
/** The n column. */ |
|
110 |
TableViewerColumn nColumn; |
|
111 |
|
|
112 |
/** The form column. */ |
|
113 |
TableViewerColumn formColumn; |
|
114 |
|
|
115 |
/** The freq column. */ |
|
116 |
TableViewerColumn freqColumn; |
|
117 |
// org.eclipse.swt.widgets.List colCombo; |
|
118 |
/** The colselector. */ |
|
119 |
ObjectSelector colselector; |
|
120 |
|
|
121 |
/** The test combo. */ |
|
122 |
Combo testCombo; |
|
123 |
|
|
124 |
/** The minfreqspinner. */ |
|
125 |
Spinner minfreqspinner; |
|
126 |
|
|
127 |
/** The top spinner. */ |
|
128 |
Spinner topSpinner; |
|
129 |
|
|
130 |
/** The fusion text. */ |
|
131 |
Text fusionText; |
|
132 |
|
|
133 |
/** The cols. */ |
|
134 |
private List<double[]> cols; |
|
135 |
|
|
136 |
/** The rows. */ |
|
137 |
private List<String> rows; |
|
138 |
|
|
139 |
/** The collist. */ |
|
140 |
List<Object> collist; |
|
141 |
|
|
142 |
/** The freqs. */ |
|
143 |
//private List<Integer> freqs; |
|
144 |
|
|
145 |
/** The previous sorted col. */ |
|
146 |
private int previousSortedCol; |
|
147 |
boolean DEFAULTREVERSE = false; |
|
148 |
boolean reverse = DEFAULTREVERSE; |
|
149 |
|
|
150 |
/** The source. */ |
|
151 |
private Object source; |
|
152 |
|
|
153 |
/** |
|
154 |
* Do save. |
|
155 |
* |
|
156 |
* @param arg0 the arg0 |
|
157 |
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor) |
|
158 |
*/ |
|
159 |
@Override |
|
160 |
public void doSave(IProgressMonitor arg0) { |
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* Do save as. |
|
166 |
* |
|
167 |
* @see org.eclipse.lyon gournd zeroui.part.EditorPart#doSaveAs() |
|
168 |
*/ |
|
169 |
@Override |
|
170 |
public void doSaveAs() { |
|
171 |
|
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* Inits the. |
|
176 |
* |
|
177 |
* @param site the site |
|
178 |
* @param input the input |
|
179 |
* @throws PartInitException the part init exception |
|
180 |
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, |
|
181 |
* org.eclipse.ui.IEditorInput) |
|
182 |
*/ |
|
183 |
@Override |
|
184 |
public void init(IEditorSite site, IEditorInput input) |
|
185 |
throws PartInitException { |
|
186 |
setSite(site); |
|
187 |
setInput(input); |
|
188 |
|
|
189 |
table = ((LexicalTableEditorInput) input).getLexicalTable(); |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* Checks if is dirty. |
|
194 |
* |
|
195 |
* @return true, if is dirty |
|
196 |
* @see org.eclipse.ui.part.EditorPart#isDirty() |
|
197 |
*/ |
|
198 |
@Override |
|
199 |
public boolean isDirty() { |
|
200 |
return false; |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* Checks if is save as allowed. |
|
205 |
* |
|
206 |
* @return true, if is save as allowed |
|
207 |
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() |
|
208 |
*/ |
|
209 |
@Override |
|
210 |
public boolean isSaveAsAllowed() { |
|
211 |
return false; |
|
212 |
} |
|
213 |
|
|
214 |
/** |
|
215 |
* Sort. |
|
216 |
* |
|
217 |
* @param col the col |
|
218 |
* @param index the index |
|
219 |
*/ |
|
220 |
public void sort(TableViewerColumn col, int index) { |
|
221 |
|
|
222 |
if (index == previousSortedCol) { |
|
223 |
reverse = !reverse; |
|
224 |
} else { |
|
225 |
reverse = DEFAULTREVERSE; |
|
226 |
} |
|
227 |
|
|
228 |
if (index == -2) {// rownames |
|
229 |
table.sortRowNames(reverse); |
|
230 |
} else if (index == -1) { // freqs |
|
231 |
try { |
|
232 |
table.sortByFreqs(reverse); |
|
233 |
StatusLine.setMessage(Messages.IndexEditor_37); |
|
234 |
} catch (Exception e2) { |
|
235 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e2); |
|
236 |
} |
|
237 |
} else if (index >= 0) { |
|
238 |
table.sort(index, reverse); |
|
239 |
} |
|
240 |
|
|
241 |
previousSortedCol = index; |
|
242 |
refreshTable(); |
|
243 |
|
|
244 |
viewer.getTable().setSortColumn(col.getColumn()); |
|
245 |
if (reverse) |
|
246 |
viewer.getTable().setSortDirection(SWT.DOWN); |
|
247 |
else |
|
248 |
viewer.getTable().setSortDirection(SWT.UP); |
|
249 |
} |
|
250 |
|
|
251 |
Label infos; |
|
252 |
/** |
|
253 |
* Creates the part control. |
|
254 |
* |
|
255 |
* @param parent the parent |
|
256 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
257 |
*/ |
|
258 |
@Override |
|
259 |
public void createPartControl(final Composite parent) { |
|
260 |
FormLayout parentLayout = new FormLayout(); |
|
261 |
parent.setLayout(parentLayout); |
|
262 |
|
|
263 |
final Composite paramArea = new Composite(parent, SWT.NONE); |
|
264 |
FormData paramLayoutData = new FormData(); |
|
265 |
paramLayoutData.top = new FormAttachment(0); |
|
266 |
paramLayoutData.left = new FormAttachment(0); |
|
267 |
paramLayoutData.right = new FormAttachment(100); |
|
268 |
paramArea.setLayoutData(paramLayoutData); |
|
269 |
|
|
270 |
GridLayout paramLayout = new GridLayout(5, false); |
|
271 |
paramArea.setLayout(paramLayout); |
|
272 |
|
|
273 |
infos = new Label(paramArea, SWT.NONE); |
|
274 |
infos.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, |
|
275 |
true, 5, 1)); |
|
276 |
refreshInfos(); |
|
277 |
|
|
278 |
Button keepTop = new Button(paramArea, SWT.PUSH); |
|
279 |
keepTop.setText(Messages.LexicalTableEditor_4); |
|
280 |
keepTop.addSelectionListener(new SelectionListener() { |
|
281 |
@Override |
|
282 |
public void widgetSelected(SelectionEvent e) { |
|
283 |
StatusLine.setMessage(Messages.LexicalTableEditor_16); |
|
284 |
System.out.println(NLS.bind(Messages.LexicalTableEditor_5, topSpinner.getSelection(), minfreqspinner.getSelection())); |
|
285 |
|
|
286 |
MessageBox messageBox = new MessageBox(e.display |
|
287 |
.getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); |
|
288 |
messageBox.setMessage(Messages.DeleteLines_1); |
|
289 |
int response = messageBox.open(); |
|
290 |
if (response != SWT.YES) |
|
291 |
return; |
|
292 |
|
|
293 |
try { |
|
294 |
table.filter(topSpinner.getSelection(), minfreqspinner.getSelection()); |
|
295 |
refreshTable(); |
|
296 |
StatusLine.setMessage(""); //$NON-NLS-1$ |
|
297 |
} catch (Exception e1) { |
|
298 |
// TODO Auto-generated catch block |
|
299 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e1); |
|
300 |
StatusLine.setMessage("LT: sort error"); //$NON-NLS-1$ |
|
301 |
} |
|
302 |
} |
|
303 |
|
|
304 |
@Override |
|
305 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
306 |
} |
|
307 |
}); |
|
308 |
infos = new Label(paramArea, SWT.NONE); |
|
309 |
infos.setText(Messages.LexicalTableEditor_8); |
|
310 |
topSpinner = new Spinner(paramArea, SWT.BORDER); |
|
311 |
|
|
312 |
infos = new Label(paramArea, SWT.NONE); |
|
313 |
infos.setText(Messages.LexicalTableEditor_6); |
|
314 |
minfreqspinner = new Spinner(paramArea, SWT.BORDER); |
|
315 |
|
|
316 |
Button fusionCol = new Button(paramArea, SWT.PUSH); |
|
317 |
fusionCol.setText(Messages.LexicalTableEditor_10); |
|
318 |
fusionCol.addSelectionListener(new SelectionListener() { |
|
319 |
@Override |
|
320 |
public void widgetSelected(SelectionEvent e) { |
|
321 |
StatusLine.setMessage(Messages.LexicalTableEditor_18); |
|
322 |
ArrayList<Object> selection = new ArrayList<Object>(); |
|
323 |
MergeDeleteDialog d = new MergeDeleteDialog(e.display |
|
324 |
.getActiveShell(), new ArrayList<Object>(collist), |
|
325 |
selection, -1); |
|
326 |
|
|
327 |
if (d.open() == Window.OK) { |
|
328 |
List<Integer> colindices = new ArrayList<Integer>(); |
|
329 |
for (int i = 0; i < collist.size(); i++) { |
|
330 |
if (selection.contains(collist.get(i))) |
|
331 |
colindices.add(i); |
|
332 |
} |
|
333 |
|
|
334 |
if (d.doMerge()) { |
|
335 |
String newname = d.getMergeName(); |
|
336 |
|
|
337 |
System.out.println(NLS.bind(Messages.LexicalTableEditor_11, colindices)); |
|
338 |
double[] firstcol = cols.get(colindices.get(0)); |
|
339 |
|
|
340 |
// merge selected cols into the first one |
|
341 |
for (int i = 1; i < colindices.size(); i++) { |
|
342 |
for (int j = 0; j < table.getNRows(); j++) { |
|
343 |
firstcol[j] += cols.get(colindices.get(i))[j]; |
|
344 |
} |
|
345 |
} |
|
346 |
|
|
347 |
// update first col of the Lexical table |
|
348 |
for (int j = 0; j < table.getNRows(); j++) { |
|
349 |
table.set(j, colindices.get(0), firstcol[j]); |
|
350 |
} |
|
351 |
|
|
352 |
// and its name |
|
353 |
table.getColNames().setString(colindices.get(0), |
|
354 |
newname); |
|
355 |
|
|
356 |
// keep only the first col |
|
357 |
List<Integer> coltodelete = colindices.subList(1, |
|
358 |
colindices.size()); |
|
359 |
table.removeCols(coltodelete); |
|
360 |
|
|
361 |
// refresh stuff |
|
362 |
collist = new ArrayList<Object>();// update col name |
|
363 |
// list |
|
364 |
try { |
|
365 |
for (String colname : table.getColNames() |
|
366 |
.asStringsArray()) { |
|
367 |
collist.add(colname); |
|
368 |
} |
|
369 |
} catch (StatException e1) { |
|
370 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e1); |
|
371 |
return; |
|
372 |
} |
|
373 |
|
|
374 |
Collections.sort(colindices);// update table viewer cols |
|
375 |
for (int i = colindices.size() - 1; i >= 1; i--) { |
|
376 |
viewer.getTable().getColumns()[colindices |
|
377 |
.get(i) + 3].dispose();// +3 = separator, |
|
378 |
// form, freq |
|
379 |
} |
|
380 |
viewer.getTable().getColumns()[colindices.get(0) + 3].setText(newname); |
|
381 |
refreshTable(); |
|
382 |
} else// delete |
|
383 |
{ |
|
384 |
System.out.println(NLS.bind(Messages.LexicalTableEditor_12, colindices)); |
|
385 |
table.removeCols(colindices); |
|
386 |
|
|
387 |
collist = new ArrayList<Object>(); |
|
388 |
Vector colnames = table.getColNames(); |
|
389 |
try { |
|
390 |
for (String colname : colnames.asStringsArray()) { |
|
391 |
collist.add(colname); |
|
392 |
} |
|
393 |
} catch (StatException e1) { |
|
394 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e1); |
|
395 |
return; |
|
396 |
} |
|
397 |
|
|
398 |
Collections.sort(colindices); |
|
399 |
for (int i = colindices.size() - 1; i >= 0; i--) { |
|
400 |
viewer.getTable().getColumns()[colindices |
|
401 |
.get(i) + 3].dispose(); |
|
402 |
} |
|
403 |
refreshTable(); |
|
404 |
} |
|
405 |
} |
|
406 |
StatusLine.setMessage(""); //$NON-NLS-1$ |
|
407 |
} |
|
408 |
|
|
409 |
@Override |
|
410 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
411 |
} |
|
412 |
}); |
|
413 |
|
|
414 |
Button mergeDeleteRows = new Button(paramArea, SWT.PUSH); |
|
415 |
mergeDeleteRows.setText(Messages.LexicalTableEditor_13); |
|
416 |
mergeDeleteRows.addSelectionListener(new SelectionListener() { |
|
417 |
@Override |
|
418 |
public void widgetSelected(SelectionEvent e) { |
|
419 |
|
|
420 |
ArrayList<Object> selection = new ArrayList<Object>(); |
|
421 |
MergeDeleteDialog d = new MergeDeleteDialog(e.display |
|
422 |
.getActiveShell(), new ArrayList<Object>(rows), |
|
423 |
selection, -1); |
|
424 |
int count = 0; |
|
425 |
if (d.open() == Window.OK) { |
|
426 |
int[] rowindices = new int[selection.size()]; |
|
427 |
for (int i = 0; i < rows.size(); i++) { |
|
428 |
if (selection.contains(rows.get(i))) { |
|
429 |
rowindices[count] = i; |
|
430 |
count++; |
|
431 |
} |
|
432 |
} |
|
433 |
|
|
434 |
if (d.doMerge()) { |
|
435 |
MergeLines.mergeLines(LexicalTableEditor2.this, d |
|
436 |
.getMergeName(), rowindices); |
|
437 |
} else { |
|
438 |
table.removeRows(rowindices); |
|
439 |
refreshTable(); |
|
440 |
viewer.getTable().deselectAll(); |
|
441 |
} |
|
442 |
} |
|
443 |
} |
|
444 |
|
|
445 |
@Override |
|
446 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
447 |
} |
|
448 |
}); |
|
449 |
|
|
450 |
// result |
|
451 |
Composite resultArea = new Composite(parent, SWT.NONE); |
|
452 |
FormData resultLayoutData = new FormData(); |
|
453 |
resultLayoutData.top = new FormAttachment(paramArea, 0); |
|
454 |
resultLayoutData.left = new FormAttachment(0); |
|
455 |
resultLayoutData.right = new FormAttachment(100); |
|
456 |
resultLayoutData.bottom = new FormAttachment(100); |
|
457 |
resultArea.setLayoutData(resultLayoutData); |
|
458 |
|
|
459 |
FormLayout resultLayout = new FormLayout(); |
|
460 |
resultArea.setLayout(resultLayout); |
|
461 |
|
|
462 |
viewer = new TableViewer(resultArea, SWT.MULTI |
|
463 |
| SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); |
|
464 |
viewer.getTable().addKeyListener(new TableKeyListener(viewer)); |
|
465 |
viewer.getTable().setLinesVisible(true); |
|
466 |
viewer.getTable().setHeaderVisible(true); |
|
467 |
|
|
468 |
FormData tableLayoutData = new FormData(); |
|
469 |
tableLayoutData.top = new FormAttachment(0); |
|
470 |
tableLayoutData.bottom = new FormAttachment(100); |
|
471 |
tableLayoutData.left = new FormAttachment(0); |
|
472 |
tableLayoutData.right = new FormAttachment(100); |
|
473 |
viewer.getTable().setLayoutData(tableLayoutData); |
|
474 |
|
|
475 |
nColumn = new TableViewerColumn(viewer, SWT.RIGHT); |
|
476 |
nColumn.getColumn().setText(" "); //$NON-NLS-1$ |
|
477 |
nColumn.getColumn().pack(); |
|
478 |
|
|
479 |
formColumn = new TableViewerColumn(viewer, SWT.LEFT); |
|
480 |
formColumn.getColumn().setText(this.table.getProperty().getName()); |
|
481 |
formColumn.getColumn().setWidth(200); |
|
482 |
formColumn.getColumn().addSelectionListener( |
|
483 |
new ColumnSelectionListener(formColumn, -2)); |
|
484 |
|
|
485 |
freqColumn = new TableViewerColumn(viewer, SWT.LEFT); |
|
486 |
freqColumn.getColumn().setText(Messages.FrequencyListEditorInput_4); |
|
487 |
freqColumn.getColumn().setWidth(200); |
|
488 |
freqColumn.getColumn().addSelectionListener( |
|
489 |
new ColumnSelectionListener(freqColumn, -1)); |
|
490 |
collist = new ArrayList<Object>(); |
|
491 |
Vector colnames = table.getColNames(); |
|
492 |
|
|
493 |
try { |
|
494 |
int[] colmargins = table.getColMarginsVector().asIntArray(); |
|
495 |
int i = 0; |
|
496 |
for (String colname : colnames.asStringsArray()) { |
|
497 |
// partColumn = new TableColumn(lineTableViewer.getTable(), |
|
498 |
// SWT.RIGHT); |
|
499 |
partColumn = new TableViewerColumn(viewer, SWT.RIGHT); |
|
500 |
partColumn.getColumn().setText(colname+" t="+colmargins[i]); //$NON-NLS-1$ |
|
501 |
partColumn.getColumn().setToolTipText(colname); |
|
502 |
collist.add(colname); |
|
503 |
partColumn.getColumn().setWidth(200); |
|
504 |
partColumn.getColumn().addSelectionListener( |
|
505 |
new ColumnSelectionListener(partColumn, i)); |
|
506 |
i++; |
|
507 |
} |
|
508 |
} catch (StatException e1) { |
|
509 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e1); |
|
510 |
return; |
|
511 |
} |
|
512 |
|
|
513 |
nColumn = new TableViewerColumn(viewer, SWT.RIGHT); |
|
514 |
nColumn.getColumn().setText(""); //$NON-NLS-1$ |
|
515 |
nColumn.getColumn().pack(); |
|
516 |
|
|
517 |
viewer.setContentProvider(new LineContentProvider()); |
|
518 |
refreshTable(); |
|
519 |
viewer.setInput(table); |
|
520 |
parent.layout(); |
|
521 |
|
|
522 |
if (table != null) { |
|
523 |
setPartName(table.getPartition().getName()+": "+table.getName()); //$NON-NLS-1$ |
|
524 |
} |
|
525 |
|
|
526 |
viewer.refresh(); |
|
527 |
viewer.getTable().setSortColumn(formColumn.getColumn()); |
|
528 |
viewer.getTable().setSortDirection(SWT.UP); |
|
529 |
|
|
530 |
createContextMenu(viewer); |
|
531 |
} |
|
532 |
|
|
533 |
private void refreshColNames() throws StatException, CqiClientException { |
|
534 |
TableColumn[] cols = viewer.getTable().getColumns(); |
|
535 |
String[] colnames = table.getColNames().asStringsArray(); |
|
536 |
|
|
537 |
for (int i = 0 ; i < cols.length ; i++) { |
|
538 |
cols[i].setText(colnames[i]+ "T="+table.getPartition().getParts().get(i).getSize()); //$NON-NLS-1$ |
|
539 |
} |
|
540 |
} |
|
541 |
|
|
542 |
private void refreshInfos() { |
|
543 |
try { |
|
544 |
infos.setText(Messages.IndexEditor_27 + table.getTotal() |
|
545 |
+ Messages.IndexEditor_28 + table.getNRows() |
|
546 |
+ Messages.LexicalTableEditor_2 + table.getFmin() |
|
547 |
+ Messages.LexicalTableEditor_3 + table.getFmax()); |
|
548 |
infos.redraw(); |
|
549 |
infos.getParent().layout(); |
|
550 |
} catch (RWorkspaceException e3) { |
|
551 |
// TODO Auto-generated catch block |
|
552 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e3); |
|
553 |
} |
|
554 |
} |
|
555 |
|
|
556 |
/** |
|
557 |
* Creates the context menu. |
|
558 |
* |
|
559 |
* @param tableViewer the table viewer |
|
560 |
*/ |
|
561 |
private void createContextMenu(TableViewer tableViewer) { |
|
562 |
|
|
563 |
MenuManager menuManager = new MenuManager(); |
|
564 |
Menu menu = menuManager.createContextMenu(tableViewer.getTable()); |
|
565 |
tableViewer.getTable().setMenu(menu); |
|
566 |
getSite().registerContextMenu(menuManager, tableViewer); |
|
567 |
getSite().setSelectionProvider(tableViewer); |
|
568 |
} |
|
569 |
|
|
570 |
/** |
|
571 |
* Refresh table. |
|
572 |
*/ |
|
573 |
public void refreshTable() { |
|
574 |
LineLabelProvider labelprovider = new LineLabelProvider(table); |
|
575 |
viewer.setLabelProvider(labelprovider); |
|
576 |
this.cols = labelprovider.getCols(); |
|
577 |
this.rows = labelprovider.getRows(); |
|
578 |
//this.freqs = labelprovider.getFreqs(); |
|
579 |
viewer.refresh(); |
|
580 |
for (TableColumn col : viewer.getTable().getColumns()) { |
|
581 |
col.pack(); |
|
582 |
} |
|
583 |
|
|
584 |
topSpinner.setMinimum(1); |
|
585 |
topSpinner.setMaximum(table.getNRows()); |
|
586 |
topSpinner.setSelection(table.getNRows()); |
|
587 |
minfreqspinner.setMinimum(table.getFmin()); |
|
588 |
minfreqspinner.setMaximum(table.getFmax()); |
|
589 |
viewer.getTable().setFocus(); |
|
590 |
} |
|
591 |
|
|
592 |
/** |
|
593 |
* Sets the col comparator. |
|
594 |
* |
|
595 |
* @param comp the comp |
|
596 |
* @param col the col |
|
597 |
*/ |
|
598 |
private void setColComparator(Comparator comp, TableColumn col) { |
|
599 |
/* |
|
600 |
* currentComparator = comp; |
|
601 |
* if (lineTableViewer.getTable().getSortColumn()!=col){ |
|
602 |
* lineTableViewer.getTable().setSortColumn(col); |
|
603 |
* lineTableViewer.getTable().setSortDirection(SWT.UP); } else |
|
604 |
* if (lineTableViewer.getTable().getSortDirection() ==SWT.UP){ |
|
605 |
* lineTableViewer.getTable().setSortDirection(SWT.DOWN); |
|
606 |
* currentComparator = new ReverseComparator(currentComparator); } else |
|
607 |
* lineTableViewer.getTable().setSortDirection(SWT.UP); |
|
608 |
* currentComparator.initialize(cooc.getCorpus()); |
|
609 |
*/ |
|
610 |
} |
|
611 |
|
|
612 |
/* (non-Javadoc) |
|
613 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
614 |
*/ |
|
615 |
@Override |
|
616 |
public void setFocus() { |
|
617 |
|
|
618 |
} |
|
619 |
|
|
620 |
/** |
|
621 |
* Gets the corpus. |
|
622 |
* |
|
623 |
* @return the corpus |
|
624 |
*/ |
|
625 |
public Corpus getCorpus() { |
|
626 |
return null; |
|
627 |
} |
|
628 |
|
|
629 |
/** |
|
630 |
* The listener interface for receiving columnSelection events. |
|
631 |
* The class that is interested in processing a columnSelection |
|
632 |
* event implements this interface, and the object created |
|
633 |
* with that class is registered with a component using the |
|
634 |
* component's <code>addColumnSelectionListener<code> method. When |
|
635 |
* the columnSelection event occurs, that object's appropriate |
|
636 |
* method is invoked. |
|
637 |
* |
|
638 |
* @see ColumnSelectionEvent |
|
639 |
*/ |
|
640 |
public class ColumnSelectionListener implements SelectionListener { |
|
641 |
|
|
642 |
/** The col. */ |
|
643 |
TableViewerColumn col; |
|
644 |
|
|
645 |
/** The index. */ |
|
646 |
int index; |
|
647 |
|
|
648 |
/** |
|
649 |
* Instantiates a new column selection listener. |
|
650 |
* |
|
651 |
* @param formColumn the form column |
|
652 |
* @param index the index |
|
653 |
*/ |
|
654 |
public ColumnSelectionListener(TableViewerColumn formColumn, int index) { |
|
655 |
this.col = formColumn; |
|
656 |
this.index = index; |
|
657 |
} |
|
658 |
|
|
659 |
/* (non-Javadoc) |
|
660 |
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
|
661 |
*/ |
|
662 |
@Override |
|
663 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
664 |
} |
|
665 |
|
|
666 |
/* (non-Javadoc) |
|
667 |
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
668 |
*/ |
|
669 |
@Override |
|
670 |
public void widgetSelected(SelectionEvent e) { |
|
671 |
StatusLine.setMessage(Messages.IndexEditor_36); |
|
672 |
sort(col, index); |
|
673 |
StatusLine.setMessage(""); //$NON-NLS-1$ |
|
674 |
} |
|
675 |
} |
|
676 |
|
|
677 |
/** |
|
678 |
* Gets the line table viewer. |
|
679 |
* |
|
680 |
* @return the line table viewer |
|
681 |
*/ |
|
682 |
public TableViewer getlineTableViewer() { |
|
683 |
return viewer; |
|
684 |
} |
|
685 |
|
|
686 |
/** |
|
687 |
* Gets the lexical table. |
|
688 |
* |
|
689 |
* @return the lexical table |
|
690 |
*/ |
|
691 |
public LexicalTable getLexicalTable() { |
|
692 |
return table; |
|
693 |
} |
|
694 |
|
|
695 |
/** |
|
696 |
* Gets the cols. |
|
697 |
* |
|
698 |
* @return the cols |
|
699 |
*/ |
|
700 |
public List<double[]> getCols() { |
|
701 |
return cols; |
|
702 |
} |
|
703 |
|
|
704 |
/** |
|
705 |
* Export data. |
|
706 |
* |
|
707 |
* @param file the file |
|
708 |
*/ |
|
709 |
public void exportData(File file) { |
|
710 |
table.exportData(file, "\t", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
|
711 |
} |
|
712 |
|
|
713 |
/** |
|
714 |
* Import data. |
|
715 |
* |
|
716 |
* @param file the file |
|
717 |
*/ |
|
718 |
public void importData(File file) { |
|
719 |
try { |
|
720 |
if (table.importData(file)) { |
|
721 |
// fix col names |
|
722 |
String[] colnames = table.getColNames().asStringsArray(); |
|
723 |
TableColumn[] cols = viewer.getTable().getColumns(); |
|
724 |
if (colnames.length > cols.length) { |
|
725 |
System.out.println(Messages.LexicalTableEditor_1+Arrays.toString(cols)+Messages.LexicalTableEditor_7+Arrays.toString(colnames)+" "); //$NON-NLS-1$ |
|
726 |
return; |
|
727 |
} |
|
728 |
for (int i = 0; i < colnames.length ; i++) { |
|
729 |
//System.out.println("set col name "+colnames[i]); |
|
730 |
cols[3 + i].setText(colnames[i]); |
|
731 |
} |
|
732 |
viewer.refresh(); |
|
733 |
viewer.setInput(table); |
|
734 |
viewer.getTable().getParent().layout(); |
|
735 |
refreshTable(); |
|
736 |
} else { |
|
737 |
System.out.println(Messages.LexicalTableEditor_14); |
|
738 |
} |
|
739 |
} catch(Exception e) { |
|
740 |
System.out.println(Messages.LexicalTableEditor_15+e); |
|
741 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e); |
|
742 |
} |
|
743 |
} |
|
744 |
|
|
745 |
/* (non-Javadoc) |
|
746 |
* @see org.txm.rcpapplication.commands.editor.CustomizableEditor#setName(java.lang.String) |
|
747 |
*/ |
|
748 |
@Override |
|
749 |
public void setName(String name) { |
|
750 |
this.setPartName(name); |
|
751 |
} |
|
752 |
|
|
753 |
/* (non-Javadoc) |
|
754 |
* @see org.txm.rcpapplication.commands.editor.CustomizableEditor#setIcon(org.eclipse.swt.graphics.Image) |
|
755 |
*/ |
|
756 |
@Override |
|
757 |
public void setIcon(Image image) { |
|
758 |
this.setTitleImage(image); |
|
759 |
} |
|
760 |
|
|
761 |
/* (non-Javadoc) |
|
762 |
* @see org.txm.rcpapplication.commands.editor.CustomizableEditor#setSource(java.lang.Object) |
|
763 |
*/ |
|
764 |
@Override |
|
765 |
public void setSource(Object source) |
|
766 |
{ |
|
767 |
this.source = source; |
|
768 |
} |
|
769 |
|
|
770 |
/* (non-Javadoc) |
|
771 |
* @see org.txm.rcpapplication.commands.editor.CustomizableEditor#getSource() |
|
772 |
*/ |
|
773 |
@Override |
|
774 |
public Object getSource() { |
|
775 |
return table; |
|
776 |
} |
|
777 |
|
|
778 |
@Override |
|
779 |
public Object toConcordance() { return null;} |
|
780 |
@Override |
|
781 |
public Object toIndex() { return null;} |
|
782 |
@Override |
|
783 |
public Object toProgression() { return null;} |
|
784 |
|
|
785 |
@Override |
|
786 |
public boolean usingCorpus(Corpus corpus) { |
|
787 |
Corpus c = getCorpus(); |
|
788 |
if (c == null) return false; |
|
789 |
return c.getName().equals(corpus.getName()); |
|
790 |
} |
|
791 |
|
|
792 |
@Override |
|
793 |
public boolean updateCorpus(Corpus corpus) { |
|
794 |
// TODO Auto-generated method stub |
|
795 |
return false; |
|
796 |
} |
|
797 |
} |
|
0 | 798 |
Formats disponibles : Unified diff