Search in sources :

Example 1 with ServerCreationWizardPageExtension

use of org.eclipse.wst.server.ui.wizard.ServerCreationWizardPageExtension in project webtools.servertools by eclipse.

the class ServerUIPlugin method loadServerCreationWizardPageExtensions.

/**
 * Load the Server creation wizard page modifiers.
 */
private static synchronized void loadServerCreationWizardPageExtensions() {
    if (serverCreationWizardPageExtensions != null)
        return;
    if (Trace.CONFIG) {
        Trace.trace(Trace.STRING_CONFIG, "->- Loading .serverCreationWizardPageExtension extension point ->-");
    }
    serverCreationWizardPageExtensions = new ArrayList<ServerCreationWizardPageExtension>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] cf = registry.getConfigurationElementsFor(ServerUIPlugin.PLUGIN_ID, "serverCreationWizardPageExtension");
    for (IConfigurationElement curConfigElement : cf) {
        try {
            // Create the class here already since the usage of the server wizard page will need to use all the extensions
            // in all the calls.  Therefore, there is no need for lazy loading here.
            ServerCreationWizardPageExtension curExtension = (ServerCreationWizardPageExtension) curConfigElement.createExecutableExtension("class");
            if (Trace.CONFIG) {
                Trace.trace(Trace.STRING_CONFIG, "  Loaded .serverCreationWizardPageExtension: " + cf[0].getAttribute("id") + ", loaded class=" + curExtension);
            }
            if (curExtension != null)
                serverCreationWizardPageExtensions.add(curExtension);
        } catch (Throwable t) {
            if (Trace.SEVERE) {
                Trace.trace(Trace.STRING_SEVERE, "  Could not load .serverCreationWizardPageExtension: " + cf[0].getAttribute("id"), t);
            }
        }
    }
    if (Trace.CONFIG) {
        Trace.trace(Trace.STRING_CONFIG, "-<- Done loading .serverCreationWizardPageExtension extension point -<-");
    }
}
Also used : ServerCreationWizardPageExtension(org.eclipse.wst.server.ui.wizard.ServerCreationWizardPageExtension)

Example 2 with ServerCreationWizardPageExtension

use of org.eclipse.wst.server.ui.wizard.ServerCreationWizardPageExtension in project webtools.servertools by eclipse.

the class NewManualServerComposite method createControl.

/**
 * Returns this page's initial visual components.
 */
protected void createControl() {
    // top level group
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.horizontalSpacing = SWTUtil.convertHorizontalDLUsToPixels(this, 4);
    layout.verticalSpacing = SWTUtil.convertVerticalDLUsToPixels(this, 4);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    setLayout(layout);
    this.setFont(getParent().getFont());
    IWorkbenchHelpSystem whs = PlatformUI.getWorkbench().getHelpSystem();
    whs.setHelp(this, ContextIds.NEW_SERVER_WIZARD);
    List<ServerCreationWizardPageExtension> pageExtensionLst = ServerUIPlugin.getServerCreationWizardPageExtensions();
    // Add the page modifier top section UI.
    for (ServerCreationWizardPageExtension curPageExtension : pageExtensionLst) {
        curPageExtension.createControl(ServerCreationWizardPageExtension.UI_POSITION.TOP, this);
        curPageExtension.setUIControlListener(this);
    }
    serverTypeComposite = new ServerTypeComposite(this, moduleType, serverTypeId, new ServerTypeComposite.ServerTypeSelectionListener() {

        public void serverTypeSelected(IServerType type2) {
            handleTypeSelection(type2);
        // WizardUtil.defaultSelect(parent, CreateServerWizardPage.this);
        }
    });
    serverTypeComposite.setIncludeIncompatibleVersions(includeIncompatible);
    GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    data.horizontalSpan = 3;
    data.minimumHeight = 150;
    serverTypeComposite.setLayoutData(data);
    whs.setHelp(serverTypeComposite, ContextIds.NEW_SERVER_TYPE);
    // Add the page modifier middle section UI.
    for (ServerCreationWizardPageExtension curPageExtension : pageExtensionLst) {
        curPageExtension.createControl(ServerCreationWizardPageExtension.UI_POSITION.MIDDLE, this);
    }
    hostnameListener = new IHostnameSelectionListener() {

        public void hostnameSelected(String selectedHostname) {
            setHost(selectedHostname);
        }
    };
    hostnameLabel = new Label(this, SWT.NONE);
    hostnameLabel.setText(Messages.hostname);
    hostname = new Text(this, SWT.SINGLE | SWT.BORDER | SWT.CANCEL);
    hostname.setText(HostnameComposite.LOCALHOST);
    hostnameDecoration = new ControlDecoration(hostname, SWT.TOP | SWT.LEAD);
    GridData data2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    hostname.setLayoutData(data2);
    new Label(this, SWT.NONE);
    hostname.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            setHostnameChangeTimer(hostname.getText());
        }
    });
    FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
    fd = registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    hostnameDecoration.setImage(fd.getImage());
    hostnameDecoration.setDescriptionText(fd.getDescription());
    hostname.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            hostnameDecoration.show();
        }

        public void focusLost(FocusEvent e) {
            hostnameDecoration.hide();
        }
    });
    List<String> hosts = ServerUIPlugin.getPreferences().getHostnames();
    String[] hosts2 = hosts.toArray(new String[hosts.size()]);
    new AutoCompleteField(hostname, new TextContentAdapter(), hosts2);
    serverNameLabel = new Label(this, SWT.NONE);
    serverNameLabel.setText(Messages.serverName);
    serverName = new Text(this, SWT.SINGLE | SWT.BORDER | SWT.CANCEL);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    if ((serverName.getStyle() & SWT.CANCEL) != 0)
        data.horizontalSpan = 2;
    serverName.setLayoutData(data);
    if (server != null)
        serverName.setText(server.getName());
    serverName.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            if (updatingServerName)
                return;
            String name = serverName.getText();
            IServerType selectedServerType = serverTypeComposite.getSelectedServerType();
            if (!validate(selectedServerType)) {
                // Do not set the server name if it is invalid
                return;
            }
            if (server != null) {
                server.setName(name);
                String base = serverName.getText().trim();
                if (ServerPlugin.isIdInUse(server, base)) {
                    server.setAttribute("id", generateUniqueId(base));
                }
                IRuntime runtime2 = server.getRuntime();
                if (runtime2 != null && runtime2 instanceof IRuntimeWorkingCopy) {
                    IRuntimeWorkingCopy rwc = (IRuntimeWorkingCopy) runtime2;
                    rwc.setName(name);
                }
            }
            if (serverNameModified)
                return;
            serverNameModified = true;
            if (serverNameToolBar != null)
                serverNameToolBar.getControl().setVisible(true);
        }
    });
    if ((serverName.getStyle() & SWT.CANCEL) == 0) {
        serverNameToolBar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
        serverNameToolBar.createControl(this);
        IAction resetDefaultAction = new // $NON-NLS-1$
        Action(// $NON-NLS-1$
        "", // $NON-NLS-1$
        IAction.AS_PUSH_BUTTON) {

            public void run() {
                ((ServerWorkingCopy) server).setDefaults(null);
                serverName.setText(server.getName());
                serverNameModified = false;
                if (serverNameToolBar != null)
                    serverNameToolBar.getControl().setVisible(false);
            }
        };
        resetDefaultAction.setToolTipText(Messages.serverNameDefault);
        resetDefaultAction.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_ETOOL_RESET_DEFAULT));
        resetDefaultAction.setDisabledImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_DTOOL_RESET_DEFAULT));
        serverNameToolBar.add(resetDefaultAction);
        serverNameToolBar.update(false);
        serverNameToolBar.getControl().setVisible(false);
    }
    runtimeLabel = new Label(this, SWT.NONE);
    runtimeLabel.setText(Messages.wizNewServerRuntime);
    runtimeCombo = new Combo(this, SWT.READ_ONLY);
    runtimeCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    runtimeCombo.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            try {
                setRuntime(runtimes[runtimeCombo.getSelectionIndex()]);
            } catch (Exception ex) {
            // ignore
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    addRuntime = new Link(this, SWT.NONE);
    addRuntime.setText("<a>" + Messages.addRuntime + "</a>");
    addRuntime.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    addRuntime.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IServerType serverType = serverTypeComposite.getSelectedServerType();
            showRuntimeWizard(serverType);
        }
    });
    configureRuntimes = new Link(this, SWT.NONE);
    configureRuntimes.setText("<a>" + Messages.configureRuntimes + "</a>");
    data = new GridData(GridData.HORIZONTAL_ALIGN_END);
    data.horizontalSpan = 3;
    configureRuntimes.setLayoutData(data);
    configureRuntimes.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (showPreferencePage()) {
                runtime = null;
                IServerType serverType = serverTypeComposite.getSelectedServerType();
                updateRuntimeCombo(serverType);
            }
        }
    });
    // Add the page modifier bottom section UI.
    for (ServerCreationWizardPageExtension curPageExtension : pageExtensionLst) {
        curPageExtension.createControl(ServerCreationWizardPageExtension.UI_POSITION.BOTTOM, this);
    }
    Dialog.applyDialogFont(this);
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ServerTypeComposite(org.eclipse.wst.server.ui.internal.viewers.ServerTypeComposite) ToolBarManager(org.eclipse.jface.action.ToolBarManager) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchHelpSystem(org.eclipse.ui.help.IWorkbenchHelpSystem) IHostnameSelectionListener(org.eclipse.wst.server.ui.internal.wizard.page.HostnameComposite.IHostnameSelectionListener) IAction(org.eclipse.jface.action.IAction) ServerCreationWizardPageExtension(org.eclipse.wst.server.ui.wizard.ServerCreationWizardPageExtension) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GridData(org.eclipse.swt.layout.GridData) IHostnameSelectionListener(org.eclipse.wst.server.ui.internal.wizard.page.HostnameComposite.IHostnameSelectionListener)

