Search in sources :

Example 11 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmDevicePeripheralsView method createPartControl.

// /**
// * Provides the editor for the tree elements
// *
// * Does minor modifications to the default editor.
// */
// private class PeripheralsViewTextCellEditor extends TextCellEditor {
// 
// private int minHeight;
// 
// public PeripheralsViewTextCellEditor(Tree tree) {
// super(tree, SWT.BORDER);
// Text txt = (Text) getControl();
// 
// Font fnt = txt.getFont();
// FontData[] fontData = fnt.getFontData();
// if (fontData != null && fontData.length > 0) {
// minHeight = fontData[0].getHeight() + 10;
// }
// }
// 
// public LayoutData getLayoutData() {
// LayoutData data = super.getLayoutData();
// if (minHeight > 0)
// data.minimumHeight = minHeight;
// return data;
// }
// }
/**
 * Callback that creates the viewer and initialises it.
 *
 * The View consists of a tree and a information panel
 */
public void createPartControl(Composite parent) {
    // Create the manager and bind to main composite
    resManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    parent.setLayoutData(new FillLayout());
    SashForm form = new SashForm(parent, SWT.VERTICAL);
    form.setLayout(new FillLayout());
    // Make sash visible
    form.setSashWidth(4);
    form.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    // =============================
    fPeripheralsTreeViewer = new CheckboxTreeViewer(form, SWT.MULTI | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Tree tree = fPeripheralsTreeViewer.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    ColumnViewerToolTipSupport.enableFor(fPeripheralsTreeViewer);
    // // Suppress tree expansion on double-click
    // // see http://www.eclipse.org/forums/index.php/t/257325/
    // peripheralsTreeViewer.getControl().addListener(SWT.MeasureItem, new Listener(){
    // @Override
    // public void handleEvent(Event event) {
    // }});
    fPeripheralsTreeViewer.setColumnProperties(fTreeProperties);
    fPeripheralsTreeViewer.setCellEditors(new CellEditor[] { null, new TextCellEditor(fPeripheralsTreeViewer.getTree()), null });
    // peripheralsTreeViewer.setCellEditors(new CellEditor[] { null, new PeripheralsViewTextCellEditor(peripheralsTreeViewer.getTree()), null });
    fPeripheralsTreeViewer.setCellModifier(new PeripheralsViewCellModifier(this));
    /*
       * Name column
       */
    TreeColumn column;
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultNameColumnWidth);
    column.setText("Name");
    // Add listener to column so peripherals are sorted by name when clicked
    column.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.PeripheralNameOrder));
        }
    });
    /*
       * Value column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultValueColumnWidth);
    column.setText("Value");
    column.setResizable(fDefaultValueColumnWidth != 0);
    /*
       * Field column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultFieldColumnWidth);
    column.setText("Field");
    column.setResizable(fDefaultFieldColumnWidth != 0);
    /*
       * Mode column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultModeWidth);
    column.setText("Mode");
    column.setResizable(fDefaultModeWidth != 0);
    /*
       * Location column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultLocationColumnWidth);
    column.setText("Location");
    column.setResizable(fDefaultLocationColumnWidth != 0);
    // Add listener to column so peripheral are sorted by address when clicked
    column.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.AddressOrder));
        }
    });
    /*
       * Description column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultDescriptionColumnWidth);
    column.setText("Description");
    column.setResizable(fDefaultDescriptionColumnWidth != 0);
    // Default to sorted by Peripheral name
    fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.PeripheralNameOrder));
    // Noting filtered
    fPeripheralsTreeViewer.addFilter(new PeripheralsViewFilter(PeripheralsViewFilter.SelectionCriteria.SelectAll));
    // Label provider
    fPeripheralsTreeViewer.setLabelProvider(new PeripheralsViewCellLabelProvider(this));
    // Content provider
    fPeripheralsTreeViewer.setContentProvider(new PeripheralsViewContentProvider(this));
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(fPeripheralsTreeViewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            // ||
            return (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION);
        // (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
        }
    };
    TreeViewerEditor.create(fPeripheralsTreeViewer, actSupport, TreeViewerEditor.DEFAULT);
    // Create the help context id for the viewer's control
    // PlatformUI.getWorkbench().getHelpSystem().setHelp(treeViewer.getControl(),
    // "usbdmMemory.viewer");
    // =============================
    fPeripheralsInformationPanel = new PeripheralsInformationPanel(form, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY, this.fPeripheralsTreeViewer);
    form.setWeights(new int[] { 80, 20 });
    // Tree expansion/collapse
    fPeripheralsTreeViewer.addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            Object element = event.getElement();
            // System.err.println("treeExpanded() => event.getElement().getClass() = " + element.getClass());
            if (element instanceof RegisterModel) {
                ((RegisterModel) element).update();
            }
            if (element instanceof PeripheralModel) {
                ((PeripheralModel) element).update();
            }
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }
    });
    // When user checks a checkbox in the tree, check all its children
    fPeripheralsTreeViewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            // peripheralsTreeViewer.expandToLevel(event.getElement(), 1);
            fPeripheralsTreeViewer.setSubtreeChecked(event.getElement(), event.getChecked());
        }
    });
    // Create the actions
    makeActions();
    // Add selected actions to context menu
    hookContextMenu();
    // Add selected actions to menu bar
    contributeToActionBars();
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) PeripheralModel(net.sourceforge.usbdm.peripherals.model.PeripheralModel) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) RegisterModel(net.sourceforge.usbdm.peripherals.model.RegisterModel) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) FillLayout(org.eclipse.swt.layout.FillLayout) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) SashForm(org.eclipse.swt.custom.SashForm) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 12 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project usbdm-eclipse-plugins by podonoghue.

the class AnnotationEditor method createControls.

public void createControls(Composite parent) {
    viewer = new TreeViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
    Tree tree = viewer.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    ColumnViewerToolTipSupport.enableFor(viewer);
    // // Suppress tree expansion on double-click
    // // see http://www.eclipse.org/forums/index.php/t/257325/
    // viewer.getControl().addListener(SWT.MeasureItem, new Listener(){
    // @Override
    // public void handleEvent(Event event) {
    // }});
    viewer.setContentProvider(new ViewContentProvider());
    // FocusCellOwnerDrawHighlighter highlighter = new FocusCellOwnerDrawHighlighter(viewer) {
    // protected Color getSelectedCellBackgroundColorNoFocus(ViewerCell cell) {
    // return Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
    // }
    // protected Color getSelectedCellForegroundColorNoFocus(ViewerCell cell) {
    // return Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
    // }
    // };
    // TreeViewerFocusCellManager focusCellManager     = new TreeViewerFocusCellManager(viewer, highlighter);
    // ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
    // @Override
    // protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
    // return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
    // || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
    // || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
    // || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
    // }
    // };
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION;
        }
    };
    TreeViewerEditor.create(viewer, actSupport, ColumnViewerEditor.DEFAULT);
    /*
       * Do columns
       */
    TreeViewerColumn column;
    column = new TreeViewerColumn(viewer, SWT.NONE);
    column.getColumn().setWidth(300);
    column.getColumn().setText("Option Name");
    column.getColumn().setResizable(true);
    column.setLabelProvider(new MyNameColumnLabelProvider());
    column = new TreeViewerColumn(viewer, SWT.NONE);
    column.getColumn().setWidth(450);
    column.getColumn().setText("Option Value");
    column.getColumn().setResizable(true);
    column.setEditingSupport(new AnnotationEditingSupport(viewer));
    column.setLabelProvider(new MyValueColumnLabelProvider());
    column = new TreeViewerColumn(viewer, SWT.NONE);
    column.getColumn().setWidth(450);
    column.getColumn().setText("Information");
    column.getColumn().setResizable(true);
    column.setLabelProvider(new MyInformationColumnLabelProvider());
}
Also used : ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Tree(org.eclipse.swt.widgets.Tree) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn)

Example 13 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project portfolio by buchen.

the class ColumnEditingSupport method prepare.

public static void prepare(ColumnViewer viewer) {
    ColumnViewerEditorActivationStrategy activationStrategy = new ColumnViewerEditorActivationStrategy(viewer) {

        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    int feature = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION;
    if (viewer instanceof TableViewer)
        TableViewerEditor.create((TableViewer) viewer, null, activationStrategy, feature);
    else if (viewer instanceof TreeViewer)
        TreeViewerEditor.create((TreeViewer) viewer, activationStrategy, feature);
}
Also used : ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 14 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project statecharts by Yakindu.

the class ExecutionContextViewerFactory method createViewer.

public static TreeViewer createViewer(Composite parent, boolean readOnly, ITypeSystemProvider provider) {
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    TreeColumnLayout layout = new TreeColumnLayout();
    comp.setLayout(layout);
    final TreeViewer viewer = new TreeViewer(comp, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    viewer.getTree().setHeaderVisible(true);
    viewer.getTree().setLinesVisible(true);
    ExecutionContextContentProvider contentProvider = new ExecutionContextContentProvider();
    viewer.setContentProvider(contentProvider);
    viewer.setFilters(new ViewerFilter[] { new TimeEventViewerFilter() });
    TreeViewerColumn nameColumn = new TreeViewerColumn(viewer, SWT.NONE);
    nameColumn.getColumn().setText("Name");
    nameColumn.getColumn().setResizable(true);
    nameColumn.setLabelProvider(new ExecutionContextLabelProvider(0, readOnly));
    TreeViewerColumn valueColumn = new TreeViewerColumn(viewer, SWT.NONE);
    valueColumn.getColumn().setText("Value");
    valueColumn.getColumn().setResizable(false);
    valueColumn.setLabelProvider(new ExecutionContextLabelProvider(1, readOnly));
    layout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(NAME_COL_WIDTH_RATIO, NAME_COL_MIN_WIDTH));
    layout.setColumnData(valueColumn.getColumn(), new ColumnWeightData(VALUE_COL_WIDTH_RATIO, VALUE_COL_MIN_WIDTH));
    if (!readOnly)
        valueColumn.setEditingSupport(new MultiEditingSupport(viewer, // 
        new EnumerationEditingSupport(viewer, provider), // 
        new IntegerEditingSupport(viewer, provider), // 
        new RealEditingSupport(viewer, provider), // 
        new BooleanEditingSupport(viewer, provider), // 
        new StringEditingSupport(viewer, provider)));
    valueColumn.getViewer().getColumnViewerEditor().addEditorActivationListener(new ColumnViewerEditorActivationListener() {

        @Override
        public void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
            contentProvider.setShouldUpdate(true);
            viewer.refresh();
        }

        @Override
        public void afterEditorActivated(ColumnViewerEditorActivationEvent event) {
            contentProvider.setShouldUpdate(false);
        }

        @Override
        public void beforeEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
        }

        @Override
        public void beforeEditorActivated(ColumnViewerEditorActivationEvent event) {
        }
    });
    return viewer;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnViewerEditorDeactivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) ColumnViewerEditorActivationListener(org.eclipse.jface.viewers.ColumnViewerEditorActivationListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) RealEditingSupport(org.yakindu.sct.simulation.ui.view.editing.RealEditingSupport) BooleanEditingSupport(org.yakindu.sct.simulation.ui.view.editing.BooleanEditingSupport) StringEditingSupport(org.yakindu.sct.simulation.ui.view.editing.StringEditingSupport) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) EnumerationEditingSupport(org.yakindu.sct.simulation.ui.view.editing.EnumerationEditingSupport) IntegerEditingSupport(org.yakindu.sct.simulation.ui.view.editing.IntegerEditingSupport) GridData(org.eclipse.swt.layout.GridData) MultiEditingSupport(org.yakindu.sct.simulation.ui.view.editing.MultiEditingSupport)

Example 15 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project azure-tools-for-java by Microsoft.

the class SparkSubmissionExDialog method createContents.

@Override
protected Control createContents(Composite parent) {
    final Composite root = new Composite(parent, SWT.NONE);
    root.setLayout(new GridLayout(2, false));
    root.setLayoutData(new GridDataBuilder().widthHint(600).build());
    final Label clusterListLabel = new Label(root, SWT.LEFT);
    clusterListLabel.setText("Cluster Name:");
    clustersListComboBox = new Combo(root, SWT.READ_ONLY);
    clustersListComboBox.setLayoutData(new GridDataBuilder().build());
    clustersListComboBox.setToolTipText("The HDInsight Spark cluster you want to submit your application to. Only Linux cluster is supported.");
    clustersListComboBox.addModifyListener(event -> {
        IClusterDetail clusterDetail = getSelectedCluster(clustersListComboBox.getText());
        if (clusterDetail != null && ClusterManagerEx.getInstance().isHdiReaderCluster(clusterDetail)) {
            showHdiReaderErrors(true);
        } else {
            showHdiReaderErrors(false);
        }
    });
    // Execute "select the first item" operation after the dialog opened
    Display.getDefault().asyncExec(() -> {
        for (IClusterDetail clusterDetail : cachedClusterDetails) {
            clustersListComboBox.add(clusterDetail.getTitle());
            clustersListComboBox.setData(clusterDetail.getTitle(), clusterDetail);
        }
        if (cachedClusterDetails.size() > 0) {
            // Send SWT.Modify event after select the first item
            clustersListComboBox.select(0);
        }
    });
    // Add blank label as a placeholder
    final Label placeholderLabel = new Label(root, SWT.LEFT);
    placeholderLabel.setVisible(false);
    final Composite warningWithLink = new Composite(root, SWT.NONE);
    warningWithLink.setLayout(new GridLayout(2, false));
    warningWithLink.setLayoutData(new GridDataBuilder().build());
    // Add warning message and link cluster button composite
    hdiReaderErrorMsgLabel = new Label(warningWithLink, SWT.LEFT);
    hdiReaderErrorMsgLabel.setText("No Ambari permission to submit job to the selected cluster...");
    hdiReaderErrorMsgLabel.setToolTipText("No Ambari permission to submit job to the selected cluster. Please ask the cluster owner or user " + "access administrator to upgrade your role to HDInsight Cluster Operator in the Azure Portal, or " + "link to the selected cluster.");
    hdiReaderLink = new Link(warningWithLink, SWT.NONE);
    hdiReaderLink.setText("<a href=\" \">Link this cluster</a>");
    hdiReaderLink.addListener(SWT.Selection, e -> {
        IClusterDetail selectedClusterDetail = getSelectedCluster(clustersListComboBox.getText());
        if (selectedClusterDetail != null && ClusterManagerEx.getInstance().isHdiReaderCluster(selectedClusterDetail)) {
            String defaultStorageRootPath = ((ClusterDetail) selectedClusterDetail).getDefaultStorageRootPath();
            AddNewHDInsightReaderClusterForm linkClusterForm = new AddNewHDInsightReaderClusterForm(PluginUtil.getParentShell(), null, (ClusterDetail) selectedClusterDetail) {

                protected void afterOkActionPerformed() {
                    showHdiReaderErrors(false);
                    HDInsightAdditionalClusterDetail linkedCluster = (HDInsightAdditionalClusterDetail) ClusterManagerEx.getInstance().findClusterDetail(clusterDetail -> getSelectedLinkedHdiCluster(clusterDetail, selectedClusterDetail.getName()), true);
                    if (linkedCluster != null) {
                        linkedCluster.setDefaultStorageRootPath(defaultStorageRootPath);
                        ClusterManagerEx.getInstance().updateHdiAdditionalClusterDetail(linkedCluster);
                        // Display the HDI reader cluster as linked cluster
                        Display.getDefault().asyncExec(() -> {
                            int selectedClusterIndex = clustersListComboBox.indexOf(selectedClusterDetail.getTitle());
                            clustersListComboBox.setItem(selectedClusterIndex, linkedCluster.getTitle());
                            clustersListComboBox.setData(linkedCluster.getTitle(), linkedCluster);
                        });
                    }
                }
            };
            linkClusterForm.open();
        }
    });
    // Hide HDInsight reader cluster error when dialog open at first time
    showHdiReaderErrors(false);
    // Radio button group for the artifact selection
    final Group artifactSelectGroup = new Group(root, SWT.NONE);
    artifactSelectGroup.setText("Select an Artifact to submit");
    artifactSelectGroup.setLayout(new GridLayout(2, false));
    artifactSelectGroup.setLayoutData(new GridDataBuilder().span(2, 2).build());
    // Project artifacts Radio button
    projectArtifactRadioButton = new Button(artifactSelectGroup, SWT.RADIO);
    projectArtifactRadioButton.setText("Artifact from Eclipse project:");
    projectArtifactRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ignored) {
            switchToProjectArtifactSelection(true);
        }
    });
    final String selectProjectArtifactTip = "The Artifact you want to use.";
    projectArtifactSelectComboBox = new Combo(artifactSelectGroup, SWT.READ_ONLY);
    projectArtifactSelectComboBox.setToolTipText(selectProjectArtifactTip);
    projectArtifactSelectComboBox.setLayoutData(new GridDataBuilder().widthHint(400).build());
    projectArtifactSelectComboBox.getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(AccessibleEvent event) {
            event.result = projectArtifactRadioButton.getText();
        }
    });
    final String[] projects = getProjects();
    projectArtifactSelectComboBox.setItems(projects);
    if (myProject != null) {
        final String selectedProjectName = myProject.getName();
        for (int i = 0; i < projects.length; ++i) {
            if (projects[i].equalsIgnoreCase(selectedProjectName)) {
                projectArtifactSelectComboBox.select(i);
            }
        }
    } else if (projects.length > 0) {
        projectArtifactSelectComboBox.select(0);
    }
    // Local artifact
    localArtifactRadioButton = new Button(artifactSelectGroup, SWT.RADIO);
    localArtifactRadioButton.setText("Artifact from hard disk:");
    localArtifactRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ignored) {
            switchToProjectArtifactSelection(false);
        }
    });
    final Composite localArtifactSelection = new Composite(artifactSelectGroup, SWT.NONE);
    localArtifactSelection.setLayout(new GridLayout(2, false));
    localArtifactSelection.setLayoutData(new GridDataBuilder().build());
    final String localArtifactInputTip = "Input the local artifact path.";
    localArtifactInput = new Text(localArtifactSelection, SWT.LEFT | SWT.BORDER);
    localArtifactInput.setToolTipText(localArtifactInputTip);
    localArtifactInput.setLayoutData(new GridDataBuilder().build());
    localArtifactInput.getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(AccessibleEvent event) {
            event.result = localArtifactRadioButton.getText();
        }
    });
    // Browser button to open file selection dialog
    localArtifactBrowseButton = new Button(localArtifactSelection, SWT.PUSH);
    localArtifactBrowseButton.setText("Browse");
    localArtifactBrowseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            FileDialog dialog = new FileDialog(SparkSubmissionExDialog.this.getShell());
            String[] extensions = { "*.jar", "*.JAR" };
            dialog.setFilterExtensions(extensions);
            String file = dialog.open();
            if (file != null) {
                localArtifactInput.setText(file);
            }
        }
    });
    localArtifactBrowseButton.getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(AccessibleEvent event) {
            event.result = "Browse. Open System File dialog to select artifact";
        }
    });
    // Default selection
    projectArtifactRadioButton.setSelection(true);
    switchToProjectArtifactSelection(true);
    // Main class input
    final Label sparkMainClassLabel = new Label(root, SWT.LEFT);
    sparkMainClassLabel.setText("Main class name");
    mainClassCombo = new Combo(root, SWT.DROP_DOWN);
    mainClassCombo.setToolTipText("Application's java/spark main class");
    mainClassCombo.setLayoutData(new GridDataBuilder().build());
    try {
        java.util.Set<String> classes = getClassesWithMainMethod();
        String[] names = new String[classes.size()];
        classes.toArray(names);
        mainClassCombo.setItems(names);
        mainClassCombo.select(0);
    } catch (CoreException e1) {
        Activator.getDefault().log("get main class list error", e1);
    }
    // Job configuration
    final Label jobConfigurationLabel = new Label(root, SWT.LEFT);
    jobConfigurationLabel.setText("Job configurations");
    jobConfigurationLabel.setLayoutData(new GridDataBuilder().verticalAlignment(TOP).build());
    jobConfigTableViewer = new TableViewer(root, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    jobConfigTableViewer.setUseHashlookup(true);
    jobConfigTableViewer.setColumnProperties(COLUMN_NAMES);
    final Table jobConfigurationTable = jobConfigTableViewer.getTable();
    jobConfigurationTable.setHeaderVisible(true);
    jobConfigurationTable.setLinesVisible(true);
    jobConfigurationTable.setLayout(new GridLayout(1, false));
    jobConfigurationTable.setLayoutData(new GridDataBuilder().heightHint(75).build());
    final TableViewerColumn keyCol = new TableViewerColumn(jobConfigTableViewer, SWT.NONE);
    keyCol.getColumn().setText(COLUMN_NAMES[0]);
    keyCol.getColumn().setWidth(150);
    final TableViewerColumn valueCol = new TableViewerColumn(jobConfigTableViewer, SWT.NONE);
    valueCol.getColumn().setText(COLUMN_NAMES[1]);
    valueCol.getColumn().setWidth(80);
    final CellEditor[] editors = new CellEditor[] { new TextCellEditor(jobConfigurationTable), new TextCellEditor(jobConfigurationTable) };
    jobConfigTableViewer.setCellEditors(editors);
    jobConfigTableViewer.setContentProvider(new JobConfigurationContentProvider());
    jobConfigTableViewer.setLabelProvider(new JobConfigurationLabelProvider());
    jobConfigTableViewer.setCellModifier(new JobConfigurationCellModifier());
    jobConfigurationTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.SPACE) {
                TableItem[] selection = ((Table) e.getSource()).getSelection();
                if (selection.length > 0) {
                    jobConfigTableViewer.editElement(selection[0].getData(), 1);
                }
            }
        }
    });
    ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(jobConfigTableViewer) {

        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            // Enable editor only with mouse double click or space key press
            if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC || event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.character == SWT.SPACE) {
                EventObject source = event.sourceEvent;
                // Take double right click as invalid mouse event
                return !(source instanceof MouseEvent && ((MouseEvent) source).button == 3);
            }
            return false;
        }
    };
    TableViewerEditor.create(jobConfigTableViewer, activationSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    initializeTable();
    // Make the table focus at the first cell when it get focus at the first time
    jobConfigTableViewer.editElement(jobConfigurationTable.getItem(0).getData(), 0);
    final Label label = new Label(root, SWT.LEFT);
    label.setText("Command line arguments");
    final String commandLineTip = "Command line arguments used in your main class; multiple arguments should be split by space.";
    commandLineTextField = new Text(root, SWT.LEFT | SWT.BORDER);
    commandLineTextField.setToolTipText(commandLineTip);
    commandLineTextField.setLayoutData(new GridDataBuilder().build());
    final String refJarsTip = "Files to be placed on the java classpath; The path needs to be a Azure Blob Storage Path (path started with wasb://); Multiple paths should be split by semicolon (;)";
    final Label referencedJarsLabel = new Label(root, SWT.LEFT);
    referencedJarsLabel.setText("Referenced Jars");
    referencedJarsTextField = new Text(root, SWT.BORDER | SWT.LEFT);
    referencedJarsTextField.setToolTipText(refJarsTip);
    referencedJarsTextField.setLayoutData(new GridDataBuilder().build());
    final Label referencedFilesLabel = new Label(root, SWT.LEFT);
    referencedFilesLabel.setText("Referenced Files");
    final String refFilesTip = "Files to be placed in executor working directory. The path needs to be a Azure Blob Storage Path (path started with wasb://); Multiple paths should be split by semicolon (;) ";
    referencedFilesTextField = new Text(root, SWT.BORDER | SWT.LEFT);
    referencedFilesTextField.setToolTipText(refFilesTip);
    referencedFilesTextField.setLayoutData(new GridDataBuilder().build());
    return super.createContents(parent);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) Arrays(java.util.Arrays) ColumnViewerEditor(org.eclipse.jface.viewers.ColumnViewerEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) HDInsightAdditionalClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.HDInsightAdditionalClusterDetail) CoreException(org.eclipse.core.runtime.CoreException) Messages(com.microsoft.azuretools.core.utils.Messages) CellEditor(org.eclipse.jface.viewers.CellEditor) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) StringUtils(org.apache.commons.lang3.StringUtils) EventObject(java.util.EventObject) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ClusterManagerEx(com.microsoft.azure.hdinsight.common.ClusterManagerEx) PluginUtil(com.microsoft.azuretools.core.utils.PluginUtil) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) KeyEvent(org.eclipse.swt.events.KeyEvent) TOP(org.eclipse.swt.SWT.TOP) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) AddNewHDInsightReaderClusterForm(com.microsoft.azuretools.azureexplorer.forms.AddNewHDInsightReaderClusterForm) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable) HDInsightProjectNature(com.microsoft.azuretools.hdinsight.projects.HDInsightProjectNature) IJavaProject(org.eclipse.jdt.core.IJavaProject) Button(org.eclipse.swt.widgets.Button) SparkSubmitModel(com.microsoft.azuretools.hdinsight.spark.common2.SparkSubmitModel) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) CENTER(org.eclipse.swt.SWT.CENTER) FILL(org.eclipse.swt.SWT.FILL) IType(org.eclipse.jdt.core.IType) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) Stream(java.util.stream.Stream) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) SWT(org.eclipse.swt.SWT) ClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.ClusterDetail) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) Label(org.eclipse.swt.widgets.Label) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull) HDINSIGHT(com.microsoft.azuretools.telemetry.TelemetryConstants.HDINSIGHT) Image(org.eclipse.swt.graphics.Image) SparkSubmissionParameter(com.microsoft.azure.hdinsight.spark.common.SparkSubmissionParameter) Table(org.eclipse.swt.widgets.Table) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) HashSet(java.util.HashSet) StringHelper(com.microsoft.azuretools.azurecommons.helpers.StringHelper) IProject(org.eclipse.core.resources.IProject) ImmutableList(com.google.common.collect.ImmutableList) IWorkspace(org.eclipse.core.resources.IWorkspace) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) CallBack(com.microsoft.azure.hdinsight.common.CallBack) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) Link(org.eclipse.swt.widgets.Link) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableItem(org.eclipse.swt.widgets.TableItem) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TableViewerEditor(org.eclipse.jface.viewers.TableViewerEditor) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Viewer(org.eclipse.jface.viewers.Viewer) JavaCore(org.eclipse.jdt.core.JavaCore) FileDialog(org.eclipse.swt.widgets.FileDialog) Activator(com.microsoft.azuretools.hdinsight.Activator) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Group(org.eclipse.swt.widgets.Group) Pair(com.microsoft.azuretools.utils.Pair) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) Dialog(org.eclipse.jface.dialogs.Dialog) AppInsightsClient(com.microsoft.azuretools.telemetry.AppInsightsClient) IMethod(org.eclipse.jdt.core.IMethod) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) HDInsightAdditionalClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.HDInsightAdditionalClusterDetail) ClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.ClusterDetail) IClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) AddNewHDInsightReaderClusterForm(com.microsoft.azuretools.azureexplorer.forms.AddNewHDInsightReaderClusterForm) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) EventObject(java.util.EventObject) HDInsightAdditionalClusterDetail(com.microsoft.azure.hdinsight.sdk.cluster.HDInsightAdditionalClusterDetail) CoreException(org.eclipse.core.runtime.CoreException) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) FileDialog(org.eclipse.swt.widgets.FileDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) Link(org.eclipse.swt.widgets.Link)

Aggregations

ColumnViewerEditorActivationEvent (org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)15 ColumnViewerEditorActivationStrategy (org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy)11 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 TableViewer (org.eclipse.jface.viewers.TableViewer)5 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)5 GridData (org.eclipse.swt.layout.GridData)5 Composite (org.eclipse.swt.widgets.Composite)5 ICellModifier (org.eclipse.jface.viewers.ICellModifier)4 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)4 FocusCellOwnerDrawHighlighter (org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter)3 TableViewerFocusCellManager (org.eclipse.jface.viewers.TableViewerFocusCellManager)3 ViewerCell (org.eclipse.jface.viewers.ViewerCell)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Tree (org.eclipse.swt.widgets.Tree)3 ArrayList (java.util.ArrayList)2 CellNavigationStrategy (org.eclipse.jface.viewers.CellNavigationStrategy)2 ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2