TabbedPane [message #236162] |
Sun, 24 June 2007 07:16  |
Eclipse User |
|
|
|
Originally posted by: alexjaquet.gmail.com
Hi,
I need to create a tabbed pane figure who could contain other figures.
Wich steps I've to follow.
Thanks for any hints.
Regards,
Alexandre
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: TabbedPane [message #238010 is a reply to message #236342] |
Fri, 17 August 2007 12:41   |
Eclipse User |
|
|
|
Hi Alexandre,
I did it in GEF. I do following:
In the figure:
public class TabPaneFigure extends Figure {
private Figure canvas;
private Figure tabs;
public TabPaneFigure() {
setLayoutManager(new BorderLayout());
this.canvas = new Figure();
this.canvas.setLayoutManager(new StackLayout());
this.tabs = new Figure();
this.tabs.setBackgroundColor(BG_COLOR);
this.tabs.setOpaque(true);
ToolbarLayout layout = new ToolbarLayout(true);
layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
this.tabs.setLayoutManager(layout);
add(this.canvas,BorderLayout.CENTER);
add(this.tabs,BorderLayout.TOP);
}
public IFigure getCanvas() {
return this.canvas;
}
public IFigure getTabs() {
return this.tabs;
}
}
And in the EditPart I do following:
public class TabPaneEditPart extends EditPart {
private HashMap<IFigure, TabButton> buttonMap =
new HashMap<IFigure, TabButton>();
protected IFigure createFigure() {
return FigureFactory.createTabPaneFigure();
}
protected void addChildVisual(EditPart childEditPart, int index) {
IFigure child = ((GraphicalEditPart) childEditPart).getFigure();
Object constraint = BorderLayout.CENTER;
TabPaneFigure figure = getLayout();
figure.getCanvas().add(child, constraint, index);
TabButton b = new TabButton((TabFigure) child, childEditPart);
figure.getTabs().add(b, constraint, index);
this.buttonMap.put(child, b);
hideChilds();
activateChilds(childEditPart);
child.setVisible(true);
childEditPart.refresh();
}
protected TabPaneFigure getLayout() {
return (TabPaneFigure) getContentPane();
}
protected void hideChilds() {
List<IFigure> childs = getLayout().getCanvas().getChildren();
for (int i = 0; i < childs.size(); i++) {
childs.get(i).setVisible(false);
}
List<EditPart> eps = getChildren();
for (int i = 0; i < eps.size(); i++) {
deactivateChilds(eps.get(i));
eps.get(i).setFocus(false);
}
}
protected void removeChildVisual(EditPart childEditPart) {
IFigure child = ((GraphicalEditPart) childEditPart).getFigure();
TabPaneFigure figure = getLayout();
figure.getCanvas().remove(child);
deactivateChilds(childEditPart);
TabButton b = this.buttonMap.get(child);
figure.getTabs().remove(b);
this.buttonMap.remove(child);
}
protected void refreshVisuals() {
refreshTabs();
super.refreshVisuals();
}
public void refreshTabs() {
Set<Entry<IFigure, TabButton>> entries = this.buttonMap.entrySet();
for (Entry<IFigure, TabButton> entry : entries) {
TabButton button = entry.getValue();
TabFigure f = (TabFiguree)entry.getKey();
String message = ... put your button text from your model
button.setText(message);
}
}
public class TabButton extends Button implements ActionListener {
private TabFigure pane;
private EditPart childEditPart;
private Label tabLabel;
public TabButton(TabFigure pane, EditPart childEditPart) {
this.pane = pane;
this.childEditPart = childEditPart;
TabModel paneModel = pane.getModel();
String message = paneModel.getMessage();
this.tabLabel = new Label(message);
setContents(this.tabLabel);
addActionListener(this);
setBorder(selectedBorder);
setBackgroundColor(BG_COLOR);
setForegroundColor(ColorConstants.black);
enableOtherButtons();
}
public void actionPerformed(ActionEvent event) {
hideChilds();
showEp();
this.pane.setVisible(true);
enableOtherButtons();
setBackgroundColor(BG_COLOR);
setForegroundColor(ColorConstants.black);
setBorder(selectedBorder);
getLayout().repaint();
}
@SuppressWarnings("unchecked")
protected void showEp() {
activateChilds(this.childEditPart);
}
public void update() {
String message = pane.getModel().getMessage();
this.tabLabel.setText(message);
}
public void setText(String text) {
this.tabLabel.setText(text);
}
}
protected void enableOtherButtons() {
TabPaneFigure figure = (TabPaneFigure) getContentPane();
List<IFigure> tabs = figure.getTabs().getChildren();
for (IFigure tab : tabs) {
TabButton button = (TabButton) tab;
button.setEnabled(true);
button.setBackgroundColor(BG_COLOR_OFF);
button.validate();
button.setBorder(deselectedBorder);
button.update();
}
}
protected void activateChilds(EditPart parent) {
List<EditPart> childs = parent.getChildren();
for (int i = 0; i < childs.size(); i++) {
childs.get(i).activate();
}
}
protected void deactivateChilds(EditPart parent) {
List<EditPart> childs = parent.getChildren();
for (int i = 0; i < childs.size(); i++) {
childs.get(i).deactivate();
}
}
public List getModelChildren() {
return ((TabPane)getModel()).getTabs();
}
}
The TabFigure is just any IFigure, e.g. another container which contains
labels and textfields.
The trick is to use the method addChildVisual(EditPart childEditPart, int
index); and removeChildVisual(EditPart part); in the EditPart of the
container which handles the tab buttons.
In my version the tabs are on the top border of the figure. You could also
draw the tabs somewhere else if you use a different layout manager in the
TabPaneFigure class.
What I do not like is that I did not find out yet how to directly edit the
tab texts. Each other Label figure you can enable to direct edit but not
the Button figure (or I do not know how to do it, maybe).
Also what I did not find out is how to add a menu to the tab buttons.
I hope you can use my example. If you have improvements please let me know.
With regards,
Udo
Am Tue, 26 Jun 2007 12:55:58 +0200 schrieb Alexandre Jaquet:
> Johan Piculell a écrit :
>> Alexandre Jaquet wrote:
>>
>>> Johan Piculell a écrit :
>>>> Sure it is, where did you read this?
>>>>
>>>> SWT - the widget set used everywhere in Eclipse
>>>> GEF - Graphic framework, consists of GEF and draw2d plugins, where
>>>> draw2d makes use of SWT.
>>
>>> I add the problem yesterday, I do
>>
>>> public IFigure createFigure() {
>>> Shell shell = new Shell(Display.getCurrent());
>>> final TabFolder tabFolder = new TabFolder (shell,
>>> SWT.BORDER);
>>> LightweightSystem lws = new LightweightSystem(shell);
>>> for (int i=0; i<6; i++) {
>>> TabItem item = new TabItem (tabFolder, SWT.NULL);
>>> item.setText ("TabItem " + i);
>>> }
>>> MyTabFolder result = new MyTabFolder();
>>> result.setFolder(tabFolder);
>>> ResizableCompartmentFigure figure =
>>> (ResizableCompartmentFigure) super
>>> .createFigure();
>>> figure.setTitleVisibility(false);
>>> lws.setContents(result);
>>> figure.add(result);
>>> return figure;
>>> }
>>
>>> But nothing is displayed
>>
>> I find it hard to follow your examples now, where is this createFigure
>> method located (in what class)? Have you tried to just return a new
>> draw2d Figure to see that everything else works?
>> What exactly do you want to achieve, do you want a plain window
>> displaying your tabbed view or are you trying to create a new edit part
>> to use in the Eclipse workbench?
>>
>> regards
>> /Johan
>>
>> I'm trying to create an editpart who contain a tabbe pane. this is way
> it's not possible because we need an IFigure.
|
|
|
|
Re: TabbedPane [message #240189 is a reply to message #238010] |
Thu, 06 December 2007 01:45  |
Eclipse User |
|
|
|
Originally posted by: elfish.126.com
Thank you for your code.
But I can't let it work for me.
Some methods couldn't be found in the classes 'TabPaneEditPart' and 'TabButton'.
|
|
|