Revision 503

tmp/org.txm.internalview.core/.project (revision 503)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.internalview.core</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.internalview.core/src/org/txm/internalview/core/Messages.java (revision 503)
1
package org.txm.internalview.core;
2

  
3
import org.eclipse.osgi.util.NLS;
4

  
5
public class Messages extends NLS {
6
	public static String InternalView_3;
7
	public static String InternalView_6;
8
	public static String InternalView_7;
9
}
0 10

  
tmp/org.txm.internalview.core/src/org/txm/internalview/core/messages_ru.properties (revision 503)
1
InternalView_3 = \  Structure informations: 
2
InternalView_6 = InternalView: failed to retrieve struct properties values: 
3
InternalView_7 = \  No structure informations
0 4

  
tmp/org.txm.internalview.core/src/org/txm/internalview/core/messages_fr.properties (revision 503)
1
InternalView_3 = \  Information des structures :
2
InternalView_6 = InternalView: erreur lors de la r?cup?ration des valeurs des propri?t?s de structure
3
InternalView_7 = \  No d'informations sur les structures
0 4

  
tmp/org.txm.internalview.core/src/org/txm/internalview/core/messages_en.properties (revision 503)
1
InternalView_3 = \  Structure informations: 
2
InternalView_6 = InternalView: failed to retrieve struct properties values: 
3
InternalView_7 = \  No structure informations
0 4

  
tmp/org.txm.internalview.core/src/org/txm/functions/internal/InternalView.java (revision 503)
1
package org.txm.functions.internal;
2

  
3
import java.io.File;
4
import java.util.ArrayList;
5
import java.util.Collection;
6
import java.util.HashMap;
7
import java.util.LinkedHashMap;
8
import java.util.List;
9

  
10
import org.eclipse.core.runtime.IProgressMonitor;
11
import org.txm.core.results.TXMParameters;
12
import org.txm.functions.TXMCommand;
13
import org.txm.internalview.core.Messages;
14
import org.txm.searchengine.cqp.CQPEngine;
15
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
16
import org.txm.searchengine.cqp.corpus.Corpus;
17
import org.txm.searchengine.cqp.corpus.Property;
18
import org.txm.searchengine.cqp.corpus.QueryResult;
19
import org.txm.searchengine.cqp.corpus.StructuralUnit;
20
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
21
import org.txm.searchengine.cqp.corpus.query.Match;
22
import org.txm.searchengine.cqp.corpus.query.Query;
23

  
24
public class InternalView extends TXMCommand  {
25

  
26
	Corpus corpus;
27
	List<Property> pProperties;
28
	StructuralUnit pStructure;
29
	List<StructuralUnitProperty> pStructProperties;
30
	Integer pCurrentStruct = -1;
31
	
32
	int nmatches = 0;
33
	List<Match> matches = new ArrayList<Match>();
34

  
35

  
36
	public InternalView(Corpus corpus) {
37
		super(corpus);
38
		this.corpus = corpus;
39
	}
40

  
41
	public void setParameters(List<Property> properties, StructuralUnit struct, List<StructuralUnitProperty> structProperties, Integer currentStructure) {
42
		if (properties != null) this.pProperties = properties;
43
		if (struct != null) this.pStructure = struct;
44
		if (structProperties != null) this.pStructProperties = structProperties;
45
		if (currentStructure != null) this.pCurrentStruct = currentStructure;
46
		
47
		dirty = true;
48
	}
49

  
50
	public String getStructInfos() {
51

  
52
		try {
53
			if (pStructProperties.size() > 0) {
54
				String str = Messages.InternalView_3;
55
				for (Property sup : pStructProperties) {
56
					int[] array = {getCurrentSegmentNo()};
57
					str += " "+sup.getName()+"="+CQPEngine.getCqiClient().struc2Str(sup.getQualifiedName(), array)[0]; //$NON-NLS-1$ //$NON-NLS-2$
58
				}
59
				return str;
60
			}
61
		} catch (Exception e) {
62
			System.out.println(Messages.InternalView_6+e.getMessage());
63
			org.txm.utils.logger.Log.printStackTrace(e);
64
		}
65
		return Messages.InternalView_7;
66
	}
67

  
68
	public HashMap<Property, List<String>> getNext() throws CqiClientException {
69
		int next = pCurrentStruct + 1;
70
		if (next < nmatches) {
71
			return getPage(next);
72
		} 
73
		return new HashMap<Property, List<String>>();
74
	}
75

  
76
	public HashMap<Property, List<String>> getPrevious() throws CqiClientException {
77
		int previous = pCurrentStruct - 1;
78
		if (previous >= 0 && previous < nmatches) {
79
			return getPage(previous);
80
		}
81
		return new HashMap<Property, List<String>>();
82
	}
83

  
84
	public HashMap<Property, List<String>> getFirst() throws CqiClientException {
85
		if (0 < nmatches) {
86
			return getPage(0);
87
		}
88
		return new HashMap<Property, List<String>>();
89
	}
90

  
91
	public HashMap<Property, List<String>> getLast() throws CqiClientException {
92
		if (nmatches - 1 >= 0) {
93
			return getPage(nmatches - 1);
94
		}
95
		return new HashMap<Property, List<String>>();
96
	}
97

  
98
	/**
99
	 * get the ith page and set the current page number to i
100
	 * 
101
	 * @param i
102
	 * @return
103
	 * @throws CqiClientException
104
	 */
105
	public LinkedHashMap<Property, List<String>> getPage(int i) throws CqiClientException {
106
		LinkedHashMap<Property, List<String>> rez = new LinkedHashMap<Property, List<String>>();
107

  
108
		if (i >= 0 && i < nmatches) {
109
			Match m = matches.get(i);
110
			Collection<? extends Integer> positions = m.getRange();
111
			int[] p = new int[positions.size()];
112
			int c = 0;
113
			for(int v : positions) p[c++] = v;
114
			for (Property prop : pProperties) {
115
				rez.put(prop, Match.getValuesForProperty(prop, p));
116
			}
117
			pCurrentStruct = i;
118
		}
119
		return rez;
120
	}
121

  
122
	public void printNext() throws CqiClientException {
123
		HashMap<Property, List<String>> seg = getNext();
124
		if (seg.size() > 0)
125
			System.out.println(seg);
126
	}
127

  
128
	public void printPrevious() throws CqiClientException {
129
		HashMap<Property, List<String>> seg = getPrevious();
130
		if (seg.size() > 0)
131
			System.out.println(seg);
132
	}
133

  
134
	public void printSeg(HashMap<Property, List<String>> seg) {
135
		Collection<List<String>> values = seg.values();
136
		if(values.size() == 0) return;
137

  
138
		for(List<String> list : values) {
139
			for(String value : list)
140
				System.out.print("\t"+value); //$NON-NLS-1$
141
			System.out.println();
142
		}
143
		System.out.println();
144
	}
145

  
146
	public Corpus getCorpus() {
147
		return corpus;
148
	}
149

  
150
	public StructuralUnit getStructuralUnit() {
151
		return pStructure;
152
	}
153

  
154
	public List<Property> getProperties() {
155
		return pProperties;
156
	}
157

  
158
	public Integer getCurrentSegmentNo() {
159
		return pCurrentStruct;
160
	}
161

  
162
	public int getNSegment() {
163
		return nmatches;
164
	}
165

  
166
	public int getSegmentLength() {
167
		if (matches.size() == 0) return 0;
168
		if (matches.size() < pCurrentStruct) return 0;
169
		if (pCurrentStruct == null) return 0;
170
		
171
		Match m = matches.get(pCurrentStruct);
172
		return m.size();
173
	}
174

  
175
	public boolean isFirst() {
176
		return pCurrentStruct == 0;
177
	}
178

  
179
	public boolean isLast() {
180
		return pCurrentStruct == nmatches - 1;
181
	}
182

  
183
	public String getLocationTail() {
184
		if (nmatches > 0)
185
			return " / "+nmatches; //$NON-NLS-1$
186
		return "";
187
	}
188

  
189
	public String getCurrentLocation() {
190
		return ""+(pCurrentStruct+1); //$NON-NLS-1$
191
	}
192

  
193
	public String getDetails() {
194
		// TODO Auto-generated method stub
195
		return corpus.getName()+" "+pStructure.getName()+" "+(pCurrentStruct+1); //$NON-NLS-1$ //$NON-NLS-2$
196
	}
197

  
198
	@Override
199
	public String getName() {
200
		// TODO Auto-generated method stub
201
		return null;
202
	}
203

  
204
	@Override
205
	public String getSimpleName() {
206
		// TODO Auto-generated method stub
207
		return null;
208
	}
209

  
210
	@Override
211
	public void clean() {
212
		// TODO Auto-generated method stub
213

  
214
	}
215

  
216
	@Override
217
	public boolean validateParameters() {
218
		return corpus != null && pStructure != null && pProperties != null && pProperties.size() > 0 && pStructProperties != null && pStructProperties.size() > 0;
219
	}
220

  
221
	@Override
222
	public boolean compute(IProgressMonitor watcher) throws Exception {
223
		//find struct start-end
224
		Query query = new Query("<"+pStructure.getName()+"> [] expand to "+pStructure); //$NON-NLS-1$ //$NON-NLS-2$
225
		//System.out.println(query);
226
		QueryResult result = corpus.query(query, "test", false); //$NON-NLS-1$
227
		nmatches = result.getNMatch();
228
		if (nmatches > 0) {
229
			matches = result.getMatches();
230
		}
231
		result.drop();
232
		//System.out.println(matches);
233
		dirty = false;
234
		return nmatches > 0;
235
	}
236

  
237
	@Override
238
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception {
239
		// TODO Auto-generated method stub
240
		return false;
241
	}
242

  
243
	@Override
244
	public boolean setParameters(TXMParameters parameters) {
245
		return false;
246
	}
247

  
248
	public HashMap<Property, List<String>> getCurrentPage() throws CqiClientException {
249
		if (pCurrentStruct == null || pCurrentStruct < 0) {
250
			return getFirst();
251
		}
252
		HashMap<Property, List<String>> current = getPage(pCurrentStruct);
253
		return current;
254
	}
255
}
0 256

  
tmp/org.txm.internalview.core/src/org/txm/functions/internal/package.html (revision 503)
1
<html>
2
<body>
3
<p>Internal view</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.internalview.core/build.properties (revision 503)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .
0 5

  
tmp/org.txm.internalview.core/.settings/org.eclipse.jdt.core.prefs (revision 503)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.6
0 8

  
tmp/org.txm.internalview.core/.classpath (revision 503)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
0 8

  
tmp/org.txm.internalview.core/META-INF/MANIFEST.MF (revision 503)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: InternalView
4
Bundle-SymbolicName: org.txm.internalview.core
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
7
Require-Bundle: org.txm.core;bundle-version="0.8.0";visibility:=reexport,
8
 org.txm.searchengine.cqp.core;visibility:=reexport
