This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Views
jpeterka edited this page Apr 18, 2013
·
9 revisions
When implementing views, one should not think of trees, buttons and text fields, but more of objects represented by those widgets. E.g. Package Explorer does not contain tree with tree items, but projects with files.
You could use these steps when creating a new view:
- identify all important objects on the view, e. g. projects and items in projects (these might not be just files but also classpath containers)
- identify operations on the view
- assign operations to view and objects
- view typically contains operations available if no object is selected
- object typically contains operations available when selected.
- usually it is not necessary to have a public select method on an object or view, it should be private and called during every operation
Example: The servers view contains only methods for creating a new server (the operation invokes NewServerWizardDialog that is returned by newServer() method) and for retrieving server instances. Other operations are on Server class.
public class ServersView extends View {
public static final String TITLE = "Servers";
public ServersView() {
super(TITLE);
}
public NewServerWizardDialog newServer(){
// implementation
return new NewServerWizardDialog();
}
public List getServers(){
// implementation
return null;
}
public Server getServer(String name){
// implementation
return null;
}
}
Note that Server instance takes the TreeItem in its constructor so that it can invoke operations on it - but this low level implementation is hidden in method's API.
public class Server {
private TreeItem treeItem;
public Server(TreeItem treeItem) {
this.treeItem = treeItem;
}
public void start() {
// implementation
}
public void stop() {
// implementation
}
}