Search in sources :

Example 1 with CompatibilityServiceListener

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;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) CompatibilityModeFactory(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityModeFactory) CompatibilityMode(eu.esdihumboldt.hale.common.align.compatibility.CompatibilityMode) IContributionItem(org.eclipse.jface.action.IContributionItem) Label(org.eclipse.swt.widgets.Label) CompatibilityServiceListener(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityServiceListener) MouseListener(org.eclipse.swt.events.MouseListener) RowLayout(org.eclipse.swt.layout.RowLayout) MenuManager(org.eclipse.jface.action.MenuManager) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

CompatibilityMode (eu.esdihumboldt.hale.common.align.compatibility.CompatibilityMode)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 CompatibilityModeFactory (eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityModeFactory)1 CompatibilityServiceListener (eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityServiceListener)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 MenuManager (org.eclipse.jface.action.MenuManager)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1