9
Export-Package: org.txm.functions.internal,
10
 org.txm.internalview.core
0 11

  
tmp/org.txm.internalview.rcp/src/org/txm/rcp/internal/rcp/handler/ComputeInternalView.java (revision 503)
1
package org.txm.rcp.internal.rcp.handler;
2

  
3
import org.eclipse.core.commands.ExecutionEvent;
4
import org.eclipse.core.commands.ExecutionException;
5
import org.eclipse.core.commands.IHandlerListener;
6
import org.eclipse.jface.viewers.IStructuredSelection;
7
import org.eclipse.ui.IWorkbenchPage;
8
import org.eclipse.ui.IWorkbenchWindow;
9
import org.eclipse.ui.PartInitException;
10
import org.eclipse.ui.handlers.HandlerUtil;
11
import org.txm.functions.internal.InternalView;
12
import org.txm.internal.rcp.editors.InternalViewEditor;
13
import org.txm.internalview.rcp.Messages;
14
import org.txm.rcp.StatusLine;
15
import org.txm.rcp.editors.TXMResultEditorInput;
16
import org.txm.rcp.handlers.BaseAbstractHandler;
17
import org.txm.rcp.views.corpora.CorporaView;
18
import org.txm.searchengine.cqp.corpus.Corpus;
19
import org.txm.utils.logger.Log;
20

  
21
public class ComputeInternalView extends BaseAbstractHandler {
22

  
23
	private IWorkbenchWindow window;
24
	private IStructuredSelection selection;
25
	private TXMResultEditorInput editorInput;
26

  
27
	// adds a double click listener to the Corpus View
28
	static	{
29
		CorporaView.addDoubleClickListener(InternalView.class, ComputeInternalView.class);
30
	}
31
	
32
	@Override
33
	public void addHandlerListener(IHandlerListener handlerListener) {
34
		super.addHandlerListener(handlerListener);
35
	}
36

  
37
	@Override
38
	public void dispose() {
39
		super.dispose();
40
	}
41

  
42
	@Override
43
	public Object execute(ExecutionEvent event) throws ExecutionException {
44
		System.out.println("Compute Internal view...");
45
		if (!this.checkCorpusEngine()) return false;
46
		
47
		window = HandlerUtil.getActiveWorkbenchWindow(event);
48
		Object sel = HandlerUtil.getCurrentSelection(event);
49
		if (!(sel instanceof IStructuredSelection)) {
50
			Log.warning(Messages.ComputeInternalView_0);
51
			return null;
52
		}
53
		
54
		selection = (IStructuredSelection) sel;
55

  
56
		InternalView iview = null;
57
		
58
		Object s = selection.getFirstElement();
59
		if (s instanceof Corpus) {
60
			Corpus corpus = (Corpus) s;
61
			iview = new InternalView(corpus);
62
		} else if (s instanceof InternalView) {
63
			iview = (InternalView)s;
64
		} else {
65
			System.out.println(Messages.ComputeInternalView_1);
66
			return null;
67
		}
68
		
69
		editorInput = new TXMResultEditorInput(iview);
70

  
71
		IWorkbenchPage page = window.getActivePage();
72
		try {
73
			StatusLine.setMessage(org.txm.rcp.Messages.OK);
74
			page.openEditor(editorInput, InternalViewEditor.ID); //$NON-NLS-1$
75
		
76
		} catch (PartInitException e) {
77
			System.err.println(org.txm.rcp.Messages.OK+ e);
78
		}
79

  
80
		return null;
81
	}
82

  
83
	@Override
84
	public boolean isEnabled() {
85
		return super.isEnabled();
86
	}
87

  
88
	@Override
89
	public boolean isHandled() {
90
		return super.isHandled();
91
	}
92

  
93
	@Override
94
	public void removeHandlerListener(IHandlerListener handlerListener) {
95
		super.removeHandlerListener(handlerListener);
96
	}
97
}
0 98

  
tmp/org.txm.internalview.rcp/src/org/txm/internalview/rcp/Messages.java (revision 503)
1
package org.txm.internalview.rcp;
2

  
3
import org.eclipse.osgi.util.NLS;
4
import org.txm.utils.messages.Utf8NLS;
5

  
6
public class Messages extends NLS {
7
	
8
	private static final String BUNDLE_NAME = Messages.class.getPackage().getName()+".messages"; //$NON-NLS-1$
9
	
10
	public static String ComputeInternalView_0;
11
	public static String ComputeInternalView_1;
12
	
13
	public static String InternalViewEditor_1;
14
	public static String InternalViewEditor_10;
15
	public static String InternalViewEditor_11;
16
	public static String InternalViewEditor_16;
17
	public static String InternalViewEditor_2;
18
	public static String InternalViewEditor_25;
19
	public static String InternalViewEditor_3;
20
	public static String InternalViewEditor_4;
21
	public static String InternalViewEditor_5;
22
	
23
	static {
24
		// initialize resource bundle
25
		Utf8NLS.initializeMessages(BUNDLE_NAME, Messages.class);
26
	}
27
}
0 28

  
tmp/org.txm.internalview.rcp/src/org/txm/internalview/rcp/AdapterFactory.java (revision 503)
1
// Copyright © 2010-2013 ENS de Lyon.
2
package org.txm.internalview.rcp;
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.functions.internal.InternalView;
8
import org.txm.internal.rcp.editors.InternalViewEditor;
9
import org.txm.rcp.Application;
10
import org.txm.rcp.adapters.TXMResultAdapterFactory;
11

  
12
// TODO: Auto-generated Javadoc
13
/**
14
 * A factory for creating Adapter objects.
15
 * 
16
 * @author jmague
17
 */
