From 9a87274d7de4c4e0973eb95e10000cad3dca1f4f Mon Sep 17 00:00:00 2001 From: Andre Bossert Date: Mon, 29 Jan 2018 15:14:37 +0100 Subject: [PATCH] updated file headers for this PR and fixed some warnings Signed-off-by: Andre Bossert --- .../build.properties | 1 - .../plugin/ConsolePageParticipant.java | 142 +++++++++--------- .../logviewer/plugin/ILogViewerConstants.java | 56 +++---- .../eclipse/logviewer/plugin/LogViewer.java | 24 +-- .../plugin/LogfileUIMessages.properties | 22 +-- .../eclipse/logviewer/plugin/UIImages.java | 57 +++---- .../plugin/action/FileClearAction.java | 82 +++++----- .../delegate/FileClearActionDelegate.java | 88 +++++------ .../plugin/file/BackgroundReader.java | 8 +- .../logviewer/plugin/file/ConsoleTail.java | 26 ++-- .../logviewer/plugin/file/FileTail.java | 32 ++-- .../plugin/file/document/LogDocument.java | 2 + 12 files changed, 274 insertions(+), 266 deletions(-) diff --git a/de.anbos.eclipse.logviewer.plugin/build.properties b/de.anbos.eclipse.logviewer.plugin/build.properties index bba1531..9678ac7 100644 --- a/de.anbos.eclipse.logviewer.plugin/build.properties +++ b/de.anbos.eclipse.logviewer.plugin/build.properties @@ -7,6 +7,5 @@ bin.includes = plugin.xml,\ plugin_de.properties,\ target/logviewer-lib.jar src.includes = lib/,\ - bin/,\ icons/ source.target/logviewer-lib.jar = src/ diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/ConsolePageParticipant.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/ConsolePageParticipant.java index fe29910..5f186ce 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/ConsolePageParticipant.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/ConsolePageParticipant.java @@ -1,71 +1,71 @@ -/* - * Copyright 2009, 2010 by Andre Bossert - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package de.anbos.eclipse.logviewer.plugin; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.console.IConsole; -import org.eclipse.ui.console.IConsoleConstants; -import org.eclipse.ui.console.IConsolePageParticipant; -import org.eclipse.ui.part.IPageBookViewPage; - -import de.anbos.eclipse.logviewer.plugin.action.ConsoleOpenAction; - -public class ConsolePageParticipant implements IConsolePageParticipant { - - private IPageBookViewPage page; - - public void activated() { - // no op - } - - public void deactivated() { - // no op - } - - public void dispose() { - page = null; - } - - public void init(IPageBookViewPage myPage, IConsole console) { - page = myPage; - IToolBarManager toolBarManager = page.getSite().getActionBars() - .getToolBarManager(); - toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, new Separator()); - toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, new Action( - LogViewerPlugin.getResourceString("logviewer.action.openwith.name"), - UIImages.getImageDescriptor(ILogViewerConstants.IMG_LOG_VIEWER)) { - public void run() { - ConsolePageParticipant.this.run(); - } - }); - } - - @SuppressWarnings("rawtypes") - public Object getAdapter(Class adapter) { - return null; - } - - private void run() { - IWorkbenchPart part = page.getSite().getWorkbenchWindow().getActivePage().getActivePart(); - ConsoleOpenAction action = EditorPropertyTester.hasAbstractConsole(part); - if (action != null) - action.run(null); - } - -} +/* + * Copyright 2009, 2010 by Andre Bossert + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package de.anbos.eclipse.logviewer.plugin; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsolePageParticipant; +import org.eclipse.ui.part.IPageBookViewPage; + +import de.anbos.eclipse.logviewer.plugin.action.ConsoleOpenAction; + +public class ConsolePageParticipant implements IConsolePageParticipant { + + private IPageBookViewPage page; + + public void activated() { + // no op + } + + public void deactivated() { + // no op + } + + public void dispose() { + page = null; + } + + public void init(IPageBookViewPage myPage, IConsole console) { + page = myPage; + IToolBarManager toolBarManager = page.getSite().getActionBars() + .getToolBarManager(); + toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, new Separator()); + toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, new Action( + LogViewerPlugin.getResourceString("logviewer.action.openwith.name"), + UIImages.getImageDescriptor(ILogViewerConstants.IMG_LOG_VIEWER)) { + public void run() { + ConsolePageParticipant.this.run(); + } + }); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Object getAdapter(Class adapter) { + return null; + } + + private void run() { + IWorkbenchPart part = page.getSite().getWorkbenchWindow().getActivePage().getActivePart(); + ConsoleOpenAction action = EditorPropertyTester.hasAbstractConsole(part); + if (action != null) + action.run(null); + } + +} diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/ILogViewerConstants.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/ILogViewerConstants.java index 1e4e99c..ce5a0b7 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/ILogViewerConstants.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/ILogViewerConstants.java @@ -1,29 +1,29 @@ - -package de.anbos.eclipse.logviewer.plugin; - -/* +/******************************************************************************* * Copyright (c) 2007 - 2011 by Michael Mimo Moratti - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2012 - 2018 by Andre Bossert * - * http://www.apache.org/licenses/LICENSE-2.0 + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions - * and limitations under the License. - */ + * Contributors: + * Michael Mimo Moratti - initial API and implementation and/or initial documentation + * Andre Bossert - extensions + * Artur Wozniak - clear file + * + *******************************************************************************/ + +package de.anbos.eclipse.logviewer.plugin; public interface ILogViewerConstants { // FileTail settings ----------------------------------------------------------- - + public static final long TAIL_FILEOPEN_ERROR_WAIT = 500; - + // Images ------------------------------------------------------------------ - + public static final String IMG_OPEN_FILE_ACTIVE = "IMG_OPEN_FILE_ACTIVE"; //$NON-NLS-1$ public static final String IMG_OPEN_FILE_PASSIVE = "IMG_OPEN_FILE_PASSIVE"; //$NON-NLS-1$ public static final String IMG_CLEAR_HISTORY_ACTIVE = "IMG_CLEAR_HISTORY_ACTIVE"; //$NON-NLS-1$ @@ -56,36 +56,36 @@ public interface ILogViewerConstants { public static final String IMG_LOG_VIEWER = "IMG_LOG_VIEWER"; public static final String IMG_FILE_CLEAR_ACTIVE = "IMG_CLEAR_ACTIVE"; //$NON-NLS-1$ public static final String IMG_FILE_CLEAR_PASSIVE = "IMG_CLEAR_PASSIVE"; //$NON-NLS-1$ - + // Preferences ------------------------------------------------------------- - + /* defines the maximal amount of rows that are backloged */ public static final int MAX_BACKLOG = 200000; public static final int DEFAULT_BACKLOG = 4000; public static final String PREF_BACKLOG = "BACKLOG"; //$NON-NLS-1$ - + public static final int MAX_TAIL_BUFFER_SIZE = 4096; public static final int DEFAULT_BUFFER_CAPACITY = 1024; public static final String PREF_BUFFER = "BUFFER"; //$NON-NLS-1$ - + public static final int MAX_READWAIT_SIZE = 1000000; public static final int DEFAULT_READWAIT_SIZE = 250; public static final String PREF_READWAIT = "READWAIT"; //$NON-NLS-1$ - + public static final String PREF_ENCODING = "ENCODING"; //$NON-NLS-1$ - + public static final String PREF_CURSORLINE_COLOR = "CURSOR_LINE_COLOR"; //$NON-NLS-1$ - + public static final String PREF_EDITOR_FONT_STYLE = "EDITOR_FONT_SYLE"; //$NON-NLS-1$ - + public static final String PREF_COLORING_ITEMS = "ITEM_COLORING"; //$NON-NLS-1$ - + public static final String PREF_LAST_OPEN_FILES = "LAST_OPEN_FILES"; //$NON-NLS-1$ - + /* defines the maximum amount of files in the drop down history */ public static final int MAX_FILES_IN_HISTORY = 10; public static final String PREF_HISTORY_FILES = "HISTORY_FILES"; //$NON-NLS-1$ - + /* word wrap */ public static boolean DEAFULT_WORD_WRAP = false; public static final String PREF_WORD_WRAP = "WORD_WRAP"; //$NON-NLS-1$ diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/LogViewer.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/LogViewer.java index 09414e5..eb47de6 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/LogViewer.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/LogViewer.java @@ -10,6 +10,8 @@ * Contributors: * Michael Mimo Moratti - initial API and implementation and/or initial documentation * Andre Bossert - extensions + * Artur Wozniak - clear file + * *******************************************************************************/ package de.anbos.eclipse.logviewer.plugin; @@ -178,7 +180,7 @@ public void closeCurrentLogFile() { } catch(IOException e) { logger.logError("unable to remove the current; active tab"); //$NON-NLS-1$ } - + int index = tabfolder.getSelectionIndex(); getSelectedItem().dispose(); if (!greyAllOutIfNoFiles()) { @@ -225,7 +227,7 @@ public void closeAllLogFiles() { Iterator keyIterator = logTab.keySet().iterator(); while(keyIterator.hasNext()) { Object key = keyIterator.next(); - LogFileTab tab = (LogFileTab)logTab.get(key); + LogFileTab tab = logTab.get(key); try { tab.close(); tab.getItem().dispose(); @@ -252,7 +254,7 @@ public void startTailOnAllDocuments() { Iterator keyIterator = logTab.keySet().iterator(); while(keyIterator.hasNext()) { Object key = keyIterator.next(); - LogFileTab tab = (LogFileTab)logTab.get(key); + LogFileTab tab = logTab.get(key); tab.getDocument().setMonitor(true); } setMonitorCounterToMax(); @@ -263,7 +265,7 @@ public void stopTailOnAllDocuments() { Iterator keyIterator = logTab.keySet().iterator(); while(keyIterator.hasNext()) { Object key = keyIterator.next(); - LogFileTab tab = (LogFileTab)logTab.get(key); + LogFileTab tab = logTab.get(key); tab.getDocument().setMonitor(false); } @@ -393,7 +395,7 @@ public void openLogFile(LogFile file) { if (file.getNamePattern().equals(LogViewerPlugin.getResourceString("logviewer.plugin.console.name"))) { createConsole(); } - + String encoding = LogViewerPlugin.getDefault().getPreferenceStore().getString(ILogViewerConstants.PREF_ENCODING); LogDocument document = new LogDocument(file,encoding); TabItem item = new TabItem(tabfolder,0); @@ -424,7 +426,7 @@ public void openLogFile(LogFile file) { } } // show active document - LogFileTab tab = (LogFileTab)logTab.get(key); + LogFileTab tab = logTab.get(key); try { showDocument(tab.getDocument(),null,0,true); tabfolder.setSelection(new TabItem[] {tab.getItem()}); @@ -466,7 +468,7 @@ public LogFileViewer getViewer() { * the actual viewer is returned if an adapter of type * FindReplaceTarget is searched */ - @SuppressWarnings("rawtypes") + @SuppressWarnings({ "rawtypes", "unchecked" }) public Object getAdapter(Class adapter) { Object object = super.getAdapter(adapter); if(object != null) { @@ -490,7 +492,7 @@ public void setCurrentLogFileTabName(String name) { public String getCurrentLogFilePath() { return getSelectedTab().getDocument().getFile().getPath(); } - + public void dispose() { viewer.removeListeners(); storeAllCurrentlyOpenFiles(); @@ -612,7 +614,7 @@ protected void showDocument(LogDocument document, ISelection sel, int index, boo private LogFileTab getSelectedTab(TabItem item) { if(item != null) { for(Iterator iter = logTab.values().iterator(); iter.hasNext();) { - LogFileTab logTab = (LogFileTab)iter.next(); + LogFileTab logTab = iter.next(); if(logTab.getItem() == item) { return logTab; } @@ -682,7 +684,7 @@ private void storeAllCurrentlyOpenFiles() { Iterator keyIterator = logTab.keySet().iterator(); while(keyIterator.hasNext()) { Object key = keyIterator.next(); - LogFileTab tab = (LogFileTab)logTab.get(key); + LogFileTab tab = logTab.get(key); LogFile logFile = tab.getDocument().getFile(); fileList.add(logFile); } @@ -736,7 +738,7 @@ public void documentChanged(DocumentEvent event) { Iterator keyIterator = logTab.keySet().iterator(); while(keyIterator.hasNext()) { Object key = keyIterator.next(); - LogFileTab newTab = (LogFileTab)logTab.get(key); + LogFileTab newTab = logTab.get(key); if (event.getDocument() == newTab.getDocument()) { showDocument(newTab.getDocument(),null,0,true); tabfolder.setSelection(new TabItem[] {newTab.getItem()}); diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/LogfileUIMessages.properties b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/LogfileUIMessages.properties index ba43625..76120d1 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/LogfileUIMessages.properties +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/LogfileUIMessages.properties @@ -1,16 +1,16 @@ - # Copyright (c) 2007 - 2009 by Michael Mimo Moratti - # Copyright (c) 2010 - 2011 by Andre Bossert - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at # - # http://www.apache.org/licenses/LICENSE-2.0 + # Copyright (c) 2007 - 2011 by Michael Mimo Moratti + # Copyright (c) 2012 - 2018 by Andre Bossert + # + # All rights reserved. This program and the accompanying materials + # are made available under the terms of the Eclipse Public License v1.0 + # which accompanies this distribution, and is available at + # http://www.eclipse.org/legal/epl-v10.html + # + # Contributors: + # Michael Mimo Moratti - initial API and implementation and/or initial documentation + # Andre Bossert - extensions # - # Unless required by applicable law or agreed to in writing, - # software distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions - # and limitations under the License. # see plugin.properties logviewer.action.openwith.name=Open with LogViewer diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/UIImages.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/UIImages.java index 6bba83d..66b8f2c 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/UIImages.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/UIImages.java @@ -1,3 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2011 by Michael Mimo Moratti + * Copyright (c) 2012 - 2018 by Andre Bossert + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Mimo Moratti - initial API and implementation and/or initial documentation + * Andre Bossert - extensions + * Artur Wozniak - clear file + * + *******************************************************************************/ + package de.anbos.eclipse.logviewer.plugin; import java.net.MalformedURLException; @@ -7,56 +23,41 @@ import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.widgets.Display; -/* - * Copyright (c) 2007 - 2011 by Michael Mimo Moratti - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions - * and limitations under the License. - */ - public class UIImages { // Attribute --------------------------------------------------------------- - + private static URL ICON_BASE_URL = null; - + private static ImageRegistry imageRegistry = null; - + // Constructor ------------------------------------------------------------- - + public UIImages() { } - + // Static ------------------------------------------------------------------ - + static { String pathSuffix = "icons/"; //$NON-NLS-1$ try { ICON_BASE_URL = new URL(LogViewerPlugin.getDefault().getBundle().getEntry("/"), pathSuffix); //$NON-NLS-1$ } catch(MalformedURLException ex) { } } - + public static ImageDescriptor getImageDescriptor(String key) { return getImageRegistry().getDescriptor(key); } - + // Private ----------------------------------------------------------------- - + private static ImageRegistry getImageRegistry() { if(imageRegistry == null) { initializeImageRegistry(); } return imageRegistry; } - + private static ImageRegistry initializeImageRegistry() { Display display = Display.getCurrent(); if(display == null) { @@ -64,7 +65,7 @@ private static ImageRegistry initializeImageRegistry() { } imageRegistry = new ImageRegistry(display); // register images - + declareRegistryImage(ILogViewerConstants.IMG_OPEN_FILE_ACTIVE, "active/open_active.gif"); //$NON-NLS-1$ declareRegistryImage(ILogViewerConstants.IMG_OPEN_FILE_PASSIVE, "passive/open_passive.gif"); //$NON-NLS-1$ declareRegistryImage(ILogViewerConstants.IMG_CLEAR_HISTORY_ACTIVE, "active/removeall_active.gif"); //$NON-NLS-1$ @@ -100,7 +101,7 @@ private static ImageRegistry initializeImageRegistry() { return imageRegistry; } - + private static void declareRegistryImage(String key, String path) { ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor(); try { @@ -110,7 +111,7 @@ private static void declareRegistryImage(String key, String path) { } imageRegistry.put(key, desc); } - + private static URL makeIconFileURL(String iconPath) throws MalformedURLException { if(ICON_BASE_URL == null) { throw new MalformedURLException(); diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/action/FileClearAction.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/action/FileClearAction.java index f8cbb72..9da5e6b 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/action/FileClearAction.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/action/FileClearAction.java @@ -1,41 +1,41 @@ -/******************************************************************************* - * Copyright (c) 2009 - 2018 by Andre Bossert - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andre Bossert - initial API and implementation and/or initial documentation - *******************************************************************************/ - -package de.anbos.eclipse.logviewer.plugin.action; - -import org.eclipse.swt.widgets.Shell; - -import de.anbos.eclipse.logviewer.plugin.ILogViewerConstants; -import de.anbos.eclipse.logviewer.plugin.LogViewer; -import de.anbos.eclipse.logviewer.plugin.LogViewerPlugin; -import de.anbos.eclipse.logviewer.plugin.UIImages; -import de.anbos.eclipse.logviewer.plugin.action.delegate.FileClearActionDelegate; - -public class FileClearAction extends AbstractViewAction { - - // Constructor - // ------------------------------------------------------------------ - - public FileClearAction(LogViewer view, Shell shell) { - super(view, shell, new FileClearActionDelegate()); - } - - // Public - // ----------------------------------------------------------------------- - - public void init() { - this.setText(LogViewerPlugin.getResourceString("menu.file.clear.text")); //$NON-NLS-1$ - this.setToolTipText(LogViewerPlugin.getResourceString("menu.file.clear.tooltip")); //$NON-NLS-1$ - this.setImageDescriptor(UIImages.getImageDescriptor(ILogViewerConstants.IMG_FILE_CLEAR_ACTIVE)); - this.setDisabledImageDescriptor(UIImages.getImageDescriptor(ILogViewerConstants.IMG_FILE_CLEAR_PASSIVE)); - } -} +/******************************************************************************* + * Copyright (c) 2009 - 2018 by Andre Bossert + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Artur Wozniak - clear file + *******************************************************************************/ + +package de.anbos.eclipse.logviewer.plugin.action; + +import org.eclipse.swt.widgets.Shell; + +import de.anbos.eclipse.logviewer.plugin.ILogViewerConstants; +import de.anbos.eclipse.logviewer.plugin.LogViewer; +import de.anbos.eclipse.logviewer.plugin.LogViewerPlugin; +import de.anbos.eclipse.logviewer.plugin.UIImages; +import de.anbos.eclipse.logviewer.plugin.action.delegate.FileClearActionDelegate; + +public class FileClearAction extends AbstractViewAction { + + // Constructor + // ------------------------------------------------------------------ + + public FileClearAction(LogViewer view, Shell shell) { + super(view, shell, new FileClearActionDelegate()); + } + + // Public + // ----------------------------------------------------------------------- + + public void init() { + this.setText(LogViewerPlugin.getResourceString("menu.file.clear.text")); //$NON-NLS-1$ + this.setToolTipText(LogViewerPlugin.getResourceString("menu.file.clear.tooltip")); //$NON-NLS-1$ + this.setImageDescriptor(UIImages.getImageDescriptor(ILogViewerConstants.IMG_FILE_CLEAR_ACTIVE)); + this.setDisabledImageDescriptor(UIImages.getImageDescriptor(ILogViewerConstants.IMG_FILE_CLEAR_PASSIVE)); + } +} diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/action/delegate/FileClearActionDelegate.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/action/delegate/FileClearActionDelegate.java index 07b92e1..fb713c2 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/action/delegate/FileClearActionDelegate.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/action/delegate/FileClearActionDelegate.java @@ -1,44 +1,44 @@ -/******************************************************************************* - * Copyright (c) 2009 - 2018 by Andre Bossert - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andre Bossert - initial API and implementation and/or initial documentation - *******************************************************************************/ - -package de.anbos.eclipse.logviewer.plugin.action.delegate; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Shell; -import de.anbos.eclipse.logviewer.plugin.LogFile.LogFileType; -import de.anbos.eclipse.logviewer.plugin.LogViewer; -import de.anbos.eclipse.logviewer.plugin.LogViewerPlugin; - -public class FileClearActionDelegate implements ILogViewerActionDelegate { - - /* - * (non-Javadoc) - * - * @see - * de.anbos.eclipse.logviewer.plugin.action.ILogfileAction#run(de.anbos. - * eclipse.logviewer.plugin.LogViewer, org.eclipse.swt.widgets.Shell) - */ - public void run(LogViewer view, Shell shell) { - - LogFileType type = view.getCurrentDocument().getFile().getType(); - if (type == LogFileType.LOGFILE_ECLIPSE_CONSOLE) { - view.clearCurrentLogFile(); - } else if (confirmFileClear(shell)) { - view.clearCurrentLogFile(); - } - } - - private boolean confirmFileClear(Shell shell) { - return MessageDialog.openQuestion(shell, LogViewerPlugin.getResourceString("dialog.file.clear.title"), //$NON-NLS-1$ - LogViewerPlugin.getResourceString("dialog.file.clear.text")); //$NON-NLS-1$ - } -} +/******************************************************************************* + * Copyright (c) 2009 - 2018 by Andre Bossert + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Artur Wozniak - clear file + *******************************************************************************/ + +package de.anbos.eclipse.logviewer.plugin.action.delegate; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import de.anbos.eclipse.logviewer.plugin.LogFile.LogFileType; +import de.anbos.eclipse.logviewer.plugin.LogViewer; +import de.anbos.eclipse.logviewer.plugin.LogViewerPlugin; + +public class FileClearActionDelegate implements ILogViewerActionDelegate { + + /* + * (non-Javadoc) + * + * @see + * de.anbos.eclipse.logviewer.plugin.action.ILogfileAction#run(de.anbos. + * eclipse.logviewer.plugin.LogViewer, org.eclipse.swt.widgets.Shell) + */ + public void run(LogViewer view, Shell shell) { + + LogFileType type = view.getCurrentDocument().getFile().getType(); + if (type == LogFileType.LOGFILE_ECLIPSE_CONSOLE) { + view.clearCurrentLogFile(); + } else if (confirmFileClear(shell)) { + view.clearCurrentLogFile(); + } + } + + private boolean confirmFileClear(Shell shell) { + return MessageDialog.openQuestion(shell, LogViewerPlugin.getResourceString("dialog.file.clear.title"), //$NON-NLS-1$ + LogViewerPlugin.getResourceString("dialog.file.clear.text")); //$NON-NLS-1$ + } +} diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/BackgroundReader.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/BackgroundReader.java index 1842a14..026b391 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/BackgroundReader.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/BackgroundReader.java @@ -1,13 +1,15 @@ /******************************************************************************* * Copyright (c) 2009 - 2018 by Andre Bossert - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Andre Bossert - initial API and implementation and/or initial documentation + * Artur Wozniak - clear file + * *******************************************************************************/ @@ -33,7 +35,7 @@ public BackgroundReader(LogFileType type, String path, String namePattern, Chars consoleTail = new ConsoleTail(path, namePattern, listener); } } - + public void setMonitorStatus(boolean monitor) { if (type == LogFileType.LOGFILE_SYSTEM_FILE) { fileTail.setMonitorStatus(monitor); diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/ConsoleTail.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/ConsoleTail.java index f681edc..ff64fe2 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/ConsoleTail.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/ConsoleTail.java @@ -1,13 +1,15 @@ /******************************************************************************* * Copyright (c) 2009 - 2018 by Andre Bossert - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Andre Bossert - initial API and implementation and/or initial documentation + * Artur Wozniak - clear file + * *******************************************************************************/ package de.anbos.eclipse.logviewer.plugin.file; @@ -42,7 +44,7 @@ public class ConsoleTail implements IDocumentListener, Runnable { - private Logger logger; + private Logger logger; private String path; private String namePattern; private IFileChangedListener listener; @@ -95,7 +97,7 @@ public String getConsolePath(IConsole console) { public String getNamePattern() { return namePattern; } - + public String getClassName() { int idx = path.indexOf(System.getProperty("file.separator")); return idx != -1 ? path.substring(0, idx) : path; @@ -109,7 +111,7 @@ public void documentChanged(DocumentEvent event) { listener.fileChanged(event.getText().toCharArray(), isFirstTimeRead); isFirstTimeRead = false; } - + public synchronized void run() { isRunning = true; try { @@ -123,7 +125,7 @@ public synchronized void run() { event.fText = doc.get(); documentAboutToBeChanged(event); documentChanged(event); - } + } } else { throw new ThreadInterruptedException("document was null"); //$NON-NLS-1$ } @@ -142,7 +144,7 @@ public synchronized void run() { try { if(doc != null) { doc.removeDocumentListener(this); - isFirstTimeRead = true; + isFirstTimeRead = true; } } catch(Exception e) { // ignore this @@ -178,7 +180,7 @@ private synchronized IDocument openConsole() throws ThreadInterruptedException { } throw new ThreadInterruptedException("no console found"); //$NON-NLS-1$ } - + private IConsole findConsole() throws FileNotFoundException { ConsolePlugin conPlugin = ConsolePlugin.getDefault(); IConsoleManager conMan = conPlugin.getConsoleManager(); @@ -217,12 +219,12 @@ private IConsole createConsole(String className) throws ClassNotFoundException, //return null; } */ - + private IDocument getConsoleDocument() throws FileNotFoundException { if (con != null) { if(con instanceof TextConsole) { return ((TextConsole)con).getDocument(); - } else { + } else { // Now open the view and console in UI-Thread UIJob uiJob = new UIJob("Update UI") { @Override @@ -234,7 +236,7 @@ public IStatus runInUIThread(IProgressMonitor monitor) { e.printStackTrace(); } if (view != null) { - // show it + // show it view.display(con); IViewPart vp =(IViewPart)view; if (vp instanceof PageBookView) { @@ -249,7 +251,7 @@ public IStatus runInUIThread(IProgressMonitor monitor) { }; uiJob.schedule(); if (viewer != null) - return viewer.getDocument(); + return viewer.getDocument(); } } throw new FileNotFoundException("no document found"); diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/FileTail.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/FileTail.java index f6a9841..8f1dfa5 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/FileTail.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/FileTail.java @@ -1,24 +1,24 @@ -/* +/******************************************************************************* * Copyright (c) 2007 - 2011 by Michael Mimo Moratti - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2012 - 2018 by Andre Bossert * - * http://www.apache.org/licenses/LICENSE-2.0 + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions - * and limitations under the License. - */ + * Contributors: + * Michael Mimo Moratti - initial API and implementation and/or initial documentation + * Andre Bossert - extensions + * Artur Wozniak - clear file + * + *******************************************************************************/ package de.anbos.eclipse.logviewer.plugin.file; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -101,7 +101,7 @@ public synchronized void run() { // no exeption if file not found, because it's predictable // see Issue 55: Improve FileTail's exception handling //logger.logError(fnf); - listener.fileChanged(LogViewerPlugin.getResourceString("tail.loading.file.notfound",new String[]{filePath}).toCharArray(),true); + listener.fileChanged(LogViewerPlugin.getResourceString("tail.loading.file.notfound",new String[]{filePath}).toCharArray(),true); } catch(ThreadInterruptedException tie) { logger.logError(tie); listener.fileChanged(LogViewerPlugin.getResourceString("tail.loading.file.error",new String[]{filePath}).toCharArray(),true); @@ -116,8 +116,8 @@ public synchronized void run() { try { if(file != null) { file.close(); - - if(isRunning==false && mappedBuffer!=null) + + if(isRunning==false && mappedBuffer!=null) { stopFileMapping(mappedBuffer); } @@ -141,7 +141,7 @@ public void stopFileMapping(Buffer buffer)throws Exception { // Private ----------------------------------------------------------------- private synchronized RandomAccessFile openFile() throws ThreadInterruptedException, FileNotFoundException { - boolean firstExec = true; + boolean firstExec = true; while(isRunning) { try { RandomAccessFile file = new RandomAccessFile(filePath,"r"); //$NON-NLS-1$ diff --git a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/document/LogDocument.java b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/document/LogDocument.java index 22b33e6..ffd45a5 100644 --- a/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/document/LogDocument.java +++ b/de.anbos.eclipse.logviewer.plugin/src/de/anbos/eclipse/logviewer/plugin/file/document/LogDocument.java @@ -10,6 +10,8 @@ * Contributors: * Michael Mimo Moratti - initial API and implementation and/or initial documentation * Andre Bossert - extensions + * Artur Wozniak - clear file + * *******************************************************************************/ package de.anbos.eclipse.logviewer.plugin.file.document;