chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1432208 - /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/
Date Fri, 11 Jan 2013 18:22:47 GMT
Author: fmui
Date: Fri Jan 11 18:22:47 2013
New Revision: 1432208

URL: http://svn.apache.org/viewvc?rev=1432208&view=rev
Log:
Workbench: login tabs are now pluggable

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractLoginTab.java
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractSpringLoginTab.java
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/BasicLoginTab.java
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
  (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractLoginTab.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractLoginTab.java?rev=1432208&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractLoginTab.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractLoginTab.java
Fri Jan 11 18:22:47 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.chemistry.opencmis.workbench;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.JPanel;
+
+import org.apache.chemistry.opencmis.client.api.Repository;
+import org.apache.chemistry.opencmis.client.api.Session;
+
+/**
+ * Abstract Login Tab.
+ * 
+ * To add a new login tab, derive a class from this class, create a file
+ * <code>META-INF/services/org.apache.chemistry.opencmis.workbench.AbstractLoginTab</code>
+ * , and put the name of the fully qualified name of your class into this file.
+ */
+public abstract class AbstractLoginTab extends JPanel {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Returns the title of the tab.
+     */
+    public abstract String getTabTitle();
+
+    /**
+     * Returns the session parameters when the user hits the "Load Repositories"
+     * button.
+     */
+    public abstract Map<String, String> getSessionParameters();
+
+    /**
+     * Defines if the session parameters should be transfered to the expert tab
+     * when the user switches from the this tab to the expert tab. The default
+     * is <code>false</code>.
+     */
+    public boolean transferSessionParametersToExpertTab() {
+        return false;
+    }
+
+    /**
+     * Called after the list of repositories has been loaded.
+     */
+    public void repositoriesLoaded(List<Repository> repositories) {
+    }
+
+    /**
+     * Called after the Workbench session has been created.
+     */
+    public void loggedIn(Session session) {
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractLoginTab.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractSpringLoginTab.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractSpringLoginTab.java?rev=1432208&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractSpringLoginTab.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractSpringLoginTab.java
Fri Jan 11 18:22:47 2013
@@ -0,0 +1,98 @@
+/*
+ * 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.chemistry.opencmis.workbench;
+
+import java.awt.Component;
+import java.awt.Container;
+
+import javax.swing.JLabel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextField;
+import javax.swing.Spring;
+import javax.swing.SpringLayout;
+
+/**
+ * Convenience methods for spring layout tabs.
+ */
+public abstract class AbstractSpringLoginTab extends AbstractLoginTab {
+
+    private static final long serialVersionUID = 1L;
+
+    protected JTextField createTextField(Container pane, String label) {
+        JTextField textField = new JTextField(60);
+        JLabel textLabel = new JLabel(label, JLabel.TRAILING);
+        textLabel.setLabelFor(textField);
+
+        pane.add(textLabel);
+        pane.add(textField);
+
+        return textField;
+    }
+
+    protected JPasswordField createPasswordField(Container pane, String label) {
+        JPasswordField textField = new JPasswordField(60);
+        JLabel textLabel = new JLabel(label, JLabel.TRAILING);
+        textLabel.setLabelFor(textField);
+
+        pane.add(textLabel);
+        pane.add(textField);
+
+        return textField;
+    }
+
+    private SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent,
int cols) {
+        SpringLayout layout = (SpringLayout) parent.getLayout();
+        Component c = parent.getComponent(row * cols + col);
+        return layout.getConstraints(c);
+    }
+
+    protected void makeCompactGrid(Container parent, int rows, int cols, int initialX, int
initialY, int xPad, int yPad) {
+        SpringLayout layout = (SpringLayout) parent.getLayout();
+
+        Spring x = Spring.constant(initialX);
+        for (int c = 0; c < cols; c++) {
+            Spring width = Spring.constant(0);
+            for (int r = 0; r < rows; r++) {
+                width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
+            }
+            for (int r = 0; r < rows; r++) {
+                SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent,
cols);
+                constraints.setX(x);
+                constraints.setWidth(width);
+            }
+            x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
+        }
+
+        Spring y = Spring.constant(initialY);
+        for (int r = 0; r < rows; r++) {
+            Spring height = Spring.constant(0);
+            for (int c = 0; c < cols; c++) {
+                height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
+            }
+            for (int c = 0; c < cols; c++) {
+                SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent,
cols);
+                constraints.setY(y);
+                constraints.setHeight(height);
+            }
+            y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
+        }
+
+        layout.getConstraints(parent).setConstraint(SpringLayout.EAST, x);
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/AbstractSpringLoginTab.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/BasicLoginTab.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/BasicLoginTab.java?rev=1432208&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/BasicLoginTab.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/BasicLoginTab.java
Fri Jan 11 18:22:47 2013
@@ -0,0 +1,236 @@
+/*
+ * 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.chemistry.opencmis.workbench;
+
+import java.awt.Container;
+import java.awt.Dimension;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.ButtonGroup;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+import javax.swing.SpringLayout;
+
+import org.apache.chemistry.opencmis.commons.enums.BindingType;
+import org.apache.chemistry.opencmis.workbench.model.ClientSession;
+
+public class BasicLoginTab extends AbstractSpringLoginTab {
+
+    private static final long serialVersionUID = 1L;
+
+    public static final String SYSPROP_URL = ClientSession.WORKBENCH_PREFIX + "url";
+    public static final String SYSPROP_BINDING = ClientSession.WORKBENCH_PREFIX + "binding";
+    public static final String SYSPROP_AUTHENTICATION = ClientSession.WORKBENCH_PREFIX +
"authentication";
+    public static final String SYSPROP_COMPRESSION = ClientSession.WORKBENCH_PREFIX + "compression";
+    public static final String SYSPROP_CLIENTCOMPRESSION = ClientSession.WORKBENCH_PREFIX
+ "clientcompression";
+    public static final String SYSPROP_COOKIES = ClientSession.WORKBENCH_PREFIX + "cookies";
+    public static final String SYSPROP_USER = ClientSession.WORKBENCH_PREFIX + "user";
+    public static final String SYSPROP_PASSWORD = ClientSession.WORKBENCH_PREFIX + "password";
+
+    private JTextField urlField;
+    private JRadioButton bindingAtomButton;
+    private JRadioButton bindingWebServicesButton;
+    private JRadioButton bindingBrowserButton;
+    private JTextField usernameField;
+    private JPasswordField passwordField;
+    private JRadioButton authenticationNoneButton;
+    private JRadioButton authenticationStandardButton;
+    private JRadioButton authenticationNTLMButton;
+    private JRadioButton compressionOnButton;
+    private JRadioButton compressionOffButton;
+    private JRadioButton clientCompressionOnButton;
+    private JRadioButton clientCompressionOffButton;
+    private JRadioButton cookiesOnButton;
+    private JRadioButton cookiesOffButton;
+
+    public BasicLoginTab() {
+        super();
+        createGUI();
+    }
+
+    private void createGUI() {
+        setLayout(new SpringLayout());
+
+        urlField = createTextField(this, "URL:");
+        urlField.setText(System.getProperty(SYSPROP_URL, ""));
+
+        createBindingButtons(this);
+
+        usernameField = createTextField(this, "Username:");
+        usernameField.setText(System.getProperty(SYSPROP_USER, ""));
+
+        passwordField = createPasswordField(this, "Password:");
+        passwordField.setText(System.getProperty(SYSPROP_PASSWORD, ""));
+
+        createAuthenticationButtons(this);
+
+        createCompressionButtons(this);
+
+        createClientCompressionButtons(this);
+
+        createCookieButtons(this);
+
+        makeCompactGrid(this, 8, 2, 5, 10, 5, 5);
+    }
+
+    protected void createBindingButtons(Container pane) {
+        JPanel bindingContainer = new JPanel();
+        bindingContainer.setLayout(new BoxLayout(bindingContainer, BoxLayout.LINE_AXIS));
+        char bc = System.getProperty(SYSPROP_BINDING, "atom").toLowerCase(Locale.ENGLISH).charAt(0);
+        boolean atom = (bc == 'a');
+        boolean ws = (bc == 'w');
+        boolean browser = (bc == 'b');
+        bindingAtomButton = new JRadioButton("AtomPub", atom);
+        bindingWebServicesButton = new JRadioButton("Web Services", ws);
+        bindingBrowserButton = new JRadioButton("Browser", browser);
+        ButtonGroup bindingGroup = new ButtonGroup();
+        bindingGroup.add(bindingAtomButton);
+        bindingGroup.add(bindingWebServicesButton);
+        bindingGroup.add(bindingBrowserButton);
+        bindingContainer.add(bindingAtomButton);
+        bindingContainer.add(Box.createRigidArea(new Dimension(10, 0)));
+        bindingContainer.add(bindingWebServicesButton);
+        bindingContainer.add(Box.createRigidArea(new Dimension(10, 0)));
+        bindingContainer.add(bindingBrowserButton);
+        JLabel bindingLabel = new JLabel("Binding:", JLabel.TRAILING);
+
+        pane.add(bindingLabel);
+        pane.add(bindingContainer);
+    }
+
+    protected void createAuthenticationButtons(Container pane) {
+        JPanel authenticationContainer = new JPanel();
+        authenticationContainer.setLayout(new BoxLayout(authenticationContainer, BoxLayout.LINE_AXIS));
+        boolean standard = (System.getProperty(SYSPROP_AUTHENTICATION, "standard").toLowerCase(Locale.ENGLISH)
+                .equals("standard"));
+        boolean ntlm = (System.getProperty(SYSPROP_AUTHENTICATION, "").toLowerCase(Locale.ENGLISH).equals("ntlm"));
+        boolean none = !standard && !ntlm;
+        authenticationNoneButton = new JRadioButton("None", none);
+        authenticationStandardButton = new JRadioButton("Standard", standard);
+        authenticationNTLMButton = new JRadioButton("NTLM", ntlm);
+        ButtonGroup authenticationGroup = new ButtonGroup();
+        authenticationGroup.add(authenticationNoneButton);
+        authenticationGroup.add(authenticationStandardButton);
+        authenticationGroup.add(authenticationNTLMButton);
+        authenticationContainer.add(authenticationNoneButton);
+        authenticationContainer.add(Box.createRigidArea(new Dimension(10, 0)));
+        authenticationContainer.add(authenticationStandardButton);
+        authenticationContainer.add(Box.createRigidArea(new Dimension(10, 0)));
+        authenticationContainer.add(authenticationNTLMButton);
+        JLabel authenticatioLabel = new JLabel("Authentication:", JLabel.TRAILING);
+
+        pane.add(authenticatioLabel);
+        pane.add(authenticationContainer);
+    }
+
+    protected void createCompressionButtons(Container pane) {
+        JPanel compressionContainer = new JPanel();
+        compressionContainer.setLayout(new BoxLayout(compressionContainer, BoxLayout.LINE_AXIS));
+        boolean compression = !(System.getProperty(SYSPROP_COMPRESSION, "on").equalsIgnoreCase("off"));
+        compressionOnButton = new JRadioButton("On", compression);
+        compressionOffButton = new JRadioButton("Off", !compression);
+        ButtonGroup compressionGroup = new ButtonGroup();
+        compressionGroup.add(compressionOnButton);
+        compressionGroup.add(compressionOffButton);
+        compressionContainer.add(compressionOnButton);
+        compressionContainer.add(Box.createRigidArea(new Dimension(10, 0)));
+        compressionContainer.add(compressionOffButton);
+        JLabel compressionLabel = new JLabel("Compression:", JLabel.TRAILING);
+
+        pane.add(compressionLabel);
+        pane.add(compressionContainer);
+    }
+
+    protected void createClientCompressionButtons(Container pane) {
+        JPanel clientCompressionContainer = new JPanel();
+        clientCompressionContainer.setLayout(new BoxLayout(clientCompressionContainer, BoxLayout.LINE_AXIS));
+        boolean clientCompression = (System.getProperty(SYSPROP_CLIENTCOMPRESSION, "off").equalsIgnoreCase("on"));
+        clientCompressionOnButton = new JRadioButton("On", clientCompression);
+        clientCompressionOffButton = new JRadioButton("Off", !clientCompression);
+        ButtonGroup clientCompressionGroup = new ButtonGroup();
+        clientCompressionGroup.add(clientCompressionOnButton);
+        clientCompressionGroup.add(clientCompressionOffButton);
+        clientCompressionContainer.add(clientCompressionOnButton);
+        clientCompressionContainer.add(Box.createRigidArea(new Dimension(10, 0)));
+        clientCompressionContainer.add(clientCompressionOffButton);
+        JLabel clientCompressionLabel = new JLabel("Client Compression:", JLabel.TRAILING);
+
+        pane.add(clientCompressionLabel);
+        pane.add(clientCompressionContainer);
+    }
+
+    protected void createCookieButtons(Container pane) {
+        JPanel cookiesContainer = new JPanel();
+        cookiesContainer.setLayout(new BoxLayout(cookiesContainer, BoxLayout.LINE_AXIS));
+        boolean cookies = (System.getProperty(SYSPROP_COOKIES, "on").equalsIgnoreCase("on"));
+        cookiesOnButton = new JRadioButton("On", cookies);
+        cookiesOffButton = new JRadioButton("Off", !cookies);
+        ButtonGroup cookiesGroup = new ButtonGroup();
+        cookiesGroup.add(cookiesOnButton);
+        cookiesGroup.add(cookiesOffButton);
+        cookiesContainer.add(cookiesOnButton);
+        cookiesContainer.add(Box.createRigidArea(new Dimension(10, 0)));
+        cookiesContainer.add(cookiesOffButton);
+        JLabel cookiesLabel = new JLabel("Cookies:", JLabel.TRAILING);
+
+        pane.add(cookiesLabel);
+        pane.add(cookiesContainer);
+    }
+
+    @Override
+    public String getTabTitle() {
+        return "Basic";
+    }
+
+    @Override
+    public Map<String, String> getSessionParameters() {
+        String url = urlField.getText();
+
+        BindingType binding = BindingType.ATOMPUB;
+        if (bindingWebServicesButton.isSelected()) {
+            binding = BindingType.WEBSERVICES;
+        } else if (bindingBrowserButton.isSelected()) {
+            binding = BindingType.BROWSER;
+        }
+
+        String username = usernameField.getText();
+        String password = new String(passwordField.getPassword());
+
+        ClientSession.Authentication authentication = ClientSession.Authentication.NONE;
+        if (authenticationStandardButton.isSelected()) {
+            authentication = ClientSession.Authentication.STANDARD;
+        } else if (authenticationNTLMButton.isSelected()) {
+            authentication = ClientSession.Authentication.NTLM;
+        }
+
+        return ClientSession.createSessionParameters(url, binding, username, password, authentication,
+                compressionOnButton.isSelected(), clientCompressionOnButton.isSelected(),
cookiesOnButton.isSelected());
+    }
+
+    @Override
+    public boolean transferSessionParametersToExpertTab() {
+        return true;
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/BasicLoginTab.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java?rev=1432208&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
Fri Jan 11 18:22:47 2013
@@ -0,0 +1,145 @@
+/*
+ * 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.chemistry.opencmis.workbench;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.io.File;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.BorderFactory;
+import javax.swing.JComboBox;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+import org.apache.chemistry.opencmis.workbench.ClientHelper.FileEntry;
+import org.apache.chemistry.opencmis.workbench.model.ClientSession;
+
+public class ExpertLoginTab extends AbstractLoginTab {
+
+    private static final long serialVersionUID = 1L;
+
+    public static final String SYSPROP_CONFIGS = ClientSession.WORKBENCH_PREFIX + "configs";
+
+    private static final String CONFIGS_FOLDER = "/configs/";
+    private static final String CONFIGS_LIBRARY = "config-library.properties";
+
+    private JComboBox configs;
+    private JTextArea sessionParameterTextArea;
+    private List<FileEntry> sessionConfigurations;
+
+    public ExpertLoginTab() {
+        super();
+        createGUI();
+    }
+
+    private void createGUI() {
+        setLayout(new BorderLayout());
+        setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
+
+        URI propFile = null;
+
+        String externalConfigs = System.getProperty(SYSPROP_CONFIGS);
+        if (externalConfigs == null) {
+            propFile = ClientHelper.getClasspathURI(CONFIGS_FOLDER + CONFIGS_LIBRARY);
+        } else {
+            propFile = (new File(externalConfigs)).toURI();
+        }
+
+        sessionConfigurations = ClientHelper.readFileProperties(propFile);
+
+        configs = new JComboBox();
+        configs.setMaximumRowCount(20);
+
+        configs.addItem(new FileEntry("", null));
+        if (sessionConfigurations != null) {
+            for (FileEntry fe : sessionConfigurations) {
+                configs.addItem(fe);
+            }
+        }
+
+        configs.addItemListener(new ItemListener() {
+            public void itemStateChanged(ItemEvent e) {
+                if (e.getStateChange() == ItemEvent.SELECTED) {
+                    FileEntry fe = (FileEntry) e.getItem();
+
+                    sessionParameterTextArea.setText(ClientHelper.readFileAndRemoveHeader(fe.getFile()));
+                    sessionParameterTextArea.setCaretPosition(0);
+                }
+            }
+        });
+
+        add(configs, BorderLayout.PAGE_START);
+
+        sessionParameterTextArea = new JTextArea();
+        sessionParameterTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
+        add(new JScrollPane(sessionParameterTextArea), BorderLayout.CENTER);
+    }
+
+    public void setSessionParameters(Map<String, String> parameters) {
+        configs.setSelectedIndex(0);
+
+        StringBuilder sb = new StringBuilder();
+        for (Map.Entry<String, String> parameter : parameters.entrySet()) {
+            sb.append(parameter.getKey());
+            sb.append("=");
+            sb.append(parameter.getValue());
+            sb.append("\n");
+        }
+
+        sessionParameterTextArea.setText(sb.toString());
+        sessionParameterTextArea.setCaretPosition(0);
+    }
+
+    @Override
+    public String getTabTitle() {
+        return "Expert";
+    }
+
+    @Override
+    public Map<String, String> getSessionParameters() {
+        Map<String, String> result = new HashMap<String, String>();
+
+        for (String line : sessionParameterTextArea.getText().split("\n")) {
+            line = line.trim();
+            if (line.startsWith("#") || (line.length() == 0)) {
+                continue;
+            }
+
+            int x = line.indexOf('=');
+            if (x < 0) {
+                result.put(line.trim(), "");
+            } else {
+                result.put(line.substring(0, x).trim(), line.substring(x + 1).trim());
+            }
+        }
+
+        return result;
+    }
+
+    @Override
+    public boolean transferSessionParametersToExpertTab() {
+        return false;
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java?rev=1432208&r1=1432207&r2=1432208&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
Fri Jan 11 18:22:47 2013
@@ -27,21 +27,13 @@ import java.awt.Font;
 import java.awt.Frame;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.File;
-import java.net.URI;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Locale;
-import java.util.Map;
+import java.util.ServiceLoader;
 
 import javax.swing.BorderFactory;
-import javax.swing.Box;
 import javax.swing.BoxLayout;
-import javax.swing.ButtonGroup;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JDialog;
@@ -50,64 +42,29 @@ import javax.swing.JLabel;
 import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JPasswordField;
-import javax.swing.JRadioButton;
-import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
-import javax.swing.JTextArea;
 import javax.swing.JTextField;
 import javax.swing.ListCellRenderer;
-import javax.swing.Spring;
-import javax.swing.SpringLayout;
 import javax.swing.UIManager;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
 import org.apache.chemistry.opencmis.client.api.Repository;
-import org.apache.chemistry.opencmis.commons.enums.BindingType;
-import org.apache.chemistry.opencmis.workbench.ClientHelper.FileEntry;
 import org.apache.chemistry.opencmis.workbench.model.ClientSession;
 
 public class LoginDialog extends JDialog {
 
-    public static final String SYSPROP_URL = ClientSession.WORKBENCH_PREFIX + "url";
-    public static final String SYSPROP_BINDING = ClientSession.WORKBENCH_PREFIX + "binding";
-    public static final String SYSPROP_AUTHENTICATION = ClientSession.WORKBENCH_PREFIX +
"authentication";
-    public static final String SYSPROP_COMPRESSION = ClientSession.WORKBENCH_PREFIX + "compression";
-    public static final String SYSPROP_CLIENTCOMPRESSION = ClientSession.WORKBENCH_PREFIX
+ "clientcompression";
-    public static final String SYSPROP_COOKIES = ClientSession.WORKBENCH_PREFIX + "cookies";
-    public static final String SYSPROP_USER = ClientSession.WORKBENCH_PREFIX + "user";
-    public static final String SYSPROP_PASSWORD = ClientSession.WORKBENCH_PREFIX + "password";
-    public static final String SYSPROP_CONFIGS = ClientSession.WORKBENCH_PREFIX + "configs";
-
-    private static final String CONFIGS_FOLDER = "/configs/";
-    private static final String CONFIGS_LIBRARY = "config-library.properties";
-
     private static final long serialVersionUID = 1L;
 
+    private static ServiceLoader<AbstractLoginTab> TAB_SERVICE_LOADER = ServiceLoader.load(AbstractLoginTab.class);
+
     private JTabbedPane loginTabs;
-    private JTextField urlField;
-    private JRadioButton bindingAtomButton;
-    private JRadioButton bindingWebServicesButton;
-    private JRadioButton bindingBrowserButton;
-    private JTextField usernameField;
-    private JPasswordField passwordField;
-    private JRadioButton authenticationNoneButton;
-    private JRadioButton authenticationStandardButton;
-    private JRadioButton authenticationNTLMButton;
-    private JRadioButton compressionOnButton;
-    private JRadioButton compressionOffButton;
-    private JRadioButton clientCompressionOnButton;
-    private JRadioButton clientCompressionOffButton;
-    private JRadioButton cookiesOnButton;
-    private JRadioButton cookiesOffButton;
-    private JTextArea sessionParameterTextArea;
+    private BasicLoginTab basicLoginTab;
+    private ExpertLoginTab expertLoginTab;
     private JButton loadRepositoryButton;
     private JButton loginButton;
     private JComboBox repositoryBox;
-
-    private List<FileEntry> sessionConfigurations;
-
-    private boolean expertLogin = false;
+    private AbstractLoginTab currentTab;
 
     private boolean canceled = true;
 
@@ -187,6 +144,8 @@ public class LoginDialog extends JDialog
                         loginButton.setEnabled(false);
                         getRootPane().setDefaultButton(loadRepositoryButton);
                     }
+
+                    currentTab.repositoriesLoaded(repositories);
                 } catch (Exception ex) {
                     repositoryBox.setEnabled(false);
                     loginButton.setEnabled(false);
@@ -205,6 +164,9 @@ public class LoginDialog extends JDialog
                     setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
                     clientSession.createSession(repositoryBox.getSelectedIndex());
+
+                    currentTab.loggedIn(clientSession.getSession());
+
                     canceled = false;
                     hideDialog();
                 } catch (Exception ex) {
@@ -229,94 +191,28 @@ public class LoginDialog extends JDialog
     }
 
     protected void addLoginTabs(final JTabbedPane loginTabs) {
-        // basic panel
-        JPanel basicPanel = new JPanel(new SpringLayout());
-
-        urlField = createTextField(basicPanel, "URL:");
-        urlField.setText(System.getProperty(SYSPROP_URL, ""));
-
-        createBindingButtons(basicPanel);
-
-        usernameField = createTextField(basicPanel, "Username:");
-        usernameField.setText(System.getProperty(SYSPROP_USER, ""));
-
-        passwordField = createPasswordField(basicPanel, "Password:");
-        passwordField.setText(System.getProperty(SYSPROP_PASSWORD, ""));
-
-        createAuthenticationButtons(basicPanel);
-
-        createCompressionButtons(basicPanel);
-
-        createClientCompressionButtons(basicPanel);
-
-        createCookieButtons(basicPanel);
-
-        makeCompactGrid(basicPanel, 8, 2, 5, 10, 5, 5);
 
-        loginTabs.addTab("Basic", basicPanel);
-
-        // expert panel
-        final JPanel expertPanel = new JPanel(new BorderLayout());
-        expertPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
-
-        URI propFile = null;
-
-        String externalConfigs = System.getProperty(SYSPROP_CONFIGS);
-        if (externalConfigs == null) {
-            propFile = ClientHelper.getClasspathURI(CONFIGS_FOLDER + CONFIGS_LIBRARY);
-        } else {
-            propFile = (new File(externalConfigs)).toURI();
+        for (AbstractLoginTab tab : TAB_SERVICE_LOADER) {
+            loginTabs.add(tab.getTabTitle(), tab);
         }
 
-        sessionConfigurations = ClientHelper.readFileProperties(propFile);
+        basicLoginTab = new BasicLoginTab();
+        loginTabs.addTab(basicLoginTab.getTabTitle(), basicLoginTab);
 
-        final JComboBox configs = new JComboBox();
-        configs.setMaximumRowCount(20);
+        expertLoginTab = new ExpertLoginTab();
+        loginTabs.addTab(expertLoginTab.getTabTitle(), expertLoginTab);
 
-        configs.addItem(new FileEntry("", null));
-        if (sessionConfigurations != null) {
-            for (FileEntry fe : sessionConfigurations) {
-                configs.addItem(fe);
-            }
-        }
-
-        configs.addItemListener(new ItemListener() {
-            public void itemStateChanged(ItemEvent e) {
-                if (e.getStateChange() == ItemEvent.SELECTED) {
-                    FileEntry fe = (FileEntry) e.getItem();
-
-                    sessionParameterTextArea.setText(ClientHelper.readFileAndRemoveHeader(fe.getFile()));
-                    sessionParameterTextArea.setCaretPosition(0);
-                }
-            }
-        });
-
-        expertPanel.add(configs, BorderLayout.PAGE_START);
-
-        sessionParameterTextArea = new JTextArea();
-        sessionParameterTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
-        expertPanel.add(new JScrollPane(sessionParameterTextArea), BorderLayout.CENTER);
-
-        loginTabs.addTab("Expert", expertPanel);
+        currentTab = (AbstractLoginTab) loginTabs.getSelectedComponent();
 
         loginTabs.addChangeListener(new ChangeListener() {
             public void stateChanged(ChangeEvent e) {
-                expertLogin = (loginTabs.getSelectedComponent() == expertPanel);
-
-                if (expertLogin) {
-                    configs.setSelectedIndex(0);
-
-                    StringBuilder sb = new StringBuilder();
-                    for (Map.Entry<String, String> parameter : createBasicSessionParameters().entrySet())
{
-                        sb.append(parameter.getKey());
-                        sb.append("=");
-                        sb.append(parameter.getValue());
-                        sb.append("\n");
+                if (loginTabs.getSelectedComponent() == expertLoginTab) {
+                    if (currentTab.transferSessionParametersToExpertTab()) {
+                        expertLoginTab.setSessionParameters(currentTab.getSessionParameters());
                     }
-
-                    sessionParameterTextArea.setText(sb.toString());
-                    sessionParameterTextArea.setCaretPosition(0);
                 }
+
+                currentTab = (AbstractLoginTab) loginTabs.getSelectedComponent();
             }
         });
     }
@@ -343,110 +239,6 @@ public class LoginDialog extends JDialog
         return textField;
     }
 
-    protected void createBindingButtons(Container pane) {
-        JPanel bindingContainer = new JPanel();
-        bindingContainer.setLayout(new BoxLayout(bindingContainer, BoxLayout.LINE_AXIS));
-        char bc = System.getProperty(SYSPROP_BINDING, "atom").toLowerCase(Locale.ENGLISH).charAt(0);
-        boolean atom = (bc == 'a');
-        boolean ws = (bc == 'w');
-        boolean browser = (bc == 'b');
-        bindingAtomButton = new JRadioButton("AtomPub", atom);
-        bindingWebServicesButton = new JRadioButton("Web Services", ws);
-        bindingBrowserButton = new JRadioButton("Browser", browser);
-        ButtonGroup bindingGroup = new ButtonGroup();
-        bindingGroup.add(bindingAtomButton);
-        bindingGroup.add(bindingWebServicesButton);
-        bindingGroup.add(bindingBrowserButton);
-        bindingContainer.add(bindingAtomButton);
-        bindingContainer.add(Box.createRigidArea(new Dimension(10, 0)));
-        bindingContainer.add(bindingWebServicesButton);
-        bindingContainer.add(Box.createRigidArea(new Dimension(10, 0)));
-        bindingContainer.add(bindingBrowserButton);
-        JLabel bindingLabel = new JLabel("Binding:", JLabel.TRAILING);
-
-        pane.add(bindingLabel);
-        pane.add(bindingContainer);
-    }
-
-    protected void createAuthenticationButtons(Container pane) {
-        JPanel authenticationContainer = new JPanel();
-        authenticationContainer.setLayout(new BoxLayout(authenticationContainer, BoxLayout.LINE_AXIS));
-        boolean standard = (System.getProperty(SYSPROP_AUTHENTICATION, "standard").toLowerCase(Locale.ENGLISH)
-                .equals("standard"));
-        boolean ntlm = (System.getProperty(SYSPROP_AUTHENTICATION, "").toLowerCase(Locale.ENGLISH).equals("ntlm"));
-        boolean none = !standard && !ntlm;
-        authenticationNoneButton = new JRadioButton("None", none);
-        authenticationStandardButton = new JRadioButton("Standard", standard);
-        authenticationNTLMButton = new JRadioButton("NTLM", ntlm);
-        ButtonGroup authenticationGroup = new ButtonGroup();
-        authenticationGroup.add(authenticationNoneButton);
-        authenticationGroup.add(authenticationStandardButton);
-        authenticationGroup.add(authenticationNTLMButton);
-        authenticationContainer.add(authenticationNoneButton);
-        authenticationContainer.add(Box.createRigidArea(new Dimension(10, 0)));
-        authenticationContainer.add(authenticationStandardButton);
-        authenticationContainer.add(Box.createRigidArea(new Dimension(10, 0)));
-        authenticationContainer.add(authenticationNTLMButton);
-        JLabel authenticatioLabel = new JLabel("Authentication:", JLabel.TRAILING);
-
-        pane.add(authenticatioLabel);
-        pane.add(authenticationContainer);
-    }
-
-    protected void createCompressionButtons(Container pane) {
-        JPanel compressionContainer = new JPanel();
-        compressionContainer.setLayout(new BoxLayout(compressionContainer, BoxLayout.LINE_AXIS));
-        boolean compression = !(System.getProperty(SYSPROP_COMPRESSION, "on").equalsIgnoreCase("off"));
-        compressionOnButton = new JRadioButton("On", compression);
-        compressionOffButton = new JRadioButton("Off", !compression);
-        ButtonGroup compressionGroup = new ButtonGroup();
-        compressionGroup.add(compressionOnButton);
-        compressionGroup.add(compressionOffButton);
-        compressionContainer.add(compressionOnButton);
-        compressionContainer.add(Box.createRigidArea(new Dimension(10, 0)));
-        compressionContainer.add(compressionOffButton);
-        JLabel compressionLabel = new JLabel("Compression:", JLabel.TRAILING);
-
-        pane.add(compressionLabel);
-        pane.add(compressionContainer);
-    }
-
-    protected void createClientCompressionButtons(Container pane) {
-        JPanel clientCompressionContainer = new JPanel();
-        clientCompressionContainer.setLayout(new BoxLayout(clientCompressionContainer, BoxLayout.LINE_AXIS));
-        boolean clientCompression = (System.getProperty(SYSPROP_CLIENTCOMPRESSION, "off").equalsIgnoreCase("on"));
-        clientCompressionOnButton = new JRadioButton("On", clientCompression);
-        clientCompressionOffButton = new JRadioButton("Off", !clientCompression);
-        ButtonGroup clientCompressionGroup = new ButtonGroup();
-        clientCompressionGroup.add(clientCompressionOnButton);
-        clientCompressionGroup.add(clientCompressionOffButton);
-        clientCompressionContainer.add(clientCompressionOnButton);
-        clientCompressionContainer.add(Box.createRigidArea(new Dimension(10, 0)));
-        clientCompressionContainer.add(clientCompressionOffButton);
-        JLabel clientCompressionLabel = new JLabel("Client Compression:", JLabel.TRAILING);
-
-        pane.add(clientCompressionLabel);
-        pane.add(clientCompressionContainer);
-    }
-
-    protected void createCookieButtons(Container pane) {
-        JPanel cookiesContainer = new JPanel();
-        cookiesContainer.setLayout(new BoxLayout(cookiesContainer, BoxLayout.LINE_AXIS));
-        boolean cookies = (System.getProperty(SYSPROP_COOKIES, "on").equalsIgnoreCase("on"));
-        cookiesOnButton = new JRadioButton("On", cookies);
-        cookiesOffButton = new JRadioButton("Off", !cookies);
-        ButtonGroup cookiesGroup = new ButtonGroup();
-        cookiesGroup.add(cookiesOnButton);
-        cookiesGroup.add(cookiesOffButton);
-        cookiesContainer.add(cookiesOnButton);
-        cookiesContainer.add(Box.createRigidArea(new Dimension(10, 0)));
-        cookiesContainer.add(cookiesOffButton);
-        JLabel cookiesLabel = new JLabel("Cookies:", JLabel.TRAILING);
-
-        pane.add(cookiesLabel);
-        pane.add(cookiesContainer);
-    }
-
     protected JButton createButton(String title) {
         JButton button = new JButton(title);
         button.setPreferredSize(new Dimension(Short.MAX_VALUE, 30));
@@ -466,100 +258,12 @@ public class LoginDialog extends JDialog
         pane.add(repositoryBox);
     }
 
-    private SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent,
int cols) {
-        SpringLayout layout = (SpringLayout) parent.getLayout();
-        Component c = parent.getComponent(row * cols + col);
-        return layout.getConstraints(c);
-    }
-
-    protected void makeCompactGrid(Container parent, int rows, int cols, int initialX, int
initialY, int xPad, int yPad) {
-        SpringLayout layout = (SpringLayout) parent.getLayout();
-
-        Spring x = Spring.constant(initialX);
-        for (int c = 0; c < cols; c++) {
-            Spring width = Spring.constant(0);
-            for (int r = 0; r < rows; r++) {
-                width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
-            }
-            for (int r = 0; r < rows; r++) {
-                SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent,
cols);
-                constraints.setX(x);
-                constraints.setWidth(width);
-            }
-            x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
-        }
-
-        Spring y = Spring.constant(initialY);
-        for (int r = 0; r < rows; r++) {
-            Spring height = Spring.constant(0);
-            for (int c = 0; c < cols; c++) {
-                height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
-            }
-            for (int c = 0; c < cols; c++) {
-                SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent,
cols);
-                constraints.setY(y);
-                constraints.setHeight(height);
-            }
-            y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
-        }
-
-        layout.getConstraints(parent).setConstraint(SpringLayout.EAST, x);
-    }
-
-    protected Map<String, String> createBasicSessionParameters() {
-        String url = urlField.getText();
-
-        BindingType binding = BindingType.ATOMPUB;
-        if (bindingWebServicesButton.isSelected()) {
-            binding = BindingType.WEBSERVICES;
-        } else if (bindingBrowserButton.isSelected()) {
-            binding = BindingType.BROWSER;
-        }
-
-        String username = usernameField.getText();
-        String password = new String(passwordField.getPassword());
-
-        ClientSession.Authentication authentication = ClientSession.Authentication.NONE;
-        if (authenticationStandardButton.isSelected()) {
-            authentication = ClientSession.Authentication.STANDARD;
-        } else if (authenticationNTLMButton.isSelected()) {
-            authentication = ClientSession.Authentication.NTLM;
-        }
-
-        return ClientSession.createSessionParameters(url, binding, username, password, authentication,
-                compressionOnButton.isSelected(), clientCompressionOnButton.isSelected(),
cookiesOnButton.isSelected());
-    }
-
-    protected Map<String, String> createExpertSessionParameters() {
-        Map<String, String> result = new HashMap<String, String>();
-
-        for (String line : sessionParameterTextArea.getText().split("\n")) {
-            line = line.trim();
-            if (line.startsWith("#") || (line.length() == 0)) {
-                continue;
-            }
-
-            int x = line.indexOf('=');
-            if (x < 0) {
-                result.put(line.trim(), "");
-            } else {
-                result.put(line.substring(0, x).trim(), line.substring(x + 1).trim());
-            }
-        }
-
-        return result;
-    }
-
     protected void setClientSession(ClientSession clientSession) {
         this.clientSession = clientSession;
     }
 
     public void createClientSession() {
-        if (expertLogin) {
-            setClientSession(new ClientSession(createExpertSessionParameters()));
-        } else {
-            setClientSession(new ClientSession(createBasicSessionParameters()));
-        }
+        setClientSession(new ClientSession(currentTab.getSessionParameters()));
     }
 
     public void showDialog() {



Mime
View raw message