18
public class AdapterFactory extends TXMResultAdapterFactory {
19
	
20
	public static final String ACTION_INTERNALVIEW = "icons/functions/InternalView.png"; //$NON-NLS-1$
21
	
22
	/** The InternalView adapter. */
23
	private IWorkbenchAdapter InternalViewAdapter = new IWorkbenchAdapter() {
24
		@Override
25
		public Object[] getChildren(Object internal) {
26
			return new Object[0];
27
		}
28

  
29
		@Override
30
		public ImageDescriptor getImageDescriptor(Object object) {
31
			return AbstractUIPlugin.imageDescriptorFromPlugin(
32
					Application.PLUGIN_ID, ACTION_INTERNALVIEW);
33
		}
34

  
35
		@Override
36
		public String getLabel(Object internalView) {
37
			return ((InternalView) internalView).getDetails(); 
38
		}
39

  
40
		@Override
41
		public Object getParent(Object internalView) {
42
			return ((InternalView) internalView).getCorpus();
43
		}
44
	};
45

  
46
	public Object getAdapter(Object adaptableObject, Class adapterType) {
47
		if(adapterType == IWorkbenchAdapter.class && adaptableObject instanceof InternalView)	{
48
			return InternalViewAdapter;
49
		}
50
		return null;
51
	}
52
}
0 53

  
tmp/org.txm.internalview.rcp/src/org/txm/internalview/rcp/messages_ru.properties (revision 503)
1
InternalViewEditor_1=Подготовка внутреннего вида...
2
InternalViewEditor_10=Внутренний вид: ошибка инициализации: 
3
InternalViewEditor_11=OK
4
InternalViewEditor_16=Ошибка
5
InternalViewEditor_2=Получение следующего результата...
6
InternalViewEditor_25=сформированный запрос: 
7
InternalViewEditor_3=Перезагрузка интерфейса
8
InternalViewEditor_4=Структура: 
9
InternalViewEditor_5=Свойство структуры: 
0 10

  
tmp/org.txm.internalview.rcp/src/org/txm/internalview/rcp/messages_fr.properties (revision 503)
1
InternalViewEditor_1  = Calcul de la vue interne...
2
InternalViewEditor_10 = InternalView: erreur d'initialisation : 
3
InternalViewEditor_11 = OK
4
InternalViewEditor_16 = Erreur
5
InternalViewEditor_2  = Récupération du prochain résultat...
6
InternalViewEditor_25 = requête générée : 
7
InternalViewEditor_3  = Rechargement de l'interface
8
InternalViewEditor_4  = Structure : 
9
InternalViewEditor_5  = Propriété de structure : 
0 10

  
tmp/org.txm.internalview.rcp/src/org/txm/internalview/rcp/messages.properties (revision 503)
1

  
2
ComputeInternalView_0 = Selection is not structured
3
ComputeInternalView_1 = Error: selection is not a Corpus
4

  
5
InternalViewEditor_1  = Computing Internal view
6
InternalViewEditor_10 = InternalView: failed to initialize form
7
InternalViewEditor_11 = OK
8
InternalViewEditor_16 = error
9
InternalViewEditor_2  = Getting next result
10
InternalViewEditor_25 = QUERY:
11
InternalViewEditor_3  = Refreshing interface
12
InternalViewEditor_4  = Structure:
13
InternalViewEditor_5  = Structural properties:
0 14

  
tmp/org.txm.internalview.rcp/src/org/txm/internal/rcp/editors/InternalViewEditor.java (revision 503)
1
package org.txm.internal.rcp.editors;
2

  
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.HashSet;
6
import java.util.List;
7

  
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.action.MenuManager;
12
import org.eclipse.jface.viewers.ColumnLabelProvider;
13
import org.eclipse.jface.viewers.IStructuredContentProvider;
14
import org.eclipse.jface.viewers.TableViewer;
15
import org.eclipse.jface.viewers.TableViewerColumn;
16
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.KeyEvent;
19
import org.eclipse.swt.events.KeyListener;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.events.SelectionListener;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.Menu;
29
import org.eclipse.swt.widgets.Table;
30
import org.eclipse.swt.widgets.TableColumn;
31
import org.eclipse.swt.widgets.TableItem;
32
import org.eclipse.ui.IEditorInput;
33
import org.eclipse.ui.IEditorSite;
34
import org.eclipse.ui.PartInitException;
35
import org.txm.concordance.core.functions.Line;
36
import org.txm.functions.internal.InternalView;
37
import org.txm.internalview.rcp.AdapterFactory;
38
import org.txm.internalview.rcp.Messages;
39
import org.txm.rcp.IImageKeys;
40
import org.txm.rcp.JobsTimer;
41
import org.txm.rcp.editors.TXMEditorPart;
42
import org.txm.rcp.editors.TXMResultEditorInput;
43
import org.txm.rcp.editors.TableKeyListener;
44
import org.txm.rcp.swt.widget.NavigationWidget;
45
import org.txm.rcp.swt.widget.PropertiesSelector;
46
import org.txm.rcp.utils.JobHandler;
47
import org.txm.rcp.views.corpora.CorporaView;
48
import org.txm.searchengine.cqp.CQPEngine;
49
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
50
import org.txm.searchengine.cqp.corpus.Corpus;
51
import org.txm.searchengine.cqp.corpus.Property;
52
import org.txm.searchengine.cqp.corpus.StructuralUnit;
53
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
54
import org.txm.searchengine.cqp.corpus.query.Match;
55
import org.txm.searchengine.cqp.corpus.query.Query;
56
import org.txm.utils.logger.Log;
57

  
58
public class InternalViewEditor extends TXMEditorPart {
59

  
60
	public static final String ID = InternalViewEditor.class.getName();
61
	
62
	Corpus corpus;
63
	InternalView internalView;
64

  
65
	Combo structCombo;
66
	List<StructuralUnit> availableStructs;
67
	PropertiesSelector propSelector;
68
	PropertiesSelector structSelector;
69
	List<Property> availables;
70
	List<Property> selected;
71
	TableViewer viewer;
72
	Table table;
73
	NavigationWidget navigation;
74
	HashMap<Property, List<String>> line;
75

  
76
	Label structInfos;
77
	private Composite formPanel;
78
	private Composite navigationPanel;
79
	private Composite resultPanel;
80

  
81
	/* (non-Javadoc)
82
	 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
83
	 */
84
	@Override
85
	public void init(IEditorSite site, IEditorInput input)
86
			throws PartInitException {
87
		setSite(site);
88
		setInput(input);
89

  
90
		TXMResultEditorInput vinput = (TXMResultEditorInput) input;
91
		if (vinput.getResult() instanceof InternalView) {
92
			this.internalView = (InternalView) vinput.getResult();
93
			this.corpus = this.internalView.getCorpus();
94
		} else {
95
			throw new PartInitException("InternalViewEditor only manages InternalView results.");
96
		}
97
	}
98

  
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.ui.part.EditorPart#isDirty()
101
	 */
102
	@Override
103
	public boolean isDirty() {
104
		return internalView.isDirty();
105
	}
106

  
107
	/* (non-Javadoc)
108
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
109
	 */
110
	@Override
111
	public boolean isSaveAsAllowed() {
112
		return false;
113
	}
114

  
115
	/* (non-Javadoc)
116
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
117
	 */
118
	@Override
119
	public boolean isSaveOnCloseNeeded() {
120
		return false;
121
	}
122
	
123
	@Override
124
	public void computeResult() {
125
		
126
		final StructuralUnit struct = this.availableStructs.get(this.structCombo.getSelectionIndex());
127
		final  List<Property> properties = propSelector.getProperties();
128
		final List<StructuralUnitProperty> supList = new ArrayList<StructuralUnitProperty>();
129
		List<Property> pList = structSelector.getProperties();
130
		for (Property property : pList) if (property instanceof StructuralUnitProperty) supList.add((StructuralUnitProperty) property);
131
		
132
		Integer currentPage = internalView.getCurrentSegmentNo();
133
		if (currentPage == null) currentPage = 0;
134
		internalView.setParameters(properties, struct, supList, currentPage);
135
		
136
		JobHandler jobhandler = new JobHandler(Messages.InternalViewEditor_1) {
137
			@Override
138
			protected IStatus run(IProgressMonitor monitor) {
139
				this.runInit(monitor);
140
				JobsTimer.start();
141
				monitor.beginTask(Messages.InternalViewEditor_2, 100);
142
				try {
143
					if (!(internalView.validateParameters() && internalView.isDirty()))
144
						return Status.CANCEL_STATUS;
145

  
146
					internalView.compute(monitor);
147
					firePropertyChange(PROP_DIRTY); // refresh the dirtiness state
148
					line = internalView.getCurrentPage(); // get the first page if pCurrentPage is not set
149
					monitor.beginTask(Messages.InternalViewEditor_3, 100);
150
					this.syncExec(new Runnable() {
151
						@Override
152
						public void run() {
153
							try {
154
								fillResultArea();
155
								CorporaView.refresh();
156
							} catch (CqiClientException e) {
157
								org.txm.rcp.utils.Logger.printStackTrace(e);
158
							}
159
						}
160
					});
161
				} catch (ThreadDeath td) {
162
					return Status.CANCEL_STATUS;
163
				} catch(Exception e) {
164
					org.txm.rcp.utils.Logger.printStackTrace(e);
165
				} finally {
166
					monitor.done();
167
					JobsTimer.stopAndPrint();
168
				}
169
				return Status.OK_STATUS;
170
			}
171
		};
172
		jobhandler.schedule();
173
	}
174

  
175
	public void fillResultArea() throws CqiClientException
176
	{
177
		initColumns();
178
		viewer.setInput(line);
179
		viewer.refresh();
180

  
181
		navigation.setInfoLineText(""+(internalView.getCurrentSegmentNo()+1), internalView.getLocationTail()); //$NON-NLS-1$
182
		structInfos.setText(internalView.getStructInfos());
183

  
184
		int current = internalView.getCurrentSegmentNo();
185
		int total = internalView.getNSegment();
186
		navigation.setFirstEnabled(current > 0);
187
		navigation.setPreviousEnabled(current > 0);
188
		navigation.setNextEnabled(total > 1 && current < total);
189
		navigation.setLastEnabled(total > 1 && current < total);
190

  
191
		navigationPanel.layout();
192
		this.setPartName(internalView.getDetails());
193
		CorporaView.refreshObject(internalView);
194
	}
195

  
196
	/* (non-Javadoc)
197
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
198
	 */
199
	@Override
200
	public void createPartControl(Composite parent) {
201
		this.setTitleImage(IImageKeys.getImage(AdapterFactory.ACTION_INTERNALVIEW));
202
		parent.setLayout(new GridLayout(1,true));
203

  
204
		formPanel = new Composite(parent, SWT.NONE);
205
		formPanel.setLayout(new GridLayout(5,false));
206
		formPanel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
207
		navigationPanel = new Composite(parent, SWT.NONE);
208
		navigationPanel.setLayout(new GridLayout(4,false));
209
		navigationPanel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
210
		resultPanel = new Composite(parent, SWT.NONE);
211
		resultPanel.setLayout(new GridLayout(1,true));
212
		resultPanel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
213

  
214
		Label structComboLabel = new Label(formPanel, SWT.NONE);
215
		structComboLabel.setText(Messages.InternalViewEditor_4);
216
		structComboLabel.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, true));
