You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/04/09 11:59:22 UTC
svn commit: r526698 [3/5] - in
/directory/ldapstudio/trunk/ldapstudio-ldifeditor: ./ META-INF/ resources/
resources/icons/ resources/templates/ src/ src/main/ src/main/java/
src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/director...
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifEditorContributor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifEditorContributor.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifEditorContributor.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifEditorContributor.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,90 @@
+/*
+ * 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.ldifeditor.editor;
+
+
+import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.texteditor.RetargetTextEditorAction;
+
+
+/**
+ * This class manages the installation and removal of global actions for the LDIF Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdifEditorContributor extends BasicTextEditorActionContributor
+{
+
+ private static final String CONTENTASSIST_ACTION = "org.apache.directory.ldapstudio.browser.ContentAssist";
+
+ private RetargetTextEditorAction contentAssist;
+
+
+ /**
+ * Creates a new instance of LdifEditorContributor.
+ */
+ public LdifEditorContributor()
+ {
+ super();
+
+ contentAssist = new RetargetTextEditorAction( LdifEditorActivator.getDefault().getResourceBundle(),
+ "ContentAssistProposal." );
+ contentAssist.setActionDefinitionId( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setActiveEditor( IEditorPart part )
+ {
+ super.setActiveEditor( part );
+ ITextEditor editor = ( part instanceof ITextEditor ) ? ( ITextEditor ) part : null;
+ contentAssist.setAction( getAction( editor, CONTENTASSIST_ACTION ) );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init( IActionBars bars, IWorkbenchPage page )
+ {
+ super.init( bars, page );
+ bars.setGlobalActionHandler( CONTENTASSIST_ACTION, contentAssist );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose()
+ {
+ setActiveEditor( null );
+ super.dispose();
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifOutlinePage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifOutlinePage.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifOutlinePage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifOutlinePage.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,447 @@
+/*
+ * 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.ldifeditor.editor;
+
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeDeleteRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModDnRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.utils.Utils;
+import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator;
+import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
+
+
+/**
+ * This class implements the Outline Page for LDIF.
+ * It used to display LDIF files and records.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdifOutlinePage extends ContentOutlinePage
+{
+ /** The editor it is attached to */
+ private LdifEditor ldifEditor;
+
+
+ /**
+ * Creates a new instance of LdifOutlinePage.
+ *
+ * @param ldifEditor
+ * the editor the Outline page is attached to
+ */
+ public LdifOutlinePage( LdifEditor ldifEditor )
+ {
+ this.ldifEditor = ldifEditor;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.views.contentoutline.ContentOutlinePage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl( Composite parent )
+ {
+ super.createControl( parent );
+
+ final TreeViewer treeViewer = getTreeViewer();
+ treeViewer.setLabelProvider( new LdifLabelProvider() );
+ treeViewer.setContentProvider( new LdifContentProvider() );
+ // treeViewer.setAutoExpandLevel(1);
+
+ treeViewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ if ( !event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection )
+ {
+ Object element = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+
+ if ( element instanceof LdifRecord )
+ {
+ LdifRecord ldifRecord = ( LdifRecord ) element;
+ ldifEditor.selectAndReveal( ldifRecord.getDnLine().getOffset(), ldifRecord.getDnLine()
+ .getLength() );
+ }
+ else if ( element instanceof List )
+ {
+ List list = ( List ) element;
+ if ( !list.isEmpty() && list.get( 0 ) instanceof LdifAttrValLine )
+ {
+ LdifAttrValLine line = ( LdifAttrValLine ) list.get( 0 );
+ ldifEditor.selectAndReveal( line.getOffset(), line.getRawAttributeDescription()
+ .length() );
+ }
+ }
+ else if ( element instanceof LdifAttrValLine )
+ {
+ LdifAttrValLine line = ( LdifAttrValLine ) element;
+ ldifEditor.selectAndReveal( line.getOffset() + line.getRawAttributeDescription().length()
+ + line.getRawValueType().length(), line.getRawValue().length() );
+ }
+ else if ( element instanceof LdifModSpec )
+ {
+ LdifModSpec modSpec = ( LdifModSpec ) element;
+ ldifEditor.selectAndReveal( modSpec.getOffset(), modSpec.getModSpecType().getLength() );
+ }
+ }
+ }
+ } );
+
+ treeViewer.addDoubleClickListener( new IDoubleClickListener()
+ {
+ public void doubleClick( DoubleClickEvent event )
+ {
+ if ( event.getSelection() instanceof IStructuredSelection )
+ {
+ Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+ if ( treeViewer.getExpandedState( obj ) )
+ treeViewer.collapseToLevel( obj, 1 );
+ else if ( ( ( ITreeContentProvider ) treeViewer.getContentProvider() ).hasChildren( obj ) )
+ treeViewer.expandToLevel( obj, 1 );
+ }
+ }
+ } );
+
+ this.refresh();
+ }
+
+
+ /**
+ * Refreshes this viewer starting with the given element.
+ *
+ * @param element
+ * the element
+ */
+ public void refresh( Object element )
+ {
+ final TreeViewer treeViewer = getTreeViewer();
+ if ( treeViewer != null && treeViewer.getTree() != null && !treeViewer.getTree().isDisposed() )
+ {
+ treeViewer.refresh( element );
+ }
+ }
+
+
+ /**
+ * Refreshes this viewer completely with information freshly obtained from this viewer's model.
+ */
+ public void refresh()
+ {
+ final TreeViewer treeViewer = getTreeViewer();
+
+ if ( treeViewer != null && treeViewer.getTree() != null && !treeViewer.getTree().isDisposed() )
+ {
+ // ISelection selection = treeViewer.getSelection();
+ // Object[] expandedElements = treeViewer.getExpandedElements();
+
+ if ( !treeViewer.getTree().isEnabled() )
+ {
+ treeViewer.getTree().setEnabled( true );
+ }
+
+ if ( ldifEditor != null )
+ {
+ if ( treeViewer.getInput() != ldifEditor.getLdifModel() )
+ {
+ treeViewer.setInput( ldifEditor.getLdifModel() );
+ }
+ }
+
+ treeViewer.refresh();
+
+ // treeViewer.setSelection(selection);
+ // treeViewer.setExpandedElements(expandedElements);
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.Page#dispose()
+ */
+ public void dispose()
+ {
+ super.dispose();
+ if ( ldifEditor != null )
+ {
+ ldifEditor.outlinePageClosed();
+ ldifEditor = null;
+ }
+ }
+
+ /**
+ * This class implements the ContentProvider used for the LDIF Outline View
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+ private static class LdifContentProvider implements ITreeContentProvider
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ public Object[] getChildren( Object element )
+ {
+ // file --> records
+ if ( element instanceof LdifFile )
+ {
+ LdifFile ldifFile = ( LdifFile ) element;
+ return ldifFile.getRecords();
+ }
+
+ // record --> Array of List of AttrValLine
+ else if ( element instanceof LdifContentRecord )
+ {
+ LdifContentRecord record = ( LdifContentRecord ) element;
+ return getUniqueAttrValLineArray( record.getAttrVals() );
+ }
+ else if ( element instanceof LdifChangeAddRecord )
+ {
+ LdifChangeAddRecord record = ( LdifChangeAddRecord ) element;
+ return getUniqueAttrValLineArray( record.getAttrVals() );
+ }
+ else if ( element instanceof LdifChangeModifyRecord )
+ {
+ LdifChangeModifyRecord record = ( LdifChangeModifyRecord ) element;
+ return record.getModSpecs();
+ }
+ else if ( element instanceof LdifChangeModDnRecord )
+ {
+ return new Object[0];
+ }
+ else if ( element instanceof LdifChangeDeleteRecord )
+ {
+ return new Object[0];
+ }
+
+ // List of AttrValLine --> Array of AttrValLine
+ else if ( element instanceof List && ( ( List ) element ).get( 0 ) instanceof LdifAttrValLine )
+ {
+ List list = ( List ) element;
+ return list.toArray();
+ }
+ else if ( element instanceof LdifModSpec )
+ {
+ LdifModSpec modSpec = ( LdifModSpec ) element;
+ return modSpec.getAttrVals();
+ }
+
+ else
+ {
+ return new Object[0];
+ }
+ }
+
+
+ /**
+ * Returns a unique line of attribute values from an array of attribute value lines
+ *
+ * @param lines
+ * the attribute value lines
+ * @return
+ * a unique line of attribute values from an array of attribute values lines
+ */
+ private Object[] getUniqueAttrValLineArray( LdifAttrValLine[] lines )
+ {
+ Map uniqueAttrMap = new LinkedHashMap();
+ for ( int i = 0; i < lines.length; i++ )
+ {
+ if ( !uniqueAttrMap.containsKey( lines[i].getUnfoldedAttributeDescription() ) )
+ {
+ uniqueAttrMap.put( lines[i].getUnfoldedAttributeDescription(), new ArrayList() );
+ }
+ ( ( List ) uniqueAttrMap.get( lines[i].getUnfoldedAttributeDescription() ) ).add( lines[i] );
+ }
+ return uniqueAttrMap.values().toArray();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public Object getParent( Object element )
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren( Object element )
+ {
+ return getChildren( element ) != null && getChildren( element ).length > 0;
+ }
+
+
+ /* (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.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 )
+ {
+ }
+ }
+
+ /**
+ * This class implements the LabelProvider used for the LDIF Outline View
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+ private static class LdifLabelProvider extends LabelProvider
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ public String getText( Object element )
+ {
+ // Record
+ if ( element instanceof LdifRecord )
+ {
+ LdifRecord ldifRecord = ( LdifRecord ) element;
+ return ldifRecord.getDnLine().getValueAsString();
+ }
+
+ // List of AttrValLine
+ else if ( element instanceof List && ( ( List ) element ).get( 0 ) instanceof LdifAttrValLine )
+ {
+ List list = ( List ) element;
+ return ( ( LdifAttrValLine ) list.get( 0 ) ).getUnfoldedAttributeDescription() + " (" + list.size()
+ + ")";
+ }
+ else if ( element instanceof LdifModSpec )
+ {
+ LdifModSpec modSpec = ( LdifModSpec ) element;
+ return modSpec.getModSpecType().getUnfoldedAttributeDescription() + " (" + modSpec.getAttrVals().length
+ + ")";
+ }
+
+ // AttrValLine
+ else if ( element instanceof LdifAttrValLine )
+ {
+ LdifAttrValLine line = ( LdifAttrValLine ) element;
+ return Utils.getShortenedString( line.getValueAsString(), 20 );
+ }
+
+ else
+ {
+ return "";
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
+ */
+ public Image getImage( Object element )
+ {
+ // Record
+ if ( element instanceof LdifContentRecord )
+ {
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_ENTRY );
+ }
+ else if ( element instanceof LdifChangeAddRecord )
+ {
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ADD );
+ }
+ else if ( element instanceof LdifChangeModifyRecord )
+ {
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MODIFY );
+ }
+ else if ( element instanceof LdifChangeDeleteRecord )
+ {
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_DELETE );
+ }
+ else if ( element instanceof LdifChangeModDnRecord )
+ {
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_RENAME );
+ }
+
+ // List of AttrValLine
+ else if ( element instanceof List && ( ( List ) element ).get( 0 ) instanceof LdifAttrValLine )
+ {
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_ATTRIBUTE );
+ }
+ else if ( element instanceof LdifModSpec )
+ {
+ LdifModSpec modSpec = ( LdifModSpec ) element;
+ if ( modSpec.isAdd() )
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_ADD );
+ else if ( modSpec.isReplace() )
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_REPLACE );
+ else if ( modSpec.isDelete() )
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_MOD_DELETE );
+ else
+ return null;
+ }
+
+ // AttrValLine
+ else if ( element instanceof LdifAttrValLine )
+ {
+ return LdifEditorActivator.getDefault().getImage( LdifEditorConstants.IMG_LDIF_VALUE );
+ }
+
+ else
+ {
+ return null;
+ }
+ }
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifSourceViewerConfiguration.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifSourceViewerConfiguration.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/LdifSourceViewerConfiguration.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,288 @@
+/*
+ * 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.ldifeditor.editor;
+
+
+import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants;
+import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator;
+import org.apache.directory.ldapstudio.ldifeditor.editor.reconciler.LdifReconcilingStrategy;
+import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifAnnotationHover;
+import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifAutoEditStrategy;
+import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifCompletionProcessor;
+import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifDamagerRepairer;
+import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifDoubleClickStrategy;
+import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifPartitionScanner;
+import org.apache.directory.ldapstudio.ldifeditor.editor.text.LdifTextHover;
+import org.apache.directory.ldapstudio.browser.common.widgets.DialogContentAssistant;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.reconciler.MonoReconciler;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.graphics.RGB;
+
+/**
+ * This class enables the features of the editor (Syntax coloring, code completion, etc.)
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdifSourceViewerConfiguration extends SourceViewerConfiguration
+{
+ private ILdifEditor editor;
+
+ // Error hover and annotations
+ private LdifAnnotationHover annotationHover;
+
+ private LdifTextHover textHover;
+
+ // Presentation Reconciler (syntax highlight)
+ private PresentationReconciler presentationReconciler;
+
+ private LdifDamagerRepairer damagerRepairer;
+
+ // Content Assistent
+ private boolean contentAssistEnabled;
+
+ private ContentAssistant contentAssistant;
+
+ private IContentAssistProcessor contentAssistProcessor;
+
+ private LdifDoubleClickStrategy doubleClickStrategy;
+
+ // Asynchronous Reconciler (annotations)
+ private MonoReconciler reconciler;
+
+ private LdifReconcilingStrategy reconcilingStrategy;
+
+ private IAutoEditStrategy[] autoEditStrategies;
+
+
+ /**
+ * Creates a new instance of LdifSourceViewerConfiguration.
+ *
+ * @param editor
+ * @param contentAssistEnabled
+ */
+ public LdifSourceViewerConfiguration( ILdifEditor editor, boolean contentAssistEnabled )
+ {
+ super();
+ this.editor = editor;
+
+ this.contentAssistEnabled = contentAssistEnabled;
+ }
+
+
+ /**
+ * Overwrites the style set in preference store
+ *
+ * @param key
+ * the key
+ * @param rgb
+ * the color
+ * @param style
+ * the stule
+ */
+ public void setTextAttribute( String key, RGB rgb, int style )
+ {
+ damagerRepairer.setTextAttribute( key, rgb, style );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getConfiguredDocumentPartitioning( ISourceViewer sourceViewer )
+ {
+ return LdifDocumentSetupParticipant.LDIF_PARTITIONING;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getConfiguredContentTypes( ISourceViewer sourceViewer )
+ {
+ return new String[]
+ { IDocument.DEFAULT_CONTENT_TYPE, LdifPartitionScanner.LDIF_RECORD };
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ITextDoubleClickStrategy getDoubleClickStrategy( ISourceViewer sourceViewer, String contentType )
+ {
+ if ( this.doubleClickStrategy == null )
+ {
+ this.doubleClickStrategy = new LdifDoubleClickStrategy();
+ }
+ return this.doubleClickStrategy;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer )
+ {
+
+ if ( this.presentationReconciler == null )
+ {
+ this.presentationReconciler = new PresentationReconciler();
+ this.presentationReconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer ) );
+
+ damagerRepairer = new LdifDamagerRepairer( this.editor );
+
+ this.presentationReconciler.setDamager( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+ this.presentationReconciler.setRepairer( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+
+ this.presentationReconciler.setDamager( damagerRepairer, LdifPartitionScanner.LDIF_RECORD );
+ this.presentationReconciler.setRepairer( damagerRepairer, LdifPartitionScanner.LDIF_RECORD );
+ }
+
+ return this.presentationReconciler;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public IReconciler getReconciler( ISourceViewer sourceViewer )
+ {
+ if ( this.reconciler == null )
+ {
+ this.reconcilingStrategy = new LdifReconcilingStrategy( editor );
+
+ // Reconciler reconciler = new Reconciler();
+ // reconciler.setIsIncrementalReconciler(true);
+ // reconciler.setReconcilingStrategy(strategy,
+ // LdifPartitionScanner.LDIF_RECORD);
+ // reconciler.setReconcilingStrategy(strategy,
+ // IDocument.DEFAULT_CONTENT_TYPE);
+ // reconciler.setProgressMonitor(new NullProgressMonitor());
+ // reconciler.setDelay(500);
+ // return reconciler;
+
+ this.reconciler = new MonoReconciler( this.reconcilingStrategy, true );
+ this.reconciler.setProgressMonitor( new NullProgressMonitor() );
+ this.reconciler.setDelay( 500 );
+ }
+
+ return this.reconciler;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public IContentAssistant getContentAssistant( ISourceViewer sourceViewer )
+ {
+ if ( this.contentAssistEnabled )
+ {
+ if ( this.contentAssistant == null )
+ {
+ // this.contentAssistant = new ContentAssistant();
+ this.contentAssistant = new DialogContentAssistant();
+
+ this.contentAssistProcessor = new LdifCompletionProcessor( editor, contentAssistant );
+ this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor,
+ LdifPartitionScanner.LDIF_RECORD );
+ this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor,
+ IDocument.DEFAULT_CONTENT_TYPE );
+ this.contentAssistant.setDocumentPartitioning( LdifDocumentSetupParticipant.LDIF_PARTITIONING );
+
+ this.contentAssistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE );
+ this.contentAssistant.setInformationControlCreator( getInformationControlCreator( sourceViewer ) );
+
+ IPreferenceStore store = LdifEditorActivator.getDefault().getPreferenceStore();
+ this.contentAssistant.enableAutoInsert( store
+ .getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) );
+ this.contentAssistant.enableAutoActivation( store
+ .getBoolean( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) );
+ this.contentAssistant.setAutoActivationDelay( store
+ .getInt( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) );
+ // this.contentAssistant.enableAutoInsert(true);
+ // this.contentAssistant.enableAutoActivation(true);
+ // this.contentAssistant.setAutoActivationDelay(100);
+ }
+ return this.contentAssistant;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public IAnnotationHover getAnnotationHover( ISourceViewer sourceViewer )
+ {
+ if ( this.annotationHover == null )
+ {
+ this.annotationHover = new LdifAnnotationHover( this.editor );
+ }
+ return this.annotationHover;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType )
+ {
+ if ( this.textHover == null )
+ {
+ this.textHover = new LdifTextHover( this.editor );
+ }
+ return this.textHover;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public IAutoEditStrategy[] getAutoEditStrategies( ISourceViewer sourceViewer, String contentType )
+ {
+ if ( autoEditStrategies == null )
+ {
+ this.autoEditStrategies = new IAutoEditStrategy[2];
+ this.autoEditStrategies[0] = new DefaultIndentLineAutoEditStrategy();
+ this.autoEditStrategies[1] = new LdifAutoEditStrategy( this.editor );
+ }
+
+ return autoEditStrategies;
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/NonExistingLdifEditorInput.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/NonExistingLdifEditorInput.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/NonExistingLdifEditorInput.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/NonExistingLdifEditorInput.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,184 @@
+/*
+ * 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.ldifeditor.editor;
+
+
+import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants;
+import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IPathEditorInput;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.editors.text.ILocationProvider;
+
+
+/**
+ * This EditorInput is used to create a LDIF file that isn't saved yet.
+ * It is used from File->New, but also from the embedded LDIF editors
+ * in modification view, in batch operation wizard and the LDIF preference page.
+ *
+ * Inspired from org.eclipse.ui.internal.editors.text.NonExistingFileEditorInput.java
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NonExistingLdifEditorInput implements IPathEditorInput, ILocationProvider
+{
+ /** The counter to create unique names */
+ private static int counter = 0;
+
+ /** The name, displayed in Editor tab */
+ private String name;
+
+
+ /**
+ * Creates a new instance of NonExistingLdifEditorInput.
+ */
+ public NonExistingLdifEditorInput()
+ {
+ counter++;
+ name = "LDIF " + counter; //$NON-NLS-1$
+ }
+
+
+ /**
+ * As the name says, this implementations always returns false.
+ */
+ public boolean exists()
+ {
+ return false;
+ }
+
+
+ /**
+ * Returns the LDIF file image.
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return LdifEditorActivator.getDefault().getImageDescriptor( LdifEditorConstants.IMG_BROWSER_LDIFEDITOR );
+ }
+
+
+ /**
+ * Returns the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+
+ /**
+ * As the name says, this implementations always returns false.
+ */
+ public IPersistableElement getPersistable()
+ {
+ return null;
+ }
+
+
+ /**
+ * Returns the name.
+ */
+ public String getToolTipText()
+ {
+ return name;
+ }
+
+
+ /**
+ * An EditorInput must return a good ILocationProvider, otherwise
+ * the editor is not editable.
+ */
+ public Object getAdapter( Class adapter )
+ {
+ if ( ILocationProvider.class.equals( adapter ) )
+ {
+ return this;
+ }
+
+ return Platform.getAdapterManager().getAdapter( this, adapter );
+ }
+
+
+ /**
+ * This implementation returns a path that point to the plugin's
+ * state location.
+ *
+ * A valid, writeable path must be returned, otherwise the editor
+ * is not editable.
+ */
+ public IPath getPath( Object element )
+ {
+ if ( element instanceof NonExistingLdifEditorInput )
+ {
+ NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) element;
+ return input.getPath();
+ }
+
+ return null;
+ }
+
+
+ /**
+ * This implemention just compares the names
+ */
+ public boolean equals( Object o )
+ {
+ if ( o == this )
+ {
+ return true;
+ }
+
+ if ( o instanceof NonExistingLdifEditorInput )
+ {
+ NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) o;
+ return name.equals( input.name );
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Returns hash code of the name string.
+ */
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+
+ /**
+ * This implementation returns a path that point to the plugin's
+ * state location. The state location is a platform indepentend
+ * location that is writeable.
+ *
+ * A valid, writeable path must be returned, otherwise the editor
+ * is not editable.
+ */
+ public IPath getPath()
+ {
+ return LdifEditorActivator.getDefault().getStateLocation().append( name + ".ldif" );
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/PathEditorInput.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/PathEditorInput.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/PathEditorInput.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/PathEditorInput.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.apache.directory.ldapstudio.ldifeditor.editor;
+
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IPathEditorInput;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.editors.text.ILocationProvider;
+
+
+/**
+ * EditorInput that stores a path.
+ */
+
+/**
+ * This EditorInput is used to open LDIF files that are located in the local file system.
+ *
+ * Inspired from org.eclipse.ui.internal.editors.text.NonExistingFileEditorInput.java
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PathEditorInput implements IPathEditorInput, ILocationProvider
+{
+
+ /** The absolute path in local file system */
+ private IPath path;
+
+
+ /**
+ *
+ * Creates a new instance of PathEditorInput.
+ *
+ * @param path the absolute path
+ */
+ public PathEditorInput( IPath path )
+ {
+ if ( path == null )
+ {
+ throw new IllegalArgumentException();
+ }
+
+ this.path = path;
+ }
+
+
+ /**
+ * Returns hash code of the path.
+ */
+ public int hashCode()
+ {
+ return path.hashCode();
+ }
+
+
+ /**
+ * This implemention just compares the names
+ */
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+
+ if ( o instanceof PathEditorInput )
+ {
+ PathEditorInput input = ( PathEditorInput ) o;
+ return path.equals( input.path );
+ }
+
+ return false;
+ }
+
+
+ /*
+ * @see org.eclipse.ui.IEditorInput#exists()
+ */
+ public boolean exists()
+ {
+ return path.toFile().exists();
+ }
+
+
+ /**
+ * Returns the LDIF file image.
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor( path.toString() );
+ }
+
+
+ /**
+ * Returns the file name only.
+ */
+ public String getName()
+ {
+ return path.toFile().getName();
+ //return path.toString();
+ }
+
+
+ /**
+ * Returns the complete path.
+ */
+ public String getToolTipText()
+ {
+ return path.makeRelative().toOSString();
+ }
+
+
+ /**
+ * Returns the path.
+ */
+ public IPath getPath()
+ {
+ return path;
+ }
+
+
+ /**
+ * An EditorInput must return a good ILocationProvider, otherwise
+ * the editor is not editable.
+ */
+ public Object getAdapter( Class adapter )
+ {
+ if ( ILocationProvider.class.equals( adapter ) )
+ {
+ return this;
+ }
+
+ return Platform.getAdapterManager().getAdapter( this, adapter );
+ }
+
+
+ /*
+ * @see org.eclipse.ui.IEditorInput#getPersistable()
+ */
+ public IPersistableElement getPersistable()
+ {
+ return null;
+ }
+
+
+ /**
+ * Returns the path.
+ */
+ public IPath getPath( Object element )
+ {
+ if ( element instanceof PathEditorInput )
+ {
+ PathEditorInput input = ( PathEditorInput ) element;
+ return input.getPath();
+ }
+
+ return null;
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/AbstractLdifAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/AbstractLdifAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/AbstractLdifAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/AbstractLdifAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,132 @@
+/*
+ * 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.ldifeditor.editor.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.texteditor.IUpdate;
+
+
+public abstract class AbstractLdifAction extends Action implements IUpdate
+{
+
+ protected LdifEditor editor;
+
+
+ public AbstractLdifAction( String text, LdifEditor editor )
+ {
+ super( text );
+ this.editor = editor;
+ }
+
+
+ public final void run()
+ {
+ if ( this.isEnabled() )
+ {
+ doRun();
+ }
+ }
+
+
+ protected abstract void doRun();
+
+
+ public boolean isEnabled()
+ {
+ update();
+ return super.isEnabled();
+ }
+
+
+ protected LdifFile getLdifModel()
+ {
+ LdifFile model = editor.getLdifModel();
+ return model;
+ }
+
+
+ protected LdifContainer[] getSelectedLdifContainers()
+ {
+
+ LdifContainer[] containers = null;
+
+ ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+ if ( sourceViewer != null )
+ {
+ LdifFile model = editor.getLdifModel();
+ Point selection = sourceViewer.getSelectedRange();
+ containers = LdifFile.getContainers( model, selection.x, selection.y );
+ }
+
+ return containers != null ? containers : new LdifContainer[0];
+
+ }
+
+
+ protected LdifPart[] getSelectedLdifParts()
+ {
+
+ LdifPart[] parts = null;
+
+ ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+ if ( sourceViewer != null )
+ {
+ LdifFile model = editor.getLdifModel();
+ Point selection = sourceViewer.getSelectedRange();
+ parts = LdifFile.getParts( model, selection.x, selection.y );
+
+ }
+
+ return parts != null ? parts : new LdifPart[0];
+
+ }
+
+
+ protected LdifModSpec getSelectedLdifModSpec()
+ {
+
+ LdifModSpec modSpec = null;
+
+ LdifContainer[] containers = getSelectedLdifContainers();
+ if ( containers.length == 1 )
+ {
+ ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+ if ( sourceViewer != null )
+ {
+ Point selection = sourceViewer.getSelectedRange();
+ modSpec = LdifFile.getInnerContainer( containers[0], selection.x );
+ }
+ }
+
+ return modSpec;
+
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/AbstractOpenValueEditorAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/AbstractOpenValueEditorAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/AbstractOpenValueEditorAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/AbstractOpenValueEditorAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.ldifeditor.editor.actions;
+
+
+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.ldif.LdifPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifControlLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDeloldrdnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNewrdnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNewsuperiorLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifValueLineBase;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+import org.apache.directory.ldapstudio.valueeditors.AbstractDialogValueEditor;
+import org.apache.directory.ldapstudio.valueeditors.IValueEditor;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+
+public abstract class AbstractOpenValueEditorAction extends AbstractLdifAction
+{
+
+ protected ValueEditorManager valueEditorManager;
+
+ protected IValueEditor valueEditor;
+
+
+ public AbstractOpenValueEditorAction( LdifEditor editor )
+ {
+ super( "Edit Value", editor );
+ valueEditorManager = editor.getValueEditorManager();
+ }
+
+
+ public Object getValueEditor()
+ {
+ return valueEditor;
+ }
+
+
+ protected void doRun()
+ {
+
+ LdifPart[] parts = getSelectedLdifParts();
+ if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
+ {
+ LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
+
+ String attributeDescription = getAttributeDescription();
+ Object rawValue = getValueEditorRawValue();
+
+ if ( valueEditor instanceof AbstractDialogValueEditor )
+ {
+ AbstractDialogValueEditor cellEditor = ( AbstractDialogValueEditor ) valueEditor;
+ cellEditor.setValue( rawValue );
+ cellEditor.activate();
+ Object newValue = cellEditor.getValue();
+
+ if ( newValue != null && newValue instanceof String || newValue instanceof byte[] )
+ {
+ IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
+
+ LdifValueLineBase newLine;
+ if ( line instanceof LdifControlLine )
+ {
+ LdifControlLine oldControlLine = ( LdifControlLine ) line;
+ if ( newValue instanceof String )
+ {
+ newLine = LdifControlLine.create( oldControlLine.getUnfoldedOid(), oldControlLine
+ .getUnfoldedCriticality(), ( String ) newValue );
+ }
+ else
+ {
+ newLine = LdifControlLine.create( oldControlLine.getUnfoldedOid(), oldControlLine
+ .getUnfoldedCriticality(), ( byte[] ) newValue );
+ }
+ }
+ else
+ {
+ if ( newValue instanceof String )
+ {
+ newLine = LdifAttrValLine.create( attributeDescription, ( String ) newValue );
+ }
+ else
+ {
+ newLine = LdifAttrValLine.create( attributeDescription, ( byte[] ) newValue );
+ }
+ }
+
+ try
+ {
+ document.replace( line.getOffset(), line.getLength(), newLine.toFormattedString() );
+ }
+ catch ( BadLocationException e )
+ {
+ e.printStackTrace();
+ }
+
+ }
+ }
+ }
+ }
+
+
+ protected IConnection getConnection()
+ {
+ return editor.getConnection() != null ? editor.getConnection() : new DummyConnection( Schema.DEFAULT_SCHEMA );
+ }
+
+
+ protected Object getValueEditorRawValue()
+ {
+ Object rawValue = null;
+ Object value = getValue();
+ if ( value != null )
+ {
+ IConnection connection = getConnection();
+ rawValue = valueEditor.getRawValue( connection, value );
+ }
+
+ return rawValue;
+ }
+
+
+ protected Object getValue()
+ {
+ LdifPart[] parts = getSelectedLdifParts();
+ Object oldValue = null;
+ if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
+ {
+ LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
+ oldValue = line.getValueAsObject();
+
+ if ( line instanceof LdifControlLine )
+ {
+ oldValue = ( ( LdifControlLine ) line ).getUnfoldedControlValue();
+ }
+
+ }
+ return oldValue;
+ }
+
+
+ protected String getAttributeDescription()
+ {
+ String attributeDescription = null;
+ LdifPart[] parts = getSelectedLdifParts();
+ if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
+ {
+ LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
+
+ if ( line instanceof LdifControlLine )
+ {
+ attributeDescription = "";
+ }
+ else
+ {
+ attributeDescription = line.getUnfoldedLineStart();
+ }
+ }
+ return attributeDescription;
+ }
+
+
+ protected boolean isEditableLineSelected()
+ {
+ LdifPart[] parts = getSelectedLdifParts();
+ boolean b = parts.length == 1
+ && ( parts[0] instanceof LdifAttrValLine || parts[0] instanceof LdifDnLine
+ || parts[0] instanceof LdifControlLine || parts[0] instanceof LdifNewrdnLine
+ || parts[0] instanceof LdifDeloldrdnLine || parts[0] instanceof LdifNewsuperiorLine );
+ return b;
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/EditLdifAttributeAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/EditLdifAttributeAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/EditLdifAttributeAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/EditLdifAttributeAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,217 @@
+/*
+ * 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.ldifeditor.editor.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.wizards.AttributeWizard;
+import org.apache.directory.ldapstudio.browser.core.internal.model.DummyConnection;
+import org.apache.directory.ldapstudio.browser.core.internal.model.DummyEntry;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+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.LdifPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecSepLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecTypeLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifValueLineBase;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.core.utils.ModelConverter;
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+
+
+public class EditLdifAttributeAction extends AbstractLdifAction
+{
+
+ ValueEditorManager manager;
+
+
+ public EditLdifAttributeAction( LdifEditor editor )
+ {
+ super( "Edit Attribute Description", editor );
+ super.setActionDefinitionId( BrowserCommonConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION );
+
+ manager = new ValueEditorManager( editor.getSite().getShell() );
+ }
+
+
+ public void update()
+ {
+ LdifContainer[] containers = getSelectedLdifContainers();
+ LdifModSpec modSpec = getSelectedLdifModSpec();
+ LdifPart[] parts = getSelectedLdifParts();
+
+ super
+ .setEnabled( parts.length == 1
+ && ( parts[0] instanceof LdifAttrValLine || modSpec != null )
+ && containers.length == 1
+ && ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord || containers[0] instanceof LdifChangeModifyRecord ) );
+ }
+
+
+ protected void doRun()
+ {
+
+ LdifContainer[] containers = getSelectedLdifContainers();
+ LdifModSpec modSpec = getSelectedLdifModSpec();
+ LdifPart[] parts = getSelectedLdifParts();
+ if ( parts.length == 1
+ && ( parts[0] instanceof LdifAttrValLine || parts[0] instanceof LdifModSpecTypeLine )
+ && containers.length == 1
+ && ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord || containers[0] instanceof LdifChangeModifyRecord ) )
+ {
+ try
+ {
+ LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
+ String attributeDescription = null;
+ String oldValue = null;
+ if ( modSpec != null && line instanceof LdifModSpecTypeLine )
+ {
+ LdifModSpecTypeLine oldLine = ( LdifModSpecTypeLine ) line;
+ attributeDescription = oldLine.getUnfoldedAttributeDescription();
+ oldValue = null;
+ }
+ else
+ {
+ LdifAttrValLine oldLine = ( LdifAttrValLine ) line;
+ attributeDescription = oldLine.getUnfoldedAttributeDescription();
+ oldValue = oldLine.getValueAsString();
+ }
+
+ Schema schema = editor.getConnection() != null ? editor.getConnection().getSchema()
+ : Schema.DEFAULT_SCHEMA;
+ IConnection dummyConnection = new DummyConnection( schema );
+
+ IEntry dummyEntry = null;
+ if ( containers[0] instanceof LdifContentRecord )
+ {
+ dummyEntry = ModelConverter.ldifContentRecordToEntry( ( LdifContentRecord ) containers[0],
+ dummyConnection );
+ }
+ else if ( containers[0] instanceof LdifChangeAddRecord )
+ {
+ dummyEntry = ModelConverter.ldifChangeAddRecordToEntry( ( LdifChangeAddRecord ) containers[0],
+ dummyConnection );
+ }
+ else if ( containers[0] instanceof LdifChangeModifyRecord )
+ {
+ dummyEntry = new DummyEntry( new DN(), dummyConnection );
+ }
+
+ AttributeWizard wizard = new AttributeWizard( "Edit Attribute Description", true, false,
+ attributeDescription, dummyEntry );
+ WizardDialog dialog = new WizardDialog( Display.getDefault().getActiveShell(), wizard );
+ dialog.setBlockOnOpen( true );
+ dialog.create();
+ if ( dialog.open() == Dialog.OK )
+ {
+ String newAttributeDescription = wizard.getAttributeDescription();
+
+ if ( newAttributeDescription != null )
+ {
+ IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
+
+ if ( modSpec != null )
+ {
+ LdifModSpecTypeLine oldTypeLine = modSpec.getModSpecType();
+ LdifModSpecTypeLine newTypeLine = null;
+ if ( oldTypeLine.isAdd() )
+ {
+ newTypeLine = LdifModSpecTypeLine.createAdd( newAttributeDescription );
+ }
+ else if ( oldTypeLine.isDelete() )
+ {
+ newTypeLine = LdifModSpecTypeLine.createDelete( newAttributeDescription );
+ }
+ else if ( oldTypeLine.isReplace() )
+ {
+ newTypeLine = LdifModSpecTypeLine.createReplace( newAttributeDescription );
+ }
+
+ LdifAttrValLine[] oldAttrValLines = modSpec.getAttrVals();
+ LdifAttrValLine[] newAttrValLines = new LdifAttrValLine[oldAttrValLines.length];
+ for ( int i = 0; i < oldAttrValLines.length; i++ )
+ {
+ LdifAttrValLine oldAttrValLine = oldAttrValLines[i];
+ newAttrValLines[i] = LdifAttrValLine.create( newAttributeDescription, oldAttrValLine
+ .getValueAsString() );
+
+ }
+
+ LdifModSpecSepLine newSepLine = LdifModSpecSepLine.create();
+
+ String text = newTypeLine.toFormattedString();
+ for ( int j = 0; j < newAttrValLines.length; j++ )
+ {
+ text += newAttrValLines[j].toFormattedString();
+ }
+ text += newSepLine.toFormattedString();
+ try
+ {
+ document.replace( modSpec.getOffset(), modSpec.getLength(), text );
+ }
+ catch ( BadLocationException e )
+ {
+ e.printStackTrace();
+ }
+
+ }
+ else
+ { // LdifContentRecord ||
+ // LdifChangeAddRecord
+ LdifAttrValLine newLine = LdifAttrValLine.create( newAttributeDescription, oldValue );
+ try
+ {
+ document.replace( line.getOffset(), line.getLength(), newLine.toFormattedString() );
+ }
+ catch ( BadLocationException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ // ...
+ }
+ }
+ catch ( NameException e )
+ {
+ }
+ catch ( ModelModificationException e )
+ {
+ }
+ }
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/EditLdifRecordAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/EditLdifRecordAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/EditLdifRecordAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/EditLdifRecordAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,91 @@
+/*
+ * 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.ldifeditor.editor.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+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.ldifeditor.LdifEditorConstants;
+import org.apache.directory.ldapstudio.ldifeditor.dialogs.LdifEntryEditorDialog;
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+import org.eclipse.jface.text.IDocument;
+
+
+public class EditLdifRecordAction extends AbstractLdifAction
+{
+
+ public EditLdifRecordAction( LdifEditor editor )
+ {
+ super( "Edit Record", editor );
+ super.setActionDefinitionId( LdifEditorConstants.ACTION_ID_EDIT_RECORD );
+ }
+
+
+ protected void doRun()
+ {
+
+ LdifContainer[] containers = getSelectedLdifContainers();
+ if ( containers.length == 1
+ && ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord ) )
+ {
+
+ LdifContainer container = containers[0];
+
+ LdifEntryEditorDialog dialog = null;
+ if ( container instanceof LdifContentRecord )
+ {
+ dialog = new LdifEntryEditorDialog( editor.getEditorSite().getShell(), editor.getConnection(),
+ ( LdifContentRecord ) container );
+ }
+ else
+ {
+ dialog = new LdifEntryEditorDialog( editor.getEditorSite().getShell(), editor.getConnection(),
+ ( LdifChangeAddRecord ) container );
+ }
+
+ editor.deactivateGlobalActionHandlers();
+ if ( dialog.open() == LdifEntryEditorDialog.OK )
+ {
+ LdifRecord record = dialog.getLdifRecord();
+
+ IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
+ String old = document.get();
+ StringBuffer sb = new StringBuffer();
+ sb.append( old.substring( 0, container.getOffset() ) );
+ sb.append( record.toFormattedString() );
+ sb.append( old.substring( container.getOffset() + container.getLength(), old.length() ) );
+ document.set( sb.toString() );
+ }
+ editor.activateGlobalActionHandlers();
+ }
+ }
+
+
+ public void update()
+ {
+ LdifContainer[] containers = getSelectedLdifContainers();
+ super.setEnabled( containers.length == 1
+ && ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord ) );
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/FormatLdifDocumentAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/FormatLdifDocumentAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/FormatLdifDocumentAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/FormatLdifDocumentAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,52 @@
+/*
+ * 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.ldifeditor.editor.actions;
+
+
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+public class FormatLdifDocumentAction extends AbstractLdifAction
+{
+
+ public FormatLdifDocumentAction( LdifEditor editor )
+ {
+ super( "Format Document", editor );
+ }
+
+
+ protected void doRun()
+ {
+ IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
+ ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+ int topIndex = sourceViewer.getTopIndex();
+ document.set( super.getLdifModel().toFormattedString() );
+ sourceViewer.setTopIndex( topIndex );
+ }
+
+
+ public void update()
+ {
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/FormatLdifRecordAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/FormatLdifRecordAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/FormatLdifRecordAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/FormatLdifRecordAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.ldifeditor.editor.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+public class FormatLdifRecordAction extends AbstractLdifAction
+{
+
+ public FormatLdifRecordAction( LdifEditor editor )
+ {
+ super( "Format Record", editor );
+ }
+
+
+ protected void doRun()
+ {
+
+ LdifContainer[] containers = super.getSelectedLdifContainers();
+ if ( containers.length > 0 )
+ {
+ IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
+ String old = document.get();
+ StringBuffer sb = new StringBuffer();
+ sb.append( old.substring( 0, containers[0].getOffset() ) );
+
+ for ( int i = 0; i < containers.length; i++ )
+ {
+ LdifContainer container = containers[i];
+ sb.append( container.toFormattedString() );
+ }
+
+ sb.append( old.substring( containers[containers.length - 1].getOffset()
+ + containers[containers.length - 1].getLength(), old.length() ) );
+
+ ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+ int topIndex = sourceViewer.getTopIndex();
+ document.set( sb.toString() );
+ sourceViewer.setTopIndex( topIndex );
+ }
+ }
+
+
+ public void update()
+ {
+ LdifContainer[] ldifContainers = super.getSelectedLdifContainers();
+ for ( int i = 0; i < ldifContainers.length; i++ )
+ {
+ LdifContainer container = ldifContainers[i];
+ if ( !( container instanceof LdifRecord ) )
+ {
+ super.setEnabled( false );
+ return;
+ }
+ }
+
+ super.setEnabled( true );
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenBestValueEditorAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenBestValueEditorAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenBestValueEditorAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenBestValueEditorAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,72 @@
+/*
+ * 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.ldifeditor.editor.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+import org.apache.directory.ldapstudio.valueeditors.AbstractDialogValueEditor;
+import org.apache.directory.ldapstudio.valueeditors.IValueEditor;
+
+
+public class OpenBestValueEditorAction extends AbstractOpenValueEditorAction
+{
+
+ public OpenBestValueEditorAction( LdifEditor editor )
+ {
+ super( editor );
+ }
+
+
+ public void update()
+ {
+
+ super.setEnabled( isEditableLineSelected() );
+
+ // determine value editor
+ IConnection connection = getConnection();
+ String attributeDescription = getAttributeDescription();
+ Object oldValue = getValue();
+
+ if ( attributeDescription != null )
+ {
+ valueEditor = valueEditorManager.getCurrentValueEditor( connection.getSchema(), attributeDescription );
+ Object rawValue = valueEditor.getRawValue( connection, oldValue );
+ if ( !( valueEditor instanceof AbstractDialogValueEditor ) || rawValue == null )
+ {
+ IValueEditor[] vps = valueEditorManager.getAlternativeValueEditors( connection.getSchema(), attributeDescription );
+ for ( int i = 0; i < vps.length
+ && ( !( valueEditor instanceof AbstractDialogValueEditor ) || rawValue == null ); i++ )
+ {
+ valueEditor = vps[i];
+ rawValue = valueEditor.getRawValue( connection, oldValue );
+ }
+ }
+ }
+
+ if ( valueEditor != null )
+ {
+ setText( valueEditor.getValueEditorName() );
+ setImageDescriptor( valueEditor.getValueEditorImageDescriptor() );
+ }
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenDefaultValueEditorAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenDefaultValueEditorAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenDefaultValueEditorAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenDefaultValueEditorAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.ldifeditor.editor.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+
+
+public class OpenDefaultValueEditorAction extends AbstractLdifAction
+{
+
+ private OpenBestValueEditorAction proxy;
+
+
+ public OpenDefaultValueEditorAction( LdifEditor editor, OpenBestValueEditorAction proxy )
+ {
+ super( "Edit Value", editor );
+ super.setActionDefinitionId( BrowserCommonConstants.ACTION_ID_EDIT_VALUE );
+ this.proxy = proxy;
+ }
+
+
+ public void update()
+ {
+ this.proxy.update();
+ super.setEnabled( this.proxy.isEnabled() );
+ }
+
+
+ protected void doRun()
+ {
+ this.proxy.run();
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenValueEditorAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenValueEditorAction.java?view=auto&rev=526698
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenValueEditorAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-ldifeditor/src/main/java/org/apache/directory/ldapstudio/ldifeditor/editor/actions/OpenValueEditorAction.java Mon Apr 9 02:59:19 2007
@@ -0,0 +1,60 @@
+/*
+ * 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.ldifeditor.editor.actions;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.ldifeditor.editor.LdifEditor;
+import org.apache.directory.ldapstudio.valueeditors.IValueEditor;
+
+
+public class OpenValueEditorAction extends AbstractOpenValueEditorAction
+{
+
+ public OpenValueEditorAction( LdifEditor editor, IValueEditor valueEditor )
+ {
+ super( editor );
+ super.valueEditor = valueEditor;
+ }
+
+
+ public void update()
+ {
+ String attributeDescription = getAttributeDescription();
+ Object rawValue = getValueEditorRawValue();
+
+ if ( isEditableLineSelected() )
+ {
+ IValueEditor[] alternativeVps = this.editor.getValueEditorManager().getAlternativeValueEditors(
+ getConnection().getSchema(), attributeDescription );
+ super.setEnabled( Arrays.asList( alternativeVps ).contains( this.valueEditor ) && rawValue != null );
+ }
+ else
+ {
+ super.setEnabled( false );
+ }
+
+ setText( valueEditor.getValueEditorName() );
+ setImageDescriptor( valueEditor.getValueEditorImageDescriptor() );
+ }
+
+}