Search in sources :

Example 1 with IOWizardAction

use of eu.esdihumboldt.hale.ui.io.action.IOWizardAction in project hale by halestudio.

the class ClassificationMappingParameterPage method createFromFileTabControl.

private Control createFromFileTabControl(Composite tabParent) {
    // Parent composite for fromFileTab
    Composite item2Content = new Composite(tabParent, SWT.NONE);
    item2Content.setLayout(new GridLayout());
    // Label to descripe what the user should do
    Label l = new Label(item2Content, SWT.NONE);
    l.setText("Select the project lookup table resource you want to use for the classification:");
    // Get the Lookuptable Service
    final LookupService lookupService = HaleUI.getServiceProvider().getService(LookupService.class);
    // Composite for comboViewerComposite and Button
    Composite parent = new Composite(item2Content, SWT.NONE);
    parent.setLayout(new GridLayout(2, false));
    parent.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    // Description Label
    description = new Label(item2Content, SWT.WRAP);
    description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    description.setText("");
    description.setVisible(false);
    // label with warning message
    Composite warnComp = new Composite(item2Content, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(warnComp);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(warnComp);
    Label warnImage = new Label(warnComp, SWT.NONE);
    warnImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(warnImage);
    Label warn = new Label(warnComp, SWT.WRAP);
    warn.setText("Classifications from a file resource will not function in another project where the alignment with the classification is imported or used as a base alignment.\n" + "If unsure, use the 'Explicit' mode instead and use the option to load the classification from a file.");
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint(300, SWT.DEFAULT).applyTo(warn);
    // Composite for ComboViewer
    Composite viewerComposite = new Composite(parent, SWT.NONE);
    viewerComposite.setLayout(new FillLayout());
    GridData layoutData = new GridData(SWT.FILL, SWT.NONE, true, false);
    viewerComposite.setLayoutData(GridDataFactory.copyData(layoutData));
    // ComboViewer
    lookupTableComboViewer = new ComboViewer(viewerComposite, SWT.READ_ONLY);
    lookupTableComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    lookupTableComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                return lookupService.getTable((String) element).getName();
            }
            return null;
        }
    });
    lookupTableComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // Show the description for the selected lookupTable
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            String desc = lookupService.getTable(selection.getFirstElement().toString()).getDescription();
            if (desc != null) {
                description.setText("Description: " + desc);
            } else {
                description.setText("");
            }
            if (!description.isVisible()) {
                description.setVisible(true);
            }
        }
    });
    lookupTableComboViewer.setInput(lookupService.getTableIDs());
    if (selectedLookupTableID != null) {
        lookupTableComboViewer.setSelection(new StructuredSelection(selectedLookupTableID), true);
    }
    // Button to load a lookupTable if no one is loaded
    final Button browseButton = new Button(parent, SWT.PUSH);
    browseButton.setText("Add...");
    browseButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IOWizardAction action = new IOWizardAction("eu.esdihumboldt.hale.lookup.import");
            action.run();
            action.dispose();
            // Refresh the viewer
            lookupTableComboViewer.setInput(lookupService.getTableIDs());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing to do here
        }
    });
    return item2Content;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) LookupService(eu.esdihumboldt.hale.common.lookup.LookupService) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) IOWizardAction(eu.esdihumboldt.hale.ui.io.action.IOWizardAction) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with IOWizardAction

use of eu.esdihumboldt.hale.ui.io.action.IOWizardAction in project hale by halestudio.

the class ImportAction method run.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
@Override
public void run() {
    if (Display.getCurrent() == null) {
        // execute in display thread
        PlatformUI.getWorkbench().getDisplay().asyncExec(this);
        return;
    }
    if (actionId == null)
        return;
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
    IOWizardAction action = new IOWizardAction(actionId);
    if (action.isEnabled()) {
        action.addPropertyChangeListener(new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (IAction.RESULT.equals(event.getProperty()))
                    notifyResult((Boolean) event.getNewValue());
            }
        });
        action.run();
    } else {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Action disabled", action.getFactory().getDisabledReason());
        notifyResult(false);
    }
    action.dispose();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IOWizardAction(eu.esdihumboldt.hale.ui.io.action.IOWizardAction)

Aggregations

IOWizardAction (eu.esdihumboldt.hale.ui.io.action.IOWizardAction)2 LookupService (eu.esdihumboldt.hale.common.lookup.LookupService)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)1 StyledString (org.eclipse.jface.viewers.StyledString)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1