217
		structCombo = new Combo(formPanel, SWT.NONE);
218
		structCombo.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, true));
219
		propSelector = new PropertiesSelector(formPanel, SWT.NONE);
220
		propSelector.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, true));
221
		propSelector.setLayout(new GridLayout(3, false));
222
		propSelector.addSelectionListener(new SelectionListener() {
223
			@Override
224
			public void widgetSelected(SelectionEvent e) {
225
				internalView.setParameters(propSelector.getProperties(), null, null, null);
226
				try {
227
					line = internalView.getPage(internalView.getCurrentSegmentNo());
228
					fillResultArea();
229
				} catch (CqiClientException e1) {
230
					System.out.println("Error: "+e1.getLocalizedMessage());
231
					Log.printStackTrace(e1);
232
				}
233
			}
234

  
235
			@Override
236
			public void widgetDefaultSelected(SelectionEvent e) {}
237
		});
238

  
239
		structSelector = new PropertiesSelector(formPanel, SWT.NONE);
240
		structSelector.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, true));
241
		structSelector.setLayout(new GridLayout(3, false));
242
		structSelector.setText(Messages.InternalViewEditor_5);
243
		structSelector.addSelectionListener(new SelectionListener() {
244
			@Override
245
			public void widgetSelected(SelectionEvent e) {
246
				ArrayList<StructuralUnitProperty> supList = new ArrayList<StructuralUnitProperty>();
247
				for (Property property : structSelector.getProperties()) if (property instanceof StructuralUnitProperty) supList.add((StructuralUnitProperty) property);
248
				internalView.setParameters(null, null, supList, null);
249
				try {
250
					line = internalView.getPage(internalView.getCurrentSegmentNo());
251
					fillResultArea();
252
				} catch (CqiClientException e1) {
253
					System.out.println("Error: "+e1.getLocalizedMessage());
254
					Log.printStackTrace(e1);
255
				}
256
			}
257

  
258
			@Override
259
			public void widgetDefaultSelected(SelectionEvent e) {}
260
		});
