001: package com.xoetrope.editor.eclipse.visualizer;
002:
003: import java.awt.BorderLayout;
004: import java.awt.CardLayout;
005: import java.awt.Frame;
006: import java.awt.Panel;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009:
010: import javax.swing.ButtonGroup;
011: import javax.swing.JPanel;
012: import javax.swing.JToggleButton;
013: import javax.swing.JToolBar;
014:
015: import net.xoetrope.editor.project.XEditorProject;
016: import net.xoetrope.editor.project.workspace.ComponentToolBar;
017: import net.xoetrope.xui.XProjectManager;
018:
019: import org.eclipse.core.resources.IResourceChangeEvent;
020: import org.eclipse.core.resources.IResourceChangeListener;
021: import org.eclipse.core.resources.ResourcesPlugin;
022: import org.eclipse.swt.SWT;
023: import org.eclipse.swt.awt.SWT_AWT;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.ui.part.ViewPart;
026:
027: import com.xoetrope.carousel.visualizer.VisualiserContainer;
028:
029: public class DataVisualiser extends ViewPart implements
030: IResourceChangeListener, ActionListener {
031: private VisualiserContainer designVisualiserContainer;
032: private VisualiserContainer debugVisualiserContainer;
033: private XEditorProject currentProject;
034: private JToggleButton designTimeButton, runTimeButton;
035: private JPanel contentPanel;
036: private CardLayout panelManager;
037: private Composite panelProxy;
038:
039: public DataVisualiser() {
040: super ();
041:
042: currentProject = (XEditorProject) XProjectManager
043: .getCurrentProject();
044: if (currentProject == null)
045: throw new RuntimeException("No active project.");
046:
047: currentProject.setObject("DataVisualiser", this );
048: setTitle("Data Visualiser (" + currentProject.getProjectTitle()
049: + ")");
050:
051: ResourcesPlugin.getWorkspace().addResourceChangeListener(this );
052: }
053:
054: public void createPartControl(Composite parent) {
055: JToolBar toolbar = new ComponentToolBar();
056:
057: // selection button
058: ButtonGroup bg = new ButtonGroup();
059: designTimeButton = new JToggleButton("Design time");
060: designTimeButton.setActionCommand("Design");
061: designTimeButton.addActionListener(this );
062: designTimeButton
063: .setToolTipText("Design time view of the data model");
064: designTimeButton.setSelected(true);
065: bg.add(designTimeButton);
066:
067: runTimeButton = new JToggleButton("Run time");
068: runTimeButton.setActionCommand("Runtime");
069: runTimeButton.addActionListener(this );
070: runTimeButton
071: .setToolTipText("Run-time/Debug view of the data model");
072: runTimeButton.setSelected(false);
073: bg.add(runTimeButton);
074:
075: toolbar.add(designTimeButton);
076: toolbar.add(runTimeButton);
077:
078: debugVisualiserContainer = new VisualiserContainer(
079: new EclipseDebuggerEngine());
080: debugVisualiserContainer.setVisible(true);
081:
082: designVisualiserContainer = new VisualiserContainer(null);
083: designVisualiserContainer.setVisible(true);
084:
085: contentPanel = new JPanel();
086: panelManager = new CardLayout();
087: contentPanel.setLayout(panelManager);
088:
089: contentPanel.add(designVisualiserContainer, "Design time");
090: contentPanel.add(debugVisualiserContainer, "Run time");
091:
092: Panel mainPanel = new Panel();
093: mainPanel.setLayout(new BorderLayout());
094: mainPanel.add(toolbar, BorderLayout.NORTH);
095: mainPanel.add(contentPanel, BorderLayout.CENTER);
096:
097: panelProxy = new Composite(parent, SWT.EMBEDDED);
098: Frame awtFrame = SWT_AWT.new_Frame(panelProxy);
099: awtFrame.add(mainPanel);
100:
101: setComponentListeners();
102: }
103:
104: public void actionPerformed(ActionEvent e) {
105: Object o = e.getSource();
106: String page = (o == designTimeButton ? "Design time"
107: : "Run time");
108: if (page != null)
109: panelManager.show(contentPanel, page);
110: }
111:
112: public void setFocus() {
113: panelProxy.setFocus();
114: }
115:
116: private void setComponentListeners() {
117: //TODO: setup the listeners
118: }
119:
120: public void resourceChanged(IResourceChangeEvent event) {
121: //TODO: not sure whether to call this here
122: // visualiserContainer.refresh();
123: }
124:
125: }
|