Search in sources :

Example 1 with ILaunchesListener2

use of org.eclipse.debug.core.ILaunchesListener2 in project webtools.servertools by eclipse.

the class ServerPropertiesEditorSection method init.

public void init(final IEditorSite site, IEditorInput input) {
    super.init(site, input);
    if (server != null) {
        fServer = (GenericServer) server.loadAdapter(GenericServer.class, new NullProgressMonitor());
    }
    fPropertyChangeListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals(GenericServerRuntime.SERVER_INSTANCE_PROPERTIES)) {
                if (!fUpdating) {
                    fUpdating = true;
                    updateControls();
                    fUpdating = false;
                }
            }
        }
    };
    server.addPropertyChangeListener(fPropertyChangeListener);
    fLaunchListener = new ILaunchesListener2() {

        public void launchesRemoved(ILaunch[] launches) {
        // Nothing to do
        }

        private ILaunchConfiguration getServerLaunchConfig(ILaunch[] launches) {
            for (int i = 0; i < launches.length; i++) {
                ILaunchConfiguration launchConfig = launches[i].getLaunchConfiguration();
                if (launchConfig != null) {
                    String serverId;
                    try {
                        serverId = launchConfig.getAttribute(GenericServerBehaviour.ATTR_SERVER_ID, (String) null);
                        if (fServer.getServer().getId().equals(serverId)) {
                            return launchConfig;
                        }
                    } catch (CoreException e) {
                    // Ignore
                    }
                }
            }
            return null;
        }

        public void launchesChanged(ILaunch[] launches) {
        // Nothing to do
        }

        public void launchesAdded(ILaunch[] launches) {
            ILaunchConfiguration lc = getServerLaunchConfig(launches);
            try {
                if (lc != null) {
                    if ("true".equals(lc.getAttribute(GenericServerBehaviour.ATTR_STOP, "false"))) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        site.getWorkbenchWindow().getWorkbench().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                IManagedForm managedForm = getManagedForm();
                                managedForm.getMessageManager().removeMessage(MESSAGE_ID_SERVER_RUNNING);
                                managedForm.getMessageManager().update();
                            }
                        });
                    } else {
                        site.getWorkbenchWindow().getWorkbench().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                getManagedForm().getMessageManager().addMessage(MESSAGE_ID_SERVER_RUNNING, GenericServerUIMessages.serverRunningCanNotSave, null, IMessageProvider.WARNING);
                            }
                        });
                    }
                }
            } catch (CoreException e) {
                GenericUiPlugin.getDefault().getLog().log(e.getStatus());
            }
        }

        public void launchesTerminated(ILaunch[] launches) {
            if (getServerLaunchConfig(launches) != null) {
                site.getWorkbenchWindow().getWorkbench().getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        getManagedForm().getMessageManager().removeMessage(MESSAGE_ID_SERVER_RUNNING);
                    }
                });
            }
        }
    };
    getLaunchManager().addLaunchListener(fLaunchListener);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PropertyChangeEvent(java.beans.PropertyChangeEvent) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) PropertyChangeListener(java.beans.PropertyChangeListener) CoreException(org.eclipse.core.runtime.CoreException) IManagedForm(org.eclipse.ui.forms.IManagedForm) ILaunch(org.eclipse.debug.core.ILaunch) ILaunchesListener2(org.eclipse.debug.core.ILaunchesListener2)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ILaunch (org.eclipse.debug.core.ILaunch)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ILaunchesListener2 (org.eclipse.debug.core.ILaunchesListener2)1 IManagedForm (org.eclipse.ui.forms.IManagedForm)1