directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r811139 - in /directory/studio/trunk/ldapbrowser-ui: ./ src/main/java/org/apache/directory/studio/entryeditors/ src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/
Date Thu, 03 Sep 2009 21:40:07 GMT
Author: seelmann
Date: Thu Sep  3 21:40:07 2009
New Revision: 811139

URL: http://svn.apache.org/viewvc?rev=811139&view=rev
Log:
DIRSTUDIO-515: First version of an LDIF entry editor (multi-tab)

Added:
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorUtils.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditor.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditorDocumentProvider.java
Modified:
    directory/studio/trunk/ldapbrowser-ui/plugin.properties
    directory/studio/trunk/ldapbrowser-ui/plugin.xml

Modified: directory/studio/trunk/ldapbrowser-ui/plugin.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/plugin.properties?rev=811139&r1=811138&r2=811139&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/plugin.properties (original)
+++ directory/studio/trunk/ldapbrowser-ui/plugin.properties Thu Sep  3 21:40:07 2009
@@ -31,6 +31,10 @@
 Editor_MultiTabEntryEditor_shortname=Entry Editor
 Editor_MultiTabEntryEditor_fullname=Entry Editor (multi-tab)
 Editor_MultiTabEntryEditor_description=Opens each entry in a separate editor tab.
+Editor_MultiTabLdifEntryEditor_id=org.apache.directory.studio.ldapbrowser.ui.editors.entry.MultiTabLdifEntryEditor
+Editor_MultiTabLdifEntryEditor_shortname=LDIF Entry Editor
+Editor_MultiTabLdifEntryEditor_fullname=LDIF Entry Editor (multi-tab)
+Editor_MultiTabLdifEntryEditor_description=Opens each entry in a separate editor tab.
 
 Editor_SearchResultEditor_id=org.apache.directory.studio.ldapbrowser.ui.editors.searchresult.SearchResultEditor
 Editor_SearchResultEditor_name=Search Result Editor

Modified: directory/studio/trunk/ldapbrowser-ui/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/plugin.xml?rev=811139&r1=811138&r2=811139&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/plugin.xml (original)
+++ directory/studio/trunk/ldapbrowser-ui/plugin.xml Thu Sep  3 21:40:07 2009
@@ -53,6 +53,13 @@
        name="%Editor_MultiTabEntryEditor_shortname">
  </editor>
  <editor
+       class="org.apache.directory.studio.ldapbrowser.ui.editors.entry.MultiTabLdifEntryEditor"
+       default="true"
+       icon="resources/icons/browser_entryeditor.gif"
+       id="%Editor_MultiTabLdifEntryEditor_id"
+       name="%Editor_MultiTabLdifEntryEditor_shortname">
+ </editor>
+ <editor
        class="org.apache.directory.studio.ldapbrowser.ui.editors.searchresult.SearchResultEditor"
        default="true"
        icon="resources/icons/browser_searchresulteditor.gif"
@@ -460,6 +467,16 @@
           priority="1"
           multiWindow="true">
     </entryEditor>
+    <entryEditor
+          class="org.apache.directory.studio.ldapbrowser.ui.editors.entry.MultiTabLdifEntryEditor"
+          description="%Editor_MultiTabLdifEntryEditor_description"
+          editorId="%Editor_MultiTabLdifEntryEditor_id"
+          icon="resources/icons/browser_entryeditor.gif"
+          id="%Editor_MultiTabLdifEntryEditor_id"
+          multiWindow="true"
+          name="%Editor_MultiTabLdifEntryEditor_fullname"
+          priority="1">
+    </entryEditor>
  </extension>
 
 </plugin>

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorUtils.java?rev=811139&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorUtils.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorUtils.java
Thu Sep  3 21:40:07 2009
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.entryeditors;
+
+import org.apache.directory.studio.connection.ui.RunnableContextRunner;
+import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesRunnable;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+
+public class EntryEditorUtils
+{
+
+    /**
+     * Checks if the attributes of the given entry are initialized and 
+     * initializes them in necessary.
+     * 
+     * @param entry the entry
+     */
+    public static void ensureAttributesInitialized( IEntry entry )
+    {
+        if ( !entry.isAttributesInitialized() )
+        {
+            boolean foa = entry.getBrowserConnection().isFetchOperationalAttributes();
+            InitializeAttributesRunnable iar = new InitializeAttributesRunnable( new IEntry[]
+                { entry }, foa );
+            RunnableContextRunner.execute( iar, null, true );
+        }
+    }
+    
+}

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditor.java?rev=811139&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditor.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditor.java
Thu Sep  3 21:40:07 2009
@@ -0,0 +1,64 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.ui.editors.entry;
+
+
+import org.apache.directory.studio.ldifeditor.editor.LdifEditor;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * An entry editor that uses LDIF format.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class MultiTabLdifEntryEditor extends LdifEditor
+{
+
+    public MultiTabLdifEntryEditor()
+    {
+        super();
+
+        // use our own document provider that saves changes to the directory
+        setDocumentProvider( new MultiTabLdifEntryEditorDocumentProvider() );
+    }
+
+
+    @Override
+    public void createPartControl( Composite parent )
+    {
+        // don't show the tool bar
+        showToolBar = false;
+
+        super.createPartControl( parent );
+    }
+
+
+    @Override
+    public boolean isSaveAsAllowed()
+    {
+        // Allowing "Save As..." requires an IPathEditorInput.
+        // Would makes things much more complex, maybe we could add this later.
+        return false;
+    }
+
+}

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditorDocumentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditorDocumentProvider.java?rev=811139&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditorDocumentProvider.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/entry/MultiTabLdifEntryEditorDocumentProvider.java
Thu Sep  3 21:40:07 2009
@@ -0,0 +1,152 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.ui.editors.entry;
+
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.studio.connection.ui.RunnableContextRunner;
+import org.apache.directory.studio.entryeditors.EntryEditorInput;
+import org.apache.directory.studio.entryeditors.EntryEditorUtils;
+import org.apache.directory.studio.ldapbrowser.core.jobs.ExecuteLdifRunnable;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry;
+import org.apache.directory.studio.ldapbrowser.core.utils.ModelConverter;
+import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldifeditor.editor.LdifDocumentProvider;
+import org.apache.directory.studio.ldifparser.LdifFormatParameters;
+import org.apache.directory.studio.ldifparser.model.container.LdifChangeModifyRecord;
+import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
+import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+
+
+/**
+ * The document provider for the LDIF entry editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class MultiTabLdifEntryEditorDocumentProvider extends LdifDocumentProvider
+{
+
+    @Override
+    protected void doSaveDocument( IProgressMonitor monitor, Object element, IDocument document,
boolean overwrite )
+        throws CoreException
+    {
+        IEntry entry = getResolvedEntry( element );
+        IBrowserConnection browserConnection = entry.getBrowserConnection();
+
+        LdifChangeModifyRecord diff = getDiff( entry );
+        if ( diff != null )
+        {
+            // save by executing the LDIF
+            ExecuteLdifRunnable runnable = new ExecuteLdifRunnable( browserConnection, diff
+                .toFormattedString( LdifFormatParameters.DEFAULT ), false, false );
+            IStatus status = RunnableContextRunner.execute( runnable, null, true );
+            if ( !status.isOK() )
+            {
+                return;
+            }
+        }
+
+        // if no difference or if saved successful: refresh input and clean dirty state
+        entry = getResolvedEntry( element );
+        LdifContentRecord record = ModelConverter.entryToLdifContentRecord( entry );
+        String content = record.toFormattedString( Utils.getLdifFormatParameters() );
+        getDocument( element ).set( content );
+    }
+
+
+    /**
+     * Gets the difference between the original entry and the modified entry.
+     * 
+     * @return the difference
+     */
+    private LdifChangeModifyRecord getDiff( IEntry originalEntry ) throws CoreException
+    {
+        LdifRecord[] records = getLdifModel().getRecords();
+        if ( records.length != 1 || !( records[0] instanceof LdifContentRecord ) )
+        {
+            throw new CoreException( new Status( IStatus.ERROR, BrowserUIConstants.PLUGIN_ID,
+                "Expected exactly one LDIF content record." ) );
+        }
+
+        try
+        {
+            LdifContentRecord modifiedRecord = ( LdifContentRecord ) records[0];
+            DummyEntry modifiedEntry = ModelConverter.ldifContentRecordToEntry( modifiedRecord,
originalEntry
+                .getBrowserConnection() );
+            LdifChangeModifyRecord record = Utils.computeDiff( originalEntry, modifiedEntry
);
+            return record;
+        }
+        catch ( InvalidNameException e )
+        {
+            throw new RuntimeException( "Failed to set input", e );
+        }
+    }
+
+
+    @Override
+    protected IDocument createDocument( Object element ) throws CoreException
+    {
+        IEntry entry = getResolvedEntry( element );
+        LdifContentRecord record = ModelConverter.entryToLdifContentRecord( entry );
+        String content = record.toFormattedString( Utils.getLdifFormatParameters() );
+
+        IDocument document = new Document();
+        document.set( content );
+        setupDocument( document );
+        return document;
+    }
+
+
+    private IEntry getResolvedEntry( Object element ) throws CoreException
+    {
+        if ( element instanceof EntryEditorInput )
+        {
+            EntryEditorInput input = ( EntryEditorInput ) element;
+            IEntry entry = input.getResolvedEntry();
+            EntryEditorUtils.ensureAttributesInitialized( entry );
+            return entry;
+        }
+        else
+        {
+            throw new CoreException( new Status( IStatus.ERROR, BrowserUIConstants.PLUGIN_ID,
+                "Expected MultiTabLdifEntryEditorInput, was " + element ) );
+        }
+    }
+
+
+    @Override
+    public boolean isModifiable( Object element )
+    {
+        return element instanceof EntryEditorInput;
+    }
+
+}



Mime
View raw message