directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r658216 - in /directory/studio/branches/1.1.0/rcp: ./ META-INF/ src/main/java/org/apache/directory/studio/actions/ src/main/resources/org/apache/directory/studio/
Date Tue, 20 May 2008 12:31:57 GMT
Author: pamarcelot
Date: Tue May 20 05:31:57 2008
New Revision: 658216

URL: http://svn.apache.org/viewvc?rev=658216&view=rev
Log:
Fix for DIRSTUDIO-330 (CoreException raised in editor when opening a *.txt file).

Removed:
    directory/studio/branches/1.1.0/rcp/src/main/java/org/apache/directory/studio/actions/PathEditorInput.java
Modified:
    directory/studio/branches/1.1.0/rcp/META-INF/MANIFEST.MF
    directory/studio/branches/1.1.0/rcp/pom.xml
    directory/studio/branches/1.1.0/rcp/src/main/java/org/apache/directory/studio/actions/OpenFileAction.java
    directory/studio/branches/1.1.0/rcp/src/main/resources/org/apache/directory/studio/messages.properties

Modified: directory/studio/branches/1.1.0/rcp/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/rcp/META-INF/MANIFEST.MF?rev=658216&r1=658215&r2=658216&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/rcp/META-INF/MANIFEST.MF (original)
+++ directory/studio/branches/1.1.0/rcp/META-INF/MANIFEST.MF Tue May 20 05:31:57 2008
@@ -10,7 +10,10 @@
  org.eclipse.update.core,
  org.eclipse.update.ui,
  org.eclipse.ui,
- org.eclipse.ui.intro
+ org.eclipse.ui.intro,
+ org.eclipse.core.resources,
+ org.eclipse.ui.ide,
+ org.eclipse.core.filesystem
 Eclipse-LazyStart: true
 Bundle-ClassPath: .,
  lib/nlog4j-1.2.25.jar

Modified: directory/studio/branches/1.1.0/rcp/pom.xml
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/rcp/pom.xml?rev=658216&r1=658215&r2=658216&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/rcp/pom.xml (original)
+++ directory/studio/branches/1.1.0/rcp/pom.xml Tue May 20 05:31:57 2008
@@ -165,6 +165,21 @@
       <artifactId>ui</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.eclipse.ui</groupId>
+      <artifactId>ide</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.core</groupId>
+      <artifactId>resources</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.core</groupId>
+      <artifactId>filesystem</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
 </project>

Modified: directory/studio/branches/1.1.0/rcp/src/main/java/org/apache/directory/studio/actions/OpenFileAction.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/rcp/src/main/java/org/apache/directory/studio/actions/OpenFileAction.java?rev=658216&r1=658215&r2=658216&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/rcp/src/main/java/org/apache/directory/studio/actions/OpenFileAction.java
(original)
+++ directory/studio/branches/1.1.0/rcp/src/main/java/org/apache/directory/studio/actions/OpenFileAction.java
Tue May 20 05:31:57 2008
@@ -21,27 +21,24 @@
 package org.apache.directory.studio.actions;
 
 
-import java.io.File;
 import java.text.MessageFormat;
 
 import org.apache.directory.studio.Messages;
-import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.IFileStore;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorRegistry;
-import org.eclipse.ui.IPathEditorInput;
-import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
 
 
 /**
@@ -54,10 +51,6 @@
 public class OpenFileAction extends Action implements IWorkbenchWindowActionDelegate
 {
 
-    /** The workbench window */
-    private IWorkbenchWindow workbenchWindow;
-
-
     /**
      * Creates a new instance of OpenFileAction.
      */
@@ -81,27 +74,32 @@
         init( window );
     }
 
+    private IWorkbenchWindow window;
+    private String filterPath;
 
-    /**
-     * {@inheritDoc}
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
      */
     public void dispose()
     {
-        workbenchWindow = null;
+        window = null;
+        filterPath = null;
     }
 
 
-    /**
-     * {@inheritDoc}
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
      */
     public void init( IWorkbenchWindow window )
     {
-        workbenchWindow = window;
+        this.window = window;
+        filterPath = System.getProperty( "user.home" ); //$NON-NLS-1$
     }
 
 
-    /**
-     * {@inheritDoc}
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
      */
     public void run( IAction action )
     {
@@ -109,81 +107,66 @@
     }
 
 
-    /**
-     * {@inheritDoc}
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
org.eclipse.jface.viewers.ISelection)
      */
     public void selectionChanged( IAction action, ISelection selection )
     {
     }
 
 
