Révision 4000

TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/actions/CreateSubcorpusDialog.java (revision 4000)
47 47
import org.eclipse.swt.widgets.TabFolder;
48 48
import org.eclipse.swt.widgets.TabItem;
49 49
import org.eclipse.swt.widgets.Text;
50
import org.txm.core.preferences.TBXPreferences;
50 51
import org.txm.rcp.messages.TXMUIMessages;
51 52
import org.txm.rcp.swt.widget.structures.AdvancedSubcorpusPanel;
52 53
import org.txm.rcp.swt.widget.structures.ComplexSubcorpusPanel;
......
158 159
		complexTab.setControl(complexPanel);
159 160

  
160 161
		// Third tab: assisted mode
161
		contextsTab = new TabItem(tabFolder, SWT.NONE);
162
		contextsTab.setText(TXMUIMessages.contexts);
163
		this.contextsPanel = new ContextsSubcorpusPanel(tabFolder, SWT.NONE, this.corpus);
164
		contextsTab.setControl(contextsPanel);
162
		if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
163
			contextsTab = new TabItem(tabFolder, SWT.NONE);
164
			contextsTab.setText(TXMUIMessages.contexts);
165
			this.contextsPanel = new ContextsSubcorpusPanel(tabFolder, SWT.NONE, this.corpus);
166
			contextsTab.setControl(contextsPanel);
167
		}
165 168

  
166 169
		// Third tab: advanced mode
167 170
		advancedTab = new TabItem(tabFolder, SWT.NONE);
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/actions/CreatePartitionDialog.java (revision 4000)
47 47
import org.eclipse.swt.widgets.TabItem;
48 48
import org.eclipse.swt.widgets.Text;
49 49
import org.txm.core.messages.TXMCoreMessages;
50
import org.txm.core.preferences.TBXPreferences;
50 51
import org.txm.rcp.messages.TXMUIMessages;
51 52
import org.txm.rcp.swt.widget.PartitionComposer;
52 53
import org.txm.rcp.swt.widget.structures.AdvancedPartitionPanel;
......
65 66
 * @author mdecorde.
66 67
 */
67 68
public class CreatePartitionDialog extends Dialog {
68
	
69

  
69 70
	/** The corpus. */
70 71
	private CQPCorpus corpus;
71
	
72

  
72 73
	/** The name text. */
73 74
	private Text nameText;
74
	
75

  
75 76
	/** The partition. */
76 77
	private Partition partition;
77
	
78

  
78 79
	private SimplePartitionPanel simplePanel;
79 80
	private PartitionComposer compositeForAssisted;
80 81
	private CrossedPartitionPanel crossedPanel;
81 82
	private AdvancedPartitionPanel advancedPartitionPanel;
82
	
83

  
83 84
	private TabItem selectedTab;
84 85

  
85 86
	private TabItem simpleTab;
86 87
	private TabItem assistedTab;
87 88
	private TabItem crossedTab;
88 89
	private TabItem advancedTab;
89
	
90

  
90 91
	/**
91 92
	 * Instantiates a new creates the partition dialog.
92 93
	 *
......
94 95
	 * @param corpus the corpus
95 96
	 */
96 97
	public CreatePartitionDialog(Shell parentShell, CQPCorpus corpus) {
97
		
98

  
98 99
		super(parentShell);
99 100
		this.corpus = corpus;
100 101
		this.setShellStyle(this.getShellStyle() | SWT.RESIZE);
101 102
	}
102
	
103

  
103 104
	/*
104 105
	 * (non-Javadoc)
105 106
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
106 107
	 */
107 108
	@Override
108 109
	protected void configureShell(Shell newShell) {
109
		
110

  
110 111
		super.configureShell(newShell);
111 112
		newShell.setText(TXMUIMessages.createPartition);
112 113
		newShell.setMinimumSize(400, 400);
113 114
	}
114
	
115

  
115 116
	/*
116 117
	 * (non-Javadoc)
117 118
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
118 119
	 */
119 120
	@Override
120 121
	protected Control createDialogArea(Composite parent) {
121
		
122

  
122 123
		Composite c = new Composite(parent, SWT.NONE);
123 124
		c.setLayout(new GridLayout(2, false));
124 125
		GridData maindatalayout = new GridData(GridData.FILL, GridData.FILL, true, false);
......
129 130
		Font f = nameLabel.getFont();
130 131
		FontData defaultFont = f.getFontData()[0];
131 132
		defaultFont.setStyle(SWT.BOLD);
132
		
133

  
133 134
		Font newf = new Font(Display.getCurrent(), defaultFont);
134 135
		nameLabel.setText(TXMUIMessages.ampNameColon);
135 136
		nameLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
136 137
		nameLabel.setFont(newf);
137
		
138

  
138 139
		nameText = new Text(c, SWT.BORDER);
139 140
		GridData data = new GridData(GridData.FILL, GridData.FILL, true, false);
140 141
		data.horizontalSpan = 1;
141 142
		nameText.setLayoutData(data);
142
		
143

  
143 144
		final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
144 145
		tabFolder.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
145 146
				true, true));
