1 企业应用支持
@Override
public
void performRequest(Request request)
{
if (request.getType() == RequestConstants.
REQ_OPEN)
{
//获得所点击的模型信息
ShipModel shipModel=(ShipModel)getModel();
ShipInfo shipInfo=shipModel.getShipInfo();
ShipInfoDialog sid=
new ShipInfoDialog(BerthUtil.
getInstances().
getShell());
sid.setShipInfo(shipInfo);
sid.open();
}
}
|
protected
void configureGraphicalViewer() {
……
ContextMenuProvider provider =
new BerthContextMenuProvider(
this,viewer, getActionRegistry());
viewer.setContextMenu(provider);
getSite().registerContextMenu("org.jport.gef.editor.contextmenu",provider, viewer);
……
}
|
@SuppressWarnings("unchecked")
public
void
createActions() {
super.createActions();
ActionRegistry registry = getActionRegistry();
IAction action =
new RefreshAction(
this);
registry.registerAction(action);
getSelectionActions().add(action.getId());
}
|
public
void buildContextMenu(IMenuManager menu) {
// Add standard action groups to the menu
GEFActionConstants.addStandardActionGroups(menu);
if (part
instanceof BerthGraphicalEditor) {
EditPart focusEditPart = getViewer().getFocusEditPart();
//判断不同的模型,为不同的模型添加不同的menu
if (focusEditPart
instanceof ShipPart) {
addShipModelPopuMenu(menu);
}
}
}
private
void
addShipModelPopuMenu(IMenuManager menu) {
//you can new an action here,but is inefficient,for everytime you click right click will create an new class
menu.add(getAction("moveUp"));
}
|
//
TODO Auto-generated method stub
try {
// invoke save service
ShipInfo shipInfo=shipModel.getShipInfo();
shipInfo.setShipName(shipNameT.getText());
shipModel.setShipInfo(shipInfo);
MessageDialogInfo.openInformation("提示信息", "位信息保存成功!");
}
catch (
Exception e) {
MessageDialogInfo.openError("错误提示", "保存位信息出错,请重试");
}
}
|
public
void setShipInfo(ShipInfo shipInfo) {
this.shipInfo = shipInfo;
getListeners().firePropertyChange(
PROPERTY_UPDATEMODEL,
null, shipInfo);
}
|
public
void propertyChange(PropertyChangeEvent evt) {
……
if (evt.getPropertyName().equals(ShipModel.
PROPERTY_UPDATEMODEL))
refreshVisuals();
}
protected
void
refreshVisuals(){
ShipFigure figure = (ShipFigure)getFigure();
ShipModel model = (ShipModel)getModel();
figure.setShipName(model.getShipInfo().getShipName());
figure.setLayout(model.getLayout());
}
|
@Override
public
void run() {
super.run();
ShipPart shipPart = (ShipPart) getSelectedObjects().get(0);
DiagramModel parent=(DiagramModel)shipPart.getParent().getModel();
ShipModel shipModel=(ShipModel)shipPart.getModel();
//just for fun
shipModel.setBgType(shipModel.getBgType()+1);
parent.removeChild(shipModel);
parent.addChild(shipModel);
}
|
public
class Navigate
extends ViewPart {
……
public
void createPartControl(Composite parent) {
……
viewer.addDoubleClickListener(
new TreeDoubleClick(viewer));
}
|
package org.jport.gef.berth.action;
public
class
TreeDoubleClick
implements IDoubleClickListener {
……
public
void doubleClick(DoubleClickEvent event)
{
IStructuredSelection selection = (IStructuredSelection) tv.getSelection();
String companyName = (String) (selection.getFirstElement());
try
{
//
//input 自动根据输入的不同来判断该Editor是否打开
input=
new BerthEditorInput(companyName);
window.getActivePage().openEditor(input, BerthGraphicalEditor.
ID);
}
catch (WorkbenchException e) {
//
TODO Auto-generated catch block
}
}
}
|
@Override
public
boolean exists() {
return (
this.name !=
null);
}
public
boolean equals(Object o) {
if (!(o
instanceof BerthEditorInput))
return
false;
return ((BerthEditorInput)o).getName().equals(getName());
}
|