You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2015/06/24 22:35:11 UTC
svn commit: r1687366 - in
/directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui:
messages.properties messages_de.properties messages_fr.properties
widgets/TableWidget.java
Author: elecharny
Date: Wed Jun 24 20:35:11 2015
New Revision: 1687366
URL: http://svn.apache.org/r1687366
Log:
o Added the Up and Down buttons, for ordered table
o Added some methods to create a table with up/down buttons
Modified:
directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages.properties
directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_de.properties
directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_fr.properties
directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/widgets/TableWidget.java
Modified: directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages.properties?rev=1687366&r1=1687365&r2=1687366&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages.properties (original)
+++ directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages.properties Wed Jun 24 20:35:11 2015
@@ -24,6 +24,9 @@ CommonUIUtils.Warning=Warning
StudioPreferencePage.Description=Expand the tree to edit preferences for a specific feature.
StudioPreferencePage.Title=Apache Directory Studio
-CommonUIWidgets.Add=Add...
-CommonUIWidgets.Edit=Edit...
-CommonUIWidgets.Delete=Delete
\ No newline at end of file
+# The TableWidget Strings
+CommonUIWidgets.AddButton=Add...
+CommonUIWidgets.EditButton=Edit...
+CommonUIWidgets.DeleteButton=Delete
+CommonUIWidgets.UpButton=Up...
+CommonUIWidgets.DownButton=Down...
\ No newline at end of file
Modified: directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_de.properties?rev=1687366&r1=1687365&r2=1687366&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_de.properties (original)
+++ directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_de.properties Wed Jun 24 20:35:11 2015
@@ -24,6 +24,9 @@ CommonUIUtils.Warning=Warnung
StudioPreferencePage.Description=Men\u00FC aufklappen, um Benutzervorgaben f\u00FCr weitere Funktionen zu bearbeiten.
-CommonUIWidgets.Add=Add...
-CommonUIWidgets.Edit=Edit...
-CommonUIWidgets.Delete=Delete
\ No newline at end of file
+# The TableWidget Strings
+CommonUIWidgets.AddButton=Add...
+CommonUIWidgets.EditButton=Edit...
+CommonUIWidgets.DeleteButton=Delete
+CommonUIWidgets.UpButton=Up...
+CommonUIWidgets.DownButton=Down...
\ No newline at end of file
Modified: directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_fr.properties?rev=1687366&r1=1687365&r2=1687366&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_fr.properties (original)
+++ directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/messages_fr.properties Wed Jun 24 20:35:11 2015
@@ -23,7 +23,9 @@ CommonUIUtils.Warning=Attention
StudioPreferencePage.Description=D\u00E9plier l''arbre pour modifier les pr\u00E9f\u00E9rences d''une fonctionnalit\u00E9 particuli\u00E8re.
-
-CommonUIWidgets.Add=Ajout
-CommonUIWidgets.Edit=Edition
-CommonUIWidgets.Delete=Suppression
\ No newline at end of file
+# The TableWidget Strings
+CommonUIWidgets.AddButton=Ajout
+CommonUIWidgets.EditButton=Edition
+CommonUIWidgets.DeleteButton=Suppression
+CommonUIWidgets.UpButton=Remonter
+CommonUIWidgets.DownButton=Descendre
\ No newline at end of file
Modified: directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/widgets/TableWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/widgets/TableWidget.java?rev=1687366&r1=1687365&r2=1687366&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/widgets/TableWidget.java (original)
+++ directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/widgets/TableWidget.java Wed Jun 24 20:35:11 2015
@@ -74,14 +74,27 @@ public class TableWidget<E> extends Abst
/** A flag set to tell if we have a Edit button */
private boolean hasEdit;
+
+ /** A flag set when the table is ordered (ie, it has a Up and Down buttons) */
+ private boolean isOrdered;
+
+ /** The flag set when the table is ordered */
+ private static final boolean ORDERED = true;
+
+ /** The flag set when the table is not ordered */
+ private static final boolean UNORDERED = false;
// UI widgets
private Composite composite;
private Table elementTable;
private TableViewer elementTableViewer;
+
+ // The buttons
private Button addButton;
private Button editButton;
private Button deleteButton;
+ private Button upButton;
+ private Button downButton;
/** The decorator */
private TableDecorator<E> decorator;
@@ -99,9 +112,23 @@ public class TableWidget<E> extends Abst
}
deleteButton.setEnabled( !selection.isEmpty() );
+
+ if ( isOrdered )
+ {
+ int selectionLine = elementTableViewer.getTable().getSelectionIndex();
+
+ // We can't enable the UP button when we don't have any element in the table,
+ // or when we have only one, or when the selection is the first one in the table
+ upButton.setEnabled( !selection.isEmpty() && ( elements.size() > 1 ) && ( selectionLine > 0 ) );
+
+ // We can't enable the DOWN button when we don't have any element in the table,
+ // or when we have only one element, or when the selected element is the last one
+ downButton.setEnabled( !selection.isEmpty() && ( elements.size() > 1 ) && ( selectionLine < elements.size() - 1 ) );
+ }
}
};
+
// A listener on the Element table, that reacts to a doubleClick : it's opening the Element editor
private IDoubleClickListener tableViewerDoubleClickListener = new IDoubleClickListener()
{
@@ -111,6 +138,7 @@ public class TableWidget<E> extends Abst
}
};
+
// A listener on the Add button, which opens the Element addition editor
private SelectionListener addButtonListener = new SelectionAdapter()
{
@@ -120,6 +148,7 @@ public class TableWidget<E> extends Abst
}
};
+
// A listener on the Edit button, that open the Element editor
private SelectionListener editButtonListener = new SelectionAdapter()
{
@@ -129,6 +158,7 @@ public class TableWidget<E> extends Abst
}
};
+
// A listener on the Delete button, which delete the selected Element
private SelectionListener deleteButtonListener = new SelectionAdapter()
{
@@ -137,6 +167,26 @@ public class TableWidget<E> extends Abst
deleteElement();
}
};
+
+
+ // A listener on the Up button, that move the selected elemnt up one position
+ private SelectionListener upButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ upElement();
+ }
+ };
+
+
+ // A listener on the Down button, that move the selected element down one position
+ private SelectionListener downButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ downElement();
+ }
+ };
/**
@@ -166,7 +216,7 @@ public class TableWidget<E> extends Abst
*/
public void createWidgetWithEdit( Composite parent, FormToolkit toolkit )
{
- createWidget( parent, toolkit, true );
+ createWidget( parent, toolkit, true, UNORDERED );
}
@@ -185,7 +235,52 @@ public class TableWidget<E> extends Abst
*/
public void createWidgetNoEdit( Composite parent, FormToolkit toolkit )
{
- createWidget( parent, toolkit, false );
+ createWidget( parent, toolkit, false, UNORDERED );
+ }
+
+
+ /**
+ * Creates the ordered Table widget. It's a Table and five buttons :
+ * <pre>
+ * +--------------------------------------+
+ * | Element 1 | (Add... )
+ * | Element 2 | (Edit...)
+ * | | (Delete )
+ * | | ---------
+ * | | (Up... )
+ * | | (Down.. )
+ * +--------------------------------------+
+ * </pre>
+ * The 'Up' and 'Down' buttons are used to order the elements.
+ *
+ * @param parent the parent
+ * @param toolkit the toolkit
+ */
+ public void createOrderedWidgetWithEdit( Composite parent, FormToolkit toolkit )
+ {
+ createWidget( parent, toolkit, true, ORDERED );
+ }
+
+
+ /**
+ * Creates the Table widget. It's a Table and four buttons :
+ * <pre>
+ * +--------------------------------------+
+ * | Element 1 | (Add... )
+ * | Element 2 | (Delete )
+ * | | ---------
+ * | | (Up... )
+ * | | (Down.. )
+ * +--------------------------------------+
+ * </pre>
+ * The 'Up' and 'Down' buttons are used to order the elements.
+ *
+ * @param parent the parent
+ * @param toolkit the toolkit
+ */
+ public void createOrderedWidgetNoEdit( Composite parent, FormToolkit toolkit )
+ {
+ createWidget( parent, toolkit, true, ORDERED );
}
@@ -207,12 +302,25 @@ public class TableWidget<E> extends Abst
* +--------------------------------------+
* </pre>
*
+ * If the table is ordered, we have two additional buttons to re-organize
+ * the elements at will :
+ * <pre>
+ * ...
+ * | | ---------
+ * | | (Up... )
+ * | | (Down.. )
+ * +--------------------------------------+
+ * </pre>
+ *
* @param parent the parent
* @param toolkit the toolkit
+ * @param hasEdit the flag set when the Edit button is present
+ * @param isOrdered the flag set when we have the Up and Down buttons
*/
- private void createWidget( Composite parent, FormToolkit toolkit, boolean hasEdit )
+ private void createWidget( Composite parent, FormToolkit toolkit, boolean hasEdit, boolean isOrdered )
{
this.hasEdit = hasEdit;
+ this.isOrdered = isOrdered;
// Composite
if ( toolkit != null )
@@ -239,8 +347,16 @@ public class TableWidget<E> extends Abst
elementTable = new Table( composite, SWT.NULL );
}
- // Define the table size and height. It will span on 3 lines.
- GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 3 );
+ // Define the table size and height. It will span on 3 to 5 lines,
+ // depending on the number of buttons
+ int nbLinesSpan = 3;
+
+ if ( isOrdered )
+ {
+ nbLinesSpan += 2;
+ }
+
+ GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true, 1, nbLinesSpan );
gd.heightHint = 20;
gd.widthHint = 100;
elementTable.setLayoutData( gd );
@@ -265,11 +381,11 @@ public class TableWidget<E> extends Abst
// Create the Add Button and its listener
if ( toolkit != null )
{
- addButton = toolkit.createButton( composite, Messages.getString( "CommonUIWidgets.Add" ), SWT.PUSH );
+ addButton = toolkit.createButton( composite, Messages.getString( "CommonUIWidgets.AddButton" ), SWT.PUSH );
}
else
{
- addButton = BaseWidgetUtils.createButton( composite, Messages.getString( "CommonUIWidgets.Add" ), 1 );
+ addButton = BaseWidgetUtils.createButton( composite, Messages.getString( "CommonUIWidgets.AddButton" ), 1 );
}
addButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
@@ -280,11 +396,11 @@ public class TableWidget<E> extends Abst
{
if ( toolkit != null )
{
- editButton = toolkit.createButton( composite, Messages.getString( "CommonUIWidgets.Edit" ), SWT.PUSH );
+ editButton = toolkit.createButton( composite, Messages.getString( "CommonUIWidgets.EditButton" ), SWT.PUSH );
}
else
{
- editButton = BaseWidgetUtils.createButton( composite, Messages.getString( "CommonUIWidgets.Edit" ), SWT.PUSH );
+ editButton = BaseWidgetUtils.createButton( composite, Messages.getString( "CommonUIWidgets.EditButton" ), SWT.PUSH );
}
// It's not enabled unless we have selected an element
@@ -296,17 +412,53 @@ public class TableWidget<E> extends Abst
// Create the Delete Button and its listener
if ( toolkit != null )
{
- deleteButton = toolkit.createButton( composite, Messages.getString( "CommonUIWidgets.Delete" ), SWT.PUSH );
+ deleteButton = toolkit.createButton( composite, Messages.getString( "CommonUIWidgets.DeleteButton" ), SWT.PUSH );
}
else
{
- deleteButton = BaseWidgetUtils.createButton( composite, Messages.getString( "CommonUIWidgets.Delete" ), SWT.PUSH );
+ deleteButton = BaseWidgetUtils.createButton( composite, Messages.getString( "CommonUIWidgets.DeleteButton" ), SWT.PUSH );
}
// It's not selected unless we have selected an index
deleteButton.setEnabled( false );
deleteButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
deleteButton.addSelectionListener( deleteButtonListener );
+
+ // Create the Up and Down button, if requested
+ if ( isOrdered )
+ {
+
+ // Create the Up Button and its listener
+ if ( toolkit != null )
+ {
+ upButton = toolkit.createButton( composite, Messages.getString( "CommonUIWidgets.UpButton" ), SWT.PUSH );
+ }
+ else
+ {
+ upButton = BaseWidgetUtils.createButton( composite, Messages.getString( "CommonUIWidgets.UpButton" ), SWT.PUSH );
+ }
+
+ // It's not selected unless we have selected an index
+ upButton.setEnabled( false );
+ upButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+ upButton.addSelectionListener( upButtonListener );
+
+
+ // Create the Down Button and its listener
+ if ( toolkit != null )
+ {
+ downButton = toolkit.createButton( composite, Messages.getString( "CommonUIWidgets.DownButton" ), SWT.PUSH );
+ }
+ else
+ {
+ downButton = BaseWidgetUtils.createButton( composite, Messages.getString( "CommonUIWidgets.DownButton" ), SWT.PUSH );
+ }
+
+ // It's not selected unless we have selected an index
+ downButton.setEnabled( false );
+ downButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+ downButton.addSelectionListener( downButtonListener );
+}
}
@@ -563,4 +715,63 @@ public class TableWidget<E> extends Abst
notifyListeners();
}
}
+
+
+ /**
+ * This method is called when the 'Up...' button is clicked
+ */
+ private void upElement()
+ {
+ StructuredSelection selection = ( StructuredSelection ) elementTableViewer.getSelection();
+
+ if ( !selection.isEmpty() )
+ {
+ // Get the line the selected element is in. We will move it up
+ int selectionLine = elementTableViewer.getTable().getSelectionIndex();
+
+ // The selected element
+ E selectedElement = (E)selection.getFirstElement();
+
+ // Just swap the elements which is just before with the selected one
+ E previousElement = getElements().get( selectionLine - 1 );
+ elements.remove( selectionLine - 1 );
+ elements.add( selectionLine, previousElement );
+
+ // Refresh the table now
+ elementTableViewer.refresh();
+ elementTableViewer.setSelection( new StructuredSelection( selectedElement ) );
+
+ notifyListeners();
+ }
+ }
+
+
+ /**
+ * This method is called when the 'Down...' button is clicked
+ * or the table viewer is double-clicked.
+ */
+ private void downElement()
+ {
+ StructuredSelection selection = ( StructuredSelection ) elementTableViewer.getSelection();
+
+ if ( !selection.isEmpty() )
+ {
+ // Get the line the selected element is in. We will move it down
+ int selectionLine = elementTableViewer.getTable().getSelectionIndex();
+
+ // The selected element
+ E selectedElement = (E)selection.getFirstElement();
+
+ // Just swap the elements which is just after with the selected one
+ E previousElement = getElements().get( selectionLine + 1 );
+ elements.remove( selectionLine + 1 );
+ elements.add( selectionLine, previousElement );
+
+ // refresh teh table now
+ elementTableViewer.refresh();
+ elementTableViewer.setSelection( new StructuredSelection( selectedElement ) );
+
+ notifyListeners();
+ }
+ }
}