261

  
262
		
263

  
264
		Button ok = new Button(formPanel, SWT.PUSH);
265
		ok.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, false));
266
		ok.setText(org.txm.rcp.Messages.REFRESH);
267
		ok.addSelectionListener(new SelectionListener() {
268
			@Override
269
			public void widgetSelected(SelectionEvent e) {
270
				internalView.setParameters(null,  null, null, 0);
271
				computeResult();
272
			}
273

  
274
			@Override
275
			public void widgetDefaultSelected(SelectionEvent e) {
276
				// TODO Auto-generated method stub
277
			}
278
		});
279

  
280
		navigation = new NavigationWidget(navigationPanel, SWT.NONE);
281
		navigation.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, true));
282
		navigation.addGoToKeyListener(new KeyListener() {
283
			@Override
284
			public void keyReleased(KeyEvent e) { }
285

  
286
			@Override
287
			public void keyPressed(KeyEvent e) {
288
				// TODO Auto-generated method stub
289
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
290
					int next = navigation.getCurrent();
291
					if (next >= 0 && next < internalView.getNSegment())
292
						try {
293
							goToPage(next);
294
						} catch (CqiClientException e1) {
295
							// TODO Auto-generated catch block
296
							org.txm.rcp.utils.Logger.printStackTrace(e1);
297
						}
298
				}
299
			}
300
		});
