Révision 1421

tmp/org.txm.ahc.rcp/src/org/txm/ahc/rcp/handlers/ComputeAHC.java (revision 1421)
65 65

  
66 66

  
67 67
	@Override
68
	public Object execute(ExecutionEvent event) throws ExecutionException {
68
	public AHC execute(ExecutionEvent event) throws ExecutionException {
69 69

  
70
		if(!this.checkStatsEngine()) {
70
		if (!this.checkStatsEngine()) {
71 71
			return null;
72 72
		}
73 73

  
......
75 75
		AHC ahc = null;
76 76

  
77 77
		final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
78
		
79
		// reopening an existing result
80
		if (selection instanceof AHC) {
81
			ahc = (AHC) selection;
82
		}
83
		// Creating
84
		else {
78
		try {
79
			// reopening an existing result
80
			if (selection instanceof AHC) {
81
				ahc = (AHC) selection;
82
			} else if (selection instanceof CA) { // Creating
85 83

  
86
			LexicalTable lexicalTable = null;
87
			CA ca = null;
88
			
89
			// Creating from CA
90
			if (selection instanceof CA) {
91
				ca = (CA) selection;
92
				lexicalTable = ca.getLexicalTable();
84
				CA ca = (CA) selection;
93 85
				ahc = new AHC(ca);
94
			}
95
			// Creating from Partition Index
96
			else if (selection instanceof PartitionIndex) {
86
			} else if (selection instanceof PartitionIndex) { // Creating from Partition Index
87

  
97 88
				PartitionIndex index = (PartitionIndex)selection;
98
				lexicalTable = new LexicalTable(index);
99
				ca = new CA(lexicalTable);
89
				LexicalTable lexicalTable = new LexicalTable(index);
90
				lexicalTable.setVisible(false);
91
				CA ca = new CA(lexicalTable);
92
				ca.setVisible(false);
100 93
				ahc = new AHC(ca);
101
			}
102
			// Creating from Lexical Table
103
			else if (selection instanceof LexicalTable) {
104
				lexicalTable = (LexicalTable) selection;
105
				ca = new CA(lexicalTable);
94
			} else if (selection instanceof LexicalTable) { // Creating from Lexical Table
95

  
96
				LexicalTable lexicalTable = (LexicalTable) selection;
97
				CA ca = new CA(lexicalTable);
98
				ca.setVisible(false);
106 99
				ahc = new AHC(ca);
107
			}
108
			// Creating from Partition
109
			else if (selection instanceof Partition) {
100
			} else if (selection instanceof Partition) { // Creating from Partition
101

  
110 102
				Partition partition = (Partition)selection;
111 103
				if (partition.getPartsCount() < 4) {
112 104
					MessageDialog d = new MessageDialog(window.getShell(), TXMCoreMessages.error_error2, null,
......
114 106
					d.open();
115 107
					return null;
116 108
				}
117
				try {
118
					String title = AHCUIMessages.bind(AHCUIMessages.computingClassificationWithP0, partition.getName());
119
					int vMax = CAPreferences.getInstance().getInt(TXMPreferences.V_MAX);
120
					int fMin =  CAPreferences.getInstance().getInt(TXMPreferences.F_MIN);
121
					Shell shell = Display.getCurrent().getActiveShell();
122
					CAParametersDialog d = new CAParametersDialog(shell, partition.getParent(), title);
123
					d.setFminAndVMax(fMin, vMax);
124
					
125
					if (d.open() == Window.OK) {
126
						WordProperty property = d.getProperty();
127
						fMin = d.getFmin();
128
						vMax = d.getMaxLines();
129
						
130
						lexicalTable = new LexicalTable(partition); // use the CAPreferencePage Fmin
131
						lexicalTable.setParameters(property, fMin, vMax, null);
132
						ca = new CA(lexicalTable);
133
						ahc = new AHC(ca);
134
					}
135
					// canceled
136
					else {
137
						return null;
138
					}
139
				} catch (Exception e) {
140
					Log.severe("Failed to build the lexical table of " + partition + ": " + e);
141
					Log.printStackTrace(e);
142
					return null;
143
				} 
144
			}
145
			
146
			// show the lexical table only if the command was called from a lexical table
147
			if(!(selection instanceof LexicalTable))	{
109

  
110

  
111
				LexicalTable lexicalTable = new LexicalTable(partition); // use the CAPreferencePage Fmin
148 112
				lexicalTable.setVisible(false);
149
			}
150
			
151
			// show the CA only if the command was called from a CA
152
			if(!(selection instanceof CA))	{
113
				CA ca = new CA(lexicalTable);
153 114
				ca.setVisible(false);
115
				ahc = new AHC(ca);
116

  
154 117
			}
155
			
156
		}
157
		
158
		
159
		ChartEditor.openEditor(ahc);
160
		return null;
161
	}
162 118

  
163

  
119
			ChartEditor.openEditor(ahc);
120
		} catch (Exception e) {
121
			Log.severe("Failed to build the AHC for selection " + selection + ": " + e);
122
			Log.printStackTrace(e);
123
			return null;
124
		} 
125
		return ahc;
126
	}
164 127
}
tmp/org.txm.ahc.rcp/src/org/txm/ahc/rcp/editors/AHCChartEditor.java (revision 1421)
1
package org.txm.ahc.rcp.editors;
2

  
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.custom.CLabel;
5
import org.eclipse.swt.widgets.Button;
6
import org.eclipse.swt.widgets.Spinner;
7
import org.eclipse.swt.widgets.ToolItem;
8
import org.txm.ahc.core.functions.AHC;
9
import org.txm.ahc.core.preferences.AHCPreferences;
10
import org.txm.ahc.rcp.messages.AHCUIMessages;
11
import org.txm.chartsengine.rcp.editors.ChartEditor;
12
import org.txm.core.results.Parameter;
13
import org.txm.rcp.IImageKeys;
14
import org.txm.rcp.editors.listeners.ComputeKeyListener;
15
import org.txm.rcp.editors.listeners.ComputeSelectionListener;
16

  
17
/**
18
 * AHC chart editor.
19
 * 
20
 * @author mdecorde
21
 * @author sjacquot
22
 *
23
 */
24
public class AHCChartEditor extends ChartEditor<AHC> {
25

  
26
	
27
	/**
28
	 * Rows computing button.
29
	 */
30
	protected ToolItem rowsComputing;
31
	
32
	
33

  
34
	/**
35
	 * The metric (euclidean, manhattan).
36
	 */
37
	@Parameter(key=AHCPreferences.METRIC)
38
	protected String metric;
39

  
40
	/**
41
	 * The method (METHODS <- c("average", "single", "complete", "ward", "weighted", "flexible")).
42
	 */
43
	@Parameter(key=AHCPreferences.METHOD)
44
	protected String method;
45

  
46
	/**
47
	 * The number of clusters.
48
	 */
49
	@Parameter(key=AHCPreferences.N_CLUSTERS)
50
	protected Spinner numberOfClusters;
51

  
52
	/**
53
	 * To compute the columns or the rows.
54
	 */
55
	@Parameter(key=AHCPreferences.COLUMNS_COMPUTING)
56
	protected ToolItem columnsComputing;
57
	
58
	/**
59
	 * To render in 2D or 3D.
60
	 */
61
	@Parameter(key=AHCPreferences.RENDERING_2D)
62
	protected Button rendering2D;
63

  
64
	
65
	
66

  
67
	@Override
68
	public void __createPartControl() {
69

  
70
		// Extend the chart editor tool bar
71
		new ToolItem(this.chartToolBar, SWT.SEPARATOR);
72

  
73
		
74
		// Computing listeners
75
		ComputeSelectionListener computeSelectionListener = new ComputeSelectionListener(this, true);
76
		ComputeKeyListener computeKeyListener = new ComputeKeyListener(this);
77
		
78
		// Number of clusters
79
	    CLabel clustersLabel = new CLabel(this.chartToolBar, SWT.CENTER);
80
		clustersLabel.setText(AHCUIMessages.numberOfClustersColon);
81
		this.chartToolBar.addControl(clustersLabel);
82

  
83
	    this.numberOfClusters = new Spinner(this.chartToolBar, SWT.BORDER);
84
	    this.numberOfClusters.setMinimum(2);
85
	    this.numberOfClusters.setIncrement(1);
86
	    this.chartToolBar.addControl(this.numberOfClusters);
87
	    this.numberOfClusters.addSelectionListener(computeSelectionListener);
88
	    this.numberOfClusters.addKeyListener(computeKeyListener);
89

  
90

  
91
		// Columns
92
		this.columnsComputing = new ToolItem(this.chartToolBar, SWT.RADIO);
93
		this.columnsComputing.setToolTipText(AHCUIMessages.computeColumns);
94
		this.columnsComputing.setImage(IImageKeys.getImage(AHCChartEditor.class, "icons/compute_columns.png")); //$NON-NLS-1$
95
		this.columnsComputing.addSelectionListener(computeSelectionListener);
96

  
97
		// Rows
98
		this.rowsComputing = new ToolItem(this.chartToolBar, SWT.RADIO);
99
		this.rowsComputing.setToolTipText(AHCUIMessages.computeRows);
100
		this.rowsComputing.setImage(IImageKeys.getImage(AHCChartEditor.class, "icons/compute_rows.png")); //$NON-NLS-1$
101

  
102
		
103
		// 2D/3D rendering
104
		this.rendering2D = new Button(this.chartToolBar, SWT.CHECK);
105
		this.rendering2D.setText("2D");//$NON-NLS-1$
106
		this.chartToolBar.addControl(this.rendering2D);
107
		this.rendering2D.addSelectionListener(computeSelectionListener);
108
		
109
		
110
		// FIXME: temporary fix, later must enable the font, rendering mode, etc. in R calls
111
		// disable all component of the rendering tool bar
112
		this.advancedChartToolBar.setEnabled(false);
113

  
114

  
115
	}
116

  
117

  
118
	@Override
119
	public void updateEditorFromChart(boolean update) {
120
		AHC ahc = this.getResult();
121

  
122
		// Update the maximum value of the number of clusters spinner according to the new AHC configuration 
123
		this.numberOfClusters.setMaximum(ahc.getMaxClustersCount());
124

  
125
		// Updates the current value of the number of clusters spinner
126
		this.numberOfClusters.setSelection(ahc.getNumberOfClusters());
127
		
128
		this.rowsComputing.setSelection(!ahc.isColumnsComputing());
129
	}
130

  
131
}
tmp/org.txm.ahc.rcp/src/org/txm/ahc/rcp/editors/AHCEditor.java (revision 1421)
1
package org.txm.ahc.rcp.editors;
2

  
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.custom.CLabel;
5
import org.eclipse.swt.widgets.Button;
6
import org.eclipse.swt.widgets.Label;
7
import org.eclipse.swt.widgets.Spinner;
8
import org.eclipse.swt.widgets.ToolItem;
9
import org.txm.ahc.core.functions.AHC;
10
import org.txm.ahc.core.preferences.AHCPreferences;
11
import org.txm.ahc.rcp.messages.AHCUIMessages;
12
import org.txm.chartsengine.rcp.editors.ChartEditor;
13
import org.txm.core.messages.TXMCoreMessages;
14
import org.txm.core.preferences.TXMPreferences;
15
import org.txm.core.results.Parameter;
16
import org.txm.rcp.IImageKeys;
17
import org.txm.rcp.editors.listeners.ComputeKeyListener;
18
import org.txm.rcp.editors.listeners.ComputeSelectionListener;
19
import org.txm.rcp.swt.GLComposite;
20
import org.txm.rcp.swt.widget.ThresholdsGroup;
21
import org.txm.rcp.swt.widget.structures.PropertiesComboViewer;
22
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
23
import org.txm.searchengine.cqp.corpus.CQPCorpus;
24

  
25
/**
26
 * AHC chart editor.
27
 * 
28
 * @author mdecorde
29
 * @author sjacquot
30
 *
31
 */
32
public class AHCEditor extends ChartEditor<AHC> {
33

  
34

  
35
	/**
36
	 * Rows computing button.
37
	 */
38
	protected ToolItem rowsComputing;
39

  
40
	/**
41
	 * Unit property.
42
	 */
43
	@Parameter(key=TXMPreferences.UNIT_PROPERTY)
44
	protected PropertiesComboViewer unitPropertyComboViewer;
45

  
46
	/**
47
	 * Minimum frequency filtering spinner.
48
	 */
49
	@Parameter(key=TXMPreferences.F_MIN)
50
	protected Spinner fMinSpinner;
51

  
52
	/**
53
	 * Maximum frequency filtering spinner.
54
	 */
55
	@Parameter(key=TXMPreferences.F_MAX)
56
	protected Spinner fMaxSpinner;
57

  
58
	/**
59
	 * Maximum number of lines filtering.
60
	 */
61
	@Parameter(key=TXMPreferences.V_MAX)
62
	protected Spinner vMaxSpinner;
63
	
64
	
65
	/**
66
	 * The metric (euclidean, manhattan).
67
	 */
68
	@Parameter(key=AHCPreferences.METRIC)
69
	protected String metric;
70

  
71
	/**
72
	 * The method (METHODS <- c("average", "single", "complete", "ward", "weighted", "flexible")).
73
	 */
74
	@Parameter(key=AHCPreferences.METHOD)
75
	protected String method;
76

  
77
	/**
78
	 * The number of clusters.
79
	 */
80
	@Parameter(key=AHCPreferences.N_CLUSTERS)
81
	protected Spinner numberOfClusters;
82

  
83
	/**
84
	 * To compute the columns or the rows.
85
	 */
86
	@Parameter(key=AHCPreferences.COLUMNS_COMPUTING)
87
	protected ToolItem columnsComputing;
88

  
89
	/**
90
	 * To render in 2D or 3D.
91
	 */
92
	@Parameter(key=AHCPreferences.RENDERING_2D)
93
	protected Button rendering2D;
94

  
95

  
96
	@Override
97
	public void __createPartControl() throws Exception {
98

  
99
		GLComposite mainParametersArea = this.getMainParametersComposite();
100
		mainParametersArea.getLayout().numColumns = 2;
101
		// parent parameters
102
		if (!this.getResult().getParent().isVisible())	{
103
			// unit property
104
			new Label(mainParametersArea, SWT.NONE).setText(TXMCoreMessages.common_property);
105
			this.unitPropertyComboViewer = new PropertiesComboViewer(mainParametersArea, this, false,
106
					CQPCorpus.getFirstParentCorpus(this.getResult()).getOrderedProperties(),
107
					this.getResult().getUnitProperty(), false);
108
		}
109

  
110
		// Extend the chart editor tool bar
111
		new ToolItem(this.chartToolBar, SWT.SEPARATOR);
112

  
113

  
114
		// Computing listeners
115
		ComputeSelectionListener computeSelectionListener = new ComputeSelectionListener(this, true);
116
		ComputeKeyListener computeKeyListener = new ComputeKeyListener(this);
117

  
118
		// Number of clusters
119
		CLabel clustersLabel = new CLabel(this.chartToolBar, SWT.CENTER);
120
		clustersLabel.setText(AHCUIMessages.numberOfClustersColon);
121
		this.chartToolBar.addControl(clustersLabel);
122

  
123
		this.numberOfClusters = new Spinner(this.chartToolBar, SWT.BORDER);
124
		this.numberOfClusters.setMinimum(2);
125
		this.numberOfClusters.setIncrement(1);
126
		this.chartToolBar.addControl(this.numberOfClusters);
127
		this.numberOfClusters.addSelectionListener(computeSelectionListener);
128
		this.numberOfClusters.addKeyListener(computeKeyListener);
129

  
130

  
131
		// Columns
132
		this.columnsComputing = new ToolItem(this.chartToolBar, SWT.RADIO);
133
		this.columnsComputing.setToolTipText(AHCUIMessages.computeColumns);
134
		this.columnsComputing.setImage(IImageKeys.getImage(AHCEditor.class, "icons/compute_columns.png")); //$NON-NLS-1$
135
		this.columnsComputing.addSelectionListener(computeSelectionListener);
136

  
137
		// Rows
138
		this.rowsComputing = new ToolItem(this.chartToolBar, SWT.RADIO);
139
		this.rowsComputing.setToolTipText(AHCUIMessages.computeRows);
140
		this.rowsComputing.setImage(IImageKeys.getImage(AHCEditor.class, "icons/compute_rows.png")); //$NON-NLS-1$
141

  
142

  
143
		// 2D/3D rendering
144
		this.rendering2D = new Button(this.chartToolBar, SWT.CHECK);
145
		this.rendering2D.setText("2D");//$NON-NLS-1$
146
		this.chartToolBar.addControl(this.rendering2D);
147
		this.rendering2D.addSelectionListener(computeSelectionListener);
148

  
149
		// FIXME: temporary fix, later must enable the font, rendering mode, etc. in R calls
150
		// disable all component of the rendering tool bar
151
		this.advancedChartToolBar.setEnabled(false);
152

  
153
		ThresholdsGroup thresholdsGroup = new ThresholdsGroup(this.getExtendedParametersGroup(), SWT.NONE, this, true, false);
154
		this.fMinSpinner = thresholdsGroup.getFMinSpinner();
155
		this.fMaxSpinner = thresholdsGroup.getFMaxSpinner();
156
		this.vMaxSpinner = thresholdsGroup.getVMaxSpinner();
157
		this.vMaxSpinner.setMinimum(1);
158

  
159
	}
160

  
161

  
162
	@Override
163
	public void updateEditorFromChart(boolean update) {
164
		AHC ahc = this.getResult();
165

  
166
		// Update the maximum value of the number of clusters spinner according to the new AHC configuration 
167
		this.numberOfClusters.setMaximum(ahc.getMaxClustersCount());
168

  
169
		// Updates the current value of the number of clusters spinner
170
		this.numberOfClusters.setSelection(ahc.getNumberOfClusters());
171

  
172
		this.rowsComputing.setSelection(!ahc.isColumnsComputing());
173
	}
174

  
175
}
0 176

  
tmp/org.txm.ahc.rcp/plugin.xml (revision 1421)
97 97
   <extension
98 98
         point="org.eclipse.ui.editors">
99 99
      <editor
100
            class="org.txm.ahc.rcp.editors.AHCChartEditor"
100
            class="org.txm.ahc.rcp.editors.AHCEditor"
101 101
            default="false"
102 102
            icon="icons/cah.png"
103 103
            id="org.txm.ahc.core.functions.AHC"
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 1421)
451 451
	 * Subclasses manual creation method called after TXMEditor.createPartControl is called.
452 452
	 * 
453 453
	 * Use this method to set your own widgets in the minimal parameters area, the top toolbar, parameters group, the result area and the bottom toolbar
454
	 * @throws Exception 
454 455
	 */
455
	public abstract void _createPartControl();
456
	public abstract void _createPartControl() throws Exception;
456 457

  
457 458
	/**
458 459
	 * Use this method to add widget next to the default Bottom toolbar
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 1421)
392 392
	/**
393 393
	 * Gets a current parameter specified by its annotation "key" attribute and its annotation "type" attribute.
394 394
	 * @param key
395
	 * @bubble if true ask the first parent
395
	 * @param propagateToParent if true ask the parents
396 396
	 * @param parameterType
397 397
	 * @return
398 398
	 */
399 399
	public Object getParameter(String key, boolean propagateToParent) {
400 400
		try {
401 401
			Field field = this.getField(key); 
402
			if(field != null)	{
402
			if (field != null)	{
403 403
				field.setAccessible(true);
404 404
				return field.get(this);	
405
			} else if (propagateToParent && this.parent != null) {
406
				return this.parent.getParameter(key, propagateToParent);
405 407
			}
406
			else if (propagateToParent) {
407
				return this.parent.getParameter(key);
408
			}
409
		}
410
		catch (IllegalArgumentException e) {
411
			// TODO Auto-generated catch block
408
		} catch (Exception e) {
412 409
			e.printStackTrace();
413 410
		}
414
		catch (IllegalAccessException e) {
415
			// TODO Auto-generated catch block
416
			e.printStackTrace();
417
		}
418 411
		return null;
419 412
	}
420 413

  
......
1187 1180
			targetField.set(this, value);
1188 1181
		}
1189 1182
		else if (this.parent != null && propagateToParent) {
1190
			this.parent.setParameter(key, value);
1183
			this.parent.setParameter(key, value, propagateToParent);
1191 1184
		}
1192 1185

  
1193 1186
		return true;
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/editors/ChartEditor.java (revision 1421)
104 104
	
105 105
	/**
106 106
	 * Subclasses manual creation.
107
	 * @throws Exception 
107 108
	 */
108
	public abstract void __createPartControl();
109
	public abstract void __createPartControl() throws Exception;
109 110
	
110 111
	
111 112
	@Override
112
	public final void _createPartControl() {
113
	public final void _createPartControl() throws Exception {
113 114
		
114 115
		// Toolbar
115 116
		this.chartToolBar = new ChartEditorToolBar(this, this.getFirstLineComposite(), null, SWT.FLAT | SWT.RIGHT);
tmp/org.txm.ahc.core/src/org/txm/ahc/core/functions/AHC.java (revision 1421)
30 30
import java.io.File;
31 31
import java.util.Arrays;
32 32

  
33
import org.eclipse.osgi.util.NLS;
33 34
import org.rosuda.REngine.REXP;
34 35
import org.txm.ahc.core.messages.AHCCoreMessages;
35 36
import org.txm.ahc.core.preferences.AHCPreferences;
......
38 39
import org.txm.core.results.Parameter;
39 40
import org.txm.core.results.TXMParameters;
40 41
import org.txm.lexicaltable.core.functions.LexicalTable;
42
import org.txm.searchengine.cqp.corpus.Property;
41 43
import org.txm.statsengine.r.core.RWorkspace;
42 44
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
43 45
import org.txm.utils.logger.Log;
......
679 681

  
680 682
	@Override
681 683
	public String getDetails() {
682
		// FIXME: to define
683
		return this.getName();
684
		return NLS.bind(this.getName()+"\ncomputed with the {0} method and the {1} metric.", method, metric);
684 685
	}
685 686

  
686 687
	@Override
687 688
	public String getName() {
688
		return ""+this.getNumberOfClusters()+" "+(this.columnsComputing?"columns":"rows");
689
		return NLS.bind("{0} clusters of  ", this.getNumberOfClusters(), this.columnsComputing?"columns":"rows");
689 690
	}
690 691

  
691 692

  
......
713 714
		return AHCCoreMessages.RESULT_TYPE;
714 715
	}
715 716

  
716

  
717

  
717
	public Property getUnitProperty() {
718
		if (getLexicalTable() != null) {
719
			return getLexicalTable().getProperty();
720
		}
721
		return null;
722
	}
718 723
}

Formats disponibles : Unified diff