146 147
		// First tab
147 148
		// --------------------------------------------------------
148
		
149

  
149 150
		simpleTab = new TabItem(tabFolder, SWT.NONE);
150 151
		simpleTab.setText(TXMUIMessages.simple);
151 152
		simplePanel = new SimplePartitionPanel(tabFolder, SWT.NONE, corpus);
152 153
		simpleTab.setControl(simplePanel);
153
		
154

  
154 155
		// Second Tab : assisted mode
155 156
		assistedTab = new TabItem(tabFolder, SWT.NONE);
156 157
		assistedTab.setText(TXMUIMessages.assisted);
157 158
		compositeForAssisted = new PartitionComposer(tabFolder, SWT.NONE, this.corpus);
158 159
		assistedTab.setControl(compositeForAssisted);
159
		
160
		// Second Tab : crossed mode
161
		crossedTab = new TabItem(tabFolder, SWT.NONE);
162
		crossedTab.setText("Crossed");
163
		crossedPanel = new CrossedPartitionPanel(tabFolder, SWT.NONE, this.corpus);
164
		crossedTab.setControl(crossedPanel);
165
		
160

  
161
		if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
162
			// Second Tab : crossed mode
163
			crossedTab = new TabItem(tabFolder, SWT.NONE);
164
			crossedTab.setText("Crossed");
165
			crossedPanel = new CrossedPartitionPanel(tabFolder, SWT.NONE, this.corpus);
166
			crossedTab.setControl(crossedPanel);
167
		}
168

  
166 169
		// Last tab: advanced mode
167 170
		advancedTab = new TabItem(tabFolder, SWT.NONE);
168 171
		advancedTab.setText(TXMUIMessages.advanced);
169 172
		advancedPartitionPanel = new AdvancedPartitionPanel(tabFolder, SWT.NONE, this.corpus);
170 173
		advancedTab.setControl(advancedPartitionPanel);
171
		
174

  
172 175
		selectedTab = simpleTab;
173
		
176

  
174 177
		// check the state of the OK button according to the change of tab
175 178
		// --------------------------------
176
		
179

  
177 180
		tabFolder.addSelectionListener(new SelectionListener() {
178
			
181

  
179 182
			@Override
180 183
			public void widgetDefaultSelected(SelectionEvent e) {}
181
			
184

  
182 185
			@Override
183 186
			public void widgetSelected(SelectionEvent e) {
184
				
187

  
185 188
				selectedTab = tabFolder.getSelection()[0];
186 189
			}
187 190
		});
188
		
191

  
189 192
		return tabFolder;
190 193
	}
191
		
194

  
192 195
	/*
193 196
	 * (non-Javadoc)
194 197
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
195 198
	 */
196 199
	@Override
197 200
	protected void okPressed() {
198
		
201

  
199 202
		if (selectedTab == advancedTab && advancedPartitionPanel.isQueriesSet()) {
200 203
			MessageDialog.openError(getShell(),
201 204
					TXMUIMessages.invalidQuery,
202 205
					TXMUIMessages.queriesCannotBeLeftEmpty);
203 206
			return;
204 207
		}
205
		
208

  
206 209
		partition = createPartition();
207 210
		super.okPressed();
208 211
	}
209
		
212

  
210 213
	/**
211 214
	 * Creates the partition.
212 215
	 *
213 216
	 * @return the partition
214 217
	 */
215 218
	public Partition createPartition() {
216
		
219

  
217 220
		Partition partition = null;
218
		
221

  
219 222
		String name = nameText.getText();
220
		
223

  
221 224
		if (selectedTab == simpleTab) { // Simple mode
222
			
225

  
223 226
			partition = simplePanel.createPartition(name, null);
224 227
		}
225 228
		else if (selectedTab == assistedTab) { // Assisted mode
226
			
229

  
227 230
			// auto-naming if needed
228 231
			if (name.isEmpty()) {
229 232
				name = compositeForAssisted.getProperty().asFullNameString();
230 233
				Log.info(TXMCoreMessages.bind(TXMUIMessages.noPartitionNameWasSpecifiedTheNameIsP0, name));
231 234
			}
232
			
235

  
233 236
			partition = this.compositeForAssisted.createPartition(name, null);
234 237
		}
235 238
		else if (selectedTab == crossedTab) { // Advanced mode
236
			
239

  
237 240
			partition = crossedPanel.createPartition(name, null);
238 241
		}
239 242
		else if (selectedTab == advancedTab) { // Advanced mode
240
			
243

  
241 244
			partition = advancedPartitionPanel.createPartition(name, null);
242 245
		}
243
		
246

  
244 247
		// Error
245 248
		if (partition == null) {
246 249
			Log.severe(TXMUIMessages.noPartWasDefined);
247 250
			return null;
248 251
		}
249
		
252

  
250 253
		return partition;
251 254
	}
