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:15:02 UTC
svn commit: r592094 [18/35] - in
/directory/sandbox/felixk/studio-schemaeditor: ./ 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/m...
Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SchemaViewPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SchemaViewPreferencePage.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SchemaViewPreferencePage.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SchemaViewPreferencePage.java Mon Nov 5 09:14:24 2007
@@ -0,0 +1,456 @@
+/*
+ * 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.schemaeditor.view.preferences;
+
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+/**
+ * This class implements the Preference page for the Schema View
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaViewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
+{
+ /** The preference page ID */
+ public static final String ID = Activator.PLUGIN_ID + ".preferences.schemaView"; //$NON-NLS-1$
+
+ /** The First Name category */
+ private static final String FIRST_NAME = "First Name";
+
+ /** The All Aliases category */
+ private static final String ALL_ALIASES = "All Aliases";
+
+ /** The OID category */
+ private static final String OID = "OID";
+
+ // UI fields
+ private Combo labelCombo;
+ private Button limitButton;
+ private Text lengthText;
+ private Button secondaryLabelButtonDisplay;
+ private Combo secondaryLabelCombo;
+ private Button secondaryLabelLimitButton;
+ private Text secondaryLabelLengthText;
+ private Button schemaLabelButtonDisplay;
+
+
+ /**
+ * Creates a new instance of SchemaViewPreferencePage.
+ */
+ public SchemaViewPreferencePage()
+ {
+ super();
+ setPreferenceStore( Activator.getDefault().getPreferenceStore() );
+ setDescription( "General settings for the Schema View of the Schema Editor Plugin" );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createContents( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayout( new GridLayout() );
+ composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+
+ // Label Group
+ Group labelGroup = new Group( composite, SWT.NONE );
+ labelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ labelGroup.setText( "Label" );
+ labelGroup.setLayout( new GridLayout() );
+ Composite labelGroupComposite = new Composite( labelGroup, SWT.NONE );
+ GridLayout gl = new GridLayout( 1, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ labelGroupComposite.setLayout( gl );
+ labelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ // Label row composite
+ Composite labelComposite = new Composite( labelGroupComposite, SWT.NONE );
+ gl = new GridLayout( 3, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ labelComposite.setLayout( gl );
+ GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false );
+ gd.horizontalSpan = 1;
+ labelComposite.setLayoutData( gd );
+
+ // Use Label
+ Label useLabel = new Label( labelComposite, SWT.NONE );
+ useLabel.setText( "Use" );
+
+ // Label Combo
+ labelCombo = new Combo( labelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
+ labelCombo.setLayoutData( new GridData() );
+ labelCombo.setItems( new String[]
+ { FIRST_NAME, ALL_ALIASES, OID } );
+ labelCombo.setEnabled( true );
+
+ // As label Label
+ Label asLabel = new Label( labelComposite, SWT.NONE );
+ asLabel.setText( "as label." );
+
+ // Abbreviate row composite
+ Composite abbreviateComposite = new Composite( labelGroupComposite, SWT.NONE );
+ gl = new GridLayout( 3, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ abbreviateComposite.setLayout( gl );
+ gd = new GridData( SWT.FILL, SWT.NONE, true, false );
+ gd.horizontalSpan = 1;
+ abbreviateComposite.setLayoutData( gd );
+
+ // Limit label lenght to Label
+ limitButton = new Button( abbreviateComposite, SWT.CHECK );
+ limitButton.setText( "Limit label length to" );
+ gd = new GridData();
+ gd.horizontalSpan = 1;
+ limitButton.setLayoutData( gd );
+
+ // Lenght Text
+ lengthText = new Text( abbreviateComposite, SWT.NONE | SWT.BORDER );
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = 1;
+ gridData.widthHint = 9 * 3;
+ lengthText.setLayoutData( gridData );
+ lengthText.setTextLimit( 3 );
+ lengthText.addVerifyListener( new VerifyListener()
+ {
+ public void verifyText( VerifyEvent e )
+ {
+ if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$
+ {
+ e.doit = false;
+ }
+ if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ e.doit = false;
+ }
+ }
+ } );
+
+ // Characters Label
+ Label charactersLabel = new Label( abbreviateComposite, SWT.NONE );
+ charactersLabel.setText( "characters." );
+
+ // Secondary Label Group
+ Group secondaryLabelGroup = new Group( composite, SWT.NONE );
+ secondaryLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ secondaryLabelGroup.setText( "Secondary label" );
+ secondaryLabelGroup.setLayout( new GridLayout() );
+ Composite secondaryLabelGroupComposite = new Composite( secondaryLabelGroup, SWT.NONE );
+ gl = new GridLayout( 1, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ secondaryLabelGroupComposite.setLayout( gl );
+ secondaryLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ secondaryLabelButtonDisplay = new Button( secondaryLabelGroupComposite, SWT.CHECK );
+ secondaryLabelButtonDisplay.setText( "Display secondary label." );
+
+ // Label row composite
+ Composite secondaryLabelComposite = new Composite( secondaryLabelGroupComposite, SWT.NONE );
+ gl = new GridLayout( 3, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ secondaryLabelComposite.setLayout( gl );
+ gd = new GridData( SWT.FILL, SWT.NONE, true, false );
+ gd.horizontalSpan = 1;
+ secondaryLabelComposite.setLayoutData( gd );
+
+ // Use Label
+ Label useLabel2 = new Label( secondaryLabelComposite, SWT.NONE );
+ useLabel2.setText( "Use" );
+
+ // Label Combo
+ secondaryLabelCombo = new Combo( secondaryLabelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
+ secondaryLabelCombo.setLayoutData( new GridData() );
+ secondaryLabelCombo.setItems( new String[]
+ { FIRST_NAME, ALL_ALIASES, OID } );
+ secondaryLabelCombo.setEnabled( true );
+
+ // As label Label
+ Label asLabel2 = new Label( secondaryLabelComposite, SWT.NONE );
+ asLabel2.setText( "as secondary label." );
+
+ // Abbreviate row composite
+ Composite abbreviateComposite2 = new Composite( secondaryLabelGroup, SWT.NONE );
+ gl = new GridLayout( 3, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ abbreviateComposite2.setLayout( gl );
+ gd = new GridData( SWT.FILL, SWT.NONE, true, false );
+ gd.horizontalSpan = 1;
+ abbreviateComposite2.setLayoutData( gd );
+
+ // Limit label lenght to Label
+ secondaryLabelLimitButton = new Button( abbreviateComposite2, SWT.CHECK );
+ secondaryLabelLimitButton.setText( "Limit secondary label length to" );
+ gd = new GridData();
+ gd.horizontalSpan = 1;
+ secondaryLabelLimitButton.setLayoutData( gd );
+
+ // Lenght Text
+ secondaryLabelLengthText = new Text( abbreviateComposite2, SWT.NONE | SWT.BORDER );
+ gridData = new GridData();
+ gridData.horizontalSpan = 1;
+ gridData.widthHint = 9 * 3;
+ secondaryLabelLengthText.setLayoutData( gridData );
+ secondaryLabelLengthText.setTextLimit( 3 );
+ secondaryLabelLengthText.addVerifyListener( new VerifyListener()
+ {
+ public void verifyText( VerifyEvent e )
+ {
+ if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$
+ {
+ e.doit = false;
+ }
+ if ( "".equals( secondaryLabelLengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ e.doit = false;
+ }
+ }
+ } );
+
+ // Schema Label Group
+ Group schemaLabelGroup = new Group( composite, SWT.NONE );
+ schemaLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ schemaLabelGroup.setText( "Schema label" );
+ schemaLabelGroup.setLayout( new GridLayout() );
+ Composite schemaLabelGroupComposite = new Composite( schemaLabelGroup, SWT.NONE );
+ gl = new GridLayout( 1, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ schemaLabelGroupComposite.setLayout( gl );
+ schemaLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ schemaLabelButtonDisplay = new Button( schemaLabelGroupComposite, SWT.CHECK );
+ schemaLabelButtonDisplay.setText( "Display schema name in label." );
+
+ // Characters Label
+ Label secondaryLabelcharactersLabel = new Label( abbreviateComposite2, SWT.NONE );
+ secondaryLabelcharactersLabel.setText( "characters." );
+
+ initFieldsFromPreferences();
+
+ initListeners();
+
+ applyDialogFont( parent );
+
+ return parent;
+ }
+
+
+ /**
+ * Initializes the fields from the preferences store.
+ */
+ private void initFieldsFromPreferences()
+ {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ labelCombo.select( store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_LABEL ) );
+ limitButton.setSelection( store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE ) );
+ lengthText.setEnabled( limitButton.getSelection() );
+ lengthText.setText( store.getString( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH ) );
+
+ secondaryLabelButtonDisplay.setSelection( store
+ .getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ) );
+ secondaryLabelCombo.select( store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL ) );
+ secondaryLabelLimitButton.setSelection( store
+ .getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE ) );
+ secondaryLabelLengthText.setText( store
+ .getString( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) );
+ if ( store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ) )
+ {
+ secondaryLabelCombo.setEnabled( true );
+ secondaryLabelLimitButton.setEnabled( true );
+ secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() );
+ }
+ else
+ {
+ secondaryLabelCombo.setEnabled( false );
+ secondaryLabelLimitButton.setEnabled( false );
+ secondaryLabelLengthText.setEnabled( false );
+ }
+
+ schemaLabelButtonDisplay.setSelection( store
+ .getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY ) );
+ }
+
+
+ /**
+ * Initializes the listeners.
+ */
+ private void initListeners()
+ {
+ limitButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ lengthText.setEnabled( limitButton.getSelection() );
+ }
+ } );
+
+ secondaryLabelButtonDisplay.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ if ( secondaryLabelButtonDisplay.getSelection() )
+ {
+ secondaryLabelCombo.setEnabled( true );
+ secondaryLabelLimitButton.setEnabled( true );
+ secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() );
+ }
+ else
+ {
+ secondaryLabelCombo.setEnabled( false );
+ secondaryLabelLimitButton.setEnabled( false );
+ secondaryLabelLengthText.setEnabled( false );
+ }
+ }
+ } );
+
+ secondaryLabelLimitButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() );
+ }
+ } );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+ */
+ protected void performDefaults()
+ {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ labelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SCHEMA_VIEW_LABEL ) );
+ limitButton.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE ) );
+ lengthText.setEnabled( limitButton.getSelection() );
+ lengthText.setText( store.getDefaultString( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH ) );
+
+ secondaryLabelButtonDisplay.setSelection( store
+ .getDefaultBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ) );
+ secondaryLabelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL ) );
+ secondaryLabelLimitButton.setSelection( store
+ .getDefaultBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE ) );
+ secondaryLabelLengthText.setText( store
+ .getDefaultString( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) );
+
+ if ( secondaryLabelButtonDisplay.getSelection() )
+ {
+ secondaryLabelCombo.setEnabled( true );
+ secondaryLabelLimitButton.setEnabled( true );
+ secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() );
+ }
+ else
+ {
+ secondaryLabelCombo.setEnabled( false );
+ secondaryLabelLimitButton.setEnabled( false );
+ secondaryLabelLengthText.setEnabled( false );
+ }
+
+ schemaLabelButtonDisplay.setSelection( store
+ .getDefaultBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY ) );
+
+ super.performDefaults();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performOk()
+ */
+ public boolean performOk()
+ {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( FIRST_NAME ) )
+ {
+ store
+ .setValue( PluginConstants.PREFS_SCHEMA_VIEW_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME );
+ }
+ else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) )
+ {
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_LABEL,
+ PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES );
+ }
+ else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( OID ) )
+ {
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID );
+ }
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE, limitButton.getSelection() );
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH, lengthText.getText() );
+
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY, secondaryLabelButtonDisplay
+ .getSelection() );
+ if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( FIRST_NAME ) )
+ {
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL,
+ PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME );
+ }
+ else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) )
+ {
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL,
+ PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES );
+ }
+ else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( OID ) )
+ {
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL,
+ PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID );
+ }
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE, secondaryLabelLimitButton
+ .getSelection() );
+ store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH,
+ secondaryLabelLengthText.getText() );
+
+ store
+ .setValue( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY, schemaLabelButtonDisplay.getSelection() );
+
+ return true;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init( IWorkbench workbench )
+ {
+ // Nothing to do
+ }
+}
Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SchemaViewPreferencePage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SearchViewPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SearchViewPreferencePage.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SearchViewPreferencePage.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SearchViewPreferencePage.java Mon Nov 5 09:14:24 2007
@@ -0,0 +1,456 @@
+/*
+ * 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.schemaeditor.view.preferences;
+
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+/**
+ * This class implements the Preference page for the Search View
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SearchViewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
+{
+ /** The preference page ID */
+ public static final String ID = Activator.PLUGIN_ID + ".preferences.searchView"; //$NON-NLS-1$
+
+ /** The First Name category */
+ private static final String FIRST_NAME = "First Name";
+
+ /** The All Aliases category */
+ private static final String ALL_ALIASES = "All Aliases";
+
+ /** The OID category */
+ private static final String OID = "OID";
+
+ // UI fields
+ private Combo labelCombo;
+ private Button limitButton;
+ private Text lengthText;
+ private Button secondaryLabelButtonDisplay;
+ private Combo secondaryLabelCombo;
+ private Button secondaryLabelLimitButton;
+ private Text secondaryLabelLengthText;
+ private Button schemaLabelButtonDisplay;
+
+
+ /**
+ * Creates a new instance of SchemaViewPreferencePage.
+ */
+ public SearchViewPreferencePage()
+ {
+ super();
+ setPreferenceStore( Activator.getDefault().getPreferenceStore() );
+ setDescription( "General settings for the Search View of the Schema Editor Plugin" );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createContents( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayout( new GridLayout() );
+ composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+
+ // Label Group
+ Group labelGroup = new Group( composite, SWT.NONE );
+ labelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ labelGroup.setText( "Label" );
+ labelGroup.setLayout( new GridLayout() );
+ Composite labelGroupComposite = new Composite( labelGroup, SWT.NONE );
+ GridLayout gl = new GridLayout( 1, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ labelGroupComposite.setLayout( gl );
+ labelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ // Label row composite
+ Composite labelComposite = new Composite( labelGroupComposite, SWT.NONE );
+ gl = new GridLayout( 3, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ labelComposite.setLayout( gl );
+ GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false );
+ gd.horizontalSpan = 1;
+ labelComposite.setLayoutData( gd );
+
+ // Use Label
+ Label useLabel = new Label( labelComposite, SWT.NONE );
+ useLabel.setText( "Use" );
+
+ // Label Combo
+ labelCombo = new Combo( labelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
+ labelCombo.setLayoutData( new GridData() );
+ labelCombo.setItems( new String[]
+ { FIRST_NAME, ALL_ALIASES, OID } );
+ labelCombo.setEnabled( true );
+
+ // As label Label
+ Label asLabel = new Label( labelComposite, SWT.NONE );
+ asLabel.setText( "as label." );
+
+ // Abbreviate row composite
+ Composite abbreviateComposite = new Composite( labelGroupComposite, SWT.NONE );
+ gl = new GridLayout( 3, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ abbreviateComposite.setLayout( gl );
+ gd = new GridData( SWT.FILL, SWT.NONE, true, false );
+ gd.horizontalSpan = 1;
+ abbreviateComposite.setLayoutData( gd );
+
+ // Limit label lenght to Label
+ limitButton = new Button( abbreviateComposite, SWT.CHECK );
+ limitButton.setText( "Limit label length to" );
+ gd = new GridData();
+ gd.horizontalSpan = 1;
+ limitButton.setLayoutData( gd );
+
+ // Lenght Text
+ lengthText = new Text( abbreviateComposite, SWT.NONE | SWT.BORDER );
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = 1;
+ gridData.widthHint = 9 * 3;
+ lengthText.setLayoutData( gridData );
+ lengthText.setTextLimit( 3 );
+ lengthText.addVerifyListener( new VerifyListener()
+ {
+ public void verifyText( VerifyEvent e )
+ {
+ if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$
+ {
+ e.doit = false;
+ }
+ if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ e.doit = false;
+ }
+ }
+ } );
+
+ // Characters Label
+ Label charactersLabel = new Label( abbreviateComposite, SWT.NONE );
+ charactersLabel.setText( "characters." );
+
+ // Secondary Label Group
+ Group secondaryLabelGroup = new Group( composite, SWT.NONE );
+ secondaryLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ secondaryLabelGroup.setText( "Secondary label" );
+ secondaryLabelGroup.setLayout( new GridLayout() );
+ Composite secondaryLabelGroupComposite = new Composite( secondaryLabelGroup, SWT.NONE );
+ gl = new GridLayout( 1, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ secondaryLabelGroupComposite.setLayout( gl );
+ secondaryLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ secondaryLabelButtonDisplay = new Button( secondaryLabelGroupComposite, SWT.CHECK );
+ secondaryLabelButtonDisplay.setText( "Display secondary label." );
+
+ // Label row composite
+ Composite secondaryLabelComposite = new Composite( secondaryLabelGroupComposite, SWT.NONE );
+ gl = new GridLayout( 3, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ secondaryLabelComposite.setLayout( gl );
+ gd = new GridData( SWT.FILL, SWT.NONE, true, false );
+ gd.horizontalSpan = 1;
+ secondaryLabelComposite.setLayoutData( gd );
+
+ // Use Label
+ Label useLabel2 = new Label( secondaryLabelComposite, SWT.NONE );
+ useLabel2.setText( "Use" );
+
+ // Label Combo
+ secondaryLabelCombo = new Combo( secondaryLabelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
+ secondaryLabelCombo.setLayoutData( new GridData() );
+ secondaryLabelCombo.setItems( new String[]
+ { FIRST_NAME, ALL_ALIASES, OID } );
+ secondaryLabelCombo.setEnabled( true );
+
+ // As label Label
+ Label asLabel2 = new Label( secondaryLabelComposite, SWT.NONE );
+ asLabel2.setText( "as secondary label." );
+
+ // Abbreviate row composite
+ Composite abbreviateComposite2 = new Composite( secondaryLabelGroup, SWT.NONE );
+ gl = new GridLayout( 3, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ abbreviateComposite2.setLayout( gl );
+ gd = new GridData( SWT.FILL, SWT.NONE, true, false );
+ gd.horizontalSpan = 1;
+ abbreviateComposite2.setLayoutData( gd );
+
+ // Limit label lenght to Label
+ secondaryLabelLimitButton = new Button( abbreviateComposite2, SWT.CHECK );
+ secondaryLabelLimitButton.setText( "Limit secondary label length to" );
+ gd = new GridData();
+ gd.horizontalSpan = 1;
+ secondaryLabelLimitButton.setLayoutData( gd );
+
+ // Lenght Text
+ secondaryLabelLengthText = new Text( abbreviateComposite2, SWT.NONE | SWT.BORDER );
+ gridData = new GridData();
+ gridData.horizontalSpan = 1;
+ gridData.widthHint = 9 * 3;
+ secondaryLabelLengthText.setLayoutData( gridData );
+ secondaryLabelLengthText.setTextLimit( 3 );
+ secondaryLabelLengthText.addVerifyListener( new VerifyListener()
+ {
+ public void verifyText( VerifyEvent e )
+ {
+ if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$
+ {
+ e.doit = false;
+ }
+ if ( "".equals( secondaryLabelLengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ e.doit = false;
+ }
+ }
+ } );
+
+ // Characters Label
+ Label secondaryLabelcharactersLabel = new Label( abbreviateComposite2, SWT.NONE );
+ secondaryLabelcharactersLabel.setText( "characters." );
+
+ // Schema Label Group
+ Group schemaLabelGroup = new Group( composite, SWT.NONE );
+ schemaLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ schemaLabelGroup.setText( "Schema label" );
+ schemaLabelGroup.setLayout( new GridLayout() );
+ Composite schemaLabelGroupComposite = new Composite( schemaLabelGroup, SWT.NONE );
+ gl = new GridLayout( 1, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ schemaLabelGroupComposite.setLayout( gl );
+ schemaLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ schemaLabelButtonDisplay = new Button( schemaLabelGroupComposite, SWT.CHECK );
+ schemaLabelButtonDisplay.setText( "Display schema name in label." );
+
+ initFieldsFromPreferences();
+
+ initListeners();
+
+ applyDialogFont( parent );
+
+ return parent;
+ }
+
+
+ /**
+ * Initializes the fields from the preferences store.
+ */
+ private void initFieldsFromPreferences()
+ {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ labelCombo.select( store.getInt( PluginConstants.PREFS_SEARCH_VIEW_LABEL ) );
+ limitButton.setSelection( store.getBoolean( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE ) );
+ lengthText.setEnabled( limitButton.getSelection() );
+ lengthText.setText( store.getString( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH ) );
+
+ secondaryLabelButtonDisplay.setSelection( store
+ .getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY ) );
+ secondaryLabelCombo.select( store.getInt( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL ) );
+ secondaryLabelLimitButton.setSelection( store
+ .getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE ) );
+ secondaryLabelLengthText.setText( store
+ .getString( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) );
+ if ( store.getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY ) )
+ {
+ secondaryLabelCombo.setEnabled( true );
+ secondaryLabelLimitButton.setEnabled( true );
+ secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() );
+ }
+ else
+ {
+ secondaryLabelCombo.setEnabled( false );
+ secondaryLabelLimitButton.setEnabled( false );
+ secondaryLabelLengthText.setEnabled( false );
+ }
+
+ schemaLabelButtonDisplay.setSelection( store
+ .getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY ) );
+ }
+
+
+ /**
+ * Initializes the listeners.
+ */
+ private void initListeners()
+ {
+ limitButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ lengthText.setEnabled( limitButton.getSelection() );
+ }
+ } );
+
+ secondaryLabelButtonDisplay.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ if ( secondaryLabelButtonDisplay.getSelection() )
+ {
+ secondaryLabelCombo.setEnabled( true );
+ secondaryLabelLimitButton.setEnabled( true );
+ secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() );
+ }
+ else
+ {
+ secondaryLabelCombo.setEnabled( false );
+ secondaryLabelLimitButton.setEnabled( false );
+ secondaryLabelLengthText.setEnabled( false );
+ }
+ }
+ } );
+
+ secondaryLabelLimitButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() );
+ }
+ } );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+ */
+ protected void performDefaults()
+ {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ labelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SEARCH_VIEW_LABEL ) );
+ limitButton.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE ) );
+ lengthText.setEnabled( limitButton.getSelection() );
+ lengthText.setText( store.getDefaultString( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH ) );
+
+ secondaryLabelButtonDisplay.setSelection( store
+ .getDefaultBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY ) );
+ secondaryLabelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL ) );
+ secondaryLabelLimitButton.setSelection( store
+ .getDefaultBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE ) );
+ secondaryLabelLengthText.setText( store
+ .getDefaultString( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) );
+
+ if ( secondaryLabelButtonDisplay.getSelection() )
+ {
+ secondaryLabelCombo.setEnabled( true );
+ secondaryLabelLimitButton.setEnabled( true );
+ secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() );
+ }
+ else
+ {
+ secondaryLabelCombo.setEnabled( false );
+ secondaryLabelLimitButton.setEnabled( false );
+ secondaryLabelLengthText.setEnabled( false );
+ }
+
+ schemaLabelButtonDisplay.setSelection( store
+ .getDefaultBoolean( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY ) );
+
+ super.performDefaults();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performOk()
+ */
+ public boolean performOk()
+ {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( FIRST_NAME ) )
+ {
+ store
+ .setValue( PluginConstants.PREFS_SEARCH_VIEW_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_FIRST_NAME );
+ }
+ else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) )
+ {
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_LABEL,
+ PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES );
+ }
+ else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( OID ) )
+ {
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID );
+ }
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE, limitButton.getSelection() );
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH, lengthText.getText() );
+
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY, secondaryLabelButtonDisplay
+ .getSelection() );
+ if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( FIRST_NAME ) )
+ {
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL,
+ PluginConstants.PREFS_SEARCH_VIEW_LABEL_FIRST_NAME );
+ }
+ else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( ALL_ALIASES ) )
+ {
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL,
+ PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES );
+ }
+ else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( OID ) )
+ {
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL,
+ PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID );
+ }
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE, secondaryLabelLimitButton
+ .getSelection() );
+ store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH,
+ secondaryLabelLengthText.getText() );
+
+ store
+ .setValue( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY, schemaLabelButtonDisplay.getSelection() );
+
+ return true;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init( IWorkbench workbench )
+ {
+ // Nothing to do
+ }
+}
Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SearchViewPreferencePage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/search/SearchPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/search/SearchPage.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/search/SearchPage.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/search/SearchPage.java Mon Nov 5 09:14:24 2007
@@ -0,0 +1,615 @@
+/*
+ * 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.schemaeditor.view.search;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginConstants;
+import org.apache.directory.studio.schemaeditor.PluginUtils;
+import org.apache.directory.studio.schemaeditor.view.ViewUtils;
+import org.apache.directory.studio.schemaeditor.view.views.SearchView;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.search.ui.ISearchPage;
+import org.eclipse.search.ui.ISearchPageContainer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.PartInitException;
+
+
+/**
+ * This class implements the Search Page.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SearchPage extends DialogPage implements ISearchPage
+{
+ /** The SearchPageContainer */
+ private ISearchPageContainer container;
+
+ // UI Fields
+ private Combo searchCombo;
+ private Button aliasesButton;
+ private Button oidButton;
+ private Button descriptionButon;
+ private Button superiorButton;
+ private Button syntaxButton;
+ private Button matchingRulesButton;
+ private Button superiorsButton;
+ private Button mandatoryAttributesButton;
+ private Button optionalAttributesButton;
+ private Button attributeTypesAndObjectClassesButton;
+ private Button attributeTypesOnlyButton;
+ private Button objectClassesOnly;
+
+ /**
+ * This enums represents the different possible search in for a Schema Search.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+ public enum SearchInEnum
+ {
+ ALIASES, OID, DESCRIPTION, SUPERIOR, SYNTAX, MATCHING_RULES, SUPERIORS, MANDATORY_ATTRIBUTES, OPTIONAL_ATTRIBUTES
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl( Composite parent )
+ {
+ parent.setLayout( new GridLayout() );
+
+ // Search String Label
+ Label searchStringLabel = new Label( parent, SWT.NONE );
+ searchStringLabel.setText( "Search string (*=any string, ?=any character):" );
+ searchStringLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ // Search Combo
+ searchCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
+ searchCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ searchCombo.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent arg0 )
+ {
+ validate();
+ }
+ } );
+
+ // Specific Scope Composite
+ Composite searchInComposite = new Composite( parent, SWT.NONE );
+ GridLayout SearchInLayout = new GridLayout( 3, true );
+ SearchInLayout.marginBottom = 0;
+ SearchInLayout.marginHeight = 0;
+ SearchInLayout.marginLeft = 0;
+ SearchInLayout.marginRight = 0;
+ SearchInLayout.marginTop = 0;
+ SearchInLayout.marginWidth = 0;
+ searchInComposite.setLayout( SearchInLayout );
+ searchInComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 3, 1 ) );
+
+ // Search In Group
+ Group searchInGroup = new Group( searchInComposite, SWT.NONE );
+ searchInGroup.setLayout( new GridLayout() );
+ searchInGroup.setText( "Search in" );
+ searchInGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ // Aliases Button
+ aliasesButton = new Button( searchInGroup, SWT.CHECK );
+ aliasesButton.setText( "Aliases" );
+
+ // OID Button
+ oidButton = new Button( searchInGroup, SWT.CHECK );
+ oidButton.setText( "OID" );
+
+ // Description Button
+ descriptionButon = new Button( searchInGroup, SWT.CHECK );
+ descriptionButon.setText( "Description" );
+
+ // Attribute Types Group
+ Group attributeTypesSearchInGroup = new Group( searchInComposite, SWT.NONE );
+ attributeTypesSearchInGroup.setText( "Seach in (for attribute types)" );
+ attributeTypesSearchInGroup.setLayout( new GridLayout() );
+ attributeTypesSearchInGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+
+ // Superior Button
+ superiorButton = new Button( attributeTypesSearchInGroup, SWT.CHECK );
+ superiorButton.setText( "Superior" );
+
+ // Syntax Button
+ syntaxButton = new Button( attributeTypesSearchInGroup, SWT.CHECK );
+ syntaxButton.setText( "Syntax" );
+
+ // Matching Rules Button
+ matchingRulesButton = new Button( attributeTypesSearchInGroup, SWT.CHECK );
+ matchingRulesButton.setText( "Matching Rules" );
+
+ // Object Classes Group
+ Group objectClassesSearchInGroup = new Group( searchInComposite, SWT.NONE );
+ objectClassesSearchInGroup.setText( "Search in (for object classes)" );
+ objectClassesSearchInGroup.setLayout( new GridLayout() );
+ objectClassesSearchInGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ // Superiors Button
+ superiorsButton = new Button( objectClassesSearchInGroup, SWT.CHECK );
+ superiorsButton.setText( "Superiors" );
+
+ // Mandatory Attributes Button
+ mandatoryAttributesButton = new Button( objectClassesSearchInGroup, SWT.CHECK );
+ mandatoryAttributesButton.setText( "Mandatory Attributes" );
+
+ // Optional Attributes Button
+ optionalAttributesButton = new Button( objectClassesSearchInGroup, SWT.CHECK );
+ optionalAttributesButton.setText( "Optional Attributes" );
+
+ // Scope Group
+ Group scopeGroup = new Group( parent, SWT.NONE );
+ scopeGroup.setText( "Scope" );
+ scopeGroup.setLayout( new GridLayout() );
+ scopeGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ // Attribute Types and Object Classes
+ attributeTypesAndObjectClassesButton = new Button( scopeGroup, SWT.RADIO );
+ attributeTypesAndObjectClassesButton.setText( "Attribute Types And Object Classes" );
+
+ // Attribute Types Only
+ attributeTypesOnlyButton = new Button( scopeGroup, SWT.RADIO );
+ attributeTypesOnlyButton.setText( "Attribute Types Only" );
+
+ // Object Classes Only
+ objectClassesOnly = new Button( scopeGroup, SWT.RADIO );
+ objectClassesOnly.setText( "Object Classes Only" );
+
+ initSearchStringHistory();
+
+ initSearchIn();
+
+ initSearchScope();
+
+ searchCombo.setFocus();
+
+ super.setControl( parent );
+ }
+
+
+ /**
+ * Initializes the Search String History.
+ */
+ private void initSearchStringHistory()
+ {
+ searchCombo.setItems( loadSearchStringHistory() );
+ }
+
+
+ /**
+ * Initializes the Search In.
+ */
+ private void initSearchIn()
+ {
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) == null )
+ {
+ aliasesButton.setSelection( true );
+ }
+ else
+ {
+ aliasesButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) );
+ }
+
+ if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) == null )
+ {
+ oidButton.setSelection( true );
+ }
+ else
+ {
+ oidButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) );
+ }
+
+ if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) == null )
+ {
+ descriptionButon.setSelection( true );
+ }
+ else
+ {
+ descriptionButon.setSelection( settings
+ .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) );
+ }
+ superiorButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR ) );
+ syntaxButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX ) );
+ matchingRulesButton.setSelection( settings
+ .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES ) );
+ superiorsButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS ) );
+ mandatoryAttributesButton.setSelection( settings
+ .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES ) );
+ optionalAttributesButton.setSelection( settings
+ .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES ) );
+ }
+
+
+ /**
+ * Initializes the Search Scope.
+ */
+ private void initSearchScope()
+ {
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ) == null )
+ {
+ attributeTypesAndObjectClassesButton.setSelection( true );
+ }
+ else
+ {
+ switch ( settings.getInt( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ) )
+ {
+ case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC:
+ attributeTypesAndObjectClassesButton.setSelection( true );
+ break;
+ case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_ONLY:
+ attributeTypesOnlyButton.setSelection( true );
+ break;
+ case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_OC_ONLY:
+ objectClassesOnly.setSelection( true );
+ break;
+ }
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.search.ui.ISearchPage#performAction()
+ */
+ public boolean performAction()
+ {
+ // Search In
+ List<SearchInEnum> searchIn = new ArrayList<SearchInEnum>();
+ if ( aliasesButton.getSelection() )
+ {
+ searchIn.add( SearchInEnum.ALIASES );
+ }
+ if ( oidButton.getSelection() )
+ {
+ searchIn.add( SearchInEnum.OID );
+ }
+ if ( descriptionButon.getSelection() )
+ {
+ searchIn.add( SearchInEnum.DESCRIPTION );
+ }
+ if ( superiorButton.getSelection() )
+ {
+ searchIn.add( SearchInEnum.SUPERIOR );
+ }
+ if ( syntaxButton.getSelection() )
+ {
+ searchIn.add( SearchInEnum.SYNTAX );
+ }
+ if ( matchingRulesButton.getSelection() )
+ {
+ searchIn.add( SearchInEnum.MATCHING_RULES );
+ }
+ if ( superiorsButton.getSelection() )
+ {
+ searchIn.add( SearchInEnum.SUPERIORS );
+ }
+ if ( mandatoryAttributesButton.getSelection() )
+ {
+ searchIn.add( SearchInEnum.MANDATORY_ATTRIBUTES );
+ }
+ if ( optionalAttributesButton.getSelection() )
+ {
+ searchIn.add( SearchInEnum.OPTIONAL_ATTRIBUTES );
+ }
+
+ // Scope
+ int scope = 0;
+ if ( attributeTypesAndObjectClassesButton.getSelection() )
+ {
+ scope = PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC;
+ }
+ else if ( attributeTypesOnlyButton.getSelection() )
+ {
+ scope = PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_ONLY;
+ }
+ else if ( objectClassesOnly.getSelection() )
+ {
+ scope = PluginConstants.PREFS_SEARCH_PAGE_SCOPE_OC_ONLY;
+ }
+
+ // Opening the SearchView and displaying the results
+ try
+ {
+ SearchView searchView = ( SearchView ) Activator.getDefault().getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().showView( SearchView.ID );
+ searchView.setSearchInput( searchCombo.getText(), searchIn.toArray( new SearchInEnum[0] ), scope );
+ }
+ catch ( PartInitException e )
+ {
+ PluginUtils.logError( "An error occured when opening the view.", e );
+ ViewUtils.displayErrorMessageBox( "Error", "An error occured when opening the view." );
+ }
+
+ return true;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.search.ui.ISearchPage#setContainer(org.eclipse.search.ui.ISearchPageContainer)
+ */
+ public void setContainer( ISearchPageContainer container )
+ {
+ this.container = container;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
+ */
+ public void setVisible( boolean visible )
+ {
+ validate();
+ super.setVisible( visible );
+ }
+
+
+ /**
+ * Verifies if the page is valid.
+ *
+ * @return
+ * true if the page is valid
+ */
+ private boolean isValid()
+ {
+ return ( ( searchCombo.getText() != null ) && ( !"".equals( searchCombo.getText() ) ) ); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Validates the page.
+ */
+ private void validate()
+ {
+ container.setPerformActionEnabled( isValid() );
+ }
+
+
+ /**
+ * Adds a new Search String to the History.
+ *
+ * @param value
+ * the value to save
+ */
+ public static void addSearchStringHistory( String value )
+ {
+ // get current history
+ String[] history = loadSearchStringHistory();
+ List<String> list = new ArrayList<String>( Arrays.asList( history ) );
+
+ // add new value or move to first position
+ if ( list.contains( value ) )
+ {
+ list.remove( value );
+ }
+ list.add( 0, value );
+
+ // check history size
+ while ( list.size() > 10 )
+ {
+ list.remove( list.size() - 1 );
+ }
+
+ // save
+ history = ( String[] ) list.toArray( new String[list.size()] );
+ Activator.getDefault().getDialogSettings().put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_HISTORY, history );
+ }
+
+
+ /**
+ * Removes the given value from the History.
+ *
+ * @param value
+ * the value to remove
+ */
+ public static void removeSearchStringHistory( String value )
+ {
+ // get current history
+ String[] history = loadSearchStringHistory();
+ List<String> list = new ArrayList<String>( Arrays.asList( history ) );
+
+ // add new value or move to first position
+ if ( list.contains( value ) )
+ {
+ list.remove( value );
+ }
+
+ // save
+ history = ( String[] ) list.toArray( new String[list.size()] );
+ Activator.getDefault().getDialogSettings().put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_HISTORY, history );
+ }
+
+
+ /**
+ * Loads the Search History
+ *
+ * @return
+ * an array of String containing the Search History
+ */
+ public static String[] loadSearchStringHistory()
+ {
+ String[] history = Activator.getDefault().getDialogSettings().getArray(
+ PluginConstants.PREFS_SEARCH_PAGE_SEARCH_HISTORY );
+ if ( history == null )
+ {
+ history = new String[0];
+ }
+ return history;
+ }
+
+
+ /**
+ * Loads the Search In.
+ *
+ * @return
+ * the search In
+ */
+ public static List<SearchInEnum> loadSearchIn()
+ {
+ List<SearchInEnum> searchScope = new ArrayList<SearchInEnum>();
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) == null )
+ {
+ searchScope.add( SearchInEnum.ALIASES );
+ }
+ else
+ {
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) )
+ {
+ searchScope.add( SearchInEnum.ALIASES );
+ }
+ }
+
+ if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) == null )
+ {
+ searchScope.add( SearchInEnum.OID );
+ }
+ else
+ {
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) )
+ {
+ searchScope.add( SearchInEnum.OID );
+ }
+ }
+
+ if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) == null )
+ {
+ searchScope.add( SearchInEnum.DESCRIPTION );
+ }
+ else
+ {
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) )
+ {
+ searchScope.add( SearchInEnum.DESCRIPTION );
+ }
+ }
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR ) )
+ {
+ searchScope.add( SearchInEnum.SUPERIOR );
+ }
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX ) )
+ {
+ searchScope.add( SearchInEnum.SYNTAX );
+ }
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES ) )
+ {
+ searchScope.add( SearchInEnum.MATCHING_RULES );
+ }
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS ) )
+ {
+ searchScope.add( SearchInEnum.SUPERIORS );
+ }
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES ) )
+ {
+ searchScope.add( SearchInEnum.MANDATORY_ATTRIBUTES );
+ }
+ if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES ) )
+ {
+ searchScope.add( SearchInEnum.OPTIONAL_ATTRIBUTES );
+ }
+
+ return searchScope;
+ }
+
+
+ /**
+ * Loads the scope.
+ *
+ * @return
+ * the scope
+ */
+ public static int loadScope()
+ {
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ) == null )
+ {
+ return PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC;
+ }
+ else
+ {
+ return settings.getInt( PluginConstants.PREFS_SEARCH_PAGE_SCOPE );
+ }
+ }
+
+
+ /**
+ * Saves the Search scope.
+ *
+ * @param scope
+ * the Search scope
+ */
+ public static void saveSearchScope( List<SearchInEnum> scope )
+ {
+ if ( ( scope != null ) && ( scope.size() > 0 ) )
+ {
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+
+ settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES, scope.contains( SearchInEnum.ALIASES ) );
+ settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID, scope.contains( SearchInEnum.OID ) );
+ settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION, scope
+ .contains( SearchInEnum.DESCRIPTION ) );
+ settings
+ .put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR, scope.contains( SearchInEnum.SUPERIOR ) );
+ settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX, scope.contains( SearchInEnum.SYNTAX ) );
+ settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES, scope
+ .contains( SearchInEnum.MATCHING_RULES ) );
+ settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS, scope
+ .contains( SearchInEnum.SUPERIORS ) );
+ settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES, scope
+ .contains( SearchInEnum.MANDATORY_ATTRIBUTES ) );
+ settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES, scope
+ .contains( SearchInEnum.OPTIONAL_ATTRIBUTES ) );
+ }
+ }
+
+
+ /**
+ * Clears the Search History.
+ */
+ public static void clearSearchHistory()
+ {
+ Activator.getDefault().getDialogSettings()
+ .put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_HISTORY, new String[0] );
+ }
+}
Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/search/SearchPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyView.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyView.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyView.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyView.java Mon Nov 5 09:14:24 2007
@@ -0,0 +1,206 @@
+/*
+ * 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.schemaeditor.view.views;
+
+
+import org.apache.directory.shared.ldap.schema.SchemaObject;
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.controller.HierarchyViewController;
+import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.schemaeditor.view.ViewUtils;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+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;
+import org.eclipse.ui.part.ViewPart;
+
+
+/**
+ * This class implements the Hierarchy View.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class HierarchyView extends ViewPart
+{
+ /** The view's ID */
+ public static final String ID = Activator.PLUGIN_ID + ".view.HierarchyView"; //$NON-NLS-1$
+
+ /** The tree viewer */
+ private TreeViewer viewer;
+
+ /** The controller */
+ private HierarchyViewController controller;
+
+ /** The Overview label */
+ private Label overviewLabel;
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createPartControl( Composite parent )
+ {
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.horizontalSpacing = 0;
+ gridLayout.marginBottom = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.marginLeft = 0;
+ gridLayout.marginRight = 0;
+ gridLayout.marginTop = 0;
+ gridLayout.marginWidth = 0;
+ gridLayout.verticalSpacing = 0;
+ parent.setLayout( gridLayout );
+
+ // Overview Label
+ overviewLabel = new Label( parent, SWT.WRAP );
+ overviewLabel.setText( "" );
+ overviewLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ // Separator Label
+ Label separatorLabel = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL );
+ separatorLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ initViewer( parent );
+
+ controller = new HierarchyViewController( this );
+
+ // Help Context for Dynamic Help
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( parent, Activator.PLUGIN_ID + "." + "hierarchy_view" );
+ }
+
+
+ /**
+ * Initializes the Viewer
+ *
+ * @param parent
+ * the parent Composite
+ */
+ private void initViewer( Composite parent )
+ {
+ viewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL );
+ viewer.setContentProvider( new HierarchyViewContentProvider() );
+ viewer.setLabelProvider( new DecoratingLabelProvider( new HierarchyViewLabelProvider( viewer ), Activator
+ .getDefault().getWorkbench().getDecoratorManager().getLabelDecorator() ) );
+ viewer.getTree().setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+ viewer.getTree().setEnabled( false );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ public void setFocus()
+ {
+ viewer.getControl().setFocus();
+ }
+
+
+ /**
+ * Gets the TreeViewer
+ *
+ * @return
+ * the TreeViewer
+ */
+ public TreeViewer getViewer()
+ {
+ return viewer;
+ }
+
+
+ /**
+ * Refreshes the viewer.
+ */
+ public void refresh()
+ {
+ viewer.refresh();
+ viewer.expandAll();
+ }
+
+
+ public void setInput( Object input )
+ {
+ viewer.setInput( input );
+ viewer.expandAll();
+ if ( input == null )
+ {
+ overviewLabel.setText( "" );
+ }
+ else
+ {
+ if ( input instanceof AttributeTypeImpl )
+ {
+ setOverviewLabel( ( AttributeTypeImpl ) input );
+ }
+ else if ( input instanceof ObjectClassImpl )
+ {
+ setOverviewLabel( ( ObjectClassImpl ) input );
+ }
+ else
+ {
+ overviewLabel.setText( "" );
+ }
+ }
+ }
+
+
+ /**
+ * Set the overview label for the given schema object.
+ *
+ * @param object
+ * the schema object
+ */
+ private void setOverviewLabel( SchemaObject object )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ String[] names = object.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ sb.append( ViewUtils.concateAliases( names ) );
+ }
+ else
+ {
+ sb.append( "(None)" );
+ }
+ sb.append( " (" );
+ sb.append( object.getOid() );
+ sb.append( ") - Schema:" );
+ sb.append( object.getSchema() );
+
+ overviewLabel.setText( sb.toString() );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#dispose()
+ */
+ public void dispose()
+ {
+ controller.dispose();
+
+ super.dispose();
+ }
+}
Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyView.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewContentProvider.java?rev=592094&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewContentProvider.java (added)
+++ directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewContentProvider.java Mon Nov 5 09:14:24 2007
@@ -0,0 +1,373 @@
+/*
+ * 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.schemaeditor.view.views;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.schemaeditor.Activator;
+import org.apache.directory.studio.schemaeditor.PluginConstants;
+import org.apache.directory.studio.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.schemaeditor.model.hierarchy.HierarchyManager;
+import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper;
+import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper;
+import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode;
+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 Schemas View.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class HierarchyViewContentProvider implements IStructuredContentProvider, ITreeContentProvider
+{
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements( Object inputElement )
+ {
+ return getChildren( inputElement );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ public Object[] getChildren( Object parentElement )
+ {
+ List<TreeNode> children = new ArrayList<TreeNode>();
+
+ if ( parentElement instanceof ObjectClassImpl )
+ {
+ ObjectClassImpl oc = ( ObjectClassImpl ) parentElement;
+
+ children = createTypeHierarchyObjectClass( oc );
+ }
+ else if ( parentElement instanceof AttributeTypeImpl )
+ {
+ AttributeTypeImpl at = ( AttributeTypeImpl ) parentElement;
+
+ children = createTypeHierarchyAttributeType( at );
+ }
+ else if ( parentElement instanceof TreeNode )
+ {
+ children = ( ( TreeNode ) parentElement ).getChildren();
+ }
+
+ return children.toArray();
+ }
+
+
+ /**
+ * Creates the Type Hierarchy for an object class.
+ *
+ * @param oc
+ * the object class
+ * @return
+ * the Type Hierarchy for an object class
+ */
+ private List<TreeNode> createTypeHierarchyObjectClass( ObjectClassImpl oc )
+ {
+ List<TreeNode> children = new ArrayList<TreeNode>();
+
+ HierarchyManager hierarchyManager = new HierarchyManager();
+
+ // Creating the wrapper of the object class
+ ObjectClassWrapper ocw = new ObjectClassWrapper( oc );
+
+ int mode = Activator.getDefault().getDialogSettings().getInt( PluginConstants.PREFS_HIERARCHY_VIEW_MODE );
+ if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_TYPE )
+ {
+ // Creating its children's wrappers
+ createChildrenHierarchy( ocw, hierarchyManager.getChildren( oc ), hierarchyManager );
+
+ // Creating its parents' wrappers
+ createParentHierarchy( hierarchyManager.getParents( oc ), children, ocw, hierarchyManager );
+ }
+ else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUPERTYPE )
+ {
+ // Creating its parents' wrappers
+ createParentHierarchy( hierarchyManager.getParents( oc ), children, ocw, hierarchyManager );
+ }
+ else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUBTYPE )
+ {
+ // Creating its children's wrappers
+ createChildrenHierarchy( ocw, hierarchyManager.getChildren( oc ), hierarchyManager );
+
+ children.add( ocw );
+ }
+
+ return children;
+ }
+
+
+ /**
+ * Creates the parent hierarchy.
+ *
+ * @param parents
+ * the parents
+ * @param children
+ * the children
+ * @param ocw
+ * the object class wrapper
+ * @param hierarchyManager
+ * the hierarchy manager
+ */
+ private void createParentHierarchy( List<Object> parents, List<TreeNode> children, ObjectClassWrapper ocw,
+ HierarchyManager hierarchyManager )
+ {
+ if ( parents != null )
+ {
+ for ( Object parent : parents )
+ {
+ if ( parent instanceof ObjectClassImpl )
+ {
+ ObjectClassImpl parentOC = ( ObjectClassImpl ) parent;
+ ObjectClassWrapper duplicatedOCW = ( ObjectClassWrapper ) duplicateTreeNode( ocw );
+
+ ObjectClassWrapper ocw2 = new ObjectClassWrapper( parentOC );
+ duplicatedOCW.setParent( ocw2 );
+ ocw2.addChild( duplicatedOCW );
+
+ createParentHierarchy( hierarchyManager.getParents( parentOC ), children, ocw2, hierarchyManager );
+ }
+ else
+ {
+ children.add( ocw );
+ }
+ }
+ }
+ else
+ {
+ children.add( ocw );
+ }
+ }
+
+
+ /**
+ * Duplicates the given node.
+ *
+ * @param node
+ * the node
+ * @return
+ * a duplicate of the given node
+ */
+ public TreeNode duplicateTreeNode( TreeNode node )
+ {
+ if ( node != null )
+ {
+ if ( node instanceof ObjectClassWrapper )
+ {
+ ObjectClassWrapper ocNode = ( ObjectClassWrapper ) node;
+
+ ObjectClassWrapper duplicatedOCNode = new ObjectClassWrapper( ocNode.getObjectClass(), ocNode
+ .getParent() );
+
+ for ( TreeNode child : ocNode.getChildren() )
+ {
+ TreeNode duplicatedChild = duplicateTreeNode( child );
+ if ( duplicatedChild != null )
+ {
+ duplicatedOCNode.addChild( duplicatedChild );
+ }
+ }
+
+ return duplicatedOCNode;
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Creates the Type Hierarchy for an attribute type.
+ *
+ * @param at
+ * the attribute type
+ * @return
+ * the Type Hierarchy for an attribute type
+ */
+ private List<TreeNode> createTypeHierarchyAttributeType( AttributeTypeImpl at )
+ {
+ List<TreeNode> children = new ArrayList<TreeNode>();
+ HierarchyManager hierarchyManager = new HierarchyManager();
+ int mode = Activator.getDefault().getDialogSettings().getInt( PluginConstants.PREFS_HIERARCHY_VIEW_MODE );
+
+ // Creating the wrapper of the attribute type
+ AttributeTypeWrapper atw = new AttributeTypeWrapper( at );
+
+ if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_TYPE )
+ {
+ // Creating the children's wrappers
+ createChildrenHierarchy( atw, hierarchyManager.getChildren( at ), hierarchyManager );
+
+ // Creating its parents' wrappers
+ List<Object> parents = hierarchyManager.getParents( at );
+ while ( ( parents != null ) && ( parents.size() == 1 ) )
+ {
+ Object parent = parents.get( 0 );
+ if ( parent instanceof AttributeTypeImpl )
+ {
+ AttributeTypeImpl parentAT = ( AttributeTypeImpl ) parent;
+
+ AttributeTypeWrapper atw2 = new AttributeTypeWrapper( parentAT );
+ atw.setParent( atw2 );
+ atw2.addChild( atw );
+
+ atw = atw2;
+
+ parents = hierarchyManager.getParents( parentAT );
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ children.add( atw );
+ }
+ else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUPERTYPE )
+ {
+ // Creating its parents' wrappers
+ List<Object> parents = hierarchyManager.getParents( at );
+ while ( ( parents != null ) && ( parents.size() == 1 ) )
+ {
+ Object parent = parents.get( 0 );
+ if ( parent instanceof AttributeTypeImpl )
+ {
+ AttributeTypeImpl parentAT = ( AttributeTypeImpl ) parent;
+
+ AttributeTypeWrapper atw2 = new AttributeTypeWrapper( parentAT );
+ atw.setParent( atw2 );
+ atw2.addChild( atw );
+
+ atw = atw2;
+
+ parents = hierarchyManager.getParents( parentAT );
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ children.add( atw );
+ }
+ else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUBTYPE )
+ {
+ // Creating the children's wrappers
+ createChildrenHierarchy( atw, hierarchyManager.getChildren( at ), hierarchyManager );
+
+ children.add( atw );
+ }
+
+ return children;
+ }
+
+
+ /**
+ * Create the children hierarchy
+ *
+ * @param node
+ * the parent node.
+ * @param children
+ * the children
+ */
+ private void createChildrenHierarchy( TreeNode node, List<Object> children, HierarchyManager hierarchyManager )
+ {
+ if ( ( children != null ) && ( children.size() > 0 ) )
+ {
+ for ( Object child : children )
+ {
+ TreeNode childNode = null;
+ if ( child instanceof AttributeTypeImpl )
+ {
+ AttributeTypeImpl at = ( AttributeTypeImpl ) child;
+ childNode = new AttributeTypeWrapper( at, node );
+ node.addChild( childNode );
+ }
+ else if ( child instanceof ObjectClassImpl )
+ {
+ ObjectClassImpl oc = ( ObjectClassImpl ) child;
+ childNode = new ObjectClassWrapper( oc, node );
+ node.addChild( childNode );
+ }
+
+ // Recursively creating the hierarchy for all children
+ // of the given element.
+ createChildrenHierarchy( childNode, hierarchyManager.getChildren( child ), hierarchyManager );
+ }
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public Object getParent( Object element )
+ {
+ if ( element instanceof TreeNode )
+ {
+ return ( ( TreeNode ) element ).getParent();
+ }
+
+ // Default
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren( Object element )
+ {
+ if ( element instanceof TreeNode )
+ {
+ return true;
+ }
+
+ // Default
+ return false;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose()
+ {
+ }
+
+
+ /* (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 )
+ {
+ }
+}
Propchange: directory/sandbox/felixk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewContentProvider.java
------------------------------------------------------------------------------
svn:eol-style = native