Adding warning that large file will not be shown fully. Feature #848
authorzev <zev@radensolutions.com>
Tue, 7 Jul 2015 14:24:47 +0000 (17:24 +0300)
committerzev <zev@radensolutions.com>
Tue, 7 Jul 2015 14:25:09 +0000 (17:25 +0300)
ChangeLog
src/java/netxms-eclipse/FileManager/src/org/netxms/ui/eclipse/filemanager/views/AgentFileManager.java
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolExecutor.java
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/views/FileViewer.java
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/widgets/TextViewWidget.java [copied from src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/views/FileViewer.java with 53% similarity]
webui/webapp/FileManager/src/org/netxms/ui/eclipse/filemanager/views/AgentFileManager.java
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolExecutor.java
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/views/FileViewer.java
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/widgets/TextViewWidget.java [copied from webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/views/FileViewer.java with 58% similarity]

index f7a3a16..6b2a874 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,7 +4,7 @@
 
 - Fixed LDAP authentication issues with Active Directory
 - Java subagent improved
-- Fixed issues: #836, #843, #845, #846
+- Fixed issues: #836, #843, #845, #846, #848
 
 
 *
index ccf61fa..2d0abcf 100644 (file)
@@ -917,14 +917,12 @@ public class AgentFileManager extends ViewPart
             runInUIThread(new Runnable() {
                @Override
                public void run()
-               {
+               {                  
                   final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                   try
                   {
                      String secondaryId = Long.toString(objectId) + "&" + URLEncoder.encode(sf.getName(), "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
-                     FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
-                           IWorkbenchPage.VIEW_ACTIVATE);
-                     view.showFile(file.getFile(), tail, file.getId(), offset);
+                     FileViewer.createView(window, getSite().getShell(), file, tail, offset, secondaryId, objectId);
                   }
                   catch(Exception e)
                   {
index 56d0b8a..d7d38a7 100644 (file)
@@ -329,9 +329,7 @@ public final class ObjectToolExecutor
                   try
                   {
                      String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
-                     FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
-                           IWorkbenchPage.VIEW_ACTIVATE);
-                     view.showFile(file.getFile(), follow, file.getId(), maxFileSize);
+                     FileViewer.createView(window, window.getShell(), file, follow, maxFileSize, secondaryId, node.object.getObjectId());
                   }
                   catch(Exception e)
                   {
index 8415946..1954558 100644 (file)
  */
 package org.netxms.ui.eclipse.objecttools.views;
 
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
-import java.util.Arrays;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.commands.ActionHandler;
-import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IActionBars;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.contexts.IContextService;
-import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.part.ViewPart;
 import org.netxms.client.AgentFile;
 import org.netxms.client.NXCSession;
-import org.netxms.client.SessionListener;
-import org.netxms.client.SessionNotification;
 import org.netxms.client.objects.AbstractObject;
-import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objecttools.Activator;
 import org.netxms.ui.eclipse.objecttools.Messages;
+import org.netxms.ui.eclipse.objecttools.widgets.TextViewWidget;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 
 /**
  * File viewer
@@ -65,21 +47,10 @@ public class FileViewer extends ViewPart
 {
        public static final String ID = "org.netxms.ui.eclipse.objecttools.views.FileViewer"; //$NON-NLS-1$
        
-       private long nodeId;
-       private String remoteFileName;
-   private String fileID;
-       private File currentFile;
-       private StyledText textViewer;
-       private final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-       private boolean follow;
-       private ConsoleJob monitorJob;
-   private ConsoleJob tryToRestartMonitoring;
-   private Action actionClear;
-       private Action actionScrollLock;
-   private Action actionCopy;
-   private Action actionSelectAll;
-   private long offset = 0;
-   private SessionListener listener;
+   private final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+   private TextViewWidget textViewer;
+   private String remoteFileName;
+   private long nodeId;
        
        /* (non-Javadoc)
         * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
@@ -116,22 +87,9 @@ public class FileViewer extends ViewPart
         */
        @Override
        public void createPartControl(Composite parent)
-       {
-               textViewer = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL);
-               textViewer.setEditable(false);
-               textViewer.setFont(JFaceResources.getTextFont());
-               textViewer.addSelectionListener(new SelectionAdapter() {
-         @Override
-         public void widgetSelected(SelectionEvent e)
-         {
-            actionCopy.setEnabled(textViewer.getSelectionCount() > 0);
-         }
-      });
-
-               createActions();
-               contributeToActionBars();
-      createPopupMenu();
-      activateContext();
+       {          
+          textViewer = new TextViewWidget(parent, SWT.BORDER, remoteFileName, nodeId, this);   
+      activateContext();               
        }
        
    /**
@@ -145,319 +103,36 @@ public class FileViewer extends ViewPart
          contextService.activateContext("org.netxms.ui.eclipse.objecttools.context.FileViewer"); //$NON-NLS-1$
       }
    }
-
-   /**
-    * Create actions
-    */
-   private void createActions()
-   {
-      final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
-      
-      actionClear = new Action(Messages.get().FileViewer_ClearOutput, SharedIcons.CLEAR_LOG) {
-         @Override
-         public void run()
-         {
-            textViewer.setText(""); //$NON-NLS-1$
-         }
-      };
-      actionClear.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.clear_output"); //$NON-NLS-1$
-      handlerService.activateHandler(actionClear.getActionDefinitionId(), new ActionHandler(actionClear));
-
-      actionScrollLock = new Action(Messages.get().FileViewer_ScrollLock, Action.AS_CHECK_BOX) { 
-         @Override
-         public void run()
-         {
-         }
-      };
-      actionScrollLock.setImageDescriptor(Activator.getImageDescriptor("icons/scroll_lock.gif")); //$NON-NLS-1$
-      actionScrollLock.setChecked(false);
-      actionScrollLock.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.scroll_lock"); //$NON-NLS-1$
-      handlerService.activateHandler(actionScrollLock.getActionDefinitionId(), new ActionHandler(actionScrollLock));
-
-      actionCopy = new Action(Messages.get().LocalCommandResults_Copy) {
-         @Override
-         public void run()
-         {
-            textViewer.copy();
-         }
-      };
-      actionCopy.setEnabled(false);
-      actionCopy.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.copy"); //$NON-NLS-1$
-      handlerService.activateHandler(actionCopy.getActionDefinitionId(), new ActionHandler(actionCopy));
-      
-      actionSelectAll = new Action(Messages.get().LocalCommandResults_SelectAll) {
-         @Override
-         public void run()
-         {
-            textViewer.selectAll();
-            actionCopy.setEnabled(textViewer.getSelectionCount() > 0);
-         }
-      };
-      actionSelectAll.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.select_all"); //$NON-NLS-1$
-      handlerService.activateHandler(actionSelectAll.getActionDefinitionId(), new ActionHandler(actionSelectAll));
-   }
-   
-   /**
-    * Contribute actions to action bar
-    */
-   private void contributeToActionBars()
-   {
-      IActionBars bars = getViewSite().getActionBars();
-      fillLocalPullDown(bars.getMenuManager());
-      fillLocalToolBar(bars.getToolBarManager());
-   }
-
-   /**
-    * Fill local pull-down menu
-    * 
-    * @param manager
-    *           Menu manager for pull-down menu
-    */
-   private void fillLocalPullDown(IMenuManager manager)
-   {
-      manager.add(actionClear);
-      manager.add(actionScrollLock);
-      manager.add(new Separator());
-      manager.add(actionSelectAll);
-      manager.add(actionCopy);
-   }
-
-   /**
-    * Fill local tool bar
-    * 
-    * @param manager
-    *           Menu manager for local toolbar
-    */
-   private void fillLocalToolBar(IToolBarManager manager)
-   {
-      manager.add(actionClear);
-      manager.add(actionScrollLock);
-   }
-
-   /**
-    * Create pop-up menu
-    */
-   private void createPopupMenu()
-   {
-      // Create menu manager
-      MenuManager menuMgr = new MenuManager();
-      menuMgr.setRemoveAllWhenShown(true);
-      menuMgr.addMenuListener(new IMenuListener() {
-         public void menuAboutToShow(IMenuManager mgr)
-         {
-            fillContextMenu(mgr);
-         }
-      });
-
-      // Create menu
-      Menu menu = menuMgr.createContextMenu(textViewer);
-      textViewer.setMenu(menu);
-   }
-
-   /**
-    * Fill context menu
-    * 
-    * @param mgr Menu manager
+       
+       /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
     */
-   private void fillContextMenu(final IMenuManager manager)
+   @Override
+   public void setFocus()
    {
-      manager.add(actionClear);
-      manager.add(actionScrollLock);
-      manager.add(new Separator());
-      manager.add(actionSelectAll);
-      manager.add(actionCopy);
+      textViewer.setFocus();
    }
-
-   /* (non-Javadoc)
-        * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
-        */
-       @Override
-       public void setFocus()
-       {
-               textViewer.setFocus();
-       }
-
+       
        /**
-        * @param file
-        * @param maxFileSize 
+        * Method that checks that file does not exceed allowed size.
+        * In case if file is too large asks if it should be opened partly. 
+        * @throws PartInitException 
         */
-   public void showFile(File file, boolean follow, String id, int maxFileSize)
+       public static boolean createView(IWorkbenchWindow window, Shell shell, final AgentFile file, boolean tail, int offset, String secondaryId, final long nodeId) throws PartInitException
        {
-               currentFile = file;
-      fileID = id;
-      offset = maxFileSize;
-               setContent(loadFile(currentFile));
-      textViewer.setTopIndex(textViewer.getLineCount());
-               this.follow = follow;
-               if (follow)
-               {
-               monitorJob = new ConsoleJob(Messages.get().FileViewer_Download_File_Updates, null, Activator.PLUGIN_ID, null) {
-                  private boolean continueWork = true;
-                  
-                  @Override
-                  protected void canceling() 
-                  {
-                     continueWork = false;
-                  }
-                  
-            @Override
-            protected void runInternal(IProgressMonitor monitor) throws Exception
-            {
-               while(continueWork)
-               {
-                  final String s = session.waitForFileTail(fileID, 3000);
-                  if (s != null)
-                  {
-                     runInUIThread(new Runnable() {                  
-                        @Override
-                        public void run()
-                        {
-                           if (!textViewer.isDisposed())
-                           {
-                              appendContent(s);                               
-                              if(!actionScrollLock.isChecked())
-                              {
-                                 textViewer.setTopIndex(textViewer.getLineCount() - 1);
-                              }
-                           }
-                        }
-                     });
-                  }                    
-               }
-            }
-   
-            @Override
-            protected String getErrorMessage()
-            {
-               return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, remoteFileName, nodeId);
-            }
-               };
-               monitorJob.setUser(false);
-               monitorJob.setSystem(true);
-               monitorJob.start();
-               
-               listener = new SessionListener() {
-            
-            @Override
-            public void notificationHandler(SessionNotification n)
-            {
-               switch(n.getCode())
-               {
-                  case SessionNotification.FILE_MONITORING_FAILED:    
-                     //Check that this is applicable on current file
-                     if(nodeId == n.getSubCode())
-                        onFileMonitoringFail();
-                     break;
-               }
-            }
-         };
-               
-               session.addListener(listener);
-               }
-       }
-   
-   private void onFileMonitoringFail()
-   {
-      tryToRestartMonitoring = new ConsoleJob(Messages.get().FileViewer_RestartFollowingJob, null, Activator.PLUGIN_ID, null) {
-         private boolean continueWork = true;
-         
-         @Override
-         protected void canceling() 
-         {
-            continueWork = false;
-         }
-         
-         @Override
-         protected void runInternal(IProgressMonitor monitor) throws Exception
-         {
-            runInUIThread(new Runnable() {                  
-               @Override
-               public void run()
-               {
-                  if (!textViewer.isDisposed())
-                  {
-                     textViewer.setForeground(new Color(getDisplay(), 255, 0, 0));
-                     textViewer.append(" \n\n" + //$NON-NLS-1$
-                               "----------------------------------------------------------------------\n" + //$NON-NLS-1$
-                               Messages.get().FileViewer_NotifyFollowConnectionLost +
-                               "\n----------------------------------------------------------------------" + //$NON-NLS-1$
-                               "\n");   //$NON-NLS-1$
-                     if(!actionScrollLock.isChecked())
-                     {
-                        textViewer.setTopIndex(textViewer.getLineCount() - 1);
-                     }
-                  }
-               }
-            });    
-            
-            //Try to reconnect in loop every 20 sec.            
-            while(continueWork)
-            {
-               try 
-               {
-                  final AgentFile file = session.downloadFileFromAgent(nodeId, remoteFileName, offset, follow);
-                  
-                  //When successfully connected - display notification to client.
-                  runInUIThread(new Runnable() {                  
-                     @Override
-                     public void run()
-                     {
-                        if (!textViewer.isDisposed())
-                        {
-                           textViewer.append(
-                                 "-------------------------------------------------------------------------------\n" + //$NON-NLS-1$
-                                 Messages.get().FileViewer_NotifyFollowConnectionEnabed +
-                                 "\n-------------------------------------------------------------------------------" + //$NON-NLS-1$
-                                       "\n \n");   //$NON-NLS-1$
-                           textViewer.setForeground(null);
-                           loadFile(file.getFile());
-                           if(!actionScrollLock.isChecked())
-                           {
-                              textViewer.setTopIndex(textViewer.getLineCount() - 1);
-                           }
-                        }
-                     }
-                  });         
-                  
-                  continueWork = false;
-               }
-               catch(Exception e)
-               {                  
-               }
-               Thread.sleep(20000);  
-            }      
-            
-         }
-
-         @Override
-         protected String getErrorMessage()
-         {
-            return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, remoteFileName, nodeId);
-         }
-      };
-      tryToRestartMonitoring.setUser(false);
-      tryToRestartMonitoring.setSystem(true);
-      tryToRestartMonitoring.start();      
-   }
-   
-   /* (non-Javadoc)
-    * @see org.eclipse.ui.part.WorkbenchPart#dispose()
-    */
-   @Override
-   public void dispose()
-   {
-      if (follow)
+          boolean exceedSize = file.getFile().length() > TextViewWidget.MAX_FILE_SIZE;
+          if(exceedSize && !MessageDialogHelper.openConfirm(shell, "File is too large",
+                  "File is too large to be fully shown. Click OK to see beginning of the file."))
       {
-         monitorJob.cancel();
-         if(tryToRestartMonitoring != null)
-            tryToRestartMonitoring.cancel();
-         if(tryToRestartMonitoring == null || tryToRestartMonitoring.getState() != Job.RUNNING)
-         {
-            final ConsoleJob job = new ConsoleJob(Messages.get().FileViewer_Stop_File_Monitoring, null, Activator.PLUGIN_ID, null) {
+             if(tail)
+             {
+                final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+
+             final ConsoleJob job = new ConsoleJob(Messages.get().FileViewer_Stop_File_Monitoring, null, Activator.PLUGIN_ID, null) {
                @Override
                protected void runInternal(IProgressMonitor monitor) throws Exception
                {
-                  session.cancelFileMonitoring(nodeId, fileID);
+                  session.cancelFileMonitoring(nodeId, file.getId());
                }
                
                @Override
@@ -470,110 +145,12 @@ public class FileViewer extends ViewPart
             job.setSystem(true);
             job.start();
          }
+         return false;
       }
-      session.removeListener(listener);
-      super.dispose();
-   }
-       
-       /**
-        * @param file
-        */
-       private String loadFile(File file)
-       {
-               StringBuilder content = new StringBuilder();
-               FileReader reader = null;
-               char[] buffer = new char[32768];
-               try
-               {
-                       reader = new FileReader(file);
-                       int size = 0;
-                       while(size < 8192000)
-                       {
-                               int count = reader.read(buffer);
-                               if (count == -1)
-                                       break;
-                               if (count == buffer.length)
-                               {
-                                       content.append(buffer);
-                               }
-                               else
-                               {
-                                       content.append(Arrays.copyOf(buffer, count));
-                               }
-                               size += count;
-                       }
-               }
-               catch(IOException e)
-               {
-                       e.printStackTrace();
-               }
-               finally
-               {
-                       if (reader != null)
-                       {
-                               try
-                               {
-                                       reader.close();
-                               }
-                               catch(IOException e)
-                               {
-                               }
-                       }
-               }
-               return content.toString();
-       }
-       
-       /**
-        * @param s
-        */
-       private void setContent(String s)
-       {
-          textViewer.setText(removeEscapeSequences(s));
-       }
-       
-       /**
-        * @param s
-        */
-       private void appendContent(String s)
-       {
-          textViewer.append(removeEscapeSequences(s));
-       }
-       
-       /**
-        * Remove escape sequences from input string
-        * 
-        * @param s
-        * @return
-        */
-       private static String removeEscapeSequences(String s)
-       {
-          StringBuilder sb = new StringBuilder();
-          for(int i = 0; i < s.length(); i++)
-          {
-             char ch = s.charAt(i);
-             if (ch == 27)
-             {
-                i++;
-                ch = s.charAt(i);
-                if (ch == '[')
-                {
-                for(; i < s.length(); i++)
-                {
-                   ch = s.charAt(i);
-                   if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
-                      break;
-                }
-                }
-                else if ((ch == '(') || (ch == ')'))
-                {
-                   i++;
-                }
-             }
-             else if ((ch >= 32) || (ch == '\r') || (ch == '\n') || (ch == '\t'))
-             {
-                sb.append(ch);
-             }
-          }
-          return sb.toString();
-       }
+          FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
+            IWorkbenchPage.VIEW_ACTIVATE);
+          view.textViewer.showFile(file.getFile(), tail, file.getId(), offset, exceedSize);
+          
+          return true;
+       }        
 }
@@ -1,28 +1,8 @@
-/**
- * NetXMS - open source network management system
- * Copyright (C) 2003-2014 Raden Solutions
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.netxms.ui.eclipse.objecttools.views;
+package org.netxms.ui.eclipse.objecttools.widgets;
 
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
 import java.util.Arrays;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
@@ -42,85 +22,52 @@ import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IViewSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.handlers.IHandlerService;
-import org.eclipse.ui.part.ViewPart;
 import org.netxms.client.AgentFile;
 import org.netxms.client.NXCSession;
 import org.netxms.client.SessionListener;
 import org.netxms.client.SessionNotification;
-import org.netxms.client.objects.AbstractObject;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objecttools.Activator;
 import org.netxms.ui.eclipse.objecttools.Messages;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.widgets.CompositeWithMessageBar;
 
-/**
- * File viewer
- */
-public class FileViewer extends ViewPart
+public class TextViewWidget extends CompositeWithMessageBar
 {
-       public static final String ID = "org.netxms.ui.eclipse.objecttools.views.FileViewer"; //$NON-NLS-1$
-       
-       private long nodeId;
-       private String remoteFileName;
-   private String fileID;
-       private File currentFile;
-       private StyledText textViewer;
-       private final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-       private boolean follow;
-       private ConsoleJob monitorJob;
-   private ConsoleJob tryToRestartMonitoring;
+   public static final long MAX_FILE_SIZE = 8192000;
+
+   private StyledText textViewer;
    private Action actionClear;
-       private Action actionScrollLock;
+   private Action actionScrollLock;
    private Action actionCopy;
    private Action actionSelectAll;
+   private String remoteFileName;
+   private long nodeId;
+   private String fileID;
+   private File currentFile;
    private long offset = 0;
+   private boolean follow;
+   private ConsoleJob monitorJob;
+   private ConsoleJob tryToRestartMonitoring;
    private SessionListener listener;
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
-        */
-       @Override
-       public void init(IViewSite site) throws PartInitException
-       {
-               super.init(site);
-               
-               // Secondary ID must by in form nodeId&remoteFileName
-               String[] parts = site.getSecondaryId().split("&"); //$NON-NLS-1$
-               if (parts.length != 2)
-                       throw new PartInitException("Internal error"); //$NON-NLS-1$
-               
-               nodeId = Long.parseLong(parts[0]);
-               AbstractObject object = session.findObjectById(nodeId);
-               if ((object == null) || (object.getObjectClass() != AbstractObject.OBJECT_NODE))
-                       throw new PartInitException(Messages.get().FileViewer_InvalidObjectID);
-               
-               try
-               {
-                       remoteFileName = URLDecoder.decode(parts[1], "UTF-8"); //$NON-NLS-1$
-               }
-               catch(UnsupportedEncodingException e)
-               {
-                       throw new PartInitException("Internal error", e); //$NON-NLS-1$
-               }
-               
-               setPartName(object.getObjectName() + ": " + remoteFileName); //$NON-NLS-1$
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
-        */
-       @Override
-       public void createPartControl(Composite parent)
-       {
-               textViewer = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL);
-               textViewer.setEditable(false);
-               textViewer.setFont(JFaceResources.getTextFont());
-               textViewer.addSelectionListener(new SelectionAdapter() {
+   private IViewPart viewPart;
+   private final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+
+   public TextViewWidget(Composite parent, int style, String remoteFileName, long nodeId, IViewPart viewPart)
+   {
+      super(parent, style);
+
+      this.remoteFileName = remoteFileName;
+      this.nodeId = nodeId;
+      this.viewPart = viewPart;
+
+      textViewer = new StyledText(getContent(), SWT.H_SCROLL | SWT.V_SCROLL);
+      textViewer.setEditable(false);
+      textViewer.setFont(JFaceResources.getTextFont());
+      textViewer.addSelectionListener(new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e)
          {
@@ -128,22 +75,9 @@ public class FileViewer extends ViewPart
          }
       });
 
-               createActions();
-               contributeToActionBars();
+      createActions();
+      contributeToActionBars();
       createPopupMenu();
-      activateContext();
-       }
-       
-   /**
-    * Activate context
-    */
-   private void activateContext()
-   {
-      IContextService contextService = (IContextService)getSite().getService(IContextService.class);
-      if (contextService != null)
-      {
-         contextService.activateContext("org.netxms.ui.eclipse.objecttools.context.FileViewer"); //$NON-NLS-1$
-      }
    }
 
    /**
@@ -151,8 +85,8 @@ public class FileViewer extends ViewPart
     */
    private void createActions()
    {
-      final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
-      
+      final IHandlerService handlerService = (IHandlerService)viewPart.getSite().getService(IHandlerService.class);
+
       actionClear = new Action(Messages.get().FileViewer_ClearOutput, SharedIcons.CLEAR_LOG) {
          @Override
          public void run()
@@ -163,7 +97,7 @@ public class FileViewer extends ViewPart
       actionClear.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.clear_output"); //$NON-NLS-1$
       handlerService.activateHandler(actionClear.getActionDefinitionId(), new ActionHandler(actionClear));
 
-      actionScrollLock = new Action(Messages.get().FileViewer_ScrollLock, Action.AS_CHECK_BOX) { 
+      actionScrollLock = new Action(Messages.get().FileViewer_ScrollLock, Action.AS_CHECK_BOX) {
          @Override
          public void run()
          {
@@ -184,7 +118,7 @@ public class FileViewer extends ViewPart
       actionCopy.setEnabled(false);
       actionCopy.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.copy"); //$NON-NLS-1$
       handlerService.activateHandler(actionCopy.getActionDefinitionId(), new ActionHandler(actionCopy));
-      
+
       actionSelectAll = new Action(Messages.get().LocalCommandResults_SelectAll) {
          @Override
          public void run()
@@ -196,13 +130,13 @@ public class FileViewer extends ViewPart
       actionSelectAll.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.select_all"); //$NON-NLS-1$
       handlerService.activateHandler(actionSelectAll.getActionDefinitionId(), new ActionHandler(actionSelectAll));
    }
-   
+
    /**
     * Contribute actions to action bar
     */
    private void contributeToActionBars()
    {
-      IActionBars bars = getViewSite().getActionBars();
+      IActionBars bars = viewPart.getViewSite().getActionBars();
       fillLocalPullDown(bars.getMenuManager());
       fillLocalToolBar(bars.getToolBarManager());
    }
@@ -210,8 +144,7 @@ public class FileViewer extends ViewPart
    /**
     * Fill local pull-down menu
     * 
-    * @param manager
-    *           Menu manager for pull-down menu
+    * @param manager Menu manager for pull-down menu
     */
    private void fillLocalPullDown(IMenuManager manager)
    {
@@ -225,8 +158,7 @@ public class FileViewer extends ViewPart
    /**
     * Fill local tool bar
     * 
-    * @param manager
-    *           Menu manager for local toolbar
+    * @param manager Menu manager for local toolbar
     */
    private void fillLocalToolBar(IToolBarManager manager)
    {
@@ -268,38 +200,29 @@ public class FileViewer extends ViewPart
       manager.add(actionCopy);
    }
 
-   /* (non-Javadoc)
-        * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
-        */
-       @Override
-       public void setFocus()
-       {
-               textViewer.setFocus();
-       }
-
-       /**
-        * @param file
-        * @param maxFileSize 
-        */
-   public void showFile(File file, boolean follow, String id, int maxFileSize)
-       {
-               currentFile = file;
+   /**
+    * @param file
+    * @param maxFileSize
+    */
+   public void showFile(File file, boolean follow, String id, int maxFileSize, boolean exceedSize)
+   {
+      currentFile = file;
       fileID = id;
       offset = maxFileSize;
-               setContent(loadFile(currentFile));
+      setContent(loadFile(currentFile));
       textViewer.setTopIndex(textViewer.getLineCount());
-               this.follow = follow;
-               if (follow)
-               {
-               monitorJob = new ConsoleJob(Messages.get().FileViewer_Download_File_Updates, null, Activator.PLUGIN_ID, null) {
-                  private boolean continueWork = true;
-                  
-                  @Override
-                  protected void canceling() 
-                  {
-                     continueWork = false;
-                  }
-                  
+      this.follow = follow;
+      if (follow)
+      {
+         monitorJob = new ConsoleJob(Messages.get().FileViewer_Download_File_Updates, null, Activator.PLUGIN_ID, null) {
+            private boolean continueWork = true;
+
+            @Override
+            protected void canceling()
+            {
+               continueWork = false;
+            }
+
             @Override
             protected void runInternal(IProgressMonitor monitor) throws Exception
             {
@@ -308,69 +231,74 @@ public class FileViewer extends ViewPart
                   final String s = session.waitForFileTail(fileID, 3000);
                   if (s != null)
                   {
-                     runInUIThread(new Runnable() {                  
+                     runInUIThread(new Runnable() {
                         @Override
                         public void run()
                         {
                            if (!textViewer.isDisposed())
                            {
-                              appendContent(s);                               
-                              if(!actionScrollLock.isChecked())
+                              appendContent(s);
+                              if (!actionScrollLock.isChecked())
                               {
                                  textViewer.setTopIndex(textViewer.getLineCount() - 1);
                               }
                            }
                         }
                      });
-                  }                    
+                  }
                }
             }
-   
+
             @Override
             protected String getErrorMessage()
             {
                return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, remoteFileName, nodeId);
             }
-               };
-               monitorJob.setUser(false);
-               monitorJob.setSystem(true);
-               monitorJob.start();
-               
-               listener = new SessionListener() {
-            
+         };
+         monitorJob.setUser(false);
+         monitorJob.setSystem(true);
+         monitorJob.start();
+
+         listener = new SessionListener() {
+
             @Override
             public void notificationHandler(SessionNotification n)
             {
                switch(n.getCode())
                {
-                  case SessionNotification.FILE_MONITORING_FAILED:    
-                     //Check that this is applicable on current file
-                     if(nodeId == n.getSubCode())
+                  case SessionNotification.FILE_MONITORING_FAILED:
+                     // Check that this is applicable on current file
+                     if (nodeId == n.getSubCode())
                         onFileMonitoringFail();
                      break;
                }
             }
          };
-               
-               session.addListener(listener);
-               }
-       }
-   
+
+         session.addListener(listener);
+      }
+      // Create notification that size exceeded
+      if (exceedSize)
+      {
+         showMessage(CompositeWithMessageBar.INFORMATION, "File is too large. Content will be shown partly.");
+      }
+   }
+
    private void onFileMonitoringFail()
    {
       tryToRestartMonitoring = new ConsoleJob(Messages.get().FileViewer_RestartFollowingJob, null, Activator.PLUGIN_ID, null) {
          private boolean continueWork = true;
-         
+
          @Override
-         protected void canceling() 
+         protected void canceling()
          {
             continueWork = false;
          }
-         
+
          @Override
          protected void runInternal(IProgressMonitor monitor) throws Exception
          {
-            runInUIThread(new Runnable() {                  
+            runInUIThread(new Runnable() {
                @Override
                public void run()
                {
@@ -378,55 +306,55 @@ public class FileViewer extends ViewPart
                   {
                      textViewer.setForeground(new Color(getDisplay(), 255, 0, 0));
                      textViewer.append(" \n\n" + //$NON-NLS-1$
-                               "----------------------------------------------------------------------\n" + //$NON-NLS-1$
-                               Messages.get().FileViewer_NotifyFollowConnectionLost +
-                               "\n----------------------------------------------------------------------" + //$NON-NLS-1$
-                               "\n");   //$NON-NLS-1$
-                     if(!actionScrollLock.isChecked())
+                           "----------------------------------------------------------------------\n"
+                           + //$NON-NLS-1$
+                           Messages.get().FileViewer_NotifyFollowConnectionLost
+                           + "\n----------------------------------------------------------------------" + //$NON-NLS-1$
+                           "\n"); //$NON-NLS-1$
+                     if (!actionScrollLock.isChecked())
                      {
                         textViewer.setTopIndex(textViewer.getLineCount() - 1);
                      }
                   }
                }
-            });    
-            
-            //Try to reconnect in loop every 20 sec.            
+            });
+
+            // Try to reconnect in loop every 20 sec.
             while(continueWork)
             {
-               try 
+               try
                {
                   final AgentFile file = session.downloadFileFromAgent(nodeId, remoteFileName, offset, follow);
-                  
-                  //When successfully connected - display notification to client.
-                  runInUIThread(new Runnable() {                  
+
+                  // When successfully connected - display notification to client.
+                  runInUIThread(new Runnable() {
                      @Override
                      public void run()
                      {
                         if (!textViewer.isDisposed())
                         {
-                           textViewer.append(
-                                 "-------------------------------------------------------------------------------\n" + //$NON-NLS-1$
-                                 Messages.get().FileViewer_NotifyFollowConnectionEnabed +
-                                 "\n-------------------------------------------------------------------------------" + //$NON-NLS-1$
-                                       "\n \n");   //$NON-NLS-1$
+                           textViewer.append("-------------------------------------------------------------------------------\n" + //$NON-NLS-1$
+                                 Messages.get().FileViewer_NotifyFollowConnectionEnabed
+                                 + "\n-------------------------------------------------------------------------------" + //$NON-NLS-1$
+                                 "\n \n"); //$NON-NLS-1$
                            textViewer.setForeground(null);
                            loadFile(file.getFile());
-                           if(!actionScrollLock.isChecked())
+                           if (!actionScrollLock.isChecked())
                            {
                               textViewer.setTopIndex(textViewer.getLineCount() - 1);
                            }
                         }
                      }
-                  });         
-                  
+                  });
+
                   continueWork = false;
                }
                catch(Exception e)
-               {                  
+               {
                }
-               Thread.sleep(20000);  
-            }      
-            
+               Thread.sleep(20000);
+            }
+
          }
 
          @Override
@@ -437,10 +365,12 @@ public class FileViewer extends ViewPart
       };
       tryToRestartMonitoring.setUser(false);
       tryToRestartMonitoring.setSystem(true);
-      tryToRestartMonitoring.start();      
+      tryToRestartMonitoring.start();
    }
-   
-   /* (non-Javadoc)
+
+   /*
+    * (non-Javadoc)
+    * 
     * @see org.eclipse.ui.part.WorkbenchPart#dispose()
     */
    @Override
@@ -449,9 +379,9 @@ public class FileViewer extends ViewPart
       if (follow)
       {
          monitorJob.cancel();
-         if(tryToRestartMonitoring != null)
+         if (tryToRestartMonitoring != null)
             tryToRestartMonitoring.cancel();
-         if(tryToRestartMonitoring == null || tryToRestartMonitoring.getState() != Job.RUNNING)
+         if (tryToRestartMonitoring == null || tryToRestartMonitoring.getState() != Job.RUNNING)
          {
             final ConsoleJob job = new ConsoleJob(Messages.get().FileViewer_Stop_File_Monitoring, null, Activator.PLUGIN_ID, null) {
                @Override
@@ -459,7 +389,7 @@ public class FileViewer extends ViewPart
                {
                   session.cancelFileMonitoring(nodeId, fileID);
                }
-               
+
                @Override
                protected String getErrorMessage()
                {
@@ -474,106 +404,106 @@ public class FileViewer extends ViewPart
       session.removeListener(listener);
       super.dispose();
    }
-       
-       /**
-        * @param file
-        */
-       private String loadFile(File file)
-       {
-               StringBuilder content = new StringBuilder();
-               FileReader reader = null;
-               char[] buffer = new char[32768];
-               try
-               {
-                       reader = new FileReader(file);
-                       int size = 0;
-                       while(size < 8192000)
-                       {
-                               int count = reader.read(buffer);
-                               if (count == -1)
-                                       break;
-                               if (count == buffer.length)
-                               {
-                                       content.append(buffer);
-                               }
-                               else
-                               {
-                                       content.append(Arrays.copyOf(buffer, count));
-                               }
-                               size += count;
-                       }
-               }
-               catch(IOException e)
-               {
-                       e.printStackTrace();
-               }
-               finally
-               {
-                       if (reader != null)
-                       {
-                               try
-                               {
-                                       reader.close();
-                               }
-                               catch(IOException e)
-                               {
-                               }
-                       }
-               }
-               return content.toString();
-       }
-       
-       /**
-        * @param s
-        */
-       private void setContent(String s)
-       {
-          textViewer.setText(removeEscapeSequences(s));
-       }
-       
-       /**
-        * @param s
-        */
-       private void appendContent(String s)
-       {
-          textViewer.append(removeEscapeSequences(s));
-       }
-       
-       /**
-        * Remove escape sequences from input string
-        
-        * @param s
-        * @return
-        */
-       private static String removeEscapeSequences(String s)
-       {
-          StringBuilder sb = new StringBuilder();
-          for(int i = 0; i < s.length(); i++)
-          {
-             char ch = s.charAt(i);
-             if (ch == 27)
-             {
-                i++;
-                ch = s.charAt(i);
-                if (ch == '[')
-                {
-                for(; i < s.length(); i++)
-                {
-                   ch = s.charAt(i);
-                   if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
-                      break;
-                }
-                }
-                else if ((ch == '(') || (ch == ')'))
-                {
-                   i++;
-                }
-             }
-             else if ((ch >= 32) || (ch == '\r') || (ch == '\n') || (ch == '\t'))
-             {
-                sb.append(ch);
-             }
-          }
-          return sb.toString();
-       }
+
+   /**
+    * @param file
+    */
+   private String loadFile(File file)
+   {
+      StringBuilder content = new StringBuilder();
+      FileReader reader = null;
+      char[] buffer = new char[32768];
+      try
+      {
+         reader = new FileReader(file);
+         int size = 0;
+         while(size < MAX_FILE_SIZE)
+         {
+            int count = reader.read(buffer);
+            if (count == -1)
+               break;
+            if (count == buffer.length)
+            {
+               content.append(buffer);
+            }
+            else
+            {
+               content.append(Arrays.copyOf(buffer, count));
+            }
+            size += count;
+         }
+      }
+      catch(IOException e)
+      {
+         e.printStackTrace();
+      }
+      finally
+      {
+         if (reader != null)
+         {
+            try
+            {
+               reader.close();
+            }
+            catch(IOException e)
+            {
+            }
+         }
+      }
+      return content.toString();
+   }
+
+   /**
+    * @param s
+    */
+   private void setContent(String s)
+   {
+      textViewer.setText(removeEscapeSequences(s));
+   }
+
+   /**
+    * @param s
+    */
+   private void appendContent(String s)
+   {
+      textViewer.append(removeEscapeSequences(s));
+   }
+
+   /**
+    * Remove escape sequences from input string
+    * 
+    * @param s
+    * @return
+    */
+   private static String removeEscapeSequences(String s)
+   {
+      StringBuilder sb = new StringBuilder();
+      for(int i = 0; i < s.length(); i++)
+      {
+         char ch = s.charAt(i);
+         if (ch == 27)
+         {
+            i++;
+            ch = s.charAt(i);
+            if (ch == '[')
+            {
+               for(; i < s.length(); i++)
+               {
+                  ch = s.charAt(i);
+                  if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
+                     break;
+               }
+            }
+            else if ((ch == '(') || (ch == ')'))
+            {
+               i++;
+            }
+         }
+         else if ((ch >= 32) || (ch == '\r') || (ch == '\n') || (ch == '\t'))
+         {
+            sb.append(ch);
+         }
+      }
+      return sb.toString();
+   }
 }
index 2e86c2c..604330c 100644 (file)
@@ -915,14 +915,12 @@ public class AgentFileManager extends ViewPart
             runInUIThread(new Runnable() {
                @Override
                public void run()
-               {
+               {                  
                   final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                   try
                   {
                      String secondaryId = Long.toString(objectId) + "&" + URLEncoder.encode(sf.getName(), "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
-                     FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
-                           IWorkbenchPage.VIEW_ACTIVATE);
-                     view.showFile(file.getFile(), tail, file.getId(), offset);
+                     FileViewer.createView(window, getSite().getShell(), file, tail, offset, secondaryId, objectId);
                   }
                   catch(Exception e)
                   {
index d1c873c..1af8451 100644 (file)
@@ -276,9 +276,7 @@ public final class ObjectToolExecutor
                   try
                   {
                      String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
-                     FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
-                           IWorkbenchPage.VIEW_ACTIVATE);
-                     view.showFile(file.getFile(), follow, file.getId(), maxFileSize);
+                     FileViewer.createView(window, window.getShell(), file, follow, maxFileSize, secondaryId, node.object.getObjectId());
                   }
                   catch(Exception e)
                   {
index 0d0996b..1954558 100644 (file)
  */
 package org.netxms.ui.eclipse.objecttools.views;
 
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
-import java.util.Arrays;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.commands.ActionHandler;
-import org.eclipse.rap.rwt.RWT;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IActionBars;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.contexts.IContextService;
-import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.part.ViewPart;
 import org.netxms.client.AgentFile;
 import org.netxms.client.NXCSession;
-import org.netxms.client.SessionListener;
-import org.netxms.client.SessionNotification;
 import org.netxms.client.objects.AbstractObject;
-import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objecttools.Activator;
 import org.netxms.ui.eclipse.objecttools.Messages;
+import org.netxms.ui.eclipse.objecttools.widgets.TextViewWidget;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 
 /**
  * File viewer
@@ -63,19 +47,10 @@ public class FileViewer extends ViewPart
 {
        public static final String ID = "org.netxms.ui.eclipse.objecttools.views.FileViewer"; //$NON-NLS-1$
        
-       private long nodeId;
-       private String remoteFileName;
-   private String fileID;
-       private File currentFile;
-       private Text textViewer;
-       private final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-       private boolean follow;
-       private ConsoleJob monitorJob;
-   private ConsoleJob tryToRestartMonitoring;
-   private Action actionClear;
-       private Action actionScrollLock;
-   private long offset = 0;
-   private SessionListener listener;
+   private final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+   private TextViewWidget textViewer;
+   private String remoteFileName;
+   private long nodeId;
        
        /* (non-Javadoc)
         * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
@@ -112,15 +87,9 @@ public class FileViewer extends ViewPart
         */
        @Override
        public void createPartControl(Composite parent)
-       {
-               textViewer = new Text(parent, SWT.H_SCROLL | SWT.V_SCROLL);
-               textViewer.setEditable(false);
-               textViewer.setData(RWT.CUSTOM_VARIANT, "monospace");
-               
-      createActions();
-      contributeToActionBars();
-      createPopupMenu();
-      activateContext();
+       {          
+          textViewer = new TextViewWidget(parent, SWT.BORDER, remoteFileName, nodeId, this);   
+      activateContext();               
        }
        
    /**
@@ -134,281 +103,36 @@ public class FileViewer extends ViewPart
          contextService.activateContext("org.netxms.ui.eclipse.objecttools.context.FileViewer"); //$NON-NLS-1$
       }
    }
-
-   /**
-    * Create actions
-    */
-   private void createActions()
-   {
-      final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
-      
-      actionClear = new Action(Messages.get().FileViewer_ClearOutput, SharedIcons.CLEAR_LOG) {
-         @Override
-         public void run()
-         {
-            textViewer.setText(""); //$NON-NLS-1$
-         }
-      };
-      actionClear.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.clear_output"); //$NON-NLS-1$
-      handlerService.activateHandler(actionClear.getActionDefinitionId(), new ActionHandler(actionClear));
-
-      actionScrollLock = new Action(Messages.get().FileViewer_ScrollLock, Action.AS_CHECK_BOX) { 
-         @Override
-         public void run()
-         {
-         }
-      };
-      actionScrollLock.setImageDescriptor(Activator.getImageDescriptor("icons/scroll_lock.gif")); //$NON-NLS-1$
-      actionScrollLock.setChecked(false);
-      actionScrollLock.setActionDefinitionId("org.netxms.ui.eclipse.objecttools.commands.scroll_lock"); //$NON-NLS-1$
-      handlerService.activateHandler(actionScrollLock.getActionDefinitionId(), new ActionHandler(actionScrollLock));
-   }
-   
-   /**
-    * Contribute actions to action bar
-    */
-   private void contributeToActionBars()
-   {
-      IActionBars bars = getViewSite().getActionBars();
-      fillLocalPullDown(bars.getMenuManager());
-      fillLocalToolBar(bars.getToolBarManager());
-   }
-
-   /**
-    * Fill local pull-down menu
-    * 
-    * @param manager
-    *           Menu manager for pull-down menu
-    */
-   private void fillLocalPullDown(IMenuManager manager)
-   {
-      manager.add(actionClear);
-      manager.add(actionScrollLock);
-   }
-
-   /**
-    * Fill local tool bar
-    * 
-    * @param manager
-    *           Menu manager for local toolbar
-    */
-   private void fillLocalToolBar(IToolBarManager manager)
-   {
-      manager.add(actionClear);
-      manager.add(actionScrollLock);
-   }
-
-   /**
-    * Create pop-up menu
-    */
-   private void createPopupMenu()
-   {
-      // Create menu manager
-      MenuManager menuMgr = new MenuManager();
-      menuMgr.setRemoveAllWhenShown(true);
-      menuMgr.addMenuListener(new IMenuListener() {
-         public void menuAboutToShow(IMenuManager mgr)
-         {
-            fillContextMenu(mgr);
-         }
-      });
-
-      // Create menu
-      Menu menu = menuMgr.createContextMenu(textViewer);
-      textViewer.setMenu(menu);
-   }
-
-   /**
-    * Fill context menu
-    * 
-    * @param mgr Menu manager
+       
+       /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
     */
-   private void fillContextMenu(final IMenuManager manager)
+   @Override
+   public void setFocus()
    {
-      manager.add(actionClear);
-      manager.add(actionScrollLock);
+      textViewer.setFocus();
    }
-
-   /* (non-Javadoc)
-        * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
-        */
-       @Override
-       public void setFocus()
-       {
-               textViewer.setFocus();
-       }
-
+       
        /**
-        * @param file
-        * @param maxFileSize 
+        * Method that checks that file does not exceed allowed size.
+        * In case if file is too large asks if it should be opened partly. 
+        * @throws PartInitException 
         */
-   public void showFile(File file, boolean follow, String id, int maxFileSize)
+       public static boolean createView(IWorkbenchWindow window, Shell shell, final AgentFile file, boolean tail, int offset, String secondaryId, final long nodeId) throws PartInitException
        {
-               currentFile = file;
-      fileID = id;
-      offset = maxFileSize;
-               setContent(loadFile(currentFile));
-
-               this.follow = follow;
-               if (follow)
-               {
-               monitorJob = new ConsoleJob(Messages.get().FileViewer_Download_File_Updates, null, Activator.PLUGIN_ID, null) {
-                  private boolean continueWork = true;
-                  
-                  @Override
-                  protected void canceling() 
-                  {
-                     continueWork = false;
-                  }
-                  
-            @Override
-            protected void runInternal(IProgressMonitor monitor) throws Exception
-            {
-               while(continueWork)
-               {
-                  final String s = session.waitForFileTail(fileID, 3000);
-                  if (s != null)
-                  {
-                     runInUIThread(new Runnable() {                  
-                        @Override
-                        public void run()
-                        {
-                           if (!textViewer.isDisposed())
-                           {
-                              appendContent(s);                               
-
-                           }
-                        }
-                     });
-                  }                    
-               }
-            }
-   
-            @Override
-            protected String getErrorMessage()
-            {
-               return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, remoteFileName, nodeId);
-            }
-               };
-               monitorJob.setUser(false);
-               monitorJob.setSystem(true);
-               monitorJob.start();
-               
-               listener = new SessionListener() {
-            
-            @Override
-            public void notificationHandler(SessionNotification n)
-            {
-               switch(n.getCode())
-               {
-                  case SessionNotification.FILE_MONITORING_FAILED:    
-                     //Check that this is applicable on current file
-                     if(nodeId == n.getSubCode())
-                        onFileMonitoringFail();
-                     break;
-               }
-            }
-         };
-               
-               session.addListener(listener);
-               }
-       }
-   
-   private void onFileMonitoringFail()
-   {
-      Display d = getSite().getShell().getDisplay();
-      tryToRestartMonitoring = new ConsoleJob(Messages.get(d).FileViewer_RestartFollowingJob, null, Activator.PLUGIN_ID, null, d) {
-         private boolean continueWork = true;
-         
-         @Override
-         protected void canceling() 
-         {
-            continueWork = false;
-         }
-         
-         @Override
-         protected void runInternal(IProgressMonitor monitor) throws Exception
-         {
-            runInUIThread(new Runnable() {                  
-               @Override
-               public void run()
-               {
-                  if (!textViewer.isDisposed())
-                  {
-                     textViewer.setForeground(new Color(getDisplay(), 255, 0, 0));
-                     textViewer.append(" \n\n" + //$NON-NLS-1$
-                               "----------------------------------------------------------------------\n" + //$NON-NLS-1$
-                               Messages.get().FileViewer_NotifyFollowConnectionLost +
-                               "\n----------------------------------------------------------------------" + //$NON-NLS-1$
-                               "\n");   //$NON-NLS-1$
-                  }
-               }
-            });    
-            
-            //Try to reconnect in loop every 20 sec.            
-            while(continueWork)
-            {
-               try 
-               {
-                  final AgentFile file = session.downloadFileFromAgent(nodeId, remoteFileName, offset, follow);
-                  
-                  //When successfully connected - display notification to client.
-                  runInUIThread(new Runnable() {                  
-                     @Override
-                     public void run()
-                     {
-                        if (!textViewer.isDisposed())
-                        {
-                           textViewer.append(
-                                 "-------------------------------------------------------------------------------\n" + //$NON-NLS-1$
-                                 Messages.get().FileViewer_NotifyFollowConnectionEnabed +
-                                 "\n-------------------------------------------------------------------------------" + //$NON-NLS-1$
-                                       "\n \n");   //$NON-NLS-1$
-                           textViewer.setForeground(null);
-                           loadFile(file.getFile());
-                        }
-                     }
-                  });         
-                  
-                  continueWork = false;
-               }
-               catch(Exception e)
-               {                  
-               }
-               Thread.sleep(20000);  
-            }      
-            
-         }
-
-         @Override
-         protected String getErrorMessage()
-         {
-            return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, remoteFileName, nodeId);
-         }
-      };
-      tryToRestartMonitoring.setUser(false);
-      tryToRestartMonitoring.setSystem(true);
-      tryToRestartMonitoring.start();      
-   }
-   
-   /* (non-Javadoc)
-    * @see org.eclipse.ui.part.WorkbenchPart#dispose()
-    */
-   @Override
-   public void dispose()
-   {
-      if (follow)
+          boolean exceedSize = file.getFile().length() > TextViewWidget.MAX_FILE_SIZE;
+          if(exceedSize && !MessageDialogHelper.openConfirm(shell, "File is too large",
+                  "File is too large to be fully shown. Click OK to see beginning of the file."))
       {
-         monitorJob.cancel();
-         if(tryToRestartMonitoring != null)
-            tryToRestartMonitoring.cancel();
-         if(tryToRestartMonitoring == null || tryToRestartMonitoring.getState() != Job.RUNNING)
-         {
-            final ConsoleJob job = new ConsoleJob(Messages.get().FileViewer_Stop_File_Monitoring, null, Activator.PLUGIN_ID, null) {
+             if(tail)
+             {
+                final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+
+             final ConsoleJob job = new ConsoleJob(Messages.get().FileViewer_Stop_File_Monitoring, null, Activator.PLUGIN_ID, null) {
                @Override
                protected void runInternal(IProgressMonitor monitor) throws Exception
                {
-                  session.cancelFileMonitoring(nodeId, fileID);
+                  session.cancelFileMonitoring(nodeId, file.getId());
                }
                
                @Override
@@ -421,110 +145,12 @@ public class FileViewer extends ViewPart
             job.setSystem(true);
             job.start();
          }
+         return false;
       }
-      session.removeListener(listener);
-      super.dispose();
-   }
-       
-       /**
-        * @param file
-        */
-       private String loadFile(File file)
-       {
-               StringBuilder content = new StringBuilder();
-               FileReader reader = null;
-               char[] buffer = new char[32768];
-               try
-               {
-                       reader = new FileReader(file);
-                       int size = 0;
-                       while(size < 8192000)
-                       {
-                               int count = reader.read(buffer);
-                               if (count == -1)
-                                       break;
-                               if (count == buffer.length)
-                               {
-                                       content.append(buffer);
-                               }
-                               else
-                               {
-                                       content.append(Arrays.copyOf(buffer, count));
-                               }
-                               size += count;
-                       }
-               }
-               catch(IOException e)
-               {
-                       e.printStackTrace();
-               }
-               finally
-               {
-                       if (reader != null)
-                       {
-                               try
-                               {
-                                       reader.close();
-                               }
-                               catch(IOException e)
-                               {
-                               }
-                       }
-               }
-               return content.toString();
-       }
-       
-       /**
-        * @param s
-        */
-       private void setContent(String s)
-       {
-          textViewer.setText(removeEscapeSequences(s));
-       }
-       
-       /**
-        * @param s
-        */
-       private void appendContent(String s)
-       {
-          textViewer.append(removeEscapeSequences(s));
-       }
-       
-       /**
-        * Remove escape sequences from input string
-        * 
-        * @param s
-        * @return
-        */
-       private static String removeEscapeSequences(String s)
-       {
-          StringBuilder sb = new StringBuilder();
-          for(int i = 0; i < s.length(); i++)
-          {
-             char ch = s.charAt(i);
-             if (ch == 27)
-             {
-                i++;
-                ch = s.charAt(i);
-                if (ch == '[')
-                {
-                for(; i < s.length(); i++)
-                {
-                   ch = s.charAt(i);
-                   if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
-                      break;
-                }
-                }
-                else if ((ch == '(') || (ch == ')'))
-                {
-                   i++;
-                }
-             }
-             else if ((ch >= 32) || (ch == '\r') || (ch == '\n') || (ch == '\t'))
-             {
-                sb.append(ch);
-             }
-          }
-          return sb.toString();
-       }
+          FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
+            IWorkbenchPage.VIEW_ACTIVATE);
+          view.textViewer.showFile(file.getFile(), tail, file.getId(), offset, exceedSize);
+          
+          return true;
+       }        
 }
@@ -1,28 +1,8 @@
-/**
- * NetXMS - open source network management system
- * Copyright (C) 2003-2014 Raden Solutions
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.netxms.ui.eclipse.objecttools.views;
+package org.netxms.ui.eclipse.objecttools.widgets;
 
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
 import java.util.Arrays;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
@@ -31,108 +11,65 @@ import org.eclipse.jface.action.IMenuListener;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IViewSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.handlers.IHandlerService;
-import org.eclipse.ui.part.ViewPart;
 import org.netxms.client.AgentFile;
 import org.netxms.client.NXCSession;
 import org.netxms.client.SessionListener;
 import org.netxms.client.SessionNotification;
-import org.netxms.client.objects.AbstractObject;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objecttools.Activator;
 import org.netxms.ui.eclipse.objecttools.Messages;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.widgets.CompositeWithMessageBar;
 
-/**
- * File viewer
- */
-public class FileViewer extends ViewPart
+public class TextViewWidget extends CompositeWithMessageBar
 {
-       public static final String ID = "org.netxms.ui.eclipse.objecttools.views.FileViewer"; //$NON-NLS-1$
-       
-       private long nodeId;
-       private String remoteFileName;
-   private String fileID;
-       private File currentFile;
-       private Text textViewer;
-       private final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-       private boolean follow;
-       private ConsoleJob monitorJob;
-   private ConsoleJob tryToRestartMonitoring;
+   public static final long MAX_FILE_SIZE = 8192000;  
+   
+   private Text textViewer;
    private Action actionClear;
-       private Action actionScrollLock;
+   private Action actionScrollLock;
+   private String remoteFileName;
+   private long nodeId;
+   private String fileID;
+   private File currentFile;
    private long offset = 0;
+   private boolean follow;
+   private ConsoleJob monitorJob;
+   private ConsoleJob tryToRestartMonitoring;
    private SessionListener listener;
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
-        */
-       @Override
-       public void init(IViewSite site) throws PartInitException
-       {
-               super.init(site);
-               
-               // Secondary ID must by in form nodeId&remoteFileName
-               String[] parts = site.getSecondaryId().split("&"); //$NON-NLS-1$
-               if (parts.length != 2)
-                       throw new PartInitException("Internal error"); //$NON-NLS-1$
-               
-               nodeId = Long.parseLong(parts[0]);
-               AbstractObject object = session.findObjectById(nodeId);
-               if ((object == null) || (object.getObjectClass() != AbstractObject.OBJECT_NODE))
-                       throw new PartInitException(Messages.get().FileViewer_InvalidObjectID);
-               
-               try
-               {
-                       remoteFileName = URLDecoder.decode(parts[1], "UTF-8"); //$NON-NLS-1$
-               }
-               catch(UnsupportedEncodingException e)
-               {
-                       throw new PartInitException("Internal error", e); //$NON-NLS-1$
-               }
-               
-               setPartName(object.getObjectName() + ": " + remoteFileName); //$NON-NLS-1$
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
-        */
-       @Override
-       public void createPartControl(Composite parent)
-       {
-               textViewer = new Text(parent, SWT.H_SCROLL | SWT.V_SCROLL);
-               textViewer.setEditable(false);
-               textViewer.setData(RWT.CUSTOM_VARIANT, "monospace");
-               
+   private IViewPart viewPart;
+   private final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+   
+   public TextViewWidget(Composite parent, int style, String remoteFileName, long nodeId, IViewPart viewPart)
+   {      
+      super(parent, style);
+      
+      this.remoteFileName = remoteFileName;
+      this.nodeId = nodeId;
+      this.viewPart = viewPart;
+      
+      textViewer = new Text(getContent(), SWT.H_SCROLL | SWT.V_SCROLL);
+      textViewer.setEditable(false);
+      textViewer.setData(RWT.CUSTOM_VARIANT, "monospace");
+      
       createActions();
       contributeToActionBars();
       createPopupMenu();
-      activateContext();
-       }
-       
-   /**
-    * Activate context
-    */
-   private void activateContext()
-   {
-      IContextService contextService = (IContextService)getSite().getService(IContextService.class);
-      if (contextService != null)
-      {
-         contextService.activateContext("org.netxms.ui.eclipse.objecttools.context.FileViewer"); //$NON-NLS-1$
-      }
    }
 
    /**
@@ -140,7 +77,7 @@ public class FileViewer extends ViewPart
     */
    private void createActions()
    {
-      final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
+      final IHandlerService handlerService = (IHandlerService)viewPart.getSite().getService(IHandlerService.class);
       
       actionClear = new Action(Messages.get().FileViewer_ClearOutput, SharedIcons.CLEAR_LOG) {
          @Override
@@ -169,7 +106,7 @@ public class FileViewer extends ViewPart
     */
    private void contributeToActionBars()
    {
-      IActionBars bars = getViewSite().getActionBars();
+      IActionBars bars = viewPart.getViewSite().getActionBars();
       fillLocalPullDown(bars.getMenuManager());
       fillLocalToolBar(bars.getToolBarManager());
    }
@@ -228,39 +165,31 @@ public class FileViewer extends ViewPart
       manager.add(actionClear);
       manager.add(actionScrollLock);
    }
+   
 
-   /* (non-Javadoc)
-        * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
-        */
-       @Override
-       public void setFocus()
-       {
-               textViewer.setFocus();
-       }
-
-       /**
-        * @param file
-        * @param maxFileSize 
-        */
-   public void showFile(File file, boolean follow, String id, int maxFileSize)
-       {
-               currentFile = file;
+   /**
+    * @param file
+    * @param maxFileSize 
+    */
+   public void showFile(File file, boolean follow, String id, int maxFileSize, boolean exceedSize)
+   {
+      currentFile = file;
       fileID = id;
-      offset = maxFileSize;
-               setContent(loadFile(currentFile));
-
-               this.follow = follow;
-               if (follow)
-               {
-               monitorJob = new ConsoleJob(Messages.get().FileViewer_Download_File_Updates, null, Activator.PLUGIN_ID, null) {
-                  private boolean continueWork = true;
-                  
-                  @Override
-                  protected void canceling() 
-                  {
-                     continueWork = false;
-                  }
-                  
+      offset = maxFileSize;      
+      setContent(loadFile(currentFile));
+      
+      this.follow = follow;
+      if (follow)
+      {
+         monitorJob = new ConsoleJob(Messages.get().FileViewer_Download_File_Updates, null, Activator.PLUGIN_ID, null) {
+            private boolean continueWork = true;
+            
+            @Override
+            protected void canceling() 
+            {
+               continueWork = false;
+            }
+            
             @Override
             protected void runInternal(IProgressMonitor monitor) throws Exception
             {
@@ -276,7 +205,7 @@ public class FileViewer extends ViewPart
                            if (!textViewer.isDisposed())
                            {
                               appendContent(s);                               
-
+                              
                            }
                         }
                      });
@@ -289,12 +218,12 @@ public class FileViewer extends ViewPart
             {
                return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, remoteFileName, nodeId);
             }
-               };
-               monitorJob.setUser(false);
-               monitorJob.setSystem(true);
-               monitorJob.start();
-               
-               listener = new SessionListener() {
+         };
+         monitorJob.setUser(false);
+         monitorJob.setSystem(true);
+         monitorJob.start();
+         
+         listener = new SessionListener() {
             
             @Override
             public void notificationHandler(SessionNotification n)
@@ -309,15 +238,19 @@ public class FileViewer extends ViewPart
                }
             }
          };
-               
-               session.addListener(listener);
-               }
-       }
+         
+         session.addListener(listener);
+      }
+      //Create notification that size exceeded
+      if(exceedSize)
+      {
+         showMessage(CompositeWithMessageBar.INFORMATION, "File is too large. Content will be shown partly.");
+      }
+   }
    
    private void onFileMonitoringFail()
    {
-      Display d = getSite().getShell().getDisplay();
-      tryToRestartMonitoring = new ConsoleJob(Messages.get(d).FileViewer_RestartFollowingJob, null, Activator.PLUGIN_ID, null, d) {
+      tryToRestartMonitoring = new ConsoleJob(Messages.get().FileViewer_RestartFollowingJob, null, Activator.PLUGIN_ID, null) {
          private boolean continueWork = true;
          
          @Override
@@ -337,10 +270,11 @@ public class FileViewer extends ViewPart
                   {
                      textViewer.setForeground(new Color(getDisplay(), 255, 0, 0));
                      textViewer.append(" \n\n" + //$NON-NLS-1$
-                               "----------------------------------------------------------------------\n" + //$NON-NLS-1$
-                               Messages.get().FileViewer_NotifyFollowConnectionLost +
-                               "\n----------------------------------------------------------------------" + //$NON-NLS-1$
-                               "\n");   //$NON-NLS-1$
+                           "----------------------------------------------------------------------\n" + //$NON-NLS-1$
+                           Messages.get().FileViewer_NotifyFollowConnectionLost +
+                           "\n----------------------------------------------------------------------" + //$NON-NLS-1$
+                           "\n");   //$NON-NLS-1$
+
                   }
                }
             });    
@@ -363,9 +297,10 @@ public class FileViewer extends ViewPart
                                  "-------------------------------------------------------------------------------\n" + //$NON-NLS-1$
                                  Messages.get().FileViewer_NotifyFollowConnectionEnabed +
                                  "\n-------------------------------------------------------------------------------" + //$NON-NLS-1$
-                                       "\n \n");   //$NON-NLS-1$
+                                 "\n \n");   //$NON-NLS-1$
                            textViewer.setForeground(null);
                            loadFile(file.getFile());
+
                         }
                      }
                   });         
@@ -425,106 +360,106 @@ public class FileViewer extends ViewPart
       session.removeListener(listener);
       super.dispose();
    }
-       
-       /**
-        * @param file
-        */
-       private String loadFile(File file)
-       {
-               StringBuilder content = new StringBuilder();
-               FileReader reader = null;
-               char[] buffer = new char[32768];
-               try
-               {
-                       reader = new FileReader(file);
-                       int size = 0;
-                       while(size < 8192000)
-                       {
-                               int count = reader.read(buffer);
-                               if (count == -1)
-                                       break;
-                               if (count == buffer.length)
-                               {
-                                       content.append(buffer);
-                               }
-                               else
-                               {
-                                       content.append(Arrays.copyOf(buffer, count));
-                               }
-                               size += count;
-                       }
-               }
-               catch(IOException e)
-               {
-                       e.printStackTrace();
-               }
-               finally
-               {
-                       if (reader != null)
-                       {
-                               try
-                               {
-                                       reader.close();
-                               }
-                               catch(IOException e)
-                               {
-                               }
-                       }
-               }
-               return content.toString();
-       }
-       
-       /**
-        * @param s
-        */
-       private void setContent(String s)
-       {
-          textViewer.setText(removeEscapeSequences(s));
-       }
-       
-       /**
-        * @param s
-        */
-       private void appendContent(String s)
-       {
-          textViewer.append(removeEscapeSequences(s));
-       }
-       
-       /**
-        * Remove escape sequences from input string
-        
-        * @param s
-        * @return
-        */
-       private static String removeEscapeSequences(String s)
-       {
-          StringBuilder sb = new StringBuilder();
-          for(int i = 0; i < s.length(); i++)
-          {
-             char ch = s.charAt(i);
-             if (ch == 27)
-             {
-                i++;
-                ch = s.charAt(i);
-                if (ch == '[')
-                {
-                for(; i < s.length(); i++)
-                {
-                   ch = s.charAt(i);
-                   if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
-                      break;
-                }
-                }
-                else if ((ch == '(') || (ch == ')'))
-                {
-                   i++;
-                }
-             }
-             else if ((ch >= 32) || (ch == '\r') || (ch == '\n') || (ch == '\t'))
-             {
-                sb.append(ch);
-             }
-          }
-          return sb.toString();
-       }
+   
+   /**
+    * @param file
+    */
+   private String loadFile(File file)
+   {
+      StringBuilder content = new StringBuilder();
+      FileReader reader = null;
+      char[] buffer = new char[32768];
+      try
+      {
+         reader = new FileReader(file);
+         int size = 0;
+         while(size < MAX_FILE_SIZE)
+         {
+            int count = reader.read(buffer);
+            if (count == -1)
+               break;
+            if (count == buffer.length)
+            {
+               content.append(buffer);
+            }
+            else
+            {
+               content.append(Arrays.copyOf(buffer, count));
+            }
+            size += count;
+         }
+      }
+      catch(IOException e)
+      {
+         e.printStackTrace();
+      }
+      finally
+      {
+         if (reader != null)
+         {
+            try
+            {
+               reader.close();
+            }
+            catch(IOException e)
+            {
+            }
+         }
+      }
+      return content.toString();
+   }
+   
+   /**
+    * @param s
+    */
+   private void setContent(String s)
+   {
+      textViewer.setText(removeEscapeSequences(s));
+   }
+   
+   /**
+    * @param s
+    */
+   private void appendContent(String s)
+   {
+      textViewer.append(removeEscapeSequences(s));
+   }
+   
+   /**
+    * Remove escape sequences from input string
+    * 
+    * @param s
+    * @return
+    */
+   private static String removeEscapeSequences(String s)
+   {
+      StringBuilder sb = new StringBuilder();
+      for(int i = 0; i < s.length(); i++)
+      {
+         char ch = s.charAt(i);
+         if (ch == 27)
+         {
+            i++;
+            ch = s.charAt(i);
+            if (ch == '[')
+            {
+               for(; i < s.length(); i++)
+               {
+                  ch = s.charAt(i);
+                  if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
+                     break;
+               }
+            }
+            else if ((ch == '(') || (ch == ')'))
+            {
+               i++;
+            }
+         }
+         else if ((ch >= 32) || (ch == '\r') || (ch == '\n') || (ch == '\t'))
+         {
+            sb.append(ch);
+         }
+      }
+      return sb.toString();
+   }
 }