You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/11/05 18:01:46 UTC
svn commit: r592087 [10/16] - in
/directory/sandbox/felixk/studio-ldapbrowser-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...
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorPasteAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorPasteAction.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorPasteAction.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorPasteAction.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,124 @@
+/*
+ * 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.ldapbrowser.ui.editors.searchresult;
+
+
+import org.apache.directory.studio.ldapbrowser.common.actions.PasteAction;
+import org.apache.directory.studio.ldapbrowser.common.dnd.ValuesTransfer;
+import org.apache.directory.studio.ldapbrowser.core.jobs.CreateValuesJob;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+
+
+/**
+ * Special paste action to copy the values of a copied attr-val to another
+ * attribute.
+ */
+public class SearchResultEditorPasteAction extends PasteAction
+{
+
+ public SearchResultEditorPasteAction()
+ {
+ super();
+ }
+
+
+ public String getText()
+ {
+ IValue[] values = getValuesToPaste();
+ if ( values != null )
+ {
+ return values.length > 1 ? "Paste Values" : "Paste Value";
+ }
+
+ return "Paste";
+ }
+
+
+ public boolean isEnabled()
+ {
+ if ( this.getValuesToPaste() != null )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ public void run()
+ {
+ IValue[] values = getValuesToPaste();
+ if ( values != null )
+ {
+// String attributeDescription = getSelectedAttributeHierarchies()[0].getAttribute().getDescription();
+//
+// String[] attributeDescriptions = new String[values.length];
+// Object[] rawValues = new Object[values.length];
+// for ( int v = 0; v < values.length; v++ )
+// {
+// attributeDescriptions[v] = attributeDescription;
+// rawValues[v] = values[v].getRawValue();
+// }
+// IEntry entry = getSelectedAttributeHierarchies()[0].getAttribute().getEntry();
+//
+// new CreateValuesJob( entry, attributeDescriptions, rawValues ).execute();
+ IEntry entry = getSelectedAttributeHierarchies()[0].getAttribute().getEntry();
+ new CreateValuesJob( entry, values ).execute();
+ }
+ }
+
+
+ /**
+ * Conditions: - an search result and a multiattribute are selected -
+ * there are IValues in clipboard
+ *
+ * @return
+ */
+ private IValue[] getValuesToPaste()
+ {
+ if ( getSelectedEntries().length + getSelectedBookmarks().length + getSelectedValues().length
+ + getSelectedAttributes().length + getSelectedSearches().length == 0
+ && getSelectedSearchResults().length == 1
+ && getSelectedAttributeHierarchies().length == 1
+ && getSelectedAttributeHierarchies()[0].size() == 1 )
+ {
+
+ Object content = this.getFromClipboard( ValuesTransfer.getInstance() );
+ if ( content != null && content instanceof IValue[] )
+ {
+ IValue[] values = ( IValue[] ) content;
+ return values;
+ }
+
+ // Object content =
+ // this.getFromClipboard(LdifAttrValLinesTransfer.getInstance());
+ // if (content != null && content instanceof LdifAttrValLine[])
+ // {
+ // LdifAttrValLine[] lines = (LdifAttrValLine[]) content;
+ // return lines;
+ // }
+ }
+
+ return null;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorPasteAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorQuickFilterWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorQuickFilterWidget.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorQuickFilterWidget.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorQuickFilterWidget.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,194 @@
+/*
+ * 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.ldapbrowser.ui.editors.searchresult;
+
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.eclipse.jface.preference.PreferenceConverter;
+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.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+
+public class SearchResultEditorQuickFilterWidget
+{
+
+ private SearchResultEditorFilter filter;
+
+ private Composite parent;
+
+ private Composite composite;
+
+ private Composite innerComposite;
+
+ private Text quickFilterValueText;
+
+ private Button clearQuickFilterButton;
+
+
+ public SearchResultEditorQuickFilterWidget( SearchResultEditorFilter filter )
+ {
+ this.filter = filter;
+ }
+
+
+ public void createComposite( Composite parent )
+ {
+ this.parent = parent;
+
+ this.composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+ GridLayout gl = new GridLayout();
+ gl.marginHeight = 2;
+ gl.marginWidth = 2;
+ composite.setLayout( gl );
+
+ this.innerComposite = null;
+ }
+
+
+ private void create()
+ {
+ innerComposite = BaseWidgetUtils.createColumnContainer( this.composite, 2, 1 );
+
+ this.quickFilterValueText = new Text( innerComposite, SWT.BORDER );
+ this.quickFilterValueText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ this.quickFilterValueText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ filter.setQuickFilterValue( quickFilterValueText.getText() );
+ clearQuickFilterButton.setEnabled( !"".equals( quickFilterValueText.getText() ) );
+ if ( !"".equals( quickFilterValueText.getText() ) )
+ {
+ RGB fgRgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+ BrowserCommonConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR );
+ RGB bgRgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+ BrowserCommonConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR );
+ Color fgColor = BrowserCommonActivator.getDefault().getColor( fgRgb );
+ Color bgColor = BrowserCommonActivator.getDefault().getColor( bgRgb );
+ quickFilterValueText.setForeground( fgColor );
+ quickFilterValueText.setBackground( bgColor );
+ FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+ .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT );
+ Font font = BrowserCommonActivator.getDefault().getFont( fontData );
+ quickFilterValueText.setFont( font );
+ }
+ else
+ {
+ quickFilterValueText.setBackground( null );
+ }
+ }
+ } );
+
+ this.clearQuickFilterButton = new Button( innerComposite, SWT.PUSH );
+ this.clearQuickFilterButton.setToolTipText( "Clear Quick Filter" );
+ this.clearQuickFilterButton.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_CLEAR ) );
+ this.clearQuickFilterButton.setEnabled( false );
+ this.clearQuickFilterButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ if ( !"".equals( quickFilterValueText.getText() ) )
+ quickFilterValueText.setText( "" );
+ }
+ } );
+
+ setEnabled( composite.isEnabled() );
+
+ composite.layout( true, true );
+ parent.layout( true, true );
+
+ }
+
+
+ private void destroy()
+ {
+ if ( !"".equals( quickFilterValueText.getText() ) )
+ quickFilterValueText.setText( "" );
+ innerComposite.dispose();
+ innerComposite = null;
+
+ composite.layout( true, true );
+ parent.layout( true, true );
+ }
+
+
+ public void dispose()
+ {
+ if ( this.innerComposite != null && !this.innerComposite.isDisposed() )
+ {
+ this.quickFilterValueText.dispose();
+ this.quickFilterValueText = null;
+ this.clearQuickFilterButton = null;
+ this.innerComposite = null;
+ }
+ if ( this.filter != null )
+ {
+ this.composite.dispose();
+ this.composite = null;
+ this.parent = null;
+ this.filter = null;
+ }
+ }
+
+
+ public void setEnabled( boolean enabled )
+ {
+ if ( this.composite != null && !this.composite.isDisposed() )
+ {
+ this.composite.setEnabled( enabled );
+ }
+ if ( this.innerComposite != null && !this.innerComposite.isDisposed() )
+ {
+ this.innerComposite.setEnabled( enabled );
+ this.quickFilterValueText.setEnabled( enabled );
+ this.clearQuickFilterButton.setEnabled( enabled );
+ }
+ }
+
+
+ public void setActive( boolean visible )
+ {
+ if ( visible && this.innerComposite == null && composite != null )
+ {
+ create();
+ this.quickFilterValueText.setFocus();
+ }
+ else if ( !visible && this.innerComposite != null && composite != null )
+ {
+ destroy();
+ }
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorQuickFilterWidget.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorSorter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorSorter.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorSorter.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorSorter.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,332 @@
+/*
+ * 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.ldapbrowser.ui.editors.searchresult;
+
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.TableColumn;
+
+
+public class SearchResultEditorSorter extends ViewerSorter implements SelectionListener
+{
+
+ protected SearchResultEditorContentProvider contentProvider;
+
+ private ISearch search;
+
+ private TableColumn[] columns;
+
+ private boolean showDn;
+
+ private int sortBy;
+
+ private int sortOrder;
+
+
+ public SearchResultEditorSorter()
+ {
+ super();
+ }
+
+
+ public void connect( SearchResultEditorContentProvider contentProvider )
+ {
+
+ this.contentProvider = contentProvider;
+
+ this.sortBy = 0;
+ this.sortOrder = BrowserCoreConstants.SORT_ORDER_NONE;
+
+ this.columns = this.contentProvider.getViewer().getTable().getColumns();
+ for ( int i = 0; i < this.columns.length; i++ )
+ {
+ this.columns[i].addSelectionListener( this );
+ }
+ }
+
+
+ public void inputChanged( ISearch newSearch, boolean showDn )
+ {
+
+ this.search = newSearch;
+ this.showDn = showDn;
+
+ for ( int i = 0; this.columns != null && i < this.columns.length; i++ )
+ {
+ this.columns[i].removeSelectionListener( this );
+ }
+ this.columns = this.contentProvider.getViewer().getTable().getColumns();
+ for ( int i = 0; i < this.columns.length; i++ )
+ {
+ this.columns[i].addSelectionListener( this );
+ }
+
+ // check sort column
+ int visibleColumns = this.search.getReturningAttributes().length;
+ if ( this.showDn )
+ visibleColumns++;
+ if ( visibleColumns < this.sortBy + 1 )
+ {
+ this.setSortColumn( 0 );
+ this.setSortColumn( 0 );
+ this.setSortColumn( 0 );
+ }
+ }
+
+
+ public void dispose()
+ {
+ for ( int i = 0; this.columns != null && i < this.columns.length; i++ )
+ {
+ if ( !this.columns[i].isDisposed() )
+ this.columns[i].removeSelectionListener( this );
+ }
+ this.columns = null;
+ this.search = null;
+ this.contentProvider = null;
+ }
+
+
+ public void widgetDefaultSelected( SelectionEvent e )
+ {
+ }
+
+
+ public void widgetSelected( SelectionEvent e )
+ {
+ if ( e.widget instanceof TableColumn )
+ {
+ int index = this.contentProvider.getViewer().getTable().indexOf( ( ( TableColumn ) e.widget ) );
+ this.setSortColumn( index );
+ }
+ }
+
+
+ private void setSortColumn( int index )
+ {
+ if ( this.sortBy == index )
+ {
+ // toggle sort order
+ this.sortOrder = this.sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ? BrowserCoreConstants.SORT_ORDER_DESCENDING
+ : this.sortOrder == BrowserCoreConstants.SORT_ORDER_DESCENDING ? BrowserCoreConstants.SORT_ORDER_NONE
+ : BrowserCoreConstants.SORT_ORDER_ASCENDING;
+ }
+ else
+ {
+ // set new sort by
+ this.sortBy = index;
+ this.sortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING;
+ }
+ if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_NONE )
+ {
+ this.sortBy = BrowserCoreConstants.SORT_BY_NONE;
+ }
+
+ TableColumn[] columns = this.contentProvider.getViewer().getTable().getColumns();
+ for ( int i = 0; i < columns.length; i++ )
+ {
+ columns[i].setImage( null );
+ }
+
+ if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING )
+ {
+ ( columns[index] ).setImage( BrowserCommonActivator.getDefault().getImage(
+ BrowserCommonConstants.IMG_SORT_ASCENDING ) );
+ }
+ else if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_DESCENDING )
+ {
+ ( columns[index] ).setImage( BrowserCommonActivator.getDefault().getImage(
+ BrowserCommonConstants.IMG_SORT_DESCENDING ) );
+ }
+ else
+ {
+ ( columns[index] ).setImage( null );
+ }
+
+ this.contentProvider.refresh();
+
+ }
+
+
+ public boolean isSorted()
+ {
+ // return this.sortOrder != SORT_ORDER_NONE;
+ return true;
+ }
+
+
+ public void sort( final Viewer viewer, Object[] elements )
+ {
+
+ if ( isSorted() )
+ {
+ Arrays.sort( elements, new Comparator()
+ {
+ public int compare( Object a, Object b )
+ {
+ return SearchResultEditorSorter.this.compare( viewer, a, b );
+ }
+ } );
+ }
+
+ }
+
+
+ public int compare( Viewer viewer, Object o1, Object o2 )
+ {
+
+ if ( this.search == null )
+ {
+ return this.equal();
+ }
+
+ // if(o1 == null && o2 == null) {
+ // return this.equal();
+ // }
+ // else if(o1 == null && o2 != null) {
+ // return this.lessThan();
+ // }
+ // else if(o1 != null && o2 == null) {
+ // return this.greaterThan();
+ // }
+ // else {
+ // if(!(o1 instanceof ISearchResult) && !(o2 instanceof ISearchResult))
+ // {
+ // return this.equal();
+ // }
+ // else if(!(o1 instanceof ISearchResult) && (o2 instanceof
+ // ISearchResult)) {
+ // return this.lessThan();
+ // }
+ // else if((o1 instanceof ISearchResult) && !(o2 instanceof
+ // ISearchResult)) {
+ // return this.greaterThan();
+ // }
+ // else {
+ ISearchResult sr1 = ( ISearchResult ) o1;
+ ISearchResult sr2 = ( ISearchResult ) o2;
+
+ IEntry entry1 = sr1.getEntry();
+ IEntry entry2 = sr2.getEntry();
+
+ String attributeName;
+ if ( showDn && this.sortBy == 0 )
+ {
+ attributeName = BrowserUIConstants.DN;
+ }
+ else if ( showDn && this.sortBy > 0 )
+ {
+ attributeName = this.search.getReturningAttributes()[this.sortBy - 1];
+ }
+ else
+ {
+ attributeName = this.search.getReturningAttributes()[this.sortBy];
+ }
+
+ if ( attributeName == BrowserUIConstants.DN )
+ {
+ // compare normalized names
+ return compare( entry1.getDn().getNormName(), entry2.getDn().getNormName() );
+ }
+ else
+ {
+ AttributeHierarchy ah1 = entry1.getAttributeWithSubtypes( attributeName );
+ AttributeHierarchy ah2 = entry2.getAttributeWithSubtypes( attributeName );
+ if ( ah1 == null && ah2 == null )
+ {
+ return this.equal();
+ }
+ else if ( ah1 == null && ah2 != null )
+ {
+ return this.lessThan();
+ }
+ else if ( ah1 != null && ah2 == null )
+ {
+ return this.greaterThan();
+ }
+ else
+ {
+ IAttribute attribute1 = ah1.getAttribute();
+ IAttribute attribute2 = ah2.getAttribute();
+
+ String value1 = getValue( attribute1 );
+ String value2 = getValue( attribute2 );
+ return compare( value1, value2 );
+ }
+ }
+ // }
+ // }
+ }
+
+
+ private String getValue( IAttribute attribute )
+ {
+ if ( attribute.getValueSize() > 0 )
+ {
+ return attribute.getStringValue();
+ }
+ else
+ {
+ return "";
+ }
+ }
+
+
+ private int lessThan()
+ {
+ return this.sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ? -1 : 1;
+ }
+
+
+ private int equal()
+ {
+ return 0;
+ }
+
+
+ private int greaterThan()
+ {
+ return this.sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ? 1 : -1;
+ }
+
+
+ private int compare( String s1, String s2 )
+ {
+ return this.sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1.compareToIgnoreCase( s2 ) : s2
+ .compareToIgnoreCase( s1 );
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorSorter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorUniversalListener.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorUniversalListener.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorUniversalListener.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,755 @@
+/*
+ * 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.ldapbrowser.ui.editors.searchresult;
+
+
+/**
+ * The SearchResultEditorUniversalListener manages all events for the search result editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.common.actions.BrowserSelectionUtils;
+import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueAddedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EntryUpdateListener;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateListener;
+import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.apache.directory.studio.ldapbrowser.ui.actions.OpenSearchResultAction;
+import org.apache.directory.studio.ldapbrowser.ui.views.browser.BrowserView;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.INullSelectionListener;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.contexts.IContextActivation;
+import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.events.IHyperlinkListener;
+import org.eclipse.ui.forms.widgets.Hyperlink;
+
+
+public class SearchResultEditorUniversalListener implements SearchUpdateListener, EntryUpdateListener
+{
+
+ /** The search result editor */
+ private SearchResultEditor editor;
+
+ /** The table viewer */
+ private TableViewer viewer;
+
+ /** The cursor */
+ private SearchResultEditorCursor cursor;
+
+ /** The action used to start the default value editor */
+ private OpenBestEditorAction startEditAction;
+
+ /** The selected search that is displayed in the search result editor */
+ private ISearch selectedSearch;
+
+ /** The hyperlink used for DNs */
+ private Hyperlink dnLink;
+
+ /** The table editor, used to display the hyperlink */
+ private TableEditor tableEditor;
+
+ /** Token used to activate and deactivate shortcuts in the editor */
+ private IContextActivation contextActivation;
+
+ /** Listener that listens for selections of ISearch objects. */
+ private INullSelectionListener searchSelectionListener = new INullSelectionListener()
+ {
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation sets the editor's input when a search is selected.
+ */
+ public void selectionChanged( IWorkbenchPart part, ISelection selection )
+ {
+ if ( editor != null && part != null )
+ {
+ if ( editor.getSite().getWorkbenchWindow() == part.getSite().getWorkbenchWindow() )
+ {
+ ISearch[] searches = BrowserSelectionUtils.getSearches( selection );
+ Object[] objects = BrowserSelectionUtils.getObjects( selection );
+ if ( searches.length == 1 && objects.length == 1 )
+ {
+ editor.setInput( new SearchResultEditorInput( searches[0] ) );
+ }
+ else
+ {
+ editor.setInput( new SearchResultEditorInput( null ) );
+ }
+ }
+ }
+ }
+ };
+
+ /** The part listener used to activate and deactivate the shortcuts */
+ private IPartListener2 partListener = new IPartListener2()
+ {
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation deactivates the shortcuts when the part is deactivated.
+ */
+ public void partDeactivated( IWorkbenchPartReference partRef )
+ {
+ if ( partRef.getPart( false ) == editor && contextActivation != null )
+ {
+ editor.getActionGroup().deactivateGlobalActionHandlers();
+
+ IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
+ IContextService.class );
+ contextService.deactivateContext( contextActivation );
+ contextActivation = null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation activates the shortcuts when the part is activated.
+ */
+ public void partActivated( IWorkbenchPartReference partRef )
+ {
+ if ( partRef.getPart( false ) == editor )
+ {
+ IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
+ IContextService.class );
+ contextActivation = contextService
+ .activateContext( BrowserCommonConstants.CONTEXT_WINDOWS );
+
+ editor.getActionGroup().activateGlobalActionHandlers();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partBroughtToTop( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partClosed( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partOpened( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partHidden( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partVisible( IWorkbenchPartReference partRef )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partInputChanged( IWorkbenchPartReference partRef )
+ {
+ }
+ };
+
+ /** The listener used to handle clicks to the DN hyper link */
+ private IHyperlinkListener dnHyperlinkListener = new IHyperlinkListener()
+ {
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation opens the search result when clicking thd DN link.
+ */
+ public void linkActivated( HyperlinkEvent e )
+ {
+ ISearchResult sr = ( ISearchResult ) e.widget.getData();
+ OpenSearchResultAction action = new OpenSearchResultAction();
+ action.setSelectedSearchResults( new ISearchResult[]
+ { sr } );
+ action.run();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void linkEntered( HyperlinkEvent e )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void linkExited( HyperlinkEvent e )
+ {
+ }
+ };
+
+ /** This listener removes the DN link when then mouse exits the hyperlink control */
+ private MouseTrackListener dnMouseTrackListener = new MouseTrackListener()
+ {
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseEnter( MouseEvent e )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation removed the DN link.
+ */
+ public void mouseExit( MouseEvent e )
+ {
+ if ( !dnLink.isDisposed() )
+ {
+ dnLink.setVisible( false );
+ tableEditor.setEditor( null );
+ }
+ }
+
+
+ public void mouseHover( MouseEvent e )
+ {
+ }
+ };
+
+ /** This listener renders the DN hyperlink when the mouse cursor moves over the DN */
+ private MouseMoveListener cursorMouseMoveListener = new MouseMoveListener()
+ {
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation renders the DN link.
+ */
+ public void mouseMove( MouseEvent e )
+ {
+ if ( !cursor.isDisposed() )
+ {
+ TableItem item = cursor.getRow();
+ if ( cursor.getColumn() == 0
+ && "DN".equalsIgnoreCase( cursor.getRow().getParent().getColumns()[0].getText() ) )
+ {
+ checkDnLink( item );
+ }
+ }
+ }
+ };
+
+ /** This listener renders the DN link when the mouse cursor moves over the DN */
+ private MouseMoveListener viewerMouseMoveListener = new MouseMoveListener()
+ {
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation renders the DN link.
+ */
+ public void mouseMove( MouseEvent e )
+ {
+ if ( !viewer.getTable().isDisposed() )
+ {
+ TableItem item = viewer.getTable().getItem( new Point( e.x, e.y ) );
+ viewer.getTable().getColumns()[0].getWidth();
+ if ( e.x > 0 && e.x < viewer.getTable().getColumns()[0].getWidth()
+ && "DN".equalsIgnoreCase( viewer.getTable().getColumns()[0].getText() ) )
+ {
+ checkDnLink( item );
+ }
+ }
+ }
+ };
+
+ /** This listener starts the value editor and toggles the cursor's background color */
+ private SelectionListener cursorSelectionListener = new SelectionAdapter()
+ {
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation sets the cursor's background color.
+ */
+ public void widgetSelected( SelectionEvent e )
+ {
+ // viewer.setSelection(new StructuredSelection(getRow()), true);
+ // viewer.getTable().setSelection(new TableItem[]{getRow()});
+ viewer.setSelection( null, true );
+ viewer.getTable().setSelection( new TableItem[0] );
+
+ ISearchResult result = cursor.getSelectedSearchResult();
+ String property = cursor.getSelectedProperty();
+ if ( property != null && result != null && viewer.getCellModifier().canModify( result, property ) )
+ {
+ cursor.setBackground( Display.getDefault().getSystemColor( SWT.COLOR_LIST_SELECTION ) );
+ }
+ else
+ {
+ cursor.setBackground( Display.getDefault().getSystemColor( SWT.COLOR_TITLE_INACTIVE_FOREGROUND ) );
+ }
+
+ // cursor.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation starts the value editor when pressing enter.
+ */
+ public void widgetDefaultSelected( SelectionEvent e )
+ {
+ viewer.setSelection( null, true );
+ viewer.getTable().setSelection( new TableItem[0] );
+ if ( startEditAction.isEnabled() )
+ startEditAction.run();
+ }
+ };
+
+ /** This listener starts the value editor when double-clicking a cell */
+ private MouseListener cursorMouseListener = new MouseAdapter()
+ {
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation starts the value editor when double-clicking a cell.
+ */
+ public void mouseDoubleClick( MouseEvent e )
+ {
+ viewer.setSelection( null, true );
+ viewer.getTable().setSelection( new TableItem[0] );
+ if ( startEditAction.isEnabled() )
+ startEditAction.run();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDown( MouseEvent e )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseUp( MouseEvent e )
+ {
+ }
+ };
+
+ /** This listener starts the value editor when typing */
+ private KeyListener cursorKeyListener = new KeyListener()
+ {
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation starts the value editor when a non-control key is pressed.
+ */
+ public void keyPressed( KeyEvent e )
+ {
+ if ( e.character != '\0' && e.character != SWT.CR && e.character != SWT.LF && e.character != SWT.BS
+ && e.character != SWT.DEL && e.character != SWT.TAB && e.character != SWT.ESC
+ && ( e.stateMask == 0 || e.stateMask == SWT.SHIFT ) )
+ {
+
+ if ( startEditAction.isEnabled()
+ && startEditAction.getBestValueEditor().getCellEditor() instanceof TextCellEditor )
+ {
+ startEditAction.run();
+ CellEditor editor = viewer.getCellEditors()[cursor.getColumn()];
+ if ( editor instanceof TextCellEditor )
+ {
+ editor.setValue( String.valueOf( e.character ) );
+ ( ( Text ) editor.getControl() ).setSelection( 1 );
+ }
+ }
+
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void keyReleased( KeyEvent e )
+ {
+ }
+ };
+
+
+ /**
+ * Creates a new instance of SearchResultEditorUniversalListener.
+ *
+ * @param editor the search result editor
+ */
+ public SearchResultEditorUniversalListener( SearchResultEditor editor )
+ {
+ this.editor = editor;
+
+ startEditAction = editor.getActionGroup().getOpenBestEditorAction();
+ viewer = editor.getMainWidget().getViewer();
+ cursor = editor.getConfiguration().getCursor( viewer );
+
+ // create dn link control
+ dnLink = new Hyperlink( viewer.getTable(), SWT.NONE );
+ dnLink.setLayoutData( new GridData( SWT.BOTTOM, SWT.LEFT, true, true ) );
+ dnLink.setText( "" );
+ dnLink.setMenu( viewer.getTable().getMenu() );
+ tableEditor = new TableEditor( viewer.getTable() );
+ tableEditor.horizontalAlignment = SWT.LEFT;
+ tableEditor.verticalAlignment = SWT.BOTTOM;
+ tableEditor.grabHorizontal = true;
+ tableEditor.grabVertical = true;
+
+ // init listeners
+ dnLink.addHyperlinkListener( dnHyperlinkListener );
+ dnLink.addMouseTrackListener( dnMouseTrackListener );
+
+ cursor.addMouseMoveListener( cursorMouseMoveListener );
+ cursor.addSelectionListener( cursorSelectionListener );
+ cursor.addMouseListener( cursorMouseListener );
+ cursor.addKeyListener( cursorKeyListener );
+
+ viewer.getTable().addMouseMoveListener( viewerMouseMoveListener );
+
+ editor.getSite().getPage().addPartListener( partListener );
+ editor.getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener( BrowserView.getId(),
+ searchSelectionListener );
+
+ EventRegistry.addSearchUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() );
+ EventRegistry.addEntryUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() );
+ }
+
+
+ /**
+ * Disposes the listener.
+ */
+ public void dispose()
+ {
+ if ( editor != null )
+ {
+ editor.getSite().getPage().removePartListener( partListener );
+ editor.getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(
+ BrowserView.getId(), searchSelectionListener );
+
+ EventRegistry.removeSearchUpdateListener( this );
+ EventRegistry.removeEntryUpdateListener( this );
+
+ selectedSearch = null;
+ startEditAction = null;
+ cursor = null;
+ viewer = null;
+ editor = null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation refreshes the search result editor.
+ */
+ public void searchUpdated( SearchUpdateEvent searchUpdateEvent )
+ {
+ if ( selectedSearch == searchUpdateEvent.getSearch() )
+ {
+ refreshInput();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation refreshes the search result editor
+ * or starts the value editor if an empty value was added.
+ */
+ public void entryUpdated( EntryModificationEvent event )
+ {
+
+ if ( event instanceof EmptyValueAddedEvent && !editor.getActionGroup().isEditorActive() )
+ {
+ EmptyValueAddedEvent evae = ( EmptyValueAddedEvent ) event;
+ IAttribute att = evae.getAddedValue().getAttribute();
+ AttributeHierarchy ah = cursor.getSelectedAttributeHierarchie();
+ if ( ah != null && ah.contains( att ) )
+ {
+ viewer.setSelection( null, true );
+ viewer.getTable().setSelection( new TableItem[0] );
+ if ( startEditAction.isEnabled() )
+ {
+ startEditAction.run();
+ }
+ }
+ }
+ else
+ {
+ viewer.refresh( true );
+ cursor.notifyListeners( SWT.Selection, new Event() );
+ }
+ }
+
+
+ /**
+ * Sets the input.
+ *
+ * @param search the search
+ */
+ void setInput( ISearch search )
+ {
+ selectedSearch = search;
+ refreshInput();
+ editor.getActionGroup().setInput( search );
+ }
+
+
+ /**
+ * Refreshes the input, makes columns visible or hides columns depending on the number
+ * of returning attributes.
+ */
+ void refreshInput()
+ {
+
+ // create at least on column
+ ensureColumnCount( 1 );
+
+ // get all columns
+ TableColumn[] columns = viewer.getTable().getColumns();
+
+ // number of used columns
+ int usedColumns;
+
+ if ( selectedSearch != null )
+ {
+
+ // get displayed attributes
+ boolean showDn = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN )
+ || selectedSearch.getReturningAttributes().length == 0;
+ String[] attributes;
+ if ( showDn )
+ {
+ attributes = new String[selectedSearch.getReturningAttributes().length + 1];
+ attributes[0] = "DN";
+ System.arraycopy( selectedSearch.getReturningAttributes(), 0, attributes, 1, attributes.length - 1 );
+ }
+ else
+ {
+ attributes = selectedSearch.getReturningAttributes();
+ }
+
+ // create missing columns
+ if ( attributes.length > columns.length )
+ {
+ ensureColumnCount( attributes.length );
+ columns = viewer.getTable().getColumns();
+ }
+
+ // set column headers
+ for ( int i = 0; i < attributes.length; i++ )
+ {
+ columns[i].setText( attributes[i] );
+ }
+ viewer.setColumnProperties( attributes );
+
+ // set input
+ ( ( SearchResultEditorLabelProvider ) viewer.getLabelProvider() ).inputChanged( selectedSearch, showDn );
+
+ viewer.setInput( selectedSearch );
+ // this.viewer.refresh();
+
+ // update cell editors
+ CellEditor[] editors = new CellEditor[attributes.length];
+ viewer.setCellEditors( editors );
+
+ if ( attributes.length > 0 )
+ {
+ int width = viewer.getTable().getClientArea().width / attributes.length;
+ for ( int i = 0; i < attributes.length; i++ )
+ {
+ columns[i].setWidth( width );
+ }
+ }
+
+ // layout columns
+ // for(int i=0; i<attributes.length; i++) {
+ // columns[i].pack();
+ // }
+ usedColumns = attributes.length;
+ }
+ else
+ {
+ viewer.setInput( null );
+ columns[0].setText( "DN" );
+ columns[0].pack();
+ usedColumns = 1;
+ }
+
+ // make unused columns invisible
+ for ( int i = usedColumns; i < columns.length; i++ )
+ {
+ columns[i].setWidth( 0 );
+ columns[i].setText( " " );
+ }
+
+ // refresh content provider (sorter and filter)
+ editor.getConfiguration().getContentProvider( editor.getMainWidget() ).refresh();
+
+ // this.cursor.setFocus();
+ }
+
+
+ /**
+ * Ensures that the table contains at least the number of
+ * the requested columns.
+ *
+ * @param count the requested number of columns
+ */
+ private void ensureColumnCount( int count )
+ {
+ TableColumn[] columns = viewer.getTable().getColumns();
+ if ( columns.length < count )
+ {
+ for ( int i = columns.length; i < count; i++ )
+ {
+ TableColumn column = new TableColumn( viewer.getTable(), SWT.LEFT );
+ column.setText( "" );
+ column.setWidth( 0 );
+ column.setResizable( true );
+ column.setMoveable( true );
+ }
+ }
+ }
+
+
+ /**
+ * Renders the DN link.
+ *
+ * @param item the table item
+ */
+ private void checkDnLink( TableItem item )
+ {
+
+ if ( dnLink == null || dnLink.isDisposed() || tableEditor == null || viewer.getTable().isDisposed()
+ || cursor.isDisposed() )
+ {
+ return;
+ }
+
+ boolean showLinks = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_LINKS );
+ if ( showLinks )
+ {
+
+ boolean linkVisible = false;
+
+ if ( item != null )
+ {
+ Object data = item.getData();
+
+ if ( data instanceof ISearchResult )
+ {
+ ISearchResult sr = ( ISearchResult ) data;
+
+ item.getFont();
+ viewer.getTable().getColumn( 0 ).getWidth();
+ viewer.getTable().getItemHeight();
+
+ // dnLink.setText("<a>"+sr.getDn().toString()+"</a>");
+ dnLink.setData( sr );
+ dnLink.setText( sr.getDn().getUpName() );
+ dnLink.setUnderlined( true );
+ dnLink.setFont( item.getFont() );
+ dnLink.setForeground( item.getForeground() );
+ dnLink.setBackground( item.getBackground() );
+ dnLink.setBounds( item.getBounds( 0 ) );
+ tableEditor.setEditor( dnLink, item, 0 );
+
+ linkVisible = true;
+ }
+
+ }
+
+ if ( !linkVisible )
+ {
+ dnLink.setVisible( false );
+ tableEditor.setEditor( null );
+ }
+ }
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorUniversalListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorWidget.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorWidget.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorWidget.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,121 @@
+/*
+ * 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.ldapbrowser.ui.editors.searchresult;
+
+
+import org.apache.directory.studio.ldapbrowser.common.widgets.ViewFormWidget;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+
+
+public class SearchResultEditorWidget extends ViewFormWidget
+{
+
+ private SearchResultEditorConfiguration configuration;
+
+ private SearchResultEditorQuickFilterWidget quickFilterWidget;
+
+ private Table table;
+
+ private TableViewer viewer;
+
+
+ public SearchResultEditorWidget( SearchResultEditorConfiguration configuration )
+ {
+ this.configuration = configuration;
+ }
+
+
+ protected Control createContent( Composite parent )
+ {
+
+ // create quick filter
+ this.quickFilterWidget = new SearchResultEditorQuickFilterWidget( this.configuration.getFilter() );
+ this.quickFilterWidget.createComposite( parent );
+
+ // create table widget and viewer
+ this.table = new Table( parent, SWT.BORDER | SWT.HIDE_SELECTION | SWT.VIRTUAL );
+ this.table.setHeaderVisible( true );
+ this.table.setLinesVisible( true );
+ this.table.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ this.viewer = new TableViewer( this.table );
+ this.viewer.setUseHashlookup( true );
+
+ // setup providers
+ this.viewer.setContentProvider( configuration.getContentProvider( this ) );
+ this.viewer.setLabelProvider( configuration.getLabelProvider( this.viewer ) );
+
+ // set table cell editors
+ this.viewer.setCellModifier( configuration.getCellModifier( this.viewer ) );
+
+ return this.table;
+ }
+
+
+ public void setInput( Object input )
+ {
+ this.viewer.setInput( input );
+ }
+
+
+ public void setFocus()
+ {
+ this.configuration.getCursor( this.viewer ).setFocus();
+ }
+
+
+ public void dispose()
+ {
+ if ( this.viewer != null )
+ {
+ this.configuration.dispose();
+
+ if ( this.quickFilterWidget != null )
+ {
+ this.quickFilterWidget.dispose();
+ this.quickFilterWidget = null;
+ }
+
+ // this.table.dispose();
+ this.table = null;
+ this.viewer = null;
+ }
+
+ super.dispose();
+ }
+
+
+ public TableViewer getViewer()
+ {
+ return viewer;
+ }
+
+
+ public SearchResultEditorQuickFilterWidget getQuickFilterWidget()
+ {
+ return quickFilterWidget;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/SearchResultEditorWidget.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowDNAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowDNAction.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowDNAction.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowDNAction.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.ui.editors.searchresult;
+
+
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.eclipse.jface.action.Action;
+
+
+public class ShowDNAction extends Action
+{
+
+ public ShowDNAction()
+ {
+ super( "Show DN", AS_CHECK_BOX );
+ super.setToolTipText( getText() );
+ super.setEnabled( true );
+
+ super.setChecked( BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN ) );
+ }
+
+
+ public void run()
+ {
+ BrowserUIPlugin.getDefault().getPreferenceStore().setValue(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN, super.isChecked() );
+ }
+
+
+ public void setChecked( boolean checked )
+ {
+ super.setChecked( checked );
+ }
+
+
+ public boolean isChecked()
+ {
+ return super.isChecked();
+ }
+
+
+ public void dispose()
+ {
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowDNAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowLinksAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowLinksAction.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowLinksAction.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowLinksAction.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.ui.editors.searchresult;
+
+
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.eclipse.jface.action.Action;
+
+
+public class ShowLinksAction extends Action
+{
+
+ public ShowLinksAction()
+ {
+ super( "DN as link", AS_CHECK_BOX );
+ super.setToolTipText( getText() );
+ super.setEnabled( true );
+
+ super.setChecked( BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_LINKS ) );
+ }
+
+
+ public void run()
+ {
+ BrowserUIPlugin.getDefault().getPreferenceStore().setValue(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_LINKS, super.isChecked() );
+ }
+
+
+ public void setChecked( boolean checked )
+ {
+ super.setChecked( checked );
+ }
+
+
+ public boolean isChecked()
+ {
+ return super.isChecked();
+ }
+
+
+ public void dispose()
+ {
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowLinksAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowQuickFilterAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowQuickFilterAction.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowQuickFilterAction.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowQuickFilterAction.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,92 @@
+/*
+ * 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.ldapbrowser.ui.editors.searchresult;
+
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+
+public class ShowQuickFilterAction extends Action
+{
+
+ public static final String SHOW_QUICKFILTER_DIALOGSETTING_KEY = ShowQuickFilterAction.class.getName()
+ + ".showQuickFilter";
+
+ private SearchResultEditorQuickFilterWidget quickFilterWidget;
+
+
+ public ShowQuickFilterAction( SearchResultEditorQuickFilterWidget quickFilterWidget )
+ {
+ super( "Show Quick Filter", AS_CHECK_BOX );
+ super.setToolTipText( "Show Quick Filter" );
+ super.setImageDescriptor( BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_FILTER ) );
+ super.setActionDefinitionId( IWorkbenchActionDefinitionIds.FIND_REPLACE );
+ super.setEnabled( true );
+
+ this.quickFilterWidget = quickFilterWidget;
+
+ if ( BrowserUIPlugin.getDefault().getDialogSettings().get( SHOW_QUICKFILTER_DIALOGSETTING_KEY ) == null )
+ {
+ BrowserUIPlugin.getDefault().getDialogSettings().put( SHOW_QUICKFILTER_DIALOGSETTING_KEY, false );
+ }
+ super.setChecked( BrowserUIPlugin.getDefault().getDialogSettings().getBoolean(
+ SHOW_QUICKFILTER_DIALOGSETTING_KEY ) );
+ this.quickFilterWidget.setActive( super.isChecked() );
+ }
+
+
+ public void run()
+ {
+
+ boolean checked = super.isChecked();
+ super.setChecked( !checked );
+
+ BrowserUIPlugin.getDefault().getDialogSettings().put( SHOW_QUICKFILTER_DIALOGSETTING_KEY, super.isChecked() );
+
+ if ( this.quickFilterWidget != null )
+ {
+ this.quickFilterWidget.setActive( super.isChecked() );
+ }
+ }
+
+
+ public void setChecked( boolean checked )
+ {
+ // super.setChecked(checked);
+ }
+
+
+ public boolean isChecked()
+ {
+ return super.isChecked();
+ }
+
+
+ public void dispose()
+ {
+ this.quickFilterWidget = null;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/searchresult/ShowQuickFilterAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/perspective/BrowserPerspective.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/perspective/BrowserPerspective.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/perspective/BrowserPerspective.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/perspective/BrowserPerspective.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.ui.perspective;
+
+
+import org.apache.directory.studio.connection.ui.wizards.NewConnectionWizard;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.ui.views.browser.BrowserView;
+import org.apache.directory.studio.ldapbrowser.ui.views.connection.ConnectionView;
+import org.apache.directory.studio.ldapbrowser.ui.views.modificationlogs.ModificationLogsView;
+import org.apache.directory.studio.ldapbrowser.ui.wizards.BatchOperationWizard;
+import org.apache.directory.studio.ldapbrowser.ui.wizards.NewBookmarkWizard;
+import org.apache.directory.studio.ldapbrowser.ui.wizards.NewEntryWizard;
+import org.apache.directory.studio.ldapbrowser.ui.wizards.NewSearchWizard;
+import org.apache.directory.studio.ldifeditor.wizards.NewLdifFileWizard;
+import org.eclipse.ui.IFolderLayout;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+
+/**
+ * This class implements the {@link IPerspectiveFactory} for the browser
+ * plugin. It is responsible for creating the perspective layout.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserPerspective implements IPerspectiveFactory
+{
+
+ /**
+ * Gets the ID of the browser perspective.
+ *
+ * @return the ID of the browser perspective
+ */
+ public static String getId()
+ {
+ return BrowserPerspective.class.getName();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createInitialLayout( IPageLayout layout )
+ {
+ defineActions( layout );
+ defineLayout( layout );
+
+ layout.addPerspectiveShortcut( "org.apache.directory.studio.schemaeditor.perspective" ); //$NON-NLS-1$
+ layout.addPerspectiveShortcut( "org.apache.directory.studio.ldapbrowser.ui.perspective.BrowserPerspective" ); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Defines the actions in the "New..." menu and the "Show views..." menu.
+ *
+ * @param layout the layout
+ */
+ private void defineActions( IPageLayout layout )
+ {
+ // Add "new wizards".
+ layout.addNewWizardShortcut( NewConnectionWizard.getId() );
+ layout.addNewWizardShortcut( NewEntryWizard.getId() );
+ layout.addNewWizardShortcut( NewSearchWizard.getId() );
+ layout.addNewWizardShortcut( NewBookmarkWizard.getId() );
+ layout.addNewWizardShortcut( BatchOperationWizard.getId() );
+ layout.addNewWizardShortcut( NewLdifFileWizard.getId() );
+
+ // Add "show views".
+ layout.addShowViewShortcut( ConnectionView.getId() );
+ layout.addShowViewShortcut( BrowserView.getId() );
+ layout.addShowViewShortcut( ModificationLogsView.getId() );
+ layout.addShowViewShortcut( IPageLayout.ID_OUTLINE );
+ layout.addShowViewShortcut( "org.eclipse.ui.views.ProgressView" );
+ }
+
+
+ /**
+ * Defines the layout.
+ *
+ * @param layout the layout
+ */
+ private void defineLayout( IPageLayout layout )
+ {
+
+ // Editor area
+ String editorArea = layout.getEditorArea();
+
+ // Browser folder
+ IFolderLayout browserFolder = layout.createFolder( "browserFolder", IPageLayout.LEFT, ( float ) 0.25,
+ editorArea );
+ browserFolder.addView( BrowserView.getId() );
+
+ // Connection folder
+ IFolderLayout connectionFolder = layout.createFolder( "connectionFolder", IPageLayout.BOTTOM, ( float ) 0.75,
+ "browserFolder" );
+ connectionFolder.addView( ConnectionView.getId() );
+
+ // Outline folder
+ IFolderLayout outlineFolder = layout.createFolder( "outlineFolder", IPageLayout.RIGHT, ( float ) 0.75,
+ editorArea );
+ outlineFolder.addView( IPageLayout.ID_OUTLINE );
+
+ // Progress folder
+ IFolderLayout progessFolder = layout.createFolder( "progressFolder", IPageLayout.BOTTOM, ( float ) 0.75,
+ "outlineFolder" );
+ progessFolder.addView( "org.eclipse.ui.views.ProgressView" );
+
+ // Log folder
+ IFolderLayout logFolder = layout.createFolder( "logFolder", IPageLayout.BOTTOM, ( float ) 0.75, editorArea );
+ logFolder.addView( ModificationLogsView.getId() );
+ logFolder.addPlaceholder( "*" );
+
+ // non-closable?
+ boolean isIDE = BrowserCommonActivator.isIDEEnvironment();
+ if ( !isIDE )
+ {
+ layout.getViewLayout( BrowserView.getId() ).setCloseable( false );
+ layout.getViewLayout( ConnectionView.getId() ).setCloseable( false );
+ layout.getViewLayout( IPageLayout.ID_OUTLINE ).setCloseable( false );
+ layout.getViewLayout( "org.eclipse.ui.views.ProgressView" ).setCloseable( false );
+ layout.getViewLayout( ModificationLogsView.getId() ).setCloseable( false );
+ }
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/perspective/BrowserPerspective.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/search/SearchPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/search/SearchPage.java?rev=592087&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/search/SearchPage.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/search/SearchPage.java Mon Nov 5 09:01:21 2007
@@ -0,0 +1,198 @@
+/*
+ * 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.ldapbrowser.ui.search;
+
+
+import org.apache.directory.studio.ldapbrowser.common.actions.BrowserSelectionUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyEvent;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyListener;
+import org.apache.directory.studio.ldapbrowser.common.widgets.search.SearchPageWrapper;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.search.ui.ISearchPage;
+import org.eclipse.search.ui.ISearchPageContainer;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class implements the {@link ISearchPage} to perform an LDAP search.
+ * It uses the {@link SearchPageWrapper} to render all UI elements.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SearchPage extends DialogPage implements ISearchPage, WidgetModifyListener
+{
+
+ /** The search page container. */
+ private ISearchPageContainer container;
+
+ /** The search. */
+ private ISearch search;
+
+ /** The search page wrapper. */
+ private SearchPageWrapper spw;
+
+ /** The error message label. */
+ private Label errorMessageLabel;
+
+
+ /**
+ * Gets the ID of the LDAP search page.
+ *
+ * @return the ID of the LDAP search page
+ */
+ public static String getId()
+ {
+ return SearchPage.class.getName();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose()
+ {
+ spw.removeWidgetModifyListener( this );
+ super.dispose();
+ }
+
+
+ /**
+ * Creates a new instance of SearchPage.
+ */
+ public SearchPage()
+ {
+ }
+
+
+ /**
+ * Creates a new instance of SearchPage.
+ *
+ * @param title the title
+ */
+ public SearchPage( String title )
+ {
+ super( title );
+ }
+
+
+ /**
+ * Creates a new instance of SearchPage.
+ *
+ * @param title the title
+ * @param image the image
+ */
+ public SearchPage( String title, ImageDescriptor image )
+ {
+ super( title, image );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean performAction()
+ {
+ spw.saveToSearch( search );
+ if ( search.getBrowserConnection() != null )
+ {
+ search.getBrowserConnection().getSearchManager().addSearch( search );
+ return spw.performSearch( search );
+ }
+
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setContainer( ISearchPageContainer container )
+ {
+ this.container = container;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createControl( Composite parent )
+ {
+ // declare search
+ search = BrowserSelectionUtils.getExampleSearch( container.getSelection() );
+
+ // create search page content
+ GridLayout gl = new GridLayout();
+ parent.setLayout( gl );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+ // gd.heightHint =
+ // convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ parent.setLayoutData( gd );
+
+ Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
+ spw = new SearchPageWrapper( SearchPageWrapper.NONE );
+ spw.createContents( composite );
+ spw.loadFromSearch( search );
+ spw.addWidgetModifyListener( this );
+
+ errorMessageLabel = BaseWidgetUtils.createLabel( parent, "", 3 );
+
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( composite,
+ BrowserUIPlugin.PLUGIN_ID + "." + "tools_search_dialog" );
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( parent,
+ BrowserUIPlugin.PLUGIN_ID + "." + "tools_search_dialog" );
+
+ super.setControl( parent );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setVisible( boolean visible )
+ {
+ container.setPerformActionEnabled( spw.isValid() );
+ super.setVisible( visible );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void widgetModified( WidgetModifyEvent event )
+ {
+ container.setPerformActionEnabled( spw.isValid() );
+
+ setErrorMessage( spw.getErrorMessage() );
+ errorMessageLabel.setText( getErrorMessage() != null ? getErrorMessage() : "" );
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/search/SearchPage.java
------------------------------------------------------------------------------
svn:eol-style = native