package hu.zsdoma.e4.logstream.ui.view;

import hu.zsdoma.e4.logstream.service.LogStreamCallback;
import hu.zsdoma.e4.logstream.service.LogStreamService;
import hu.zsdoma.e4.logstream.service.LogStreamServiceImpl;

import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.part.ViewPart;

public class LogStreamView extends ViewPart implements LogStreamCallback {
    private LogStreamService logStreamService;
    private Table table;

	public LogStreamView() {
	    logStreamService = new LogStreamServiceImpl("/tmp/test.txt");
	    logStreamService.registerCallback(this);
	    logStreamService.start();
	}

	@Override
	public void createPartControl(final Composite parent) {
	    table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
	    table.setHeaderVisible(true);
	    table.setLinesVisible(true);
	}

    @Override
    public void setFocus() {
        System.out.println("setFocus");
    }

    @Override
    public void onStreamChanged(final List<String> pufferedLines) {
        table.getDisplay().syncExec(() -> {
            TableItem tableItem = null;
            for (String string : pufferedLines) {
                tableItem = new TableItem(table, SWT.NONE);
                tableItem.setText(string);
            }
            if (tableItem != null) {
                table.showItem(tableItem);
            }
        });
    }

    @Override
    public void dispose() {
        logStreamService.stop();
    }

}

@@ -232,16 +232,235 @@
 .List;%0A%0A
+import org.eclipse.jface.action.Action;%0Aimport org.eclipse.jface.action.IAction;%0Aimport org.eclipse.jface.action.IMenuManager;%0Aimport org.eclipse.jface.action.IToolBarManager;%0Aimport org.eclipse.jface.action.Separator;%0A
 import o
@@ -601,16 +601,122 @@
 leItem;%0A
+import org.eclipse.ui.IActionBars;%0Aimport org.eclipse.ui.ISharedImages;%0Aimport org.eclipse.ui.PlatformUI;%0A
 import o
@@ -836,66 +836,292 @@
 ate 
-LogStreamService logStreamService;%0A    private Table table
+final String LOG_FILE = %22/home/zsoltdoma/svn/cams-raca/offline/trunk/production/core/target/eosgi-dist/racaof-production-main/log/wrapper.log%22;%0A%0A    private LogStreamService logStreamService;%0A    private Table table;%0A    private IAction clearAction;%0A    private IAction openFileAction
 ;%0A%0A%09
@@ -1198,23 +1198,16 @@
 mpl(
-%22/tmp/test.txt%22
+LOG_FILE
 );%0A%09
@@ -1488,17 +1488,1684 @@
 (true);%0A
-%09
+%0A%09    clearAction = createClearMenu();%0A%09    openFileAction = createOpenFileAction();%0A%0A%09    IActionBars bars = getViewSite().getActionBars();%0A%0A%09    IToolBarManager toolBarManager = bars.getToolBarManager();%0A%09    createToolBar(toolBarManager);%0A%0A%09    IMenuManager menuManager = bars.getMenuManager();%0A%09    createMenu(menuManager);%0A%09%7D%0A%0A%09private IAction createOpenFileAction() %7B%0A%09    IAction openFileAction = new Action() %7B%0A%09        @Override%0A%09        public void run() %7B%0A%09            System.out.println(%22open file action%22);%0A%09        %7D%0A        %7D;%0A        openFileAction.setText(%22Open file%22);%0A        openFileAction.setToolTipText(%22Open file for follow as log%22);%0A        openFileAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().%0A            getImageDescriptor(ISharedImages.IMG_OBJ_FILE));%0A%0A        return openFileAction;%0A    %7D%0A%0A    public void createMenu(final IMenuManager menuManager) %7B%0A%09    menuManager.add(clearAction);%0A%09    menuManager.add(new Separator());%0A%09    menuManager.add(openFileAction);%0A%09%7D%0A%0A    public void createToolBar(final IToolBarManager toolBarManager) %7B%0A        toolBarManager.add(clearAction);%0A    %7D%0A%0A    public IAction createClearMenu() %7B%0A        IAction action1 = new Action() %7B%0A            @Override%0A            public void run() %7B%0A                table.getDisplay().syncExec(() -%3E %7B%0A                    table.clearAll();%0A                %7D);%0A            %7D%0A        %7D;;%0A        action1.setText(%22Clear%22);%0A        action1.setToolTipText(%22Clear console log%22);%0A        action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().%0A            getImageDescriptor(ISharedImages.IMG_ETOOL_CLEAR));%0A        return action1;%0A    
 %7D%0A%0A    @

Add clear and openFile action.