Search in sources :

Example 1 with BrowserUtility

use of org.jboss.tools.foundation.ui.util.BrowserUtility in project jbosstools-openshift by jbosstools.

the class OpenInWebConsoleHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    IResource resource = UIUtils.getFirstElement(currentSelection, IResource.class);
    Connection connection = null;
    if (resource == null) {
        connection = UIUtils.getFirstElement(currentSelection, Connection.class);
    } else {
        connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
    }
    String msg;
    if (connection == null) {
        msg = "Could not find an OpenShift connection to open a console for";
    } else {
        String url = getWebConsoleUrl(connection, resource);
        if (!StringUtils.isEmpty(url)) {
            new BrowserUtility().checkedCreateExternalBrowser(url, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
            return Status.OK_STATUS;
        }
        msg = NLS.bind("Could not determine the url for the web console on {0}", connection.getHost());
    }
    MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "No Web Console Url", msg);
    return new Status(IStatus.WARNING, OpenShiftUIActivator.PLUGIN_ID, msg);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) IResource(com.openshift.restclient.model.IResource)

Example 2 with BrowserUtility

use of org.jboss.tools.foundation.ui.util.BrowserUtility in project jbosstools-openshift by jbosstools.

the class ConnectionWizardPage method onUserdocLinkClicked.

protected void onUserdocLinkClicked(final IObservableValue<String> userdocUrlObservable) {
    String userdocUrl = (String) userdocUrlObservable.getValue();
    if (StringUtils.isEmpty(userdocUrl)) {
        return;
    }
    new BrowserUtility().checkedCreateExternalBrowser(userdocUrl, OpenShiftCommonUIActivator.PLUGIN_ID, OpenShiftCommonUIActivator.getDefault().getLog());
}
Also used : BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility)

Example 3 with BrowserUtility

use of org.jboss.tools.foundation.ui.util.BrowserUtility in project jbosstools-openshift by jbosstools.

the class WebHooksComponent method onClickWebhook.

private SelectionAdapter onClickWebhook(final IBuildConfig buildConfig) {
    return new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String url = buildConfig.getBuildSource().getURI();
            url = StringUtils.removeEnd(url, ".git");
            if (isGitHub(url)) {
                // open https://github.com/<user>/<repo>/settings/hooks
                if (!url.endsWith("/")) {
                    url = url + "/";
                }
                url += "settings/hooks";
            }
            new BrowserUtility().checkedCreateExternalBrowser(url, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
        }
    };
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility)

Example 4 with BrowserUtility

use of org.jboss.tools.foundation.ui.util.BrowserUtility in project jbosstools-openshift by jbosstools.

the class OpenShiftPreferencePage method createFieldEditors.

@Override
public void createFieldEditors() {
    Link link = new Link(getFieldEditorParent(), SWT.WRAP);
    link.setText("The OpenShift client binary (oc) is required for features such as Port Forwarding or Log Streaming. " + "You can find more information about how to install it from <a>here</a>.");
    GridDataFactory.fillDefaults().span(3, 1).hint(1, 60).grab(true, false).applyTo(link);
    link.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_INSTRUCTIONS_URL, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
        }
    });
    this.cliLocationEditor = new CliFileEditor();
    cliLocationEditor.setFilterPath(SystemUtils.getUserHome());
    String[] suffixes = ocBinary.getExtensions();
    String[] filters = new String[suffixes.length];
    for (int i = 0; i < filters.length; i++) {
        filters[i] = "*" + suffixes[i];
    }
    cliLocationEditor.setFileExtensions(filters);
    cliLocationEditor.setValidateStrategy(FileFieldEditor.VALIDATE_ON_KEY_STROKE);
    addField(cliLocationEditor);
    ocVersionLabel = new Label(getFieldEditorParent(), SWT.WRAP);
    ocVersionLabel.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT));
    GridDataFactory.fillDefaults().span(3, 1).applyTo(ocVersionLabel);
    ocMessageComposite = new Composite(getFieldEditorParent(), SWT.NONE);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(ocMessageComposite);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(ocMessageComposite);
    Label label = new Label(ocMessageComposite, SWT.NONE);
    label.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.TOP).applyTo(label);
    ocMessageLabel = new Label(ocMessageComposite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(ocMessageLabel);
    ocMessageComposite.setVisible(false);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Label(org.eclipse.swt.widgets.Label) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) Link(org.eclipse.swt.widgets.Link)

Example 5 with BrowserUtility

use of org.jboss.tools.foundation.ui.util.BrowserUtility in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createOCWarningControls.

@SuppressWarnings("unchecked")
private void createOCWarningControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Composite composite = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
    ValueBindingBuilder.bind(WidgetProperties.visible().observe(composite)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, Boolean.class) {

        @Override
        public Object convert(Object fromObject) {
            return !((IStatus) fromObject).isOK();
        }
    }).in(dbc);
    Label label = new Label(composite, SWT.NONE);
    ValueBindingBuilder.bind(WidgetProperties.image().observe(label)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, Image.class) {

        @Override
        public Object convert(Object fromObject) {
            switch(((IStatus) fromObject).getSeverity()) {
                case IStatus.WARNING:
                    return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
                case IStatus.ERROR:
                    return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
                default:
                    return null;
            }
        }
    }).in(dbc);
    Link link = new Link(composite, SWT.WRAP);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(link)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, String.class) {

        @Override
        public Object convert(Object fromObject) {
            return ((IStatus) fromObject).getMessage();
        }
    }).in(dbc);
    link.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (DOWNLOAD_LINK_TEXT.equals(e.text)) {
                new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_INSTRUCTIONS_URL, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
            } else {
                int rc = PreferencesUtil.createPreferenceDialogOn(getShell(), OPEN_SHIFT_PREFERENCE_PAGE_ID, new String[] { OPEN_SHIFT_PREFERENCE_PAGE_ID }, null).open();
                if (rc == Dialog.OK) {
                    new Job("Checking oc binary") {

                        @Override
                        protected IStatus run(IProgressMonitor monitor) {
                            IStatus stat = OCBinary.getInstance().getStatus(model.getConnection(), monitor);
                            model.setOCBinaryStatus(stat);
                            return stat;
                        }
                    }.schedule();
                }
            }
        }
    });
    GridDataFactory.fillDefaults().hint(LINK_DEFAULT_WIDTH, SWT.DEFAULT).applyTo(link);
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            IObservableValue<IStatus> observable = BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model);
            Status status = (Status) observable.getValue();
            switch(status.getSeverity()) {
                case IStatus.ERROR:
                    return OpenShiftUIActivator.statusFactory().errorStatus(OpenShiftUIMessages.OCBinaryErrorMessage);
                case IStatus.WARNING:
                    return OpenShiftUIActivator.statusFactory().warningStatus(OpenShiftUIMessages.OCBinaryWarningMessage);
            }
            return status;
        }
    };
    dbc.addValidationStatusProvider(validator);
    BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model).addValueChangeListener(event -> getShell().pack());
}
Also used : ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) Status(org.eclipse.core.runtime.Status) RsyncStatus(org.jboss.tools.openshift.internal.core.util.RSyncValidator.RsyncStatus) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Converter(org.eclipse.core.databinding.conversion.Converter) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) Job(org.eclipse.core.runtime.jobs.Job) Link(org.eclipse.swt.widgets.Link)

Aggregations

BrowserUtility (org.jboss.tools.foundation.ui.util.BrowserUtility)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 Link (org.eclipse.swt.widgets.Link)3 Converter (org.eclipse.core.databinding.conversion.Converter)2 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Job (org.eclipse.core.runtime.jobs.Job)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)2 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)2 RsyncStatus (org.jboss.tools.openshift.internal.core.util.RSyncValidator.RsyncStatus)2 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)2 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)2 IResource (com.openshift.restclient.model.IResource)1 ValidationStatus (org.eclipse.core.databinding.validation.ValidationStatus)1