Search in sources :

Example 16 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project cubrid-manager by CUBRID.

the class JdbcOptionComposite method createButtonComp.

/**
	 *
	 * Create button composite
	 *
	 * @param composite the composite
	 */
private void createButtonComp(Composite composite) {
    Composite buttonComposite = new Composite(composite, SWT.NONE);
    {
        GridLayout layout = new GridLayout();
        layout.numColumns = 3;
        buttonComposite.setLayout(layout);
        buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    }
    Hyperlink link = new Hyperlink(buttonComposite, SWT.None);
    link.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    link.setText(Messages.titleJdbcAdvancedOptionView);
    link.addMouseListener(new MouseListener() {

        public void mouseUp(MouseEvent e) {
            IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
            try {
                IWebBrowser br = browserSupport.createBrowser(null);
                br.openURL(new URL(Messages.msgCubridJdbcInfoUrl));
            } catch (Exception ignored) {
            }
        }

        public void mouseDown(MouseEvent e) {
        }

        public void mouseDoubleClick(MouseEvent e) {
        }
    });
    addButton = new Button(buttonComposite, SWT.PUSH);
    addButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    addButton.setText(Messages.btnAdd);
    addButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            TableItem itemNew = new TableItem(jdbcInfoTv.getTable(), SWT.SINGLE);
            int newIndex = jdbcInfoTv.getTable().getItemCount() - 1;
            focusCell(itemNew, newIndex, 0);
        }
    });
    Button delButton = new Button(buttonComposite, SWT.PUSH);
    delButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    delButton.setText(Messages.btnDelete);
    delButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = jdbcInfoTv.getTable().getSelection();
            if (selection == null || selection.length == 0) {
                return;
            }
            jdbcInfoTv.getTable().setSelection(-1);
            for (TableItem item : selection) {
                item.dispose();
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) URL(java.net.URL) GridLayout(org.eclipse.swt.layout.GridLayout) MouseListener(org.eclipse.swt.events.MouseListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) Hyperlink(com.novocode.naf.swt.custom.Hyperlink)

Example 17 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project cubrid-manager by CUBRID.

the class NoticeDashboardPage method createFormText.

private FormText createFormText(Composite composite) {
    FormText text = toolkit.createFormText(composite, true);
    text.addHyperlinkListener(new IHyperlinkListener() {

        public void linkExited(HyperlinkEvent e) {
        }

        public void linkEntered(HyperlinkEvent e) {
        }

        public void linkActivated(HyperlinkEvent e) {
            String href = (String) e.getHref();
            String url = CommonUITool.urlEncodeForSpaces(href);
            try {
                IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
                IWebBrowser browser = support.getExternalBrowser();
                browser.openURL(new URL(url));
            } catch (PartInitException e1) {
                LOGGER.error("Can not initialize web browser on the application.", e1);
            } catch (MalformedURLException e2) {
                LOGGER.error("The url {} is invalid.", url, e2);
            }
        }
    });
    return text;
}
Also used : MalformedURLException(java.net.MalformedURLException) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) FormText(org.eclipse.ui.forms.widgets.FormText) IHyperlinkListener(org.eclipse.ui.forms.events.IHyperlinkListener) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL)

Example 18 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project sling by apache.

the class AbstractOpenInBrowserHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getCurrentSelection(event);
    JcrNode node = SelectionUtils.getFirst(sel, JcrNode.class);
    if (node == null) {
        return null;
    }
    Shell shell = HandlerUtil.getActiveShell(event);
    IModule module = ServerUtil.getModule(node.getProject());
    if (module == null) {
        MessageDialog.openWarning(shell, "Cannot open browser", "Not configured for any server");
        return null;
    }
    IServer[] servers = ServerUtil.getServersByModule(module, new NullProgressMonitor());
    if (servers == null || servers.length == 0) {
        MessageDialog.openWarning(shell, "Cannot open browser", "Not configured for any server");
        return null;
    }
    IServer server = servers[0];
    URL url;
    try {
        url = getUrlToOpen(node, server);
    } catch (MalformedURLException e) {
        StatusManager.getManager().handle(new Status(Status.WARNING, Activator.PLUGIN_ID, "Url is invalid", e), StatusManager.SHOW);
        return null;
    }
    try {
        IWorkbenchBrowserSupport browserSupport = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getBrowserSupport();
        browserSupport.createBrowser("org.apache.sling.ide.openOnServer").openURL(url);
    } catch (PartInitException e) {
        StatusManager.getManager().handle(new Status(Status.WARNING, Activator.PLUGIN_ID, "Failed creating browser instance", e), StatusManager.SHOW | StatusManager.LOG);
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) IModule(org.eclipse.wst.server.core.IModule) IServer(org.eclipse.wst.server.core.IServer) MalformedURLException(java.net.MalformedURLException) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL)

Example 19 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project dbeaver by dbeaver.

the class MockDataWizardPageSettings method createControl.

public void createControl(Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 1);
    {
        SelectionListener changeListener = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                updateState();
            }
        };
        Composite entityPlaceholder = UIUtils.createPlaceholder(composite, 2);
        this.entityNameText = UIUtils.createLabelText(entityPlaceholder, "Entity", "", SWT.NONE | SWT.READ_ONLY);
        GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
        gd.widthHint = 230;
        gd.verticalIndent = 5;
        gd.horizontalIndent = 9;
        entityPlaceholder.setLayoutData(gd);
        Group settingsGroup = UIUtils.createControlGroup(composite, MockDataMessages.tools_mockdata_wizard_page_settings_group_settings, 4, GridData.FILL_HORIZONTAL, 0);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.verticalIndent = 5;
        settingsGroup.setLayoutData(gd);
        this.removeOldDataCheck = UIUtils.createCheckbox(settingsGroup, MockDataMessages.tools_mockdata_wizard_page_settings_checkbox_remove_old_data, null, mockDataSettings.isRemoveOldData(), 4);
        removeOldDataCheck.addSelectionListener(changeListener);
        this.rowsText = UIUtils.createLabelText(settingsGroup, "Rows ", String.valueOf(mockDataSettings.getRowsNumber()), SWT.BORDER, new GridData(110, SWT.DEFAULT));
        rowsText.addSelectionListener(changeListener);
        rowsText.addVerifyListener(UIUtils.getLongVerifyListener(rowsText));
        rowsText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                updateState();
            }
        });
    }
    {
        Group generatorsGroup = UIUtils.createControlGroup(composite, "Generators", 5, GridData.FILL_BOTH, 0);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.verticalIndent = 5;
        generatorsGroup.setLayoutData(gd);
        columnsTableViewer = new TableViewer(generatorsGroup, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
        final Table table = columnsTableViewer.getTable();
        gd = new GridData(GridData.FILL_VERTICAL);
        gd.widthHint = 230;
        table.setLayoutData(gd);
        table.setHeaderVisible(true);
        table.setLinesVisible(true);
        columnsTableViewer.setContentProvider(new IStructuredContentProvider() {

            @Override
            public void dispose() {
            }

            @Override
            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            }

            @Override
            public Object[] getElements(Object inputElement) {
                if (inputElement instanceof Collection) {
                    return ((Collection<?>) inputElement).toArray();
                }
                return new Object[0];
            }
        });
        // TODO VoidProgressMonitor
        VoidProgressMonitor monitor = new VoidProgressMonitor();
        CellLabelProvider labelProvider = new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBSAttributeBase attribute = (DBSAttributeBase) cell.getElement();
                AttributeGeneratorProperties attributeGeneratorProperties = mockDataSettings.getAttributeGeneratorProperties(attribute);
                if (cell.getColumnIndex() == 0) {
                    cell.setImage(DBeaverIcons.getImage(DBValueFormatting.getTypeImage(attribute)));
                    cell.setText(attribute.getName());
                    try {
                        if (DBUtils.checkUnique(monitor, mockDataSettings.getEntity(), attribute)) {
                            cell.setFont(boldFont);
                        }
                    } catch (DBException e) {
                        log.error("Error checking the attribute '" + attribute.getName() + "' properties", e);
                    }
                    if (attributeGeneratorProperties != null && attributeGeneratorProperties.isEmpty()) {
                        cell.setForeground(table.getDisplay().getSystemColor(SWT.COLOR_RED));
                        noGeneratorInfoLabel.setVisible(true);
                    }
                } else {
                    if (attributeGeneratorProperties != null && !attributeGeneratorProperties.isEmpty()) {
                        String selectedGeneratorId = attributeGeneratorProperties.getSelectedGeneratorId();
                        String label = mockDataSettings.getGeneratorDescriptor(selectedGeneratorId).getLabel();
                        cell.setText(label.trim());
                    }
                }
            }
        };
        TableViewerColumn attributeColumn = new TableViewerColumn(columnsTableViewer, SWT.LEFT);
        attributeColumn.setLabelProvider(labelProvider);
        attributeColumn.getColumn().setText("Attribute");
        TableViewerColumn generatorColumn = new TableViewerColumn(columnsTableViewer, SWT.LEFT);
        generatorColumn.setLabelProvider(labelProvider);
        generatorColumn.getColumn().setText("Generator");
        generatorColumn.setEditingSupport(new EditingSupport(columnsTableViewer) {

            @Override
            protected CellEditor getCellEditor(Object element) {
                DBSAttributeBase attribute = (DBSAttributeBase) element;
                AttributeGeneratorProperties attributeGenerators = mockDataSettings.getAttributeGeneratorProperties(attribute);
                Set<String> generators = new LinkedHashSet<>();
                if (attributeGenerators.isEmpty()) {
                    // TODO item.setForeground(columnsTableViewer.getDisplay().getSystemColor(SWT.COLOR_RED));
                    noGeneratorInfoLabel.setVisible(true);
                    TextCellEditor textCellEditor = new TextCellEditor(columnsTableViewer.getTable());
                    textCellEditor.getControl().setEnabled(false);
                    return textCellEditor;
                } else {
                    for (String generatorId : attributeGenerators.getGenerators()) {
                        generators.add(mockDataSettings.getGeneratorDescriptor(generatorId).getLabel());
                    }
                    CustomComboBoxCellEditor customComboBoxCellEditor = new CustomComboBoxCellEditor(columnsTableViewer, columnsTableViewer.getTable(), generators.toArray(new String[generators.size()]), SWT.BORDER | SWT.READ_ONLY);
                    return customComboBoxCellEditor;
                }
            }

            @Override
            protected boolean canEdit(Object element) // disable the generator selection
            {
                return true;
            }

            @Override
            protected Object getValue(Object element) {
                DBSAttributeBase attribute = (DBSAttributeBase) element;
                String selectedGenerator = mockDataSettings.getAttributeGeneratorProperties(attribute).getSelectedGeneratorId();
                if (selectedGenerator != null) {
                    return mockDataSettings.getGeneratorDescriptor(selectedGenerator).getLabel();
                } else {
                    return "";
                }
            }

            @Override
            protected void setValue(Object element, Object value) {
                DBSAttributeBase attribute = (DBSAttributeBase) element;
                selectGenerator(attribute, (String) value);
            }
        });
        table.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                saveGeneratorProperties();
                reloadProperties((DBSAttributeBase) e.item.getData(), null);
            }
        });
        // generator properties
        Composite placeholder = UIUtils.createPlaceholder(generatorsGroup, 1);
        placeholder.setLayoutData(new GridData(GridData.FILL_BOTH));
        Composite labelCombo = UIUtils.createPlaceholder(placeholder, 5);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        labelCombo.setLayoutData(gd);
        generatorCombo = new Combo(labelCombo, SWT.READ_ONLY | SWT.DROP_DOWN);
        gd = new GridData();
        gd.widthHint = 80;
        generatorCombo.setLayoutData(gd);
        generatorCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                selectGenerator(selectedAttribute, generatorCombo.getText());
            }
        });
        Composite descriptionCombo = UIUtils.createPlaceholder(labelCombo, 2);
        gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
        descriptionCombo.setLayoutData(gd);
        generatorDescriptionLabel = new Label(descriptionCombo, SWT.NONE);
        generatorDescriptionLabel.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT));
        generatorDescriptionLabel.setText("");
        gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
        gd.horizontalIndent = 5;
        generatorDescriptionLabel.setLayoutData(gd);
        generatorDescriptionLink = UIUtils.createLink(descriptionCombo, "", new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (!CommonUtils.isEmpty(generatorLinkUrl)) {
                    IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
                    try {
                        support.getExternalBrowser().openURL(new URL(generatorLinkUrl));
                    } catch (Exception ex) {
                    }
                }
            }
        });
        gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
        gd.horizontalIndent = 5;
        generatorDescriptionLink.setLayoutData(gd);
        Button resetButton = new Button(labelCombo, SWT.PUSH);
        resetButton.setText("Reset");
        resetButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                for (Object key : propertySource.getProperties().keySet()) {
                    propertySource.resetPropertyValueToDefault(key);
                }
                propsEditor.loadProperties(propertySource);
                columnsTableViewer.refresh(true, true);
            }
        });
        gd = new GridData();
        gd.horizontalIndent = 5;
        resetButton.setLayoutData(gd);
        propsEditor = new PropertyTreeViewer(placeholder, SWT.BORDER);
        gd = new GridData(GridData.FILL_BOTH);
        gd.verticalIndent = 5;
        propsEditor.getControl().setLayoutData(gd);
        noGeneratorInfoLabel = UIUtils.createInfoLabel(composite, "Generators for the red highlighted attributes aren't found. So, no data will be generated for them.");
        // noGeneratorInfoLabel.setForeground(columnsTableViewer.getDisplay().getSystemColor(SWT.COLOR_RED));
        gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
        gd.horizontalSpan = 2;
        gd.verticalIndent = 5;
        noGeneratorInfoLabel.setLayoutData(gd);
        noGeneratorInfoLabel.setVisible(false);
        table.addControlListener(new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                UIUtils.packColumns(table);
                UIUtils.maxTableColumnsWidth(table);
                table.removeControlListener(this);
            }
        });
    }
    setControl(composite);
    boldFont = UIUtils.makeBoldFont(columnsTableViewer.getControl().getFont());
}
Also used : DBException(org.jkiss.dbeaver.DBException) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) CLabel(org.eclipse.swt.custom.CLabel) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) URL(java.net.URL) CustomComboBoxCellEditor(org.jkiss.dbeaver.ui.controls.CustomComboBoxCellEditor) AttributeGeneratorProperties(org.jkiss.dbeaver.ext.mockdata.MockDataSettings.AttributeGeneratorProperties) DBException(org.jkiss.dbeaver.DBException) GridData(org.eclipse.swt.layout.GridData) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)

Example 20 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project knime-core by knime.

the class IntroPage method handleLink.

private void handleLink(final URI link) {
    try {
        URL url = link.toURL();
        IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
        support.getExternalBrowser().openURL(url);
    } catch (MalformedURLException ex) {
        LOGGER.error("Malformed URL '" + link.toString() + "': " + ex.getMessage(), ex);
    } catch (PartInitException ex) {
        LOGGER.error("Could not open external browser for '" + link.toString() + "': " + ex.getMessage(), ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL)

Aggregations

IWorkbenchBrowserSupport (org.eclipse.ui.browser.IWorkbenchBrowserSupport)36 URL (java.net.URL)31 IWebBrowser (org.eclipse.ui.browser.IWebBrowser)29 PartInitException (org.eclipse.ui.PartInitException)21 MalformedURLException (java.net.MalformedURLException)18 GridData (org.eclipse.swt.layout.GridData)7 GridLayout (org.eclipse.swt.layout.GridLayout)6 IOException (java.io.IOException)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Button (org.eclipse.swt.widgets.Button)5 Composite (org.eclipse.swt.widgets.Composite)5 Label (org.eclipse.swt.widgets.Label)5 Status (org.eclipse.core.runtime.Status)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 CoreException (org.eclipse.core.runtime.CoreException)3 HyperlinkEvent (org.eclipse.ui.forms.events.HyperlinkEvent)3 FormText (org.eclipse.ui.forms.widgets.FormText)3 Hyperlink (com.novocode.naf.swt.custom.Hyperlink)2 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2