Révision 2245
tmp/org.txm.rcp/src/main/java/org/eclipse/jface/fieldassist/TXMAutoCompleteField.java (revision 2245) | ||
---|---|---|
3 | 3 |
import java.util.ArrayList; |
4 | 4 |
|
5 | 5 |
import org.eclipse.jface.bindings.keys.KeyStroke; |
6 |
import org.eclipse.swt.events.SelectionListener; |
|
6 | 7 |
import org.eclipse.swt.widgets.Control; |
7 | 8 |
|
8 | 9 |
/** |
... | ... | |
61 | 62 |
proposalProvider = new TXMSimpleContentProposalProvider(proposals); |
62 | 63 |
proposalProvider.setFiltering(true); |
63 | 64 |
|
64 |
adapter = new TXMContentProposalAdapter(control, controlContentAdapter, |
|
65 |
proposalProvider, keyStroke, autoActivationCharacters); |
|
65 |
adapter = new TXMContentProposalAdapter(control, controlContentAdapter, proposalProvider, keyStroke, autoActivationCharacters); |
|
66 | 66 |
adapter.setPropagateKeys(true); |
67 | 67 |
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); |
68 | 68 |
adapter.addContentProposalListener(new IContentProposalListener2() { |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 2245) | ||
---|---|---|
98 | 98 |
* @author sjacquot |
99 | 99 |
* |
100 | 100 |
*/ |
101 |
public abstract class TXMEditor<T extends TXMResult> extends EditorPart { |
|
101 |
public abstract class TXMEditor<T extends TXMResult> extends EditorPart implements ITXMResultEditor<T> {
|
|
102 | 102 |
|
103 | 103 |
/** |
104 | 104 |
* ID to use in plugin.xml to contribute to the top toolbar. |
... | ... | |
825 | 825 |
* |
826 | 826 |
* @param result |
827 | 827 |
* @param update force the editor to update its result parameters |
828 |
* @param editor |
|
829 |
* @param chartsComponentsProvider |
|
830 |
* @param resetView |
|
831 |
* @param clearChartItemsSelection |
|
832 | 828 |
*/ |
833 | 829 |
public JobHandler compute(final boolean update) { |
834 | 830 |
|
... | ... | |
1096 | 1092 |
List<TXMResult> results = this.getResult().getDeepChildren(); |
1097 | 1093 |
|
1098 | 1094 |
for (int i = 0; i < results.size(); i++) { |
1099 |
ArrayList<TXMEditor> editors = SWTEditorsUtils.getEditors(results.get(i)) ;
|
|
1095 |
ArrayList<ITXMResultEditor<?>> editors = SWTEditorsUtils.getEditors(results.get(i)) ;
|
|
1100 | 1096 |
for (int j = 0; j < editors.size(); j++) { |
1101 |
TXMEditor txmEditor = editors.get(j);
|
|
1097 |
ITXMResultEditor<?> txmEditor = editors.get(j);
|
|
1102 | 1098 |
if(txmEditor != this |
1103 | 1099 |
//&& txmEditor.isDirty() |
1104 | 1100 |
) { |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/ITXMResultEditor.java (revision 2245) | ||
---|---|---|
1 |
package org.txm.rcp.editors; |
|
2 |
|
|
3 |
import org.eclipse.swt.widgets.Composite; |
|
4 |
import org.eclipse.ui.IEditorPart; |
|
5 |
import org.txm.core.results.TXMResult; |
|
6 |
import org.txm.rcp.utils.JobHandler; |
|
7 |
|
|
8 |
public interface ITXMResultEditor<T extends TXMResult> extends IEditorPart { |
|
9 |
public T getResult(); |
|
10 |
|
|
11 |
/** |
|
12 |
* Computes the TXMResult if all required parameters are set then refreshes the editor UI. |
|
13 |
* Also loads and saves some parameters from result to Widgets fields and from Widgets fields to result. |
|
14 |
* |
|
15 |
* @param result |
|
16 |
* @param update force the editor to update its result parameters |
|
17 |
*/ |
|
18 |
public JobHandler compute(boolean update); |
|
19 |
|
|
20 |
public void refresh(boolean update) throws Exception; |
|
21 |
|
|
22 |
/** |
|
23 |
* |
|
24 |
* @return the editor main composite |
|
25 |
*/ |
|
26 |
public Composite getContainer(); |
|
27 |
|
|
28 |
public void close(); |
|
29 |
|
|
30 |
/** |
|
31 |
* Closes the editor from the UI thread and deletes or not the linked result. |
|
32 |
*/ |
|
33 |
public void close(boolean deleteResult); |
|
34 |
|
|
35 |
/** |
|
36 |
* lock/unlock the editor's result |
|
37 |
* @param locked |
|
38 |
*/ |
|
39 |
public void setLocked(boolean locked); |
|
40 |
} |
|
0 | 41 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMMultiPageEditor.java (revision 2245) | ||
---|---|---|
36 | 36 |
import org.eclipse.ui.IEditorPart; |
37 | 37 |
import org.eclipse.ui.part.EditorPart; |
38 | 38 |
import org.eclipse.ui.part.MultiPageEditorPart; |
39 |
import org.txm.core.results.TXMResult; |
|
40 |
import org.txm.rcp.utils.JobHandler; |
|
39 | 41 |
|
40 | 42 |
/** |
41 | 43 |
* |
... | ... | |
46 | 48 |
*/ |
47 | 49 |
//FIXME: SJ: this class leads to a lot of problem : focus, activation, etc. find a way to stop to use it. It actually used only for the CA at this moment. |
48 | 50 |
@Deprecated |
49 |
public abstract class TXMMultiPageEditor extends MultiPageEditorPart {
|
|
51 |
public abstract class TXMMultiPageEditor<T extends TXMResult> extends MultiPageEditorPart implements ITXMResultEditor<T>{
|
|
50 | 52 |
|
51 | 53 |
/** The Constant ID. */ |
52 | 54 |
public static final String ID = "org.txm.rcp.editors.GenericMultiPageEditor"; //$NON-NLS-1$ |
... | ... | |
207 | 209 |
super.setPartName(partName); |
208 | 210 |
} |
209 | 211 |
|
212 |
@Override |
|
213 |
public JobHandler compute(boolean update) { |
|
214 |
JobHandler job = null; |
|
215 |
for (EditorPart editor : editors) { |
|
216 |
if (editor instanceof ITXMResultEditor) { |
|
217 |
job = ((ITXMResultEditor) editor).compute(update); |
|
218 |
} |
|
219 |
} |
|
220 |
return job; |
|
221 |
} |
|
222 |
|
|
223 |
@Override |
|
224 |
public void refresh(boolean update) throws Exception { |
|
225 |
for (EditorPart editor : editors) { |
|
226 |
if (editor instanceof ITXMResultEditor) { |
|
227 |
((ITXMResultEditor) editor).refresh(update); |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
210 | 231 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMFormEditor.java (revision 2245) | ||
---|---|---|
1 |
package org.txm.rcp.editors; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
4 |
import org.eclipse.swt.widgets.Composite; |
|
5 |
import org.eclipse.ui.forms.editor.FormEditor; |
|
6 |
import org.txm.core.results.TXMResult; |
|
7 |
import org.txm.rcp.utils.JobHandler; |
|
8 |
|
|
9 |
/** |
|
10 |
* Editor to see a TXMResult from different point of views |
|
11 |
* |
|
12 |
* @author mdecorde |
|
13 |
* |
|
14 |
* @param <T> the TXMResult class to be seen |
|
15 |
*/ |
|
16 |
public abstract class TXMFormEditor<T extends TXMResult> extends FormEditor implements ITXMResultEditor<T>{ |
|
17 |
|
|
18 |
protected T result; |
|
19 |
|
|
20 |
@Override |
|
21 |
public T getResult() { |
|
22 |
return result; |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public JobHandler compute(boolean update) { |
|
27 |
for (Object page : pages) { |
|
28 |
if (page instanceof ITXMResultEditor) { |
|
29 |
return ((ITXMResultEditor)page).compute(update); |
|
30 |
} |
|
31 |
} |
|
32 |
return null; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public void refresh(boolean update) throws Exception { |
|
37 |
for (Object page : pages) { |
|
38 |
if (page instanceof ITXMResultEditor) { |
|
39 |
((ITXMResultEditor)page).refresh(update); |
|
40 |
} |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void close() { |
|
46 |
for (Object page : pages) { |
|
47 |
if (page instanceof ITXMResultEditor) { |
|
48 |
((ITXMResultEditor)page).close(); |
|
49 |
} |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public void close(boolean deleteResult) { |
|
55 |
for (Object page : pages) { |
|
56 |
if (page instanceof ITXMResultEditor) { |
|
57 |
((ITXMResultEditor)page).close(deleteResult); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public void setLocked(boolean locked) { |
|
64 |
for (Object page : pages) { |
|
65 |
if (page instanceof ITXMResultEditor) { |
|
66 |
((ITXMResultEditor)page).setLocked(locked); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public void doSave(IProgressMonitor monitor) { |
|
73 |
for (Object page : pages) { |
|
74 |
if (page instanceof ITXMResultEditor) { |
|
75 |
((ITXMResultEditor)page).doSave(monitor); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public void doSaveAs() { |
|
82 |
for (Object page : pages) { |
|
83 |
if (page instanceof ITXMResultEditor) { |
|
84 |
((ITXMResultEditor)page).doSaveAs(); |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public boolean isSaveAsAllowed() { |
|
91 |
boolean saveAllowed = true; |
|
92 |
for (Object page : pages) { |
|
93 |
if (page instanceof ITXMResultEditor) { |
|
94 |
saveAllowed = saveAllowed && ((ITXMResultEditor)page).isSaveAsAllowed(); |
|
95 |
} |
|
96 |
} |
|
97 |
return saveAllowed; |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* |
|
102 |
* @return the root composite of this multi paged editor |
|
103 |
*/ |
|
104 |
public Composite getContainer() { |
|
105 |
return super.getContainer(); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
0 | 109 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/results/SetTXMResultLockState.java (revision 2245) | ||
---|---|---|
34 | 34 |
import org.eclipse.ui.commands.IElementUpdater; |
35 | 35 |
import org.eclipse.ui.menus.UIElement; |
36 | 36 |
import org.txm.core.results.TXMResult; |
37 |
import org.txm.rcp.editors.ITXMResultEditor; |
|
37 | 38 |
import org.txm.rcp.editors.TXMEditor; |
38 | 39 |
import org.txm.rcp.handlers.BaseAbstractHandler; |
39 | 40 |
import org.txm.rcp.utils.SWTEditorsUtils; |
... | ... | |
62 | 63 |
|
63 | 64 |
CorporaView.refresh(); |
64 | 65 |
//TODO should be done with a listener |
65 |
for (TXMEditor<?> editor : SWTEditorsUtils.getEditors()) {
|
|
66 |
for (ITXMResultEditor<?> editor : SWTEditorsUtils.getEditors()) {
|
|
66 | 67 |
editor.setLocked(editor.getResult().isLocked()); |
67 | 68 |
} |
68 | 69 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/results/DeleteObject.java (revision 2245) | ||
---|---|---|
35 | 35 |
import org.eclipse.core.commands.AbstractHandler; |
36 | 36 |
import org.eclipse.core.commands.ExecutionEvent; |
37 | 37 |
import org.eclipse.core.commands.ExecutionException; |
38 |
import org.eclipse.core.resources.IProject; |
|
39 |
import org.eclipse.core.runtime.CoreException; |
|
38 | 40 |
import org.eclipse.core.runtime.IProgressMonitor; |
39 | 41 |
import org.eclipse.core.runtime.IStatus; |
40 | 42 |
import org.eclipse.core.runtime.Status; |
... | ... | |
57 | 59 |
import org.txm.objects.CorpusBuild; |
58 | 60 |
import org.txm.objects.Project; |
59 | 61 |
import org.txm.rcp.StatusLine; |
62 |
import org.txm.rcp.editors.ITXMResultEditor; |
|
60 | 63 |
import org.txm.rcp.editors.TXMEditor; |
61 | 64 |
import org.txm.rcp.messages.TXMUIMessages; |
62 | 65 |
import org.txm.rcp.preferences.RCPPreferences; |
... | ... | |
66 | 69 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
67 | 70 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
68 | 71 |
import org.txm.searchengine.cqp.corpus.Partition; |
72 |
import org.txm.utils.LogMonitor; |
|
69 | 73 |
import org.txm.utils.logger.Log; |
70 | 74 |
|
71 | 75 |
/** |
... | ... | |
289 | 293 |
Log.info(NLS.bind(TXMUIMessages.deletedColonP0, o)); |
290 | 294 |
deleted.add(o); |
291 | 295 |
deleted.addAll(children); |
292 |
} |
|
293 |
else { |
|
296 |
} else if (o instanceof IProject) { |
|
297 |
try { |
|
298 |
((IProject)o).delete(true, new LogMonitor()); |
|
299 |
deleted.add(o); |
|
300 |
} catch (CoreException e) { |
|
301 |
// TODO Auto-generated catch block |
|
302 |
e.printStackTrace(); |
|
303 |
} |
|
304 |
} else { |
|
294 | 305 |
Log.severe(TXMCoreMessages.bind("Can not delete: {0}.", o)); |
295 | 306 |
} |
296 | 307 |
|
... | ... | |
307 | 318 |
if (!(o instanceof TXMResult)) { |
308 | 319 |
return; |
309 | 320 |
} |
310 |
|
|
321 |
|
|
311 | 322 |
TXMResult r = (TXMResult) o; |
312 | 323 |
List<TXMResult> all = new ArrayList<TXMResult>();//r.getDeepChildren(); |
313 | 324 |
all.add(r); |
314 | 325 |
if (children) { |
315 | 326 |
all.addAll(r.getDeepChildren()); |
316 | 327 |
} |
317 |
ArrayList<TXMEditor> editors = SWTEditorsUtils.getEditors();
|
|
328 |
ArrayList<ITXMResultEditor<?>> editors = SWTEditorsUtils.getEditors();
|
|
318 | 329 |
for (TXMResult tr : all) { // close editors of the result and its children |
319 |
for (TXMEditor<?> editor : editors) {
|
|
330 |
for (ITXMResultEditor<?> editor : editors) {
|
|
320 | 331 |
if (tr == editor.getResult()) { |
321 | 332 |
editor.getEditorSite().getPage().closeEditor(editor, true); |
322 | 333 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/files/CreateFolder.java (revision 2245) | ||
---|---|---|
101 | 101 |
System.out.println(NLS.bind(TXMUIMessages.newFolderColonP0, newfile.getAbsolutePath())); |
102 | 102 |
|
103 | 103 |
} |
104 |
Explorer.refresh(); |
|
105 |
MacroExplorer.refresh(); |
|
104 |
Explorer.refresh(newfile);
|
|
105 |
MacroExplorer.refresh(newfile);
|
|
106 | 106 |
|
107 | 107 |
return null; |
108 | 108 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/files/DeleteFile.java (revision 2245) | ||
---|---|---|
78 | 78 |
int buttonID = dialog.open(); |
79 | 79 |
switch(buttonID) { |
80 | 80 |
case SWT.YES: |
81 |
File parentFile = file.getParentFile(); |
|
81 | 82 |
if (file.isFile()) { |
82 | 83 |
if (!file.delete()) System.out.println(NLS.bind(TXMUIMessages.failedToDeleteFileP0, file)); |
83 | 84 |
} else if (file.isDirectory()) { |
84 | 85 |
if (!DeleteDir.deleteDirectory(file)) System.out.println(NLS.bind(TXMUIMessages.failedToDeleteFileP0, file)); |
85 | 86 |
} |
86 |
Explorer.refresh(); |
|
87 |
MacroExplorer.refresh(); |
|
87 |
Explorer.refresh(parentFile);
|
|
88 |
MacroExplorer.refresh(parentFile);
|
|
88 | 89 |
case SWT.NO: |
89 | 90 |
// exits here ... |
90 | 91 |
break; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/files/CreateFile.java (revision 2245) | ||
---|---|---|
83 | 83 |
} |
84 | 84 |
useSavedValue = false; |
85 | 85 |
} |
86 |
|
|
87 | 86 |
} |
88 | 87 |
} |
89 | 88 |
} |
... | ... | |
91 | 90 |
//ask new file name |
92 | 91 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); |
93 | 92 |
FileDialog dialog = new FileDialog(shell, SWT.SAVE); |
93 |
|
|
94 | 94 |
if (LastOpened.getFile(ID) != null && useSavedValue) { |
95 | 95 |
dialog.setFilterPath(LastOpened.getFolder(ID)); |
96 | 96 |
dialog.setFileName(LastOpened.getFile(ID)); |
... | ... | |
115 | 115 |
} |
116 | 116 |
} |
117 | 117 |
EditFile.openfile(newfile); |
118 |
Explorer.refresh(); |
|
119 |
MacroExplorer.refresh(); |
|
118 |
Explorer.refresh(newfile.getParentFile());
|
|
119 |
MacroExplorer.refresh(newfile.getParentFile());
|
|
120 | 120 |
return null; |
121 | 121 |
} |
122 | 122 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/files/RenameFile.java (revision 2245) | ||
---|---|---|
75 | 75 |
if (newname.equals(file.getName())) return; // nothing to do |
76 | 76 |
if (newname == null || newname.trim().length() == 0) return; // error |
77 | 77 |
|
78 |
if (!file.renameTo(new File(file.getParentFile(), newname))) |
|
78 |
File nfile = new File(file.getParentFile(), newname); |
|
79 |
if (!file.renameTo(nfile)) |
|
79 | 80 |
System.out.println(TXMUIMessages.failedToRename+file+TXMUIMessages.to+newname); |
80 |
Explorer.refresh(); |
|
81 |
MacroExplorer.refresh(); |
|
81 |
Explorer.refresh(nfile);
|
|
82 |
MacroExplorer.refresh(nfile);
|
|
82 | 83 |
} |
83 | 84 |
} |
84 | 85 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/files/PasteFile.java (revision 2245) | ||
---|---|---|
68 | 68 |
|
69 | 69 |
public static void paste(File folder) { |
70 | 70 |
|
71 |
File dest = null; |
|
72 |
|
|
71 | 73 |
if (folder.isFile()) folder = folder.getParentFile(); |
72 | 74 |
if (folder.isDirectory() && folder.canWrite()) { |
73 | 75 |
if (CopyFile.toCopy != null) { |
74 | 76 |
File source = CopyFile.toCopy; |
75 | 77 |
if (source.isDirectory()) return; // don't copy directory |
76 | 78 |
|
77 |
File dest = new File(folder, source.getName());
|
|
79 |
dest = new File(folder, source.getName()); |
|
78 | 80 |
while (dest.exists()) { |
79 | 81 |
dest = new File(folder, "copy_"+dest.getName()); //$NON-NLS-1$ |
80 | 82 |
} |
... | ... | |
87 | 89 |
} else if (CutFile.toCut != null) { |
88 | 90 |
File source = CutFile.toCut; |
89 | 91 |
if (source.isDirectory()) return; // don't move directory |
90 |
File dest = new File(folder, source.getName());
|
|
92 |
dest = new File(folder, source.getName()); |
|
91 | 93 |
while (dest.exists()) { |
92 | 94 |
dest = new File(folder, "copy_"+dest.getName()); //$NON-NLS-1$ |
93 | 95 |
} |
... | ... | |
107 | 109 |
System.out.println("Coping files: "+StringUtils.join(Arrays.asList(paths), ", ")); |
108 | 110 |
for (String path : paths) { |
109 | 111 |
File source = new File(path); |
110 |
File dest = new File(folder, source.getName());
|
|
112 |
dest = new File(folder, source.getName()); |
|
111 | 113 |
while (dest.exists()) { |
112 | 114 |
dest = new File(folder, "copy_"+dest.getName()); //$NON-NLS-1$ |
113 | 115 |
} |
... | ... | |
127 | 129 |
} |
128 | 130 |
CopyFile.toCopy = null; |
129 | 131 |
CutFile.toCut = null; |
130 |
Explorer.refresh(); |
|
131 |
MacroExplorer.refresh(); |
|
132 |
Explorer.refresh(dest);
|
|
133 |
MacroExplorer.refresh(dest);
|
|
132 | 134 |
} |
133 | 135 |
} |
134 | 136 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/CreateMacro.java (revision 2245) | ||
---|---|---|
48 | 48 |
import org.txm.rcp.handlers.files.EditFile; |
49 | 49 |
import org.txm.rcp.messages.TXMUIMessages; |
50 | 50 |
import org.txm.rcp.swt.dialog.LastOpened; |
51 |
import org.txm.rcp.views.fileexplorer.Explorer; |
|
51 | 52 |
import org.txm.rcp.views.fileexplorer.MacroExplorer; |
52 | 53 |
import org.txm.utils.AsciiUtils; |
53 | 54 |
import org.txm.utils.io.IOUtils; |
... | ... | |
195 | 196 |
writer.close(); |
196 | 197 |
|
197 | 198 |
EditFile.openfile(newfile); |
198 |
//Explorer.refresh();
|
|
199 |
MacroExplorer.refresh(); |
|
199 |
Explorer.refresh(newfile);
|
|
200 |
MacroExplorer.refresh(newfile);
|
|
200 | 201 |
} |
201 | 202 |
} catch (IOException e) { |
202 | 203 |
System.out.println(e.getLocalizedMessage()); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/adapters/RCPProjectAdapterFactory.java (revision 2245) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
package org.txm.rcp.adapters; |
|
3 |
|
|
4 |
import org.eclipse.core.resources.IProject; |
|
5 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
6 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
|
7 |
import org.eclipse.ui.model.WorkbenchAdapter; |
|
8 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
9 |
import org.txm.rcp.Application; |
|
10 |
import org.txm.rcp.IImageKeys; |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* A factory for creating Adapter objects. |
|
15 |
* |
|
16 |
* @author mdecorde |
|
17 |
* @author sjacquot |
|
18 |
*/ |
|
19 |
public class RCPProjectAdapterFactory extends TXMResultAdapterFactory { |
|
20 |
|
|
21 |
@Override |
|
22 |
public Object getAdapter(Object adaptableObject, Class adapterType) { |
|
23 |
if(adapterType == IWorkbenchAdapter.class && adaptableObject instanceof IProject) { |
|
24 |
return new WorkbenchAdapter() { |
|
25 |
@Override |
|
26 |
public Object[] getChildren(Object o) { |
|
27 |
return new Object[0]; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
32 |
return AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, IImageKeys.PROJECT); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public String getLabel(Object o) { |
|
37 |
return ((IProject) o).getName(); |
|
38 |
} |
|
39 |
}; |
|
40 |
} |
|
41 |
return null; |
|
42 |
} |
|
43 |
} |
|
0 | 44 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/adapters/TXMResultAdapter.java (revision 2245) | ||
---|---|---|
34 | 34 |
|
35 | 35 |
@Override |
36 | 36 |
public Object[] getChildren(Object result) { |
37 |
if (!(result instanceof TXMResult)) { |
|
38 |
return new Object[0]; |
|
39 |
} |
|
37 | 40 |
return ((TXMResult) result).getChildren(!TBXPreferences.getInstance().getBoolean(TBXPreferences.SHOW_ALL_RESULT_NODES)).toArray(); |
38 | 41 |
} |
39 | 42 |
|
40 | 43 |
@Override |
41 | 44 |
public String getLabel(Object result) { |
45 |
if (!(result instanceof TXMResult)) { |
|
46 |
return result.toString(); |
|
47 |
} |
|
42 | 48 |
String label = ((TXMResult) result).getCurrentName(); |
43 | 49 |
|
44 | 50 |
// FIXME: SJ: doesn't work if a result has more than one editor opened |
... | ... | |
52 | 58 |
|
53 | 59 |
@Override |
54 | 60 |
public Object getParent(Object result) { |
55 |
return ((TXMResult) result).getParent(); |
|
61 |
if (result instanceof TXMResult) { |
|
62 |
return ((TXMResult) result).getParent(); |
|
63 |
} else { |
|
64 |
return null; |
|
65 |
} |
|
56 | 66 |
} |
57 | 67 |
|
58 | 68 |
@Override |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/adapters/ProjectAdapterFactory.java (revision 2245) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
package org.txm.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.txm.objects.Project; |
|
8 |
import org.txm.rcp.Application; |
|
9 |
import org.txm.rcp.IImageKeys; |
|
10 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* A factory for creating Adapter objects. |
|
15 |
* |
|
16 |
* @author mdecorde |
|
17 |
* @author sjacquot |
|
18 |
*/ |
|
19 |
public class ProjectAdapterFactory extends TXMResultAdapterFactory { |
|
20 |
|
|
21 |
@Override |
|
22 |
public Object getAdapter(Object adaptableObject, Class adapterType) { |
|
23 |
if(adapterType == IWorkbenchAdapter.class && adaptableObject instanceof Project) { |
|
24 |
return new TXMResultAdapter() { |
|
25 |
@Override |
|
26 |
public Object[] getChildren(Object o) { |
|
27 |
Project p = (Project) o; |
|
28 |
if (p.isOpen()) { |
|
29 |
return p.getCorpora().toArray(); |
|
30 |
} |
|
31 |
|
|
32 |
return new Object[0]; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public ImageDescriptor getImageDescriptor(Object object) { |
|
37 |
return AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, IImageKeys.PROJECT); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public String getLabel(Object o) { |
|
42 |
return ((Project) o).getName(); |
|
43 |
} |
|
44 |
}; |
|
45 |
} |
|
46 |
return null; |
|
47 |
} |
|
48 |
} |
|
0 | 49 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/AdapterFactory.java (revision 2245) | ||
---|---|---|
27 | 27 |
// |
28 | 28 |
package org.txm.rcp; |
29 | 29 |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.Collections; |
|
32 |
import java.util.Comparator; |
|
33 | 30 |
import java.util.HashMap; |
34 |
import java.util.List; |
|
35 | 31 |
|
36 | 32 |
import org.eclipse.core.runtime.IAdapterFactory; |
37 | 33 |
import org.eclipse.jface.resource.ImageDescriptor; |
38 |
import org.eclipse.osgi.util.NLS; |
|
39 | 34 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
40 | 35 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
41 | 36 |
import org.txm.core.results.TXMResult; |
42 | 37 |
//import org.txm.functions.queryindex.QueryIndex; |
43 | 38 |
import org.txm.rcp.adapters.TXMResultAdapter; |
44 |
import org.txm.rcp.messages.TXMUIMessages; |
|
45 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
46 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
47 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
48 | 39 |
|
49 | 40 |
/** |
50 | 41 |
* A factory for creating Adapter objects. |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/TXMResultContentProvider.java (revision 2245) | ||
---|---|---|
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.rcp.views.corpora; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.Collections; |
|
32 |
import java.util.Comparator; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import org.eclipse.core.runtime.IAdaptable; |
|
36 |
import org.eclipse.core.runtime.Platform; |
|
37 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
38 |
import org.eclipse.jface.viewers.Viewer; |
|
39 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
|
40 |
import org.txm.Toolbox; |
|
41 |
import org.txm.core.preferences.TBXPreferences; |
|
42 |
import org.txm.core.results.TXMResult; |
|
43 |
import org.txm.objects.CorpusBuild; |
|
44 |
import org.txm.objects.Project; |
|
45 |
import org.txm.objects.Workspace; |
|
46 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
47 |
|
|
48 |
/** |
|
49 |
* Content provider of the Corpus view. |
|
50 |
* |
|
51 |
* @author mdecorde |
|
52 |
*/ |
|
53 |
public class TXMResultContentProvider implements ITreeContentProvider { |
|
54 |
|
|
55 |
private CorporaView view; |
|
56 |
|
|
57 |
public TXMResultContentProvider(CorporaView view) { |
|
58 |
this.view = view; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Gets the adapter. |
|
63 |
* |
|
64 |
* @param element the element |
|
65 |
* @return the adapter |
|
66 |
*/ |
|
67 |
protected IWorkbenchAdapter getAdapter(Object element) { |
|
68 |
IWorkbenchAdapter adapter = null; |
|
69 |
if (element instanceof IAdaptable) { |
|
70 |
adapter = (IWorkbenchAdapter) ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class); |
|
71 |
} |
|
72 |
if (element != null && adapter == null) { |
|
73 |
adapter = (IWorkbenchAdapter) Platform.getAdapterManager().loadAdapter(element, IWorkbenchAdapter.class.getName()); |
|
74 |
} |
|
75 |
return adapter; |
|
76 |
} |
|
77 |
|
|
78 |
/* (non-Javadoc) |
|
79 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
|
80 |
*/ |
|
81 |
@Override |
|
82 |
public Object[] getChildren(Object element) { |
|
83 |
IWorkbenchAdapter adapter = getAdapter(element); |
|
84 |
if (adapter != null) { |
|
85 |
Object[] children = adapter.getChildren(element); |
|
86 |
// FIXME: sort here the TXM result according to current sorting preference order, eg. getWeight(), getDate(), getName(), getClass() |
|
87 |
// Arrays.sort(children, new Comparator<Object>() { |
|
88 |
// @Override |
|
89 |
// public int compare(Object o1, Object o2) { |
|
90 |
// if (o1 == null) return -1; |
|
91 |
// if (o2 == null) return 1; |
|
92 |
// return o1.toString().compareTo(o2.toString()); |
|
93 |
// } |
|
94 |
// }); |
|
95 |
return children; |
|
96 |
} |
|
97 |
else if (element instanceof TXMResult) { |
|
98 |
return ((TXMResult)element).getChildren().toArray(); |
|
99 |
} |
|
100 |
return new Object[0]; |
|
101 |
} |
|
102 |
|
|
103 |
/* (non-Javadoc) |
|
104 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
105 |
*/ |
|
106 |
@Override |
|
107 |
public Object[] getElements(Object element) { |
|
108 |
// return element; |
|
109 |
// |
|
110 |
// if (element instanceof Workspace) { |
|
111 |
// ArrayList<MainCorpus> elements = new ArrayList<MainCorpus>(); |
|
112 |
// Workspace p = (Workspace) element; |
|
113 |
// |
|
114 |
// for (Project b : p.getProjects()) { |
|
115 |
// for (TXMResult o : b.getChildren(MainCorpus.class)) { |
|
116 |
// elements.add((MainCorpus)o); |
|
117 |
// } |
|
118 |
// } |
|
119 |
// //System.out.println("get elements: "+elements); |
|
120 |
// Collections.sort(elements, new Comparator<MainCorpus>() { |
|
121 |
// |
|
122 |
// @Override |
|
123 |
// public int compare(MainCorpus o1, MainCorpus o2) { |
|
124 |
// if (o1 == null) return -1; |
|
125 |
// if (o2 == null) return 1; |
|
126 |
// return o1.getName().compareTo(o2.getName()); |
|
127 |
// } |
|
128 |
// }); |
|
129 |
// //System.out.println("corpora view content: "+elements); |
|
130 |
// return elements.toArray(); |
|
131 |
// } else |
|
132 |
if (element instanceof Workspace && !TBXPreferences.getInstance().getBoolean(TBXPreferences.SHOW_ALL_RESULT_NODES)) { |
|
133 |
Workspace w = (Workspace)element; |
|
134 |
ArrayList<CorpusBuild> corpora = new ArrayList<CorpusBuild>(); |
|
135 |
for (Project p : w.getProjects()) { |
|
136 |
corpora.addAll(p.getCorpora()); |
|
137 |
} |
|
138 |
return corpora.toArray(); |
|
139 |
} |
|
140 |
else if (element instanceof TXMResult) { |
|
141 |
return ((TXMResult)element).getChildren().toArray(); |
|
142 |
} |
|
143 |
else if (element instanceof List) { |
|
144 |
List list = (List)element; |
|
145 |
return list.toArray(); |
|
146 |
} |
|
147 |
return new Object[0]; |
|
148 |
} |
|
149 |
|
|
150 |
/* (non-Javadoc) |
|
151 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
|
152 |
*/ |
|
153 |
@Override |
|
154 |
public Object getParent(Object element) { |
|
155 |
// IWorkbenchAdapter adapter = getAdapter(element); |
|
156 |
// if (adapter != null) { |
|
157 |
// return adapter.getParent(element); |
|
158 |
// } |
|
159 |
// else |
|
160 |
if (element instanceof TXMResult) { |
|
161 |
return ((TXMResult)element).getParent(); |
|
162 |
} |
|
163 |
return null; |
|
164 |
} |
|
165 |
|
|
166 |
/* (non-Javadoc) |
|
167 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
|
168 |
*/ |
|
169 |
@Override |
|
170 |
public boolean hasChildren(Object element) { |
|
171 |
if (element instanceof TXMResult) { |
|
172 |
return getChildren(element).length > 0; |
|
173 |
} else { |
|
174 |
int n = getChildren(element).length; |
|
175 |
return n > 0; |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
/* (non-Javadoc) |
|
180 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
|
181 |
*/ |
|
182 |
@Override |
|
183 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
184 |
} |
|
185 |
|
|
186 |
/* (non-Javadoc) |
|
187 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
188 |
*/ |
|
189 |
@Override |
|
190 |
public void dispose() { |
|
191 |
} |
|
192 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorpusViewContentProvider.java (revision 2245) | ||
---|---|---|
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.rcp.views.corpora; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.Collections; |
|
32 |
import java.util.Comparator; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import org.eclipse.core.resources.IProject; |
|
36 |
import org.eclipse.core.resources.IWorkspace; |
|
37 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
38 |
import org.eclipse.core.runtime.CoreException; |
|
39 |
import org.eclipse.core.runtime.IAdaptable; |
|
40 |
import org.eclipse.core.runtime.Platform; |
|
41 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
42 |
import org.eclipse.jface.viewers.Viewer; |
|
43 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
|
44 |
import org.txm.Toolbox; |
|
45 |
import org.txm.core.preferences.TBXPreferences; |
|
46 |
import org.txm.core.results.TXMResult; |
|
47 |
import org.txm.objects.CorpusBuild; |
|
48 |
import org.txm.objects.Project; |
|
49 |
import org.txm.objects.Workspace; |
|
50 |
import org.txm.rcp.adapters.RCPProjectAdapterFactory; |
|
51 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
52 |
import org.txm.utils.logger.Log; |
|
53 |
|
|
54 |
/** |
|
55 |
* Content provider of the Corpus view. |
|
56 |
* |
|
57 |
* @author mdecorde |
|
58 |
*/ |
|
59 |
public class CorpusViewContentProvider implements ITreeContentProvider { |
|
60 |
|
|
61 |
private CorporaView view; |
|
62 |
|
|
63 |
public CorpusViewContentProvider(CorporaView view) { |
|
64 |
this.view = view; |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Gets the adapter. |
|
69 |
* |
|
70 |
* @param element the element |
|
71 |
* @return the adapter |
|
72 |
*/ |
|
73 |
protected IWorkbenchAdapter getAdapter(Object element) { |
|
74 |
IWorkbenchAdapter adapter = null; |
|
75 |
|
|
76 |
if (element instanceof IAdaptable) { |
|
77 |
adapter = (IWorkbenchAdapter) ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class); |
|
78 |
} |
|
79 |
if (element != null && adapter == null) { |
|
80 |
adapter = (IWorkbenchAdapter) Platform.getAdapterManager().loadAdapter(element, IWorkbenchAdapter.class.getName()); |
|
81 |
} |
|
82 |
return adapter; |
|
83 |
} |
|
84 |
|
|
85 |
/* (non-Javadoc) |
|
86 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
|
87 |
*/ |
|
88 |
@Override |
|
89 |
public Object[] getChildren(Object element) { |
|
90 |
IWorkbenchAdapter adapter = getAdapter(element); |
|
91 |
if (adapter != null) { |
|
92 |
Object[] children = adapter.getChildren(element); |
|
93 |
// FIXME: sort here the TXM result according to current sorting preference order, eg. getWeight(), getDate(), getName(), getClass() |
|
94 |
// Arrays.sort(children, new Comparator<Object>() { |
|
95 |
// @Override |
|
96 |
// public int compare(Object o1, Object o2) { |
|
97 |
// if (o1 == null) return -1; |
|
98 |
// if (o2 == null) return 1; |
|
99 |
// return o1.toString().compareTo(o2.toString()); |
|
100 |
// } |
|
101 |
// }); |
|
102 |
return children; |
|
103 |
} |
|
104 |
else if (element instanceof TXMResult) { |
|
105 |
if (element instanceof Project) { |
|
106 |
Project p = (Project)element; |
|
107 |
if (p.getRCPProject().isOpen()) { |
|
108 |
return p.getChildren().toArray(); |
|
109 |
} |
|
110 |
} else { |
|
111 |
return ((TXMResult)element).getChildren().toArray(); |
|
112 |
} |
|
113 |
} |
|
114 |
return new Object[0]; |
|
115 |
} |
|
116 |
|
|
117 |
/* (non-Javadoc) |
|
118 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
119 |
*/ |
|
120 |
@Override |
|
121 |
public Object[] getElements(Object element) { |
|
122 |
// return element; |
|
123 |
// |
|
124 |
// if (element instanceof Workspace) { |
|
125 |
// ArrayList<MainCorpus> elements = new ArrayList<MainCorpus>(); |
|
126 |
// Workspace p = (Workspace) element; |
|
127 |
// |
|
128 |
// for (Project b : p.getProjects()) { |
|
129 |
// for (TXMResult o : b.getChildren(MainCorpus.class)) { |
|
130 |
// elements.add((MainCorpus)o); |
|
131 |
// } |
|
132 |
// } |
|
133 |
// //System.out.println("get elements: "+elements); |
|
134 |
// Collections.sort(elements, new Comparator<MainCorpus>() { |
|
135 |
// |
|
136 |
// @Override |
|
137 |
// public int compare(MainCorpus o1, MainCorpus o2) { |
|
138 |
// if (o1 == null) return -1; |
|
139 |
// if (o2 == null) return 1; |
|
140 |
// return o1.getName().compareTo(o2.getName()); |
|
141 |
// } |
|
142 |
// }); |
|
143 |
// //System.out.println("corpora view content: "+elements); |
|
144 |
// return elements.toArray(); |
|
145 |
// } else |
|
146 |
if (element instanceof Workspace && !TBXPreferences.getInstance().getBoolean(TBXPreferences.SHOW_ALL_RESULT_NODES)) { |
|
147 |
Workspace w = (Workspace)element; |
|
148 |
ArrayList<Object> elements = new ArrayList<Object>(); |
|
149 |
for (Project p : w.getProjects()) { |
|
150 |
if (p.getRCPProject().isOpen()) { |
|
151 |
elements.addAll(p.getCorpora()); |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
IWorkspace rcpWorkspace = ResourcesPlugin.getWorkspace(); |
|
156 |
IProject corporaDirectory = rcpWorkspace.getRoot().getProject("corpora"); |
|
157 |
String path = corporaDirectory.getLocation().toOSString(); |
|
158 |
IProject projects[]; |
|
159 |
projects = rcpWorkspace.getRoot().getProjects(); |
|
160 |
for (IProject project : projects) { |
|
161 |
String path2 = project.getLocation().toOSString(); |
|
162 |
if (!project.isOpen() && path2.startsWith(path)) { |
|
163 |
elements.add(project); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
|
|
168 |
return elements.toArray(); |
|
169 |
} |
|
170 |
else if (element instanceof TXMResult) { |
|
171 |
return ((TXMResult)element).getChildren().toArray(); |
|
172 |
} |
|
173 |
else if (element instanceof List) { |
|
174 |
List list = (List)element; |
|
175 |
return list.toArray(); |
|
176 |
} |
|
177 |
return new Object[0]; |
|
178 |
} |
|
179 |
|
|
180 |
/* (non-Javadoc) |
|
181 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
|
182 |
*/ |
|
183 |
@Override |
|
184 |
public Object getParent(Object element) { |
|
185 |
// IWorkbenchAdapter adapter = getAdapter(element); |
|
186 |
// if (adapter != null) { |
|
187 |
// return adapter.getParent(element); |
|
188 |
// } |
|
189 |
// else |
|
190 |
if (element instanceof TXMResult) { |
|
191 |
return ((TXMResult)element).getParent(); |
|
192 |
} |
|
193 |
return null; |
|
194 |
} |
|
195 |
|
|
196 |
/* (non-Javadoc) |
|
197 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
|
198 |
*/ |
|
199 |
@Override |
|
200 |
public boolean hasChildren(Object element) { |
|
201 |
if (element instanceof TXMResult) { |
|
202 |
return getChildren(element).length > 0; |
|
203 |
} else { |
|
204 |
int n = getChildren(element).length; |
|
205 |
return n > 0; |
|
206 |
} |
|
207 |
} |
|
208 |
|
|
209 |
/* (non-Javadoc) |
|
210 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
|
211 |
*/ |
|
212 |
@Override |
|
213 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
214 |
} |
|
215 |
|
|
216 |
/* (non-Javadoc) |
|
217 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
218 |
*/ |
|
219 |
@Override |
|
220 |
public void dispose() { |
|
221 |
} |
|
222 |
} |
|
0 | 223 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorporaView.java (revision 2245) | ||
---|---|---|
32 | 32 |
|
33 | 33 |
import org.eclipse.core.commands.Command; |
34 | 34 |
import org.eclipse.core.commands.common.NotDefinedException; |
35 |
import org.eclipse.core.resources.IProject; |
|
35 | 36 |
import org.eclipse.core.runtime.IProgressMonitor; |
36 | 37 |
import org.eclipse.core.runtime.IStatus; |
37 | 38 |
import org.eclipse.core.runtime.Status; |
... | ... | |
74 | 75 |
import org.txm.objects.Workspace; |
75 | 76 |
import org.txm.rcp.IImageKeys; |
76 | 77 |
import org.txm.rcp.StatusLine; |
78 |
import org.txm.rcp.commands.workspace.OpenCorpus; |
|
77 | 79 |
import org.txm.rcp.editors.TXMEditor; |
78 | 80 |
import org.txm.rcp.handlers.BaseAbstractHandler; |
79 | 81 |
import org.txm.rcp.handlers.results.DeleteObject; |
... | ... | |
86 | 88 |
//import org.txm.functions.queryindex.QueryIndex; |
87 | 89 |
//import org.txm.rcp.editors.input.QueryIndexEditorInput; |
88 | 90 |
//import org.txm.rcp.editors.queryindex.QueryIndexEditor; |
89 |
// TODO: Auto-generated Javadoc |
|
90 | 91 |
/** |
91 | 92 |
* This sample class demonstrates how to plug-in a new workbench view. The view |
92 | 93 |
* shows data obtained from the model. The sample creates a dummy model on the |
... | ... | |
165 | 166 |
public void _reload() { |
166 | 167 |
if (Toolbox.isInitialized()) { |
167 | 168 |
|
168 |
treeViewer.setContentProvider(new TXMResultContentProvider(this));
|
|
169 |
treeViewer.setContentProvider(new CorpusViewContentProvider(this));
|
|
169 | 170 |
treeViewer.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelProvider(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator())); |
170 | 171 |
|
171 | 172 |
Workspace w = Toolbox.workspace; |
... | ... | |
241 | 242 |
// return true; |
242 | 243 |
// } |
243 | 244 |
// }); |
244 |
treeViewer.setContentProvider(new TXMResultContentProvider(this));
|
|
245 |
treeViewer.setContentProvider(new CorpusViewContentProvider(this));
|
|
245 | 246 |
treeViewer.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelProvider(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator())); |
246 | 247 |
|
247 | 248 |
// for now the sorter is used to sort the Corpus, Subcorpus and partition objects |
... | ... | |
361 | 362 |
String commandId = doubleClickInstalledCommands.get(selectedItem.getClass().getName()); |
362 | 363 |
if (commandId != null) { |
363 | 364 |
BaseAbstractHandler.executeCommand(commandId); |
364 |
} else { |
|
365 |
} else if (selectedItem instanceof IProject) { |
|
366 |
OpenCorpus.open((IProject)selectedItem ); |
|
367 |
} else { |
|
365 | 368 |
if (treeViewer.getExpandedState(selectedItem)) { |
366 | 369 |
treeViewer.collapseToLevel(selectedItem, 99); |
367 | 370 |
} else { |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/cmdparameters/ParametersView.java (revision 2245) | ||
---|---|---|
63 | 63 |
import org.txm.rcp.editors.TXMEditor; |
64 | 64 |
import org.txm.rcp.swt.widget.PropertiesSelector; |
65 | 65 |
import org.txm.rcp.swt.widget.QueryWidget; |
66 |
import org.txm.searchengine.core.IQuery; |
|
66 | 67 |
import org.txm.searchengine.cqp.ReferencePattern; |
67 | 68 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
68 | 69 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
69 | 70 |
import org.txm.searchengine.cqp.corpus.Property; |
70 | 71 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
71 | 72 |
import org.txm.searchengine.cqp.corpus.WordProperty; |
72 |
//import org.txm.rcp.editors.referencer.ReferencerEditor; |
|
73 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
|
74 | 73 |
|
75 | 74 |
/** |
76 | 75 |
* Alternative display of the TXMEditor form fields |
... | ... | |
249 | 248 |
}); |
250 | 249 |
c = sp; |
251 | 250 |
((Spinner) c).setDigits(2); |
252 |
} else if (clazz.equals(CQLQuery.class)) { |
|
251 |
} else if (clazz.equals(Boolean.class)) { |
|
252 |
final Button sp = new Button(panel, SWT.CHECK); |
|
253 |
sp.addSelectionListener(new SelectionListener() { |
|
254 |
|
|
255 |
@Override |
|
256 |
public void widgetSelected(SelectionEvent e) { |
|
257 |
try { |
|
258 |
f.set(result, sp.getSelection()); |
|
259 |
if (activated != null && !activated.getParametersGroupsComposite().isDisposed()) { |
|
260 |
activated.compute(false); |
|
261 |
} |
|
262 |
} catch (Exception e1) { |
|
263 |
e1.printStackTrace(); |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
@Override |
|
268 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
269 |
} |
|
270 |
}); |
|
271 |
c = sp; |
|
272 |
} else if (clazz.equals(IQuery.class)) { |
|
253 | 273 |
final QueryWidget qw = new QueryWidget(panel, SWT.NONE); |
254 | 274 |
if (value != null) { |
255 |
qw.setText(((CQLQuery) value).getQueryString());
|
|
275 |
qw.setText(((IQuery) value).getQueryString());
|
|
256 | 276 |
} |
257 | 277 |
qw.addSelectionListener(new SelectionListener() { |
258 | 278 |
|
... | ... | |
391 | 411 |
Label l2 = new Label(panel, SWT.NONE); |
392 | 412 |
if (value != null) { |
393 | 413 |
TypeVariable<?>[] pp = value.getClass().getTypeParameters(); |
394 |
l2.setText("" + value); |
|
414 |
l2.setText(clazz.getSimpleName()+"=" + value); |
|
415 |
} else { |
|
416 |
l2.setText(clazz.getSimpleName()+"=" + value); |
|
395 | 417 |
} |
396 | 418 |
c = l2; |
397 | 419 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/cmdparameters/TXMResultPreferencesView.java (revision 2245) | ||
---|---|---|
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.rcp.views.cmdparameters; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
|
|
32 |
import org.apache.commons.lang.StringUtils; |
|
33 |
import org.eclipse.core.resources.IProject; |
|
34 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
|
35 |
import org.eclipse.jface.layout.GridDataFactory; |
|
36 |
import org.eclipse.jface.viewers.CellEditor; |
|
37 |
import org.eclipse.jface.viewers.CellLabelProvider; |
|
38 |
import org.eclipse.jface.viewers.EditingSupport; |
|
39 |
import org.eclipse.jface.viewers.ICellModifier; |
|
40 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
41 |
import org.eclipse.jface.viewers.TextCellEditor; |
|
42 |
import org.eclipse.jface.viewers.TreeViewer; |
|
43 |
import org.eclipse.jface.viewers.TreeViewerColumn; |
|
44 |
import org.eclipse.jface.viewers.ViewerCell; |
|
45 |
import org.eclipse.swt.SWT; |
|
46 |
import org.eclipse.swt.events.KeyEvent; |
|
47 |
import org.eclipse.swt.events.KeyListener; |
|
48 |
import org.eclipse.swt.events.SelectionEvent; |
|
49 |
import org.eclipse.swt.events.SelectionListener; |
|
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.Composite; |
|
54 |
import org.eclipse.swt.widgets.Label; |
|
55 |
import org.eclipse.swt.widgets.Text; |
|
56 |
import org.eclipse.swt.widgets.TreeItem; |
|
57 |
import org.eclipse.ui.IPartService; |
|
58 |
import org.eclipse.ui.PlatformUI; |
|
59 |
import org.eclipse.ui.part.ViewPart; |
|
60 |
import org.osgi.service.prefs.BackingStoreException; |
|
61 |
import org.osgi.service.prefs.Preferences; |
|
62 |
import org.txm.core.preferences.TXMPreferences; |
|
63 |
import org.txm.core.results.TXMResult; |
|
64 |
import org.txm.objects.Project; |
|
65 |
import org.txm.rcp.views.corpora.CorporaView; |
|
66 |
|
|
67 |
/** |
|
68 |
* Alternative display of the TXMEditor form fields |
|
69 |
* |
|
70 |
* @author mdecorde. |
|
71 |
*/ |
|
72 |
public class TXMResultPreferencesView extends ViewPart { |
|
73 |
|
|
74 |
/** The ID. */ |
|
75 |
public static String ID = TXMResultPreferencesView.class.getName(); //$NON-NLS-1$ |
|
76 |
|
|
77 |
private Text refs; |
|
78 |
private ParametersComposite parametersComposite; |
|
79 |
/** |
|
80 |
* Instantiates a new queries view. |
|
81 |
*/ |
|
82 |
public TXMResultPreferencesView() { |
|
83 |
IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService(); |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public void dispose() { |
|
88 |
IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService(); |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Refresh. |
|
93 |
*/ |
|
94 |
public static void refresh() { |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
/* |
|
99 |
* (non-Javadoc) |
|
100 |
* |
|
101 |
* @see |
|
102 |
* org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets |
|
103 |
* .Composite) |
|
104 |
*/ |
|
105 |
@Override |
|
106 |
public void createPartControl(Composite parent) { |
|
107 |
|
|
108 |
parent.setLayout(new GridLayout(4, false)); |
|
109 |
|
|
110 |
Button refresh = new Button(parent, SWT.PUSH); |
|
111 |
refresh.setText("Refresh"); |
|
112 |
refresh.addSelectionListener(new SelectionListener() { |
|
113 |
|
|
114 |
@Override |
|
115 |
public void widgetSelected(SelectionEvent e) { |
|
116 |
Object obj = CorporaView.getFirstSelectedObject(); |
|
117 |
if (obj instanceof TXMResult) { |
|
118 |
parametersComposite.updateEditorParameters(obj); |
|
119 |
} else { |
|
120 |
System.out.println("Select an object in the corpora view (current="+obj+")"); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
126 |
}); |
|
127 |
refresh.setLayoutData(GridDataFactory.fillDefaults().align(GridData.BEGINNING, GridData.BEGINNING).grab(false, false).create()); |
|
128 |
|
|
129 |
Button upButton = new Button(parent, SWT.PUSH); |
|
130 |
upButton.setText("⇧"); |
|
131 |
upButton.addSelectionListener(new SelectionListener() { |
|
132 |
|
|
133 |
@Override |
|
134 |
public void widgetSelected(SelectionEvent e) { |
|
135 |
Object obj = parametersComposite.getInput(); |
|
136 |
if (obj instanceof TXMResult) { |
|
137 |
TXMResult p = ((TXMResult)obj).getParent(); |
|
138 |
if (p != null) { |
|
139 |
parametersComposite.updateEditorParameters(p); |
|
140 |
} |
|
141 |
} else { |
|
142 |
System.out.println("Select an object in the corpora view (current="+obj+")"); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
148 |
}); |
|
149 |
upButton.setLayoutData(GridDataFactory.fillDefaults().align(GridData.BEGINNING, GridData.BEGINNING).grab(false, false).create()); |
|
150 |
|
|
151 |
new Label(parent, SWT.NONE).setText("properties"); |
|
152 |
|
|
153 |
refs = new Text(parent, SWT.BORDER); |
|
154 |
refs.setText(ParametersComposite.DEFAULT_REFS); |
|
155 |
refs.addKeyListener(new KeyListener() { |
|
156 |
|
|
157 |
@Override |
|
158 |
public void keyReleased(KeyEvent e) { |
|
159 |
if (e.keyCode == SWT.KEYPAD_CR || e.keyCode == SWT.CR) { |
|
160 |
parametersComposite.setReferences(refs.getText().split(",")); |
|
161 |
parametersComposite.refresh(); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
@Override |
|
166 |
public void keyPressed(KeyEvent e) { } |
|
167 |
}); |
|
168 |
|
|
169 |
refresh.setLayoutData(GridDataFactory.fillDefaults().align(GridData.BEGINNING, GridData.BEGINNING).grab(false, false).create()); |
|
170 |
|
|
171 |
parametersComposite = new ParametersComposite(parent, SWT.NONE); |
|
172 |
parametersComposite.setLayoutData(GridDataFactory.fillDefaults().align(GridData.FILL, GridData.FILL).grab(true, true).span(4, 1).create()); |
|
173 |
} |
|
174 |
|
|
175 |
@Override |
|
176 |
public void setFocus() { |
|
177 |
// TODO Auto-generated method stub |
|
178 |
} |
|
179 |
} |
|
0 | 180 |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/cmdparameters/ParametersComposite.java (revision 2245) | ||
---|---|---|
1 |
package org.txm.rcp.views.cmdparameters; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
|
|
5 |
import org.apache.commons.lang.StringUtils; |
|
6 |
import org.eclipse.core.resources.IProject; |
|
7 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
|
8 |
import org.eclipse.jface.layout.GridDataFactory; |
|
9 |
import org.eclipse.jface.viewers.CellLabelProvider; |
|
10 |
import org.eclipse.jface.viewers.EditingSupport; |
|
11 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
12 |
import org.eclipse.jface.viewers.TextCellEditor; |
|
13 |
import org.eclipse.jface.viewers.TreeViewer; |
|
14 |
import org.eclipse.jface.viewers.TreeViewerColumn; |
|
15 |
import org.eclipse.jface.viewers.ViewerCell; |
|
16 |
import org.eclipse.swt.SWT; |
|
17 |
import org.eclipse.swt.layout.GridData; |
|
18 |
import org.eclipse.swt.widgets.Composite; |
|
19 |
import org.eclipse.swt.widgets.Text; |
|
20 |
import org.osgi.service.prefs.BackingStoreException; |
|
21 |
import org.osgi.service.prefs.Preferences; |
|
22 |
import org.txm.core.preferences.TXMPreferences; |
|
23 |
import org.txm.core.results.TXMResult; |
|
24 |
import org.txm.objects.Project; |
|
25 |
import org.txm.rcp.swt.GLComposite; |
|
26 |
|
|
27 |
public class ParametersComposite extends GLComposite { |
|
28 |
|
|
29 |
private TreeViewer tv; |
|
30 |
private TreeViewerColumn nameColumn; |
|
31 |
private TreeViewerColumn valueColumn; |
|
32 |
private TextCellEditor cellEditor; |
|
33 |
|
|
34 |
public static String DEFAULT_REFS = "class,user_name"; |
|
35 |
private String[] references = DEFAULT_REFS.split(","); |
|
36 |
|
|
37 |
public ParametersComposite(Composite parent, int style) { |
|
38 |
super(parent, style, "Parameters"); |
|
39 |
|
|
40 |
tv = new TreeViewer(this); |
|
41 |
tv.getTree().setLayoutData(GridDataFactory.fillDefaults().align(GridData.FILL, GridData.FILL).grab(true, true).create()); |
|
42 |
tv.getTree().setHeaderVisible(true); |
|
43 |
tv.getTree().setLinesVisible(true); |
|
44 |
tv.setContentProvider(new ITreeContentProvider() { |
|
45 |
|
|
46 |
@Override |
|
47 |
public Object[] getElements(Object inputElement) { |
|
48 |
if (inputElement instanceof String) { |
|
49 |
String npath = inputElement.toString(); |
|
50 |
return getChildren(TXMPreferences.preferencesRootNode.node(npath)); |
|
51 |
} else if (inputElement instanceof Project) { |
|
52 |
Project project = (Project)inputElement; |
Formats disponibles : Unified diff