Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 15734 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/views/properties/PropertySheetEntry.java (-30 / +108 lines)
Lines 49-54 Link Here
49
		IPropertySheetEntry {
49
		IPropertySheetEntry {
50
50
51
	/**
51
	/**
52
	 * The value displayed when property values from different objects 
53
	 * of one kind have different values
54
	 */
55
	private static final String VALUE_INCONSISTENT = ""; //$NON-NLS-1$
56
57
	/**
52
	 * The values we are displaying/editing. These objects repesent the value of
58
	 * The values we are displaying/editing. These objects repesent the value of
53
	 * one of the properties of the values of our parent entry. Except for the
59
	 * one of the properties of the values of our parent entry. Except for the
54
	 * root entry where they represent the input (selected) objects.
60
	 * root entry where they represent the input (selected) objects.
Lines 61-71 Link Here
61
	private Map sources = new HashMap(0);
67
	private Map sources = new HashMap(0);
62
68
63
	/**
69
	/**
64
	 * The value of this entry is defined as the the first object in its value
70
	 * An array of values or, if they are <code>IPropertySource</code>,
65
	 * array or, if that object is an <code>IPropertySource</code>, the value
71
	 * the values it returns when sent <code>getEditableValue</code>.  
66
	 * it returns when sent <code>getEditableValue</code>
67
	 */
72
	 */
68
	private Object editValue;
73
	private Object[] editValues; 
69
74
70
	private PropertySheetEntry parent;
75
	private PropertySheetEntry parent;
71
76
Lines 78-85 Link Here
78
	private String errorText;
83
	private String errorText;
79
84
80
	private PropertySheetEntry[] childEntries = null;
85
	private PropertySheetEntry[] childEntries = null;
86
	
87
	/**
88
	 * The parameter is
89
	 * <ul>
90
	 * <li><code>true</code> if inconsistent properties should be blanked,</li> 
91
	 * <li><code>false</code> otherwise.</li>
92
	 * </ul>
93
	 */
94
	protected boolean blankNotEqualPropertyValues = false;
81
95
82
	/**
96
	/**
97
	 * Constructs an <code>PropertySheetEntry</code> that may blank inconsistent 
98
	 * properties depending on the <code>blankInconsistency</code> parameter.
99
	 * 
100
	 * @param blankNotEqualPropertyValues a parameter indicating, that property
101
	 * values should be blanked, if many selected objects have the same 
102
	 * properties with different values.
103
	 * <ul> 
104
	 * 	<li><code>true</code> enabled </li> 
105
	 *  <li><code>false</code> disabled </li>
106
	 * </ul>
107
	 */
108
	public PropertySheetEntry(boolean blankNotEqualPropertyValues){
109
		this.blankNotEqualPropertyValues = blankNotEqualPropertyValues;
110
	}
111
	
112
	/**
113
	 * Default constructor. <code>PropertySheetEntry</code> will not care about
114
	 * property value of different objects. Always the first one will be displayed.
115
	 */
116
	public PropertySheetEntry(){ }
117
	
118
	/**
83
	 * Create the CellEditorListener for this entry. It listens for value
119
	 * Create the CellEditorListener for this entry. It listens for value
84
	 * changes in the CellEditor, and cancel and finish requests.
120
	 * changes in the CellEditor, and cancel and finish requests.
85
	 */
121
	 */
Lines 119-124 Link Here
119
		if (editor == null) {
155
		if (editor == null) {
120
			return;
156
			return;
121
		}
157
		}
158
		if (!editor.isDirty()
159
				/*we care only if blank can be set*/
160
				&& blankNotEqualPropertyValues){
161
			return;
162
		}
122
163
123
		// Check if editor has a valid value
164
		// Check if editor has a valid value
124
		if (!editor.isValueValid()) {
165
		if (!editor.isValueValid()) {
Lines 133-143 Link Here
133
		boolean changed = false;
174
		boolean changed = false;
134
		if (values.length > 1) {
175
		if (values.length > 1) {
135
			changed = true;
176
			changed = true;
136
		} else if (editValue == null) {
177
		} else if (editValues[0] == null) {
137
			if (newValue != null) {
178
			if (newValue != null) {
138
				changed = true;
179
				changed = true;
139
			}
180
			}
140
		} else if (!editValue.equals(newValue)) {
181
		} else if (!editValues[0].equals(newValue)) {
141
			changed = true;
182
			changed = true;
142
		}
183
		}
143
184
Lines 256-270 Link Here
256
	 * Factory method to create a new child <code>PropertySheetEntry</code>
297
	 * Factory method to create a new child <code>PropertySheetEntry</code>
257
	 * instance.
298
	 * instance.
258
	 * <p>
299
	 * <p>
259
	 * Subclasses may overwrite to create new instances of their own class.
300
	 * Subclasses may overwrite to create new instances of their own class, 
301
	 * but should pass <code>blankingInconsistency</code> to child entries. 
260
	 * </p>
302
	 * </p>
261
	 * 
303
	 * 
262
	 * @return a new <code>PropertySheetEntry</code> instance for the
304
	 * @return a new <code>PropertySheetEntry</code> instance for the
263
	 *         descriptor passed in
305
	 *         descriptor passed in
306
	 * @see #blankNotEqualPropertyValues
264
	 * @since 3.1
307
	 * @since 3.1
265
	 */
308
	 */
266
	protected PropertySheetEntry createChildEntry() {
309
	protected PropertySheetEntry createChildEntry() {
267
		return new PropertySheetEntry();
310
		return new PropertySheetEntry(blankNotEqualPropertyValues);
268
	}
311
	}
269
312
270
	/*
313
	/*
Lines 381-388 Link Here
381
			}
424
			}
382
		}
425
		}
383
		if (editor != null) {
426
		if (editor != null) {
384
			editor.setValue(editValue);
427
			boolean consistent = true;
385
			setErrorText(editor.getErrorMessage());
428
			Object editValue = editValues[0]; 
429
			for(int i = 1; i < editValues.length; i++){
430
				if (!editValue.equals(editValues[i])){
431
					consistent = false;
432
				}
433
			}
434
435
			if (consistent == true || 
436
					/*or consistency checking is disabled*/			
437
					!blankNotEqualPropertyValues){
438
				editor.setValue(editValues[0]);
439
				setErrorText(editor.getErrorMessage());
440
			} else {
441
				editor.setValue(VALUE_INCONSISTENT);
442
				setErrorText(null);
443
			}
386
		}
444
		}
387
		return editor;
445
		return editor;
388
	}
446
	}
Lines 432-438 Link Here
432
		if (provider == null) {
490
		if (provider == null) {
433
			return null;
491
			return null;
434
		}
492
		}
435
		return provider.getImage(editValue);
493
		return provider.getImage(editValues[0]);
436
	}
494
	}
437
495
438
	/**
496
	/**
Lines 480-497 Link Here
480
	 * (non-Javadoc) Method declared on IPropertySheetEntry.
538
	 * (non-Javadoc) Method declared on IPropertySheetEntry.
481
	 */
539
	 */
482
	public String getValueAsString() {
540
	public String getValueAsString() {
483
		if (editValue == null) {
541
		String[] textEditValues = new String[editValues.length];
484
			return "";//$NON-NLS-1$
542
		// compute all edit values
485
		}
543
		for(int i = 0; i < editValues.length; i++){
486
		ILabelProvider provider = descriptor.getLabelProvider();
544
			if (editValues[i] != null) {
487
		if (provider == null) {
545
				ILabelProvider provider = descriptor.getLabelProvider();
488
			return editValue.toString();
546
				if (provider != null) {
547
					String text = provider.getText(editValues[i]);
548
					if (text != null) {
549
						textEditValues[i] = text;
550
					} else {
551
						textEditValues[i] = "";//$NON-NLS-1$
552
					}
553
				} else {
554
					textEditValues[i] = editValues[i].toString();
555
				}
556
			} else {
557
				textEditValues[i] =  "";//$NON-NLS-1$
558
			}
489
		}
559
		}
490
		String text = provider.getText(editValue);
560
		// check consistency if required
491
		if (text == null) {
561
		if(blankNotEqualPropertyValues){
492
			return "";//$NON-NLS-1$
562
			for(int i = 1; i < textEditValues.length; i++){
563
				if (!textEditValues[0].equals(textEditValues[i])){
564
					return VALUE_INCONSISTENT;
565
				}
566
			}
493
		}
567
		}
494
		return text;
568
		return textEditValues[0];
495
	}
569
	}
496
570
497
	/**
571
	/**
Lines 743-759 Link Here
743
		sources = new HashMap(values.length * 2 + 1);
817
		sources = new HashMap(values.length * 2 + 1);
744
818
745
		if (values.length == 0) {
819
		if (values.length == 0) {
746
			editValue = null;
820
			editValues = new Object[1];
747
		} else {
821
		} else {
748
			// set the first value object as the entry's value
822
			
749
			Object newValue = values[0];
823
			editValues = new Object[values.length];
750
824
			
751
			// see if we should convert the value to an editable value
825
			for(int i = 0; i < editValues.length; i++){
752
			IPropertySource source = getPropertySource(newValue);
826
				// see if we should convert the value to an editable value
753
			if (source != null) {
827
				IPropertySource source = getPropertySource(values[i]);
754
				newValue = source.getEditableValue();
828
				if (source != null) {
829
					editValues[i] = source.getEditableValue();
830
				} else {
831
					editValues[i] = values[i];
832
				}
755
			}
833
			}
756
			editValue = newValue;
834
			
757
		}
835
		}
758
836
759
		// update our child entries
837
		// update our child entries

Return to bug 15734