252
	
255

  
253 256
	/**
254 257
	 * Gets the partition.
255 258
	 *
256 259
	 * @return the partition
257 260
	 */
258 261
	public Partition getPartition() {
259
		
262

  
260 263
		return partition;
261 264
	}
262 265
}
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 4000)
89 89
import org.txm.rcp.swt.widget.NewNavigationWidget;
90 90
import org.txm.rcp.swt.widget.PropertiesSelector;
91 91
import org.txm.rcp.swt.widget.QueryWidget;
92
import org.txm.rcp.swt.widget.RadioGroup;
92 93
import org.txm.rcp.swt.widget.ReferencePatternSelector;
93 94
import org.txm.rcp.utils.JobHandler;
94 95
import org.txm.rcp.utils.SWTEditorsUtils;
......
1440 1441
				else if (object instanceof Button) {
1441 1442
					((Button) object).setSelection((Boolean) value);
1442 1443
				}
1444
				else if (object instanceof RadioGroup) {
1445
					((RadioGroup) object).setSelection((String) value);
1446
				}
1443 1447
				else if (object instanceof Viewer) {
1444 1448
					if (value != null) {
1445 1449
						// FIXME: SJ: fire a new selection changed event leading to a cyclic recursion...
......
1606 1610
				else if (object instanceof Button) {
1607 1611
					value = ((Button) object).getSelection();
1608 1612
				}
1613
				else if (object instanceof RadioGroup) {
1614
					value = ((RadioGroup) object).getSelection();
1615
				}
1609 1616
				else if (object instanceof Viewer) {
1610 1617
					
1611 1618
					IStructuredSelection selection = ((IStructuredSelection) ((Viewer) object).getSelection());
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/RadioGroup.java (revision 4000)
1
package org.txm.rcp.swt.widget;
2

  
3
import java.util.LinkedHashMap;
4

  
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.layout.RowLayout;
7
import org.eclipse.swt.widgets.Button;
8
import org.eclipse.swt.widgets.Composite;
9
import org.eclipse.swt.widgets.Group;
10
import org.txm.rcp.swt.GLComposite;
11

  
12
/**
13
 * Wrap SWT Button (radio) in a Group + methods to get&set selection
14
 * 
15
 * @author mdecorde
16
 *
17
 */
18
public class RadioGroup extends GLComposite {
19

  
20
	LinkedHashMap<String, Button> buttons = new LinkedHashMap<>();
21
	private Group group;
22
	
23
	public RadioGroup(Composite parent, int style, String title, String[][] choices) {
24
		
25
		super(parent, style, "RadioGroup");
26
		this.getLayout().numColumns = 1;
27
		
28
		group = new Group(this, SWT.NONE);
29
		if (title != null) group.setText(title);
30
		group.setLayout(new RowLayout(SWT.HORIZONTAL));
31
		
32
		for (String[] choice : choices) {
33
			
34
			if (choice.length == 0) continue;
35
			if (choice[0] == null) continue;
36
			
37
			Button b = new Button(group, SWT.RADIO);
38
			b.setData(choice[0]);
39
			b.setText(choice[0]);
40
			b.setToolTipText(choice[0]);
41
			if (choice.length > 1 && choice[1] != null) {
42
				b.setText(choice[1]);
43
				b.setToolTipText(choice[1]);
44
			}
45
			if (choice.length > 2 && choice[2] != null) {
46
				b.setToolTipText(choice[2]);
47
			}
48
			buttons.put(choice[0], b);
49
		}
50
	}
51
	
52
	public void setVertical() {
53
		
54
		group.setLayout(new RowLayout(SWT.VERTICAL));
55
	}
56
	
57
	public void setHorizontal() {
58
		
59
		group.setLayout(new RowLayout(SWT.HORIZONTAL));
60
	}
61
	
62
	public String getSelection() {
63
		
64
		for (Button b : buttons.values()) {
65
			
66
			if (b.getSelection()) return b.getData().toString();
67
		}
68
		return null;
69
	}
70
	
71
	public void setSelection(String value) {
72
		
73
		for (Button b : buttons.values()) {
74
			
75
			if (b.getData().toString().equals(value)) b.setSelection(true); ;
76
		}
77
	}
78

  
79
}
0 80

  

Formats disponibles : Unified diff