Revision 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/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/fileexplorer/Explorer.java (revision 2245)
103 103

  
104 104
		explorerView.tv.refresh();
105 105
	}
106
	
107
	/**
108
	 * Refresh.
109
	 */
110
	public static void refresh(File f) {
111
		if (f == null) return;
112
		
113
		Explorer explorerView = (Explorer) PlatformUI.getWorkbench()
114
				.getActiveWorkbenchWindow().getActivePage().findView(
115
						Explorer.ID);
106 116

  
117
		explorerView.tv.refresh(f);
118
	}
119

  
107 120
	/* (non-Javadoc)
108 121
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
109 122
	 */
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/fileexplorer/MacroExplorer.java (revision 2245)
124 124
				.getActiveWorkbenchWindow().getActivePage().findView(
125 125
						MacroExplorer.ID);
126 126
		
127
		//TODO this might cause big latences
127 128
		initCurrentDirectory();
128 129
		
129 130
		if (explorerView != null) {
......
131 132
			explorerView.tv.refresh();
132 133
		}
133 134
	}
135
	
136
	/**
137
	 * Refresh a file.
138
	 */
139
	public static void refresh(File f) {
140
		if (f == null) return;
141
		
142
		MacroExplorer explorerView = (MacroExplorer) PlatformUI.getWorkbench()
143
				.getActiveWorkbenchWindow().getActivePage().findView(
144
						MacroExplorer.ID);
145
		
146
		if (explorerView != null) {
147
			explorerView.tv.refresh(f);
148
		}
149
	}
134 150

  
135 151
	public TreeViewer getTreeViewer() {
136 152
		return tv;
......
190 206
				
191 207
				if (CreateMacro.createMacro(currentRootDir.getAbsolutePath(), name)) {
192 208
					MacroExplorer.refresh();
193
					tv.refresh();
194 209
				}
195 210
			}
196 211
		});
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/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;
53
					IEclipsePreferences prefs = project.getPreferencesScope().getNode("/project/"+project.getName());
54
					return getChildren(prefs);
55
				} else if (inputElement instanceof TXMResult) {
56
					TXMResult result = (TXMResult)inputElement;
57
					//return new Object[] {TXMPreferences.preferencesRootNode.node(result.getParametersNodePath())};
58
					return getChildren(TXMPreferences.preferencesRootNode.node(result.getParametersNodePath()));
59
				}  else if (inputElement instanceof IProject) {
60
					IProject project = (IProject) inputElement;
61
					return getChildren(TXMPreferences.preferencesRootNode.node("/"+project.getName()));
62
				}
63
				
64
				return new Object[0];
65
			}
66

  
67
			@Override
68
			public Object[] getChildren(Object parentElement) {
69
				if (parentElement instanceof Preferences) {
70
					Preferences prefs = (Preferences)parentElement;
71
					try {
72
						ArrayList<Object> children = new ArrayList<Object>();
73
						String[] nodes = prefs.childrenNames();
74
						String[] attributes = prefs.keys();
75
						for (String n : nodes) {
76
							children.add(prefs.node(n));
77
						}
78
						for (String name : attributes) {
79
							children.add(new Object[] {prefs, name});
80
						}
81
						return children.toArray();
82
					} catch (BackingStoreException e) {
83
						e.printStackTrace();
84
					}
85
				}
86
				return null;
87
			}
88

  
89
			@Override
90
			public Object getParent(Object element) {
91
				if (element instanceof Preferences) {
92
					Preferences prefs = (Preferences)element;
93
					return prefs.parent();
94
				}
95
				return null;
96
			}
97

  
98
			@Override
99
			public boolean hasChildren(Object element) {
100
				if (element instanceof Preferences) {
101
					Preferences prefs = (Preferences)element;
102
					try {
103
						return prefs.childrenNames().length > 0 || prefs.keys().length > 0;
104
					} catch (BackingStoreException e) {
105
						// TODO Auto-generated catch block
106
						e.printStackTrace();
107
					}
108
				}
109
				return false;
110
			}
111
			
112
		});
113
		
114
		nameColumn = new TreeViewerColumn(tv, SWT.NONE);
115
		nameColumn.getColumn().setText("node");
116
		nameColumn.getColumn().pack();
