Révision 3947

TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/HashMapWidget.java (revision 3947)
1
package org.txm.rcp.swt;
2

  
3
import java.util.HashMap;
4
import java.util.LinkedHashMap;
5

  
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.events.MouseEvent;
8
import org.eclipse.swt.events.MouseListener;
9
import org.eclipse.swt.events.SelectionEvent;
10
import org.eclipse.swt.events.SelectionListener;
11
import org.eclipse.swt.widgets.Button;
12
import org.eclipse.swt.widgets.Composite;
13
import org.eclipse.swt.widgets.Label;
14
import org.txm.rcp.messages.TXMUIMessages;
15
import org.txm.rcp.swt.dialog.HashMapDialog;
16

  
17
/**
18
 * Widget : label + button to open the selector
19
 * 
20
 * @author mdecorde
21
 *
22
 */
23
public class HashMapWidget extends GLComposite {
24
	
25
	Label valueLabel;
26
	Button changeValues;
27
	LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
28
	LinkedHashMap<String, String> defaultValues = new LinkedHashMap<String, String>();
29

  
30
	public HashMapWidget(Composite parent, int style, String name) {
31
		
32
		super(parent, style, name);
33
		
34
		new Label(parent, SWT.NONE).setText(name);
35
		
36
		valueLabel = new Label(parent, SWT.NONE);
37
		valueLabel.addMouseListener(new MouseListener() {
38
			
39
			@Override
40
			public void mouseUp(MouseEvent e) { }
41
			
42
			@Override
43
			public void mouseDown(MouseEvent e) { }
44
			
45
			@Override
46
			public void mouseDoubleClick(MouseEvent e) {
47
				
48
				HashMapDialog dialog = new HashMapDialog(e.display.getActiveShell(), "Negativ filters", defaultValues, values);
49
				if (dialog.open() == HashMapDialog.OK) {
50
					values = dialog.getValues();
51
					updateLabel();
52
				}
53
				
54
			}
55
		});
56
		
57
		changeValues = new Button(parent, SWT.PUSH);
58
		changeValues.setText(TXMUIMessages.edit);
59
		changeValues.addSelectionListener(new SelectionListener() {
60
			
61
			@Override
62
			public void widgetSelected(SelectionEvent e) {
63
				
64
				HashMapDialog dialog = new HashMapDialog(e.display.getActiveShell(), "Negativ filters", defaultValues, values);
65
				if (dialog.open() == HashMapDialog.OK) {
66
					values = dialog.getValues();
67
					updateLabel();
68
				}
69
			}
70
			
71
			@Override
72
			public void widgetDefaultSelected(SelectionEvent e) { }
73
		});
74
	}
75
	
76
	public void setDefaultValues(LinkedHashMap<String, String> values) {
77
		
78
		this.defaultValues.clear();
79
		if (defaultValues == null) return;
80
		
81
		this.defaultValues.putAll(values);
82
	}
83
	
84
	public void setValues(LinkedHashMap<String, String> values) {
85
		
86
		this.values.clear();
87
		if (values == null) return;
88
		
89
		this.values.putAll(values);
90
		updateLabel();
91
	}
92

  
93
	protected void updateLabel() {
94
		
95
		if (valueLabel.isDisposed()) return;
96
		
97
		String s = "";
98
		for (String k : values.keySet()) {
99
			if (values.get(k) != null && values.get(k).length() > 0) {
100
				if (s.length() > 0) s += ", ";
101
				s += k+ "=" + values.get(k);
102
			}
103
		}
104
		valueLabel.setText(s);
105
		valueLabel.getParent().layout(true);
106
		valueLabel.getParent().getParent().layout(true);
107
		
108
	}
109

  
110
	public LinkedHashMap<String, String> getValues() {
111
		
112
		return new LinkedHashMap<>(values);
113
	}
114
	
115
	public LinkedHashMap<String, String> getDefaultValues() {
116
		
117
		return new LinkedHashMap<>(defaultValues);
118
	}
119
}
0 120

  
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/dialog/HashMapDialog.java (revision 3947)
1
package org.txm.rcp.swt.dialog;
2

  
3
import java.util.HashMap;
4
import java.util.LinkedHashMap;
5

  
6
import org.eclipse.jface.dialogs.Dialog;
7
import org.eclipse.swt.SWT;
8
import org.eclipse.swt.layout.GridData;
9
import org.eclipse.swt.layout.GridLayout;
10
import org.eclipse.swt.widgets.Composite;
11
import org.eclipse.swt.widgets.Control;
12
import org.eclipse.swt.widgets.Label;
13
import org.eclipse.swt.widgets.Shell;
14
import org.eclipse.swt.widgets.Text;
15

  
16
/**
17
 * Dialog to set HashMap values given a HashMap pre-filled with values to edit
18
 * 
19
 * @author mdecorde
20
 *
21
 */
