Search in sources :

Example 1 with PublishAdapter

use of org.eclipse.wst.server.core.util.PublishAdapter in project webtools.servertools by eclipse.

the class ServerLocationEditorSection method addChangeListeners.

/**
 * Add listeners to detect undo changes and publishing of the server.
 */
protected void addChangeListeners() {
    listener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (updating)
                return;
            updating = true;
            if (ITomcatServer.PROPERTY_INSTANCE_DIR.equals(event.getPropertyName()) || ITomcatServer.PROPERTY_TEST_ENVIRONMENT.equals(event.getPropertyName())) {
                updateServerDirButtons();
                updateServerDirFields();
                validate();
            } else if (ITomcatServer.PROPERTY_DEPLOY_DIR.equals(event.getPropertyName())) {
                String s = (String) event.getNewValue();
                ServerLocationEditorSection.this.deployDir.setText(s);
                updateDefaultDeployLink();
                validate();
            }
            updating = false;
        }
    };
    server.addPropertyChangeListener(listener);
    publishListener = new PublishAdapter() {

        public void publishFinished(IServer server2, IStatus status) {
            boolean flag = false;
            if (status.isOK() && server2.getModules().length == 0)
                flag = true;
            if (flag != allowRestrictedEditing) {
                allowRestrictedEditing = flag;
                // Update the state of the fields
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        boolean customServerDir = false;
                        if (!ServerLocationEditorSection.this.serverDirCustom.isDisposed())
                            customServerDir = ServerLocationEditorSection.this.serverDirCustom.getSelection();
                        if (!ServerLocationEditorSection.this.serverDirMetadata.isDisposed())
                            ServerLocationEditorSection.this.serverDirMetadata.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.serverDirInstall.isDisposed())
                            ServerLocationEditorSection.this.serverDirInstall.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.serverDirCustom.isDisposed())
                            ServerLocationEditorSection.this.serverDirCustom.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.serverDir.isDisposed())
                            ServerLocationEditorSection.this.serverDir.setEnabled(allowRestrictedEditing && customServerDir);
                        if (!ServerLocationEditorSection.this.serverDirBrowse.isDisposed())
                            ServerLocationEditorSection.this.serverDirBrowse.setEnabled(allowRestrictedEditing && customServerDir);
                        if (!ServerLocationEditorSection.this.setDefaultDeployDir.isDisposed())
                            ServerLocationEditorSection.this.setDefaultDeployDir.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.deployDir.isDisposed())
                            ServerLocationEditorSection.this.deployDir.setEnabled(allowRestrictedEditing);
                        if (!ServerLocationEditorSection.this.deployDirBrowse.isDisposed())
                            ServerLocationEditorSection.this.deployDirBrowse.setEnabled(allowRestrictedEditing);
                    }
                });
            }
        }
    };
    server.getOriginal().addPublishListener(publishListener);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) PropertyChangeListener(java.beans.PropertyChangeListener) PublishAdapter(org.eclipse.wst.server.core.util.PublishAdapter)

Example 2 with PublishAdapter

use of org.eclipse.wst.server.core.util.PublishAdapter in project webtools.servertools by eclipse.

the class ServerTableViewer method addListeners.