301
		navigation.addFirstListener(new SelectionListener() {
302
			@Override
303
			public void widgetSelected(SelectionEvent e) {
304
				if (internalView != null) {
305
					try {
306
						line = internalView.getFirst();
307
						fillResultArea(); // one segment at time
308

  
309
						navigation.setFirstEnabled(false);
310
						navigation.setPreviousEnabled(false);
311
						navigation.setNextEnabled(true);
312
						navigation.setLastEnabled(true);
313
					} catch (CqiClientException e1) {
314
						// TODO Auto-generated catch block
315
						org.txm.rcp.utils.Logger.printStackTrace(e1);
316
					}
317
				}
318
			}
319

  
320
			@Override
321
			public void widgetDefaultSelected(SelectionEvent e) { }
322
		});
323
		navigation.addPreviousListener(new SelectionListener() {
324
			@Override
325
			public void widgetSelected(SelectionEvent e) {
326
				if (internalView != null) {
327
					try {
328
						line = internalView.getPrevious();
329
						fillResultArea(); // one segment at time
330

  
331
						navigation.setFirstEnabled(true);
332
						navigation.setPreviousEnabled(!internalView.isFirst());
333
						navigation.setNextEnabled(true);
334
						navigation.setLastEnabled(true);
335
					} catch (CqiClientException e1) {
336
						// TODO Auto-generated catch block
337
						org.txm.rcp.utils.Logger.printStackTrace(e1);
338
					}
339
				}
340
			}
341

  
342
			@Override
343
			public void widgetDefaultSelected(SelectionEvent e) { }
344
		});
345
		navigation.addNextListener(new SelectionListener() {
346
			@Override
347
			public void widgetSelected(SelectionEvent e) {
348
				if (internalView != null) {
349
					try {
350
						line = internalView.getNext();
351
						fillResultArea(); // one segment at time
352

  
353
						navigation.setFirstEnabled(true);
354
						navigation.setPreviousEnabled(true);
355
						navigation.setNextEnabled(!internalView.isLast());
356
						navigation.setLastEnabled(true);
357
					} catch (CqiClientException e1) {
358
						// TODO Auto-generated catch block
359
						org.txm.rcp.utils.Logger.printStackTrace(e1);
360
					}
361
				}
362
			}
363

  
364
			@Override
365
			public void widgetDefaultSelected(SelectionEvent e) { }
366
		});
367
		navigation.addLastListener(new SelectionListener() {
368
			@Override
369
			public void widgetSelected(SelectionEvent e) {
370
				if (internalView != null) {
371
					try {
372
						line = internalView.getLast();
373
						fillResultArea(); // one segment at time
374

  
375
						navigation.setFirstEnabled(true);
376
						navigation.setPreviousEnabled(true);
377
						navigation.setNextEnabled(false);
378
						navigation.setLastEnabled(false);
379
					} catch (CqiClientException e1) {
380
						// TODO Auto-generated catch block
381
						org.txm.rcp.utils.Logger.printStackTrace(e1);
382
					}
383
				}
384
			}
385

  
386
			@Override
387
			public void widgetDefaultSelected(SelectionEvent e) { }
388
		});
389

  
390
		structInfos = new Label(navigationPanel, SWT.NONE);
391
		structInfos.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true));
392
		structInfos.setText(""); //$NON-NLS-1$
393

  
394
		//		Button style = new Button(navigationPanel, SWT.RADIO);
395
		//		style.setText("table");
396

  
397
		viewer = new TableViewer(resultPanel);
398
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
399
		viewer.getTable().setLinesVisible(true);
400
		viewer.getTable().setHeaderVisible(true);
401
		table = viewer.getTable();
402
		table.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
403
		viewer.setContentProvider(new IStructuredContentProvider() {
404

  
405
			@Override
406
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { }
407

  
408
			@Override
409
			public void dispose() { }
410

  
411
			@Override
412
			public Object[] getElements(Object inputElement) {
413
				int nlines = internalView.getSegmentLength();
414
				List<Property> props = internalView.getProperties();
415

  
416
				ArrayList<Object[]> lines = new ArrayList<Object[]>();
417
				for (int i = 0 ; i < nlines ; i++) {
418
					lines.add(new String[props.size()]);
419
				}
420
				if (inputElement instanceof HashMap<?,?>) {
421
					HashMap<Property, List<String>> l = (HashMap<Property, List<String>>) inputElement;
422
					for(int i = 0 ; i < props.size() ; i++) {
423
						Property prop = props.get(i);
424
						List<String> data = l.get(prop);
425
						for (int j = 0 ; j < nlines ; j++) {
426
							lines.get(j)[i] = data.get(j);
427
						}
428
					}
429
				}
430
				return lines.toArray();
431
			}
432
		});
433
		
434
		initializeFields();
435
		
436
		createContextMenu();
437
		
438
		computeResult();
439
	}
440

  
441
	protected boolean goToPage(int next) throws CqiClientException {
442
		line = internalView.getPage(next);
443
		fillResultArea(); // one segment at time
444

  
445
		if (next == 0) {
446
			navigation.setFirstEnabled(false);
447
			navigation.setPreviousEnabled(false);
448
		} else {
449
			navigation.setFirstEnabled(true);
450
			navigation.setFirstEnabled(true);
451
		}
452

  
453
		if (next == internalView.getNSegment() -1) {
454
			navigation.setNextEnabled(false);
455
			navigation.setLastEnabled(false);
456
		} else { 
457
			navigation.setNextEnabled(true);
458
			navigation.setLastEnabled(true);
459
		}
460
		return true;
461
	}
462

  
463
	private void reloadStructuralUnitProperties() {
464
		StructuralUnit struct = availableStructs.get(structCombo.getSelectionIndex());
465
		ArrayList<Property> availables = new ArrayList<Property>(struct.getOrderedProperties());
466
		for (int i = 0 ; i < availables.size() ; i++) {
467
			String name = availables.get(i).getName();
468
			if (name.equals("base") || name.equals("project")) //$NON-NLS-1$ //$NON-NLS-2$
469
				availables.remove(i--);
470
		}
471
		ArrayList<Property> selected = new ArrayList<Property>();
472
		if (availables.size() > 0) {
473
			selected.add(availables.remove(0));
474
		}
475
		structSelector.setProperties(availables, selected);
476
	}
477

  
478
	HashMap<Property, TableViewerColumn> columns = new HashMap<Property, TableViewerColumn>();
479
	HashMap<TableViewerColumn, Integer> columnsOrder = new HashMap<TableViewerColumn, Integer>();
480
	private void initColumns() {
481

  
482
		for( TableViewerColumn col : columns.values()) {
483
			col.getColumn().dispose();
484
		}
485
		columnsOrder = new HashMap<TableViewerColumn, Integer>();
486
		columns = new HashMap<Property, TableViewerColumn>();
487

  
488
		if (internalView == null) {
489
			//System.out.println("REMOVE NON USED COLUMNS");
490
		} else {
491
			int c = 0;
492

  
493
			for (final Property prop : internalView.getProperties()) {
494
				if (!columns.containsKey(prop)) {
495
					final TableViewerColumn col = new TableViewerColumn(viewer, SWT.NONE);
496
					col.getColumn().setWidth(100);
497
					col.getColumn().setText(prop.getName());
498
					col.setLabelProvider(new ColumnLabelProvider() {
499
						@Override
500
						public String getText(Object element) {
501
							if (element instanceof Object[]) {
502
								Integer idx = columnsOrder.get(col);
503
								return ""+((Object[])element)[idx]; //$NON-NLS-1$
504
							}
505
							return Messages.InternalViewEditor_16;
506
						}
507
					});
508
					columns.put(prop, col);
509

  
510
				}
511
				TableViewerColumn col = columns.get(prop);
512
				columnsOrder.put(col, c++);
513
			}
514
		}
515
	}
516

  
517
	/**
518
	 * Creates the context menu.
519
	 *
520
	 * @param tableViewer the table viewer
521
	 */
522
	private void createContextMenu() {
523

  
524
		MenuManager menuManager = new MenuManager();
525
		Menu menu = menuManager.createContextMenu(viewer.getTable());
526

  
527
		// Set the MenuManager
528
		viewer.getTable().setMenu(menu);
529
		getSite().registerContextMenu(menuManager, viewer);
530
		// Make the selection available
531
		getSite().setSelectionProvider(viewer);
532
	}
533

  
534
	/* (non-Javadoc)
535
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
536
	 */
537
	@Override
538
	public void setFocus() {
539

  
540
	}
541

  
542

  
543
	public String buildQuery() {
544
		TableColumn[] cols = viewer.getTable().getColumns();
545
		TableItem[] items = viewer.getTable().getItems();
546
		int[] indexes = viewer.getTable().getSelectionIndices();
547
		if (indexes.length == 0 ) return ""; //$NON-NLS-1$
548

  
549
		StringBuffer query = new StringBuffer("["); //$NON-NLS-1$
550
		for (int icol = 0 ; icol < cols.length ; icol++) {
551
			TableColumn col = cols[icol];
552
			if (icol > 0)
553
				query.append(" & " +col.getText()+"=\""); //$NON-NLS-1$ //$NON-NLS-2$
554
			else
555
				query.append(col.getText()+"=\""); //$NON-NLS-1$
556
			HashSet<String> values = new HashSet<String>();
557
			for (int i = 0 ; i < indexes.length ; i++) {
558
				int idx = indexes[i];
559
				values.add(Query.addBackSlash(items[idx].getText(icol)));
560
			}
561
			boolean firstValue = true;
562
			for (String value : values) {
563
				if (firstValue) {
564
					query.append(value);
565
					firstValue = false;
566
				} else {
567
					query.append("|"+value); //$NON-NLS-1$
568
				}
569
			}
570
			query.append("\""); //$NON-NLS-1$
571
		}
572
		query.append("]"); //$NON-NLS-1$
573
		System.out.println(Messages.InternalViewEditor_25+query);
574
		return query.toString();
575
	}
576

  
577
	//TODO move/replace this to a link / with a command call
578
//	public Object toConcordance(){
579
//		String query = buildQuery();
580
//		if (query == null) return null;
581
//
582
//		Concordance concordance = new Concordance(corpus);
583
//		concordance.setParameters(new Query(query), null, null, null, null, null, null, null, null, null, null);
584
//		TXMResultEditorInput editorInput = new TXMResultEditorInput(concordance);
585
//		IWorkbenchPage page = this.getSite().getPage();
586
//		try {
587
//			ConcordanceEditor conceditor = (ConcordanceEditor) page
588
//					.openEditor(editorInput, "ConcordanceEditor"); //$NON-NLS-1$
589
//			return conceditor;
590
//		} catch (PartInitException e) {
591
//			System.err.println(NLS.bind(Messages.GetConcordances_4, e));
592
//		}
593
//		return null;
594
//	}
595
//
596
//	public Object toIndex() {
597
//		String query = buildQuery();
598
//		if (query == null) return null;
599
//		try {
600
//			Index index = new Index(corpus);
601
//			index.setParameters(new Query(query), Arrays.asList(corpus.getWordProperty()), null, null, null, null);
602
//			TXMResultEditorInput editorInput = new TXMResultEditorInput(index);
603
//			IWorkbenchPage page = this.getSite().getPage();
604
//
605
//			IndexEditor voceditor = (IndexEditor) page
606
//					.openEditor(editorInput,
607
//							"org.txm.rcp.editors.index.IndexEditor"); //$NON-NLS-1$
608
//			voceditor.setFocus(query);
609
//			voceditor.computeResult();
610
//			return voceditor;
611
//		} catch (Exception e) {
612
//			System.err.println(NLS.bind(Messages.GetConcordances_4, e));
613
//		}
614
//		return null;
615
//	}
616

  
617
	public boolean backToText(Line line) {
618
		Match m = line.getMatch();
619
		internalView.getCurrentSegmentNo();
620
		int[] cpos= {m.getStart()};
621
		int[] n;
622
		try {
623
			StructuralUnitProperty sup = null;
624
			for (StructuralUnitProperty s : internalView.getStructuralUnit().getProperties()) {
625
				sup = s;
626
				break;
627
			}
628
			n = CQPEngine.getCqiClient().cpos2Struc(sup.getQualifiedName(), cpos);
629
			return goToPage(n[0]);
630
		} catch (Exception e) {
631
			System.out.println("Error while internal view go back to "+line);
632
			Log.printStackTrace(e);
633
		} 
634
		return false;
635
	}
636

  
637
	@Override
638
	protected void initializeFields() {
639
		try { // init combos
640
			availables = new ArrayList<Property>(corpus.getOrderedProperties());
641
			availableStructs = corpus.getStructuralUnits();
642
			
643
			selected = new ArrayList<Property>();
644
			
645
			if (internalView.getProperties() != null && internalView.getProperties().size() > 0) {
646
				selected = internalView.getProperties();
647
				availables.removeAll(selected);
648
				propSelector.setProperties(availables, selected);
649
			} else {
650
				availables.remove(corpus.getProperty("word")); //$NON-NLS-1$
651
				selected.add(corpus.getProperty("word")); //$NON-NLS-1$
652
				propSelector.setCorpus(corpus);
653
			}
654
			
655
			if (internalView.getCurrentSegmentNo() != null) {
656
				Integer n = internalView.getCurrentSegmentNo();
657
				n++;
658
				navigation.setInfoLineText(n.toString(), internalView.getLocationTail());
659
			}
660

  
661
			for (StructuralUnit struct : availableStructs)
662
				structCombo.add(struct.toString());
663
			if (availableStructs.size() > 0) {
664
				int hasS = -1;
665
				int hasP = -1;
666
				for (int i = 0 ; i < availableStructs.size() ; i++) {
667
					if (availableStructs.get(i).getName().equals("s")) hasS = i; //$NON-NLS-1$
668
					else if (availableStructs.get(i).getName().equals("p")) hasP = i; //$NON-NLS-1$
669
				}
670

  
671
				if (hasS > 0) { 
672
					structCombo.select(hasS);
673
				} else if (hasP > 0) {
674
					structCombo.select(hasP);
675
				} else {
676
					structCombo.select(0);
677
				}	
678

  
679
				structCombo.addSelectionListener(new SelectionListener() {
680
					@Override
681
					public void widgetSelected(SelectionEvent e) {
682
						reloadStructuralUnitProperties();
683
					}
684

  
685
					@Override
686
					public void widgetDefaultSelected(SelectionEvent e) { }
687
				});
688
				
689
				reloadStructuralUnitProperties();
690
			}
691
		} catch (CqiClientException e) {
692
			System.out.println(Messages.InternalViewEditor_10);
693
			org.txm.rcp.utils.Logger.printStackTrace(e);
694
		}
695
	}
696
}
0 697

  
tmp/org.txm.internalview.rcp/build.properties (revision 503)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml
0 6

  
tmp/org.txm.internalview.rcp/plugin.xml (revision 503)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin> <extension
4
         point="org.eclipse.ui.commands">
5
      <command
6
            categoryId="org.txm.rcp.category.txm"
7
            defaultHandler="org.txm.rcp.internal.rcp.handler.ComputeInternalView"
8
            id="org.txm.rcp.internal.rcp.handler.ComputeInternalView"
9
            name="InternalView">
10
      </command>
11
   </extension>   <extension
12
         point="org.eclipse.ui.menus">
13
      <menuContribution
14
            allPopups="false"
15
            locationURI="toolbar:org.txm.rcp.toolbartools">
16
         <command
17
               commandId="org.txm.rcp.internal.rcp.handler.ComputeInternalView"
18
               icon="icons/functions/InternalView.png"
19
               style="push">
20
            <visibleWhen
21
                  checkEnabled="false">
22
               <reference
23
                     definitionId="OneCorpusSelected">
24
               </reference>
25
            </visibleWhen>
26
         </command>
27
      </menuContribution>
28
      <menuContribution
29
            allPopups="false"
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff