1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2000, 2010 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 org.eclipse.draw2d.Border;
|
14
|
import org.eclipse.draw2d.Figure;
|
15
|
import org.eclipse.draw2d.IFigure;
|
16
|
import org.eclipse.draw2d.LayoutManager;
|
17
|
import org.eclipse.draw2d.MarginBorder;
|
18
|
import org.eclipse.draw2d.ToolbarLayout;
|
19
|
|
20
|
import org.eclipse.gef.internal.ui.palette.PaletteColorUtil;
|
21
|
import org.eclipse.gef.palette.PaletteContainer;
|
22
|
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
|
23
|
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
|
24
|
|
25
|
public class GroupEditPart extends PaletteEditPart {
|
26
|
|
27
|
/** Scrollpane border constant for icon and column layout mode **/
|
28
|
private static final Border SCROLL_PANE_BORDER = new MarginBorder(2, 2, 2,
|
29
|
2);
|
30
|
|
31
|
/** Scrollpane border constant for list and details layout mode **/
|
32
|
private static final Border SCROLL_PANE_LIST_BORDER = new MarginBorder(2,
|
33
|
0, 2, 0);
|
34
|
|
35
|
private int cachedLayout = -1;
|
36
|
|
37
|
public GroupEditPart(PaletteContainer group) {
|
38
|
super(group);
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
|
43
|
*/
|
44
|
public IFigure createFigure() {
|
45
|
Figure figure = new Figure();
|
46
|
figure.setOpaque(true);
|
47
|
figure.setBackgroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND);
|
48
|
return figure;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals()
|
53
|
*/
|
54
|
protected void refreshVisuals() {
|
55
|
int layout = getLayoutSetting();
|
56
|
if (cachedLayout == layout)
|
57
|
return;
|
58
|
cachedLayout = layout;
|
59
|
LayoutManager manager;
|
60
|
if (layout == PaletteViewerPreferences.LAYOUT_COLUMNS) {
|
61
|
manager = new ColumnsLayout();
|
62
|
getContentPane().setBorder(SCROLL_PANE_BORDER);
|
63
|
} else if (layout == PaletteViewerPreferences.LAYOUT_ICONS) {
|
64
|
PaletteContainerFlowLayout flow = new PaletteContainerFlowLayout();
|
65
|
flow.setMajorSpacing(0);
|
66
|
flow.setMinorSpacing(0);
|
67
|
manager = flow;
|
68
|
getContentPane().setBorder(SCROLL_PANE_BORDER);
|
69
|
} else {
|
70
|
manager = new ToolbarLayout();
|
71
|
getContentPane().setBorder(SCROLL_PANE_LIST_BORDER);
|
72
|
}
|
73
|
getContentPane().setLayoutManager(manager);
|
74
|
}
|
75
|
|
76
|
}
|