You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2010/07/12 17:04:30 UTC
svn commit: r963311 [2/2] - in /directory/studio/trunk/ldapservers: ./
resources/ resources/icons/
resources/org/apache/directory/studio/ldapservers/
src/main/java/org/apache/directory/studio/ldapservers/
src/main/java/org/apache/directory/studio/ldaps...
Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java?rev=963311&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java Mon Jul 12 15:04:29 2010
@@ -0,0 +1,407 @@
+/*
+ * 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.
+ *
+ */
+/*******************************************************************************
+ * Copyright (c) 2003, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.apache.directory.studio.ldapservers.views;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.ldapservers.LdapServersManager;
+import org.apache.directory.studio.ldapservers.LdapServersManagerListener;
+import org.apache.directory.studio.ldapservers.model.LdapServer;
+import org.apache.directory.studio.ldapservers.model.LdapServerEvent;
+import org.apache.directory.studio.ldapservers.model.LdapServerEventType;
+import org.apache.directory.studio.ldapservers.model.LdapServerListener;
+import org.apache.directory.studio.ldapservers.model.LdapServerStatus;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class implements a {@link TreeViewer} that displays the servers.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ServersTableViewer extends TreeViewer
+{
+ /** The root element */
+ protected static final String ROOT = "root"; //$NON-NLS-1$
+
+ /** The label provider */
+ private ServersViewLabelProvider labelProvider;
+
+ /** The server handler listener */
+ private LdapServersManagerListener serversHandlerListener;
+
+ /** The server listener */
+ private LdapServerListener serverListener;
+
+ /** A flag to stop the animation */
+ private boolean stopAnimation;
+
+ /** The list of server needing animation */
+ private List<LdapServer> serversNeedingAnimation = new ArrayList<LdapServer>();
+
+
+ public ServersTableViewer( Tree tree )
+ {
+ super( tree );
+
+ labelProvider = new ServersViewLabelProvider();
+ setLabelProvider( labelProvider );
+ setContentProvider( new ServersViewContentProvider() );
+
+ setComparator( new ServersViewerComparator( labelProvider ) );
+
+ setInput( ROOT );
+
+ addListeners();
+ }
+
+
+ /**
+ * Adds the listener
+ */
+ private void addListeners()
+ {
+ // The server handler listener
+ serversHandlerListener = new LdapServersManagerListener()
+ {
+ public void serverAdded( LdapServer server )
+ {
+ addServer( server );
+ server.addListener( serverListener );
+ }
+
+
+ public void serverRemoved( LdapServer server )
+ {
+ refreshServer( server );
+ }
+
+
+ public void serverUpdated( LdapServer server )
+ {
+ removeServer( server );
+ server.removeListener( serverListener );
+
+ }
+ };
+
+ // Adding the listener to the servers handler
+ LdapServersManager.getDefault().addListener( serversHandlerListener );
+
+ // The server listener
+ serverListener = new LdapServerListener()
+ {
+ public void serverChanged( LdapServerEvent event )
+ {
+ // Checking if the event is null
+ if ( event == null )
+ {
+ return;
+ }
+
+ // Getting the kind of event and the associated server
+ LdapServerEventType kind = event.getKind();
+ LdapServer server = event.getServer();
+ switch ( kind )
+ {
+ // The server status has changed
+ case STATUS_CHANGED:
+ // First, we refresh the server
+ refreshServer( server );
+
+ // Then, we get the status of the server to see if we
+ // need to start or stop the animation thread
+ LdapServerStatus state = server.getStatus();
+
+ // If the state is STARTING or STOPPING, we need to
+ // add the server to the list of servers needing
+ // animation and eventually start the animation thread
+ if ( ( state == LdapServerStatus.STARTING ) || ( state == LdapServerStatus.STOPPING ) )
+ {
+ boolean startAnimationThread = false;
+
+ synchronized ( serversNeedingAnimation )
+ {
+ if ( !serversNeedingAnimation.contains( server ) )
+ {
+ if ( serversNeedingAnimation.isEmpty() )
+ startAnimationThread = true;
+ serversNeedingAnimation.add( server );
+ }
+ }
+
+ if ( startAnimationThread )
+ {
+ startAnimationThread();
+ }
+ }
+
+ // If the state is *not* STARTING or STOPPING, we need
+ // to remove the server from the list of servers
+ // needing animation and eventually stop the animation
+ // if this list is empty
+ else
+ {
+ boolean stopAnimationThread = false;
+
+ synchronized ( serversNeedingAnimation )
+ {
+ if ( serversNeedingAnimation.contains( server ) )
+ {
+ serversNeedingAnimation.remove( server );
+ if ( serversNeedingAnimation.isEmpty() )
+ stopAnimationThread = true;
+ }
+ }
+
+ if ( stopAnimationThread )
+ {
+ stopAnimationThread();
+ }
+ }
+ break;
+ // The server has been renamed
+ case RENAMED:
+ // We simply refresh the server
+ refreshServer( server );
+ break;
+ }
+
+ }
+ };
+
+ // Adding the listener to the servers
+ for ( LdapServer server : LdapServersManager.getDefault().getServersList() )
+ {
+ server.addListener( serverListener );
+ }
+ }
+
+
+ /**
+ * Adds a server.
+ *
+ * @param server
+ * the server
+ */
+ private void addServer( final LdapServer server )
+ {
+ Display.getDefault().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+ add( ROOT, server );
+ }
+ } );
+ }
+
+
+ /**
+ * Refreshes a server.
+ *
+ * @param server
+ * the server
+ */
+ private void refreshServer( final LdapServer server )
+ {
+ Display.getDefault().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ refresh( server );
+ ISelection sel = ServersTableViewer.this.getSelection();
+ ServersTableViewer.this.setSelection( sel );
+ }
+ catch ( Exception e )
+ {
+ // ignore
+ }
+ }
+ } );
+ }
+
+
+ /**
+ * Removes a server.
+ *
+ * @param server
+ * the server
+ */
+ private void removeServer( final LdapServer server )
+ {
+ Display.getDefault().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+ remove( server );
+ }
+ } );
+ }
+
+
+ /**
+ * Starts the animation thread.
+ */
+ private void startAnimationThread()
+ {
+ stopAnimation = false;
+
+ final Display display = getTree().getDisplay();
+ final int SLEEP = 200;
+ final Runnable[] animatorThread = new Runnable[1];
+ animatorThread[0] = new Runnable()
+ {
+ public void run()
+ {
+ // Checking if we need to stop the animation
+ if ( !stopAnimation )
+ {
+ try
+ {
+ // Changing the animation state on the label provider
+ labelProvider.animate();
+
+ // Looping on the currently starting servers
+ for ( LdapServer server : serversNeedingAnimation.toArray( new LdapServer[0] ) )
+ {
+ if ( server != null && getTree() != null && !getTree().isDisposed() )
+ {
+ updateAnimation( server );
+ }
+ }
+ }
+ catch ( Exception e )
+ {
+ // Trace.trace( Trace.FINEST, "Error in Servers view animation", e ); TODO
+ }
+
+ // Re-launching the animation
+ display.timerExec( SLEEP, animatorThread[0] );
+ }
+ }
+ };
+
+ // Launching the animation asynchronously
+ Display.getDefault().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+ display.timerExec( SLEEP, animatorThread[0] );
+ }
+ } );
+ }
+
+
+ /**
+ * Stops the animation thread.
+ */
+ private void stopAnimationThread()
+ {
+ stopAnimation = true;
+ }
+
+
+ /**
+ * Updates the animation for the given server
+ *
+ * @param server
+ * the server
+ */
+ private void updateAnimation( LdapServer server )
+ {
+ try
+ {
+ Widget widget = doFindItem( server );
+ TreeItem item = ( TreeItem ) widget;
+ item.setText( 1, labelProvider.getColumnText( server, 1 ) );
+ item.setImage( 1, labelProvider.getColumnImage( server, 1 ) );
+ }
+ catch ( Exception e )
+ {
+ // Trace.trace( Trace.WARNING, "Error in optimized animation", e );
+ //TODO
+ }
+ }
+
+
+ /**
+ * Resorts the table based on field.
+ *
+ * @param column
+ * the column being updated
+ * @param col
+ * the column
+ */
+ protected void resortTable( final TreeColumn column, int col )
+ {
+ ServersViewerComparator sorter = ( ServersViewerComparator ) getComparator();
+
+ if ( col == sorter.getTopPriority() )
+ sorter.reverseTopPriority();
+ else
+ sorter.setTopPriority( col );
+
+ PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+ refresh();
+ updateDirectionIndicator( column );
+ }
+ } );
+ }
+
+
+ /**
+ * Updates the direction indicator as column is now the primary column.
+ *
+ * @param column
+ */
+ protected void updateDirectionIndicator( TreeColumn column )
+ {
+ getTree().setSortColumn( column );
+ if ( ( ( ServersViewerComparator ) getComparator() ).getTopPriorityDirection() == ServersViewerComparator.ASCENDING )
+ getTree().setSortDirection( SWT.UP );
+ else
+ getTree().setSortDirection( SWT.DOWN );
+ }
+}
\ No newline at end of file
Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java?rev=963311&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java Mon Jul 12 15:04:29 2010
@@ -0,0 +1,498 @@
+/*
+ * 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.ldapservers.views;
+
+
+import org.apache.directory.studio.ldapservers.LdapServersManager;
+import org.apache.directory.studio.ldapservers.LdapServersManagerListener;
+import org.apache.directory.studio.ldapservers.model.LdapServer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.contexts.IContextActivation;
+import org.eclipse.ui.part.ViewPart;
+
+
+/**
+ * This class implements the Servers view.
+ * <p>
+ * It displays the list of Apache Directory Servers.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ServersView extends ViewPart
+{
+ /** The ID of the view */
+// public static final String ID = ApacheDsPluginConstants.VIEW_SERVERS_VIEW;
+
+ /** The tree*/
+ private Tree tree;
+
+ /** The table viewer */
+ private ServersTableViewer tableViewer;
+
+ /** The view instance */
+ private ServersView instance;
+
+ /** Token used to activate and deactivate shortcuts in the view */
+ private IContextActivation contextActivation;
+
+ private static final String TAG_COLUMN_WIDTH = "columnWidth"; //$NON-NLS-1$
+ protected int[] columnWidths;
+
+ // Actions
+// private NewServerAction newServer;
+// private OpenConfigurationAction openConfiguration;
+// private DeleteAction delete;
+// private RenameAction rename;
+// private RunAction run;
+// private StopAction stop;
+// private CreateConnectionAction createConnection;
+// private PropertiesAction properties;
+
+ // Listeners
+ private LdapServersManagerListener ldapServersManagerListener = new LdapServersManagerListener()
+ {
+ public void serverAdded( LdapServer server )
+ {
+ tableViewer.refresh();
+ }
+
+
+ public void serverRemoved( LdapServer server )
+ {
+ tableViewer.refresh();
+ }
+
+
+ public void serverUpdated( LdapServer server )
+ {
+ tableViewer.refresh();
+ }
+ };
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createPartControl( Composite parent )
+ {
+ instance = this;
+
+ // Creating the Tree
+ tree = new Tree( parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL );
+ tree.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+ tree.setHeaderVisible( true );
+ tree.setLinesVisible( false );
+
+ // Adding columns
+ TreeColumn serverColumn = new TreeColumn( tree, SWT.SINGLE );
+ serverColumn.setText( Messages.getString( "ServersView.server" ) ); //$NON-NLS-1$
+ serverColumn.setWidth( columnWidths[0] );
+ serverColumn.addSelectionListener( getHeaderListener( 0 ) );
+ tree.setSortColumn( serverColumn );
+ tree.setSortDirection( SWT.UP );
+
+ TreeColumn stateColumn = new TreeColumn( tree, SWT.SINGLE );
+ stateColumn.setText( Messages.getString( "ServersView.state" ) ); //$NON-NLS-1$
+ stateColumn.setWidth( columnWidths[1] );
+ stateColumn.addSelectionListener( getHeaderListener( 1 ) );
+
+ // Creating the viewer
+ tableViewer = new ServersTableViewer( tree );
+
+// initActions();
+// initToolbar();
+// initContextMenu();
+// initListeners();
+
+ // set help context
+ // TODO
+// PlatformUI.getWorkbench().getHelpSystem()
+// .setHelp( parent, ApacheDsPluginConstants.PLUGIN_ID + "." + "gettingstarted_views_servers" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ /**
+ * Gets a header listener for the given column.
+ *
+ * @param col
+ * the column
+ * @return
+ * a header listener for the given column
+ */
+ private SelectionListener getHeaderListener( final int col )
+ {
+ return new SelectionAdapter()
+ {
+ /**
+ * Handles the case of user selecting the header area.
+ */
+ public void widgetSelected( SelectionEvent e )
+ {
+ if ( tableViewer == null )
+ return;
+ TreeColumn column = ( TreeColumn ) e.widget;
+ tableViewer.resortTable( column, col );
+ }
+ };
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
+ */
+ public void init( IViewSite site, IMemento memento ) throws PartInitException
+ {
+ super.init( site, memento );
+ columnWidths = new int[]
+ { 150, 80 };
+ for ( int i = 0; i < 2; i++ )
+ {
+ if ( memento != null )
+ {
+ Integer in = memento.getInteger( TAG_COLUMN_WIDTH + i );
+ if ( in != null && in.intValue() > 5 )
+ {
+ columnWidths[i] = in.intValue();
+ }
+ }
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.ViewPart#saveState(org.eclipse.ui.IMemento)
+ */
+ public void saveState( IMemento memento )
+ {
+ TreeColumn[] tc = tableViewer.getTree().getColumns();
+ for ( int i = 0; i < 2; i++ )
+ {
+ int width = tc[i].getWidth();
+ if ( width != 0 )
+ {
+ memento.putInteger( TAG_COLUMN_WIDTH + i, width );
+ }
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ public void setFocus()
+ {
+ if ( tree != null )
+ {
+ tree.setFocus();
+ }
+ }
+
+
+// /**
+// * Initializes the actions.
+// */
+// private void initActions()
+// {
+// newServer = new NewServerAction();
+//
+// openConfiguration = new OpenConfigurationAction( this );
+// openConfiguration.setEnabled( false );
+//
+// delete = new DeleteAction( this );
+// delete.setEnabled( false );
+//
+// rename = new RenameAction( this );
+// rename.setEnabled( false );
+//
+// run = new RunAction( this );
+// run.setEnabled( false );
+//
+// stop = new StopAction( this );
+// stop.setEnabled( false );
+//
+// createConnection = new CreateConnectionAction( this );
+// createConnection.setEnabled( false );
+//
+// properties = new PropertiesAction( this );
+// properties.setEnabled( false );
+// }
+
+
+// /**
+// * Initializes the toolbar.
+// */
+// private void initToolbar()
+// {
+// IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
+// toolbar.add( newServer );
+// toolbar.add( new Separator() );
+// toolbar.add( run );
+// toolbar.add( stop );
+// }
+
+
+// /**
+// * Initializes the Context Menu.
+// */
+// private void initContextMenu()
+// {
+// MenuManager contextMenu = new MenuManager( "" ); //$NON-NLS-1$
+// contextMenu.setRemoveAllWhenShown( true );
+// contextMenu.addMenuListener( new IMenuListener()
+// {
+// public void menuAboutToShow( IMenuManager manager )
+// {
+// MenuManager newManager = new MenuManager( Messages.getString( "ServersView.new" ) ); //$NON-NLS-1$
+// newManager.add( newServer );
+// manager.add( newManager );
+// manager.add( openConfiguration );
+// manager.add( new Separator() );
+// manager.add( delete );
+// manager.add( rename );
+// manager.add( new Separator() );
+// manager.add( run );
+// manager.add( stop );
+// manager.add( new Separator() );
+// MenuManager ldapBrowserManager = new MenuManager( Messages.getString( "ServersView.ldapBrowser" ) ); //$NON-NLS-1$
+// ldapBrowserManager.add( createConnection );
+// manager.add( ldapBrowserManager );
+// manager.add( new Separator() );
+// manager.add( properties );
+// }
+// } );
+//
+// // set the context menu to the table viewer
+// tableViewer.getControl().setMenu( contextMenu.createContextMenu( tableViewer.getControl() ) );
+//
+// // register the context menu to enable extension actions
+// getSite().registerContextMenu( contextMenu, tableViewer );
+// }
+
+
+// /**
+// * Initializes the listeners
+// */
+// private void initListeners()
+// {
+// LdapServersManager serversHandler = LdapServersManager.getDefault();
+// serversHandler.addListener( ldapServersManagerListener );
+//
+// tableViewer.addDoubleClickListener( new IDoubleClickListener()
+// {
+// public void doubleClick( DoubleClickEvent event )
+// {
+// openConfiguration.run();
+// }
+// } );
+//
+// tableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+// {
+// public void selectionChanged( SelectionChangedEvent event )
+// {
+// updateActionsStates();
+// }
+// } );
+//
+// // Initializing the PartListener
+// getSite().getPage().addPartListener( new IPartListener2()
+// {
+// /**
+// * This implementation deactivates the shortcuts when the part is deactivated.
+// */
+// public void partDeactivated( IWorkbenchPartReference partRef )
+// {
+// if ( partRef.getPart( false ) == instance && contextActivation != null )
+// {
+// ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+// ICommandService.class );
+// if ( commandService != null )
+// {
+// commandService.getCommand( newServer.getActionDefinitionId() ).setHandler( null );
+// commandService.getCommand( openConfiguration.getActionDefinitionId() ).setHandler( null );
+// commandService.getCommand( delete.getActionDefinitionId() ).setHandler( null );
+// commandService.getCommand( rename.getActionDefinitionId() ).setHandler( null );
+// commandService.getCommand( run.getActionDefinitionId() ).setHandler( null );
+// commandService.getCommand( stop.getActionDefinitionId() ).setHandler( null );
+// commandService.getCommand( properties.getActionDefinitionId() ).setHandler( null );
+// }
+//
+// IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
+// IContextService.class );
+// contextService.deactivateContext( contextActivation );
+// contextActivation = null;
+// }
+// }
+//
+//
+// /**
+// * This implementation activates the shortcuts when the part is activated.
+// */
+// public void partActivated( IWorkbenchPartReference partRef )
+// {
+// if ( partRef.getPart( false ) == instance )
+// {
+// IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
+// IContextService.class );
+// contextActivation = contextService.activateContext( ApacheDsPluginConstants.CONTEXTS_SERVERS_VIEW );
+//
+// ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+// ICommandService.class );
+// if ( commandService != null )
+// {
+// commandService.getCommand( newServer.getActionDefinitionId() ).setHandler(
+// new ActionHandler( newServer ) );
+// commandService.getCommand( openConfiguration.getActionDefinitionId() ).setHandler(
+// new ActionHandler( openConfiguration ) );
+// commandService.getCommand( delete.getActionDefinitionId() ).setHandler(
+// new ActionHandler( delete ) );
+// commandService.getCommand( rename.getActionDefinitionId() ).setHandler(
+// new ActionHandler( rename ) );
+// commandService.getCommand( run.getActionDefinitionId() ).setHandler( new ActionHandler( run ) );
+// commandService.getCommand( stop.getActionDefinitionId() )
+// .setHandler( new ActionHandler( stop ) );
+// commandService.getCommand( properties.getActionDefinitionId() ).setHandler(
+// new ActionHandler( properties ) );
+// }
+// }
+// }
+//
+//
+// public void partBroughtToTop( IWorkbenchPartReference partRef )
+// {
+// }
+//
+//
+// public void partClosed( IWorkbenchPartReference partRef )
+// {
+// }
+//
+//
+// public void partHidden( IWorkbenchPartReference partRef )
+// {
+// }
+//
+//
+// public void partInputChanged( IWorkbenchPartReference partRef )
+// {
+// }
+//
+//
+// public void partOpened( IWorkbenchPartReference partRef )
+// {
+// }
+//
+//
+// public void partVisible( IWorkbenchPartReference partRef )
+// {
+// }
+//
+// } );
+// }
+//
+//
+// /**
+// * Enables or disables the actions according to the current selection
+// * in the viewer.
+// */
+// public void updateActionsStates()
+// {
+// // Getting the selection
+// StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection();
+//
+// if ( !selection.isEmpty() )
+// {
+// Server server = ( Server ) selection.getFirstElement();
+//
+// switch ( server.getState() )
+// {
+// case STARTED:
+// run.setEnabled( false );
+// stop.setEnabled( true );
+// break;
+// case STARTING:
+// run.setEnabled( false );
+// stop.setEnabled( false );
+// break;
+// case STOPPED:
+// run.setEnabled( true );
+// stop.setEnabled( false );
+// break;
+// case STOPPING:
+// run.setEnabled( false );
+// stop.setEnabled( false );
+// break;
+// case UNKNONW:
+// run.setEnabled( false );
+// stop.setEnabled( false );
+// break;
+// }
+//
+// openConfiguration.setEnabled( true );
+// delete.setEnabled( true );
+// rename.setEnabled( true );
+// createConnection.setEnabled( true );
+// properties.setEnabled( true );
+// }
+// else
+// {
+// openConfiguration.setEnabled( false );
+// delete.setEnabled( false );
+// rename.setEnabled( false );
+// run.setEnabled( false );
+// stop.setEnabled( false );
+// createConnection.setEnabled( false );
+// properties.setEnabled( false );
+// }
+// }
+
+
+ /**
+ * Gets the table viewer.
+ *
+ * @return
+ * the table viewer
+ */
+ public TreeViewer getViewer()
+ {
+ return tableViewer;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#dispose()
+ */
+ public void dispose()
+ {
+ LdapServersManager.getDefault().removeListener( ldapServersManagerListener );
+
+ super.dispose();
+ }
+}
Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewContentProvider.java?rev=963311&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewContentProvider.java (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewContentProvider.java Mon Jul 12 15:04:29 2010
@@ -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.ldapservers.views;
+
+
+import org.apache.directory.studio.ldapservers.LdapServersManager;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * This class implements the content provider for the Servers view.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ServersViewContentProvider implements IStructuredContentProvider, ITreeContentProvider
+{
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements( Object inputElement )
+ {
+ return LdapServersManager.getDefault().getServersList().toArray();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose()
+ {
+ // Nothing to do
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+ {
+ // Nothing to do
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ public Object[] getChildren( Object parentElement )
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public Object getParent( Object element )
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren( Object element )
+ {
+ return false;
+ }
+}
Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java?rev=963311&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java Mon Jul 12 15:04:29 2010
@@ -0,0 +1,169 @@
+/*
+ * 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.ldapservers.views;
+
+
+import org.apache.directory.studio.ldapservers.LdapServersPlugin;
+import org.apache.directory.studio.ldapservers.LdapServersPluginConstants;
+import org.apache.directory.studio.ldapservers.model.LdapServer;
+import org.apache.directory.studio.ldapservers.model.LdapServerStatus;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * This class implements the label provider for the Servers view.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ServersViewLabelProvider extends LabelProvider implements ITableLabelProvider
+{
+ private static final String THREE_DOTS = "..."; //$NON-NLS-1$
+ private static final String TWO_DOTS = ".."; //$NON-NLS-1$
+ private static final String ONE_DOT = "."; //$NON-NLS-1$
+ private int count = 1;
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+ */
+ public String getColumnText( Object element, int columnIndex )
+ {
+ if ( element instanceof LdapServer )
+ {
+ LdapServer server = ( LdapServer ) element;
+ if ( columnIndex == 0 )
+ {
+ return server.getName();
+ }
+ else if ( columnIndex == 1 )
+ {
+ LdapServerStatus status = ( ( LdapServer ) element ).getStatus();
+ switch ( status )
+ {
+ case STARTED:
+ return "started"; // TODO
+ case STARTING:
+ return "starting" + getDots(); // TODO
+ case RESTARTED:
+ return "restarted"; // TODO
+ case RESTARTING:
+ return "restarting" + getDots(); // TODO
+ case STOPPED:
+ return "stopped"; // TODO
+ case STOPPING:
+ return "stopped" + getDots(); // TODO
+ case UNKNOWN:
+ return "unkown"; // TODO
+ }
+ }
+
+ }
+
+ return null;
+ }
+
+
+ private String getDots()
+ {
+ if ( count == 1 )
+ {
+ return ServersViewLabelProvider.ONE_DOT;
+ }
+ else if ( count == 2 )
+ {
+ return ServersViewLabelProvider.TWO_DOTS;
+ }
+ else
+ {
+ return ServersViewLabelProvider.THREE_DOTS;
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+ */
+ public Image getColumnImage( Object element, int columnIndex )
+ {
+ if ( element instanceof LdapServer )
+ {
+ if ( columnIndex == 0 )
+ {
+ return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER );
+ }
+ else if ( columnIndex == 1 )
+ {
+ switch ( ( ( LdapServer ) element ).getStatus() )
+ {
+ case STARTED:
+ return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STARTED );
+ case STARTING:
+ switch ( count )
+ {
+ case 1:
+ return LdapServersPlugin.getDefault().getImage(
+ LdapServersPluginConstants.IMG_SERVER_STARTING1 );
+ case 2:
+ return LdapServersPlugin.getDefault().getImage(
+ LdapServersPluginConstants.IMG_SERVER_STARTING2 );
+ case 3:
+ return LdapServersPlugin.getDefault().getImage(
+ LdapServersPluginConstants.IMG_SERVER_STARTING3 );
+ }
+ case STOPPED:
+ return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STOPPED );
+ case STOPPING:
+ switch ( count )
+ {
+ case 1:
+ return LdapServersPlugin.getDefault().getImage(
+ LdapServersPluginConstants.IMG_SERVER_STOPPING1 );
+ case 2:
+ return LdapServersPlugin.getDefault().getImage(
+ LdapServersPluginConstants.IMG_SERVER_STOPPING2 );
+ case 3:
+ return LdapServersPlugin.getDefault().getImage(
+ LdapServersPluginConstants.IMG_SERVER_STOPPING3 );
+ }
+ case UNKNOWN:
+ return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER );
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Increase the counter of the animation.
+ */
+ public void animate()
+ {
+ count++;
+
+ if ( count > 3 )
+ {
+ count = 1;
+ }
+ }
+}
Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewerComparator.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewerComparator.java?rev=963311&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewerComparator.java (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewerComparator.java Mon Jul 12 15:04:29 2010
@@ -0,0 +1,197 @@
+/*
+ * 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.
+ *
+ */
+/*******************************************************************************
+ * Copyright (c) 2003, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.apache.directory.studio.ldapservers.views;
+
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+
+
+/**
+ * This class implements the servers table viewer comparator.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ServersViewerComparator extends ViewerComparator
+{
+ public static final int MAX_DEPTH = 3;
+ public static final int ASCENDING = 1;
+ public static final int DESCENDING = -1;
+
+ protected ServersViewLabelProvider labelProvider;
+
+ protected int[] priorities = new int[]
+ { 0 };
+
+ protected int[] directions = new int[]
+ { ASCENDING };
+
+
+ /**
+ * Creates a new instance of ServersViewerComparator.
+ *
+ * @param labelProvider
+ * the label provider
+ */
+ public ServersViewerComparator( ServersViewLabelProvider labelProvider )
+ {
+ this.labelProvider = labelProvider;
+ }
+
+
+ /**
+ * Sets the top priority.
+ *
+ * @param priority
+ * the priority
+ */
+ public void setTopPriority( int priority )
+ {
+ if ( priorities[0] == priority )
+ {
+ return;
+ }
+
+ int len = priorities.length + 1;
+ if ( len > MAX_DEPTH )
+ {
+ len = MAX_DEPTH;
+ }
+
+ int[] temp = new int[len];
+ System.arraycopy( priorities, 0, temp, 1, len - 1 );
+ temp[0] = priority;
+ priorities = temp;
+
+ temp = new int[len];
+ System.arraycopy( directions, 0, temp, 1, len - 1 );
+ temp[0] = ASCENDING;
+ directions = temp;
+ }
+
+
+ /**
+ * Gets the top priority.
+ *
+ * @return
+ * the top priority
+ */
+ public int getTopPriority()
+ {
+ return priorities[0];
+ }
+
+
+ /**
+ * Sets the top priority direction
+ *
+ * @param direction
+ * the direction
+ */
+ public void setTopPriorityDirection( int direction )
+ {
+ if ( direction == ASCENDING || direction == DESCENDING )
+ {
+ directions[0] = direction;
+ }
+ }
+
+
+ /**
+ * Gets the top priority direction
+ *
+ * @return
+ * the top priority direction
+ */
+ public int getTopPriorityDirection()
+ {
+ return directions[0];
+ }
+
+
+ /**
+ * Reverses the top priority
+ */
+ public void reverseTopPriority()
+ {
+ directions[0] *= -1;
+ }
+
+
+ /**
+ * Returns a negative, zero, or positive number depending on whether
+ * the first element is less than, equal to, or greater than
+ * the second element.
+ * <p>
+ * The default implementation of this method is based on
+ * comparing the elements' categories as computed by the <code>category</code>
+ * framework method. Elements within the same category are further
+ * subjected to a case insensitive compare of their label strings, either
+ * as computed by the content viewer's label provider, or their
+ * <code>toString</code> values in other cases. Subclasses may override.
+ * </p>
+ *
+ * @param viewer the viewer
+ * @param e1 the first element
+ * @param e2 the second element
+ * @param a the direction
+ * @return a negative number if the first element is less than the
+ * second element; the value <code>0</code> if the first element is
+ * equal to the second element; and a positive number if the first
+ * element is greater than the second element
+ */
+ public int compare( Viewer viewer, Object e1, Object e2, int a )
+ {
+ int col = priorities[a];
+
+ String s1 = labelProvider.getColumnText( e1, col );
+ String s2 = labelProvider.getColumnText( e2, col );
+
+ int s = s1.compareToIgnoreCase( s2 ) * directions[a];
+ if ( s == 0 )
+ {
+ if ( a == priorities.length - 1 )
+ {
+ return 0;
+ }
+ return compare( viewer, e1, e2, a + 1 );
+ }
+ return s;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public int compare( Viewer viewer, Object e1, Object e2 )
+ {
+ return compare( viewer, e1, e2, 0 );
+ }
+}
\ No newline at end of file
Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages.properties?rev=963311&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages.properties (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages.properties Mon Jul 12 15:04:29 2010
@@ -0,0 +1,21 @@
+# 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.
+
+ServersView.ldapBrowser=LDAP Browser
+ServersView.new=&New
+ServersView.server=Server
+ServersView.state=State
Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages_de.properties?rev=963311&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages_de.properties (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages_de.properties Mon Jul 12 15:04:29 2010
@@ -0,0 +1,21 @@
+# 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.
+
+ServersView.ldapBrowser=LDAP Browser
+ServersView.new=&Neu
+ServersView.server=Server
+ServersView.state=Status
Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages_fr.properties?rev=963311&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages_fr.properties (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/messages_fr.properties Mon Jul 12 15:04:29 2010
@@ -0,0 +1,21 @@
+# 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.
+
+ServersView.ldapBrowser=Navigateur LDAP
+ServersView.new=&Nouveau
+ServersView.server=Serveur
+ServersView.state=Etat