Search in sources :

Example 1 with LicenseWizardFragment

use of org.eclipse.wst.server.ui.internal.wizard.fragment.LicenseWizardFragment in project webtools.servertools by eclipse.

the class TomcatRuntimeComposite method createControl.

/**
 * Provide a wizard page to change the Tomcat installation directory.
 */
protected void createControl() {
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    setLayout(layout);
    setLayoutData(new GridData(GridData.FILL_BOTH));
    PlatformUI.getWorkbench().getHelpSystem().setHelp(this, ContextIds.RUNTIME_COMPOSITE);
    Label label = new Label(this, SWT.NONE);
    label.setText(Messages.runtimeName);
    GridData data = new GridData();
    data.horizontalSpan = 2;
    label.setLayoutData(data);
    name = new Text(this, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    name.setLayoutData(data);
    name.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            runtimeWC.setName(name.getText());
            validate();
        }
    });
    label = new Label(this, SWT.NONE);
    label.setText(Messages.installDir);
    data = new GridData();
    data.horizontalSpan = 2;
    label.setLayoutData(data);
    installDir = new Text(this, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    installDir.setLayoutData(data);
    installDir.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            runtimeWC.setLocation(new Path(installDir.getText()));
            validate();
        }
    });
    Button browse = SWTUtil.createButton(this, Messages.browse);
    browse.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent se) {
            DirectoryDialog dialog = new DirectoryDialog(TomcatRuntimeComposite.this.getShell());
            dialog.setMessage(Messages.selectInstallDir);
            dialog.setFilterPath(installDir.getText());
            String selectedDirectory = dialog.open();
            if (selectedDirectory != null)
                installDir.setText(selectedDirectory);
        }
    });
    installLabel = new Label(this, SWT.RIGHT);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalIndent = 10;
    installLabel.setLayoutData(data);
    install = SWTUtil.createButton(this, Messages.install);
    install.setEnabled(false);
    install.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent se) {
            String license = null;
            try {
                license = ir.getLicense(new NullProgressMonitor());
            } catch (CoreException e) {
                Trace.trace(Trace.SEVERE, "Error getting license", e);
            }
            TaskModel taskModel = new TaskModel();
            taskModel.putObject(LicenseWizardFragment.LICENSE, license);
            TaskWizard wizard2 = new TaskWizard(Messages.installDialogTitle, new WizardFragment() {

                protected void createChildFragments(List list) {
                    list.add(new LicenseWizardFragment());
                }
            }, taskModel);
            WizardDialog dialog2 = new WizardDialog(getShell(), wizard2);
            if (dialog2.open() == Window.CANCEL)
                return;
            DirectoryDialog dialog = new DirectoryDialog(TomcatRuntimeComposite.this.getShell());
            dialog.setMessage(Messages.selectInstallDir);
            dialog.setFilterPath(installDir.getText());
            String selectedDirectory = dialog.open();
            if (selectedDirectory != null) {
                // ir.install(new Path(selectedDirectory));
                final IPath installPath = new Path(selectedDirectory);
                installRuntimeJob = new Job("Installing server runtime environment") {

                    public boolean belongsTo(Object family) {
                        return ServerPlugin.PLUGIN_ID.equals(family);
                    }

                    protected IStatus run(IProgressMonitor monitor) {
                        try {
                            ir.install(installPath, monitor);
                        } catch (CoreException ce) {
                            return ce.getStatus();
                        }
                        return Status.OK_STATUS;
                    }
                };
                installDir.setText(selectedDirectory);
                jobListener = new JobChangeAdapter() {

                    public void done(IJobChangeEvent event) {
                        installRuntimeJob.removeJobChangeListener(this);
                        installRuntimeJob = null;
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                if (!isDisposed()) {
                                    validate();
                                }
                            }
                        });
                    }
                };
                installRuntimeJob.addJobChangeListener(jobListener);
                installRuntimeJob.schedule();
            }
        }
    });
    updateJREs();
    // JDK location
    label = new Label(this, SWT.NONE);
    label.setText(Messages.installedJRE);
    data = new GridData();
    data.horizontalSpan = 2;
    label.setLayoutData(data);
    combo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
    combo.setItems(jreNames);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    combo.setLayoutData(data);
    combo.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            int sel = combo.getSelectionIndex();
            IVMInstall vmInstall = null;
            if (sel > 0)
                vmInstall = (IVMInstall) installedJREs.get(sel - 1);
            runtime.setVMInstall(vmInstall);
            validate();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    Button button = SWTUtil.createButton(this, Messages.installedJREs);
    button.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            String currentVM = combo.getText();
            if (showPreferencePage()) {
                updateJREs();
                combo.setItems(jreNames);
                combo.setText(currentVM);
                if (combo.getSelectionIndex() == -1)
                    combo.select(0);
                validate();
            }
        }
    });
    init();
    validate();
    Dialog.applyDialogFont(this);
    name.forceFocus();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ModifyListener(org.eclipse.swt.events.ModifyListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) Job(org.eclipse.core.runtime.jobs.Job) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) WizardFragment(org.eclipse.wst.server.ui.wizard.WizardFragment) LicenseWizardFragment(org.eclipse.wst.server.ui.internal.wizard.fragment.LicenseWizardFragment) IPath(org.eclipse.core.runtime.IPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) TaskWizard(org.eclipse.wst.server.ui.internal.wizard.TaskWizard) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IVMInstall(org.eclipse.jdt.launching.IVMInstall) LicenseWizardFragment(org.eclipse.wst.server.ui.internal.wizard.fragment.LicenseWizardFragment) GridData(org.eclipse.swt.layout.GridData) WizardDialog(org.eclipse.jface.wizard.WizardDialog) TaskModel(org.eclipse.wst.server.core.TaskModel) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with LicenseWizardFragment

