Author: rombert
Date: Fri Jul 19 15:03:07 2013
New Revision: 1504901

URL: http://svn.apache.org/r1504901
Log:
SLING-2973 - [Tooling] Align Eclipse tooling to proposed structure

Persist configuration changes made to the server.

Added:
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerContextPathCommand.java
   (with props)
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerPasswordCommand.java
   (with props)
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerUsernameCommand.java
   (with props)
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerPortCommand.java
   (with props)
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerStringPropertyCommand.java
   (with props)
Modified:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ConnectionEditorSection.java

Modified: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF?rev=1504901&r1=1504900&r2=1504901&view=diff
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF 
(original)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF 
Fri Jul 19 15:03:07 2013
@@ -8,6 +8,8 @@ Bundle-ClassPath: .
 Import-Package: org.apache.sling.slingclipse,
  org.apache.sling.slingclipse.api,
  org.apache.sling.slingclipse.helper,
+ org.eclipse.core.commands,
+ org.eclipse.core.commands.operations,
  org.eclipse.core.resources,
  org.eclipse.core.runtime;version="3.4.0",
  org.eclipse.core.runtime.jobs,

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerContextPathCommand.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerContextPathCommand.java?rev=1504901&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerContextPathCommand.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerContextPathCommand.java
 Fri Jul 19 15:03:07 2013
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.wst.internal;
+
+import 
org.apache.sling.ide.eclipse.wst.ui.internal.SetServerStringPropertyCommand;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+public class SetServerContextPathCommand extends 
SetServerStringPropertyCommand {
+
+    public SetServerContextPathCommand(IServerWorkingCopy server, String 
newValue) {
+        super(server, SlingLaunchpadServer.PROP_CONTEXT_PATH, newValue, "/");
+    }
+
+}

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerContextPathCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerContextPathCommand.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerPasswordCommand.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerPasswordCommand.java?rev=1504901&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerPasswordCommand.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerPasswordCommand.java
 Fri Jul 19 15:03:07 2013
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.wst.internal;
+
+import 
org.apache.sling.ide.eclipse.wst.ui.internal.SetServerStringPropertyCommand;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+public class SetServerPasswordCommand extends SetServerStringPropertyCommand {
+
+    public SetServerPasswordCommand(IServerWorkingCopy server, String 
newValue) {
+        super(server, SlingLaunchpadServer.PROP_PASSWORD, newValue, "admin");
+    }
+
+}

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerPasswordCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerPasswordCommand.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerUsernameCommand.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerUsernameCommand.java?rev=1504901&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerUsernameCommand.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerUsernameCommand.java
 Fri Jul 19 15:03:07 2013
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.wst.internal;
+
+import 
org.apache.sling.ide.eclipse.wst.ui.internal.SetServerStringPropertyCommand;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+public class SetServerUsernameCommand extends SetServerStringPropertyCommand {
+
+    public SetServerUsernameCommand(IServerWorkingCopy server, String 
newValue) {
+        super(server, SlingLaunchpadServer.PROP_USERNAME, newValue, "admin");
+    }
+
+}

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerUsernameCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SetServerUsernameCommand.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java?rev=1504901&r1=1504900&r2=1504901&view=diff
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java
 (original)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadConfiguration.java
 Fri Jul 19 15:03:07 2013
