View | Details | Raw Unified | Return to bug 225162
Collapse All | Expand All

(-)src/org/eclipse/gef/ui/palette/PaletteContextMenuProvider.java (-8 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 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 13-20 Link Here
13
import org.eclipse.jface.action.IMenuManager;
13
import org.eclipse.jface.action.IMenuManager;
14
14
15
import org.eclipse.gef.ContextMenuProvider;
15
import org.eclipse.gef.ContextMenuProvider;
16
import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart;
16
import org.eclipse.gef.EditPart;
17
import org.eclipse.gef.ui.actions.GEFActionConstants;
17
import org.eclipse.gef.ui.actions.GEFActionConstants;
18
import org.eclipse.gef.ui.palette.editparts.IPinnableEditPart;
18
19
19
/**
20
/**
20
 * Provides the context menu for a palette.
21
 * Provides the context menu for a palette.
Lines 51-62 Link Here
51
public void buildContextMenu(IMenuManager menu) {
52
public void buildContextMenu(IMenuManager menu) {
52
	GEFActionConstants.addStandardActionGroups(menu);
53
	GEFActionConstants.addStandardActionGroups(menu);
53
54
54
	Object selectedPart = getPaletteViewer().getSelectedEditParts().get(0);
55
	EditPart selectedPart = (EditPart) getPaletteViewer()
55
	if (selectedPart instanceof DrawerEditPart 
56
        .getSelectedEditParts().get(0);
56
					&& ((DrawerEditPart)selectedPart).canBePinned()) {
57
    IPinnableEditPart pinnablePart = (IPinnableEditPart) selectedPart
57
		menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, 
58
        .getAdapter(IPinnableEditPart.class);
58
						new PinDrawerAction((DrawerEditPart)selectedPart));
59
    if (pinnablePart != null && pinnablePart.canBePinned()) {
59
	}
60
        menu.appendToGroup(GEFActionConstants.MB_ADDITIONS,
61
            new PinDrawerAction(pinnablePart));
62
    } 
60
	menu.appendToGroup(GEFActionConstants.GROUP_VIEW, new LayoutAction(
63
	menu.appendToGroup(GEFActionConstants.GROUP_VIEW, new LayoutAction(
61
			getPaletteViewer().getPaletteViewerPreferences()));
64
			getPaletteViewer().getPaletteViewerPreferences()));
62
	menu.appendToGroup(GEFActionConstants.GROUP_VIEW, new ChangeIconSizeAction(
65
	menu.appendToGroup(GEFActionConstants.GROUP_VIEW, new ChangeIconSizeAction(
(-)src/org/eclipse/gef/ui/palette/PinDrawerAction.java (-6 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 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 13-27 Link Here
13
import org.eclipse.jface.action.Action;
13
import org.eclipse.jface.action.Action;
14
14
15
import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart;
15
import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart;
16
import org.eclipse.gef.ui.palette.editparts.IPinnableEditPart;
16
17
17
/**
18
/**
18
 * An action that can be used to pin the given drawer open.
19
 * An action that can be used to pin the given pinnable palette editpart (drawer
20
 * or stack) open.
19
 * 
21
 * 
20
 * @author Pratik Shah
22
 * @author Pratik Shah
21
 */
23
 */
22
public class PinDrawerAction extends Action {
24
public class PinDrawerAction extends Action {
23
	
25
	
24
private DrawerEditPart drawer;
26
private IPinnableEditPart pinnableEditPart;
25
27
26
/**
28
/**
27
 * Constructor
29
 * Constructor
Lines 29-47 Link Here
29
 * @param	drawer	The EditPart for the drawer that this action pins/unpins
31
 * @param	drawer	The EditPart for the drawer that this action pins/unpins
30
 */
32
 */
31
public PinDrawerAction (DrawerEditPart drawer) {
33
public PinDrawerAction (DrawerEditPart drawer) {
32
	this.drawer = drawer;
34
	this.pinnableEditPart = drawer;
33
	setChecked(drawer.isPinnedOpen());
35
	setChecked(drawer.isPinnedOpen());
34
	setEnabled(drawer.isExpanded());
36
	setEnabled(drawer.isExpanded());
35
	setText(PaletteMessages.PINNED);
37
	setText(PaletteMessages.PINNED);
36
}
38
}
37
39
38
/**
40
/**
39
 * Toggles the pinned open status of the drawer.
41
 * Constructor
42
 *
43
 * @param pinnableEditPart the pinnable palette editpart
44
 * @since 3.4
45
 */
46
public PinDrawerAction(IPinnableEditPart pinnableEditPart) {
47
    this.pinnableEditPart = pinnableEditPart;
48
    setChecked(pinnableEditPart.isPinnedOpen());
49
    setEnabled(pinnableEditPart.isExpanded());
50
    setText(PaletteMessages.PINNED);
51
}
52
53
/**
54
 * Toggles the pinned open status of the pinnable palette editpart.
40
 * 
55
 * 
41
 * @see org.eclipse.jface.action.Action#run()
56
 * @see org.eclipse.jface.action.Action#run()
42
 */
57
 */
43
public void run() {
58
public void run() {
44
	drawer.setPinnedOpen(!drawer.isPinnedOpen());
59
	pinnableEditPart.setPinnedOpen(!pinnableEditPart.isPinnedOpen());
45
}
60
}
46
61
47
}
62
}
(-)src/org/eclipse/gef/internal/ui/palette/editparts/PinnablePaletteStackFigure.java (-66 / +69 lines)
Lines 16-22 Link Here
16
16
17
import org.eclipse.swt.graphics.Color;
17
import org.eclipse.swt.graphics.Color;
18
18
19
import org.eclipse.draw2d.AbstractHintLayout;
20
import org.eclipse.draw2d.AbstractLayout;
19
import org.eclipse.draw2d.AbstractLayout;
21
import org.eclipse.draw2d.Animation;
20
import org.eclipse.draw2d.Animation;
22
import org.eclipse.draw2d.BorderLayout;
21
import org.eclipse.draw2d.BorderLayout;
Lines 130-182 Link Here
130
}
129
}
131
130
132
/**
131
/**
133
 * Layout manager for the palette stack figure that handles the layout of the
132
 * Layout manager for the palette stack header figure that handles the layout of
134
 * <code>headerFigure</code>, <code>expandablePane</code>, and
133
 * the <code>headerFigure</code> (<code>pinFigure</code>,
135
 * <code>pinFigure</code> when in list or details layout mode.
134
 * <code>arrowFigure</code>, and the active tool figure) when in list or
135
 * details layout mode.
136
 */
136
 */
137
private class PaletteStackListLayout
137
private class HeaderListLayout
138
    extends AbstractHintLayout {
138
    extends StackLayout {
139
139
140
protected boolean isSensitiveVertically(IFigure container) {
140
protected boolean isSensitiveVertically(IFigure container) {
141
    return false;
141
    return false;
142
}
142
}
143
143
144
protected Dimension calculatePreferredSize(IFigure parent, int wHint, int hHint) {
144
protected Dimension calculatePreferredSize(IFigure parent, int wHint, int hHint) {
145
    Dimension headerSize = headerFigure.getPreferredSize(wHint, hHint);
145
    if (isExpanded()) {
146
146
        Dimension pinSize = pinFigure.getSize();
147
    if (((PinnablePaletteStackFigure) parent).isExpanded()) {
147
        Dimension preferredSize = super.calculatePreferredSize(parent, wHint
148
        Dimension paneSize = expandablePane.getPreferredSize(wHint, hHint);
148
            - pinSize.width, hHint);
149
        return new Dimension(Math.max(headerSize.width, paneSize.width),
149
        preferredSize.width += pinSize.width;
150
            headerSize.height + paneSize.height);
150
        return preferredSize;
151
    } else {
151
    } else {
152
        return headerSize;
152
        return super.calculatePreferredSize(parent, wHint, hHint);
153
    }
153
    }
154
}
154
}
155
155
156
public void layout(IFigure parent) {
156
public void layout(IFigure parent) {
157
    Rectangle clientArea = Rectangle.SINGLETON;
158
    parent.getClientArea(clientArea);
159
    int wHint = clientArea.width;
160
    int hHint = -1;
161
162
    Rectangle rect = new Rectangle();
163
    rect.setSize(headerFigure.getPreferredSize(wHint, hHint));
164
    rect.setLocation(clientArea.getTopLeft());
165
    headerFigure.setBounds(rect);
166
167
    if (((PinnablePaletteStackFigure) parent).isExpanded()) {
168
        rect.translate(0, rect.height);
169
        rect.setSize(expandablePane.getPreferredSize(wHint, hHint));
170
        expandablePane.setBounds(rect);
171
172
        rect.setSize(pinFigure.getPreferredSize());
173
        rect.setLocation(headerFigure.getBounds().right()
174
            - rect.getSize().width, headerFigure.getBounds().getCenter().y
175
            - (rect.getSize().height / 2));
176
        pinFigure.setBounds(rect);
177
157
158
    Rectangle r = parent.getClientArea();
159
    List children = parent.getChildren();
160
    IFigure child;
161
162
    Dimension pinSize = isExpanded() ? pinFigure.getPreferredSize()
163
        : EMPTY_DIMENSION;
164
165
    for (int i = 0; i < children.size(); i++) {
166
        child = (IFigure) children.get(i);
167
        if (child == arrowFigure) {
168
            Rectangle.SINGLETON.setBounds(r);
169
            Rectangle.SINGLETON.width = 11;
170
            child.setBounds(Rectangle.SINGLETON);
171
        } else if (child == pinFigure) {
172
            Rectangle.SINGLETON.setSize(pinSize);
173
            Rectangle.SINGLETON.setLocation(r.right() - pinSize.width, r
174
                .getCenter().y
175
                - (pinSize.height / 2));
176
            child.setBounds(Rectangle.SINGLETON);
177
        } else {
178
            child.setBounds(r.getResized(-pinSize.width, 0));
179
        }
178
    }
180
    }
179
180
}
181
}
181
}
182
}
182
183
Lines 193-199 Link Here
193
}
194
}
194
195
195
public void layout(IFigure parent) {
196
public void layout(IFigure parent) {
196
    if (((PinnablePaletteStackFigure) parent).isExpanded()) {
197
    if (isExpanded()) {
197
        headerFigure.setBounds(headerBoundsLayoutHint);
198
        headerFigure.setBounds(headerBoundsLayoutHint);
198
199
199
        Rectangle paneBounds = parent.getClientArea();
200
        Rectangle paneBounds = parent.getClientArea();
Lines 295-300 Link Here
295
    headerFigure.add(arrowFigure);
296
    headerFigure.add(arrowFigure);
296
297
297
    pinFigure = new PinFigure();
298
    pinFigure = new PinFigure();
299
    pinFigure.setBorder(new MarginBorder(0, 0, 0, 2));
298
300
299
    expandablePane = new Figure();
301
    expandablePane = new Figure();
300
302
Lines 336-343 Link Here
336
            .getTopRight().getTranslated(-1, 1));
338
            .getTopRight().getTranslated(-1, 1));
337
        g.drawLine(headerBounds.getBottomLeft().getTranslated(1, 0),
339
        g.drawLine(headerBounds.getBottomLeft().getTranslated(1, 0),
338
            headerBounds.getTopLeft().getTranslated(1, 1));
340
            headerBounds.getTopLeft().getTranslated(1, 1));
339
        g.drawLine(headerBounds.getBottomRight().getTranslated(-1, 0),
341
        g.drawLine(headerBounds.getBottomRight().getTranslated(-2, 0),
340
            headerBounds.getTopRight().getTranslated(-1, 1));
342
            headerBounds.getTopRight().getTranslated(-2, 1));
341
343
342
        g.drawLine(pinAreaBounds.getTopLeft().getTranslated(0, 1),
344
        g.drawLine(pinAreaBounds.getTopLeft().getTranslated(0, 1),
343
            pinAreaBounds.getTopRight().getTranslated(-1, 1));
345
            pinAreaBounds.getTopRight().getTranslated(-1, 1));
Lines 350-359 Link Here
350
        points.addPoint(headerBounds.getTopLeft().getTranslated(0, 2));
352
        points.addPoint(headerBounds.getTopLeft().getTranslated(0, 2));
351
        points.addPoint(headerBounds.getTopLeft().getTranslated(1, 1));
353
        points.addPoint(headerBounds.getTopLeft().getTranslated(1, 1));
352
        points.addPoint(headerBounds.getTopLeft().getTranslated(2, 0));
354
        points.addPoint(headerBounds.getTopLeft().getTranslated(2, 0));
353
        points.addPoint(headerBounds.getTopRight().getTranslated(-2, 0));
355
        points.addPoint(headerBounds.getTopRight().getTranslated(-3, 0));
354
        points.addPoint(headerBounds.getTopRight().getTranslated(-1, 1));
356
        points.addPoint(headerBounds.getTopRight().getTranslated(-2, 1));
355
        points.addPoint(headerBounds.getTopRight().getTranslated(0, 2));
357
        points.addPoint(headerBounds.getTopRight().getTranslated(-1, 2));
356
        points.addPoint(headerBounds.getBottomRight());
358
        points.addPoint(headerBounds.getBottomRight().getTranslated(-1, 0));
357
        points.addPoint(pinAreaBounds.getTopRight().getTranslated(-1, 0));
359
        points.addPoint(pinAreaBounds.getTopRight().getTranslated(-1, 0));
358
        points.addPoint(paneBounds.getBottomRight().getTranslated(-1, -1));
360
        points.addPoint(paneBounds.getBottomRight().getTranslated(-1, -1));
359
        points.addPoint(paneBounds.getBottomLeft().getTranslated(0, -1));
361
        points.addPoint(paneBounds.getBottomLeft().getTranslated(0, -1));
Lines 368-376 Link Here
368
        g.drawPoint(pt.x, pt.y);
370
        g.drawPoint(pt.x, pt.y);
369
        pt = headerBounds.getTopLeft().getTranslated(1, 0);
371
        pt = headerBounds.getTopLeft().getTranslated(1, 0);
370
        g.drawPoint(pt.x, pt.y);
372
        g.drawPoint(pt.x, pt.y);
371
        pt = headerBounds.getTopRight().getTranslated(-1, 0);
373
        pt = headerBounds.getTopRight().getTranslated(-2, 0);
372
        g.drawPoint(pt.x, pt.y);
374
        g.drawPoint(pt.x, pt.y);
373
        pt = headerBounds.getTopRight().getTranslated(0, 1);
375
        pt = headerBounds.getTopRight().getTranslated(-1, 1);
374
        g.drawPoint(pt.x, pt.y);
376
        g.drawPoint(pt.x, pt.y);
375
    } else {
377
    } else {
376
378
Lines 427-432 Link Here
427
    return isExpanded() && pinFigure.getModel().isSelected();
429
    return isExpanded() && pinFigure.getModel().isSelected();
428
}
430
}
429
431
432
/**
433
 * Pins or unpins the stack. The stack can be pinned open only when it is
434
 * expanded. Attempts to pin it when it is collapsed will do nothing.
435
 * 
436
 * @param pinned
437
 *            <code>true</code> if the stack is to be pinned
438
 */
439
public void setPinned(boolean pinned) {
440
    if (isExpanded()) {
441
        pinFigure.setSelected(pinned);
442
    }
443
}
444
430
public void setExpanded(boolean value) {
445
public void setExpanded(boolean value) {
431
    arrowFigure.setSelected(value);
446
    arrowFigure.setSelected(value);
432
    if (!value) {
447
    if (!value) {
Lines 448-478 Link Here
448
    if (newLayoutMode == PaletteViewerPreferences.LAYOUT_LIST
463
    if (newLayoutMode == PaletteViewerPreferences.LAYOUT_LIST
449
        || newLayoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) {
464
        || newLayoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) {
450
465
451
        headerFigure.setLayoutManager(new StackLayout() {
466
        headerFigure.setLayoutManager(new HeaderListLayout());
452
453
            public void layout(IFigure figure) {
454
                Rectangle r = figure.getClientArea();
455
                List children = figure.getChildren();
456
                IFigure child;
457
                for (int i = 0; i < children.size(); i++) {
458
                    child = (IFigure) children.get(i);
459
                    if (child == arrowFigure) {
460
                        Rectangle.SINGLETON.setBounds(r);
461
                        Rectangle.SINGLETON.width = 11;
462
                        child.setBounds(Rectangle.SINGLETON);
463
                    } else {
464
                        child.setBounds(r);
465
                    }
466
                }
467
            }
468
        });
469
467
470
        expandablePane.setLayoutManager(new ToolbarLayout());
468
        expandablePane.setLayoutManager(new ToolbarLayout());
471
        expandablePane.setBorder(new MarginBorder(1, 0, 1, 0));
469
        expandablePane.setBorder(new MarginBorder(1, 0, 1, 0));
472
        setLayoutManager(new PaletteStackListLayout());
470
        setLayoutManager(new ToolbarLayout());
473
471
474
    } else {
472
    } else {
475
476
        headerFigure.setLayoutManager(new BorderLayout());
473
        headerFigure.setLayoutManager(new BorderLayout());
477
        if (activeToolFigure != null) {
474
        if (activeToolFigure != null) {
478
            headerFigure.setConstraint(activeToolFigure, BorderLayout.CENTER);
475
            headerFigure.setConstraint(activeToolFigure, BorderLayout.CENTER);
Lines 482-488 Link Here
482
        setLayoutManager(new PaletteStackIconLayout());
479
        setLayoutManager(new PaletteStackIconLayout());
483
480
484
        // account for space used by pin figure
481
        // account for space used by pin figure
485
        expandablePane.setBorder(new MarginBorder(18, 2, 2, 2));
482
        expandablePane.setBorder(new MarginBorder(18, 0, 0, 0));
486
483
487
        if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) {
484
        if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) {
488
            expandablePane.setLayoutManager(new ColumnsLayout());
485
            expandablePane.setLayoutManager(new ColumnsLayout());
Lines 515-526 Link Here
515
    if (isExpanded()) {
512
    if (isExpanded()) {
516
        if (expandablePane.getParent() != this) {
513
        if (expandablePane.getParent() != this) {
517
            add(expandablePane);
514
            add(expandablePane);
518
            add(pinFigure);
515
            
516
            if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST
517
                || layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) {
518
                headerFigure.add(pinFigure);
519
            } else {
520
                add(pinFigure);
521
            }
519
        }
522
        }
520
    } else {
523
    } else {
521
        if (expandablePane.getParent() == this) {
524
        if (expandablePane.getParent() == this) {
522
            remove(expandablePane);
525
            remove(expandablePane);
523
            remove(pinFigure);
526
            pinFigure.getParent().remove(pinFigure);
524
        }
527
        }
525
    }
528
    }
526
}
529
}
(-)src/org/eclipse/gef/internal/ui/palette/editparts/PinnablePaletteStackEditPart.java (-2 / +19 lines)
Lines 23-28 Link Here
23
import org.eclipse.gef.palette.PaletteStack;
23
import org.eclipse.gef.palette.PaletteStack;
24
import org.eclipse.gef.palette.ToolEntry;
24
import org.eclipse.gef.palette.ToolEntry;
25
import org.eclipse.gef.ui.palette.PaletteViewer;
25
import org.eclipse.gef.ui.palette.PaletteViewer;
26
import org.eclipse.gef.ui.palette.editparts.IPinnableEditPart;
26
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
27
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
27
28
28
/**
29
/**
Lines 35-41 Link Here
35
 */
36
 */
36
public class PinnablePaletteStackEditPart
37
public class PinnablePaletteStackEditPart
37
    extends PaletteEditPart
38
    extends PaletteEditPart
38
    implements IPaletteStackEditPart {
39
    implements IPaletteStackEditPart, IPinnableEditPart {
39
40
40
// listen to see if active tool is changed in the palette
41
// listen to see if active tool is changed in the palette
41
private PaletteListener paletteListener = new PaletteListener() {
42
private PaletteListener paletteListener = new PaletteListener() {
Lines 200-210 Link Here
200
}
201
}
201
202
202
public void openMenu() {
203
public void openMenu() {
203
    getStackFigure().setExpanded(true);
204
    setExpanded(true);
205
}
206
207
public void setExpanded(boolean value) {
208
    getStackFigure().setExpanded(value);
204
}
209
}
205
210
206
public boolean isExpanded() {
211
public boolean isExpanded() {
207
    return getStackFigure().isExpanded();
212
    return getStackFigure().isExpanded();
208
}
213
}
209
214
215
public boolean canBePinned() {
216
    return isExpanded();
217
}
218
219
public boolean isPinnedOpen() {
220
    return getStackFigure().isPinnedOpen();
221
}
222
223
public void setPinnedOpen(boolean pinned) {
224
    getStackFigure().setPinned(pinned);
225
}
226
210
}
227
}
(-)src/org/eclipse/gef/internal/ui/palette/editparts/GroupEditPart.java (+11 lines)
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.gef.internal.ui.palette.editparts;
11
package org.eclipse.gef.internal.ui.palette.editparts;
12
12
13
import org.eclipse.draw2d.Border;
13
import org.eclipse.draw2d.Figure;
14
import org.eclipse.draw2d.Figure;
14
import org.eclipse.draw2d.IFigure;
15
import org.eclipse.draw2d.IFigure;
15
import org.eclipse.draw2d.LayoutManager;
16
import org.eclipse.draw2d.LayoutManager;
17
import org.eclipse.draw2d.MarginBorder;
16
import org.eclipse.draw2d.ToolbarLayout;
18
import org.eclipse.draw2d.ToolbarLayout;
17
19
18
import org.eclipse.gef.internal.ui.palette.PaletteColorUtil;
20
import org.eclipse.gef.internal.ui.palette.PaletteColorUtil;
Lines 24-29 Link Here
24
	extends PaletteEditPart 
26
	extends PaletteEditPart 
25
{
27
{
26
28
29
/** Scrollpane border constant for icon and column layout mode **/
30
private static final Border SCROLL_PANE_BORDER = new MarginBorder(2, 2, 2, 2);
31
32
/** Scrollpane border constant for list and details layout mode **/
33
private static final Border SCROLL_PANE_LIST_BORDER = new MarginBorder(2, 0, 2, 0);
34
27
private int cachedLayout = -1;
35
private int cachedLayout = -1;
28
36
29
public GroupEditPart(PaletteContainer group) {
37
public GroupEditPart(PaletteContainer group) {
Lines 51-63 Link Here
51
	LayoutManager manager;
59
	LayoutManager manager;
52
	if (layout == PaletteViewerPreferences.LAYOUT_COLUMNS) {
60
	if (layout == PaletteViewerPreferences.LAYOUT_COLUMNS) {
53
		manager = new ColumnsLayout();
61
		manager = new ColumnsLayout();
62
        getContentPane().setBorder(SCROLL_PANE_BORDER);		
54
	} else if (layout == PaletteViewerPreferences.LAYOUT_ICONS) {
63
	} else if (layout == PaletteViewerPreferences.LAYOUT_ICONS) {
55
	    PaletteContainerFlowLayout flow = new PaletteContainerFlowLayout();
64
	    PaletteContainerFlowLayout flow = new PaletteContainerFlowLayout();
56
		flow.setMajorSpacing(0);
65
		flow.setMajorSpacing(0);
57
		flow.setMinorSpacing(0);
66
		flow.setMinorSpacing(0);
58
		manager = flow;
67
		manager = flow;
68
        getContentPane().setBorder(SCROLL_PANE_BORDER);
59
	} else {
69
	} else {
60
		manager = new ToolbarLayout();
70
		manager = new ToolbarLayout();
71
        getContentPane().setBorder(SCROLL_PANE_LIST_BORDER);
61
	}
72
	}
62
	getContentPane().setLayoutManager(manager);
73
	getContentPane().setLayoutManager(manager);
63
}
74
}
(-)src/org/eclipse/gef/internal/ui/palette/editparts/ToolEntryEditPart.java (-2 / +19 lines)
Lines 42-47 Link Here
42
import org.eclipse.gef.palette.PaletteStack;
42
import org.eclipse.gef.palette.PaletteStack;
43
import org.eclipse.gef.palette.ToolEntry;
43
import org.eclipse.gef.palette.ToolEntry;
44
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
44
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
45
import org.eclipse.gef.ui.palette.editparts.IPinnableEditPart;
45
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
46
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
46
47
47
public class ToolEntryEditPart
48
public class ToolEntryEditPart
Lines 207-212 Link Here
207
	super(paletteEntry);
208
	super(paletteEntry);
208
}
209
}
209
210
211
public Object getAdapter(Class key) {
212
    if (key == IPinnableEditPart.class) {
213
        if ((getParent() instanceof PinnablePaletteStackEditPart)
214
            && ((PinnablePaletteStackEditPart) getParent()).canBePinned()
215
            && ((PaletteStack) getParent().getModel()).getActiveEntry().equals(
216
                getModel())) {
217
            return getParent();
218
        }
219
    }
220
    return super.getAdapter(key);
221
}
222
210
protected AccessibleEditPart createAccessible() {
223
protected AccessibleEditPart createAccessible() {
211
	return new AccessibleGraphicalEditPart () {
224
	return new AccessibleGraphicalEditPart () {
212
		public void getDescription(AccessibleEvent e) {
225
		public void getDescription(AccessibleEvent e) {
Lines 445-455 Link Here
445
458
446
static Rectangle getSelectionRectangle(int layoutMode, DetailedLabelFigure labelFigure) {
459
static Rectangle getSelectionRectangle(int layoutMode, DetailedLabelFigure labelFigure) {
447
    Rectangle rect = Rectangle.SINGLETON;
460
    Rectangle rect = Rectangle.SINGLETON;
448
    rect.setBounds(labelFigure.getBounds());
461
    rect.setBounds(labelFigure.getClientArea());
449
    if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST
462
    if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST
450
        || layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) {
463
        || layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) {
464
        rect.x -= 5;
465
        rect.y -= 2;
451
        rect.width = labelFigure.getPreferredSize().width + 17;
466
        rect.width = labelFigure.getPreferredSize().width + 17;
452
        rect.x += 11;
467
        rect.height += 4;
468
    } else {
469
        rect.expand(2, 2);        
453
    }
470
    }
454
    rect.intersect(labelFigure.getBounds().getExpanded(-1, -1));
471
    rect.intersect(labelFigure.getBounds().getExpanded(-1, -1));
455
    return rect;
472
    return rect;
(-)src/org/eclipse/gef/internal/ui/palette/editparts/DrawerFigure.java (-3 / +7 lines)
Lines 60-67 Link Here
60
protected static final Color FG_COLOR = FigureUtilities.mixColors(
60
protected static final Color FG_COLOR = FigureUtilities.mixColors(
61
    PaletteColorUtil.WIDGET_NORMAL_SHADOW, PaletteColorUtil.WIDGET_BACKGROUND);
61
    PaletteColorUtil.WIDGET_NORMAL_SHADOW, PaletteColorUtil.WIDGET_BACKGROUND);
62
62
63
/** Scrollpane border constant **/
63
/** Scrollpane border constant for icon and column layout mode **/
64
protected static final Border SCROLL_PANE_BORDER = new MarginBorder(2, 0, 2, 0);
64
protected static final Border SCROLL_PANE_BORDER = new MarginBorder(2, 2, 2, 2);
65
/** Scrollpane border constant for list and details layout mode **/
66
protected static final Border SCROLL_PANE_LIST_BORDER = new MarginBorder(2, 0, 2, 0);
65
/** Title margin border constant **/
67
/** Title margin border constant **/
66
protected static final Border TITLE_MARGIN_BORDER = new MarginBorder(4, 2, 2, 2);
68
protected static final Border TITLE_MARGIN_BORDER = new MarginBorder(4, 2, 2, 2);
67
/** Toggle button border constant**/
69
/** Toggle button border constant**/
Lines 335-341 Link Here
335
	scrollpane.setContents(new Figure());
337
	scrollpane.setContents(new Figure());
336
	scrollpane.getContents().setOpaque(true);
338
	scrollpane.getContents().setOpaque(true);
337
	scrollpane.getContents().setBackgroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND);
339
	scrollpane.getContents().setBackgroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND);
338
	scrollpane.getContents().setBorder(SCROLL_PANE_BORDER);
339
}
340
}
340
341
341
IFigure buildTooltip() {
342
IFigure buildTooltip() {
Lines 465-477 Link Here
465
	LayoutManager manager;
466
	LayoutManager manager;
466
	if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) {
467
	if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) {
467
		manager = new ColumnsLayout();
468
		manager = new ColumnsLayout();
469
        getContentPane().setBorder(SCROLL_PANE_BORDER);
468
	} else if (layoutMode == PaletteViewerPreferences.LAYOUT_ICONS) {
470
	} else if (layoutMode == PaletteViewerPreferences.LAYOUT_ICONS) {
469
	    PaletteContainerFlowLayout fl = new PaletteContainerFlowLayout();
471
	    PaletteContainerFlowLayout fl = new PaletteContainerFlowLayout();
470
		fl.setMinorSpacing(0);
472
		fl.setMinorSpacing(0);
471
		fl.setMajorSpacing(0);
473
		fl.setMajorSpacing(0);
472
		manager = fl;
474
		manager = fl;
475
 	    getContentPane().setBorder(SCROLL_PANE_BORDER);
473
	} else {
476
	} else {
474
		manager = new ToolbarLayout();
477
		manager = new ToolbarLayout();
478
        getContentPane().setBorder(SCROLL_PANE_LIST_BORDER);
475
	}
479
	}
476
	getContentPane().setLayoutManager(manager);
480
	getContentPane().setLayoutManager(manager);
477
}
481
}
(-)src/org/eclipse/gef/internal/ui/palette/editparts/DrawerEditPart.java (-13 / +2 lines)
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.IPinnableEditPart;
38
import org.eclipse.gef.ui.palette.editparts.PaletteAnimator;
39
import org.eclipse.gef.ui.palette.editparts.PaletteAnimator;
39
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
40
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
40
41
Lines 44-50 Link Here
44
 * @author Pratik Shah
45
 * @author Pratik Shah
45
 */
46
 */
46
public class DrawerEditPart 
47
public class DrawerEditPart 
47
	extends PaletteEditPart
48
	extends PaletteEditPart implements IPinnableEditPart
48
{
49
{
49
	
50
	
50
private static final String PROPERTY_EXPANSION_STATE = "expansion"; //$NON-NLS-1$
51
private static final String PROPERTY_EXPANSION_STATE = "expansion"; //$NON-NLS-1$
Lines 128-145 Link Here
128
	return getDrawerFigure().getContentPane();
129
	return getDrawerFigure().getContentPane();
129
}
130
}
130
131
131
/**
132
 * Returns the expansion state of the drawer
133
 * @return <code>true</code> if the drawer is expanded; false otherwise
134
 */
135
public boolean isExpanded() {
132
public boolean isExpanded() {
136
	return getDrawerFigure().isExpanded();
133
	return getDrawerFigure().isExpanded();
137
}
134
}
138
135
139
/**
140
 * Returns <code>true</code> if the drawer is pinned open.
141
 * @return boolean
142
 */
143
public boolean isPinnedOpen() {
136
public boolean isPinnedOpen() {
144
	return getDrawerFigure().isPinnedOpen();
137
	return getDrawerFigure().isPinnedOpen();
145
}
138
}
Lines 264-273 Link Here
264
	getDrawerFigure().setTitleIcon(image);
257
	getDrawerFigure().setTitleIcon(image);
265
}
258
}
266
259
267
/**
268
 * Sets the drawer's pinned state to the specified value.
269
 * @param pinned <code>true</code> if the drawer should be pinned when opened
270
 */
271
public void setPinnedOpen(boolean pinned) {
260
public void setPinnedOpen(boolean pinned) {
272
	getDrawerFigure().setPinned(pinned);
261
	getDrawerFigure().setPinned(pinned);
273
}
262
}
(-)src/org/eclipse/gef/ui/parts/PaletteViewerKeyHandler.java (-19 / +63 lines)
Lines 23-33 Link Here
23
import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart;
23
import org.eclipse.gef.internal.ui.palette.editparts.DrawerEditPart;
24
import org.eclipse.gef.internal.ui.palette.editparts.GroupEditPart;
24
import org.eclipse.gef.internal.ui.palette.editparts.GroupEditPart;
25
import org.eclipse.gef.internal.ui.palette.editparts.IPaletteStackEditPart;
25
import org.eclipse.gef.internal.ui.palette.editparts.IPaletteStackEditPart;
26
import org.eclipse.gef.internal.ui.palette.editparts.PaletteStackEditPart;
27
import org.eclipse.gef.internal.ui.palette.editparts.PinnablePaletteStackEditPart;
26
import org.eclipse.gef.internal.ui.palette.editparts.TemplateEditPart;
28
import org.eclipse.gef.internal.ui.palette.editparts.TemplateEditPart;
27
import org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditPart;
29
import org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditPart;
30
import org.eclipse.gef.palette.PaletteEntry;
28
import org.eclipse.gef.palette.PaletteStack;
31
import org.eclipse.gef.palette.PaletteStack;
29
import org.eclipse.gef.ui.palette.PaletteViewer;
32
import org.eclipse.gef.ui.palette.PaletteViewer;
30
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
31
33
32
/**
34
/**
33
 * KeyHandler for the {@link org.eclipse.gef.ui.palette.PaletteViewer Palette}.
35
 * KeyHandler for the {@link org.eclipse.gef.ui.palette.PaletteViewer Palette}.
Lines 64-72 Link Here
64
	return result && isExpandedDrawer(getFocusEditPart());
66
	return result && isExpandedDrawer(getFocusEditPart());
65
}
67
}
66
68
67
private boolean acceptOpenContextMenu(KeyEvent event) {
69
private boolean acceptExpandStack(KeyEvent event) {
68
	return event.keyCode == SWT.ARROW_DOWN && (event.stateMask & SWT.ALT) > 0
70
	return event.keyCode == SWT.ARROW_DOWN && (event.stateMask & SWT.ALT) > 0
69
			&& isContextMenu(getFocusEditPart());
71
			&& isCollapsedStack(getFocusEditPart());
72
}
73
74
private boolean acceptCollapseStack(KeyEvent event) {
75
    return event.keyCode == SWT.ARROW_UP
76
        && (event.stateMask & SWT.ALT) > 0
77
        && isExpandedStack(getFocusEditPart());
70
}
78
}
71
79
72
private boolean acceptSetFocusOnDrawer(KeyEvent event) {
80
private boolean acceptSetFocusOnDrawer(KeyEvent event) {
Lines 88-99 Link Here
88
		if (isCollapsedDrawer(palettePart)) {
96
		if (isCollapsedDrawer(palettePart)) {
89
			navList.add(palettePart);
97
			navList.add(palettePart);
90
			return;
98
			return;
91
		} else if (stackPart instanceof IPaletteStackEditPart
99
		} else if (stackPart instanceof PaletteStackEditPart
92
				&& stackPart.getChildren().contains(palettePart)) {
100
            && stackPart.getChildren().contains(palettePart)) {
93
			// we only want to add the top level item to the navlist
101
            // we only want to add the top level item to the navlist
94
			if (((PaletteStack)((PaletteEditPart)stackPart).getModel())
102
            if (((PaletteStack) stackPart.getModel()).getActiveEntry().equals(
95
				.getActiveEntry().equals(palettePart.getModel()))
103
                palettePart.getModel()))
96
				navList.add(palettePart);
104
                navList.add(palettePart);
105
        } else if (stackPart instanceof PinnablePaletteStackEditPart
106
            && stackPart.getChildren().contains(palettePart)) {
107
            // we only want to add the top level item to the navlist unless
108
            // the palette stack is expanded
109
            if (((PinnablePaletteStackEditPart) stackPart).isExpanded()
110
                || ((PaletteStack) stackPart.getModel()).getActiveEntry()
111
                    .equals(palettePart.getModel())) {
112
                navList.add(palettePart);
113
            }
97
		} else if ((palettePart instanceof ToolEntryEditPart 
114
		} else if ((palettePart instanceof ToolEntryEditPart 
98
		  || palettePart instanceof DrawerEditPart
115
		  || palettePart instanceof DrawerEditPart
99
		  || palettePart instanceof TemplateEditPart)) {
116
		  || palettePart instanceof TemplateEditPart)) {
Lines 173-183 Link Here
173
}
190
}
174
191
175
/**
192
/**
176
 * Returns <code>true</code> if the passed
193
 * Returns <code>true</code> if the passed focusPart is a collapsed pinnable
177
 * Editpart's parent contains a context menu, false otherwise.
194
 * palette stack, false otherwise.
195
 */
196
boolean isCollapsedStack(EditPart focusPart) {
197
    EditPart parent = focusPart.getParent();
198
    return parent instanceof PaletteStackEditPart
199
        || (parent instanceof PinnablePaletteStackEditPart
200
            && !((PinnablePaletteStackEditPart) parent).isExpanded());
201
}
202
203
/**
204
 * Returns <code>true</code> if the passed focusPart is an expanded pinnable
205
 * palette stack, false otherwise.
178
 */
206
 */
179
boolean isContextMenu(EditPart part) {
207
boolean isExpandedStack(EditPart focusPart) {
180
	return part.getParent() instanceof IPaletteStackEditPart;
208
    EditPart parent = focusPart.getParent();
209
    return parent instanceof PaletteStackEditPart
210
        || (parent instanceof PinnablePaletteStackEditPart
211
            && ((PinnablePaletteStackEditPart) parent).isExpanded());
181
}
212
}
182
213
183
/**
214
/**
Lines 193-203 Link Here
193
	if (acceptCollapseDrawer(event)) {
224
	if (acceptCollapseDrawer(event)) {
194
		collapseDrawer();
225
		collapseDrawer();
195
		return true;
226
		return true;
196
	}
227
	}	
197
	if (acceptOpenContextMenu(event)) {
228
	if (acceptExpandStack(event)) {
198
		openContextMenu();
229
		expandStack();
199
		return true;
230
		return true;
200
	}
231
	}
232
    if (acceptCollapseStack(event)) {
233
        collapseStack(event);
234
        return true;
235
    }
201
	if (acceptIntoExpandedDrawer(event)) {
236
	if (acceptIntoExpandedDrawer(event)) {
202
		if (navigateIntoExpandedDrawer(event))
237
		if (navigateIntoExpandedDrawer(event))
203
			return true;
238
			return true;
Lines 232-239 Link Here
232
protected void navigateTo(EditPart part, KeyEvent event) {
267
protected void navigateTo(EditPart part, KeyEvent event) {
233
	if (part == null)
268
	if (part == null)
234
		return;
269
		return;
235
	getViewer().select(part);
270
	if (part instanceof IPaletteStackEditPart) {
236
	getViewer().reveal(part);
271
        PaletteEntry activeEntry = ((PaletteStack) part.getModel())
272
            .getActiveEntry();
273
        part = (EditPart) getViewer().getEditPartRegistry().get(activeEntry);
274
    }
275
    getViewer().select(part);
276
    getViewer().reveal(part);
237
}
277
}
238
278
239
private boolean navigateToDrawer(KeyEvent event) {
279
private boolean navigateToDrawer(KeyEvent event) {
Lines 272-279 Link Here
272
	return false;
312
	return false;
273
}
313
}
274
314
275
private void openContextMenu() {
315
private void expandStack() {
276
	((IPaletteStackEditPart)getFocusEditPart().getParent()).openMenu();
316
	((IPaletteStackEditPart)getFocusEditPart().getParent()).openMenu();
277
}
317
}
318
private void collapseStack(KeyEvent event) {
319
    ((PinnablePaletteStackEditPart)getFocusEditPart().getParent()).setExpanded(false);
320
    navigateTo(getFocusEditPart().getParent(), event);    
321
}
278
322
279
}
323
}
(-)src/org/eclipse/gef/ui/palette/editparts/IPinnableEditPart.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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
12
package org.eclipse.gef.ui.palette.editparts;
13
14
/**
15
 * This interface is used to identify and work with a pinnable palette editpart
16
 * (e.g. drawers, stacks).
17
 * 
18
 * @author crevells
19
 * @since 3.4
20
 */
21
public interface IPinnableEditPart {
22
23
/**
24
 * Returns <code>true</code> if the palette editpart is pinned open.
25
 * 
26
 * @return boolean
27
 */
28
public boolean isPinnedOpen();
29
30
/**
31
 * @return <code>true</code> if the palette editpart can be pinned open.
32
 */
33
public boolean canBePinned();
34
35
/**
36
 * Sets the palette editpart's pinned state to the specified value.
37
 * 
38
 * @param pinned
39
 *            <code>true</code> if the palette editpart should be pinned when
40
 *            opened
41
 */
42
public void setPinnedOpen(boolean pinned);
43
44
/**
45
 * Returns the expansion state of the palette editpart
46
 * 
47
 * @return <code>true</code> if the palette editpart is expanded; false
48
 *         otherwise
49
 */
50
public boolean isExpanded();
51
52
}

Return to bug 225162