use of eu.esdihumboldt.hale.ui.util.ViewContextMenu in project hale by halestudio.
the class StyledMapView method createPartControl.
/**
* @see MapView#createPartControl(Composite)
*/
@Override
public void createPartControl(Composite parent) {
HaleUI.registerWorkbenchUndoRedo(getViewSite());
super.createPartControl(parent);
Control mainControl = null;
// try to get the Swing embedding composite
Control[] children = parent.getChildren();
if (children != null && children.length > 0) {
for (Control child : children) {
// find based on class name (class from CityServer3D)
if (child.getClass().getSimpleName().equals("SwingComposite")) {
mainControl = child;
break;
}
}
if (mainControl == null) {
if (children.length >= 2) {
// Eclipse 4 - the first composite is the toolbar
mainControl = children[0];
} else {
mainControl = children[0];
}
}
} else {
mainControl = parent;
}
new ViewContextMenu(getSite(), getSite().getSelectionProvider(), mainControl) {
@Override
public void menuAboutToShow(IMenuManager manager) {
ISelection sel = getSite().getSelectionProvider().getSelection();
// show summary about selected instances
if (sel != null && !sel.isEmpty() && sel instanceof InstanceSelection) {
List<Object> source = new ArrayList<Object>();
List<Object> transformed = new ArrayList<Object>();
for (Object object : ((InstanceSelection) sel).toArray()) {
DataSet ds = null;
if (object instanceof Instance) {
ds = ((Instance) object).getDataSet();
}
if (object instanceof InstanceReference) {
ds = ((InstanceReference) object).getDataSet();
}
if (ds != null) {
switch(ds) {
case SOURCE:
source.add(object);
break;
case TRANSFORMED:
transformed.add(object);
break;
}
}
}
if (!source.isEmpty() || !transformed.isEmpty()) {
Action noAction = new Action("Selection:") {
};
noAction.setEnabled(false);
manager.add(noAction);
}
if (!source.isEmpty()) {
Action selectAction = new SelectInstancesAction(source, DataSet.SOURCE);
selectAction.setEnabled(!transformed.isEmpty());
manager.add(selectAction);
}
if (!transformed.isEmpty()) {
Action selectAction = new SelectInstancesAction(transformed, DataSet.TRANSFORMED);
selectAction.setEnabled(!source.isEmpty());
manager.add(selectAction);
}
}
super.menuAboutToShow(manager);
}
};
final Menu swtMenu = mainControl.getMenu();
getMapKit().getMainMap().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
mouseReleased(e);
}
@Override
public void mouseReleased(final MouseEvent e) {
if (e.isPopupTrigger()) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (Platform.WS_GTK.equals(Platform.getWS())) {
/*
* Work-around (or rather hack) for Eclipse Bug
* 233450
*/
GTKAWTBridgePopupFix.showMenu(swtMenu);
} else {
swtMenu.setLocation(e.getXOnScreen(), e.getYOnScreen());
swtMenu.setVisible(true);
}
}
});
}
}
});
}
Aggregations