/** * Get an <code>Image</code> from the provide SWT image constant. * * @param imageID the SWT image constant * @return image the image */ private Image getSWTImage(final int imageID) { Shell shell = getShell(); final Display display; if (!Widgets.isDisposed(shell)) { shell = shell.getParent().getShell(); } if (Widgets.isDisposed(shell)) { display = Display.getCurrent(); // The dialog should be always instantiated in UI thread. // However it was possible to instantiate it in other threads // (the code worked in most cases) so the assertion covers // only the failing scenario. See bug 107082 for details. Assert.isNotNull(display, "The dialog should be created in UI thread"); // $NON-NLS-1$ } else { display = shell.getDisplay(); } final Image[] image = new Image[1]; display.syncExec( new Runnable() { @Override public void run() { image[0] = display.getSystemImage(imageID); } }); return image[0]; }
private void configureRuntimeCombo() throws CoreException { if (Widgets.isDisposed(runtimeComboViewer)) { return; } String lastUsedRuntime = lastSelectedRuntime; List<String> runtimesList = new ArrayList<String>(); String selectedRuntime = null; serverRuntimes = getServerRuntimes(null); runtimeComboViewer.setInput(ArrayContentProvider.getInstance()); runtimesList.addAll(serverRuntimes.keySet()); runtimesList.add(Messages.newProjectWizardRuntimePageNoRuntimeSelectedLabel); runtimeComboViewer.setInput(runtimesList); runtimeComboViewer.setSelection( new StructuredSelection(Messages.newProjectWizardRuntimePageNoRuntimeSelectedLabel)); for (Map.Entry<String, IRuntime> entry : serverRuntimes.entrySet()) { IRuntime runtime = entry.getValue(); if (lastUsedRuntime != null && lastUsedRuntime.equals(runtime.getId())) { selectedRuntime = lastUsedRuntime; } } if (selectedRuntime != null) { runtimeComboViewer.setSelection(new StructuredSelection(selectedRuntime)); } }
/** * returns the selected runtime * * @return */ public IRuntime getSelectedRuntime() { if (!Widgets.isDisposed(runtimeComboViewer)) { String runtimeId = runtimeComboViewer.getSelection().toString(); if (!runtimeId.equalsIgnoreCase(Messages.newProjectWizardRuntimePageNoRuntimeSelectedLabel)) { return serverRuntimes.get(runtimeId); } } return null; }
private void validateCamelVersion() { if (getSelectedCamelVersion() != null && !isCamelVersionValid(getSelectedCamelVersion())) { if (!Widgets.isDisposed(camelInfoText)) { camelInfoText.setText( NLS.bind( Messages.newProjectWizardRuntimePageCamelVersionInvalidWarning, getSelectedCamelVersion())); setPageComplete(false); } } else { if (!Widgets.isDisposed(camelInfoText)) { camelInfoText.setText(""); // $NON-NLS-1$ } } if (!Widgets.isDisposed(warningIconLabel) && !Widgets.isDisposed(camelInfoText)) { warningIconLabel.setVisible(camelInfoText.getText().length() > 0); } }
public void preselectCamelVersionForRuntime(String runtimeCamelVersion) { if (Widgets.isDisposed(camelVersionCombo)) { return; } if (UNKNOWN_CAMEL_VERSION.equals(runtimeCamelVersion)) { camelVersionCombo.setEnabled(true); } else { List<String> compatibleVersions = Arrays.stream(camelVersionCombo.getItems()) .filter(camelVersion -> isCompatible(runtimeCamelVersion, camelVersion)) .collect(Collectors.toList()); if (!compatibleVersions.isEmpty()) { if (compatibleVersions.contains(runtimeCamelVersion)) { camelVersionCombo.setText(runtimeCamelVersion); } else { Collections.sort(compatibleVersions); camelVersionCombo.setText(compatibleVersions.get(compatibleVersions.size() - 1)); } } else { camelVersionCombo.select(Math.max(0, camelVersionCombo.getItemCount() - 1)); } } }
/** * returns the selected camel version * * @return */ public String getSelectedCamelVersion() { if (!Widgets.isDisposed(camelVersionCombo)) { return camelVersionCombo.getText(); } return null; }
/** /!\ Public for test purpose */ public void validate() { // if runtime is selected other than NO RUNTIME if (getSelectedRuntime() != null) { // determine the camel version of that runtime String runtimeCamelVersion = determineRuntimeCamelVersion(getSelectedRuntime()); if (UNKNOWN_CAMEL_VERSION.equals(runtimeCamelVersion)) { if (!Widgets.isDisposed(camelVersionCombo)) { camelVersionCombo.setEnabled(true); } camelInfoText.setText( Messages .FuseIntegrationProjectWizardRuntimeAndCamelPage_WarningMessageWhenCamelVersionCannotBeDeterminedInRuntime); } else { // and compare if selected camel version fits that version if (!isCompatible(runtimeCamelVersion, getSelectedCamelVersion())) { // Display warning and suggest the correct version camelInfoText.setText( NLS.bind( Messages.newProjectWizardRuntimePageCamelVersionsDontMatchWarning, runtimeCamelVersion)); } else { camelInfoText.setText(""); // $NON-NLS-1$ } if (!Widgets.isDisposed(camelVersionCombo)) { camelVersionCombo.setEnabled(false); } } } else { if (!Widgets.isDisposed(camelVersionCombo)) { camelVersionCombo.setEnabled(true); } if (!Widgets.isDisposed(camelInfoText)) { camelInfoText.setText(""); // $NON-NLS-1$ } } // TODO: leaving that out until we decide to support other camel versions than the ones we ship // try { // getWizard().getContainer().run(false, false, new IRunnableWithProgress() { // @Override // public void run(IProgressMonitor monitor) throws InvocationTargetException, // InterruptedException { // monitor.beginTask(Messages.newProjectWizardRuntimePageResolveDependencyStatus, // IProgressMonitor.UNKNOWN); // validateCamelVersion(); // monitor.done(); // } // }); // } catch (Exception ex) { // ProjectTemplatesActivator.pluginLog().logError(ex); // } if (!Widgets.isDisposed(warningIconLabel) && !Widgets.isDisposed(camelInfoText)) { warningIconLabel.setVisible(!camelInfoText.getText().isEmpty()); } if (!Widgets.isDisposed(runtimeComboViewer) && !Widgets.isDisposed(camelVersionCombo)) { setPageComplete( !Strings.isBlank(runtimeComboViewer.getSelection().toString()) && !Strings.isBlank(camelVersionCombo.getText()) && !warningIconLabel.isVisible()); } }