From commits-return-15996-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Mon Nov 05 14:47:18 2007 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 96245 invoked from network); 5 Nov 2007 14:47:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Nov 2007 14:47:18 -0000 Received: (qmail 63151 invoked by uid 500); 5 Nov 2007 14:47:06 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 63103 invoked by uid 500); 5 Nov 2007 14:47:05 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 63092 invoked by uid 99); 5 Nov 2007 14:47:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2007 06:47:05 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2007 14:47:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 02DEF1A9846; Mon, 5 Nov 2007 06:46:50 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r592022 [4/4] - in /directory/sandbox/felixk/studio-connection-ui: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ src/ma... Date: Mon, 05 Nov 2007 14:46:37 -0000 To: commits@directory.apache.org From: felixk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071105144650.02DEF1A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/HistoryUtils.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/HistoryUtils.java?rev=592022&view=auto ============================================================================== --- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/HistoryUtils.java (added) +++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/HistoryUtils.java Mon Nov 5 06:46:32 2007 @@ -0,0 +1,88 @@ +/* + * 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.directory.studio.connection.ui.widgets; + + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; + + +/** + * The HistoryUtils are used to save and load the history of input fields. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class HistoryUtils +{ + + /** + * Saves the the given value under the given key in the dialog settings. + * + * @param key the key + * @param value the value + */ + public static void save( String key, String value ) + { + // get current history + String[] history = load( key ); + List list = new ArrayList( Arrays.asList( history ) ); + + // add new value or move to first position + if ( list.contains( value ) ) + { + list.remove( value ); + } + list.add( 0, value ); + + // check history size + while ( list.size() > 20 ) + { + list.remove( list.size() - 1 ); + } + + // save + history = list.toArray( new String[list.size()] ); + ConnectionUIPlugin.getDefault().getDialogSettings().put( key, history ); + + } + + + /** + * Loads the value of the given key from the dialog settings + * + * @param key the key + * @return the value + */ + public static String[] load( String key ) + { + String[] history = ConnectionUIPlugin.getDefault().getDialogSettings().getArray( key ); + if ( history == null ) + { + history = new String[0]; + } + return history; + } + +} Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/HistoryUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java?rev=592022&view=auto ============================================================================== --- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java (added) +++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java Mon Nov 5 06:46:32 2007 @@ -0,0 +1,367 @@ +/* + * 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.directory.studio.connection.ui.widgets; + + +import org.apache.directory.studio.connection.core.Connection; +import org.apache.directory.studio.connection.core.ConnectionCorePlugin; +import org.apache.directory.studio.connection.core.ConnectionParameter; +import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod; +import org.apache.directory.studio.connection.core.jobs.CheckNetworkParameterJob; +import org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage; +import org.apache.directory.studio.connection.ui.ConnectionUIConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Text; + + +/** + * The NetworkParameterPage is used the edit the network parameters of a + * connection. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class NetworkParameterPage extends AbstractConnectionParameterPage +{ + + /** The connection name text widget */ + private Text nameText; + + /** The host name combo with the history of recently used host names */ + private Combo hostCombo; + + /** The host combo with the history of recently used ports */ + private Combo portCombo; + + /** The combo to select the encryption method */ + private Combo encryptionMethodCombo; + + /** The button to check the connection parameters */ + private Button checkConnectionButton; + + + /** + * Creates a new instance of NetworkParameterPage. + */ + public NetworkParameterPage() + { + } + + + /** + * Gets the connection name. + * + * @return the connectio name + */ + private String getName() + { + return nameText.getText(); + } + + + /** + * Gets the host name. + * + * @return the host name + */ + private String getHostName() + { + return hostCombo.getText(); + } + + + /** + * Gets the port. + * + * @return the port + */ + private int getPort() + { + return Integer.parseInt( portCombo.getText() ); + } + + + /** + * Gets the encyrption method. + * + * @return the encyrption method + */ + private ConnectionParameter.EncryptionMethod getEncyrptionMethod() + { + switch ( encryptionMethodCombo.getSelectionIndex() ) + { + case 1: + return ConnectionParameter.EncryptionMethod.LDAPS; + case 2: + return ConnectionParameter.EncryptionMethod.START_TLS; + default: + return ConnectionParameter.EncryptionMethod.NONE; + } + } + + + /** + * Gets a temporary connection with all conection parameter + * entered in this page. + * + * @return a test connection + */ + private Connection getTestConnection() + { + ConnectionParameter cp = new ConnectionParameter( null, getHostName(), getPort(), getEncyrptionMethod(), + ConnectionParameter.AuthenticationMethod.NONE, null, null, null, null ); + Connection conn = new Connection( cp ); + return conn; + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#createComposite(org.eclipse.swt.widgets.Composite) + */ + public void createComposite( Composite parent ) + { + + Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); + + Composite nameComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); + BaseWidgetUtils.createLabel( nameComposite, "Connection name:", 1 ); + nameText = BaseWidgetUtils.createText( nameComposite, "", 1 ); + nameText.addModifyListener( new ModifyListener() + { + public void modifyText( ModifyEvent event ) + { + connectionPageModified(); + } + } ); + + BaseWidgetUtils.createSpacer( composite, 1 ); + + Group group = BaseWidgetUtils.createGroup( composite, "Network Parameter", 1 ); + + Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 ); + BaseWidgetUtils.createLabel( groupComposite, "Hostname:", 1 ); + String[] hostHistory = HistoryUtils.load( ConnectionUIConstants.DIALOGSETTING_KEY_HOST_HISTORY ); + hostCombo = BaseWidgetUtils.createCombo( groupComposite, hostHistory, -1, 2 ); + hostCombo.addModifyListener( new ModifyListener() + { + public void modifyText( ModifyEvent event ) + { + connectionPageModified(); + } + } ); + + BaseWidgetUtils.createLabel( groupComposite, "Port:", 1 ); + String[] portHistory = HistoryUtils.load( ConnectionUIConstants.DIALOGSETTING_KEY_PORT_HISTORY ); + portCombo = BaseWidgetUtils.createCombo( groupComposite, portHistory, -1, 2 ); + portCombo.addVerifyListener( new VerifyListener() + { + public void verifyText( VerifyEvent event ) + { + if ( !event.text.matches( "[0-9]*" ) ) + { + event.doit = false; + } + if ( portCombo.getText().length() > 4 && event.text.length() > 0 ) + { + event.doit = false; + } + } + } ); + portCombo.addModifyListener( new ModifyListener() + { + public void modifyText( ModifyEvent event ) + { + connectionPageModified(); + } + } ); + + String[] encMethods = new String[] + { "No encryption", "Use SSL encryption (ldaps://)", "Use StartTLS extension" }; + int index = 0; + BaseWidgetUtils.createLabel( groupComposite, "Encryption method:", 1 ); + encryptionMethodCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, encMethods, index, 2 ); + encryptionMethodCombo.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent event ) + { + connectionPageModified(); + } + } ); + BaseWidgetUtils.createSpacer( groupComposite, 1 ); + BaseWidgetUtils + .createLabel( + groupComposite, + "Warning: The current version doesn't support certificate validation, \nbe aware of invalid certificates or man-in-the-middle attacks!", + 2 ); + + BaseWidgetUtils.createSpacer( groupComposite, 2 ); + checkConnectionButton = new Button( groupComposite, SWT.PUSH ); + GridData gd = new GridData(); + gd.horizontalAlignment = SWT.RIGHT; + gd.verticalAlignment = SWT.BOTTOM; + checkConnectionButton.setLayoutData( gd ); + checkConnectionButton.setText( "Check Network Parameter" ); + checkConnectionButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent event ) + { + Connection connection = getTestConnection(); + CheckNetworkParameterJob job = new CheckNetworkParameterJob( connection ); + RunnableContextJobAdapter.execute( job, runnableContext ); + if ( job.getExternalResult().isOK() ) + { + MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Check Network Parameter", + "The connection was established successfully." ); + } + } + } ); + + validate(); + nameText.setFocus(); + } + + + /** + * Called when an input field was modified. + */ + private void connectionPageModified() + { + // validate() + validate(); + + // fire + fireConnectionPageModified(); + } + + + /** + * Validates the input fields after each modification. + */ + private void validate() + { + // set enabled/disabled state of check connection button + checkConnectionButton.setEnabled( !hostCombo.getText().equals( "" ) && !portCombo.getText().equals( "" ) ); + + // validate input fields + message = null; + errorMessage = null; + if ( "".equals( portCombo.getText() ) ) + { + message = "Please enter a port. The default LDAP port is 389."; + } + if ( "".equals( hostCombo.getText() ) ) + { + message = "Please enter a hostname."; + } + if ( "".equals( nameText.getText() ) ) + { + message = "Please enter a connection name."; + } + if ( ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionByName( nameText.getText() ) != null + && ( connectionParameter == null || !nameText.getText().equals( connectionParameter.getName() ) ) ) + { + errorMessage = "A connection named '" + nameText.getText() + "' already exists."; + } + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#loadParameters(org.apache.directory.studio.connection.core.ConnectionParameter) + */ + public void loadParameters( ConnectionParameter parameter ) + { + connectionParameter = parameter; + + nameText.setText( parameter.getName() ); + hostCombo.setText( parameter.getHost() ); + portCombo.setText( Integer.toString( parameter.getPort() ) ); + int index = parameter.getEncryptionMethod() == EncryptionMethod.LDAPS ? 1 + : parameter.getEncryptionMethod() == EncryptionMethod.START_TLS ? 2 : 0; + encryptionMethodCombo.select( index ); + + connectionPageModified(); + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveParameters(org.apache.directory.studio.connection.core.ConnectionParameter) + */ + public void saveParameters( ConnectionParameter parameter ) + { + parameter.setName( getName() ); + parameter.setHost( getHostName() ); + parameter.setPort( getPort() ); + parameter.setEncryptionMethod( getEncyrptionMethod() ); + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveDialogSettings() + */ + public void saveDialogSettings() + { + HistoryUtils.save( ConnectionUIConstants.DIALOGSETTING_KEY_HOST_HISTORY, hostCombo.getText() ); + HistoryUtils.save( ConnectionUIConstants.DIALOGSETTING_KEY_PORT_HISTORY, portCombo.getText() ); + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#setFocus() + */ + public void setFocus() + { + nameText.setFocus(); + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#areParametersModifed() + */ + public boolean areParametersModifed() + { + return isReconnectionRequired() || !( connectionParameter.getName().equals( getName() ) ); + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#isReconnectionRequired() + */ + public boolean isReconnectionRequired() + { + return connectionParameter == null || !( connectionParameter.getHost().equals( getHostName() ) ) + || connectionParameter.getPort() != getPort() + || connectionParameter.getEncryptionMethod() != getEncyrptionMethod(); + } + +} Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/RunnableContextJobAdapter.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/RunnableContextJobAdapter.java?rev=592022&view=auto ============================================================================== --- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/RunnableContextJobAdapter.java (added) +++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/RunnableContextJobAdapter.java Mon Nov 5 06:46:32 2007 @@ -0,0 +1,112 @@ +/* + * 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.directory.studio.connection.ui.widgets; + + +import org.apache.directory.studio.connection.core.jobs.AbstractConnectionJob; +import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.swt.widgets.Display; + + +/** + * This class provides some convinience methods to execute a job within + * an {@link IRunnableContext}. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class RunnableContextJobAdapter +{ + + /** + * Executes the given job within a new {@link ProgressMonitorDialog}. + * + * @param job the job to execute + */ + public static void execute( final AbstractConnectionJob job ) + { + execute( job, null ); + } + + + /** + * Executes the given job within the given runnable context and enabled error handling + * + * @param runnableContext the runnable context + * @param job the job to execute + */ + public static void execute( final AbstractConnectionJob job, IRunnableContext runnableContext ) + { + execute( job, runnableContext, true ); + } + + + /** + * Executes the given job within the given runnable context. + * + * @param runnableContext the runnable context + * @param job the job to execute + * @param handleError true to handle errors + */ + public static void execute( final AbstractConnectionJob job, IRunnableContext runnableContext, boolean handleError ) + { + + if ( runnableContext == null ) + { + runnableContext = new ProgressMonitorDialog( Display.getDefault().getActiveShell() ); + } + + IRunnableWithProgress runnable = new IRunnableWithProgress() + { + public void run( IProgressMonitor ipm ) throws InterruptedException + { + job.setExternalProgressMonitor( ipm ); + job.execute(); + job.join(); + } + }; + + try + { + runnableContext.run( true, true, runnable ); + } + catch ( Exception ex ) + { + ConnectionUIPlugin.getDefault().getExceptionHandler().handleException( + new Status( IStatus.ERROR, ConnectionUIPlugin.PLUGIN_ID, IStatus.ERROR, ex.getMessage() != null ? ex + .getMessage() : "", ex ) ); + } + + if ( handleError && !job.getExternalResult().isOK() ) + { + IStatus status = job.getExternalResult(); + ConnectionUIPlugin.getDefault().getExceptionHandler().handleException( status ); + } + + } + +} Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/RunnableContextJobAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ViewFormWidget.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ViewFormWidget.java?rev=592022&view=auto ============================================================================== --- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ViewFormWidget.java (added) +++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ViewFormWidget.java Mon Nov 5 06:46:32 2007 @@ -0,0 +1,256 @@ +/* + * 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.directory.studio.connection.ui.widgets; + + +import org.apache.directory.studio.connection.ui.ConnectionUIConstants; +import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ViewForm; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; + + +/** + * The ViewFormWidget is a widget that provides an info text, + * a tool bar, a menu and a main content composite including + * a context menu. + * It looks like this: + *
+ * -----------------------------------
+ * | info text     | tool bar | menu |
+ * -----------------------------------
+ * |                                 |
+ * |          main content           |
+ * |                                 |
+ * -----------------------------------
+ * 
+ * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public abstract class ViewFormWidget +{ + + /** The view form control */ + protected ViewForm control; + + /** The info text, positioned at the top left */ + protected Text infoText; + + /** The action tool bar */ + protected ToolBar actionToolBar; + + /** The action tool bar manager */ + protected IToolBarManager actionToolBarManager; + + /** The menu tool bar. */ + protected ToolBar menuToolBar; + + /** The menu manager. */ + protected MenuManager menuManager; + + /** The context menu manager. */ + protected MenuManager contextMenuManager; + + + /** + * Creates the widget. + * + * @param parent the parent composite + */ + public void createWidget( Composite parent ) + { + + control = new ViewForm( parent, SWT.NONE ); + // control.marginWidth = 0; + // control.marginHeight = 0; + // control.horizontalSpacing = 0; + // control.verticalSpacing = 0; + control.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + + // infoText = BaseWidgetUtils.createLabeledText(control, "", 1); + Composite infoTextControl = BaseWidgetUtils.createColumnContainer( control, 1, 1 ); + infoTextControl.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + infoText = BaseWidgetUtils.createLabeledText( infoTextControl, "", 1 ); + infoText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, true ) ); + control.setTopLeft( infoTextControl ); + + // tool bar + actionToolBar = new ToolBar( control, SWT.FLAT | SWT.RIGHT ); + actionToolBar.setLayoutData( new GridData( SWT.END, SWT.NONE, true, false ) ); + actionToolBarManager = new ToolBarManager( actionToolBar ); + control.setTopCenter( actionToolBar ); + + // local menu + this.menuManager = new MenuManager(); + menuToolBar = new ToolBar( control, SWT.FLAT | SWT.RIGHT ); + ToolItem ti = new ToolItem( menuToolBar, SWT.PUSH, 0 ); + ti.setImage( ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_PULLDOWN ) ); + ti.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + showViewMenu(); + } + } ); + control.setTopRight( menuToolBar ); + + // content + Composite composite = BaseWidgetUtils.createColumnContainer( control, 1, 1 ); + GridLayout gl = new GridLayout(); + gl.horizontalSpacing = 0; + gl.verticalSpacing = 0; + gl.marginHeight = 0; + gl.marginWidth = 0; + composite.setLayout( gl ); + Control childControl = this.createContent( composite ); + control.setContent( composite ); + + // context menu + this.contextMenuManager = new MenuManager(); + Menu menu = this.contextMenuManager.createContextMenu( childControl ); + childControl.setMenu( menu ); + } + + + /** + * Creates the content. + * + * @param control the control + * + * @return the control + */ + protected abstract Control createContent( Composite control ); + + + /** + * Shows the local view menu. + */ + private void showViewMenu() + { + Menu aMenu = menuManager.createContextMenu( control ); + Point topLeft = new Point( 0, 0 ); + topLeft.y += menuToolBar.getBounds().height; + topLeft = menuToolBar.toDisplay( topLeft ); + aMenu.setLocation( topLeft.x, topLeft.y ); + aMenu.setVisible( true ); + } + + + /** + * Disposes this widget. + */ + public void dispose() + { + if ( control != null ) + { + + if ( contextMenuManager != null ) + { + contextMenuManager.removeAll(); + contextMenuManager.dispose(); + contextMenuManager = null; + } + if ( menuToolBar != null ) + { + menuToolBar.dispose(); + menuToolBar = null; + menuManager.dispose(); + menuManager = null; + } + if ( actionToolBar != null ) + { + actionToolBar.dispose(); + actionToolBar = null; + actionToolBarManager.removeAll(); + actionToolBarManager = null; + } + + if ( infoText != null ) + { + infoText.dispose(); + infoText = null; + } + + control.dispose(); + control = null; + } + } + + + /** + * Gets the info text. + * + * @return the info text + */ + public Text getInfoText() + { + return infoText; + } + + + /** + * Gets the tool bar manager. + * + * @return the tool bar manager + */ + public IToolBarManager getToolBarManager() + { + return this.actionToolBarManager; + } + + + /** + * Gets the menu manager. + * + * @return the menu manager + */ + public IMenuManager getMenuManager() + { + return menuManager; + } + + + /** + * Gets the context menu manager. + * + * @return the context menu manager + */ + public IMenuManager getContextMenuManager() + { + return this.contextMenuManager; + } + +} Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ViewFormWidget.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizard.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizard.java?rev=592022&view=auto ============================================================================== --- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizard.java (added) +++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizard.java Mon Nov 5 06:46:32 2007 @@ -0,0 +1,192 @@ +/* + * 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.directory.studio.connection.ui.wizards; + + +import org.apache.directory.studio.connection.core.Connection; +import org.apache.directory.studio.connection.core.ConnectionCorePlugin; +import org.apache.directory.studio.connection.core.ConnectionFolder; +import org.apache.directory.studio.connection.core.ConnectionParameter; +import org.apache.directory.studio.connection.core.jobs.OpenConnectionsJob; +import org.apache.directory.studio.connection.ui.ConnectionParameterPage; +import org.apache.directory.studio.connection.ui.ConnectionParameterPageManager; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; + + +/** + * The NewConnectionWizard is used to create a new connection. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class NewConnectionWizard extends Wizard implements INewWizard +{ + + /** The wizard pages. */ + private NewConnectionWizardPage[] wizardPages; + + /** The connection parameter pages. */ + private ConnectionParameterPage[] pages; + + /** The selected connection folder. */ + private ConnectionFolder selectedConnectionFolder; + + /** + * Creates a new instance of NewConnectionWizard. + */ + public NewConnectionWizard() + { + setWindowTitle( "New LDAP Connection" ); + setNeedsProgressMonitor( true ); + } + + + /** + * Gets the id. + * + * @return the id + */ + public static String getId() + { + return NewConnectionWizard.class.getName(); + } + + + /** + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + */ + public void init( IWorkbench workbench, IStructuredSelection selection ) + { + Object firstElement = selection.getFirstElement(); + if ( firstElement instanceof ConnectionFolder ) + { + selectedConnectionFolder = ( ConnectionFolder ) firstElement; + } + else if ( firstElement instanceof Connection ) + { + Connection connection = ( Connection ) firstElement; + selectedConnectionFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager() + .getParentConnectionFolder( connection ); + } + + if ( selectedConnectionFolder == null ) + { + selectedConnectionFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager() + .getRootConnectionFolder(); + } + } + + + /** + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + public void addPages() + { + pages = ConnectionParameterPageManager.getConnectionParameterPages(); + + wizardPages = new NewConnectionWizardPage[pages.length]; + for ( int i = 0; i < pages.length; i++ ) + { + wizardPages[i] = new NewConnectionWizardPage( this, pages[i] ); + addPage( wizardPages[i] ); + } + } + + + /** + * @see org.eclipse.jface.wizard.Wizard#createPageControls(org.eclipse.swt.widgets.Composite) + */ + public void createPageControls( Composite pageContainer ) + { + super.createPageControls( pageContainer ); + + // TODO: set help context ID, move help from browser-help plugin to connections-help plugin + // for ( NewConnectionWizardPage wizardPage : wizardPages ) + // { + // PlatformUI.getWorkbench().getHelpSystem().setHelp( wizardPage.getControl(), + // ConnectionUIPlugin.PLUGIN_ID + "." + "tools_newconnection_wizard" ); + // } + } + + + /** + * @see org.eclipse.jface.wizard.Wizard#canFinish() + */ + public boolean canFinish() + { + for ( int i = 0; i < pages.length; i++ ) + { + if ( !pages[i].isValid() ) + { + return false; + } + } + return true; + } + + + /** + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + public boolean performFinish() + { + // get connection parameters from pages and save dialog settings + ConnectionParameter connectionParameter = new ConnectionParameter(); + for ( int i = 0; i < pages.length; i++ ) + { + pages[i].saveParameters( connectionParameter ); + pages[i].saveDialogSettings(); + } + + // create persistent connection + final Connection conn = new Connection( connectionParameter ); + ConnectionCorePlugin.getDefault().getConnectionManager().addConnection( conn ); + + // add connection to folder + selectedConnectionFolder.addConnectionId( conn.getId() ); + + // open connection + new OpenConnectionsJob( conn ).execute(); + + return true; + } + + + /** + * Gets the test connection parameters. + * + * @return the test connection parameters + */ + public ConnectionParameter getTestConnectionParameters() + { + ConnectionParameter connectionParameter = new ConnectionParameter(); + for ( int i = 0; i < pages.length; i++ ) + { + pages[i].saveParameters( connectionParameter ); + } + return connectionParameter; + } + +} Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizard.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizardPage.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizardPage.java?rev=592022&view=auto ============================================================================== --- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizardPage.java (added) +++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizardPage.java Mon Nov 5 06:46:32 2007 @@ -0,0 +1,135 @@ +/* + * 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.directory.studio.connection.ui.wizards; + + +import org.apache.directory.studio.connection.core.ConnectionParameter; +import org.apache.directory.studio.connection.ui.ConnectionParameterPage; +import org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener; +import org.apache.directory.studio.connection.ui.ConnectionUIConstants; +import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + + +/** + * NewConnectionWizard. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class NewConnectionWizardPage extends WizardPage implements ConnectionParameterPageModifyListener +{ + + /** The wizard. */ + private NewConnectionWizard wizard; + + /** The page. */ + private ConnectionParameterPage page; + + + /** + * Creates a new instance of NewConnectionWizard. + * + * @param page the page + * @param wizard the wizard + */ + public NewConnectionWizardPage( NewConnectionWizard wizard, ConnectionParameterPage page ) + { + super( page.getPageName() ); + setTitle( page.getPageName() ); + setDescription( page.getPageDescription() ); + setImageDescriptor( ConnectionUIPlugin.getDefault().getImageDescriptor( + ConnectionUIConstants.IMG_CONNECTION_WIZARD ) ); + setPageComplete( false ); + + page.setConnectionParameterPageModifyListener( this ); + page.setRunnableContext( getContainer() ); + + this.wizard = wizard; + this.page = page; + } + + + /** + * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean) + */ + public void setVisible( boolean visible ) + { + super.setVisible( visible ); + + if ( visible ) + { + page.setFocus(); + } + } + + + /** + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl( Composite parent ) + { + Composite composite = new Composite( parent, SWT.NONE ); + GridLayout gl = new GridLayout( 1, false ); + composite.setLayout( gl ); + page.createComposite( composite ); + setControl( composite ); + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener#connectionParameterPageModified() + */ + public void connectionParameterPageModified() + { + //only one of the messages can be shown + //warning messages are more important + //than info messages + if ( page.getMessage() != null ) + { + setMessage( page.getMessage() ); + } + else if ( page.getInfoMessage() != null ) + { + setMessage( page.getInfoMessage() ); + } + else + { + setMessage( null ); + } + setErrorMessage( page.getErrorMessage() ); + setPageComplete( page.isValid() ); + getContainer().updateButtons(); + } + + + /** + * @see org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener#getTestConnectionParameters() + */ + public ConnectionParameter getTestConnectionParameters() + { + return wizard.getTestConnectionParameters(); + } + +} \ No newline at end of file Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizardPage.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/connectionParameterPages.exsd URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/connectionParameterPages.exsd?rev=592022&view=auto ============================================================================== --- directory/sandbox/felixk/studio-connection-ui/src/main/resources/connectionParameterPages.exsd (added) +++ directory/sandbox/felixk/studio-connection-ui/src/main/resources/connectionParameterPages.exsd Mon Nov 5 06:46:32 2007 @@ -0,0 +1,167 @@ + + + + + + + + + A ConnectionParameterPage is used to specify additional parameters to a connection. + + + + + + + + + + + + The extension-point of this extension. + + + + + + + Extension identifier. + + + + + + + Name of this extension. + + + + + + + + + + + + + + + + + + + + + + + + The name of the function. + + + + + + + + + + + + + + + + + + + + The specific class implementing the function. + + + + + + + + + + + + + + + + + + + + + + 1.0.0 + + + + + + + + + <p> +<pre> + <extension + point="org.apache.directory.studio.connectionparameterpages"> + + <valueEditor + name="Browser Options" + class="org.apache.directory.studio.ldapbrowser.common.wizard.connection.ConnectionParameterPage" + /> + </extension> +</pre> +<p> + + + + + + + + + + + + + + + + + + + + + + + + + + + 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. + + + + Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_add.gif URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_add.gif?rev=592022&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_add.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_connect.gif URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_connect.gif?rev=592022&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_connect.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_connected.gif URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_connected.gif?rev=592022&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_connected.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_disconnect.gif URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_disconnect.gif?rev=592022&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_disconnect.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_disconnected.gif URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_disconnected.gif?rev=592022&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_disconnected.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_folder.gif URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_folder.gif?rev=592022&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_folder.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_wizard.gif URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_wizard.gif?rev=592022&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/connection_wizard.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/pulldown.gif URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/pulldown.gif?rev=592022&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/resources/resources/icons/pulldown.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream