Révision 3294
trunk/org.txm.texts.rcp/src/org/txm/texts/rcp/TextViewColumnLabelProvider.java (revision 3294) | ||
---|---|---|
1 |
package org.txm.texts.rcp; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import org.eclipse.jface.viewers.ColumnLabelProvider; |
|
7 |
import org.txm.objects.Text; |
|
8 |
|
|
9 |
|
|
10 |
public class TextViewColumnLabelProvider extends ColumnLabelProvider { |
|
11 |
|
|
12 |
int n; |
|
13 |
TextsViewEditor editor; |
|
14 |
|
|
15 |
public TextViewColumnLabelProvider(TextsViewEditor editor, int n) { |
|
16 |
this.n = n; |
|
17 |
this.editor = editor; |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public String getText(Object element) { |
|
22 |
|
|
23 |
Text text = (Text)element; |
|
24 |
return editor.getResult().getLines().get(text.getName()).get(n); |
|
25 |
} |
|
26 |
} |
|
0 | 27 |
trunk/org.txm.texts.rcp/src/org/txm/texts/rcp/TextsViewEditor.java (revision 3294) | ||
---|---|---|
1 |
package org.txm.texts.rcp; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.LinkedHashMap; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import org.eclipse.jface.viewers.ColumnLabelProvider; |
|
9 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
|
10 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
|
11 |
import org.eclipse.jface.viewers.ISelection; |
|
12 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
13 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
14 |
import org.eclipse.jface.viewers.TableViewer; |
|
15 |
import org.eclipse.jface.viewers.TableViewerColumn; |
|
16 |
import org.eclipse.jface.viewers.ViewerComparator; |
|
17 |
import org.eclipse.swt.SWT; |
|
18 |
import org.eclipse.swt.graphics.Image; |
|
19 |
import org.eclipse.swt.layout.GridData; |
|
20 |
import org.eclipse.swt.layout.GridLayout; |
|
21 |
import org.eclipse.swt.widgets.TableColumn; |
|
22 |
import org.txm.core.results.Parameter; |
|
23 |
import org.txm.edition.rcp.handlers.OpenEdition; |
|
24 |
import org.txm.objects.Text; |
|
25 |
import org.txm.rcp.IImageKeys; |
|
26 |
import org.txm.rcp.editors.TXMEditor; |
|
27 |
import org.txm.rcp.editors.TableKeyListener; |
|
28 |
import org.txm.rcp.editors.listeners.ComputeSelectionListener; |
|
29 |
import org.txm.rcp.swt.widget.PropertiesSelector; |
|
30 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
31 |
import org.txm.texts.core.TextsView; |
|
32 |
|
|
33 |
|
|
34 |
public class TextsViewEditor extends TXMEditor<TextsView> { |
|
35 |
|
|
36 |
@Parameter(key = "columns") |
|
37 |
PropertiesSelector<StructuralUnitProperty> propertiesSelector; |
|
38 |
|
|
39 |
TableViewer viewer; |
|
40 |
// HashMap<String, TableViewerColumn> columns = new HashMap<String, TableViewerColumn>(); |
|
41 |
|
|
42 |
@Override |
|
43 |
public void _createPartControl() throws Exception { |
|
44 |
|
|
45 |
this.getParent().setLayout(new GridLayout(1, true)); |
|
46 |
|
|
47 |
propertiesSelector = new PropertiesSelector<>(this.getMainParametersComposite()); |
|
48 |
ArrayList<StructuralUnitProperty> properties = new ArrayList<>(getResult().getCorpus().getStructuralUnitProperties("text")); |
|
49 |
for (int i = 0 ; i < properties.size() ; i++) { |
|
50 |
if (properties.get(i).getName().equals("id")) { |
|
51 |
properties.remove(i); |
|
52 |
break; |
|
53 |
} |
|
54 |
} |
|
55 |
propertiesSelector.setProperties(properties); |
|
56 |
ComputeSelectionListener computeSelectionListener = new ComputeSelectionListener(this); |
|
57 |
propertiesSelector.addSelectionListener(computeSelectionListener); |
|
58 |
|
|
59 |
viewer = new TableViewer(this.getResultArea(), SWT.NONE); |
|
60 |
viewer.getTable().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); |
|
61 |
viewer.getTable().setHeaderVisible(true); |
|
62 |
viewer.getTable().setLinesVisible(true); |
|
63 |
viewer.getTable().addKeyListener(new TableKeyListener(viewer)); |
|
64 |
|
|
65 |
viewer.setContentProvider(new IStructuredContentProvider() { |
|
66 |
|
|
67 |
@SuppressWarnings("rawtypes") |
|
68 |
@Override |
|
69 |
public Object[] getElements(Object inputElement) { |
|
70 |
|
|
71 |
if (inputElement instanceof List) { |
|
72 |
return ((List)inputElement).toArray(); |
|
73 |
} |
|
74 |
|
|
75 |
return null; |
|
76 |
} |
|
77 |
|
|
78 |
}); |
|
79 |
|
|
80 |
viewer.setComparator(new ViewerComparator()); |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
public void updateResultFromEditor() { |
|
86 |
|
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public void updateEditorFromResult(boolean update) throws Exception { |
|
91 |
|
|
92 |
|
|
93 |
TextsView tv = getResult(); |
|
94 |
if (viewer.getTable().getColumns().length == 0 || viewer.getTable().getColumns().length != tv.getColumns().size()) { |
|
95 |
if (viewer.getTable().getColumns().length > 0) { |
|
96 |
for (TableColumn column : viewer.getTable().getColumns()) { |
|
97 |
column.dispose(); |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
TableViewerColumn c = new TableViewerColumn(viewer, SWT.NONE); |
|
102 |
TableColumn textColumn = c.getColumn(); |
|
103 |
textColumn.setText("Text"); |
|
104 |
textColumn.setToolTipText("Text"); |
|
105 |
textColumn.setWidth(200); |
|
106 |
c.setLabelProvider(new ColumnLabelProvider() { |
|
107 |
@Override |
|
108 |
public String getText(Object element) { |
|
109 |
Text text = (Text)element; |
|
110 |
return text.getName(); |
|
111 |
} |
|
112 |
}); |
|
113 |
|
|
114 |
c = new TableViewerColumn(viewer, SWT.NONE); |
|
115 |
TableColumn editionColumn = c.getColumn(); |
|
116 |
editionColumn.setText("Edition"); |
|
117 |
editionColumn.setToolTipText("Edition"); |
|
118 |
editionColumn.setWidth(65); |
|
119 |
c.setLabelProvider(new ColumnLabelProvider() { |
|
120 |
@Override |
|
121 |
public Image getImage(Object element) { |
|
122 |
Text text = (Text)element; |
|
123 |
TextsViewEditor.this.getResult().getLines().get(text.getName()); |
|
124 |
if (text.getEditions().size() > 0) { |
|
125 |
return IImageKeys.getImage(IImageKeys.EDITION); |
|
126 |
} else { |
|
127 |
return null; |
|
128 |
} |
|
129 |
} |
|
130 |
@Override |
|
131 |
public String getText(Object element) { |
|
132 |
return null; |
|
133 |
} |
|
134 |
}); |
|
135 |
|
|
136 |
c = new TableViewerColumn(viewer, SWT.NONE); |
|
137 |
TableColumn separatorColumn = c.getColumn(); |
|
138 |
separatorColumn.setText(" "); |
|
139 |
separatorColumn.setWidth(2); |
|
140 |
c.getColumn().setResizable(false); |
|
141 |
c.setLabelProvider(new ColumnLabelProvider() { |
|
142 |
@Override |
|
143 |
public String getText(Object element) { |
|
144 |
return ""; |
|
145 |
} |
|
146 |
}); |
|
147 |
|
|
148 |
int nColumn = 0; |
|
149 |
for (StructuralUnitProperty col : this.getResult().getColumns()) { |
|
150 |
c = new TableViewerColumn(viewer, SWT.NONE); |
|
151 |
TableColumn newColumn = c.getColumn(); |
|
152 |
newColumn.setText(col.getName()); |
|
153 |
newColumn.setData(nColumn); |
|
154 |
newColumn.setToolTipText(col.getFullName()); |
|
155 |
newColumn.setWidth(100); |
|
156 |
c.setLabelProvider(new TextViewColumnLabelProvider(this, nColumn)); |
|
157 |
nColumn++; |
|
158 |
} |
|
159 |
|
|
160 |
} |
|
161 |
// |
|
162 |
viewer.setInput(getResult().getCorpus().getProject().getTexts()); |
|
163 |
|
|
164 |
viewer.addDoubleClickListener(new IDoubleClickListener() { |
|
165 |
|
|
166 |
@Override |
|
167 |
public void doubleClick(DoubleClickEvent event) { |
|
168 |
ISelection sel = viewer.getSelection(); |
|
169 |
StructuredSelection ssel = (StructuredSelection)sel; |
|
170 |
Object o = ssel.getFirstElement(); |
|
171 |
if (o != null && o instanceof Text) { |
|
172 |
OpenEdition.openEdition(getResult().getCorpus(), new String[] {getResult().getProject().getDefaultEditionName()}, ((Text)o).getName()); |
|
173 |
} |
|
174 |
} |
|
175 |
}); |
|
176 |
} |
|
177 |
} |
|
0 | 178 |
trunk/org.txm.texts.rcp/src/org/txm/texts/rcp/TextsViewAdapterFactory.java (revision 3294) | ||
---|---|---|
1 |
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté |
|
2 |
package org.txm.texts.rcp; |
|
3 |
|
|
4 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
5 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
6 |
import org.osgi.framework.FrameworkUtil; |
|
7 |
import org.txm.rcp.adapters.TXMResultAdapter; |
|
8 |
import org.txm.rcp.adapters.TXMResultAdapterFactory; |
|
9 |
import org.txm.texts.core.TextsView; |
|
10 |
|
|
11 |
|
|
12 |
/** |
|
13 |
* A factory for creating Adapter objects. |
|
14 |
* |
|
15 |
* @author mdecorde |
|
16 |
*/ |
|
17 |
public class TextsViewAdapterFactory extends TXMResultAdapterFactory { |
|
18 |
|
|
19 |
|
|
20 |
public static final ImageDescriptor ICON = AbstractUIPlugin.imageDescriptorFromPlugin(FrameworkUtil.getBundle(TextsViewAdapterFactory.class).getSymbolicName(), |
|
21 |
"platform:/plugin/org.txm.rcp/icons/objects/books.png"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
22 |
|
|
23 |
@Override |
|
24 |
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { |
|
25 |
if (this.canAdapt(adapterType) && adaptableObject instanceof TextsView) { |
|
26 |
return adapterType.cast(new TXMResultAdapter() { |
|
27 |
|
|
28 |
@Override |
|
29 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
30 |
return ICON; |
|
31 |
} |
|
32 |
}); |
|
33 |
} |
|
34 |
return null; |
|
35 |
} |
|
36 |
} |
|
0 | 37 |
trunk/org.txm.texts.rcp/src/org/txm/texts/rcp/ComputeTextView.java (revision 3294) | ||
---|---|---|
1 |
package org.txm.texts.rcp; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.ExecutionEvent; |
|
4 |
import org.eclipse.core.commands.ExecutionException; |
|
5 |
import org.txm.core.preferences.TXMPreferences; |
|
6 |
import org.txm.rcp.editors.TXMEditor; |
|
7 |
import org.txm.rcp.handlers.BaseAbstractHandler; |
|
8 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
9 |
import org.txm.texts.core.TextsView; |
|
10 |
|
|
11 |
public class ComputeTextView extends BaseAbstractHandler { |
|
12 |
|
|
13 |
@Override |
|
14 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
15 |
|
|
16 |
if (!this.checkCorpusEngine()) { |
|
17 |
return false; |
|
18 |
} |
|
19 |
|
|
20 |
TextsView concordance = null; |
|
21 |
|
|
22 |
// From link: creating from parameter node |
|
23 |
String parametersNodePath = event.getParameter(TXMPreferences.RESULT_PARAMETERS_NODE_PATH); |
|
24 |
if (parametersNodePath != null && !parametersNodePath.isEmpty()) { |
|
25 |
concordance = new TextsView(parametersNodePath); |
|
26 |
} |
|
27 |
// From view result node |
|
28 |
else { |
|
29 |
Object selection = this.getCorporaViewSelectedObject(event); |
|
30 |
|
|
31 |
// Creating from Corpus |
|
32 |
if (selection instanceof MainCorpus) { |
|
33 |
MainCorpus corpus = (MainCorpus) selection; |
|
34 |
concordance = new TextsView(corpus); |
|
35 |
} |
|
36 |
// Reopening existing result |
|
37 |
else if (selection instanceof TextsView) { |
|
38 |
concordance = (TextsView) selection; |
|
39 |
} |
|
40 |
// Error |
|
41 |
else { |
|
42 |
return this.logCanNotExecuteCommand(selection); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
openEditor(concordance); |
|
47 |
return null; |
|
48 |
} |
|
49 |
|
|
50 |
public static TXMEditor<TextsView> openEditor(TextsView view) { |
|
51 |
return TXMEditor.openEditor(view, TextsViewEditor.class.getName()); |
|
52 |
} |
|
53 |
|
|
54 |
} |
|
0 | 55 |
trunk/org.txm.texts.rcp/build.properties (revision 3294) | ||
---|---|---|
1 |
source.. = src/ |
|
2 |
output.. = bin/ |
|
3 |
bin.includes = META-INF/,\ |
|
4 |
.,\ |
|
5 |
plugin.xml |
|
0 | 6 |
trunk/org.txm.texts.rcp/plugin.xml (revision 3294) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
<extension |
|
5 |
point="org.eclipse.ui.commands"> |
|
6 |
<command |
|
7 |
defaultHandler="org.txm.texts.rcp.ComputeTextView" |
|
8 |
id="org.txm.texts.rcp.ComputeTextView" |
|
9 |
name="Texts" |
|
10 |
returnTypeId="org.txm.texts.core.TextsView"> |
|
11 |
</command> |
|
12 |
</extension> |
|
13 |
<extension |
|
14 |
point="org.eclipse.ui.menus"> |
|
15 |
<menuContribution |
|
16 |
locationURI="menu:menu.corpus"> |
|
17 |
<command |
|
18 |
commandId="org.txm.texts.rcp.ComputeTextView" |
|
19 |
icon="platform:/plugin/org.txm.rcp/icons/objects/books.png" |
|
20 |
style="push" |
|
21 |
tooltip="%command.name"> |
|
22 |
<visibleWhen |
|
23 |
checkEnabled="false"> |
|
24 |
<or> |
|
25 |
<reference |
|
26 |
definitionId="OneMainCorpusSelected"> |
|
27 |
</reference> |
|
28 |
</or> |
|
29 |
</visibleWhen> |
|
30 |
</command> |
|
31 |
</menuContribution> |
|
32 |
<menuContribution |
|
33 |
allPopups="false" |
|
34 |
locationURI="toolbar:org.txm.rcp.toolbarcorpus"> |
|
35 |
<command |
|
36 |
commandId="org.txm.texts.rcp.ComputeTextView" |
|
37 |
icon="platform:/plugin/org.txm.rcp/icons/objects/books.png" |
|
38 |
style="push" |
|
39 |
tooltip="%command.name"> |
|
40 |
<visibleWhen |
|
41 |
checkEnabled="false"> |
|
42 |
<or> |
|
43 |
<reference |
|
44 |
definitionId="OneMainCorpusSelected"> |
|
45 |
</reference> |
|
46 |
</or> |
|
47 |
</visibleWhen> |
|
48 |
</command> |
|
49 |
</menuContribution> |
|
50 |
<menuContribution |
|
51 |
allPopups="false" |
|
52 |
locationURI="popup:org.txm.rcp.views.corpora.CorporaView"> |
|
53 |
<command |
|
54 |
commandId="org.txm.texts.rcp.ComputeTextView" |
|
55 |
icon="platform:/plugin/org.txm.rcp/icons/objects/books.png" |
|
56 |
style="push" |
|
57 |
tooltip="%command.name"> |
|
58 |
<visibleWhen |
|
59 |
checkEnabled="false"> |
|
60 |
<or> |
|
61 |
<reference |
|
62 |
definitionId="OneMainCorpusSelected"> |
|
63 |
</reference> |
|
64 |
</or> |
|
65 |
</visibleWhen> |
|
66 |
</command> |
|
67 |
</menuContribution> |
|
68 |
</extension> |
|
69 |
<extension |
|
70 |
point="org.eclipse.ui.editors"> |
|
71 |
<editor |
|
72 |
class="org.txm.texts.rcp.TextsViewEditor" |
|
73 |
default="false" |
|
74 |
icon="platform:/plugin/org.txm.rcp/icons/objects/books.png" |
|
75 |
id="org.txm.texts.rcp.TextsViewEditor" |
|
76 |
name="Texts"> |
|
77 |
</editor> |
|
78 |
</extension> |
|
79 |
<extension |
|
80 |
point="org.eclipse.core.runtime.adapters"> |
|
81 |
<factory |
|
82 |
adaptableType="org.txm.texts.core.TextsView" |
|
83 |
class="org.txm.texts.rcp.TextsViewAdapterFactory"> |
|
84 |
<adapter |
|
85 |
type="org.eclipse.ui.model.IWorkbenchAdapter"> |
|
86 |
</adapter> |
|
87 |
</factory> |
|
88 |
</extension> |
|
89 |
|
|
90 |
</plugin> |
|
0 | 91 |
trunk/org.txm.texts.rcp/.settings/org.eclipse.jdt.core.prefs (revision 3294) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.8 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.8 |
|
0 | 8 |
trunk/org.txm.texts.rcp/.classpath (revision 3294) | ||
---|---|---|
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.8"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> |
|
5 |
<accessrules> |
|
6 |
<accessrule kind="accessible" pattern="**"/> |
|
7 |
</accessrules> |
|
8 |
</classpathentry> |
|
9 |
<classpathentry kind="src" path="src"/> |
|
10 |
<classpathentry kind="output" path="bin"/> |
|
11 |
</classpath> |
|
0 | 12 |
trunk/org.txm.texts.rcp/META-INF/MANIFEST.MF (revision 3294) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: org.txm.texts.rcp |
|
4 |
Bundle-SymbolicName: org.txm.texts.rcp;singleton:=true |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Automatic-Module-Name: org.txm.texts.rcp |
|
7 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 |
|
8 |
Require-Bundle: org.txm.rcp;bundle-version="0.8.2", |
|
9 |
org.txm.texts.core;bundle-version="1.0.0", |
|
10 |
org.txm.edition.rcp;bundle-version="1.0.0" |
|
11 |
Export-Package: org.txm.texts.rcp |
|
0 | 12 |
trunk/org.txm.texts.rcp/.project (revision 3294) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.texts.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 |
trunk/org.txm.texts.core/.settings/org.eclipse.jdt.core.prefs (revision 3294) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.8 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.8 |
|
0 | 8 |
trunk/org.txm.texts.core/.classpath (revision 3294) | ||
---|---|---|
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.8"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> |
|
5 |
<accessrules> |
|
6 |
<accessrule kind="accessible" pattern="**"/> |
|
7 |
</accessrules> |
|
8 |
</classpathentry> |
|
9 |
<classpathentry kind="src" path="src"/> |
|
10 |
<classpathentry kind="output" path="bin"/> |
|
11 |
</classpath> |
|
0 | 12 |
trunk/org.txm.texts.core/META-INF/MANIFEST.MF (revision 3294) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: org.txm.texts.core |
|
4 |
Bundle-SymbolicName: org.txm.texts.core;singleton:=true |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Automatic-Module-Name: org.txm.texts.core |
|
7 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 |
|
8 |
Require-Bundle: org.txm.core;bundle-version="0.8.2";visibility:=reexport, |
|
9 |
org.txm.searchengine.core;bundle-version="1.0.0";visibility:=reexport, |
|
10 |
org.txm.utils.core;visibility:=reexport, |
|
11 |
org.txm.searchengine.cqp.core;visibility:=reexport |
|
12 |
Export-Package: org.txm.texts.core |
|
0 | 13 |
trunk/org.txm.texts.core/.project (revision 3294) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.texts.core</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 |
trunk/org.txm.texts.core/src/org/txm/texts/core/TextsView.java (revision 3294) | ||
---|---|---|
1 |
package org.txm.texts.core; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.PrintWriter; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.LinkedHashMap; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
import org.apache.commons.lang.StringUtils; |
|
10 |
import org.eclipse.osgi.util.NLS; |
|
11 |
import org.txm.core.results.Parameter; |
|
12 |
import org.txm.core.results.TXMParameters; |
|
13 |
import org.txm.core.results.TXMResult; |
|
14 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
15 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
16 |
import org.txm.searchengine.cqp.corpus.Property; |
|
17 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
18 |
import org.txm.utils.TXMProgressMonitor; |
|
19 |
import org.txm.utils.logger.Log; |
|
20 |
|
|
21 |
public class TextsView extends TXMResult { |
|
22 |
|
|
23 |
@Parameter(key = "columns") |
|
24 |
ArrayList<StructuralUnitProperty> pColumns; |
|
25 |
|
|
26 |
private LinkedHashMap<String, ArrayList<String>> result; |
|
27 |
|
|
28 |
public MainCorpus getCorpus() { |
|
29 |
return (MainCorpus)parent; |
|
30 |
} |
|
31 |
|
|
32 |
public TextsView(MainCorpus corpus) { |
|
33 |
|
|
34 |
super(corpus); |
|
35 |
} |
|
36 |
|
|
37 |
public TextsView(String parametersNodePath) { |
|
38 |
|
|
39 |
super(parametersNodePath); |
|
40 |
} |
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
@Override |
|
45 |
public boolean saveParameters() throws Exception { |
|
46 |
|
|
47 |
this.saveParameter("columns", StringUtils.join(pColumns, "\t")); |
|
48 |
return true; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public boolean loadParameters() throws Exception { |
|
53 |
|
|
54 |
String v = this.getStringParameterValue("columns").toString(); |
|
55 |
if ("*".equals(v)) { |
|
56 |
; |
|
57 |
this.pColumns = new ArrayList<>(getCorpus().getStructuralUnit("text").getUserDefinedOrderedProperties()); |
|
58 |
for (int i = 0 ; i < pColumns.size() ; i++) { |
|
59 |
if (pColumns.get(i).getName().equals("id")) { |
|
60 |
pColumns.remove(i); |
|
61 |
break; |
|
62 |
} |
|
63 |
} |
|
64 |
} else { |
|
65 |
this.pColumns = new ArrayList(Property.stringToProperties(getCorpus(), v)); |
|
66 |
} |
|
67 |
|
|
68 |
return pColumns != null; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public boolean setParameters(TXMParameters parameters) throws Exception { |
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
if (parameters.get("columns") != null) { |
|
77 |
|
|
78 |
Object o = parameters.get("columns"); |
|
79 |
if (o instanceof List) { |
|
80 |
pColumns = new ArrayList((List)o); |
|
81 |
} else { |
|
82 |
String v = parameters.get("columns").toString(); |
|
83 |
if ("*".equals(v)) { |
|
84 |
this.pColumns = new ArrayList<>(getCorpus().getStructuralUnit("text").getUserDefinedOrderedProperties()); |
|
85 |
} else { |
|
86 |
this.pColumns = new ArrayList(Property.stringToProperties(getCorpus(), v)); |
|
87 |
} |
|
88 |
} |
|
89 |
return true; |
|
90 |
} |
|
91 |
return false; |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public String getName() { |
|
96 |
|
|
97 |
return "Texts ("+pColumns.toString()+")"; |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
public String getSimpleName() { |
|
102 |
|
|
103 |
return "Texts"; |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public String getDetails() { |
|
108 |
|
|
109 |
return getName(); |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public void clean() { |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public boolean canCompute() throws Exception { |
|
119 |
|
|
120 |
return pColumns != null; |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
protected boolean _compute(TXMProgressMonitor monitor) throws Exception { |
|
125 |
|
|
126 |
result = new LinkedHashMap<String, ArrayList<String>>(); |
|
127 |
|
|
128 |
// preset arrays |
|
129 |
String[] texts = getCorpus().getCorpusTextIdsList(); |
|
130 |
for (String t : texts) { |
|
131 |
ArrayList<String> values = new ArrayList<String>(); |
|
132 |
result.put(t, values); |
|
133 |
|
|
134 |
if (getCorpus().getProject().getText(t) == null) { |
|
135 |
Log.warning(NLS.bind("The {0} Corpus has no text named ''{1}''.", getCorpus(), t)); |
|
136 |
return false; |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
// optimization: get values property per property then set the Text property value arrays |
|
141 |
int positions [] = new int[texts.length]; |
|
142 |
for (int i = 0 ; i < texts.length ; i++) { |
|
143 |
positions[i] = i; |
|
144 |
} |
|
145 |
for (int icol = 0 ; icol < pColumns.size() ; icol++) { |
|
146 |
StructuralUnitProperty col = pColumns.get(icol); |
|
147 |
|
|
148 |
String[] values = CQPSearchEngine.getCqiClient().struc2Str(col.getQualifiedName(), positions); |
|
149 |
|
|
150 |
for (int i = 0 ; i < texts.length ; i++) { |
|
151 |
result.get(texts[i]).add( values[i]); |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
return true; |
|
156 |
} |
|
157 |
|
|
158 |
@Override |
|
159 |
protected boolean _toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception { |
|
160 |
|
|
161 |
PrintWriter writer = org.txm.utils.io.IOUtils.getWriter(outfile, encoding); |
|
162 |
writer.println("text"+colseparator+StringUtils.join(pColumns, colseparator)); |
|
163 |
|
|
164 |
for (String text : result.keySet()) { |
|
165 |
writer.println(text+colseparator+StringUtils.join(result.get(text), colseparator)); |
|
166 |
} |
|
167 |
|
|
168 |
writer.close(); |
|
169 |
return false; |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public String getResultType() { |
|
174 |
return "TextView"; |
|
175 |
} |
|
176 |
|
|
177 |
public LinkedHashMap<String, ArrayList<String>> getLines() { |
|
178 |
return result; |
|
179 |
} |
|
180 |
|
|
181 |
public List<StructuralUnitProperty> getColumns() { |
|
182 |
|
|
183 |
return pColumns; |
|
184 |
} |
|
185 |
|
|
186 |
} |
|
0 | 187 |
trunk/org.txm.texts.core/src/org/txm/texts/core/TextsViewPreferences.java (revision 3294) | ||
---|---|---|
1 |
package org.txm.texts.core; |
|
2 |
|
|
3 |
import org.osgi.service.prefs.Preferences; |
|
4 |
import org.txm.core.preferences.TXMPreferences; |
|
5 |
|
|
6 |
public class TextsViewPreferences extends TXMPreferences { |
|
7 |
|
|
8 |
/** |
|
9 |
* Gets the instance. |
|
10 |
* |
|
11 |
* @return the instance |
|
12 |
*/ |
|
13 |
public static TXMPreferences getInstance() { |
|
14 |
if (!TXMPreferences.instances.containsKey(TextsViewPreferences.class)) { |
|
15 |
new TextsViewPreferences(); |
|
16 |
} |
|
17 |
return TXMPreferences.instances.get(TextsViewPreferences.class); |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public void initializeDefaultPreferences() { |
|
22 |
super.initializeDefaultPreferences(); |
|
23 |
|
|
24 |
Preferences preferences = this.getDefaultPreferencesNode(); |
|
25 |
|
|
26 |
preferences.put("columns", "*"); |
|
27 |
} |
|
28 |
} |
|
0 | 29 |
trunk/org.txm.texts.core/build.properties (revision 3294) | ||
---|---|---|
1 |
source.. = src/ |
|
2 |
output.. = bin/ |
|
3 |
bin.includes = META-INF/,\ |
|
4 |
.,\ |
|
5 |
plugin.xml |
|
0 | 6 |
trunk/org.txm.texts.core/plugin.xml (revision 3294) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
<extension |
|
5 |
point="org.eclipse.core.runtime.preferences"> |
|
6 |
<initializer |
|
7 |
class="org.txm.texts.core.TextsViewPreferences"> |
|
8 |
</initializer> |
|
9 |
</extension> |
|
10 |
|
|
11 |
</plugin> |
|
0 | 12 |
Formats disponibles : Unified diff