You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/12/18 18:53:22 UTC
svn commit: r488368 [8/23] - in /directory/sandbox/pamarcelot/ldapstudio:
ldapstudio-browser-ui/ ldapstudio-browser-ui/META-INF/
ldapstudio-browser-ui/about_files/ ldapstudio-browser-ui/icons/
ldapstudio-browser-ui/icons/ovr16/ ldapstudio-browser-ui/sr...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/FilterSubtreeDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/FilterSubtreeDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/FilterSubtreeDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/FilterSubtreeDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,128 @@
+/*
+ * 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.ldapstudio.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.ui.widgets.search.FilterWidget;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+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.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class FilterSubtreeDialog extends Dialog
+{
+
+ public static final String DIALOG_TITLE = "Filter Subtree";
+
+ private IConnection connection;
+
+ private FilterWidget filterWidget;
+
+ private String filter;
+
+
+ public FilterSubtreeDialog( Shell parentShell, String filter, IConnection connection )
+ {
+ super( parentShell );
+ this.filter = filter;
+ this.connection = connection;
+ setShellStyle( SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE );
+ }
+
+
+ public String getFilter()
+ {
+ return this.filter;
+ }
+
+
+ protected void configureShell( Shell newShell )
+ {
+ super.configureShell( newShell );
+ newShell.setText( DIALOG_TITLE );
+ }
+
+
+ protected void buttonPressed( int buttonId )
+ {
+ if ( buttonId == IDialogConstants.OK_ID )
+ {
+ this.filter = filterWidget.getFilter();
+ filterWidget.saveDialogSettings();
+ }
+
+ // call super implementation
+ super.buttonPressed( buttonId );
+ }
+
+
+ protected Control createButtonBar( Composite parent )
+ {
+ Composite composite = ( Composite ) super.createButtonBar( parent );
+ return composite;
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+ // Composite composite = parent;
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+ // gd.heightHint =
+ // convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH)/2;
+ composite.setLayoutData( gd );
+
+ Composite inner = new Composite( composite, SWT.NONE );
+ GridLayout gridLayout = new GridLayout( 2, false );
+ inner.setLayout( gridLayout );
+ gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL );
+ gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+ inner.setLayoutData( gd );
+
+ filterWidget = new FilterWidget( connection, filter != null ? filter : "" );
+ filterWidget.createWidget( inner );
+ // filterWidget.addWidgetModifyListener(new WidgetModifyListener(){
+ // public void widgetModified(WidgetModifyEvent event) {
+ // wizard.setExportFilter(filterWidget.getFilter());
+ // validate();
+ // }
+ // });
+ filterWidget.setFocus();
+
+ return composite;
+ }
+
+
+ protected boolean canHandleShellCloseEvent()
+ {
+ // proposal popup is opened, don't close dialog!
+ return super.canHandleShellCloseEvent();
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/HexDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/HexDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/HexDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/HexDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,252 @@
+/*
+ * 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.ldapstudio.browser.ui.dialogs;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.ExceptionHandler;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+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.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+
+public class HexDialog extends Dialog
+{
+
+ public static final String DIALOG_TITLE = "Hex Editor";
+
+ public static final double MAX_WIDTH = 550.0;
+
+ public static final double MAX_HEIGHT = 550.0;
+
+ public static final int LOAD_BUTTON_ID = 9998;
+
+ public static final int SAVE_BUTTON_ID = 9999;
+
+ private byte[] currentData;
+
+ private byte[] returnData;
+
+ private Text hexText;
+
+
+ public HexDialog( Shell parentShell, byte[] initialData )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ this.currentData = initialData;
+ }
+
+
+ public boolean close()
+ {
+ return super.close();
+ }
+
+
+ protected void buttonPressed( int buttonId )
+ {
+ if ( buttonId == IDialogConstants.OK_ID )
+ {
+ this.returnData = this.currentData;
+ }
+ else if ( buttonId == SAVE_BUTTON_ID )
+ {
+ FileDialog fileDialog = new FileDialog( getShell(), SWT.SAVE );
+ fileDialog.setText( "Save Data" );
+ // fileDialog.setFilterExtensions(new String[]{"*.jpg"});
+ String returnedFileName = fileDialog.open();
+ if ( returnedFileName != null )
+ {
+ try
+ {
+ File file = new File( returnedFileName );
+ FileOutputStream out = new FileOutputStream( file );
+ out.write( currentData );
+ out.flush();
+ out.close();
+ }
+ catch ( FileNotFoundException e )
+ {
+ new ExceptionHandler().handleException( new Status( IStatus.ERROR, BrowserUIPlugin.PLUGIN_ID,
+ IStatus.ERROR, "Can't write to file", e ) );
+ }
+ catch ( IOException e )
+ {
+ new ExceptionHandler().handleException( new Status( IStatus.ERROR, BrowserUIPlugin.PLUGIN_ID,
+ IStatus.ERROR, "Can't write to file", e ) );
+ }
+ }
+ }
+ else if ( buttonId == LOAD_BUTTON_ID )
+ {
+ FileDialog fileDialog = new FileDialog( getShell(), SWT.OPEN );
+ fileDialog.setText( "Load Data" );
+ String returnedFileName = fileDialog.open();
+ if ( returnedFileName != null )
+ {
+ try
+ {
+ File file = new File( returnedFileName );
+ FileInputStream in = new FileInputStream( file );
+ ByteArrayOutputStream out = new ByteArrayOutputStream( ( int ) file.length() );
+ byte[] buf = new byte[4096];
+ int len;
+ while ( ( len = in.read( buf ) ) > 0 )
+ {
+ out.write( buf, 0, len );
+ }
+ this.currentData = out.toByteArray();
+ hexText.setText( toFormattedHex( this.currentData ) );
+ out.close();
+ in.close();
+ }
+ catch ( FileNotFoundException e )
+ {
+ new ExceptionHandler().handleException( new Status( IStatus.ERROR, BrowserUIPlugin.PLUGIN_ID,
+ IStatus.ERROR, "Can't read file", e ) );
+ }
+ catch ( IOException e )
+ {
+ new ExceptionHandler().handleException( new Status( IStatus.ERROR, BrowserUIPlugin.PLUGIN_ID,
+ IStatus.ERROR, "Can't read file", e ) );
+ }
+ }
+ }
+ else
+ {
+ this.returnData = null;
+ }
+
+ super.buttonPressed( buttonId );
+ }
+
+
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( DIALOG_TITLE );
+ shell.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_HEXEDITOR ) );
+ }
+
+
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ createButton( parent, LOAD_BUTTON_ID, "Load Data...", false );
+ createButton( parent, SAVE_BUTTON_ID, "Save Data...", false );
+ createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+ createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+ // create composite
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+
+ hexText = new Text( composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY );
+ hexText.setFont( JFaceResources.getFont( JFaceResources.TEXT_FONT ) );
+
+ hexText.setText( toFormattedHex( this.currentData ) );
+ // GridData gd = new GridData(GridData.GRAB_HORIZONTAL |
+ // GridData.HORIZONTAL_ALIGN_FILL);
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.widthHint = convertHorizontalDLUsToPixels( ( int ) ( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH * 1.6 ) );
+ gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 );
+ hexText.setLayoutData( gd );
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ private String toFormattedHex( byte[] data )
+ {
+ StringBuffer sb = new StringBuffer();
+ for ( int i = 0; i < data.length; i++ )
+ {
+ int b = ( int ) data[i];
+ if ( b < 0 )
+ b = 256 + b;
+ String s = Integer.toHexString( b );
+ if ( s.length() == 1 )
+ s = "0" + s;
+ sb.append( s ).append( " " );
+ if ( ( i + 1 ) % 8 == 0 )
+ sb.append( " " );
+
+ if ( i == data.length - 1 )
+ {
+ while ( ( i + 1 ) % 16 != 0 )
+ {
+ sb.append( " " );
+ if ( ( i + 1 ) % 8 == 0 )
+ sb.append( " " );
+ i++;
+ }
+ sb.append( " " );
+ }
+
+ if ( ( i + 1 ) % 16 == 0 )
+ {
+ sb.append( " " );
+ for ( int x = i - 16 + 1; x <= i && x < data.length; x++ )
+ {
+ if ( data[x] > 32 && data[x] < 127 )
+ sb.append( ( char ) data[x] );
+ else
+ sb.append( '.' );
+ if ( ( x + 1 ) % 8 == 0 )
+ sb.append( " " );
+ }
+ }
+
+ if ( ( i + 1 ) % 16 == 0 )
+ {
+ sb.append( "\r\n" );
+ }
+ }
+ return sb.toString();
+ }
+
+
+ public byte[] getData()
+ {
+ return this.returnData;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ImageDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ImageDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ImageDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ImageDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,681 @@
+/*
+ * 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.ldapstudio.browser.ui.dialogs;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.ExceptionHandler;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+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.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageLoader;
+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.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+
+
+public class ImageDialog extends Dialog
+{
+
+ public static final String DIALOG_TITLE = "Image Editor";
+
+ // public static final String[] IMAGE_FILE_EXTENSIONS = {"*.jpg; *.jpeg;
+ // *.gif; *.bmp; *.png"};
+ public static final int MAX_WIDTH = 250;
+
+ public static final int MAX_HEIGHT = 250;
+
+ public static final int CURRENT_TAB = 0;
+
+ public static final int NEW_TAB = 1;
+
+ public static final String SELECTED_TAB_DIALOGSETTINGS_KEY = ImageDialog.class.getName() + ".tab";
+
+ private TabFolder tabFolder;
+
+ private TabItem currentTab;
+
+ private TabItem newTab;
+
+ private byte[] currentImageRawData;
+
+ private Image currentImage;
+
+ private Composite currentImageContainer;
+
+ private Label currentImageLabel;
+
+ private Text currentImageTypeText;
+
+ private Text currentImageWidthText;
+
+ private Text currentImageHeightText;
+
+ private Text currentImageSizeText;
+
+ private Button currentImageSaveButton;
+
+ private byte[] newImageRawData;
+
+ private Image newImage;
+
+ private Composite newImageContainer;
+
+ private Label newImageLabel;
+
+ private Text newImageTypeText;
+
+ private Text newImageWidthText;
+
+ private Text newImageHeightText;
+
+ private Text newImageSizeText;
+
+ private Text newImageFilenameText;
+
+ private Button newImageBrowseButton;
+
+ private int requiredImageType;
+
+ private byte[] newImageRawDataInRequiredFormat;
+
+ private Button okButton;
+
+
+ public ImageDialog( Shell parentShell, byte[] currentImageRawData, int requiredImageType )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ this.currentImageRawData = currentImageRawData;
+ this.requiredImageType = requiredImageType;
+
+ newImageRawDataInRequiredFormat = null;
+ }
+
+
+ public boolean close()
+ {
+ if ( this.currentImage != null && !this.currentImage.isDisposed() )
+ {
+ this.currentImage.dispose();
+ }
+ if ( this.newImage != null && !this.newImage.isDisposed() )
+ {
+ this.newImage.dispose();
+ }
+
+ // save selected tab to dialog settings
+ BrowserUIPlugin.getDefault().getDialogSettings().put( SELECTED_TAB_DIALOGSETTINGS_KEY,
+ this.tabFolder.getSelectionIndex() );
+
+ return super.close();
+ }
+
+
+ protected void buttonPressed( int buttonId )
+ {
+ if ( buttonId == IDialogConstants.OK_ID )
+ {
+ if ( this.newImageRawData != null )
+ {
+ try
+ {
+ ImageData imageData = new ImageData( new ByteArrayInputStream( this.newImageRawData ) );
+ if ( imageData.type != this.requiredImageType )
+ {
+ ImageLoader imageLoader = new ImageLoader();
+ imageLoader.data = new ImageData[]
+ { imageData };
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ imageLoader.save( baos, this.requiredImageType );
+ this.newImageRawDataInRequiredFormat = baos.toByteArray();
+ }
+ else
+ {
+ this.newImageRawDataInRequiredFormat = this.newImageRawData;
+ }
+ }
+ catch ( SWTException swte )
+ {
+ this.newImageRawDataInRequiredFormat = null;
+ }
+ }
+
+ }
+ else
+ {
+ this.newImageRawDataInRequiredFormat = null;
+ }
+
+ super.buttonPressed( buttonId );
+ }
+
+
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( DIALOG_TITLE );
+ shell.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_IMAGEEDITOR ) );
+ }
+
+
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+ createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+
+ // load dialog settings
+ try
+ {
+ int tabIndex = BrowserUIPlugin.getDefault().getDialogSettings().getInt( SELECTED_TAB_DIALOGSETTINGS_KEY );
+ this.tabFolder.setSelection( tabIndex );
+ }
+ catch ( Exception e )
+ {
+ }
+
+ // update on load
+ updateTabFolder();
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ GridData gd1 = new GridData( GridData.FILL_BOTH );
+ gd1.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+ gd1.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+ composite.setLayoutData( gd1 );
+
+ this.tabFolder = new TabFolder( composite, SWT.TOP );
+ GridLayout mainLayout = new GridLayout();
+ mainLayout.marginWidth = 0;
+ mainLayout.marginHeight = 0;
+ this.tabFolder.setLayout( mainLayout );
+ this.tabFolder.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ this.tabFolder.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ updateTabFolder();
+ }
+ } );
+
+ // current image
+ if ( this.currentImageRawData != null && this.currentImageRawData.length > 0 )
+ {
+ currentImageContainer = new Composite( this.tabFolder, SWT.NONE );
+ GridLayout currentLayout = new GridLayout( 1, false );
+ currentLayout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN );
+ currentLayout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN );
+ currentLayout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING );
+ currentLayout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING );
+ currentImageContainer.setLayout( currentLayout );
+ currentImageContainer.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+
+ currentImageLabel = createImageLabel( currentImageContainer );
+
+ Composite currentImageInfoContainer = createImageInfoContainer( currentImageContainer );
+ currentImageTypeText = createImageInfo( currentImageInfoContainer, "Image Type:" );
+ currentImageSizeText = createImageInfo( currentImageInfoContainer, "Image Size:" );
+ currentImageWidthText = createImageInfo( currentImageInfoContainer, "Image Width:" );
+ currentImageHeightText = createImageInfo( currentImageInfoContainer, "Image Height:" );
+
+ Composite currentImageSaveContainer = createImageInfoContainer( currentImageContainer );
+ Label dummyLabel = BaseWidgetUtils.createLabel( currentImageSaveContainer, "", 1 );
+ GridData gd = new GridData( GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL );
+ dummyLabel.setLayoutData( gd );
+ currentImageSaveButton = createButton( currentImageSaveContainer, "Save..." );
+ currentImageSaveButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent event )
+ {
+ FileDialog fileDialog = new FileDialog( ImageDialog.this.getShell(), SWT.SAVE );
+ fileDialog.setText( "Save Image" );
+ fileDialog.setFilterExtensions( new String[]
+ { "*.jpg" } );
+ String returnedFileName = fileDialog.open();
+ if ( returnedFileName != null )
+ {
+ try
+ {
+ File file = new File( returnedFileName );
+ FileOutputStream out = new FileOutputStream( file );
+ out.write( currentImageRawData );
+ out.flush();
+ out.close();
+ }
+ catch ( FileNotFoundException e )
+ {
+ new ExceptionHandler().handleException( new Status( IStatus.ERROR,
+ BrowserUIPlugin.PLUGIN_ID, IStatus.ERROR, "Can't write to file", e ) );
+ }
+ catch ( IOException e )
+ {
+ new ExceptionHandler().handleException( new Status( IStatus.ERROR,
+ BrowserUIPlugin.PLUGIN_ID, IStatus.ERROR, "Can't write to file", e ) );
+ }
+ }
+ }
+ } );
+
+ this.currentTab = new TabItem( this.tabFolder, SWT.NONE );
+ this.currentTab.setText( "Current Image" );
+ this.currentTab.setControl( currentImageContainer );
+ }
+
+ // new image
+ newImageContainer = new Composite( this.tabFolder, SWT.NONE );
+ GridLayout newLayout = new GridLayout( 1, false );
+ newLayout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN );
+ newLayout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN );
+ newLayout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING );
+ newLayout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING );
+ newImageContainer.setLayout( newLayout );
+ newImageContainer.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+
+ newImageLabel = createImageLabel( newImageContainer );
+
+ Composite newImageInfoContainer = createImageInfoContainer( newImageContainer );
+ newImageTypeText = createImageInfo( newImageInfoContainer, "Image Type:" );
+ newImageSizeText = createImageInfo( newImageInfoContainer, "Image Size:" );
+ newImageWidthText = createImageInfo( newImageInfoContainer, "Image Width:" );
+ newImageHeightText = createImageInfo( newImageInfoContainer, "Image Height:" );
+
+ Composite newImageSelectContainer = createImageInfoContainer( newImageContainer );
+ newImageFilenameText = new Text( newImageSelectContainer, SWT.SINGLE | SWT.BORDER );
+ GridData gd = new GridData( GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL );
+ newImageFilenameText.setLayoutData( gd );
+ newImageFilenameText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ updateNewImageGroup();
+ }
+ } );
+ newImageBrowseButton = createButton( newImageSelectContainer, "Browse..." );
+ newImageBrowseButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent event )
+ {
+ FileDialog fileDialog = new FileDialog( ImageDialog.this.getShell(), SWT.OPEN );
+ fileDialog.setText( "Select Image" );
+ // fileDialog.setFilterExtensions(IMAGE_FILE_EXTENSIONS);
+ fileDialog.setFileName( new File( newImageFilenameText.getText() ).getName() );
+ fileDialog.setFilterPath( new File( newImageFilenameText.getText() ).getParent() );
+ String returnedFileName = fileDialog.open();
+ if ( returnedFileName != null )
+ {
+ newImageFilenameText.setText( returnedFileName );
+ }
+ }
+ } );
+
+ this.newTab = new TabItem( this.tabFolder, SWT.NONE );
+ this.newTab.setText( "New Image" );
+ this.newTab.setControl( newImageContainer );
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ private void updateCurrentImageGroup()
+ {
+
+ if ( currentTab != null )
+ {
+
+ if ( currentImage != null && !currentImage.isDisposed() )
+ {
+ currentImage.dispose();
+ currentImage = null;
+ }
+
+ if ( currentImageRawData != null && currentImageRawData.length > 0 )
+ {
+ try
+ {
+ ImageData imageData = new ImageData( new ByteArrayInputStream( currentImageRawData ) );
+ currentImage = new Image( getShell().getDisplay(), resizeImage( imageData ) );
+ currentImageLabel.setText( "" );
+ currentImageLabel.setImage( currentImage );
+ currentImageTypeText.setText( getImageType( imageData.type ) );
+ currentImageSizeText.setText( getSizeString( currentImageRawData.length ) );
+ currentImageWidthText.setText( imageData.width + " Pixel" );
+ currentImageHeightText.setText( imageData.height + " Pixel" );
+ }
+ catch ( SWTException swte )
+ {
+ currentImageLabel.setImage( null );
+ currentImageLabel.setText( " Unsupported format " );
+ currentImageTypeText.setText( "Unsupported format" );
+ currentImageSizeText.setText( getSizeString( currentImageRawData.length ) );
+ currentImageWidthText.setText( "-" );
+ currentImageHeightText.setText( "-" );
+ }
+ // currentImageGroup.setVisible(true);
+ }
+ else
+ {
+ currentImageLabel.setImage( null );
+ currentImageLabel.setText( " No Image " );
+ currentImageTypeText.setText( "No Image" );
+ currentImageSizeText.setText( "-" );
+ currentImageWidthText.setText( "-" );
+ currentImageHeightText.setText( "-" );
+ }
+
+ currentImageSaveButton.setEnabled( currentImageRawData != null && currentImageRawData.length > 0 );
+
+ // super.initializeBounds();
+ }
+ }
+
+
+ private void updateNewImageGroup()
+ {
+
+ if ( newImage != null && !newImage.isDisposed() )
+ {
+ newImage.dispose();
+ newImage = null;
+ }
+
+ if ( !"".equals( newImageFilenameText.getText() ) )
+ {
+ try
+ {
+ File file = new File( newImageFilenameText.getText() );
+ FileInputStream in = new FileInputStream( file );
+ ByteArrayOutputStream out = new ByteArrayOutputStream( ( int ) file.length() );
+ byte[] buf = new byte[4096];
+ int len;
+ while ( ( len = in.read( buf ) ) > 0 )
+ {
+ out.write( buf, 0, len );
+ }
+ this.newImageRawData = out.toByteArray();
+ out.close();
+ in.close();
+ }
+ catch ( FileNotFoundException e )
+ {
+ newImageRawData = null;
+ newImageLabel.setImage( null );
+ newImageLabel.setText( " Error: File not found " );
+ newImageTypeText.setText( "-" );
+ newImageSizeText.setText( "-" );
+ newImageWidthText.setText( "-" );
+ newImageHeightText.setText( "-" );
+ }
+ catch ( IOException e )
+ {
+ newImageRawData = null;
+ newImageLabel.setImage( null );
+ newImageLabel.setText( " Error: Can't read file (" + e.getMessage() + ") " );
+ newImageTypeText.setText( "-" );
+ newImageSizeText.setText( "-" );
+ newImageWidthText.setText( "-" );
+ newImageHeightText.setText( "-" );
+ }
+ }
+ else
+ {
+ newImageRawData = null;
+ newImageLabel.setImage( null );
+ newImageLabel.setText( " No image selected " );
+ newImageTypeText.setText( "-" );
+ newImageSizeText.setText( "-" );
+ newImageWidthText.setText( "-" );
+ newImageHeightText.setText( "-" );
+ }
+
+ if ( newImageRawData != null && newImageRawData.length > 0 )
+ {
+ try
+ {
+ ImageData imageData = new ImageData( new ByteArrayInputStream( newImageRawData ) );
+ newImage = new Image( getShell().getDisplay(), resizeImage( imageData ) );
+ newImageLabel.setImage( newImage );
+ newImageTypeText.setText( getImageType( imageData.type ) );
+ if ( imageData.type != requiredImageType )
+ {
+ newImageTypeText.setText( newImageTypeText.getText() + " (will be converted to "
+ + getImageType( this.requiredImageType ) + ")" );
+ }
+ newImageSizeText.setText( getSizeString( newImageRawData.length ) );
+ newImageWidthText.setText( imageData.width + " Pixel" );
+ newImageHeightText.setText( imageData.height + " Pixel" );
+ }
+ catch ( SWTException swte )
+ {
+ newImageLabel.setImage( null );
+ newImageLabel.setText( " Unsupported format " );
+ newImageTypeText.setText( "Unsupported format" );
+ newImageSizeText.setText( getSizeString( newImageRawData.length ) );
+ newImageWidthText.setText( "-" );
+ newImageHeightText.setText( "-" );
+ }
+ }
+
+ if ( okButton != null )
+ {
+ okButton.setEnabled( newImage != null );
+ }
+
+ newImageLabel.getParent().layout();
+ newImageTypeText.getParent().layout();
+ // newImageGroup.layout();
+ // super.initializeBounds();
+
+ }
+
+
+ private void updateTabFolder()
+ {
+ if ( currentImageSaveButton != null )
+ {
+ if ( tabFolder.getSelectionIndex() == CURRENT_TAB )
+ {
+ currentImageSaveButton.setFocus();
+ }
+ updateCurrentImageGroup();
+ }
+
+ if ( newImageBrowseButton != null )
+ {
+ if ( tabFolder.getSelectionIndex() == NEW_TAB || currentImageSaveButton == null )
+ {
+ newImageBrowseButton.setFocus();
+ }
+ updateNewImageGroup();
+ }
+ }
+
+
+ private ImageData resizeImage( ImageData imageData )
+ {
+ double widthScaleFactor = 1.0;
+ if ( imageData.width > MAX_WIDTH )
+ {
+ widthScaleFactor = ( double ) MAX_WIDTH / imageData.width;
+ }
+ double heightScaleFactor = 1.0;
+ if ( imageData.height > MAX_HEIGHT )
+ {
+ heightScaleFactor = ( double ) MAX_HEIGHT / imageData.height;
+ }
+
+ if ( heightScaleFactor < widthScaleFactor )
+ {
+ imageData = imageData.scaledTo(
+ convertHorizontalDLUsToPixels( ( int ) ( imageData.width * heightScaleFactor ) ),
+ convertHorizontalDLUsToPixels( ( int ) ( imageData.height * heightScaleFactor ) ) );
+ }
+ else
+ {
+ imageData = imageData.scaledTo(
+ convertHorizontalDLUsToPixels( ( int ) ( imageData.width * widthScaleFactor ) ),
+ convertHorizontalDLUsToPixels( ( int ) ( imageData.height * widthScaleFactor ) ) );
+ }
+
+ return imageData;
+ }
+
+
+ private Label createImageLabel( Composite parent )
+ {
+ Composite labelComposite = new Composite( parent, SWT.BORDER );
+ GridLayout gl = new GridLayout( 1, true );
+ labelComposite.setLayout( gl );
+ GridData gd = new GridData( GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL );
+ gd.widthHint = MAX_WIDTH;
+ gd.heightHint = MAX_HEIGHT;
+ labelComposite.setLayoutData( gd );
+ labelComposite.setBackground( getShell().getDisplay().getSystemColor( SWT.COLOR_WIDGET_NORMAL_SHADOW ) );
+
+ Label imageLabel = new Label( labelComposite, SWT.CENTER );
+ gd = new GridData( SWT.CENTER, SWT.CENTER, true, true );
+ imageLabel.setLayoutData( gd );
+ return imageLabel;
+ }
+
+
+ private Composite createImageInfoContainer( Composite parent )
+ {
+ Composite imageInfoContainer = new Composite( parent, SWT.NONE );
+ GridLayout gl = new GridLayout( 2, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ imageInfoContainer.setLayout( gl );
+ imageInfoContainer.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ return imageInfoContainer;
+ }
+
+
+ private Text createImageInfo( Composite parent, String label )
+ {
+ BaseWidgetUtils.createLabel( parent, label, 1 );
+ Text text = BaseWidgetUtils.createLabeledText( parent, "", 1 );
+ return text;
+ }
+
+
+ private Button createButton( Composite parent, String label )
+ {
+ Button button = BaseWidgetUtils.createButton( parent, label, 1 );
+ return button;
+ }
+
+
+ public static String getSizeString( int length )
+ {
+ if ( length > 1000000 )
+ return ( length / 1000000 ) + " MB (" + length + " bytes)";
+ else if ( length > 1000 )
+ return ( length / 1000 ) + " KB (" + length + " bytes)";
+ else
+ return length + " bytes";
+ }
+
+
+ public static String getImageInfo( byte[] imageRawData )
+ {
+
+ if ( imageRawData == null )
+ {
+ return "NULL";
+ }
+
+ String text = "Image (" + imageRawData.length + " Bytes)";
+ try
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream( imageRawData );
+ ImageData imageData = new ImageData( bais );
+
+ String typePrefix = getImageType( imageData.type );
+ if ( !"".equals( typePrefix ) )
+ typePrefix += "-";
+
+ text = typePrefix + "Image (" + imageData.width + "x" + imageData.height + " Pixel, " + imageRawData.length
+ + " Bytes)";
+ }
+ catch ( SWTException swte )
+ {
+ text = "Invalid Image (" + imageRawData.length + " Bytes)";
+ }
+ return text;
+ }
+
+
+ public static String getImageType( int swtCode )
+ {
+ String type = "";
+ if ( swtCode == SWT.IMAGE_JPEG )
+ type = "JPEG";
+ else if ( swtCode == SWT.IMAGE_GIF )
+ type = "GIF";
+ else if ( swtCode == SWT.IMAGE_PNG )
+ type = "PNG";
+ else if ( swtCode == SWT.IMAGE_BMP || swtCode == SWT.IMAGE_BMP_RLE )
+ type = "BMP";
+ return type;
+ }
+
+
+ /**
+ *
+ *
+ * @return Returns the image data in required format or null.
+ */
+ public byte[] getNewImageRawData()
+ {
+ return this.newImageRawDataInRequiredFormat;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/LdifEntryEditorDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/LdifEntryEditorDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/LdifEntryEditorDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/LdifEntryEditorDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,230 @@
+/*
+ * 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.ldapstudio.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.core.internal.model.DummyConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.model.NameException;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.core.utils.ModelConverter;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidget;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetActionGroup;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetConfiguration;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetUniversalListener;
+import org.apache.directory.ldapstudio.browser.ui.wizards.NewEntryAttributesWizardPageActionGroup;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class LdifEntryEditorDialog extends Dialog
+{
+
+ public static final String DIALOG_TITLE = "LDIF Entry Editor";
+
+ public static final int MAX_WIDTH = 450;
+
+ public static final int MAX_HEIGHT = 250;
+
+ private IConnection connection;
+
+ private LdifRecord ldifRecord;
+
+ private IEntry entry;
+
+ private EntryEditorWidgetConfiguration configuration;
+
+ private EntryEditorWidgetActionGroup actionGroup;
+
+ private EntryEditorWidget mainWidget;
+
+ private EntryEditorWidgetUniversalListener universalListener;
+
+
+ public LdifEntryEditorDialog( Shell parentShell, IConnection connection, LdifContentRecord ldifRecord )
+ {
+ this( parentShell, connection, ldifRecord, null );
+ }
+
+
+ public LdifEntryEditorDialog( Shell parentShell, IConnection connection, LdifChangeAddRecord ldifRecord )
+ {
+ this( parentShell, connection, ldifRecord, null );
+ }
+
+
+ private LdifEntryEditorDialog( Shell parentShell, IConnection connection, LdifRecord ldifRecord, String s )
+ {
+ super( parentShell );
+ setShellStyle( getShellStyle() | SWT.RESIZE );
+ this.ldifRecord = ldifRecord;
+
+ this.connection = new DummyConnection( ( connection != null && connection.getSchema() != null ) ? connection
+ .getSchema() : Schema.DEFAULT_SCHEMA );
+ }
+
+
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( DIALOG_TITLE );
+ shell.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_BROWSER_LDIFEDITOR ) );
+ }
+
+
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+ createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+
+ getShell().update();
+ getShell().layout( true, true );
+ }
+
+
+ protected void buttonPressed( int buttonId )
+ {
+
+ if ( IDialogConstants.OK_ID == buttonId )
+ {
+ if ( this.ldifRecord instanceof LdifContentRecord )
+ {
+ this.ldifRecord = ModelConverter.entryToLdifContentRecord( entry );
+ }
+ else if ( this.ldifRecord instanceof LdifChangeAddRecord )
+ {
+ this.ldifRecord = ModelConverter.entryToLdifChangeAddRecord( entry );
+ }
+ }
+
+ super.buttonPressed( buttonId );
+ }
+
+
+ public void create()
+ {
+ super.create();
+ // this.actionGroup.activateGlobalActionHandlers();
+ }
+
+
+ public boolean close()
+ {
+ boolean returnValue = super.close();
+ if ( returnValue )
+ {
+ this.dispose();
+ }
+ return returnValue;
+ }
+
+
+ public void dispose()
+ {
+ if ( this.configuration != null )
+ {
+ this.universalListener.dispose();
+ this.universalListener = null;
+ this.mainWidget.dispose();
+ this.mainWidget = null;
+ this.actionGroup.deactivateGlobalActionHandlers();
+ this.actionGroup.dispose();
+ this.actionGroup = null;
+ this.configuration.dispose();
+ this.configuration = null;
+ }
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+
+ // create configuration
+ this.configuration = new EntryEditorWidgetConfiguration();
+
+ // create main widget
+ this.mainWidget = new EntryEditorWidget( this.configuration );
+ this.mainWidget.createWidget( composite );
+ this.mainWidget.getViewer().getTree().setFocus();
+
+ // create actions
+ this.actionGroup = new NewEntryAttributesWizardPageActionGroup( this.mainWidget, this.configuration );
+ this.actionGroup.fillToolBar( this.mainWidget.getToolBarManager() );
+ this.actionGroup.fillMenu( this.mainWidget.getMenuManager() );
+ this.actionGroup.fillContextMenu( this.mainWidget.getContextMenuManager() );
+ this.actionGroup.activateGlobalActionHandlers();
+
+ // create the listener
+ this.universalListener = new EntryEditorWidgetUniversalListener( this.mainWidget.getViewer(), this.actionGroup
+ .getOpenDefaultEditorAction() );
+
+ try
+ {
+
+ if ( ldifRecord instanceof LdifContentRecord )
+ {
+ entry = ModelConverter.ldifContentRecordToEntry( ( LdifContentRecord ) ldifRecord, connection );
+ }
+ else if ( ldifRecord instanceof LdifChangeAddRecord )
+ {
+ entry = ModelConverter.ldifChangeAddRecordToEntry( ( LdifChangeAddRecord ) ldifRecord, connection );
+ }
+
+ if ( entry != null )
+ {
+ this.mainWidget.getViewer().setInput( entry );
+ }
+
+ }
+ catch ( ModelModificationException e )
+ {
+ e.printStackTrace();
+ }
+ catch ( NameException e )
+ {
+ e.printStackTrace();
+ }
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ public LdifRecord getLdifRecord()
+ {
+ return ldifRecord;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/MoveEntriesDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/MoveEntriesDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/MoveEntriesDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/MoveEntriesDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,148 @@
+/*
+ * 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.ldapstudio.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.DnBuilderWidget;
+import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyEvent;
+import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyListener;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class MoveEntriesDialog extends Dialog implements WidgetModifyListener
+{
+
+ public static final String DIALOG_TITLE = "Move Entries";
+
+ private IEntry[] entries;
+
+ private DnBuilderWidget dnBuilderWidget;
+
+ private Button simulateMoveButton;
+
+ private Button okButton;
+
+ private DN parentDn;
+
+ private boolean simulateMove;
+
+
+ public MoveEntriesDialog( Shell parentShell, IEntry[] entries )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ this.entries = entries;
+ this.parentDn = null;
+ }
+
+
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( DIALOG_TITLE );
+ }
+
+
+ public boolean close()
+ {
+ this.dnBuilderWidget.removeWidgetModifyListener( this );
+ this.dnBuilderWidget.dispose();
+ return super.close();
+ }
+
+
+ protected void okPressed()
+ {
+ this.parentDn = this.dnBuilderWidget.getParentDn();
+ this.simulateMove = this.simulateMoveButton.getSelection();
+
+ this.dnBuilderWidget.saveDialogSettings();
+
+ super.okPressed();
+ }
+
+
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
+ createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 3 / 2;
+ composite.setLayoutData( gd );
+
+ BaseWidgetUtils.createLabel( composite,
+ "Please enter/select the parent DN where the selected entries should be moved to.", 1 );
+
+ this.dnBuilderWidget = new DnBuilderWidget( false, true );
+ this.dnBuilderWidget.addWidgetModifyListener( this );
+ this.dnBuilderWidget.createContents( composite );
+ this.dnBuilderWidget.setInput( this.entries[0].getConnection(), null, null, this.entries[0].getDn()
+ .getParentDn() );
+
+ this.simulateMoveButton = BaseWidgetUtils.createCheckbox( composite,
+ "Simulate subtree moving by searching/adding/deleting recursively", 1 );
+ this.simulateMoveButton.setSelection( false );
+ this.simulateMoveButton.setEnabled( false );
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ public void widgetModified( WidgetModifyEvent event )
+ {
+ if ( this.okButton != null )
+ {
+ this.okButton.setEnabled( this.dnBuilderWidget.getParentDn() != null );
+ }
+ }
+
+
+ public DN getParentDn()
+ {
+ return this.parentDn;
+ }
+
+
+ public boolean isSimulateMove()
+ {
+ return simulateMove;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/MultivaluedDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/MultivaluedDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/MultivaluedDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/MultivaluedDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,334 @@
+/*
+ * 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.ldapstudio.browser.ui.dialogs;
+
+
+import java.util.Iterator;
+
+import org.apache.directory.ldapstudio.browser.core.events.AttributeDeletedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EmptyValueAddedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EmptyValueDeletedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.events.ModelModifier;
+import org.apache.directory.ldapstudio.browser.core.events.ValueAddedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.ValueDeletedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.ValueModifiedEvent;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Attribute;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierachie;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidget;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetActionGroup;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetConfiguration;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetUniversalListener;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.OpenDefaultEditorAction;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class MultivaluedDialog extends Dialog implements ModelModifier
+{
+
+ public static final String DIALOG_TITLE = "Multivalued Editor";
+
+ public static final int MAX_WIDTH = 450;
+
+ public static final int MAX_HEIGHT = 250;
+
+ private AttributeHierachie attributeHierarchie;
+
+ private EntryEditorWidgetConfiguration configuration;
+
+ private EntryEditorWidgetActionGroup actionGroup;
+
+ private EntryEditorWidget mainWidget;
+
+ private MultiValuedEntryEditorUniversalListener universalListener;
+
+
+ public MultivaluedDialog( Shell parentShell, AttributeHierachie attributeHierarchie )
+ {
+ super( parentShell );
+ setShellStyle( getShellStyle() | SWT.RESIZE );
+ this.attributeHierarchie = attributeHierarchie;
+ }
+
+
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( DIALOG_TITLE );
+ shell.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_MULTIVALUEDEDITOR ) );
+ }
+
+
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ createButton( parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL, false );
+
+ getShell().update();
+ getShell().layout( true, true );
+ }
+
+
+ protected void buttonPressed( int buttonId )
+ {
+ if ( IDialogConstants.CLOSE_ID == buttonId )
+ {
+ close();
+ }
+ else
+ {
+ super.buttonPressed( buttonId );
+ }
+ }
+
+
+ public int open()
+ {
+ this.dialogOpened();
+ return super.open();
+ }
+
+
+ public boolean close()
+ {
+ boolean returnValue = super.close();
+ if ( returnValue )
+ {
+ this.dispose();
+ this.dialogClosed();
+ }
+ return returnValue;
+ }
+
+
+ public void dispose()
+ {
+ if ( this.configuration != null )
+ {
+ this.universalListener.dispose();
+ this.universalListener = null;
+ this.mainWidget.dispose();
+ this.mainWidget = null;
+ this.actionGroup.deactivateGlobalActionHandlers();
+ this.actionGroup.dispose();
+ this.actionGroup = null;
+ this.configuration.dispose();
+ this.configuration = null;
+ }
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+
+ // create configuration
+ this.configuration = new EntryEditorWidgetConfiguration();
+
+ // create main widget
+ this.mainWidget = new EntryEditorWidget( this.configuration );
+ this.mainWidget.createWidget( composite );
+ this.mainWidget.getViewer().setInput( attributeHierarchie );
+ this.mainWidget.getViewer().getTree().setFocus();
+
+ // create actions
+ this.actionGroup = new EntryEditorWidgetActionGroup( this.mainWidget, this.configuration );
+ this.actionGroup.fillToolBar( this.mainWidget.getToolBarManager() );
+ this.actionGroup.fillMenu( this.mainWidget.getMenuManager() );
+ this.actionGroup.fillContextMenu( this.mainWidget.getContextMenuManager() );
+ this.actionGroup.activateGlobalActionHandlers();
+
+ // create the listener
+ this.universalListener = new MultiValuedEntryEditorUniversalListener( this.mainWidget.getViewer(),
+ this.actionGroup.getOpenDefaultEditorAction() );
+
+ // start edit mode if an empty value exists
+ for ( Iterator it = attributeHierarchie.iterator(); it.hasNext(); )
+ {
+ IAttribute attribute = ( IAttribute ) it.next();
+ IValue[] values = attribute.getValues();
+ for ( int i = 0; i < values.length; i++ )
+ {
+ IValue value = values[i];
+ if ( value.isEmpty() )
+ {
+ this.mainWidget.getViewer().setSelection( new StructuredSelection( value ), true );
+ if ( this.actionGroup.getOpenDefaultEditorAction().isEnabled() )
+ {
+ this.actionGroup.getOpenDefaultEditorAction().run();
+ break;
+ }
+ }
+ }
+ }
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ private void dialogOpened()
+ {
+ if ( this.attributeHierarchie.getAttribute().getValueSize() == 0 )
+ {
+ this.attributeHierarchie.getAttribute().addEmptyValue( this );
+ }
+ }
+
+
+ private void dialogClosed()
+ {
+
+ for ( Iterator it = attributeHierarchie.iterator(); it.hasNext(); )
+ {
+ IAttribute attribute = ( IAttribute ) it.next();
+ if ( attribute != null )
+ {
+
+ // remove empty values
+ IValue[] values = attribute.getValues();
+ for ( int i = 0; i < values.length; i++ )
+ {
+ if ( values[i].isEmpty() )
+ {
+ attribute.deleteEmptyValue( this );
+ }
+ }
+
+ // are all values deleted?
+ if ( attribute.getValueSize() == 0 )
+ {
+ try
+ {
+ attribute.getEntry().deleteAttribute( attribute, this );
+ }
+ catch ( ModelModificationException e )
+ {
+ }
+ // new DeleteAttributeValueCommand(attribute).execute();
+ }
+ }
+ }
+
+ }
+
+ class MultiValuedEntryEditorUniversalListener extends EntryEditorWidgetUniversalListener
+ {
+
+ public MultiValuedEntryEditorUniversalListener( TreeViewer treeViewer, OpenDefaultEditorAction startEditAction )
+ {
+ super( treeViewer, startEditAction );
+ }
+
+
+ public void entryUpdated( EntryModificationEvent event )
+ {
+
+ if ( this.viewer == null || this.viewer.getTree() == null || this.viewer.getTree().isDisposed() )
+ {
+ return;
+ }
+
+ if ( this.viewer.isCellEditorActive() )
+ this.viewer.cancelEditing();
+
+ // set new input because attributes are newly created after a
+ // modification
+ IEntry entry = attributeHierarchie.getEntry();
+ String attributeDescription = attributeHierarchie.getAttributeDescription();
+ attributeHierarchie = entry.getAttributeWithSubtypes( attributeDescription );
+ if ( attributeHierarchie == null )
+ {
+ EventRegistry.suspendEventFireingInCurrentThread();
+ try
+ {
+ IAttribute attribute = new Attribute( entry, attributeDescription );
+ entry.addAttribute( attribute, null );
+ attribute.addEmptyValue( null );
+ }
+ catch ( ModelModificationException e )
+ {
+ }
+ EventRegistry.resumeEventFireingInCurrentThread();
+ attributeHierarchie = entry.getAttributeWithSubtypes( attributeDescription );
+ }
+ this.viewer.setInput( attributeHierarchie );
+ this.viewer.refresh();
+
+ // select added/modified value
+ if ( event instanceof ValueAddedEvent )
+ {
+ ValueAddedEvent vaEvent = ( ValueAddedEvent ) event;
+ this.viewer.setSelection( new StructuredSelection( vaEvent.getAddedValue() ), true );
+ this.viewer.refresh();
+ }
+ else if ( event instanceof ValueModifiedEvent )
+ {
+ ValueModifiedEvent vmEvent = ( ValueModifiedEvent ) event;
+ this.viewer.setSelection( new StructuredSelection( vmEvent.getNewValue() ), true );
+ }
+ else if ( event instanceof ValueDeletedEvent )
+ {
+ ValueDeletedEvent vdEvent = ( ValueDeletedEvent ) event;
+ if ( vdEvent.getDeletedValue().getAttribute().getValueSize() > 0 )
+ {
+ this.viewer.setSelection( new StructuredSelection( vdEvent.getDeletedValue().getAttribute()
+ .getValues()[0] ), true );
+ }
+ }
+ else if ( event instanceof EmptyValueAddedEvent )
+ {
+ viewer.refresh();
+ EmptyValueAddedEvent evaEvent = ( EmptyValueAddedEvent ) event;
+ viewer.setSelection( new StructuredSelection( evaEvent.getAddedValue() ), true );
+ if ( startEditAction.isEnabled() )
+ startEditAction.run();
+ }
+ else if ( event instanceof EmptyValueDeletedEvent )
+ {
+ EmptyValueDeletedEvent evdEvent = ( EmptyValueDeletedEvent ) event;
+ if ( viewer.getSelection().isEmpty() && evdEvent.getDeletedValue().getAttribute().getValueSize() > 0 )
+ viewer.setSelection( new StructuredSelection(
+ evdEvent.getDeletedValue().getAttribute().getValues()[0] ), true );
+ }
+ else if ( event instanceof AttributeDeletedEvent )
+ {
+
+ }
+ }
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,120 @@
+/*
+ * 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.ldapstudio.browser.ui.dialogs;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class ObjectClassDialog extends Dialog
+{
+
+ public static final String DIALOG_TITLE = "Object Class Editor";
+
+ public static final double MAX_WIDTH = 250.0;
+
+ public static final double MAX_HEIGHT = 250.0;
+
+ private Schema schema;
+
+ private String initialValue;
+
+ private Combo objectClassCombo;
+
+ private String returnValue;
+
+
+ public ObjectClassDialog( Shell parentShell, Schema schema, String initialValue )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ this.initialValue = initialValue;
+ this.schema = schema;
+ this.returnValue = null;
+ }
+
+
+ public boolean close()
+ {
+ return super.close();
+ }
+
+
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( DIALOG_TITLE );
+ shell.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_TEXTEDITOR ) );
+ }
+
+
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ super.createButtonsForButtonBar( parent );
+ }
+
+
+ protected void okPressed()
+ {
+ this.returnValue = this.objectClassCombo.getText();
+ super.okPressed();
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+ // create composite
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+ composite.setLayoutData( gd );
+
+ // combo widget
+ String[] allOcNames = schema.getObjectClassDescriptionNames();
+ Arrays.sort( allOcNames );
+ objectClassCombo = BaseWidgetUtils.createReadonlyCombo( composite, allOcNames, 0, 1 );
+ objectClassCombo.setText( initialValue );
+ objectClassCombo.setVisibleItemCount( 20 );
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ public String getObjectClass()
+ {
+ return this.returnValue;
+ }
+}