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 [16/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/s...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/EditLdifAttributeAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/EditLdifAttributeAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/EditLdifAttributeAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/EditLdifAttributeAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,218 @@
+/*
+ * 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.editors.ldif.actions;
+
+
+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.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifEditor;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProviderManager;
+import org.apache.directory.ldapstudio.browser.ui.wizards.AttributeWizard;
+
+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
+{
+
+ ValueProviderManager manager;
+
+
+ public EditLdifAttributeAction( LdifEditor editor )
+ {
+ super( "Edit Attribute Description", editor );
+ super.setActionDefinitionId( BrowserUIConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION );
+
+ manager = new ValueProviderManager( 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/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/EditLdifRecordAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/EditLdifRecordAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/EditLdifRecordAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/EditLdifRecordAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.editors.ldif.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.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.dialogs.LdifEntryEditorDialog;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifEditor;
+
+import org.eclipse.jface.text.IDocument;
+
+
+public class EditLdifRecordAction extends AbstractLdifAction
+{
+
+ public EditLdifRecordAction( LdifEditor editor )
+ {
+ super( "Edit Record", editor );
+ super.setActionDefinitionId( BrowserUIConstants.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/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/FormatLdifDocumentAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/FormatLdifDocumentAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/FormatLdifDocumentAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/FormatLdifDocumentAction.java Mon Dec 18 09:52:58 2006
@@ -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.browser.ui.editors.ldif.actions;
+
+
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.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/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/FormatLdifRecordAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/FormatLdifRecordAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/FormatLdifRecordAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/FormatLdifRecordAction.java Mon Dec 18 09:52:58 2006
@@ -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.browser.ui.editors.ldif.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.browser.ui.editors.ldif.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/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenBestValueEditorAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenBestValueEditorAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenBestValueEditorAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenBestValueEditorAction.java Mon Dec 18 09:52:58 2006
@@ -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.browser.ui.editors.ldif.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifEditor;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.AbstractDialogCellEditor;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+
+
+public class OpenBestValueEditorAction extends AbstractOpenValueEditorAction
+{
+
+ public OpenBestValueEditorAction( LdifEditor editor )
+ {
+ super( editor );
+ }
+
+
+ public void update()
+ {
+
+ super.setEnabled( isEditableLineSelected() );
+
+ // determine value provider
+ Schema schema = getSchema();
+ String attributeDescription = getAttributeDescription();
+ Object oldValue = getValue();
+
+ if ( attributeDescription != null )
+ {
+ valueProvider = manager.getCurrentValueProvider( schema, attributeDescription );
+ Object rawValue = valueProvider.getRawValue( null, schema, oldValue );
+ if ( !( valueProvider instanceof AbstractDialogCellEditor ) || rawValue == null )
+ {
+ ValueProvider[] vps = manager.getAlternativeValueProvider( schema, attributeDescription );
+ for ( int i = 0; i < vps.length
+ && ( !( valueProvider instanceof AbstractDialogCellEditor ) || rawValue == null ); i++ )
+ {
+ valueProvider = vps[i];
+ rawValue = valueProvider.getRawValue( null, schema, oldValue );
+ }
+ }
+ }
+
+ if ( valueProvider != null )
+ {
+ setText( valueProvider.getCellEditorName() );
+ setImageDescriptor( valueProvider.getCellEditorImageDescriptor() );
+ }
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenDefaultValueEditorAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenDefaultValueEditorAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenDefaultValueEditorAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenDefaultValueEditorAction.java Mon Dec 18 09:52:58 2006
@@ -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.browser.ui.editors.ldif.actions;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifEditor;
+
+
+public class OpenDefaultValueEditorAction extends AbstractLdifAction
+{
+
+ private OpenBestValueEditorAction proxy;
+
+
+ public OpenDefaultValueEditorAction( LdifEditor editor, OpenBestValueEditorAction proxy )
+ {
+ super( "Edit Value", editor );
+ super.setActionDefinitionId( BrowserUIConstants.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/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenValueEditorAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenValueEditorAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenValueEditorAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/OpenValueEditorAction.java Mon Dec 18 09:52:58 2006
@@ -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.browser.ui.editors.ldif.actions;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifEditor;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+
+
+public class OpenValueEditorAction extends AbstractOpenValueEditorAction
+{
+
+ public OpenValueEditorAction( LdifEditor editor, ValueProvider valueProvider )
+ {
+ super( editor );
+ super.valueProvider = valueProvider;
+ }
+
+
+ public void update()
+ {
+ String attributeDescription = getAttributeDescription();
+ Object rawValue = getValueProviderRawValue();
+
+ if ( isEditableLineSelected() )
+ {
+ ValueProvider[] alternativeVps = this.editor.getValueProviderManager().getAlternativeValueProvider(
+ getSchema(), attributeDescription );
+ super.setEnabled( Arrays.asList( alternativeVps ).contains( this.valueProvider ) && rawValue != null );
+ }
+ else
+ {
+ super.setEnabled( false );
+ }
+
+ setText( valueProvider.getCellEditorName() );
+ setImageDescriptor( valueProvider.getCellEditorImageDescriptor() );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifAnnotationUpdater.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifAnnotationUpdater.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifAnnotationUpdater.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifAnnotationUpdater.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,144 @@
+/*
+ * 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.editors.ldif.reconciler;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.ui.editors.ldif.ILdifEditor;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IAnnotationModelExtension;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+class LdifAnnotationUpdater
+{
+
+ private static final String ERROR_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.error";
+
+ private ILdifEditor editor;
+
+
+ public LdifAnnotationUpdater( ILdifEditor editor )
+ {
+ this.editor = editor;
+ }
+
+
+ public void dispose()
+ {
+ }
+
+
+ public void updateAnnotations( LdifContainer[] containers )
+ {
+
+ }
+
+
+ public void updateAnnotations()
+ {
+
+ LdifFile model = editor.getLdifModel();
+ ISourceViewer viewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+ if ( viewer == null )
+ return;
+
+ IDocument document = viewer.getDocument();
+ IAnnotationModel annotationModel = viewer.getAnnotationModel();
+ if ( document == null || annotationModel == null || model == null )
+ return;
+
+ if ( annotationModel instanceof IAnnotationModelExtension )
+ {
+ ( ( IAnnotationModelExtension ) annotationModel ).removeAllAnnotations();
+
+ List positionList = new ArrayList();
+
+ LdifContainer[] containers = model.getContainers();
+ for ( int i = 0; i < containers.length; i++ )
+ {
+ LdifContainer container = containers[i];
+
+ // LdifPart errorPart = null;
+ int errorOffset = -1;
+ int errorLength = -1;
+ StringBuffer errorText = null;
+
+ LdifPart[] parts = container.getParts();
+ for ( int k = 0; k < parts.length; k++ )
+ {
+ LdifPart part = parts[k];
+ if ( !part.isValid() )
+ {
+ if ( errorOffset == -1 )
+ {
+ // errorPart = part;
+ errorOffset = part.getOffset();
+ errorLength = part.getLength();
+ errorText = new StringBuffer();
+ errorText.append( part.toRawString() );
+ }
+ else
+ {
+ errorLength += part.getLength();
+ errorText.append( part.toRawString() );
+ }
+ }
+ }
+
+ if ( errorOffset == -1 && !container.isValid() )
+ {
+ errorOffset = container.getOffset();
+ errorLength = container.getLength();
+ errorText = new StringBuffer();
+ errorText.append( container.toRawString() );
+ }
+
+ if ( errorOffset > -1 )
+ {
+ // Annotation annotation = new Annotation("DEFAULT",
+ // true,
+ // invalidFilters[i].toString());
+ // if(errorPart instanceof LdifUnknownPart) {
+ // errorOffset = container.getOffset();
+ // errorLength = container.getLength();
+ // errorText = new StringBuffer(container.toString());
+ // }
+ Annotation annotation = new Annotation( ERROR_ANNOTATION_TYPE, true, errorText.toString() );
+ Position position = new Position( errorOffset, errorLength );
+ positionList.add( position );
+ viewer.getAnnotationModel().addAnnotation( annotation, position );
+ }
+
+ }
+ }
+ }
+
+}
\ No newline at end of file
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifFoldingRegionUpdater.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifFoldingRegionUpdater.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifFoldingRegionUpdater.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifFoldingRegionUpdater.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,224 @@
+/*
+ * 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.editors.ldif.reconciler;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+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.LdifPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifCommentContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNonEmptyLineBase;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifSepLine;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.ILdifEditor;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+
+public class LdifFoldingRegionUpdater implements IPropertyChangeListener
+{
+
+ private ILdifEditor editor;
+
+
+ public LdifFoldingRegionUpdater( ILdifEditor editor )
+ {
+ this.editor = editor;
+
+ BrowserUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( this );
+ }
+
+
+ public void dispose()
+ {
+ BrowserUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this );
+ }
+
+
+ public void propertyChange( PropertyChangeEvent event )
+ {
+ if ( BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE.equals( event.getProperty() )
+ || BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS.equals( event.getProperty() )
+ || BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS.equals( event.getProperty() )
+ || BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES.equals( event.getProperty() ) )
+ {
+ this.updateFoldingRegions();
+ }
+ }
+
+
+ public void updateFoldingRegions()
+ {
+
+ ISourceViewer viewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+ if ( viewer == null )
+ return;
+
+ IDocument document = viewer.getDocument();
+
+ try
+ {
+ ProjectionAnnotationModel projectionAnnotationModel = ( ProjectionAnnotationModel ) editor
+ .getAdapter( ProjectionAnnotationModel.class );
+ if ( projectionAnnotationModel == null )
+ return;
+
+ // create folding regions of current LDIF model; mark comments
+ // and
+ // folded lines as collapsed
+ Map positionToAnnotationMap = createFoldingRegions( editor.getLdifModel(), document );
+
+ // compare with current annotation model (--> toAdd, toDelete)
+ List annotationsToDeleteList = new ArrayList();
+ Map annotationsToAddMap = new HashMap();
+ this.computeDifferences( projectionAnnotationModel, positionToAnnotationMap, annotationsToDeleteList,
+ annotationsToAddMap );
+ Annotation[] annotationsToDelete = ( Annotation[] ) annotationsToDeleteList
+ .toArray( new Annotation[annotationsToDeleteList.size()] );
+
+ // update annotation model
+ if ( !annotationsToDeleteList.isEmpty() || !annotationsToAddMap.isEmpty() )
+ {
+ projectionAnnotationModel.modifyAnnotations( annotationsToDelete, annotationsToAddMap,
+ new Annotation[0] );
+ }
+
+ }
+ catch ( BadLocationException e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+ private void computeDifferences( ProjectionAnnotationModel model, Map positionToAnnotationMap,
+ List annotationsToDeleteList, Map annotationsToAddMap )
+ {
+
+ for ( Iterator iter = model.getAnnotationIterator(); iter.hasNext(); )
+ {
+ Object annotation = iter.next();
+ if ( annotation instanceof ProjectionAnnotation )
+ {
+ Position position = model.getPosition( ( Annotation ) annotation );
+ if ( positionToAnnotationMap.containsKey( position ) )
+ positionToAnnotationMap.remove( position );
+ else
+ annotationsToDeleteList.add( annotation );
+ }
+ }
+
+ for ( Iterator iter = positionToAnnotationMap.keySet().iterator(); iter.hasNext(); )
+ {
+ Position position = ( Position ) iter.next();
+ ProjectionAnnotation annotation = ( ProjectionAnnotation ) positionToAnnotationMap.get( position );
+ annotationsToAddMap.put( annotation, position );
+ }
+ }
+
+
+ /**
+ * Creates all folding region of the given LDIF model.
+ * LdifCommentContainers and wrapped lines are marked as collapsed.
+ *
+ * @param model
+ * @param document
+ * @return a map with positions as keys to annotations as values
+ * @throws BadLocationException
+ */
+ private Map createFoldingRegions( LdifFile model, IDocument document ) throws BadLocationException
+ {
+ Map positionToAnnotationMap = new HashMap();
+ LdifContainer[] containers = model.getContainers();
+
+ boolean ENABLE_FOLDING = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE );
+ boolean FOLD_COMMENTS = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS );
+ boolean FOLD_RECORDS = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS );
+ boolean FOLD_WRAPPEDLINES = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES );
+
+ if ( ENABLE_FOLDING )
+ {
+ for ( int i = 0; i < containers.length; i++ )
+ {
+ LdifContainer container = containers[i];
+ int containerStartLine = document.getLineOfOffset( container.getOffset() );
+ int containerEndLine = -1;
+ LdifPart[] parts = container.getParts();
+ for ( int j = parts.length - 1; j >= 0; j-- )
+ {
+ if ( containerEndLine == -1
+ && ( !( parts[j] instanceof LdifSepLine ) || ( container instanceof LdifCommentContainer && j < parts.length - 1 ) ) )
+ {
+ containerEndLine = document.getLineOfOffset( parts[j].getOffset() + parts[j].getLength() - 1 );
+ // break;
+ }
+ if ( parts[j] instanceof LdifNonEmptyLineBase )
+ {
+ LdifNonEmptyLineBase line = ( LdifNonEmptyLineBase ) parts[j];
+ if ( line.isFolded() )
+ {
+ Position position = new Position( line.getOffset(), line.getLength() );
+ // ProjectionAnnotation annotation = new
+ // ProjectionAnnotation(true);
+ ProjectionAnnotation annotation = new ProjectionAnnotation( FOLD_WRAPPEDLINES );
+ positionToAnnotationMap.put( position, annotation );
+ }
+ }
+ }
+
+ if ( containerStartLine < containerEndLine )
+ {
+ int start = document.getLineOffset( containerStartLine );
+ int end = document.getLineOffset( containerEndLine ) + document.getLineLength( containerEndLine );
+ Position position = new Position( start, end - start );
+ // ProjectionAnnotation annotation = new
+ // ProjectionAnnotation(container instanceof
+ // LdifCommentContainer);
+ ProjectionAnnotation annotation = new ProjectionAnnotation( FOLD_RECORDS
+ || ( FOLD_COMMENTS && container instanceof LdifCommentContainer ) );
+ positionToAnnotationMap.put( position, annotation );
+ }
+ }
+ }
+
+ return positionToAnnotationMap;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifReconcilingStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifReconcilingStrategy.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifReconcilingStrategy.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/reconciler/LdifReconcilingStrategy.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,127 @@
+/*
+ * 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.editors.ldif.reconciler;
+
+
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.ILdifEditor;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifOutlinePage;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+
+
+public class LdifReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension
+{
+
+ private ILdifEditor editor;
+
+ // private IDocument document;
+ // private IProgressMonitor progressMonitor;
+
+ private LdifFoldingRegionUpdater foldingUpdater;
+
+ private LdifAnnotationUpdater annotationUpdater;
+
+
+ public LdifReconcilingStrategy( ILdifEditor editor )
+ {
+ this.editor = editor;
+
+ this.annotationUpdater = new LdifAnnotationUpdater( this.editor );
+ this.foldingUpdater = new LdifFoldingRegionUpdater( this.editor );
+
+ }
+
+
+ public void dispose()
+ {
+ this.annotationUpdater.dispose();
+ this.foldingUpdater.dispose();
+ }
+
+
+ public void setDocument( IDocument document )
+ {
+ // this.document = document;
+ }
+
+
+ public void setProgressMonitor( IProgressMonitor monitor )
+ {
+ // this.progressMonitor = monitor;
+ }
+
+
+ public void reconcile( DirtyRegion dirtyRegion, IRegion subRegion )
+ {
+ reconcile();
+ }
+
+
+ public void reconcile( IRegion partition )
+ {
+ reconcile();
+ }
+
+
+ public void initialReconcile()
+ {
+ reconcile();
+ }
+
+
+ private void reconcile()
+ {
+ notifyEnvironment();
+ }
+
+
+ private void notifyEnvironment()
+ {
+
+ Display.getDefault().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+
+ // notify outline
+ IContentOutlinePage outline = ( IContentOutlinePage ) editor.getAdapter( IContentOutlinePage.class );
+ if ( outline != null && outline instanceof LdifOutlinePage )
+ {
+ ( ( LdifOutlinePage ) outline ).refresh();
+ }
+
+ // notify annotation updater
+ annotationUpdater.updateAnnotations();
+
+ // notify folding updater
+ foldingUpdater.updateFoldingRegions();
+
+ }
+ } );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifAnnotationHover.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifAnnotationHover.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifAnnotationHover.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifAnnotationHover.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.editors.ldif.text;
+
+
+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.ui.editors.ldif.ILdifEditor;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+public class LdifAnnotationHover implements IAnnotationHover
+{
+
+ private ILdifEditor editor;
+
+
+ public LdifAnnotationHover( ILdifEditor editor )
+ {
+ this.editor = editor;
+ }
+
+
+ public String getHoverInfo( ISourceViewer sourceViewer, int lineNumber )
+ {
+
+ try
+ {
+ if ( this.editor != null )
+ {
+
+ int offset = sourceViewer.getDocument().getLineOffset( lineNumber );
+ LdifContainer container = LdifFile.getContainer( this.editor.getLdifModel(), offset );
+ if ( container != null )
+ {
+ LdifPart part = LdifFile.getContainerContent( container, offset );
+ if ( part != null )
+ {
+ // return container.getClass().getName() + " - " +
+ // part.getClass().getName();
+ return container.getInvalidString() + " - " + part.getInvalidString();
+ }
+ }
+ }
+ }
+ catch ( BadLocationException e )
+ {
+ }
+
+ return null;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifAutoEditStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifAutoEditStrategy.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifAutoEditStrategy.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifAutoEditStrategy.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,87 @@
+/*
+ * 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.editors.ldif.text;
+
+
+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.LdifChangeModifyRecord;
+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.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecTypeLine;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.ILdifEditor;
+
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextUtilities;
+
+
+public class LdifAutoEditStrategy implements IAutoEditStrategy
+{
+
+ private ILdifEditor editor;
+
+
+ public LdifAutoEditStrategy( ILdifEditor editor )
+ {
+ this.editor = editor;
+ }
+
+
+ public void customizeDocumentCommand( IDocument d, DocumentCommand c )
+ {
+
+ LdifFile model = editor.getLdifModel();
+ LdifContainer container = LdifFile.getContainer( model, c.offset );
+ LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, c.offset ) : null;
+ LdifPart part = container != null ? LdifFile.getContainerContent( container, c.offset ) : null;
+
+ boolean smartInsertAttributeInModSpec = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC );
+ if ( smartInsertAttributeInModSpec )
+ {
+ if ( c.length == 0 && c.text != null && TextUtilities.endsWith( d.getLegalLineDelimiters(), c.text ) != -1 )
+ {
+
+ if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec
+ && ( part instanceof LdifAttrValLine || part instanceof LdifModSpecTypeLine ) )
+ {
+ LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
+ String att = modSpec.getModSpecType().getUnfoldedAttributeDescription();
+ c.text += att + ": ";
+ }
+ }
+ }
+
+ boolean autoWrap = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_LDIFEDITOR_FORMATTER_AUTOWRAP );
+ if ( autoWrap )
+ {
+
+ }
+
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifCompletionProcessor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifCompletionProcessor.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifCompletionProcessor.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifCompletionProcessor.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,460 @@
+/*
+ * 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.editors.ldif.text;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifInvalidPart;
+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.LdifChangeModDnRecord;
+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.LdifInvalidContainer;
+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.container.LdifSepContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifChangeTypeLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifSepLine;
+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.editors.ldif.ILdifEditor;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.swt.graphics.Image;
+
+
+public class LdifCompletionProcessor extends TemplateCompletionProcessor
+{
+
+ // private final static String DN = "dn: ";
+ private final static String CT_ADD = "changetype: add" + BrowserCoreConstants.LINE_SEPARATOR;
+
+ private final static String CT_MODIFY = "changetype: modify" + BrowserCoreConstants.LINE_SEPARATOR;
+
+ private final static String CT_DELETE = "changetype: delete" + BrowserCoreConstants.LINE_SEPARATOR;
+
+ private final static String CT_MODDN = "changetype: moddn" + BrowserCoreConstants.LINE_SEPARATOR;
+
+ private final static String MD_NEWRDN = "newrdn: ";
+
+ private final static String MD_DELETEOLDRDN_TRUE = "deleteoldrdn: 1";
+
+ // private final static String MD_DELETEOLDRDN_FALSE = "deleteoldrdn:
+ // 0";
+ private final static String MD_NEWSUPERIOR = "newsuperior: ";
+
+ private final ILdifEditor editor;
+
+ private final ContentAssistant contentAssistant;
+
+
+ public LdifCompletionProcessor( ILdifEditor editor, ContentAssistant contentAssistant )
+ {
+ this.editor = editor;
+ this.contentAssistant = contentAssistant;
+ }
+
+
+ public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset )
+ {
+
+ IPreferenceStore store = BrowserUIPlugin.getDefault().getPreferenceStore();
+ contentAssistant.enableAutoInsert( store
+ .getBoolean( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) );
+ contentAssistant.enableAutoActivation( store
+ .getBoolean( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) );
+ contentAssistant.setAutoActivationDelay( store
+ .getInt( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) );
+
+ List proposalList = new ArrayList();
+
+ LdifFile model = editor.getLdifModel();
+ LdifContainer container = LdifFile.getContainer( model, offset );
+ LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, offset ) : null;
+ LdifPart part = container != null ? LdifFile.getContainerContent( container, offset ) : null;
+ int documentLine = -1;
+ int documentLineOffset = -1;
+ String prefix = "";
+ try
+ {
+ documentLine = viewer.getDocument().getLineOfOffset( offset );
+ documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
+ prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
+ }
+ catch ( BadLocationException e )
+ {
+ }
+ // TemplateContextType contextType = getContextType(viewer, new
+ // Region(offset, 0));
+
+ // Add context dependend template proposals
+ ICompletionProposal[] templateProposals = super.computeCompletionProposals( viewer, offset );
+ if ( templateProposals != null )
+ {
+ proposalList.addAll( Arrays.asList( templateProposals ) );
+ }
+
+ // changetype: xxx
+ if ( container instanceof LdifRecord )
+ {
+ LdifRecord record = ( LdifRecord ) container;
+ LdifPart[] parts = record.getParts();
+ if ( parts.length > 1 && ( !( parts[1] instanceof LdifChangeTypeLine ) || !parts[1].isValid() ) )
+ {
+ if ( CT_ADD.startsWith( prefix ) )
+ proposalList.add( new CompletionProposal( CT_ADD, offset - prefix.length(), prefix.length(), CT_ADD
+ .length(), BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_ADD ), CT_ADD
+ .substring( 0, CT_ADD.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ), null, null ) );
+ if ( CT_MODIFY.startsWith( prefix ) )
+ proposalList.add( new CompletionProposal( CT_MODIFY, offset - prefix.length(), prefix.length(),
+ CT_MODIFY.length(),
+ BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MODIFY ), CT_MODIFY
+ .substring( 0, CT_MODIFY.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ), null,
+ null ) );
+ if ( CT_DELETE.startsWith( prefix ) )
+ proposalList.add( new CompletionProposal( CT_DELETE, offset - prefix.length(), prefix.length(),
+ CT_DELETE.length(),
+ BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_DELETE ), CT_DELETE
+ .substring( 0, CT_DELETE.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ), null,
+ null ) );
+ if ( CT_MODDN.startsWith( prefix ) )
+ proposalList.add( new CompletionProposal( CT_MODDN, offset - prefix.length(), prefix.length(),
+ CT_MODDN.length(), BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_RENAME ),
+ CT_MODDN.substring( 0, CT_MODDN.length() - BrowserCoreConstants.LINE_SEPARATOR.length() ),
+ null, null ) );
+ }
+
+ }
+
+ // changetype: modify
+ if ( container instanceof LdifChangeModDnRecord )
+ {
+ LdifChangeModDnRecord record = ( LdifChangeModDnRecord ) container;
+ if ( ( record.getNewrdnLine() == null || !record.getNewrdnLine().isValid() )
+ && MD_NEWRDN.startsWith( prefix ) )
+ {
+ proposalList.add( new CompletionProposal( MD_NEWRDN, offset - prefix.length(), prefix.length(),
+ MD_NEWRDN.length(), null, null, null, null ) );
+ }
+ if ( ( record.getDeloldrdnLine() == null || !record.getDeloldrdnLine().isValid() )
+ && MD_DELETEOLDRDN_TRUE.startsWith( prefix ) )
+ {
+ proposalList.add( new CompletionProposal( MD_DELETEOLDRDN_TRUE, offset - prefix.length(), prefix
+ .length(), MD_DELETEOLDRDN_TRUE.length(), null, null, null, null ) );
+ }
+ if ( ( record.getNewsuperiorLine() == null || !record.getNewsuperiorLine().isValid() )
+ && MD_NEWSUPERIOR.startsWith( prefix ) )
+ {
+ proposalList.add( new CompletionProposal( MD_NEWSUPERIOR, offset - prefix.length(), prefix.length(),
+ MD_NEWSUPERIOR.length(), null, null, null, null ) );
+ }
+ }
+
+ // modspecs
+ if ( innerContainer instanceof LdifModSpec )
+ {
+ LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
+ String att = modSpec.getModSpecType().getRawAttributeDescription();
+ if ( att != null && att.startsWith( prefix ) )
+ {
+ proposalList.add( new CompletionProposal( att, offset - prefix.length(), prefix.length(), att.length(),
+ null, null, null, null ) );
+ }
+ }
+
+ // attribute descriptions
+ if ( container instanceof LdifContentRecord || container instanceof LdifChangeAddRecord )
+ {
+
+ if ( part instanceof LdifInvalidPart
+ || part instanceof LdifAttrValLine
+ || ( part instanceof LdifSepLine && ( container instanceof LdifContentRecord || container instanceof LdifChangeAddRecord ) ) )
+ {
+
+ String rawAttributeDescription = prefix;
+ String rawValueType = "";
+
+ if ( part instanceof LdifAttrValLine )
+ {
+ LdifAttrValLine line = ( LdifAttrValLine ) part;
+ rawAttributeDescription = line.getRawAttributeDescription();
+ rawValueType = line.getRawValueType();
+ }
+
+ if ( offset <= part.getOffset() + rawAttributeDescription.length() )
+ {
+ Schema schema = editor.getConnection() != null ? editor.getConnection().getSchema()
+ : Schema.DEFAULT_SCHEMA;
+ String[] attributeNames = schema.getAttributeTypeDescriptionNames();
+ Arrays.sort( attributeNames );
+ for ( int a = 0; a < attributeNames.length; a++ )
+ {
+ if ( rawAttributeDescription.length() == 0
+ || attributeNames[a].startsWith( rawAttributeDescription ) )
+ {
+
+ String proposal = attributeNames[a];
+
+ if ( rawValueType.length() == 0 )
+ {
+ if ( schema.getAttributeTypeDescription( proposal ).isBinary() )
+ {
+ proposal += ":: ";
+ }
+ else
+ {
+ proposal += ": ";
+ }
+ }
+
+ proposalList
+ .add( new CompletionProposal( proposal, offset - rawAttributeDescription.length(),
+ rawAttributeDescription.length(), proposal.length() ) );
+ }
+ }
+ }
+ }
+ }
+
+ // comment
+ boolean commentOnly = false;
+ if ( documentLineOffset == offset )
+ {
+ commentOnly = proposalList.isEmpty();
+ proposalList.add( new CompletionProposal( "# ", offset, 0, 2, BrowserUIPlugin.getDefault().getImage(
+ BrowserUIConstants.IMG_LDIF_COMMENT ), "# - Comment", null, null ) );
+ }
+
+ // adjust auto-insert
+ this.contentAssistant.enableAutoInsert( !commentOnly );
+
+ ICompletionProposal[] proposals = ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] );
+ return proposals;
+
+ }
+
+
+ protected String extractPrefix( ITextViewer viewer, int offset )
+ {
+
+ IDocument document = viewer.getDocument();
+ if ( offset > document.getLength() )
+ return ""; //$NON-NLS-1$
+
+ try
+ {
+ int documentLine = viewer.getDocument().getLineOfOffset( offset );
+ int documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
+ String prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
+ return prefix;
+ }
+ catch ( BadLocationException e )
+ {
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+
+ public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset )
+ {
+ return null;
+ }
+
+
+ public char[] getCompletionProposalAutoActivationCharacters()
+ {
+
+ char[] chars = new char[53];
+ for ( int i = 0; i < 26; i++ )
+ chars[i] = ( char ) ( 'a' + i );
+ for ( int i = 0; i < 26; i++ )
+ chars[i + 26] = ( char ) ( 'A' + i );
+ chars[52] = ':';
+
+ return chars;
+ }
+
+
+ public char[] getContextInformationAutoActivationCharacters()
+ {
+ return null;
+ }
+
+
+ public String getErrorMessage()
+ {
+ return null;
+ }
+
+
+ public IContextInformationValidator getContextInformationValidator()
+ {
+ return null;
+ }
+
+
+ protected Template[] getTemplates( String contextTypeId )
+ {
+ Template[] templates = BrowserUIPlugin.getDefault().getLdifTemplateStore().getTemplates( contextTypeId );
+ return templates;
+ }
+
+
+ protected TemplateContextType getContextType( ITextViewer viewer, IRegion region )
+ {
+
+ int offset = region.getOffset();
+
+ LdifFile model = editor.getLdifModel();
+ LdifContainer container = LdifFile.getContainer( model, offset );
+ LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, offset ) : null;
+ LdifPart part = container != null ? LdifFile.getContainerContent( container, offset ) : null;
+ int documentLine = -1;
+ int documentLineOffset = -1;
+ String prefix = "";
+ try
+ {
+ documentLine = viewer.getDocument().getLineOfOffset( offset );
+ documentLineOffset = viewer.getDocument().getLineOffset( documentLine );
+ prefix = viewer.getDocument().get( documentLineOffset, offset - documentLineOffset );
+ }
+ catch ( BadLocationException e )
+ {
+ }
+
+ // FILE
+ if ( container == null && innerContainer == null && part == null )
+ {
+ return BrowserUIPlugin.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+ BrowserUIConstants.LDIF_FILE_TEMPLATE_ID );
+ }
+ if ( container instanceof LdifSepContainer && innerContainer == null && part instanceof LdifSepLine )
+ {
+ return BrowserUIPlugin.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+ BrowserUIConstants.LDIF_FILE_TEMPLATE_ID );
+ }
+ if ( ( container instanceof LdifInvalidContainer && part instanceof LdifInvalidPart && "d".equals( prefix ) )
+ || ( container instanceof LdifContentRecord && part instanceof LdifInvalidPart && "dn".equals( prefix ) )
+ || ( container instanceof LdifContentRecord && part instanceof LdifInvalidPart && "dn:".equals( prefix ) ) )
+ {
+ return BrowserUIPlugin.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+ BrowserUIConstants.LDIF_FILE_TEMPLATE_ID );
+ }
+
+ // MODIFICATION RECORD
+ if ( container instanceof LdifChangeModifyRecord && innerContainer == null
+ && ( part instanceof LdifSepLine || part instanceof LdifInvalidPart ) )
+ {
+ return BrowserUIPlugin.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+ BrowserUIConstants.LDIF_MODIFICATION_RECORD_TEMPLATE_ID );
+ }
+
+ // MODIFICATION ITEM
+ if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec )
+ {
+ return BrowserUIPlugin.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+ BrowserUIConstants.LDIF_MODIFICATION_ITEM_TEMPLATE_ID );
+ }
+
+ // MODDN RECORD
+ if ( container instanceof LdifChangeModDnRecord && innerContainer == null
+ && ( part instanceof LdifSepLine || part instanceof LdifInvalidPart ) )
+ {
+ return BrowserUIPlugin.getDefault().getLdifTemplateContextTypeRegistry().getContextType(
+ BrowserUIConstants.LDIF_MODDN_RECORD_TEMPLATE_ID );
+ }
+
+ // TemplateContextType contextType =
+ // BrowserUIPlugin.getDefault().getContextTypeRegistry().getContextType(BrowserUIConstants.LDIF_FILE_TEMPLATE_ID);
+ // TemplateContextType contextType =
+ // BrowserUIPlugin.getDefault().getContextTypeRegistry().getContextType(BrowserUIConstants.LDIF_MODIFICATION_RECORD_TEMPLATE_ID);
+
+ return null;
+
+ }
+
+
+ protected Image getImage( Template template )
+ {
+
+ if ( template.getPattern().indexOf( "add: " ) > -1 )
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MOD_ADD );
+ }
+ else if ( template.getPattern().indexOf( "replace: " ) > -1 )
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MOD_REPLACE );
+ }
+ else if ( template.getPattern().indexOf( "delete: " ) > -1 )
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MOD_DELETE );
+ }
+
+ else if ( template.getPattern().indexOf( "changetype: add" ) > -1 )
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_ADD );
+ }
+ else if ( template.getPattern().indexOf( "changetype: modify" ) > -1 )
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MODIFY );
+ }
+ else if ( template.getPattern().indexOf( "changetype: delete" ) > -1 )
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_DELETE );
+ }
+ else if ( template.getPattern().indexOf( "changetype: moddn" ) > -1 )
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_RENAME );
+ }
+ else if ( template.getPattern().indexOf( "dn: " ) > -1 )
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_ENTRY );
+ }
+
+ else
+ {
+ return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_TEMPLATE );
+ }
+
+ }
+
+}