protected void addListeners() {
    serverResourceListener = new IServerLifecycleListener() {

        public void serverAdded(IServer server) {
            addServer(server);
            server.addServerListener(serverListener);
            ((Server) server).addPublishListener(publishListener);
        }

        public void serverChanged(IServer server) {
            refreshServer(server);
        }

        public void serverRemoved(IServer server) {
            removeServer(server);
            server.removeServerListener(serverListener);
            ((Server) server).removePublishListener(publishListener);
        }
    };
    ServerCore.addServerLifecycleListener(serverResourceListener);
    publishListener = new PublishAdapter() {

        public void publishStarted(IServer server) {
            handlePublishChange(server, true);
        }

        public void publishFinished(IServer server, IStatus status) {
            handlePublishChange(server, false);
        }
    };
    serverListener = new IServerListener() {

        public void serverChanged(ServerEvent event) {
            if (event == null)
                return;
            int eventKind = event.getKind();
            IServer server = event.getServer();
            if ((eventKind & ServerEvent.SERVER_CHANGE) != 0) {
                // server change event
                if ((eventKind & ServerEvent.STATE_CHANGE) != 0) {
                    refreshServer(server);
                    int state = event.getState();
                    String id = server.getId();
                    if (state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING) {
                        boolean startThread = false;
                        synchronized (starting) {
                            if (!starting.contains(id)) {
                                if (starting.isEmpty())
                                    startThread = true;
                                starting.add(id);
                            }
                        }
                        if (startThread)
                            startThread();
                    } else {
                        boolean stopThread = false;
                        synchronized (starting) {
                            if (starting.contains(id)) {
                                starting.remove(id);
                                if (starting.isEmpty())
                                    stopThread = true;
                            }
                        }
                        if (stopThread)
                            stopThread();
                    }
                } else
                    refreshServer(server);
            } else if ((eventKind & ServerEvent.MODULE_CHANGE) != 0) {
                // module change event
                if ((eventKind & ServerEvent.STATE_CHANGE) != 0 || (eventKind & ServerEvent.PUBLISH_STATE_CHANGE) != 0) {
                    refreshServer(server);
                }
            }
        }
    };
    // add listeners to servers
    IServer[] servers = ServerCore.getServers();
    if (servers != null) {
        int size = servers.length;
        for (int i = 0; i < size; i++) {
            servers[i].addServerListener(serverListener);
            ((Server) servers[i]).addPublishListener(publishListener);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Server(org.eclipse.wst.server.core.internal.Server) PublishAdapter(org.eclipse.wst.server.core.util.PublishAdapter)

Example 3 with PublishAdapter

use of org.eclipse.wst.server.core.util.PublishAdapter in project webtools.servertools by eclipse.

the class ServersView2 method addListener.

protected void addListener() {
    // To enable the UI updating of servers and its childrens
    serverResourceListener = new IServerLifecycleListener() {

        public void serverAdded(IServer server) {
            addServer(server);
            server.addServerListener(serverListener);
            ((Server) server).addPublishListener(publishListener);
        }

        public void serverChanged(IServer server) {
            refreshServerContent(server);
        }

        public void serverRemoved(IServer server) {
            removeServer(server);
            server.removeServerListener(serverListener);
            ((Server) server).removePublishListener(publishListener);
        }
    };
    ServerCore.addServerLifecycleListener(serverResourceListener);
    // To enable the refresh of the State decorator
    publishListener = new PublishAdapter() {

        public void publishStarted(IServer server) {
            handlePublishChange(server, true);
        }

        public void publishFinished(IServer server, IStatus status) {
            handlePublishChange(server, false);
        }
    };
    serverListener = new IServerListener() {

        public void serverChanged(ServerEvent event) {
            if (event == null)
                return;
            int eventKind = event.getKind();
            IServer server = event.getServer();
            if ((eventKind & ServerEvent.SERVER_CHANGE) != 0) {
                // server change event
                if ((eventKind & ServerEvent.STATE_CHANGE) != 0) {
                    int state = event.getState();
                    String id = server.getId();
                    if (state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING) {
                        boolean startThread = false;
                        synchronized (starting) {
                            if (!starting.contains(id)) {
                                if (starting.isEmpty())
                                    startThread = true;
                                starting.add(id);
                            }
                        }
                        if (startThread)
                            startThread();
                    } else {
                        boolean stopThread = false;
                        synchronized (starting) {
                            if (starting.contains(id)) {
                                starting.remove(id);
                                if (starting.isEmpty())
                                    stopThread = true;
                            }
                        }
                        if (stopThread)
                            stopThread();
                    }
                    refreshServerState(server);
                    refreshServerContent(server);
                } else if ((eventKind & ServerEvent.PUBLISH_STATE_CHANGE) != 0 || (eventKind & ServerEvent.STATUS_CHANGE) != 0) {
                    refreshServerState(server);
                }
            } else if ((eventKind & ServerEvent.MODULE_CHANGE) != 0) {
                // module change event
                if ((eventKind & ServerEvent.STATE_CHANGE) != 0 || (eventKind & ServerEvent.PUBLISH_STATE_CHANGE) != 0 || (eventKind & ServerEvent.STATUS_CHANGE) != 0) {
                    refreshServerContent(server);
                }
            }
        // TODO Angel Says: I don't think we need this
        // refreshServer(server);
        }
    };
    // add listeners to servers
    IServer[] servers = ServerCore.getServers();
    if (servers != null) {
        int size = servers.length;
        for (int i = 0; i < size; i++) {
            servers[i].addServerListener(serverListener);
            ((Server) servers[i]).addPublishListener(publishListener);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Server(org.eclipse.wst.server.core.internal.Server) PublishAdapter(org.eclipse.wst.server.core.util.PublishAdapter) Point(org.eclipse.swt.graphics.Point)

Example 4 with PublishAdapter

use of org.eclipse.wst.server.core.util.PublishAdapter in project webtools.servertools by eclipse.

the class PublishAdapterTestCase method testListener.

public void testListener() {
    PublishAdapter listener = new PublishAdapter();
    listener.publishStarted(null);
    listener.publishFinished(null, null);
}
Also used : PublishAdapter(org.eclipse.wst.server.core.util.PublishAdapter)

Example 5 with PublishAdapter

use of org.eclipse.wst.server.core.util.PublishAdapter in project liferay-ide by liferay.

the class LiferayServerSettingsEditorSection method addChangeListeners.

protected void addChangeListeners() {
    listener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (updating) {
                return;
            }
            updating = true;
            if (ITomcatServer.PROPERTY_INSTANCE_DIR.equals(event.getPropertyName()) || ITomcatServer.PROPERTY_TEST_ENVIRONMENT.equals(event.getPropertyName())) {
                updateServerDirButtons();
                updateServerDirFields();
                validate();
            } else if (ILiferayTomcatServer.PROPERTY_MEMORY_ARGS.equals(event.getPropertyName())) {
                String s = (String) event.getNewValue();
                LiferayServerSettingsEditorSection.this.memoryArgs.setText(s);
                validate();
            } else if (ILiferayTomcatServer.PROPERTY_USER_TIMEZONE.equals(event.getPropertyName())) {
                String s = (String) event.getNewValue();
                LiferayServerSettingsEditorSection.this.userTimezone.setText(s);
                validate();
            } else if (ILiferayTomcatServer.PROPERTY_EXTERNAL_PROPERTIES.equals(event.getPropertyName())) {
                String s = (String) event.getNewValue();
                LiferayServerSettingsEditorSection.this.externalProperties.setText(s);
                validate();
            } else if (ILiferayTomcatServer.PROPERTY_SERVER_MODE.equals(event.getPropertyName())) {
                int s = (Integer) event.getNewValue();
                standardServerMode.setSelection(s == ILiferayTomcatConstants.STANDARD_SERVER_MODE);
                developmentServerMode.setSelection(s == ILiferayTomcatConstants.DEVELOPMENT_SERVER_MODE);
                validate();
            } else if (ILiferayTomcatServer.PROPERTY_USE_DEFAULT_PORTAL_SERVER_SETTINGS.equals(event.getPropertyName())) {
                boolean s = (Boolean) event.getNewValue();
                useDefaultPortalServerSettings.setSelection(s);
                validate();
            }
            updating = false;
        }
    };
    server.addPropertyChangeListener(listener);
    publishListener = new PublishAdapter() {

        public void publishFinished(IServer server2, IStatus status) {
            boolean flag = false;
            if (status.isOK() && (server2.getModules().length == 0)) {
                flag = true;
            }
            if (flag != allowRestrictedEditing) {
                allowRestrictedEditing = flag;
            }
        }
    };
    server.getOriginal().addPublishListener(publishListener);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) PropertyChangeListener(java.beans.PropertyChangeListener) PublishAdapter(org.eclipse.wst.server.core.util.PublishAdapter)

Aggregations

PublishAdapter (org.eclipse.wst.server.core.util.PublishAdapter)6 IStatus (org.eclipse.core.runtime.IStatus)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3 IServer (org.eclipse.wst.server.core.IServer)3 Server (org.eclipse.wst.server.core.internal.Server)2 Point (org.eclipse.swt.graphics.Point)1