Astah Plug-in can add an extra view in Astah. For example, you can make a view to show a list of class summary or whatever you would like to show on Astah. So in this page, let’s create a Plug-in to add an extended view to Astah. And let’s make it show just a “hello world” text on there as an easy example.
To add an extended view, use IPluginExtraTabView interface. Below is a sample of the HelloWoroldView which implements the IPluginExtraTabView.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | /*
* Please change this class's package to your genearated Plug-in's package.
* Plug-in's package namespace => com.example
* com.change_vision.astah.extension.plugin => X
* com.example => O
* com.example.internal => O
* learning => X
*/
package com.example.internal;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import com.change_vision.jude.api.inf.project.ProjectAccessor;
import com.change_vision.jude.api.inf.project.ProjectAccessorFactory;
import com.change_vision.jude.api.inf.project.ProjectEvent;
import com.change_vision.jude.api.inf.project.ProjectEventListener;
import com.change_vision.jude.api.inf.ui.IPluginExtraTabView;
import com.change_vision.jude.api.inf.ui.ISelectionListener;
public class HelloWorldView extends JPanel implements IPluginExtraTabView, ProjectEventListener {
public HelloWorldView() {
initComponents();
}
private void initComponents() {
setLayout(new BorderLayout());
add(createLabelPane(), BorderLayout.CENTER);
addProjectEventListener();
}
private void addProjectEventListener() {
try {
ProjectAccessor projectAccessor = ProjectAccessorFactory.getProjectAccessor();
projectAccessor.addProjectEventListener(this);
} catch (ClassNotFoundException e) {
e.getMessage();
}
}
private Container createLabelPane() {
JLabel label = new JLabel("hello world");
JScrollPane pane = new JScrollPane(label);
return pane;
}
@Override
public void projectChanged(ProjectEvent e) {
}
@Override
public void projectClosed(ProjectEvent e) {
}
@Override
public void projectOpened(ProjectEvent e) {
}
@Override
public void addSelectionListener(ISelectionListener listener) {
}
@Override
public Component getComponent() {
return this;
}
@Override
public String getDescription() {
return "Show Hello World here";
}
@Override
public String getTitle() {
return "Hello World View";
}
public void activated() {
}
public void deactivated() {
}
}
|
The getComponent() tells Astah what to show on the extended tab view such as a table. In our sample, the instance of a JPanel with a JLabel is returned to Astah by the getComponent(). And the label on the extended tab should be defined in the getTitle().
A class implementing ProjectEventListener interface is an observer which keeps watching the models on current Astah. And the projectChanged() method will be called when there was a change in models such as adding/deleting of classes.
Next, let’s write the plugin.xml to add the extended view to Astah.
1 2 3 4 5 6 7 8 9 | <?xml version="1.0" encoding="UTF-8"?>
<plugin>
<extension point="com.change_vision.astah.ui.view">
<view
id="com.example.internal.HelloWorldView"
type="extraTab"
class="com.example.internal.HelloWorldView" />
</extension>
</plugin>
|
| Tag name | Attribute | Required | Description |
|---|---|---|---|
| extension | o | Specify extension point | |
| point | o | Specify com.change_vision.astah.ui.view | |
| view | o | Specify view configuration | |
| id | o | View’s ID | |
| type | o | Specify the location of the view | |
| extraTab if you put the view on ExtraView | |||
| class | o | Specify implementation of the class |
Now an extended view has been added to Astah.