117
		nameColumn.setLabelProvider(new CellLabelProvider() {
118

  
119
			@Override
120
			public void update(ViewerCell cell) {
121
				Object element = cell.getElement();
122

  
123
				if (element instanceof Preferences) {
124
					Preferences c = (Preferences)element;
125
					if (references != null && references.length > 0) {
126
						ArrayList<String> values = new ArrayList<String>();
127
						for (String k : references) {
128
							if (c.get(k, null) != null) {
129
								values.add(c.get(k, null));
130
							}
131
						}
132
						
133
						if (values.size() == 0) values.add(c.name());
134
						cell.setText(StringUtils.join(values, ", "));
135
					} else {
136
						cell.setText(c.name());
137
					}
138
				} else if (element instanceof Object[]) {
139
					Object[] c = (Object[])element;
140
					
141
					cell.setText(c[1].toString());
142
				} else {
143
					cell.setText(element.toString());
144
				}
145
			}
146
			
147
		});
148
		valueColumn = new TreeViewerColumn(tv, SWT.NONE);
149
		valueColumn.getColumn().setText("value");
150
		valueColumn.getColumn().pack();
151
		valueColumn.setLabelProvider(new CellLabelProvider() {
152

  
153
			@Override
154
			public void update(ViewerCell cell) {
155
				Object element = cell.getElement();
156

  
157
				if (element instanceof Preferences) {
158
					Preferences c = (Preferences)element;
159
					cell.setText("");
160
				} else if (element instanceof Object[]) {
161
					Object[] c = (Object[])element;
162
					Preferences p = (Preferences) c[0];
163
					cell.setText(p.get(c[1].toString(), ""));
164
				} else {
165
					cell.setText(element.toString());
166
				}
167
			}
168
		});
169
		
170
		cellEditor = new TextCellEditor(tv.getTree());
171
		valueColumn.setEditingSupport(new EditingSupport(tv) {
172

  
173
	        @Override
174
	        protected void setValue(Object element, Object value) {
175
	        	if (element instanceof Object[]) {
176
	            	Object[] data = (Object[]) element;
177
	            	Preferences prefs = (Preferences) data[0];
178
	            	String key = data[1].toString();
179
	            	prefs.put(key, value.toString());
180
	            	tv.refresh(element);
181
	            	
182
	            }
183
	        	return;
184
	        }
185

  
186
	        @Override
187
	        protected Object getValue(Object element) {
188
	        	if (element instanceof Object[]) {
189
	            	Object[] data = (Object[]) element;
190
	            	Preferences prefs = (Preferences) data[0];
191
	            	String key = data[1].toString();
192
	            	return prefs.get(key, "");
193
	            }
194
	        	return null;
195
	        }
196

  
197
	        @Override
198
	        protected TextCellEditor getCellEditor(Object element) {
199
	            return cellEditor;
200
	        }
201

  
202
	        @Override
203
	        protected boolean canEdit(Object element) {
204
	            return element instanceof Object[];
205
	        }
206
	    });
207
	}
208
	
209
	
210

  
211
	public void updateEditorParameters(Object input) {
212
		tv.setInput(input);
213
		nameColumn.getColumn().pack();
214
		valueColumn.getColumn().pack();
215
	}
216

  
217

  
218

  
219
	public void refresh() {
220
		tv.refresh();
221
	}
222

  
223
	public void setReferences(String[] split) {
224
		references = split;
225
	}
226

  
227
	public Object getInput() {
228
		return tv.getInput();
229
	}
230
}
0 231

  
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/actions/CreatePartitionDialog.java (revision 2245)
675 675
			return null;
676 676
		}
677 677
		
678
		try {
679
			p.compute();
680
		} catch (Exception e) {
681
			// TODO Auto-generated catch block
682
			e.printStackTrace();
683
			return null;
684
		}
685
		
686
		if (p.getPartsCount() == 0) {
687
			Log.severe(TXMUIMessages.errorColonThePartitionCreatedHasNoPart);
688
			return null;
689
		}		
690 678
		return p;
691 679
	}
692 680

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/utils/SWTEditorsUtils.java (revision 2245)
13 13
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
14 14
import org.eclipse.e4.ui.model.application.ui.basic.MStackElement;
15 15
import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicFactoryImpl;
16
import org.eclipse.e4.ui.model.application.ui.basic.impl.PartSashContainerImpl;
16 17
import org.eclipse.e4.ui.workbench.modeling.EModelService;
17 18
import org.eclipse.ui.IEditorInput;
18 19
import org.eclipse.ui.IEditorPart;
......
23 24
import org.eclipse.ui.handlers.HandlerUtil;
24 25
import org.eclipse.ui.part.EditorPart;
25 26
import org.txm.core.results.TXMResult;
26
import org.txm.rcp.editors.TXMEditor;
27
import org.txm.rcp.editors.ITXMResultEditor;
27 28
import org.txm.rcp.editors.TXMMultiPageEditor;
28 29
import org.txm.rcp.editors.TXMResultEditorInput;
29 30

  
......
53 54
		//		return null;