22
public class HashMapDialog extends Dialog {
23

  
24
	LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
25
	LinkedHashMap<String, String> defaultValues = new LinkedHashMap<String, String>();
26
	HashMap<String, Text> fields = new HashMap<String, Text>();
27
	String title;
28
	
29
	/**
30
	 * 
31
	 * @param parentShell
32
	 * @param title
33
	 * @param values values to edit, value may be null
34
	 */
35
	public HashMapDialog(Shell parentShell, String title, LinkedHashMap<String, String> defaultValues, LinkedHashMap<String, String> values) {
36
		
37
		super(parentShell);
38
		
39
		this.title = title;
40
		
41
		if (defaultValues != null) {
42
			this.values.putAll(defaultValues);
43
		}
44

  
45
		if (values != null) {
46
			this.values.putAll(values);
47
		}
48
	}
49
	
50
	@Override
51
	protected void configureShell(Shell newShell) {
52
		
53
		super.configureShell(newShell);
54
		newShell.setText(title);
55
	} 
56
	
57
	@Override
58
	protected Control createDialogArea(Composite parent) {
59
		
60
		parent.setLayout(new GridLayout(2, false));
61
		
62
		for (String k : values.keySet()) {
63
			Label l = new Label(parent, SWT.NONE);
64
			l.setText(k);
65
			l.setLayoutData(new GridData());
66
			
67
			Text field = new Text(parent, SWT.BORDER);
68
			field.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
69
			if (values.get(k) != null) {
70
				field.setText(values.get(k));
71
			}
72
			
73
			fields.put(k, field);
74
		}
75
		
76
		return parent;
77
	}
78
	
79
	@Override
80
	protected void okPressed() {
81
		
82
		values.clear();
83
		for (String k : fields.keySet()) {
84
			if (fields.get(k).getText().length() > 0) {
85
				values.put(k, fields.get(k).getText());
86
			}
87
		}
88
		
89
		super.okPressed();
90
	}
91
	
92
	/**
93
	 * 
94
	 * @return the values set
95
	 */
96
	public LinkedHashMap<String, String> getValues() {
97
		
98
		return values;
99
	}
100
}
0 101

  
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/dialog/ComboDialog.java (revision 3947)
37 37
import org.eclipse.swt.widgets.Composite;
38 38
import org.eclipse.swt.widgets.Control;
39 39
import org.eclipse.swt.widgets.Label;
40
import org.eclipse.swt.widgets.Layout;
41 40
import org.eclipse.swt.widgets.Shell;
42 41
import org.txm.rcp.messages.TXMUIMessages;
43 42

  
......
85 84
	 * @param defaultValue the default value (may be null)
86 85
	 */
87 86
	public ComboDialog(Shell parentShell, String title, List<String> values, String defaultValue) {
87
		
88 88
		this(parentShell, title, values, defaultValue, null);
89
		
90 89
	}
91 90
	
92 91
	/**
......
98 97
	 * @param defaultValue the default value (may be null)
99 98
	 * @param comboStyle if null combo is SINGLE and READONLY
100 99
	 */
101
	public ComboDialog(Shell parentShell, String title, List<String> values,
102
			String defaultValue, Integer comboStyle) {
100
	public ComboDialog(Shell parentShell, String title, List<String> values, String defaultValue, Integer comboStyle) {
101
		
103 102
		super(parentShell);
104 103
		this.parentShell = parentShell;
105 104
		this.setShellStyle(this.getShellStyle());
......
114 113
	 */
115 114
	@Override
116 115
	protected void configureShell(Shell newShell) {
116
		
117 117
		super.configureShell(newShell);
118 118
		newShell.setText(title);
119 119
	}
......
139 139
			style = comboStyle;
140 140
		}
141 141
		combo = new Combo(p, style);
142
		combo.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true,
143
				true, 5, 1));
142
		combo.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 5, 1));
144 143
		combo.setItems(values.toArray(new String[] {}));
145 144
		// combo.setLayoutData(new GridData(GridData.FILL,GridData.FILL, true,
146 145
		// true));
......
157 156
	 */
158 157
	@Override
159 158
	protected void okPressed() {
159
		
160 160
		selectedIndex = combo.getSelectionIndex();
161 161
		selectedValue = values.get(selectedIndex);
162 162
		super.okPressed();
......
168 168
	 * @return the values
169 169
	 */
170 170
	public List<String> getValues() {
171
		
171 172
		return values;
172 173
	}
173 174

  
......
177 178
	 * @param values the new values
178 179
	 */
179 180
	public void setValues(List<String> values) {
181
		
180 182
		this.values = values;
181 183
		combo.setItems(values.toArray(new String[] {}));
182
		if (values.size() > 0)
184
		if (values.size() > 0) {
183 185
			combo.select(0);
186
		}
184 187
	}
185 188

  
186 189
	/**
......
189 192
	 * @return the selected index
190 193
	 */
191 194
	public int getSelectedIndex() {
195
		
192 196
		return selectedIndex;
193 197
	}
194 198

  
......
198 202
	 * @return the selected value
199 203
	 */
200 204
	public String getSelectedValue() {
205
		
201 206
		return selectedValue;
202 207
	}
203 208

  
......
207 212
	 * @param string the string
208 213
	 */
209 214
	public void selectValue(String string) {
215
		
210 216
		for (int i = 0; i < values.size(); i++)
211 217
			if (values.get(i).equals(string)) {
212 218
				combo.select(i);
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/dialog/PropertySelector.java (revision 3947)
46 46
import org.txm.searchengine.cqp.corpus.CQPCorpus;
47 47
import org.txm.searchengine.cqp.corpus.Property;
48 48

  
49
// TODO: Auto-generated Javadoc
50 49
/**
51
 * The Class PropertySelector.
50
 * Select and order a properties list
52 51
 */
53 52
public class PropertySelector extends Dialog {
54 53

  
......
77 76
	 * @param corpus the corpus
78 77
	 */
79 78
	public PropertySelector(Shell parentShell, CQPCorpus corpus) {
79
		
80 80
		super(parentShell);
81 81
		try {
82 82
			this.properties = new ArrayList<Property>(corpus.getOrderedProperties());
......
96 96
	 * @param title the title
97 97
	 * @param mess the mess
98 98
	 */
99
	public PropertySelector(Shell parentShell, CQPCorpus corpus, String title,
100
			String mess) {
99
	public PropertySelector(Shell parentShell, CQPCorpus corpus, String title, String mess) {
100
		
101 101
		super(parentShell);
102 102
		this.corpus = corpus;
103 103
		this.title = title;
......
115 115
	 */
116 116
	@Override
117 117
	protected void configureShell(Shell newShell) {
118
		
118 119
		super.configureShell(newShell);
119 120
		newShell.setText(TXMUIMessages.selectAProperty);
120
		if (title != null)
121
		if (title != null) {
121 122
			newShell.setText(title);
123
		}
122 124
	}
123 125

  
124 126
	/** The composite. */
......
129 131
	 */
130 132
	@Override
131 133
	protected Control createDialogArea(Composite parent) {
134
		
132 135
		composite = new Composite(parent, SWT.NONE);
133 136
		GridLayout layout = new GridLayout(2, false);
134 137
		composite.setLayout(layout);
......
163 166
	 */
164 167
	@Override
165 168
	protected void okPressed() {
169
		
166 170
		int propIndex = anaPropCombo.getSelectionIndex();
167 171
		if (propIndex == -1) {
168 172
			MessageDialog.openError(getShell(),
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/PropertiesSelector.java (revision 3947)
33 33

  
34 34
import org.eclipse.osgi.util.NLS;
35 35
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.events.MouseEvent;
37
import org.eclipse.swt.events.MouseListener;
36 38
import org.eclipse.swt.events.SelectionEvent;
37 39
import org.eclipse.swt.events.SelectionListener;
38 40
import org.eclipse.swt.layout.GridData;
......
43 45
import org.eclipse.swt.widgets.Listener;
44 46
import org.txm.objects.CorpusBuild;
45 47
import org.txm.rcp.messages.TXMUIMessages;
48
import org.txm.rcp.swt.dialog.HashMapDialog;
46 49
import org.txm.rcp.swt.dialog.MultiplePropertySelectionDialog;
47 50
import org.txm.rcp.swt.dialog.SinglePropertySelectionDialog;
48 51
import org.txm.searchengine.core.Property;
......
87 90
	
88 91
	ArrayList<Listener> listeners = new ArrayList<>();
89 92
	
93

  
90 94
	/**
91 95
	 * Instantiates a new properties selector.
92 96
	 *
......
94 98
	 * @param style the style
95 99
	 */
96 100
	public PropertiesSelector(Composite parent, int style) {
101
		this(parent, style, null);
102
	}
103
	
104
	/**
105
	 * Instantiates a new properties selector.
106
	 *
107
	 * @param parent the parent
108
	 * @param style the style
109
	 * @param title widget title to display 
110
	 */
111
	public PropertiesSelector(Composite parent, int style, String title) {
97 112
		super(parent, style);
98 113
		
99 114
		this.setLayout(new GridLayout(3, false));
100 115
		
101 116
		// "properties"
102 117
		propLabel = new Label(this, SWT.NONE);
103
		propLabel.setText(TXMUIMessages.propertiesColon);
118
		if (title != null) {
119
			propLabel.setText(title);
120
		} else {
121
			propLabel.setText(TXMUIMessages.propertiesColon);
122
		}
104 123
		propLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, true));
105 124
		
106 125
		// selected properties
107 126
		propertiesLabel = new Label(this, SWT.NONE);
108 127
		propertiesLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
128
		propertiesLabel.addMouseListener(new MouseListener() {
129
			
130
			@Override
131
			public void mouseUp(MouseEvent e) { }
132
			
133
			@Override
134
			public void mouseDown(MouseEvent e) { }
135
			
136
			@Override
137
			public void mouseDoubleClick(MouseEvent e) {
138
				
139
				showEditorDialog();
140
				refresh();
141
			}
142
		});
109 143
		
110 144
		// "edit"
111 145
		openEditDialog = new Button(this, SWT.PUSH);
......
131 165
	 * @param parent
132 166
	 */
133 167
	public PropertiesSelector(Composite parent) {
134
		this(parent, SWT.NONE);
168
		this(parent, SWT.NONE, null);
135 169
	}
136 170
	
171
	/**
172
	 * Instantiates a new properties selector.
173
	 * 
174
	 * @param parent
175
	 */
176
	public PropertiesSelector(Composite parent, String title) {
177
		this(parent, SWT.NONE, titles);
178
	}
179
	
137 180
	public void setButtonText(String text) {
138 181
		if (openEditDialog != null && !openEditDialog.isDisposed()) {
139 182
			openEditDialog.setText(text);
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorporaView.java (revision 3947)
130 130
	 */
131 131
	// private static HashMap<Class, Class> managedDoubleClickClasses = new HashMap<Class, Class>();
132 132
	
133
	
134 133
	public static HashMap<String, String> doubleClickInstalledCommands = new HashMap<>();
135 134
	
136
	
137
	// public static HashMap<Class, Class> getManagedDoubleClickClasses() {
138
	// return managedDoubleClickClasses;
139
	// }
140
	
141
	
142 135
	/**
143 136
	 * Gets the single instance of CorporaView.
144 137
	 *
......
157 150
	}
158 151
	
159 152
	public TreeViewer getTreeViewer() {
153
		
160 154
		return treeViewer;
161 155
	}
162 156
	
......
492 486
	 */
493 487
	@Override
494 488
	public void setFocus() {
489
		
495 490
		treeViewer.getControl().setFocus();
496 491
	}
497 492
	
......
501 496
	 * @return
502 497
	 */
503 498
	public static Object getFirstSelectedObject() {
499
		
504 500
		CorporaView corporaView = getInstance();
505 501
		if (corporaView != null) {
506 502
			try {
......
521 517
	 * @return
522 518
	 */
523 519
	public static List<?> getSelectedObjects() {
520
		
524 521
		CorporaView corporaView = getInstance();
525 522
		if (corporaView != null) {
526 523
			try {
......
585 582
	 * Refresh the tree view.
586 583
	 */
587 584
	public static void refresh() {
585
		
588 586
		CorporaView corporaView = getInstance();
589 587
		if (corporaView != null) {
590 588
			corporaView.treeViewer.refresh();
......
602 600
		corporaView.treeViewer.refresh();
603 601
	}
604 602
	
605
	
606
	
607 603
	/**
608 604
	 * Refreshes the specified result node in the tree view.
609 605
	 * 
610 606
	 * @param result
611 607
	 */
612 608
	public static void refreshObject(final TXMResult result) {
609
		
613 610
		Display.getDefault().syncExec(new Runnable() {
614 611
			
615 612
			@Override
616 613
			public void run() {
617 614
				
618 615
				CorporaView corporaView = getInstance();
619
				
620 616
				corporaView.treeViewer.refresh();
621 617
				
622 618
				try {
623 619
					CorporaView.expand(result.getParent());
624 620
				}
625
				catch (NullPointerException e) {
626
				}
621
				catch (NullPointerException e) { }
627 622
			}
628 623
		});
629 624
	}
......
634 629
	 * @param editor
635 630
	 */
636 631
	public static void refreshObject(TXMEditor editor) {
632
		
637 633
		refreshObject(editor.getResult());
638 634
	}
639 635
	
......
643 639
	 * @param obj
644 640
	 */
645 641
	public static void expand(Object obj) {
642
		
646 643
		final CorporaView corporaView = getInstance();
647 644
		if (obj != null) {
648 645
			corporaView.treeViewer.expandToLevel(obj, 1);
......
654 651
	 * @param obj
655 652
	 */
656 653
	public static void reveal(TXMResult obj) {
654
		
657 655
		final CorporaView corporaView = getInstance();
658 656
		if (obj != null && corporaView != null) {
659 657
			corporaView.treeViewer.reveal(obj);
......
666 664
	 * @return
667 665
	 */
668 666
	public static boolean isActive() {
667
		
669 668
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
670 669
		if (window == null) {
671 670
			return false;
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/commands/function/RefreshCorporaView.java (revision 3947)
5 5
import org.eclipse.core.commands.ExecutionException;
6 6
import org.txm.rcp.views.corpora.CorporaView;
7 7

  
8
/**
9
 * Refresh the corpora view TreeViewer
10
 * 
11
 * @author mdecorde
12
 *
13
 */
8 14
public class RefreshCorporaView extends AbstractHandler  {
9 15

  
10 16
	@Override
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 3947)
6 6
import java.lang.reflect.Field;
7 7
import java.util.ArrayList;
8 8
import java.util.Arrays;
9
import java.util.HashMap;
9 10
import java.util.HashSet;
10 11
import java.util.LinkedHashMap;
11 12
import java.util.List;
......
79 80
import org.txm.rcp.messages.TXMUIMessages;
80 81
import org.txm.rcp.preferences.RCPPreferences;
81 82
import org.txm.rcp.swt.GLComposite;
83
import org.txm.rcp.swt.HashMapWidget;
82 84
import org.txm.rcp.swt.dialog.ComputeProgressMonitorDialog;
83 85
import org.txm.rcp.swt.widget.AssistedChoiceQueryWidget;
84 86
import org.txm.rcp.swt.widget.AssistedQueryWidget;
......
975 977
								Log.finest("TXMEditor.compute(): " + TXMEditor.this.getClass().getSimpleName() + ": auto updating result from editor."); //$NON-NLS-1$ //$NON-NLS-2$
976 978
								autoUpdateResultFromEditorParameters();
977 979
								
978
								
979
								
980 980
								// FIXME: SJ: useless at this time?
981 981
								// Stores the last parameters before the computing to later auto-update the Widgets only if some parameters have changed
982 982
								// setLastComputingParameters(TXMEditor.this.getResult().getLastParametersFromHistory());
......
1383 1383
	 * NewNavigationWidget (Integer)
1384 1384
	 * AssistedQueryWidget (String, from Query)
1385 1385
	 * QueryWidget (String, from Query)
1386
	 * HashMapWidget (HashMap<String, String>)
1386 1387
	 * 
1387 1388
	 */
1388 1389
	public void autoUpdateEditorFieldsFromResult(boolean update) {
......
1477 1478
				else if (object instanceof NewNavigationWidget) {
1478 1479
					((NewNavigationWidget) object).setCurrentPosition((Integer) value);
1479 1480
				}
1481
				else if (object instanceof HashMapWidget) {
1482
					((HashMapWidget) object).setValues((LinkedHashMap) value);
1483
				}
1480 1484
				else if (object instanceof AssistedChoiceQueryWidget) {
1481 1485
					if (!((IQuery) value).getQueryString().isEmpty()) {
1482 1486
						((AssistedChoiceQueryWidget) object).setText(((IQuery) value).getQueryString());
......
1575 1579
				else if (object instanceof FloatSpinner) {
1576 1580
					value = ((FloatSpinner) object).getSelectionAsFloat();
1577 1581
				}
1582
				else if (object instanceof HashMapWidget) {
1583
					value = ((HashMapWidget) object).getValues();
1584
				}
1578 1585
				else if (object instanceof Spinner) {
1579 1586
					value = ((Spinner) object).getSelection();
1580 1587
				}
TXM/trunk/bundles/org.txm.texts.core/src/org/txm/texts/core/TextsView.java (revision 3947)
1 1
package org.txm.texts.core;
2 2

  
3 3
import java.io.File;
4
import java.io.ObjectOutputStream;
4 5
import java.io.PrintWriter;
6
import java.io.StringReader;
7
import java.io.StringWriter;
5 8
import java.util.ArrayList;
9
import java.util.HashMap;
6 10
import java.util.LinkedHashMap;
7 11
import java.util.List;
12
import java.util.Properties;
8 13

  
9 14
import org.apache.commons.lang.StringUtils;
10 15
import org.eclipse.osgi.util.NLS;
......
30 35
	//	ArrayList<String> positiveFilters;
31 36

  
32 37
	@Parameter(key = "negativeFilters")
33
	String negativeFilters;
38
	LinkedHashMap<String, String> negativeFilters;
34 39

  
35 40
	private LinkedHashMap<String, ArrayList<String>> result;
36 41

  
......
53 58
	@Override
54 59
	public boolean saveParameters() throws Exception {
55 60

  
56
		this.saveParameter("columns", StringUtils.join(pColumns, "\t"));
61
		
62
		String s = "";
63
		for (StructuralUnitProperty sup : pColumns) {
64
			if (s.length() > 0) s += "\t";
65
			s += sup.getFullName();
66
		}
67
		this.saveParameter("columns", s);
57 68
		//		this.saveParameter("positiveFilters", StringUtils.join(positiveFilters, "\t"));
58
		this.saveParameter("negativeFilters", negativeFilters);
69
		
70
		Properties props = new Properties();
71
		props.putAll(negativeFilters);
72
		StringWriter sw = new StringWriter();
73
		props.store(sw, "");
74
		this.saveParameter("negativeFilters", sw.toString());
59 75
		return true;
60 76
	}
61 77

  
......
64 80

  
65 81
		String v = this.getStringParameterValue("columns").toString();
66 82
		if ("*".equals(v)) {
67
			;
83
			
68 84
			this.pColumns = new ArrayList<>(getCorpus().getStructuralUnit("text").getUserDefinedOrderedProperties());
69 85
			for (int i = 0 ; i < pColumns.size() ; i++) {
70 86
				if (pColumns.get(i).getName().equals("id")) {
......
77 93
		}
78 94

  
79 95
		v = this.getStringParameterValue("negativeFilters").toString();
80
		if (v.contains("=")) {
81
			this.negativeFilters = v;
82
		} else {
83
			this.negativeFilters = "";
96
		this.negativeFilters = new LinkedHashMap<String, String>();
97
		if (v != null && v.length() > 0) {
98
			Properties props = new Properties();
99
			props.load(new StringReader(v));
100
			
101
			for (Object k : props.keySet()) negativeFilters.put(k.toString(), props.get(k.toString()).toString());
84 102
		}
85 103

  
86 104
		//		v = this.getStringParameterValue("positiveFilters").toString();
......
172 190
				}
173 191
			}
174 192
		}
175
		
176
		
177 193

  
178
		if (negativeFilters.length() > 0 && pColumns.size() > 0) {
194
		if (negativeFilters.size() > 0 && pColumns.size() > 0) {
179 195

  
180 196
			ArrayList<String> columnNames = new ArrayList<>(pColumns.size());
181 197
			for (StructuralUnitProperty p : pColumns) columnNames.add(p.getName());
182 198

  
183
			String[] filters = negativeFilters.split(";");
184

  
185 199
			ArrayList<String> keys = new ArrayList<>(result.keySet());
186 200
			for (String text : keys) {
187 201

  
188
				for (String negativeFilter : filters) {
189
					String[] split = negativeFilter.split("=", 2);
190
					if (split.length == 2 
191
							&& columnNames.contains(split[0]) 
192
							&& result.get(text).get(columnNames.indexOf(split[0])).matches(split[1])) {
202
				for (String negativeFilter : negativeFilters.keySet()) {
203
					if (columnNames.contains(negativeFilter) 
204
							&& result.get(text).get(columnNames.indexOf(negativeFilter)).matches(negativeFilters.get(negativeFilter))) {
193 205
						// remove this line
194 206
						result.remove(text);
195 207
						break;
TXM/trunk/bundles/org.txm.texts.rcp/src/org/txm/texts/rcp/TextsViewEditor.java (revision 3947)
1 1
package org.txm.texts.rcp;
2 2

  
3 3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.LinkedHashMap;
4 6
import java.util.List;
5 7

  
6 8
import org.eclipse.e4.ui.workbench.modeling.EModelService;
......
18 20
import org.eclipse.swt.graphics.Point;
19 21
import org.eclipse.swt.layout.GridData;
20 22
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Label;
22 23
import org.eclipse.swt.widgets.TableColumn;
23 24
import org.txm.Toolbox;
24 25
import org.txm.core.results.Parameter;
......
31 32
import org.txm.rcp.editors.TableKeyListener;
32 33
import org.txm.rcp.editors.TableLinesViewerComparator;
33 34
import org.txm.rcp.editors.listeners.ComputeSelectionListener;
35
import org.txm.rcp.swt.HashMapWidget;
34 36
import org.txm.rcp.swt.widget.PropertiesSelector;
35 37
import org.txm.rcp.utils.SWTEditorsUtils;
36 38
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
......
42 44
	PropertiesSelector<StructuralUnitProperty> propertiesSelector;
43 45
	
44 46
	@Parameter(key = "negativeFilters")
45
	org.eclipse.swt.widgets.Text negativeFiltersText;
47
	HashMapWidget negativeFiltersText;
46 48
	
47 49
	TableViewer viewer;
48 50
//	HashMap<String, TableViewerColumn> columns = new HashMap<String, TableViewerColumn>();
......
56 58
		
57 59
		this.getMainParametersComposite().getLayout().numColumns = 10;
58 60
		
59
		propertiesSelector = new PropertiesSelector<>(this.getMainParametersComposite());
60 61
		ArrayList<StructuralUnitProperty> properties = new ArrayList<>(getResult().getCorpus().getStructuralUnitProperties("text"));
61 62
		for (int i = 0 ; i < properties.size() ; i++) {
62
			if (properties.get(i).getName().equals("id")) {
63
			if (properties.get(i).getName().equals("id") || properties.get(i).getName().equals("project")) {
63 64
				properties.remove(i);
64 65
				break;
65 66
			}
66 67
		}
68
		Collections.sort(properties);
69
		
70
		ComputeSelectionListener computeSelectionListener = new ComputeSelectionListener(this);
71
		
72
		propertiesSelector = new PropertiesSelector<>(this.getMainParametersComposite(), "Metadata");
67 73
		propertiesSelector.setProperties(properties);
68
		ComputeSelectionListener computeSelectionListener = new ComputeSelectionListener(this);
69 74
		propertiesSelector.addSelectionListener(computeSelectionListener);
70
		
71
		new Label(this.getMainParametersComposite(), SWT.NONE).setText("Negative filters (p1=v1;p2=v2)");
72
		
73
		negativeFiltersText = new org.eclipse.swt.widgets.Text(this.getMainParametersComposite(), SWT.BORDER);
74
		negativeFiltersText.addSelectionListener(computeSelectionListener);
75
		GridData gdata = new GridData(GridData.FILL, GridData.CENTER, true, false);
76
		gdata.minimumWidth = 300;
75
				
76
		negativeFiltersText = new HashMapWidget(this.getMainParametersComposite(), SWT.NONE, "Negative filters: ");
77
		//negativeFiltersText.addSelectionListener(computeSelectionListener);
78
		GridData gdata = new GridData(GridData.FILL, GridData.FILL, false, false);
77 79
		negativeFiltersText.setLayoutData(gdata);
80
		LinkedHashMap<String, String> defaultValues = new LinkedHashMap<String, String>();
81
		for (StructuralUnitProperty sup : properties) {
82
			defaultValues.put(sup.getName(), "");
83
		}
84
		negativeFiltersText.setDefaultValues(defaultValues);
78 85
		
79 86
		viewer = new TableViewer(this.getResultArea(), SWT.MULTI|SWT.VIRTUAL);
80 87
		viewer.getTable().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
TXM/trunk/bundles/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/StructuralUnitProperty.java (revision 3947)
39 39
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
40 40
import org.txm.searchengine.cqp.clientExceptions.UnexpectedAnswerException;
41 41
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
42
import org.txm.searchengine.cqp.corpus.query.MatchUtils;
43 42
import org.txm.searchengine.cqp.serverException.CqiServerError;
44 43
import org.txm.utils.logger.Log;
45 44

  
......
57 56
	/** The structural unit. */
58 57
	private StructuralUnit structuralUnit;
59 58
	
60
	
61
	
62 59
	/**
63 60
	 * Instantiates a new structural unit property.
64 61
	 * 
......
66 63
	 *
67 64
	 * @param structuralUnit the structural unit
68 65
	 * @param name the name
69
	 * @param corpus the corpus
70
	 *            {@link StructuralUnit#getProperty(String)}
66
	 * @param corpus the corpus {@link StructuralUnit#getProperty(String)}
71 67
	 */
72 68
	public StructuralUnitProperty(StructuralUnit structuralUnit, String name, CQPCorpus corpus) {
69
		
73 70
		super(name, corpus);
74 71
		this.structuralUnit = structuralUnit;
75 72
	}
......
80 77
	 * @return the structural unit
81 78
	 */
82 79
	public StructuralUnit getStructuralUnit() {
80
		
83 81
		return structuralUnit;
84 82
	}
85 83
	
......
90 88
	 */
91 89
	@Override
92 90
	public String getFullName() {
91
		
93 92
		return structuralUnit.getName() + "_" + this.getName(); //$NON-NLS-1$
94 93
	}
95 94
	
......
100 99
	 * @return the full name
101 100
	 */
102 101
	public String asFullNameString() {
102
		
103 103
		return this.structuralUnit.getName() + this.asString();
104 104
	}
105 105
	
......
111 111
	 * @return
112 112
	 */
113 113
	public static String asFullNameString(List<StructuralUnitProperty> properties) {
114
		
114 115
		String str = ""; ///$NON-NLS-1$
115 116
		for (int i = 0; i < properties.size(); i++) {
116 117
			if (i > 0) {
......
131 132
	 * @throws CqiClientException the cqi client exception
132 133
	 */
133 134
	public List<String> getValues(CQPCorpus subcorpus) throws CqiClientException {
135
		
134 136
		try {
135 137
			AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
136 138
			return cqiClient.getData(this, subcorpus);
......
163 165
	 * @throws CqiClientException the cqi client exception
164 166
	 */
165 167
	public List<String> getValues(CQPCorpus subcorpus, int number) throws CqiClientException {
168
		
166 169
		try {
167 170
			AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
168 171
			return cqiClient.getData(this, number);
......
191 194
	 * @throws CqiClientException the cqi client exception
192 195
	 */
193 196
	public List<String> getValues() throws CqiClientException {
197
		
194 198
		return getValues(this.getCorpus());
195 199
	}
196 200
	
......
202 206
	 * @throws CqiClientException the cqi client exception
203 207
	 */
204 208
	public List<String> getOrderedValues() throws CqiClientException {
209
		
205 210
		List<String> values = getValues(this.getCorpus());
206 211
		Collections.sort(values);
207 212
		return values;
......
216 221
	 * @throws CqiClientException the cqi client exception
217 222
	 */
218 223
	public List<String> getOrderedValues(CQPCorpus corpus) throws CqiClientException {
224
		
219 225
		List<String> values = getValues(corpus);
220 226
		Collections.sort(values);
221 227
		return values;
......
228 234
	 * @return the number of values in this corpus, -1 if an error occured
229 235
	 */
230 236
	public Integer getNumberOfValues(CQPCorpus corpus) {
237
		
231 238
		try {
232 239
			QueryResult tmp = corpus.query(new CQLQuery("<" + this.getFullName() + ">[]"), UUID.randomUUID().toString(), false); //$NON-NLS-1$ //$NON-NLS-2$
233 240
			int ret = tmp.getNMatch();
......
248 255
	 * @return
249 256
	 */
250 257
	public static List<StructuralUnitProperty> stringToProperties(CQPCorpus corpus, String str) {
258
		
251 259
		ArrayList<StructuralUnitProperty> structs = new ArrayList<>();
252 260
		if (str == null || str.length() == 0) {
253 261
			return structs;
......
286 294
	 * @throws CqiClientException
287 295
	 */
288 296
	public static StructuralUnitProperty stringToStructuralUnitProperty(CQPCorpus corpus, String str) throws CqiClientException {
297
		
289 298
		if (str == null) {
290 299
			return null;
291 300
		}
......
304 313
	}
305 314
	
306 315
	public String cpos2Str(int position) throws UnexpectedAnswerException, IOException, CqiServerError {
316
		
307 317
		AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
308 318
		return cqiClient.getSingleData(this, new int[] { position }).get(0);
309 319
	}
310 320
	
311 321
	public String[] cpos2Str(int[] positions) throws UnexpectedAnswerException, IOException, CqiServerError {
322
		
312 323
		AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
313 324
		return cqiClient.getSingleData(this, positions).toArray(new String[positions.length]);
314 325
	}
......
322 333
	 * @throws CqiClientException
323 334
	 */
324 335
	public int getNValues() throws IOException, CqiServerError, CqiClientException {
336
		
325 337
		return getValues().size();
326 338
	}
327 339
	
......
334 346
	 * @throws CqiClientException
335 347
	 */
336 348
	public String[] getValuesAsStrings() throws IOException, CqiServerError, CqiClientException {
349
		
337 350
		List<String> values = getValues();
338 351
		return values.toArray(new String[values.size()]);
339 352
	}

Formats disponibles : Unified diff