Search in sources :

Example 1 with DeleteServerDialogExtension

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

the class ServerUIPlugin method loadDeleteServerDialogExtensions.

/**
 * Load the Delete server dialog modifiers.
 */
private static synchronized void loadDeleteServerDialogExtensions() {
    if (deleteServerDialogExtensions != null)
        return;
    if (Trace.CONFIG) {
        Trace.trace(Trace.STRING_CONFIG, "->- Loading .deleteServerDialogExtension extension point ->-");
    }
    deleteServerDialogExtensions = new ArrayList<DeleteServerDialogExtension>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] cf = registry.getConfigurationElementsFor(ServerUIPlugin.PLUGIN_ID, "deleteServerDialogExtension");
    for (IConfigurationElement curConfigElement : cf) {
        try {
            DeleteServerDialogExtension curExtension = (DeleteServerDialogExtension) curConfigElement.createExecutableExtension("class");
            if (Trace.CONFIG) {
                Trace.trace(Trace.STRING_CONFIG, "  Loaded .deleteServerDialogExtension: " + cf[0].getAttribute("id") + ", loaded class=" + curExtension);
            }
            if (curExtension != null)
                deleteServerDialogExtensions.add(curExtension);
        } catch (Throwable t) {
            if (Trace.SEVERE) {
                Trace.trace(Trace.STRING_SEVERE, "  Could not load .deleteServerDialogExtension: " + cf[0].getAttribute("id"), t);
            }
        }
    }
    if (Trace.CONFIG) {
        Trace.trace(Trace.STRING_CONFIG, "-<- Done loading .deleteServerDialogExtension extension point -<-");
    }
}
Also used : DeleteServerDialogExtension(org.eclipse.wst.server.ui.DeleteServerDialogExtension)

Example 2 with DeleteServerDialogExtension

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

the class DeleteServerDialog method buttonPressed.

protected void buttonPressed(int buttonId) {
    if (buttonId == OK) {
        final boolean checked = (checkDeleteConfigs != null && checkDeleteConfigs.getSelection());
        final boolean deleteRunning = (checkDeleteRunning == null || checkDeleteRunning.getSelection());
        final boolean deleteRunningStop = (checkDeleteRunningStop != null && checkDeleteRunningStop.getSelection());
        Thread t = new Thread("Delete servers") {

            public void run() {
                if (runningServersList.size() > 0) {
                    // stop servers and/or updates servers' list
                    prepareForDeletion(deleteRunning, deleteRunningStop);
                }
                Job job = new Job(Messages.deleteServerTask) {

                    protected IStatus run(IProgressMonitor monitor) {
                        if (servers.length == 0) {
                            // all servers have been deleted from list
                            return Status.OK_STATUS;
                        }
                        try {
                            if (monitor.isCanceled())
                                return Status.CANCEL_STATUS;
                            for (DeleteServerDialogExtension curDialogExtension : dialogExtensionLst) {
                                curDialogExtension.performPreDeleteAction(monitor);
                            }
                            int size = servers.length;
                            for (int i = 0; i < size; i++) servers[i].delete();
                            if (monitor.isCanceled())
                                return Status.CANCEL_STATUS;
                            if (checked) {
                                size = configs.length;
                                for (int i = 0; i < size; i++) {
                                    configs[i].refreshLocal(IResource.DEPTH_INFINITE, monitor);
                                    configs[i].delete(true, true, monitor);
                                }
                            }
                            for (DeleteServerDialogExtension curDialogExtension : dialogExtensionLst) {
                                curDialogExtension.performPostDeleteAction(monitor);
                            }
                        } catch (Exception e) {
                            if (Trace.SEVERE) {
                                Trace.trace(Trace.STRING_SEVERE, "Error while deleting resources", e);
                            }
                            return new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, 0, e.getMessage(), e);
                        }
                        return Status.OK_STATUS;
                    }
                };
                // set rule for workspace and servers
                int size = servers.length;
                ISchedulingRule[] rules = new ISchedulingRule[size + 1];
                for (int i = 0; i < size; i++) rules[i] = servers[i];
                IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
                rules[size] = ruleFactory.createRule(ResourcesPlugin.getWorkspace().getRoot());
                job.setRule(MultiRule.combine(rules));
                job.setPriority(Job.BUILD);
                job.schedule();
            }
        };
        t.setDaemon(true);
        t.start();
    }
    super.buttonPressed(buttonId);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResourceRuleFactory(org.eclipse.core.resources.IResourceRuleFactory) Job(org.eclipse.core.runtime.jobs.Job) DeleteServerDialogExtension(org.eclipse.wst.server.ui.DeleteServerDialogExtension) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 3 with DeleteServerDialogExtension

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

the class DeleteServerDialog method createCustomArea.

/**
 */
protected Control createCustomArea(Composite parent) {
    // create a composite with standard margins and spacing
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setFont(parent.getFont());
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ContextIds.DELETE_SERVER_DIALOG);
    if (configs.length > 0) {
        checkDeleteConfigs = new Button(composite, SWT.CHECK);
        checkDeleteConfigs.setText(NLS.bind(Messages.deleteServerDialogLooseConfigurations, configs[0].getName()));
        checkDeleteConfigs.setSelection(true);
    }
    // prompt for stopping running servers
    int size = runningServersList.size();
    if (size > 0) {
        if (servers.length > 1) {
            checkDeleteRunning = new Button(composite, SWT.CHECK);
            checkDeleteRunning.setText(Messages.deleteServerDialogRunningServer);
            checkDeleteRunning.setSelection(true);
        }
        if (runningServerCanStop) {
            checkDeleteRunningStop = new Button(composite, SWT.CHECK);
            checkDeleteRunningStop.setText(Messages.deleteServerDialogRunningServerStop);
            checkDeleteRunningStop.setSelection(true);
            GridData data = new GridData();
            if (checkDeleteRunning != null) {
                // Only indent the checkbox if the delete running servers checkbox is available.
                data.horizontalIndent = 15;
                checkDeleteRunning.addSelectionListener(new SelectionAdapter() {

                    public void widgetSelected(SelectionEvent e) {
                        checkDeleteRunningStop.setEnabled(checkDeleteRunning.getSelection());
                    }
                });
            }
            checkDeleteRunningStop.setLayoutData(data);
        }
    }
    List<DeleteServerDialogExtension> fullDialogExtensionLst = ServerUIPlugin.getDeleteServerDialogExtensions();
    // Add the dialog extension UI.
    for (DeleteServerDialogExtension curDialogExtension : fullDialogExtensionLst) {
        curDialogExtension.setServers(servers);
        if (curDialogExtension.isEnabled()) {
            dialogExtensionLst.add(curDialogExtension);
            curDialogExtension.createControl(composite);
        }
    }
    Dialog.applyDialogFont(composite);
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DeleteServerDialogExtension(org.eclipse.wst.server.ui.DeleteServerDialogExtension)

Aggregations

DeleteServerDialogExtension (org.eclipse.wst.server.ui.DeleteServerDialogExtension)3 IResourceRuleFactory (org.eclipse.core.resources.IResourceRuleFactory)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 Job (org.eclipse.core.runtime.jobs.Job)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1