@@ -16,93 +16,46 @@
  */
 package org.apache.sling.ide.eclipse.wst.internal;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
 
 public class SlingLaunchpadConfiguration {
 
-    private final IFolder path;
-
-    private int port = 8080;
-    private String contextPath = "/";
-    private String username = "admin";
-    private String password = "admin";
-
-    public SlingLaunchpadConfiguration(IFolder path) {
-        this.path = path;
-    }
-
-    public void load(IProgressMonitor monitor) {
-
-        IFile configFile = path.getFile("config.ini");
-        if (!configFile.exists()) {
-            return;
-        }
-
-        Properties p = new Properties();
-        InputStream contents = null;
-        try {
-            contents = configFile.getContents();
-            p.load(contents);
-
-            port = Integer.parseInt(p.getProperty("launchpad.port"));
-            contextPath = p.getProperty("launchpad.contextPath", "/");
-            username = p.getProperty("launchpad.username");
-            password = p.getProperty("launchpad.password");
-
-        } catch (CoreException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } finally {
-            try {
-                contents.close();
-            } catch (IOException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-        }
+    private SlingLaunchpadServer server;
 
+    public SlingLaunchpadConfiguration(SlingLaunchpadServer server) {
+        this.server = server;
     }
 
     public int getPort() {
-        return port;
+        // TODO central place for setting defaults
+        return 
server.getServerWorkingCopy().getAttribute(SlingLaunchpadServer.PROP_PORT, 
8080);
     }
 
     public void setPort(int port) {
-        this.port = port;
+        
server.getServerWorkingCopy().setAttribute(SlingLaunchpadServer.PROP_PORT, 
port);
     }
 
     public String getContextPath() {
-        return contextPath;
+        return 
server.getServerWorkingCopy().getAttribute(SlingLaunchpadServer.PROP_CONTEXT_PATH,
 "/");
     }
 
     public void setContextPath(String contextPath) {
-        this.contextPath = contextPath;
+        
server.getServerWorkingCopy().setAttribute(SlingLaunchpadServer.PROP_CONTEXT_PATH,
 contextPath);
     }
 
     public String getUsername() {
-        return username;
+        return 
server.getServerWorkingCopy().getAttribute(SlingLaunchpadServer.PROP_USERNAME, 
"admin");
     }
 
     public void setUsername(String username) {
-        this.username = username;
+        
server.getServerWorkingCopy().setAttribute(SlingLaunchpadServer.PROP_USERNAME, 
username);
     }
 
     public String getPassword() {
-        return password;
+        return 
server.getServerWorkingCopy().getAttribute(SlingLaunchpadServer.PROP_PASSWORD, 
"admin");
     }
 
     public void setPassword(String password) {
-        this.password = password;
+        
server.getServerWorkingCopy().setAttribute(SlingLaunchpadServer.PROP_PASSWORD, 
password);
     }
 
 }

Modified: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java?rev=1504901&r1=1504900&r2=1504901&view=diff
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java
 (original)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java
 Fri Jul 19 15:03:07 2013
@@ -16,18 +16,22 @@
  */
 package org.apache.sling.ide.eclipse.wst.internal;
 
-import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.model.ServerDelegate;
 
 public class SlingLaunchpadServer extends ServerDelegate {
 
+    public static final String PROP_PASSWORD = "launchpad.password";
+    public static final String PROP_USERNAME = "launchpad.username";
+    public static final String PROP_CONTEXT_PATH = "launchpad.contextPath";
+    public static final String PROP_PORT = "launchpad.port";
+
     private static final String MODULE_TYPE_SLING_CONTENT = "sling.content";
+
     private SlingLaunchpadConfiguration config;
 
     public SlingLaunchpadConfiguration getConfiguration() {
@@ -36,12 +40,7 @@ public class SlingLaunchpadServer extend
             return config;
         }
 
-        IFolder folder = getServer().getServerConfiguration();
-
-        config = new SlingLaunchpadConfiguration(folder);
-        config.load(new NullProgressMonitor()); // TODO progress monitor
-
-        return config;
+        return config = new SlingLaunchpadConfiguration(this);
 
     }
 
@@ -122,4 +121,13 @@ public class SlingLaunchpadServer extend
         }
     }
 
+    @Override
+    public void setDefaults(IProgressMonitor monitor) {
+
+        setAttribute(PROP_PORT, 8080);
+        setAttribute(PROP_CONTEXT_PATH, "/");
+        setAttribute(PROP_USERNAME, "admin");
+        setAttribute(PROP_PASSWORD, "admin");
+    }
+
 }

Modified: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ConnectionEditorSection.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ConnectionEditorSection.java?rev=1504901&r1=1504900&r2=1504901&view=diff
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ConnectionEditorSection.java
 (original)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ConnectionEditorSection.java
 Fri Jul 19 15:03:07 2013
@@ -16,25 +16,29 @@
  */
 package org.apache.sling.ide.eclipse.wst.ui.internal;
 