use of org.eclipse.wst.server.ui.internal.wizard.fragment.LicenseWizardFragment in project eclipse-integration-commons by spring-projects.

the class ServerConfigurator method installServer.

public ServerHandler installServer(final ServerDescriptor descriptor, File installLocation, IOverwriteQuery query, IProgressMonitor monitor) throws CoreException {
    try {
        SubMonitor progress = SubMonitor.convert(monitor);
        progress.beginTask(NLS.bind("Installing Runtime {0}", descriptor.getRuntimeName()), 100);
        File serverLocation = getLocation(descriptor);
        if (serverLocation == null) {
            final boolean[] response = new boolean[1];
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    response[0] = MessageDialog.openQuestion(UiUtil.getShell(), "Install Runtime", NLS.bind("No local installation of {0} found. Proceed with download?", descriptor.getServerName()));
                }
            });
            if (!response[0]) {
                throw new OperationCanceledException();
            }
            InstallableRuntime2 ir = new ServerDescriptorInstaller(descriptor);
            // prompt license if necessary
            if (ir.getLicenseURL() != null) {
                progress.subTask("Downloading license");
                try {
                    final boolean[] result = new boolean[1];
                    final String license = ir.getLicense(progress.newChild(20));
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            TaskModel taskModel = new TaskModel();
                            taskModel.putObject(LicenseWizardFragment.LICENSE, license);
                            TaskWizard wizard2 = new TaskWizard("License", new WizardFragment() {

                                @SuppressWarnings({ "unchecked", "rawtypes" })
                                @Override
                                protected void createChildFragments(List list) {
                                    list.add(new LicenseWizardFragment());
                                }
                            }, taskModel);
                            WizardDialog dialog2 = new WizardDialog(UiUtil.getShell(), wizard2);
                            result[0] = (dialog2.open() == Window.OK);
                        }
                    });
                    if (!result[0]) {
                        // user did not agree to license
                        throw new OperationCanceledException();
                    }
                } catch (CoreException e) {
                    StatusHandler.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error getting license", e));
                }
            }
            progress.setWorkRemaining(80);
            // schedule download job
            serverLocation = new File(installLocation, descriptor.getInstallPath());
            monitor.subTask(NLS.bind("Downloading runtime to {0}", serverLocation.getAbsolutePath()));
            File archiveFile = File.createTempFile("runtime", null);
            archiveFile.deleteOnExit();
            HttpUtil.download(descriptor.getArchiveUrl(), archiveFile, serverLocation, descriptor.getArchivePath(), progress.newChild(70));
        // Path path = new Path(location.getAbsolutePath());
        // ir.install(path, new SubProgressMonitor(monitor, 70));
        }
        // create wtp runtime
        progress.setWorkRemaining(10);
        monitor.subTask(NLS.bind("Creating server {0}", descriptor.getServerName()));
        ServerHandler serverHandler = new ServerHandler(descriptor, serverLocation);
        serverHandler.createServer(progress.newChild(10), query, descriptor.getCallback());
        return serverHandler;
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Installing runtime failed", e));
    } finally {
        monitor.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) WizardFragment(org.eclipse.wst.server.ui.wizard.WizardFragment) LicenseWizardFragment(org.eclipse.wst.server.ui.internal.wizard.fragment.LicenseWizardFragment) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) ServerHandler(org.springsource.ide.eclipse.commons.configurator.ServerHandler) IOException(java.io.IOException) InstallableRuntime2(org.eclipse.wst.server.core.internal.InstallableRuntime2) TaskWizard(org.eclipse.wst.server.ui.internal.wizard.TaskWizard) CoreException(org.eclipse.core.runtime.CoreException) LicenseWizardFragment(org.eclipse.wst.server.ui.internal.wizard.fragment.LicenseWizardFragment) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) WizardDialog(org.eclipse.jface.wizard.WizardDialog) TaskModel(org.eclipse.wst.server.core.TaskModel)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 TaskModel (org.eclipse.wst.server.core.TaskModel)2 TaskWizard (org.eclipse.wst.server.ui.internal.wizard.TaskWizard)2 LicenseWizardFragment (org.eclipse.wst.server.ui.internal.wizard.fragment.LicenseWizardFragment)2 WizardFragment (org.eclipse.wst.server.ui.wizard.WizardFragment)2 File (java.io.File)1 IOException (java.io.IOException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1