-    /**
-     * {@inheritDoc}
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.action.Action#run()
      */
     public void run()
     {
-        // get path
-        FileDialog dialog = new FileDialog( workbenchWindow.getShell(), SWT.OPEN );
-        dialog.setText( Messages.getString( "OpenFileAction.Open_File" ) ); //$NON-NLS-1$
-        String path = dialog.open();
-        if ( path == null || path.length() == 0 )
-        {
-            // canceled
-            return;
-        }
-
-        // check file 
-        File file = new File( path );
-        if ( !file.exists() )
-        {
-            String msg = MessageFormat.format(
-                Messages.getString( "OpenFileAction.File_x_does_not_exist" ), new Object[]
//$NON-NLS-1$
-                    { file.getName() } );
-            MessageDialog.openWarning( workbenchWindow.getShell(), Messages
-                .getString( "OpenFileAction.Warning_message" ), msg ); //$NON-NLS-1$
-            return;
-        }
-        if ( !file.canRead() )
-        {
-            String msg = MessageFormat.format(
-                Messages.getString( "OpenFileAction.File_x_is_not_readable" ), new Object[]
//$NON-NLS-1$
-                    { file.getName() } );
-            MessageDialog.openWarning( workbenchWindow.getShell(), Messages
-                .getString( "OpenFileAction.Warning_message" ), msg ); //$NON-NLS-1$
-            return;
-        }
-
-        // get editor for this file
-        IWorkbench workbench = workbenchWindow.getWorkbench();
-        IEditorRegistry editorRegistry = workbench.getEditorRegistry();
-        IEditorDescriptor descriptor = editorRegistry.getDefaultEditor( file.getName() );
-
-        if ( descriptor == null )
-        {
-            String msg = MessageFormat.format(
-                Messages.getString( "OpenFileAction.No_appropriate_editor_found_for_x" ),
new Object[] //$NON-NLS-1$
-                { file.getName() } );
-            MessageDialog.openWarning( workbenchWindow.getShell(), Messages
-                .getString( "OpenFileAction.Warning_message" ), msg ); //$NON-NLS-1$
-            return;
-        }
-
-        // create IEdiorInput
-        IPath location = new Path( file.getAbsolutePath() );
-        ImageDescriptor imageDescriptor = descriptor.getImageDescriptor();
-        IPathEditorInput input = new PathEditorInput( location, imageDescriptor );
-
-        // activate editor
-        IWorkbenchPage page = workbenchWindow.getActivePage();
-        String editorId = descriptor.getId();
-        try
-        {
-            page.openEditor( input, editorId );
-        }
-        catch ( PartInitException e )
-        {
-            e.printStackTrace();
+        FileDialog dialog = new FileDialog( window.getShell(), SWT.OPEN | SWT.MULTI );
+        dialog.setText( Messages.getString( "OpenFileAction.Open_File" ) );
+        dialog.setFilterPath( filterPath );
+        dialog.open();
+        String[] names = dialog.getFileNames();
+
+        if ( names != null )
+        {
+            filterPath = dialog.getFilterPath();
+
+            int numberOfFilesNotFound = 0;
+            StringBuffer notFound = new StringBuffer();
+            IWorkbenchPage page = window.getActivePage();
+            for ( String name : names )
+            {
+                IFileStore fileStore = EFS.getLocalFileSystem().getStore( new Path( filterPath
) ).getChild( name );
+                IFileInfo fetchInfo = fileStore.fetchInfo();
+                if ( !fetchInfo.isDirectory() && fetchInfo.exists() )
+                {
+                    try
+                    {
+                        IDE.openEditorOnFileStore( page, fileStore );
+                    }
+                    catch ( PartInitException e )
+                    {
+                        MessageDialog.openError( window.getShell(), Messages.getString( "OpenFileAction.Error"
), e
+                            .getMessage() );
+                    }
+                }
+                else
+                {
+                    if ( ++numberOfFilesNotFound > 1 )
+                    {
+                        notFound.append( '\n' );
+                    }
+                    notFound.append( fileStore.getName() );
+                }
+            }
+
+            if ( numberOfFilesNotFound > 0 )
+            {
+                String msg = MessageFormat.format( numberOfFilesNotFound == 1 ? Messages
+                    .getString( "OpenFileAction.File_not_found" ) : Messages
+                    .getString( "OpenFileAction.Files_not_found" ), new Object[]
+                    { notFound.toString() } );
+                MessageDialog.openError( window.getShell(), Messages.getString( "OpenFileAction.Error"
), msg );
+            }
         }
     }
-
 }
\ No newline at end of file

Modified: directory/studio/branches/1.1.0/rcp/src/main/resources/org/apache/directory/studio/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/rcp/src/main/resources/org/apache/directory/studio/messages.properties?rev=658216&r1=658215&r2=658216&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/rcp/src/main/resources/org/apache/directory/studio/messages.properties
(original)
+++ directory/studio/branches/1.1.0/rcp/src/main/resources/org/apache/directory/studio/messages.properties
Tue May 20 05:31:57 2008
@@ -42,11 +42,10 @@
 
 # Strings used by OpenFileAction Class
 OpenFileAction.Open_File=Open File...
-OpenFileAction.Warning_message=Problem
 OpenFileAction.Open_file_from_filesystem=Open file from filesystem
-OpenFileAction.File_x_does_not_exist=File {0} doesn't exist.
-OpenFileAction.File_x_is_not_readable=File {0} isn't readable.
-OpenFileAction.No_appropriate_editor_found_for_x=No appropriate editor found for {0}.
+OpenFileAction.File_not_found=The file ''{0}'' could not be found.
+OpenFileAction.Files_not_found=The following files could not be found:\n{0}
+OpenFileAction.Error=Error!
 
 # Strings used by ReportABugAction Class
 ReportABugAction.Report_a_bug=Report a bug...



Mime
View raw message