+import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 
+import org.apache.sling.ide.eclipse.wst.internal.SetServerContextPathCommand;
+import org.apache.sling.ide.eclipse.wst.internal.SetServerPasswordCommand;
+import org.apache.sling.ide.eclipse.wst.internal.SetServerUsernameCommand;
 import org.apache.sling.ide.eclipse.wst.internal.SlingLaunchpadConfiguration;
 import org.apache.sling.ide.eclipse.wst.internal.SlingLaunchpadServer;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.forms.IFormColors;
 import org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.ui.forms.IFormColors;
 import org.eclipse.wst.server.ui.editor.ServerEditorSection;
 
 public class ConnectionEditorSection extends ServerEditorSection {
@@ -46,6 +50,7 @@ public class ConnectionEditorSection ext
     private Text usernameText;
     private Text passwordText;
     private SlingLaunchpadServer launchpadServer;
+    private PropertyChangeListener serverListener;
 
     @Override
     public void createSection(Composite parent) {
@@ -113,6 +118,25 @@ public class ConnectionEditorSection ext
     public void init(IEditorSite site, IEditorInput input) {
         super.init(site, input);
 
+        serverListener = new PropertyChangeListener() {
+
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+
+                if 
(SlingLaunchpadServer.PROP_PORT.equals(evt.getPropertyName())) {
+                    portText.setText(((Integer) evt.getNewValue()).toString());
+                } else if 
(SlingLaunchpadServer.PROP_CONTEXT_PATH.equals(evt.getPropertyName())) {
+                    contextPathText.setText((String) evt.getNewValue());
+                } else if 
(SlingLaunchpadServer.PROP_USERNAME.equals(evt.getPropertyName())) {
+                    usernameText.setText((String) evt.getNewValue());
+                } else if 
(SlingLaunchpadServer.PROP_PASSWORD.equals(evt.getPropertyName())) {
+                    passwordText.setText((String) evt.getNewValue());
+                }
+            }
+        };
+
+        server.addPropertyChangeListener(serverListener);
+
         launchpadServer = (SlingLaunchpadServer) 
server.getAdapter(SlingLaunchpadServer.class);
         if (launchpadServer == null) {
             // TODO progress monitor
@@ -131,19 +155,43 @@ public class ConnectionEditorSection ext
         usernameText.setText(config.getUsername());
         passwordText.setText(config.getPassword());
 
-        portText.addModifyListener(new ModifyListener() {
-
+        ModifyListener listener = new ModifyListener() {
             @Override
             public void modifyText(ModifyEvent e) {
-
-                try {
-                    config.setPort(Integer.parseInt(portText.getText()));
-                    // TODO persist change
-                } catch (NumberFormatException ex) {
-                    // shucks
+                if (e.getSource() == portText) {
+                    try {
+                        int port = Integer.parseInt(portText.getText());
+                        execute(new SetServerPortCommand(server, port));
+                    } catch (NumberFormatException ex) {
+                        // shucks
+                    }
+                } else if (e.getSource() == contextPathText) {
+                    execute(new SetServerContextPathCommand(server, 
contextPathText.getText()));
+                } else if (e.getSource() == usernameText) {
+                    execute(new SetServerUsernameCommand(server, 
usernameText.getText()));
+                } else if (e.getSource() == passwordText) {
+                    execute(new SetServerPasswordCommand(server, 
passwordText.getText()));
                 }
             }
-        });
+        };
+
+        for (Text text : new Text[] { portText, contextPathText, usernameText, 
passwordText }) {
+            text.addModifyListener(listener);
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.wst.server.ui.editor.ServerEditorSection#dispose()
+     */
+    @Override
+    public void dispose() {
+        if (server != null)
+            server.removePropertyChangeListener(serverListener);
+
+        super.dispose();
     }
 
 }

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerPortCommand.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerPortCommand.java?rev=1504901&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerPortCommand.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerPortCommand.java
 Fri Jul 19 15:03:07 2013
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.wst.ui.internal;
+
+import org.apache.sling.ide.eclipse.wst.internal.SlingLaunchpadServer;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+public class SetServerPortCommand extends AbstractOperation {
+
+    private IServerWorkingCopy server;
+    private int port;
+    private int oldValue;
+
+    public SetServerPortCommand(IServerWorkingCopy server, int port) {
+        super("Setting server port...");
+        this.server = server;
+        this.port = port;
+    }
+
+    @Override
+    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        oldValue = server.getAttribute(SlingLaunchpadServer.PROP_PORT, 8080);
+
+        server.setAttribute(SlingLaunchpadServer.PROP_PORT, port);
+
+        return Status.OK_STATUS;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see 
org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor,
+     * org.eclipse.core.runtime.IAdaptable)
+     */
+    @Override
+    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        return execute(monitor, info);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see 
org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor,
+     * org.eclipse.core.runtime.IAdaptable)
+     */
+    @Override
+    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        server.setAttribute(SlingLaunchpadServer.PROP_PORT, oldValue);
+
+        return Status.OK_STATUS;
+    }
+
+}

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerPortCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerPortCommand.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerStringPropertyCommand.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerStringPropertyCommand.java?rev=1504901&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerStringPropertyCommand.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerStringPropertyCommand.java
 Fri Jul 19 15:03:07 2013
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.wst.ui.internal;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+public abstract class SetServerStringPropertyCommand extends AbstractOperation 
{
+
+    private IServerWorkingCopy server;
+    private String newValue;
+    private String propertyName;
+    private String defaultValue;
+    private String oldValue;
+
+    public SetServerStringPropertyCommand(IServerWorkingCopy server, String 
propertyName, String newValue,
+            String defaultValue) {
+        super("Setting property " + propertyName + " ...");
+
+        this.server = server;
+        this.propertyName = propertyName;
+        this.newValue = newValue;
+        this.defaultValue = defaultValue;
+    }
+
+    @Override
+    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        oldValue = server.getAttribute(propertyName, defaultValue);
+
+        server.setAttribute(propertyName, newValue);
+
+        return Status.OK_STATUS;
+    }
+
+    @Override
+    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        return execute(monitor, info);
+    }
+
+    @Override
+    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws 
ExecutionException {
+        server.setAttribute(propertyName, oldValue);
+
+        return Status.OK_STATUS;
+    }
+
+}

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerStringPropertyCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SetServerStringPropertyCommand.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL


Reply via email to