use of eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityServiceListener in project hale by halestudio.
the class CompatibilityModeComposite method createControl.
/**
* @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createControl(Composite parent) {
parent.getParent().setRedraw(true);
// initiate the composite for the compatibility elements
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new RowLayout(SWT.HORIZONTAL));
// label for displaying the status of the mode
final Label statusLabel = new Label(comp, SWT.NONE);
statusLabel.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_SIGNED_YES));
// label for displaying the mode itself
final Label modeLabel = new Label(comp, SWT.NONE);
// Menu for mode selection on left click
IContributionItem popupMenu = new CompatibilityMenu();
final MenuManager mmanager = new MenuManager();
mmanager.add(popupMenu);
modeLabel.setMenu(mmanager.createContextMenu(modeLabel));
modeLabel.addMouseListener(new MouseListener() {
@Override
public void mouseDoubleClick(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDown(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseUp(MouseEvent e) {
modeLabel.getMenu().setVisible(true);
}
});
// listener to update the mode label
modeListener = new ExclusiveExtensionListener<CompatibilityMode, CompatibilityModeFactory>() {
@Override
public void currentObjectChanged(final CompatibilityMode arg0, final CompatibilityModeFactory arg1) {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
modeLabel.setText(cs.getCurrentDefinition().getDisplayName());
}
});
}
};
cs.addListener(modeListener);
// listener for updating the mode status label
compListener = new CompatibilityServiceListener() {
@Override
public void compatibilityChanged(final boolean isCompatible, List<Cell> incompatibleCells) {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (isCompatible) {
statusLabel.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_SIGNED_YES));
statusLabel.setToolTipText("No incompatibility detected!");
}
if (!isCompatible) {
statusLabel.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_SIGNED_NO));
statusLabel.setToolTipText("Incompatibility detected!");
}
}
});
}
};
cs.addCompatibilityListener(compListener);
modeLabel.setText(cs.getCurrentDefinition().getDisplayName());
statusLabel.setToolTipText("No incompatibility detected!");
return comp;
}
Aggregations