Search in sources :

Example 36 with KeyEvent

use of org.eclipse.swt.events.KeyEvent in project MonjaDB by Kanatoko.

the class MActionView method init2.

//--------------------------------------------------------------------------------
public void init2() {
    parent.setLayout(new FormLayout());
    sashForm = new SashForm(parent, SWT.SMOOTH | SWT.VERTICAL);
    FormData fd_sashForm1 = new FormData();
    fd_sashForm1.top = new FormAttachment(0, 1);
    fd_sashForm1.left = new FormAttachment(0, 1);
    fd_sashForm1.right = new FormAttachment(100, -1);
    fd_sashForm1.bottom = new FormAttachment(100, -1);
    sashForm.setLayoutData(fd_sashForm1);
    table = new Table(sashForm, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    table.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            onTableStateChange();
        }
    });
    table.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 13) {
                e.doit = false;
                if (//Shift + Enter
                (e.stateMask & SWT.SHIFT) != 0) {
                    repeatActionsOnTable();
                } else {
                    editActions();
                }
            }
        }
    });
    FormData fd_table = new FormData();
    fd_table.top = new FormAttachment(0, 0);
    fd_table.bottom = new FormAttachment(100, 0);
    fd_table.left = new FormAttachment(0, 0);
    fd_table.right = new FormAttachment(100, 0);
    table.setLayoutData(fd_table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn actionColumn = new TableColumn(table, SWT.NONE);
    actionColumn.setWidth(100);
    actionColumn.setText("Action");
    TableColumn dateColumn = new TableColumn(table, SWT.NONE);
    dateColumn.setWidth(100);
    dateColumn.setText("Date");
    editorComposite = new Composite(sashForm, SWT.BORDER);
    editorComposite.setLayout(new FormLayout());
    text = new Text(editorComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    text.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            onTextStateChange();
        }
    });
    FormData fd_text = new FormData();
    fd_text.bottom = new FormAttachment(100, -40);
    fd_text.right = new FormAttachment(100);
    fd_text.top = new FormAttachment(0);
    fd_text.left = new FormAttachment(0);
    text.setLayoutData(fd_text);
    executeButton = new Button(editorComposite, SWT.NONE);
    executeButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            executeActionsOnText();
        }
    });
    executeButton.setEnabled(false);
    FormData fd_executeButton = new FormData();
    fd_executeButton.top = new FormAttachment(text, 6);
    fd_executeButton.left = new FormAttachment(text, -120, SWT.RIGHT);
    fd_executeButton.right = new FormAttachment(100, -10);
    executeButton.setLayoutData(fd_executeButton);
    executeButton.setText("Execute");
    editorComposite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            onSashResize();
        }
    });
    MSwtUtil.getTableColumnWidthFromProperties("actionListTable", table, prop, new int[] { 200, 100 });
    MSwtUtil.addListenerToTableColumns2(table, this);
    //table.addListener( SWT.KeyDown, this );
    table.addListener(SWT.MouseDoubleClick, this);
    menuManager = new MenuManager();
    Menu contextMenu = menuManager.createContextMenu(table);
    table.setMenu(contextMenu);
    //executeTableAction
    {
        redoAction = new Action() {

            public void run() {
                //------------
                repeatActionsOnTable();
            }
        };
        //------------
        redoAction.setToolTipText("Redo Selected Actions");
        redoAction.setText("Redo\tShift+Enter");
        initAction(redoAction, "table_go.png", menuManager);
        redoAction.setEnabled(false);
    }
    //editAction
    {
        editAction = new Action() {

            public void run() {
                //------------
                editActions();
            }
        };
        //------------
        editAction.setToolTipText("Edit Actions on The Text Editor");
        editAction.setText("Edit\tEnter");
        initAction(editAction, "pencil.png", menuManager);
        editAction.setEnabled(false);
    }
    dropDownMenu.add(new Separator());
    menuManager.add(new Separator());
    //executeAction
    {
        executeAction = new Action() {

            public void run() {
                //------------
                executeActionsOnText();
            }
        };
        //------------
        executeAction.setToolTipText("Execute Actions on the Textarea");
        executeAction.setText("Execute");
        setActionImage(executeAction, "bullet_go.png");
        addActionToToolBar(executeAction);
        executeAction.setEnabled(false);
        dropDownMenu.add(executeAction);
    }
    dropDownMenu.add(new Separator());
    menuManager.add(new Separator());
    //copyAction
    {
        copyAction = new Action() {

            public void run() {
                //------------
                copyActions();
            }
        };
        //------------
        copyAction.setToolTipText("Copy Actions to Clipboard");
        copyAction.setText("Copy");
        setActionImage(copyAction, "page_copy.png");
        addActionToToolBar(copyAction);
        copyAction.setEnabled(false);
        dropDownMenu.add(copyAction);
        menuManager.add(copyAction);
    }
    dropDownMenu.add(new Separator());
    menuManager.add(new Separator());
    //clearAction
    {
        clearAction = new Action() {

            public void run() {
                //------------
                clearActions();
            }
        };
        //------------
        clearAction.setToolTipText("Clear All");
        clearAction.setText("Clear All");
        initAction(clearAction, "table_delete.png", menuManager);
        clearAction.setEnabled(false);
    }
    //saveAction
    {
        saveAction = new Action() {

            public void run() {
                //------------
                saveActions();
            }
        };
        //------------
        saveAction.setToolTipText("Save Action");
        saveAction.setText("Save");
        initAction(saveAction, "cog_add.png", menuManager);
        saveAction.setEnabled(false);
    }
    //load actionLogList
    if (prop.containsKey(ACTION_LOG_LIST)) {
        String savedStr = prop.getProperty(ACTION_LOG_LIST);
        actionLogList = (java.util.List) JSON.parse(savedStr);
        for (int i = 0; i < actionLogList.size(); ++i) {
            Map actionLog = (Map) actionLogList.get(i);
            addActionToTable(actionLog);
        }
    } else {
        actionLogList = new LinkedList();
    }
    if (prop.containsKey(ACTIONLOG_COMPOSITE_WEIGHT)) {
        (new Thread() {

            public void run() {
                MSystemUtil.sleep(0);
                shell.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        //----
                        sashForm.setWeights(prop.getIntArrayProperty(ACTIONLOG_COMPOSITE_WEIGHT));
                    }
                });
            //----
            }
        }).start();
    } else {
        sashForm.setWeights(new int[] { 70, 30 });
    }
    initializedTime = System.currentTimeMillis();
}
Also used : MEditAction(net.jumperz.app.MMonjaDBCore.action.mj.MEditAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) SashForm(org.eclipse.swt.custom.SashForm) java.util(java.util) MenuManager(org.eclipse.jface.action.MenuManager) ControlEvent(org.eclipse.swt.events.ControlEvent) Separator(org.eclipse.jface.action.Separator)

Example 37 with KeyEvent

use of org.eclipse.swt.events.KeyEvent in project sling by apache.

the class ArchetypeParametersWizardPage method createControl.

/**
	 * @see IDialogPage#createControl(Composite)
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    layout.verticalSpacing = 9;
    Label label = new Label(container, SWT.NULL);
    label.setText("&Group Id:");
    groupId = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    groupId.setLayoutData(gd);
    groupId.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
            if (!javaPackageModified) {
                if (artifactId.getText().length() == 0) {
                    javaPackage.setText(getDefaultJavaPackage(groupId.getText(), ""));
                } else {
                    javaPackage.setText(getDefaultJavaPackage(groupId.getText(), artifactId.getText()));
                }
            }
        }
    });
    label = new Label(container, SWT.NULL);
    label.setText("&Artifact Id:");
    artifactId = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    artifactId.setLayoutData(gd);
    artifactId.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
            if (javaPackageModified) {
                return;
            }
            if (groupId.getText().length() == 0) {
                javaPackage.setText(getDefaultJavaPackage("", artifactId.getText()));
            } else {
                javaPackage.setText(getDefaultJavaPackage(groupId.getText(), artifactId.getText()));
            }
        }
    });
    label = new Label(container, SWT.NULL);
    label.setText("&Version:");
    version = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    version.setLayoutData(gd);
    version.setText("0.0.1-SNAPSHOT");
    version.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    label = new Label(container, SWT.NULL);
    label.setText("&Package:");
    javaPackage = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    javaPackage.setLayoutData(gd);
    javaPackageModified = false;
    javaPackage.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            javaPackageModified = true;
        }
    });
    javaPackage.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    label = new Label(container, SWT.NULL);
    gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
    label.setLayoutData(gd);
    label.setText("&Parameters:");
    propertiesViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION);
    propertiesTable = propertiesViewer.getTable();
    propertiesTable.setLinesVisible(true);
    propertiesTable.setHeaderVisible(true);
    propertiesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 2));
    CellNavigationStrategy strategy = new CellNavigationStrategy();
    TableViewerFocusCellManager focusCellMgr = new TableViewerFocusCellManager(propertiesViewer, new FocusCellOwnerDrawHighlighter(propertiesViewer), strategy);
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(propertiesViewer) {

        @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;
        }
    };
    int features = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK;
    TableViewerEditor.create(propertiesViewer, focusCellMgr, actSupport, features);
    TableColumn propertiesTableNameColumn = new TableColumn(propertiesTable, SWT.NONE);
    propertiesTableNameColumn.setWidth(130);
    propertiesTableNameColumn.setText("Name");
    TableColumn propertiesTableValueColumn = new TableColumn(propertiesTable, SWT.NONE);
    propertiesTableValueColumn.setWidth(230);
    propertiesTableValueColumn.setText("Value");
    propertiesViewer.setColumnProperties(new String[] { KEY_PROPERTY, VALUE_PROPERTY });
    propertiesViewer.setCellEditors(new CellEditor[] { new TextCellEditor(propertiesTable, SWT.NONE), new TextCellEditor(propertiesTable, SWT.NONE) });
    propertiesViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return true;
        }

        public void modify(Object element, String property, Object value) {
            if (element instanceof TableItem) {
                ((TableItem) element).setText(getTextIndex(property), String.valueOf(value));
                dialogChanged();
            }
        }

        public Object getValue(Object element, String property) {
            if (element instanceof TableItem) {
                return ((TableItem) element).getText(getTextIndex(property));
            }
            return null;
        }
    });
    initialize();
    setPageComplete(false);
    setControl(container);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) CellNavigationStrategy(org.eclipse.jface.viewers.CellNavigationStrategy) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableViewerFocusCellManager(org.eclipse.jface.viewers.TableViewerFocusCellManager) FocusCellOwnerDrawHighlighter(org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 38 with KeyEvent

use of org.eclipse.swt.events.KeyEvent in project sling by apache.

the class SetupServerWizardPage method createControl.

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 3;
    layout.verticalSpacing = 9;
    layout.marginBottom = 10;
    GridDataFactory singleRowGridDataFactory = GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(layout.numColumns, 1);
    useExistingServer = new Button(container, SWT.RADIO);
    useExistingServer.setText("Add to existing server");
    singleRowGridDataFactory.applyTo(useExistingServer);
    Label existingServerLabel = new Label(container, SWT.NONE);
    GridData locationLabelData = new GridData();
    locationLabelData.horizontalIndent = HORIZONTAL_INDENT;
    existingServerLabel.setLayoutData(locationLabelData);
    existingServerLabel.setText("Location:");
    existingServerLabel.setEnabled(true);
    existingServerCombo = new SlingLaunchpadCombo(container, null);
    existingServerCombo.getWidget().addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    existingServerCombo.refreshRepositoryList(new NullProgressMonitor());
    existingServerCombo.getWidget().setEnabled(true);
    {
        startExistingServerButton = new Button(container, SWT.CHECK);
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
        gd.horizontalIndent = HORIZONTAL_INDENT;
        startExistingServerButton.setLayoutData(gd);
        startExistingServerButton.setText("Start server after project creation (if server not yet started).");
        startExistingServerButton.setSelection(true);
    }
    skipServerConfiguration = new Button(container, SWT.RADIO);
    skipServerConfiguration.setText("Don't deploy on a server");
    singleRowGridDataFactory.applyTo(skipServerConfiguration);
    setupNewServer = new Button(container, SWT.RADIO);
    setupNewServer.setText("Setup new server");
    singleRowGridDataFactory.applyTo(setupNewServer);
    newLabel(container, "Server name:");
    newServerName = newText(container);
    newLabel(container, "Host name:");
    newServerHostnameName = newText(container);
    newServerHostnameName.setText("localhost");
    newLabel(container, "Port:");
    newServerPort = newText(container);
    newServerPort.setText(Integer.toString(config.getPort()));
    newLabel(container, "Username:");
    newServerUsername = newText(container);
    newServerUsername.setText(config.getUsername());
    newLabel(container, "Password:");
    newServerPassword = newText(container);
    newServerPassword.setText(config.getPassword());
    newLabel(container, "Debug Port:");
    newServerDebugPort = newText(container);
    newServerDebugPort.setText(Integer.toString(config.getDebugPort()));
    SelectionAdapter radioListener = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            updateEnablements();
            dialogChanged();
        }
    };
    useExistingServer.addSelectionListener(radioListener);
    setupNewServer.addSelectionListener(radioListener);
    ModifyListener ml = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    };
    KeyListener kl = new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            dialogChanged();
        }

        @Override
        public void keyPressed(KeyEvent e) {
            dialogChanged();
        }
    };
    newServerName.addModifyListener(ml);
    newServerName.addKeyListener(kl);
    newServerHostnameName.addModifyListener(ml);
    newServerHostnameName.addKeyListener(kl);
    newServerPort.addModifyListener(ml);
    newServerPort.addKeyListener(kl);
    newServerDebugPort.addModifyListener(ml);
    newServerDebugPort.addKeyListener(kl);
    useExistingServer.setSelection(existingServerCombo.hasServers());
    existingServerCombo.getWidget().setEnabled(existingServerCombo.hasServers());
    startExistingServerButton.setEnabled(existingServerCombo.hasServers());
    setupNewServer.setSelection(!existingServerCombo.hasServers());
    updateEnablements();
    setPageComplete(false);
    setControl(container);
    // allow the selection to proceed in case we have a preselected server
    if (useExistingServer.getSelection()) {
        if (existingServerCombo.getErrorMessage(SKIP_SERVER_STARTED) == null) {
            updateStatus(null);
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SlingLaunchpadCombo(org.apache.sling.ide.eclipse.ui.internal.SlingLaunchpadCombo) KeyEvent(org.eclipse.swt.events.KeyEvent) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener)

Example 39 with KeyEvent

use of org.eclipse.swt.events.KeyEvent in project bndtools by bndtools.

the class RepositoryBundleSelectionPart method createSection.

void createSection(Section section, FormToolkit toolkit) {
    // Toolbar buttons
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    fillToolBar(toolbar);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(getLabelProvider());
    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ToolItem remove = getRemoveItemTool();
            if (remove != null)
                remove.setEnabled(isRemovable(event.getSelection()));
        }
    });
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            event.detail = DND.DROP_COPY;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (FileTransfer.getInstance().isSupportedType(transferType))
                return true;
            if (ResourceTransfer.getInstance().isSupportedType(transferType))
                return true;
            if (URLTransfer.getInstance().isSupportedType(transferType))
                return true;
            ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return false;
            }
            Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
            while (iterator.hasNext()) {
                if (!selectionIsDroppable(iterator.next())) {
                    return false;
                }
            }
            return true;
        }

        private boolean selectionIsDroppable(Object element) {
            return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
        }

        @Override
        public boolean performDrop(Object data) {
            TransferData transfer = getCurrentEvent().currentDataType;
            if (URLTransfer.getInstance().isSupportedType(transfer)) {
                String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
                return handleURLDrop(urlStr);
            } else if (data instanceof String[]) {
                return handleFileNameDrop((String[]) data);
            } else if (data instanceof IResource[]) {
                return handleResourceDrop((IResource[]) data);
            } else {
                return handleSelectionDrop();
            }
        }

        private boolean handleResourceDrop(IResource[] resources) {
            File[] files = new File[resources.length];
            for (int i = 0; i < resources.length; i++) {
                files[i] = resources[i].getLocation().toFile();
            }
            return handleFileDrop(files);
        }

        private boolean handleFileNameDrop(String[] paths) {
            File[] files = new File[paths.length];
            for (int i = 0; i < paths.length; i++) {
                files[i] = new File(paths[i]);
            }
            return handleFileDrop(files);
        }

        private boolean handleFileDrop(File[] files) {
            if (files.length > 0) {
                BndPreferences prefs = new BndPreferences();
                boolean hideWarning = prefs.getHideWarningExternalFile();
                if (!hideWarning) {
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
                    if (Window.CANCEL == dialog.getReturnCode())
                        return false;
                    if (dialog.getToggleState()) {
                        prefs.setHideWarningExternalFile(true);
                    }
                }
                AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
                WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                if (Window.OK == dialog.open()) {
                    List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
                    List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
                    for (Pair<String, String> addingBundle : addingBundles) {
                        Attrs attribs = new Attrs();
                        attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
                        addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
                    }
                    handleAdd(addingClauses);
                }
                return true;
            }
            return false;
        }

        private boolean handleSelectionDrop() {
            ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return false;
            }
            List<VersionedClause> adding = new LinkedList<VersionedClause>();
            Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
            while (iterator.hasNext()) {
                Object item = iterator.next();
                if (item instanceof RepositoryBundle) {
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
                    adding.add(newClause);
                } else if (item instanceof RepositoryBundleVersion) {
                    RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
                    adding.add(newClause);
                } else if (item instanceof RepositoryResourceElement) {
                    RepositoryResourceElement elt = (RepositoryResourceElement) item;
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
                    adding.add(newClause);
                }
            }
            handleAdd(adding);
            return true;
        }

        private boolean handleURLDrop(String urlStr) {
            try {
                URI uri = new URI(sanitizeUrl(urlStr));
                AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
                WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                if (dialog.open() == Window.OK) {
                    Set<ResourceDescriptor> resources = wizard.getResult();
                    List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
                    for (ResourceDescriptor resource : resources) {
                        Attrs attrs = new Attrs();
                        attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
                        VersionedClause clause = new VersionedClause(resource.bsn, attrs);
                        newBundles.add(clause);
                    }
                    handleAdd(newBundles);
                    return true;
                }
                return false;
            } catch (URISyntaxException e) {
                MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
                return false;
            }
        }

        private String sanitizeUrl(String urlStr) {
            int newline = urlStr.indexOf('\n');
            if (newline > -1)
                return urlStr.substring(0, newline).trim();
            return urlStr;
        }

        private void handleAdd(Collection<VersionedClause> newClauses) {
            if (newClauses == null || newClauses.isEmpty())
                return;
            List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
            for (VersionedClause newClause : newClauses) {
                boolean found = false;
                for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
                    VersionedClause existing = iter.next();
                    if (newClause.getName().equals(existing.getName())) {
                        int index = iter.previousIndex();
                        iter.set(newClause);
                        viewer.replace(newClause, index);
                        found = true;
                        break;
                    }
                }
                if (!found)
                    toAdd.add(newClause);
            }
            bundles.addAll(toAdd);
            viewer.add(toAdd.toArray());
            markDirty();
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setExpandEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
            } else if (e.character == '+') {
                doAdd();
            }
        }
    });
    // Layout
    GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 50;
    gd.heightHint = getTableHeightHint();
    table.setLayoutData(gd);
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) BndPreferences(bndtools.preferences.BndPreferences) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectBundle(bndtools.model.repo.ProjectBundle) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) LinkedList(java.util.LinkedList) Collection(java.util.Collection) File(java.io.File) AddFilesToRepositoryWizard(bndtools.wizards.workspace.AddFilesToRepositoryWizard) Attrs(aQute.bnd.header.Attrs) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) TransferData(org.eclipse.swt.dnd.TransferData) ISelection(org.eclipse.jface.viewers.ISelection) ToolItem(org.eclipse.swt.widgets.ToolItem) Pair(bndtools.types.Pair) Composite(org.eclipse.swt.widgets.Composite) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) RepositoryResourceElement(bndtools.model.repo.RepositoryResourceElement) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) AddJpmDependenciesWizard(org.bndtools.core.ui.wizards.jpm.AddJpmDependenciesWizard) TableViewer(org.eclipse.jface.viewers.TableViewer) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 40 with KeyEvent

use of org.eclipse.swt.events.KeyEvent in project bndtools by bndtools.

the class RunBlacklistPart method createSection.

private void createSection(Section section, FormToolkit tk) {
    section.setText("Run Blacklist");
    section.setDescription("The specified requirements will be excluded from the resolution.");
    // Create toolbar
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    fillToolBar(toolbar);
    // Create main panel
    Composite composite = tk.createComposite(section);
    section.setClient(composite);
    table = tk.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new RequirementLabelProvider());
    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            removeTool.setEnabled(!viewer.getSelection().isEmpty());
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
            } else if (e.character == '+') {
                doAddBundle();
            }
        }
    });
    RequirementViewerDropAdapter dropper = new RequirementViewerDropAdapter();
    dropper.install(viewer);
    // Layout
    GridLayout layout;
    GridData gd;
    layout = new GridLayout(2, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 5;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.widthHint = 50;
    gd.heightHint = 50;
    table.setLayoutData(gd);
    gd = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) RequirementLabelProvider(org.bndtools.core.ui.resource.RequirementLabelProvider)

Aggregations

KeyEvent (org.eclipse.swt.events.KeyEvent)98 KeyAdapter (org.eclipse.swt.events.KeyAdapter)63 GridData (org.eclipse.swt.layout.GridData)54 GridLayout (org.eclipse.swt.layout.GridLayout)42 Composite (org.eclipse.swt.widgets.Composite)42 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 Text (org.eclipse.swt.widgets.Text)34 KeyListener (org.eclipse.swt.events.KeyListener)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)32 Label (org.eclipse.swt.widgets.Label)29 ModifyEvent (org.eclipse.swt.events.ModifyEvent)22 ModifyListener (org.eclipse.swt.events.ModifyListener)22 Point (org.eclipse.swt.graphics.Point)21 Button (org.eclipse.swt.widgets.Button)21 MouseEvent (org.eclipse.swt.events.MouseEvent)20 TableViewer (org.eclipse.jface.viewers.TableViewer)19 StyledText (org.eclipse.swt.custom.StyledText)13 FocusEvent (org.eclipse.swt.events.FocusEvent)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12