54 55

  
55 56
		// FIXME: SJ: new version, also works with ChartEditorInput
56
		ArrayList<TXMEditor> editors = getEditors(result);
57
		ArrayList<ITXMResultEditor<?>> editors = getEditors(result);
57 58
		if(!editors.isEmpty())	{
58 59
			return editors.get(0);
59 60
		}
......
65 66
	 * Gets all opened editors.
66 67
	 * @return all opened editors if there is at least one otherwise returns an empty list
67 68
	 */
68
	public static ArrayList<TXMEditor> getEditors() {
69
		ArrayList<TXMEditor> editors = new ArrayList<TXMEditor>();
69
	public static ArrayList<ITXMResultEditor<?>> getEditors() {
70
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<ITXMResultEditor<?>>();
70 71

  
71 72
		IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
72 73
		for (IWorkbenchWindow window : windows) {
......
75 76
				for (IEditorReference reference : page.getEditorReferences()) {
76 77
					IEditorPart tmpEditor = reference.getEditor(false);
77 78

  
78
					if(tmpEditor instanceof TXMEditor)	{
79
						editors.add((TXMEditor) tmpEditor);
79
					if(tmpEditor instanceof ITXMResultEditor)	{
80
						editors.add((ITXMResultEditor<?>) tmpEditor);
80 81
					}
81 82
					else if(tmpEditor instanceof TXMMultiPageEditor)	{
82 83
						TXMMultiPageEditor txmMultipageEditor = ((TXMMultiPageEditor)tmpEditor);
83 84
						for (int i = 0; i < txmMultipageEditor.getEditors().size(); i++) {
84
							if(txmMultipageEditor.getEditors().get(i) instanceof TXMEditor)	{
85
								TXMEditor txmEditor = ((TXMEditor)txmMultipageEditor.getEditors().get(i));
85
							if(txmMultipageEditor.getEditors().get(i) instanceof ITXMResultEditor)	{
86
								ITXMResultEditor txmEditor = ((ITXMResultEditor)txmMultipageEditor.getEditors().get(i));
86 87
								editors.add(txmEditor);
87 88
							}
88 89
						}
......
99 100
	 * @param result
100 101
	 * @return all opened editors for the specified result if there is at least one otherwise returns an empty list
101 102
	 */
102
	public static ArrayList<TXMEditor> getEditors(HashSet<TXMResult> results)	{
103
	public static ArrayList<ITXMResultEditor<?>> getEditors(HashSet<TXMResult> results)	{
103 104

  
104
		ArrayList<TXMEditor> editors = new ArrayList<TXMEditor>();
105
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<ITXMResultEditor<?>>();
105 106

  
106
		ArrayList<TXMEditor> all_editors = getEditors();
107
		ArrayList<ITXMResultEditor<?>> all_editors = getEditors();
107 108

  
108
		for (TXMEditor txmEditor : all_editors) {
109
		for (ITXMResultEditor<?> txmEditor : all_editors) {
109 110

  
110 111
			if (results.contains(txmEditor.getResult()))	{
111 112
				editors.add(txmEditor);
......
120 121
	 * @param result
121 122
	 * @return all opened editors for the specified result if there is at least one otherwise returns an empty list
122 123
	 */
123
	public static ArrayList<TXMEditor> getEditors(TXMResult result)	{
124
	public static ArrayList<ITXMResultEditor<?>> getEditors(TXMResult result)	{
124 125

  
125
		ArrayList<TXMEditor> editors = new ArrayList<TXMEditor>();
126
		ArrayList<ITXMResultEditor<?>> editors = new ArrayList<ITXMResultEditor<?>>();
126 127

  
127
		ArrayList<TXMEditor> all_editors = getEditors();
128
		ArrayList<ITXMResultEditor<?>> all_editors = getEditors();
128 129

  
129
		for (TXMEditor txmEditor : all_editors) {
130
		for (ITXMResultEditor<?> txmEditor : all_editors) {
130 131

  
131 132
			if (result == txmEditor.getResult())	{
132 133
				editors.add(txmEditor);
......
141 142
	 * @param event
142 143
	 * @return
143 144
	 */
144
	public static TXMEditor getActiveEditor(ExecutionEvent event)	{
145
	public static ITXMResultEditor getActiveEditor(ExecutionEvent event)	{
145 146

  
146 147
		IEditorPart editor = null;
147 148

  
......
157 158

  
158 159
		}
159 160

  
160
		if(!(editor instanceof TXMEditor))	{
161
		if(!(editor instanceof ITXMResultEditor))	{
161 162
			return null;
162 163
		}
163 164

  
164
		return (TXMEditor)editor;
165
		return (ITXMResultEditor)editor;
165 166
	}
166 167

  
167 168
	/**
......
228 229
	public static void addPart(MPart parentPart, MPart partToAdd, int position, float percent) {
229 230
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
230 231
		EModelService service = (EModelService) window.getService(EModelService.class);
231
		MPartStack stackToInsert = createPartStack(partToAdd);
232

  
232
		
233 233
		MUIElement parent = parentPart.getParent();
234 234
		while (!(parent instanceof MPartSashContainerElement))	{
235 235
			parent = parent.getParent();
236 236
		}
237
		service.insert(stackToInsert, (MPartSashContainerElement) parent, position, percent);
237
		MPartSashContainerElement sashContainer = (MPartSashContainerElement)parent;
238
		
239
		MPartStack stackToInsert = createPartStack(partToAdd);
240
		
241
		//TODO find out why the insert method always create a new sash
242
		service.insert(stackToInsert, sashContainer, position, percent);
238 243
	}
239 244

  
240 245
	/**
241
	 * Creates a part stack for the specified part.
246
	 * Creates a part stack for the specified part
242 247
	 * @param part
243 248
	 * @return
244 249
	 */
245 250
	private static MPartStack createPartStack(MPart part) {
246 251
		MStackElement stackElement = part;
252

  
247 253
		MPartStack stack = BasicFactoryImpl.eINSTANCE.createPartStack();
248 254
		stack.getChildren().add(stackElement);
249 255
		stack.setSelectedElement(stackElement);
......
251 257
	}
252 258

  
253 259
	/**
254
	 * close a TXMEditor from its result
260
	 * close a ITXMResultEditor from its result
255 261
	 * 
256 262
	 * @param r
257 263
	 */
258 264
	public static boolean closeEditor(TXMResult r) {
259 265
		IEditorPart e = getEditor(r);
260
		if (e != null && e instanceof TXMEditor && ((TXMEditor)e).getResult() == r) {
261
			((TXMEditor)e).close();
266
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor)e).getResult() == r) {
267
			((ITXMResultEditor)e).close();
262 268
			return true;
263 269
		}
264 270
		return false;
......
266 272

  
267 273
	public static boolean refreshEditor(TXMResult r) {
268 274
		IEditorPart e = getEditor(r);
269
		if (e != null && e instanceof TXMEditor && ((TXMEditor)e).getResult() == r) {
275
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor)e).getResult() == r) {
270 276
			try {
271
				((TXMEditor)e).refresh(true);
277
				((ITXMResultEditor)e).refresh(true);
272 278
				return true;
273 279
			} catch (Exception e1) {
274 280
				// TODO Auto-generated catch block
......
280 286

  
281 287
	public static boolean activateEditor(TXMResult r) {
282 288
		IEditorPart e = getEditor(r);
283
		if (e != null && e instanceof TXMEditor && ((TXMEditor)e).getResult() == r) {
289
		if (e != null && e instanceof ITXMResultEditor && ((ITXMResultEditor<?>)e).getResult() == r) {
284 290
			try {
285
				((TXMEditor)e).getSite().getPage().activate(e);
291
				((ITXMResultEditor<?>)e).getSite().getPage().activate(e);
286 292
				return true;
287 293
			} catch (Exception e1) {
288 294
				// TODO Auto-generated catch block
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/CloseCorpus.java (revision 2245)
1
package org.txm.rcp.commands.workspace;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.eclipse.core.commands.AbstractHandler;
7
import org.eclipse.core.commands.ExecutionEvent;
8
import org.eclipse.core.commands.ExecutionException;
9
import org.eclipse.core.runtime.IProgressMonitor;
10
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.core.runtime.Status;
12
import org.eclipse.jface.viewers.ISelection;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.swt.widgets.Display;
15
import org.eclipse.ui.handlers.HandlerUtil;
16
import org.txm.objects.Project;
17
import org.txm.rcp.commands.CloseEditorsUsing;
18
import org.txm.rcp.commands.RestartTXM;
19
import org.txm.rcp.utils.JobHandler;
20
import org.txm.searchengine.cqp.corpus.MainCorpus;
21

  
22
public class CloseCorpus extends AbstractHandler {
23

  
24
	public static final String ID = CloseCorpus.class.getCanonicalName();
25

  
26
	@Override
27
	public Object execute(ExecutionEvent event) throws ExecutionException {
28

  
29
		ISelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
30
		if (!(sel instanceof IStructuredSelection)) return null;
31
		IStructuredSelection selection = (IStructuredSelection) sel;
32
		ArrayList<MainCorpus> corpora = new ArrayList<MainCorpus>();
33
		for (Object s : selection.toArray()) {
34
			if (s instanceof MainCorpus) {
35
				corpora.add((MainCorpus)s);
36
			}
37
		}
38
		
39
		close(corpora);
40

  
41
		return corpora;
42
	}
43

  
44
	public static JobHandler close(final MainCorpus corpus) {
45
		ArrayList<MainCorpus> l = new ArrayList<MainCorpus>();
46
		l.add(corpus);
47
		return close(l);
48
	}
49

  
50
	public static JobHandler close(final List<MainCorpus> corpora) {
51

  
52
		for (final MainCorpus corpus : corpora) {
53
			final Project project = corpus.getProject();
54
			if (project == null)  return null;
55

  
56
			Display d = Display.getCurrent();
57
			if (d == null) {
58
				d = Display.getDefault();
59
			}
60

  
61
			if (d != null) {
62
				d.syncExec(new Runnable() {
63
					@Override
64
					public void run() {CloseEditorsUsing.corpus(corpus);}
65
				});
66
			}
67
		}
68
		JobHandler job = new JobHandler("Closing corpus "+corpora) {
69

  
70
			@Override
71
			protected IStatus run(IProgressMonitor monitor) {
72
				for (final MainCorpus corpus : corpora) {
73
					corpus.getProject().close(monitor);
74
				}
75

  
76
				this.syncExec(new Runnable() {
77
					@Override
78
					public void run() {
79
						RestartTXM.reloadViews();
80
					}
81
				});
82
				return Status.OK_STATUS;
83

  
84
			}
85
		};
86

  
87
		job.schedule();
88

  
89
		return job;
90
	}
91
}
0 92

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/OpenCorpus.java (revision 2245)
1
package org.txm.rcp.commands.workspace;
2

  
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.core.resources.IProject;
7
import org.eclipse.core.runtime.CoreException;
8
import org.eclipse.core.runtime.IProgressMonitor;
9
import org.eclipse.core.runtime.IStatus;
10
import org.eclipse.core.runtime.Status;
11
import org.eclipse.jface.viewers.ISelection;
12
import org.eclipse.jface.viewers.IStructuredSelection;
13
import org.eclipse.swt.widgets.Display;
14
import org.eclipse.ui.handlers.HandlerUtil;
15
import org.txm.Toolbox;
16
import org.txm.objects.Project;
17
import org.txm.rcp.commands.CloseEditorsUsing;
18
import org.txm.rcp.commands.RestartTXM;
19
import org.txm.rcp.utils.JobHandler;
20
import org.txm.rcp.views.corpora.CorporaView;
21
import org.txm.searchengine.cqp.corpus.MainCorpus;
22

  
23
public class OpenCorpus extends AbstractHandler {
24

  
25
	public static final String ID = OpenCorpus.class.getCanonicalName();
26

  
27
	@Override
28
	public Object execute(ExecutionEvent event) throws ExecutionException {
29

  
30
		ISelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
31
		if (!(sel instanceof IStructuredSelection)) return null;
32
		IStructuredSelection selection = (IStructuredSelection) sel;
33

  
34
		Object s = selection.getFirstElement();
35
		if (!(s instanceof IProject))
36
			return null;
37
		IProject project = (IProject) s;
38
		open(project);
39

  
40
		return project;
41
	}
42

  
43
	public static JobHandler open(final IProject iproject) {
44

  
45
		if (iproject == null)  return null;
46

  
47
		Display d = Display.getCurrent();
48
		if (d == null) {
49
			d = Display.getDefault();
50
		}
51
		
52
		JobHandler job = new JobHandler("Opening corpus "+iproject.getName()) {
53

  
54
			@Override
55
			protected IStatus run(IProgressMonitor monitor) {
56
				
57
				Project project = null;
58
				for (Project p : Toolbox.workspace.getProjects()) {
59
					if (iproject.equals(p.getRCPProject())) {
60
						project = p;
61
						break;
62
					}
63
				}
64
				
65
				if (project == null) {
66
					if (!iproject.isOpen()) {
67
						try {
68
							iproject.open(monitor);
69
						} catch (CoreException e) {
70
							// TODO Auto-generated catch block
71
							e.printStackTrace();
72
						}
73
					}
74
					project = Project.loadProjectFromProjectScope(iproject);
75
					project.open(monitor);
76
				}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff