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 206800
Collapse All | Expand All

(-)src/org/eclipse/gef/internal/ui/palette/editparts/ToolEntryEditPart.java (-3 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 38-43 Link Here
38
import org.eclipse.gef.palette.PaletteEntry;
38
import org.eclipse.gef.palette.PaletteEntry;
39
import org.eclipse.gef.palette.ToolEntry;
39
import org.eclipse.gef.palette.ToolEntry;
40
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
40
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
41
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
41
42
42
public class ToolEntryEditPart
43
public class ToolEntryEditPart
43
	extends PaletteEditPart
44
	extends PaletteEditPart
Lines 266-272 Link Here
266
}
267
}
267
268
268
/**
269
/**
269
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#deactivate()
270
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#deactivate()
270
 */
271
 */
271
public void deactivate() {
272
public void deactivate() {
272
	customLabel.dispose();
273
	customLabel.dispose();
Lines 302-308 Link Here
302
}
303
}
303
304
304
/**
305
/**
305
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#getToolTipText()
306
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#getToolTipText()
306
 */
307
 */
307
protected String getToolTipText() {
308
protected String getToolTipText() {
308
	String result = null;
309
	String result = null;
(-)src/org/eclipse/gef/internal/ui/palette/editparts/GroupEditPart.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 17-22 Link Here
17
17
18
import org.eclipse.gef.palette.PaletteContainer;
18
import org.eclipse.gef.palette.PaletteContainer;
19
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
19
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
20
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
20
21
21
public class GroupEditPart 
22
public class GroupEditPart 
22
	extends PaletteEditPart 
23
	extends PaletteEditPart 
Lines 28-33 Link Here
28
	super(group);
29
	super(group);
29
}
30
}
30
31
32
/**
33
 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
34
 */
31
public IFigure createFigure() {
35
public IFigure createFigure() {
32
	return new GroupFigure();
36
	return new GroupFigure();
33
}
37
}
(-)src/org/eclipse/gef/internal/ui/palette/editparts/SliderPaletteEditPart.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 17-22 Link Here
17
17
18
import org.eclipse.gef.palette.PaletteRoot;
18
import org.eclipse.gef.palette.PaletteRoot;
19
import org.eclipse.gef.ui.palette.PaletteViewer;
19
import org.eclipse.gef.ui.palette.PaletteViewer;
20
import org.eclipse.gef.ui.palette.editparts.PaletteAnimator;
21
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
22
import org.eclipse.gef.ui.palette.editparts.PaletteToolbarLayout;
20
23
21
public class SliderPaletteEditPart 
24
public class SliderPaletteEditPart 
22
	extends PaletteEditPart
25
	extends PaletteEditPart
(-)src/org/eclipse/gef/internal/ui/palette/editparts/SeparatorEditPart.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 19-24 Link Here
19
import org.eclipse.draw2d.geometry.Rectangle;
19
import org.eclipse.draw2d.geometry.Rectangle;
20
20
21
import org.eclipse.gef.palette.PaletteSeparator;
21
import org.eclipse.gef.palette.PaletteSeparator;
22
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
22
23
23
/**
24
/**
24
 * EditPart for the PaletteSeparator
25
 * EditPart for the PaletteSeparator
Lines 45-51 Link Here
45
}
46
}
46
47
47
/**
48
/**
48
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#getToolTipText()
49
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#getToolTipText()
49
 */
50
 */
50
protected String getToolTipText() {
51
protected String getToolTipText() {
51
	return null;
52
	return null;
(-)src/org/eclipse/gef/internal/ui/palette/editparts/PaletteStackEditPart.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 48-53 Link Here
48
import org.eclipse.gef.ui.actions.SetActivePaletteToolAction;
48
import org.eclipse.gef.ui.actions.SetActivePaletteToolAction;
49
import org.eclipse.gef.ui.palette.PaletteViewer;
49
import org.eclipse.gef.ui.palette.PaletteViewer;
50
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
50
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
51
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
51
52
52
/**
53
/**
53
 * The EditPart for a PaletteStack.
54
 * The EditPart for a PaletteStack.
(-)src/org/eclipse/gef/internal/ui/palette/editparts/PaletteAnimator.java (-110 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.gef.internal.ui.palette.editparts;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.draw2d.LayoutAnimator;
18
import org.eclipse.draw2d.IFigure;
19
20
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
21
22
/**
23
 * @author Randy Hudson, Pratik Shah
24
 */
25
public class PaletteAnimator extends LayoutAnimator {
26
27
private List drawers = new ArrayList();
28
private PaletteViewerPreferences prefs;
29
30
/**
31
 * Constructor
32
 */
33
public PaletteAnimator(PaletteViewerPreferences prefs) {
34
	this.prefs = prefs;
35
}
36
37
public void addDrawer(DrawerEditPart drawer) {
38
	drawers.add(drawer.getFigure());
39
}
40
41
protected void autoCollapse(DrawerFigure openDrawer) {
42
	int autoCollapseMode = prefs.getAutoCollapseSetting();
43
	
44
	// Collapse never
45
	if (autoCollapseMode == PaletteViewerPreferences.COLLAPSE_NEVER)
46
		return;
47
	
48
	DrawerFigure drawer;
49
50
	// Collapse always
51
	if (autoCollapseMode == PaletteViewerPreferences.COLLAPSE_ALWAYS) {
52
		for (Iterator iter = drawers.iterator(); iter.hasNext();) {
53
			drawer = (DrawerFigure) iter.next();
54
			if (drawer != openDrawer)
55
				drawer.setExpanded(false);
56
		}
57
		return;
58
	}
59
	
60
	// Collapse as needed
61
	int wHint = openDrawer.getParent().getClientArea().width;
62
	int availableHeight = openDrawer.getParent().getSize().height;
63
	int requiredHeight = 0;
64
	List closable = new ArrayList();
65
	for (Iterator iter = openDrawer.getParent().getChildren().iterator(); iter.hasNext();) {
66
		IFigure sibling = (IFigure) iter.next();
67
		int height = sibling.getPreferredSize(wHint, -1).height;
68
		requiredHeight += height;
69
		if (!(sibling instanceof DrawerFigure) || sibling == openDrawer)
70
			continue;
71
		drawer = (DrawerFigure)sibling;
72
		if (drawer.isExpanded() && !drawer.isPinnedOpen())
73
			closable.add(drawer);
74
	}
75
	
76
	//Start closing until requiredHeight <= available
77
	for (int i = closable.size() - 1; i >= 0 && requiredHeight > availableHeight; i--) {
78
		drawer = (DrawerFigure)closable.get(i);
79
		int expandedHeight = drawer.getPreferredSize(wHint, -1).height;
80
		drawer.setExpanded(false);
81
		int collapsedHeight = drawer.getPreferredSize(wHint, -1).height;
82
		requiredHeight -= (expandedHeight - collapsedHeight);
83
	}
84
}
85
86
public void playbackStarting(IFigure figure) {
87
	if (figure instanceof DrawerFigure)
88
		((DrawerFigure)figure).setAnimating(true);
89
}
90
91
public void removeDrawer(DrawerEditPart drawer) {
92
	drawers.remove(drawer.getFigure());
93
}
94
95
public void init(IFigure figure) {
96
	if (figure instanceof DrawerFigure) {
97
		DrawerFigure drawer = (DrawerFigure) figure;
98
		if (drawer.isExpanded())
99
			autoCollapse(drawer);
100
		return;
101
	}
102
	super.init(figure);
103
}
104
105
public void tearDown(IFigure figure) {
106
	if (figure instanceof DrawerFigure)
107
		((DrawerFigure) figure).setAnimating(false);
108
}
109
110
}
(-)src/org/eclipse/gef/internal/ui/palette/editparts/DrawerFigure.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 52-57 Link Here
52
import org.eclipse.gef.internal.Internal;
52
import org.eclipse.gef.internal.Internal;
53
import org.eclipse.gef.ui.palette.PaletteMessages;
53
import org.eclipse.gef.ui.palette.PaletteMessages;
54
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
54
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
55
import org.eclipse.gef.ui.palette.editparts.PaletteToolbarLayout;
55
56
56
/**
57
/**
57
 * @author Pratik Shah
58
 * @author Pratik Shah
(-)src/org/eclipse/gef/internal/ui/palette/editparts/PaletteEditPart.java (-341 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.gef.internal.ui.palette.editparts;
12
13
import java.beans.PropertyChangeEvent;
14
import java.beans.PropertyChangeListener;
15
import java.util.ArrayList;
16
import java.util.Collections;
17
import java.util.HashMap;
18
import java.util.Iterator;
19
import java.util.List;
20
import java.util.Map;
21
22
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.widgets.Display;
24
25
import org.eclipse.jface.resource.ImageDescriptor;
26
import org.eclipse.ui.IMemento;
27
28
import org.eclipse.draw2d.Border;
29
import org.eclipse.draw2d.IFigure;
30
import org.eclipse.draw2d.MarginBorder;
31
import org.eclipse.draw2d.geometry.Dimension;
32
import org.eclipse.draw2d.text.FlowPage;
33
import org.eclipse.draw2d.text.TextFlow;
34
35
import org.eclipse.gef.AccessibleEditPart;
36
import org.eclipse.gef.DragTracker;
37
import org.eclipse.gef.Request;
38
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
39
import org.eclipse.gef.palette.PaletteContainer;
40
import org.eclipse.gef.palette.PaletteEntry;
41
import org.eclipse.gef.palette.PaletteSeparator;
42
import org.eclipse.gef.tools.SelectEditPartTracker;
43
import org.eclipse.gef.ui.palette.PaletteMessages;
44
import org.eclipse.gef.ui.palette.PaletteViewer;
45
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
46
47
public abstract class PaletteEditPart
48
	extends AbstractGraphicalEditPart
49
	implements PropertyChangeListener
50
{
51
	
52
public static final String XML_NAME = "entry"; //$NON-NLS-1$
53
private static final Border TOOLTIP_BORDER = new MarginBorder(0, 2, 1, 0);
54
private static ImageCache globalImageCache;
55
private AccessibleEditPart acc;
56
private PropertyChangeListener childListener = new PropertyChangeListener() {
57
	public void propertyChange(PropertyChangeEvent evt) {
58
		if (evt.getPropertyName().equals(PaletteEntry.PROPERTY_VISIBLE)) {
59
			refreshChildren();
60
		}
61
	}
62
};
63
private Image image;
64
private ImageDescriptor imgDescriptor;
65
66
public PaletteEditPart(PaletteEntry model) {
67
	setModel(model);
68
}
69
70
/**
71
 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#activate()
72
 */
73
public void activate() {
74
	super.activate();
75
	PaletteEntry model = (PaletteEntry)getModel();
76
	model.addPropertyChangeListener(this);
77
	traverseChildren(model, true);
78
}
79
80
/**
81
 * returns the AccessibleEditPart for this EditPart.   This method is called lazily from
82
 * {@link #getAccessibleEditPart()}.
83
 */
84
protected AccessibleEditPart createAccessible() {
85
	return null;
86
}
87
88
public void createEditPolicies() { }
89
90
protected IFigure createToolTip() {
91
	String message = getToolTipText();
92
	if (message == null || message.length() == 0)
93
		return null;
94
95
	FlowPage fp = new FlowPage() {
96
		public Dimension getPreferredSize(int w, int h) {
97
			Dimension d = super.getPreferredSize(-1, -1);
98
			if (d.width > 150)
99
				d = super.getPreferredSize(150, -1);
100
			return d;
101
		}
102
	};
103
	fp.setOpaque(true);
104
	fp.setBorder(TOOLTIP_BORDER);
105
	TextFlow tf = new TextFlow();
106
	tf.setText(message);
107
	fp.add(tf);
108
	return fp;
109
}
110
111
/**
112
 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#deactivate()
113
 */
114
public void deactivate() {
115
	PaletteEntry model = (PaletteEntry)getModel();
116
	model.removePropertyChangeListener(this);
117
	traverseChildren(model, false);
118
	if (image != null) {
119
		image.dispose();
120
		image = null;
121
	}
122
	super.deactivate();
123
}
124
125
126
protected AccessibleEditPart getAccessibleEditPart() {
127
	if (acc == null)
128
		acc = createAccessible();
129
	return acc;
130
}
131
132
class SingleSelectionTracker extends SelectEditPartTracker {
133
	SingleSelectionTracker() {
134
		super(PaletteEditPart.this);
135
	}
136
	protected void performSelection() {
137
		if (hasSelectionOccurred())
138
			return;
139
		setFlag(FLAG_SELECTION_PERFORMED, true);
140
		getCurrentViewer().select(getSourceEditPart());
141
	}
142
}
143
144
/**
145
 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getDragTracker(Request)
146
 */
147
public DragTracker getDragTracker(Request request) {
148
	return new SingleSelectionTracker();
149
}
150
151
/**
152
 * Returns the image cache.
153
 * The cache is global, and is shared by all palette edit parts. This has the disadvantage
154
 * that once an image is allocated, it is never freed until the display is disposed. 
155
 * However, it has the advantage that the same image in different palettes is
156
 * only ever created once.
157
 */
158
protected static ImageCache getImageCache() {
159
	ImageCache cache = globalImageCache;
160
	if (cache == null) {
161
		globalImageCache = cache = new ImageCache();
162
		Display display = Display.getDefault();
163
		if (display != null) {
164
			display.disposeExec(new Runnable() {
165
				public void run() {
166
					if (globalImageCache != null) {
167
						globalImageCache.dispose();
168
						globalImageCache = null;
169
					}
170
				}	
171
			});
172
		}
173
	}
174
	return cache;
175
}
176
177
/**
178
 * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren()
179
 */
180
public List getModelChildren() {
181
	List modelChildren;
182
	if (getModel() instanceof PaletteContainer)
183
		modelChildren = new ArrayList(((PaletteContainer)getModel()).getChildren());
184
	else
185
		return Collections.EMPTY_LIST;
186
	
187
	PaletteEntry prevVisibleEntry = null;
188
	for (Iterator iter = modelChildren.iterator(); iter.hasNext();) {
189
		PaletteEntry entry = (PaletteEntry) iter.next();
190
		if (!entry.isVisible())
191
			// not visible
192
			iter.remove();
193
		else if (entry instanceof PaletteSeparator && prevVisibleEntry == null) 
194
			// first visible item in a group is a separator, don't need it
195
			iter.remove();
196
		else if (entry instanceof PaletteSeparator && prevVisibleEntry instanceof PaletteSeparator)
197
			// previous visible entry was a separator, don't need it
198
			iter.remove();
199
		else
200
			prevVisibleEntry = entry;
201
	}
202
	// check to see if last visible entry was a separator, and thus should be hidden
203
	if (prevVisibleEntry instanceof PaletteSeparator) 
204
		modelChildren.remove(prevVisibleEntry);
205
	
206
	return modelChildren;
207
}
208
209
protected PaletteEntry getPaletteEntry() {
210
	return (PaletteEntry)getModel();
211
}
212
213
PaletteViewer getPaletteViewer() {
214
	return (PaletteViewer)getViewer();
215
}
216
217
protected PaletteViewerPreferences getPreferenceSource() {
218
	return ((PaletteViewer)getViewer()).getPaletteViewerPreferences();
219
}
220
221
protected IFigure getToolTipFigure() {
222
	return getFigure();
223
}
224
225
protected String getToolTipText() {
226
	String text = null;
227
	PaletteEntry entry = (PaletteEntry)getModel();
228
	String desc = entry.getDescription();
229
	boolean needName = nameNeededInToolTip();
230
	if (desc == null
231
	  || desc.trim().equals(entry.getLabel())
232
	  || desc.trim().equals("")) { //$NON-NLS-1$
233
		if (needName)
234
			text = entry.getLabel();
235
	} else {
236
		if (needName)
237
			text = entry.getLabel() + " " //$NON-NLS-1$
238
					+ PaletteMessages.NAME_DESCRIPTION_SEPARATOR + " " + desc; //$NON-NLS-1$
239
		else
240
			text = desc;
241
	}
242
	if (text != null && text.trim().equals(""))//$NON-NLS-1$
243
		return null;
244
	return text;
245
}
246
247
protected boolean nameNeededInToolTip() {
248
	return getPreferenceSource().getLayoutSetting() 
249
			== PaletteViewerPreferences.LAYOUT_ICONS;
250
}
251
252
/**
253
 * @see java.beans.PropertyChangeListener#propertyChange(PropertyChangeEvent)
254
 */
255
public void propertyChange(PropertyChangeEvent evt) {
256
	String property = evt.getPropertyName();
257
	if (property.equals(PaletteContainer.PROPERTY_CHILDREN)) {
258
		traverseChildren((List)evt.getOldValue(), false);
259
		refreshChildren();
260
		traverseChildren((List)evt.getNewValue(), true);
261
	} else if (property.equals(PaletteEntry.PROPERTY_LABEL)
262
			|| property.equals(PaletteEntry.PROPERTY_SMALL_ICON)
263
			|| property.equals(PaletteEntry.PROPERTY_LARGE_ICON)
264
			|| property.equals(PaletteEntry.PROPERTY_DESCRIPTION))
265
		refreshVisuals();
266
}
267
268
public void restoreState(IMemento memento) {
269
	Iterator iter = getChildren().iterator();
270
	IMemento[] childMementos = memento.getChildren(XML_NAME);
271
	int index = 0;
272
	while (iter.hasNext())
273
		((PaletteEditPart)iter.next()).restoreState(childMementos[index++]);
274
}
275
276
public void saveState(IMemento memento) {
277
	Iterator iter = getChildren().iterator();
278
	while (iter.hasNext())
279
		((PaletteEditPart)iter.next()).saveState(memento.createChild(XML_NAME));
280
}
281
282
protected void setImageDescriptor(ImageDescriptor desc) {
283
	if (desc == imgDescriptor)
284
		return;
285
	imgDescriptor = desc;
286
	setImageInFigure(getImageCache().getImage(imgDescriptor));
287
}
288
289
protected void setImageInFigure(Image image) { }
290
291
private void traverseChildren(PaletteEntry parent, boolean add) {
292
	if (!(parent instanceof PaletteContainer))
293
		return;
294
	PaletteContainer container = (PaletteContainer)parent;
295
	traverseChildren(container.getChildren(), add);
296
}
297
298
private void traverseChildren(List children, boolean add) {	
299
	for (Iterator iter = children.iterator(); iter.hasNext();) {
300
		PaletteEntry entry = (PaletteEntry) iter.next();
301
		if (add) {
302
			entry.addPropertyChangeListener(childListener);
303
		} else {
304
			entry.removePropertyChangeListener(childListener);
305
		}		
306
	}
307
}
308
309
protected static class ImageCache {
310
	/** Map from ImageDescriptor to Image */
311
	private Map images = new HashMap(11);
312
	
313
	Image getImage(ImageDescriptor desc) {
314
		if (desc == null) {
315
			return null;
316
		}
317
		Image img = null;
318
		Object obj = images.get(desc);
319
		if (obj != null) {
320
			img = (Image)obj;
321
		} else {
322
			img = desc.createImage();
323
			images.put(desc, img);
324
		}
325
		return img;
326
	}
327
328
	Image getMissingImage() {
329
		return getImage(ImageDescriptor.getMissingImageDescriptor());
330
	}
331
	
332
	void dispose() {
333
		for (Iterator i = images.values().iterator(); i.hasNext();) {
334
			Image img = (Image) i.next();
335
			img.dispose();
336
		}
337
		images.clear();
338
	}
339
}
340
341
}
(-)src/org/eclipse/gef/internal/ui/palette/editparts/DrawerEditPart.java (-3 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 35-40 Link Here
35
import org.eclipse.gef.palette.PaletteDrawer;
35
import org.eclipse.gef.palette.PaletteDrawer;
36
import org.eclipse.gef.palette.PaletteTemplateEntry;
36
import org.eclipse.gef.palette.PaletteTemplateEntry;
37
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
37
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
38
import org.eclipse.gef.ui.palette.editparts.PaletteAnimator;
39
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
38
40
39
/**
41
/**
40
 * EditPart for a PaletteDrawer
42
 * EditPart for a PaletteDrawer
Lines 141-147 Link Here
141
}
143
}
142
144
143
/**
145
/**
144
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#nameNeededInToolTip()
146
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#nameNeededInToolTip()
145
 */
147
 */
146
protected boolean nameNeededInToolTip() {
148
protected boolean nameNeededInToolTip() {
147
	return false;
149
	return false;
Lines 156-161 Link Here
156
	return getDrawerFigure().isPinShowing();
158
	return getDrawerFigure().isPinShowing();
157
}
159
}
158
160
161
/**
162
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#createAccessible()
163
 */
159
protected AccessibleEditPart createAccessible() {
164
protected AccessibleEditPart createAccessible() {
160
	return new AccessibleGraphicalEditPart() {
165
	return new AccessibleGraphicalEditPart() {
161
		public void getDescription(AccessibleEvent e) {
166
		public void getDescription(AccessibleEvent e) {
Lines 210-215 Link Here
210
	getFigure().addLayoutListener(getPaletteAnimator());
215
	getFigure().addLayoutListener(getPaletteAnimator());
211
}
216
}
212
217
218
/**
219
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#restoreState(org.eclipse.ui.IMemento)
220
 */
213
public void restoreState(IMemento memento) {
221
public void restoreState(IMemento memento) {
214
	setExpanded(new Boolean(memento.getString(PROPERTY_EXPANSION_STATE)).booleanValue());
222
	setExpanded(new Boolean(memento.getString(PROPERTY_EXPANSION_STATE)).booleanValue());
215
	setPinnedOpen(new Boolean(memento.getString(PROPERTY_PINNED_STATE)).booleanValue());
223
	setPinnedOpen(new Boolean(memento.getString(PROPERTY_PINNED_STATE)).booleanValue());
Lines 222-227 Link Here
222
	super.restoreState(memento);
230
	super.restoreState(memento);
223
}
231
}
224
232
233
/**
234
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#saveState(org.eclipse.ui.IMemento)
235
 */
225
public void saveState(IMemento memento) {
236
public void saveState(IMemento memento) {
226
	memento.putString(PROPERTY_EXPANSION_STATE, new Boolean(isExpanded()).toString());
237
	memento.putString(PROPERTY_EXPANSION_STATE, new Boolean(isExpanded()).toString());
227
	memento.putString(PROPERTY_PINNED_STATE, new Boolean(isPinnedOpen()).toString());
238
	memento.putString(PROPERTY_PINNED_STATE, new Boolean(isPinnedOpen()).toString());
Lines 244-250 Link Here
244
}
255
}
245
256
246
/**
257
/**
247
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#setImageInFigure(Image)
258
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#setImageInFigure(Image)
248
 */
259
 */
249
protected void setImageInFigure(Image image) {
260
protected void setImageInFigure(Image image) {
250
	getDrawerFigure().setTitleIcon(image);
261
	getDrawerFigure().setTitleIcon(image);
(-)src/org/eclipse/gef/internal/ui/palette/editparts/TemplateEditPart.java (-6 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 27-32 Link Here
27
import org.eclipse.gef.palette.PaletteEntry;
27
import org.eclipse.gef.palette.PaletteEntry;
28
import org.eclipse.gef.palette.PaletteTemplateEntry;
28
import org.eclipse.gef.palette.PaletteTemplateEntry;
29
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
29
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
30
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
30
31
31
/**
32
/**
32
 * @author Eric Bordeau, Pratik Shah
33
 * @author Eric Bordeau, Pratik Shah
Lines 49-55 Link Here
49
}
50
}
50
51
51
/**
52
/**
52
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#createAccessible()
53
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#createAccessible()
53
 */
54
 */
54
protected AccessibleEditPart createAccessible() {
55
protected AccessibleEditPart createAccessible() {
55
	return new AccessibleGraphicalEditPart () {
56
	return new AccessibleGraphicalEditPart () {
Lines 81-87 Link Here
81
}
82
}
82
83
83
/**
84
/**
84
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#deactivate()
85
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#deactivate()
85
 */
86
 */
86
public void deactivate() {
87
public void deactivate() {
87
	((DetailedLabelFigure)getFigure()).dispose();
88
	((DetailedLabelFigure)getFigure()).dispose();
Lines 89-95 Link Here
89
}
90
}
90
91
91
/**
92
/**
92
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#getDragTracker(Request)
93
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#getDragTracker(Request)
93
 */
94
 */
94
public DragTracker getDragTracker(Request request) {
95
public DragTracker getDragTracker(Request request) {
95
	return new SingleSelectionTracker() {
96
	return new SingleSelectionTracker() {
Lines 105-111 Link Here
105
}
106
}
106
107
107
/**
108
/**
108
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#getToolTipText()
109
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#getToolTipText()
109
 */
110
 */
110
protected String getToolTipText() {
111
protected String getToolTipText() {
111
	String result = null;
112
	String result = null;
Lines 159-165 Link Here
159
}
160
}
160
161
161
/**
162
/**
162
 * @see org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart#setImageInFigure(Image)
163
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#setImageInFigure(Image)
163
 */
164
 */
164
protected void setImageInFigure(Image image) {
165
protected void setImageInFigure(Image image) {
165
	DetailedLabelFigure fig = (DetailedLabelFigure)getFigure();
166
	DetailedLabelFigure fig = (DetailedLabelFigure)getFigure();
(-)src/org/eclipse/gef/internal/ui/palette/editparts/PaletteToolbarLayout.java (-181 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.gef.internal.ui.palette.editparts;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.ToolbarLayout;
19
import org.eclipse.draw2d.geometry.Dimension;
20
import org.eclipse.draw2d.geometry.Rectangle;
21
22
/**
23
 * A ToolbarLayout-like layout for the palette.  This layout is palette-specific and 
24
 * should not be used externally.  This layout only works when vertically oriented.
25
 * 
26
 * @author Pratik Shah
27
 */
28
public class PaletteToolbarLayout 
29
	extends ToolbarLayout 
30
{
31
32
/**
33
 * A figure is growing if it's an expanded drawer.
34
 * 
35
 * @param 	child	The figure that is to be marked as growing or non-growing
36
 * @return	<code>true</code> if the given child is considered growing
37
 */
38
protected boolean isChildGrowing(IFigure child) {
39
	return child instanceof DrawerFigure && ((DrawerFigure)child).isExpanded();
40
}
41
42
public void layout(IFigure parent) {
43
	List children = parent.getChildren();
44
	List childrenGrabbingVertical = new ArrayList();
45
	int numChildren = children.size();
46
	Rectangle clientArea = parent.getClientArea();
47
	int x = clientArea.x;
48
	int y = clientArea.y;
49
	int availableHeight = clientArea.height;
50
	boolean stretching;
51
	Dimension prefSizes [] = new Dimension[numChildren];
52
	Dimension minSizes [] = new Dimension[numChildren];
53
	int totalHeight = 0, totalMinHeight = 0, heightOfNonGrowingChildren = 0, 
54
		heightPerChild = 0, excessHeight = 0;
55
	
56
	/*
57
	 * Determine hints.
58
	 */
59
	int wHint = clientArea.width;
60
	int hHint = -1;
61
62
	/*
63
	 * Store the preferred and minimum sizes of all figures.  Determine which figures can
64
	 * be stretched/shrunk.
65
	 */
66
	for (int i = 0; i < numChildren; i++) {
67
		IFigure child = (IFigure)children.get(i);
68
		
69
		prefSizes[i] = child.getPreferredSize(wHint, hHint);
70
		minSizes[i] = child.getMinimumSize(wHint, hHint);
71
		
72
		totalHeight += prefSizes[i].height;
73
		totalMinHeight += minSizes[i].height;
74
						
75
		if (isChildGrowing(child)) {
76
			childrenGrabbingVertical.add(child);
77
		} else {
78
			heightOfNonGrowingChildren += prefSizes[i].height;
79
		}
80
	}
81
	totalHeight += (numChildren - 1) * getSpacing();
82
	totalMinHeight += (numChildren - 1) * getSpacing();
83
84
	/*
85
	 * This is the algorithm that determines which figures need to be compressed/stretched
86
	 * and by how much.
87
	 */
88
	stretching = totalHeight - Math.max(availableHeight, totalMinHeight) < 0;
89
	if (stretching) {
90
		/*
91
		 * We only want the last child to stretch.  So, we mark all but the last
92
		 * growing child as non-growing.
93
		 */
94
		for (int i = 0; i < childrenGrabbingVertical.size() - 1; i++) {
95
			int index = children.indexOf(childrenGrabbingVertical.get(i));
96
			heightOfNonGrowingChildren += prefSizes[index].height;
97
		}
98
		if (!childrenGrabbingVertical.isEmpty()) {
99
			Object last = childrenGrabbingVertical
100
					.get(childrenGrabbingVertical.size() - 1);
101
			childrenGrabbingVertical.clear();
102
			childrenGrabbingVertical.add(last);
103
			heightPerChild = availableHeight - heightOfNonGrowingChildren;
104
		}
105
	} else if (!childrenGrabbingVertical.isEmpty()) {
106
		/*
107
		 * So long as there is at least one child that can be grown, figure out how much
108
		 * height should be given to each growing child.
109
		 */
110
		boolean childrenDiscarded;
111
		// spaceToConsume is the space height available on the palette that is to be
112
		// shared by the growing children.
113
		int spaceToConsume = availableHeight - heightOfNonGrowingChildren;
114
		// heightPerChild is the height that each growing child is to be grown up to
115
		heightPerChild = spaceToConsume / childrenGrabbingVertical.size();
116
		// excessHeight is the space leftover at the bottom of the palette after each
117
		// growing child has been grown by heightPerChild.
118
		excessHeight = spaceToConsume - (heightPerChild * childrenGrabbingVertical.size());
119
		do {
120
			childrenDiscarded = false;
121
			for (Iterator iter = childrenGrabbingVertical.iterator(); iter.hasNext();) {
122
				IFigure childFig = (IFigure)iter.next();
123
				int i = childFig.getParent().getChildren().indexOf(childFig);
124
				// In the case of shrinking, if the child's height is less than
125
				// heightPerChild, mark that child as non-growing
126
				if (prefSizes[i].height < heightPerChild) {
127
					spaceToConsume -= prefSizes[i].height;
128
					heightOfNonGrowingChildren += prefSizes[i].height;
129
					iter.remove();
130
					if (!childrenGrabbingVertical.isEmpty()) {
131
						childrenDiscarded = true;
132
						heightPerChild = spaceToConsume / childrenGrabbingVertical.size();
133
						excessHeight = spaceToConsume 
134
								- (heightPerChild * childrenGrabbingVertical.size());
135
					}
136
					break;
137
				}
138
			}
139
		} while (childrenDiscarded);
140
	}	
141
142
	/*
143
	 * Do the actual layout, i.e. set the bounds of all the figures.
144
	 */
145
	for (int i = 0; i < numChildren; i++) {
146
		IFigure child = (IFigure)children.get(i);
147
		Rectangle newBounds = new Rectangle(x, y, prefSizes[i].width, prefSizes[i].height);
148
149
		if (childrenGrabbingVertical.contains(child)) {
150
			// Set the height of growing children.  If this is the last one, give it
151
			// the excess height.
152
			childrenGrabbingVertical.remove(child);
153
			if (childrenGrabbingVertical.isEmpty())
154
				newBounds.height = heightPerChild + excessHeight;
155
			else
156
				newBounds.height = heightPerChild;
157
		}
158
159
		if (getStretchMinorAxis())
160
			newBounds.width = clientArea.width;
161
		else
162
			newBounds.width = Math.min(prefSizes[i].width, clientArea.width);
163
164
		int adjust = clientArea.width - newBounds.width;
165
		switch (getMinorAlignment()) {
166
			case ALIGN_TOPLEFT: 
167
				adjust = 0;
168
				break;
169
			case ALIGN_CENTER:
170
				adjust /= 2;
171
				break;
172
			case ALIGN_BOTTOMRIGHT:
173
				break;
174
		}
175
		newBounds.x += adjust;
176
		child.setBounds(newBounds);
177
		y += newBounds.height + getSpacing();
178
	}
179
}
180
181
}
(-)src/org/eclipse/gef/ui/palette/editparts/PaletteEditPart.java (-6 / +81 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-14 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.gef.internal.ui.palette.editparts;
11
package org.eclipse.gef.ui.palette.editparts;
12
12
13
import java.beans.PropertyChangeEvent;
13
import java.beans.PropertyChangeEvent;
14
import java.beans.PropertyChangeListener;
14
import java.beans.PropertyChangeListener;
Lines 44-54 Link Here
44
import org.eclipse.gef.ui.palette.PaletteViewer;
44
import org.eclipse.gef.ui.palette.PaletteViewer;
45
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
45
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
46
46
47
/**
48
 * The abstract implementation of palette edit parts. All edit parts used in 
49
 * the palette must extend this class.
50
 */
47
public abstract class PaletteEditPart
51
public abstract class PaletteEditPart
48
	extends AbstractGraphicalEditPart
52
	extends AbstractGraphicalEditPart
49
	implements PropertyChangeListener
53
	implements PropertyChangeListener
50
{
54
{
51
	
55
	
56
/**
57
 * The name of each entry in the palette, used to restore the state.
58
 */	
52
public static final String XML_NAME = "entry"; //$NON-NLS-1$
59
public static final String XML_NAME = "entry"; //$NON-NLS-1$
53
private static final Border TOOLTIP_BORDER = new MarginBorder(0, 2, 1, 0);
60
private static final Border TOOLTIP_BORDER = new MarginBorder(0, 2, 1, 0);
54
private static ImageCache globalImageCache;
61
private static ImageCache globalImageCache;
Lines 63-68 Link Here
63
private Image image;
70
private Image image;
64
private ImageDescriptor imgDescriptor;
71
private ImageDescriptor imgDescriptor;
65
72
73
/**
74
 * Constructor for the PaletteEditPart. 
75
 * @param model The model element for this edit part.
76
 */
66
public PaletteEditPart(PaletteEntry model) {
77
public PaletteEditPart(PaletteEntry model) {
67
	setModel(model);
78
	setModel(model);
68
}
79
}
Lines 80-92 Link Here
80
/**
91
/**
81
 * returns the AccessibleEditPart for this EditPart.   This method is called lazily from
92
 * returns the AccessibleEditPart for this EditPart.   This method is called lazily from
82
 * {@link #getAccessibleEditPart()}.
93
 * {@link #getAccessibleEditPart()}.
94
 * @return the AccessibleEditPart.
83
 */
95
 */
84
protected AccessibleEditPart createAccessible() {
96
protected AccessibleEditPart createAccessible() {
85
	return null;
97
	return null;
86
}
98
}
87
99
100
/**
101
 * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
102
 */
88
public void createEditPolicies() { }
103
public void createEditPolicies() { }
89
104
105
/**
106
 * Create the tool tip for this palette edit part.
107
 * @return the tool tip figure.
108
 */
90
protected IFigure createToolTip() {
109
protected IFigure createToolTip() {
91
	String message = getToolTipText();
110
	String message = getToolTipText();
92
	if (message == null || message.length() == 0)
111
	if (message == null || message.length() == 0)
Lines 122-138 Link Here
122
	super.deactivate();
141
	super.deactivate();
123
}
142
}
124
143
125
144
/**
145
 * @see org.eclipse.gef.editparts.AbstractEditPart#getAccessibleEditPart()
146
 */
126
protected AccessibleEditPart getAccessibleEditPart() {
147
protected AccessibleEditPart getAccessibleEditPart() {
127
	if (acc == null)
148
	if (acc == null)
128
		acc = createAccessible();
149
		acc = createAccessible();
129
	return acc;
150
	return acc;
130
}
151
}
131
152
132
class SingleSelectionTracker extends SelectEditPartTracker {
153
/**
133
	SingleSelectionTracker() {
154
 * A selection tracker for the edit part. 
155
 */
156
public class SingleSelectionTracker extends SelectEditPartTracker {
157
	/**
158
	 * Constructor for a SingleSelectionTracker.
159
	 */
160
	public SingleSelectionTracker() {
134
		super(PaletteEditPart.this);
161
		super(PaletteEditPart.this);
135
	}
162
	}
163
	/**
164
	 * @see org.eclipse.gef.tools.SelectEditPartTracker#performSelection()
165
	 */
136
	protected void performSelection() {
166
	protected void performSelection() {
137
		if (hasSelectionOccurred())
167
		if (hasSelectionOccurred())
138
			return;
168
			return;
Lines 154-159 Link Here
154
 * that once an image is allocated, it is never freed until the display is disposed. 
184
 * that once an image is allocated, it is never freed until the display is disposed. 
155
 * However, it has the advantage that the same image in different palettes is
185
 * However, it has the advantage that the same image in different palettes is
156
 * only ever created once.
186
 * only ever created once.
187
 * @return the image cache.
157
 */
188
 */
158
protected static ImageCache getImageCache() {
189
protected static ImageCache getImageCache() {
159
	ImageCache cache = globalImageCache;
190
	ImageCache cache = globalImageCache;
Lines 206-227 Link Here
206
	return modelChildren;
237
	return modelChildren;
207
}
238
}
208
239
240
/**
241
 * Get the model element for this palette edit part.
242
 * @return the model element.
243
 */
209
protected PaletteEntry getPaletteEntry() {
244
protected PaletteEntry getPaletteEntry() {
210
	return (PaletteEntry)getModel();
245
	return (PaletteEntry)getModel();
211
}
246
}
212
247
213
PaletteViewer getPaletteViewer() {
248
/**
249
 * Get the palette viewer for this palette edit part.
250
 * @return the palette viewer.
251
 */
252
protected PaletteViewer getPaletteViewer() {
214
	return (PaletteViewer)getViewer();
253
	return (PaletteViewer)getViewer();
215
}
254
}
216
255
256
/**
257
 * Get the palette viewer preferences for this palette edit part.
258
 * @return the palette viewer preferences.
259
 */
217
protected PaletteViewerPreferences getPreferenceSource() {
260
protected PaletteViewerPreferences getPreferenceSource() {
218
	return ((PaletteViewer)getViewer()).getPaletteViewerPreferences();
261
	return ((PaletteViewer)getViewer()).getPaletteViewerPreferences();
219
}
262
}
220
263
264
/**
265
 * Get the tool tip figure for this palette edit part.
266
 * @return the tool tip figure.
267
 */
221
protected IFigure getToolTipFigure() {
268
protected IFigure getToolTipFigure() {
222
	return getFigure();
269
	return getFigure();
223
}
270
}
224
271
272
/**
273
 * Get the tool tip text for this palette edit part.
274
 * @return the tool tip text.
275
 */
225
protected String getToolTipText() {
276
protected String getToolTipText() {
226
	String text = null;
277
	String text = null;
227
	PaletteEntry entry = (PaletteEntry)getModel();
278
	PaletteEntry entry = (PaletteEntry)getModel();
Lines 244-249 Link Here
244
	return text;
295
	return text;
245
}
296
}
246
297
298
/**
299
 * Determine if the name is needed in the tool tip.
300
 * @return <code>true</code> if the name is needed in the tool tip.
301
 * @since 3.2
302
 */
247
protected boolean nameNeededInToolTip() {
303
protected boolean nameNeededInToolTip() {
248
	return getPreferenceSource().getLayoutSetting() 
304
	return getPreferenceSource().getLayoutSetting() 
249
			== PaletteViewerPreferences.LAYOUT_ICONS;
305
			== PaletteViewerPreferences.LAYOUT_ICONS;
Lines 265-270 Link Here
265
		refreshVisuals();
321
		refreshVisuals();
266
}
322
}
267
323
324
/**
325
 * Restore the state of the palette entry. 
326
 * @param memento the saved state of the palette entry.
327
 */
268
public void restoreState(IMemento memento) {
328
public void restoreState(IMemento memento) {
269
	Iterator iter = getChildren().iterator();
329
	Iterator iter = getChildren().iterator();
270
	IMemento[] childMementos = memento.getChildren(XML_NAME);
330
	IMemento[] childMementos = memento.getChildren(XML_NAME);
Lines 273-284 Link Here
273
		((PaletteEditPart)iter.next()).restoreState(childMementos[index++]);
333
		((PaletteEditPart)iter.next()).restoreState(childMementos[index++]);
274
}
334
}
275
335
336
/**
337
 * Save the state of the palette entry. 
338
 * @param memento the saved state of the palette entry.
339
 */
276
public void saveState(IMemento memento) {
340
public void saveState(IMemento memento) {
277
	Iterator iter = getChildren().iterator();
341
	Iterator iter = getChildren().iterator();
278
	while (iter.hasNext())
342
	while (iter.hasNext())
279
		((PaletteEditPart)iter.next()).saveState(memento.createChild(XML_NAME));
343
		((PaletteEditPart)iter.next()).saveState(memento.createChild(XML_NAME));
280
}
344
}
281
345
346
/**
347
 * Set the image for this palette edit part.
348
 * @param desc the image descriptor.
349
 */
282
protected void setImageDescriptor(ImageDescriptor desc) {
350
protected void setImageDescriptor(ImageDescriptor desc) {
283
	if (desc == imgDescriptor)
351
	if (desc == imgDescriptor)
284
		return;
352
		return;
Lines 286-291 Link Here
286
	setImageInFigure(getImageCache().getImage(imgDescriptor));
354
	setImageInFigure(getImageCache().getImage(imgDescriptor));
287
}
355
}
288
356
357
/**
358
 * Set the image to be used in the figure for this edit edit.
359
 * @param image the image
360
 */
289
protected void setImageInFigure(Image image) { }
361
protected void setImageInFigure(Image image) { }
290
362
291
private void traverseChildren(PaletteEntry parent, boolean add) {
363
private void traverseChildren(PaletteEntry parent, boolean add) {
Lines 306-311 Link Here
306
	}
378
	}
307
}
379
}
308
380
381
/**
382
 * The image cache for this edit part.
383
 */
309
protected static class ImageCache {
384
protected static class ImageCache {
310
	/** Map from ImageDescriptor to Image */
385
	/** Map from ImageDescriptor to Image */
311
	private Map images = new HashMap(11);
386
	private Map images = new HashMap(11);
(-)src/org/eclipse/gef/ui/palette/editparts/PaletteAnimator.java (-4 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-25 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.gef.internal.ui.palette.editparts;
11
package org.eclipse.gef.ui.palette.editparts;
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Iterator;
14
import java.util.Iterator;
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.draw2d.LayoutAnimator;
18
import org.eclipse.draw2d.IFigure;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.LayoutAnimator;
19
19
20
import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart;
21
import org.eclipse.gef.internal.ui.palette.editparts.DrawerFigure;
20
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
22
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
21
23
22
/**
24
/**
25
 * An animator for the layout of the palette.
26
 * 
23
 * @author Randy Hudson, Pratik Shah
27
 * @author Randy Hudson, Pratik Shah
24
 */
28
 */
25
public class PaletteAnimator extends LayoutAnimator {
29
public class PaletteAnimator extends LayoutAnimator {
Lines 28-43 Link Here
28
private PaletteViewerPreferences prefs;
32
private PaletteViewerPreferences prefs;
29
33
30
/**
34
/**
31
 * Constructor
35
 * Constructor for a PaletteAnimator
36
 * @param prefs The palette PaletteViewerPreferencesPreferences
32
 */
37
 */
33
public PaletteAnimator(PaletteViewerPreferences prefs) {
38
public PaletteAnimator(PaletteViewerPreferences prefs) {
34
	this.prefs = prefs;
39
	this.prefs = prefs;
35
}
40
}
36
41
42
/**
43
 * Add a drawer to the palette.
44
 * @param drawer the drawer.
45
 */
37
public void addDrawer(DrawerEditPart drawer) {
46
public void addDrawer(DrawerEditPart drawer) {
38
	drawers.add(drawer.getFigure());
47
	drawers.add(drawer.getFigure());
39
}
48
}
40
49
50
/**
51
 * Collapse the provided drawer if the automatoc collapse setting is enabled. 
52
 * @param openDrawer The drawer to collapse.
53
 * @since 3.2
54
 */
41
protected void autoCollapse(DrawerFigure openDrawer) {
55
protected void autoCollapse(DrawerFigure openDrawer) {
42
	int autoCollapseMode = prefs.getAutoCollapseSetting();
56
	int autoCollapseMode = prefs.getAutoCollapseSetting();
43
	
57
	
Lines 83-97 Link Here
83
	}
97
	}
84
}
98
}
85
99
100
/**
101
 * @see org.eclipse.draw2d.Animator#playbackStarting(org.eclipse.draw2d.IFigure)
102
 */
86
public void playbackStarting(IFigure figure) {
103
public void playbackStarting(IFigure figure) {
87
	if (figure instanceof DrawerFigure)
104
	if (figure instanceof DrawerFigure)
88
		((DrawerFigure)figure).setAnimating(true);
105
		((DrawerFigure)figure).setAnimating(true);
89
}
106
}
90
107
108
/**
109
 * Remove the drawer.
110
 * @param drawer the drawer.
111
 */
91
public void removeDrawer(DrawerEditPart drawer) {
112
public void removeDrawer(DrawerEditPart drawer) {
92
	drawers.remove(drawer.getFigure());
113
	drawers.remove(drawer.getFigure());
93
}
114
}
94
115
116
/**
117
 * @see org.eclipse.draw2d.Animator#init(org.eclipse.draw2d.IFigure)
118
 */
95
public void init(IFigure figure) {
119
public void init(IFigure figure) {
96
	if (figure instanceof DrawerFigure) {
120
	if (figure instanceof DrawerFigure) {
97
		DrawerFigure drawer = (DrawerFigure) figure;
121
		DrawerFigure drawer = (DrawerFigure) figure;
Lines 102-107 Link Here
102
	super.init(figure);
126
	super.init(figure);
103
}
127
}
104
128
129
/**
130
 * @see org.eclipse.draw2d.Animator#tearDown(org.eclipse.draw2d.IFigure)
131
 */
105
public void tearDown(IFigure figure) {
132
public void tearDown(IFigure figure) {
106
	if (figure instanceof DrawerFigure)
133
	if (figure instanceof DrawerFigure)
107
		((DrawerFigure) figure).setAnimating(false);
134
		((DrawerFigure) figure).setAnimating(false);
(-)src/org/eclipse/gef/ui/palette/editparts/PaletteToolbarLayout.java (-4 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-14 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.gef.internal.ui.palette.editparts;
11
package org.eclipse.gef.ui.palette.editparts;
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Iterator;
14
import java.util.Iterator;
Lines 19-27 Link Here
19
import org.eclipse.draw2d.geometry.Dimension;
19
import org.eclipse.draw2d.geometry.Dimension;
20
import org.eclipse.draw2d.geometry.Rectangle;
20
import org.eclipse.draw2d.geometry.Rectangle;
21
21
22
import org.eclipse.gef.internal.ui.palette.editparts.DrawerFigure;
23
22
/**
24
/**
23
 * A ToolbarLayout-like layout for the palette.  This layout is palette-specific and 
25
 * A ToolbarLayout-like layout for the palette. This layout only works when 
24
 * should not be used externally.  This layout only works when vertically oriented.
26
 * vertically oriented.
25
 * 
27
 * 
26
 * @author Pratik Shah
28
 * @author Pratik Shah
27
 */
29
 */
Lines 39-44 Link Here
39
	return child instanceof DrawerFigure && ((DrawerFigure)child).isExpanded();
41
	return child instanceof DrawerFigure && ((DrawerFigure)child).isExpanded();
40
}
42
}
41
43
44
/**
45
 * @see org.eclipse.draw2d.ToolbarLayout#layout(org.eclipse.draw2d.IFigure)
46
 */
42
public void layout(IFigure parent) {
47
public void layout(IFigure parent) {
43
	List children = parent.getChildren();
48
	List children = parent.getChildren();
44
	List childrenGrabbingVertical = new ArrayList();
49
	List childrenGrabbingVertical = new ArrayList();
(-)src/org/eclipse/gef/ui/palette/PaletteViewer.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 32-38 Link Here
32
import org.eclipse.gef.editparts.SimpleRootEditPart;
32
import org.eclipse.gef.editparts.SimpleRootEditPart;
33
import org.eclipse.gef.internal.ui.palette.PaletteSelectionTool;
33
import org.eclipse.gef.internal.ui.palette.PaletteSelectionTool;
34
import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart;
34
import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart;
35
import org.eclipse.gef.internal.ui.palette.editparts.PaletteEditPart;
36
import org.eclipse.gef.internal.ui.palette.editparts.PaletteStackEditPart;
35
import org.eclipse.gef.internal.ui.palette.editparts.PaletteStackEditPart;
37
import org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditPart;
36
import org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditPart;
38
import org.eclipse.gef.palette.PaletteDrawer;
37
import org.eclipse.gef.palette.PaletteDrawer;
Lines 42-47 Link Here
42
import org.eclipse.gef.palette.PaletteStack;
41
import org.eclipse.gef.palette.PaletteStack;
43
import org.eclipse.gef.palette.ToolEntry;
42
import org.eclipse.gef.palette.ToolEntry;
44
import org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog;
43
import org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog;
44
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
45
import org.eclipse.gef.ui.parts.PaletteViewerKeyHandler;
45
import org.eclipse.gef.ui.parts.PaletteViewerKeyHandler;
46
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
46
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
47
47
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 28-33 Link Here
28
 org.eclipse.gef.ui.console.icons,
28
 org.eclipse.gef.ui.console.icons,
29
 org.eclipse.gef.ui.palette,
29
 org.eclipse.gef.ui.palette,
30
 org.eclipse.gef.ui.palette.customize,
30
 org.eclipse.gef.ui.palette.customize,
31
 org.eclipse.gef.ui.palette.editparts,
31
 org.eclipse.gef.ui.parts,
32
 org.eclipse.gef.ui.parts,
32
 org.eclipse.gef.ui.properties,
33
 org.eclipse.gef.ui.properties,
33
 org.eclipse.gef.ui.rulers,
34
 org.eclipse.gef.ui.rulers,

Return to bug 206800