Example 3 with ServerCreationWizardPageExtension

use of org.eclipse.wst.server.ui.wizard.ServerCreationWizardPageExtension in project webtools.servertools by eclipse.

the class NewManualServerComposite method handleTypeSelection.

/**
 * Handle the server type selection.
 */
protected void handleTypeSelection(IServerType serverType) {
    canProceed = true;
    // wizard.setMessage(null, IMessageProvider.NONE);
    if (serverType instanceof ServerTypeProxy) {
        hostname.setVisible(false);
        serverNameLabel.setVisible(false);
        serverName.setVisible(false);
        hostnameLabel.setVisible(false);
        runtimeLabel.setVisible(false);
        runtimeCombo.setVisible(false);
        configureRuntimes.setVisible(false);
        addRuntime.setVisible(false);
        hostnameDecoration.setImage(null);
        hostnameDecoration.setDescriptionText(null);
        final ServerTypeProxy serverTypeFinal = (ServerTypeProxy) serverType;
        success = false;
        ServerTypeProxy serverProxy = (ServerTypeProxy) serverType;
        RuntimeTypeProxy runtimeProxy = (RuntimeTypeProxy) serverProxy.getRuntimeType();
        runtime = new RuntimeProxy(runtimeProxy);
        server = new ServerWorkingCopy(serverProxy.getId(), null, runtime, serverProxy);
        fireServerWorkingCopyChanged();
        listener.serverSelected(server);
        // Fire the property change event.
        List<ServerCreationWizardPageExtension> pageExtensionLst = ServerUIPlugin.getServerCreationWizardPageExtensions();
        for (ServerCreationWizardPageExtension curPageExtension : pageExtensionLst) {
            curPageExtension.handlePropertyChanged(new PropertyChangeEvent(this, AbstractUIControl.PROP_SERVER_TYPE, oldServerType, serverType));
        }
        wizard.update();
        try {
            wizard.run(true, true, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    success = showDownloadableServerWizard(serverTypeFinal, monitor);
                }
            });
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        if (success) {
            // Update the old server type value.
            oldServerType = serverTypeFinal;
        }
        wizard.update();
        return;
    }
    if (serverType != null) {
        // Update the old server type value.
        hostname.setVisible(true);
        serverNameLabel.setVisible(true);
        serverName.setVisible(true);
        hostnameLabel.setVisible(true);
        if (serverType.requiresRuntime() && server != null && ServerUIPlugin.getRuntimes(serverType.getRuntimeType()).length >= 1) {
            runtimeLabel.setVisible(true);
            runtimeCombo.setVisible(true);
            configureRuntimes.setVisible(true);
            addRuntime.setVisible(true);
        }
        hostnameDecoration.setImage(fd.getImage());
        hostnameDecoration.setDescriptionText(fd.getDescription());
    }
    boolean wrong = false;
    if (serverType != null && moduleType != null) {
        IRuntimeType runtimeType = serverType.getRuntimeType();
        // dummy module type means matches all module types
        boolean dummyModule = moduleType.getId() == null && moduleType.getVersion() == null;
        if (!dummyModule && !ServerUtil.isSupportedModule(runtimeType.getModuleTypes(), moduleType)) {
            serverType = null;
            wrong = true;
        // wizard.setMessage("Not the right spec level2", IMessageProvider.ERROR);
        }
    }
    if (wrong) {
        server = null;
        runtime = null;
        wizard.setMessage(NLS.bind(Messages.errorVersionLevel, new Object[] { moduleType.getName(), moduleType.getVersion() }), IMessageProvider.ERROR);
    } else if (serverType == null) {
        server = null;
        runtime = null;
        // $NON-NLS-1$
        wizard.setMessage("", IMessageProvider.ERROR);
    } else {
        // wizard.setMessage(null, IMessageProvider.NONE);
        loadServerImpl(serverType);
        if (server != null && module != null) {
            IStatus status = NewServerComposite.isSupportedModule(server, module);
            if (status != null) {
                if (status.getSeverity() == IStatus.ERROR)
                    wizard.setMessage(status.getMessage(), IMessageProvider.ERROR);
                else if (status.getSeverity() == IStatus.WARNING)
                    wizard.setMessage(status.getMessage(), IMessageProvider.WARNING);
                else if (status.getSeverity() == IStatus.INFO)
                    wizard.setMessage(status.getMessage(), IMessageProvider.INFORMATION);
            }
        }
    }
    if (serverName != null && !serverNameModified) {
        updatingServerName = true;
        if (server == null)
            serverName.setText("");
        else
            serverName.setText(server.getName());
        updatingServerName = false;
    }
    updateRuntimeCombo(serverType);
    if (serverName != null) {
        if (server == null) {
            serverName.setEditable(false);
            serverNameToolBar.getControl().setVisible(false);
        } else {
            serverName.setEditable(true);
            serverNameToolBar.getControl().setVisible(serverNameModified);
        }
    }
    if (hostname != null && server != null) {
        hostname.setText(server.getHost());
    }
    listener.serverSelected(server);
    // Fire the property change event.
    List<ServerCreationWizardPageExtension> pageExtensionLst = ServerUIPlugin.getServerCreationWizardPageExtensions();
    for (ServerCreationWizardPageExtension curPageExtension : pageExtensionLst) {
        curPageExtension.handlePropertyChanged(new PropertyChangeEvent(this, AbstractUIControl.PROP_SERVER_TYPE, oldServerType, serverType));
    }
    // Update the old server type value.
    oldServerType = serverType;
    validate(serverType);
    wizard.update();
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IStatus(org.eclipse.core.runtime.IStatus) ServerCreationWizardPageExtension(org.eclipse.wst.server.ui.wizard.ServerCreationWizardPageExtension) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Aggregations

ServerCreationWizardPageExtension (org.eclipse.wst.server.ui.wizard.ServerCreationWizardPageExtension)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 ToolBarManager (org.eclipse.jface.action.ToolBarManager)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 IWorkbenchHelpSystem (org.eclipse.ui.help.IWorkbenchHelpSystem)1 ServerTypeComposite (org.eclipse.wst.server.ui.internal.viewers.ServerTypeComposite)1 IHostnameSelectionListener (org.eclipse.wst.server.ui.internal.wizard.page.HostnameComposite.IHostnameSelectionListener)1