From 2c68fad68a68b3e2af2e8634e0418384faa63219 Mon Sep 17 00:00:00 2001 From: bananeweizen Date: Tue, 31 Jan 2006 08:19:55 +0000 Subject: [PATCH] Removed PHP debug log view. The main PHPeclipse feature includes the Eclipse standard error log view, so this source copy is not necessary. --- net.sourceforge.phpeclipse.xdebug.ui/plugin.xml | 12 - .../ui/views/logview/EventDetailsDialog.java | 630 ------------- .../ui/views/logview/EventDetailsDialogAction.java | 94 -- .../xdebug/ui/views/logview/FilterDialog.java | 164 ---- .../xdebug/ui/views/logview/LogEntry.java | 237 ----- .../xdebug/ui/views/logview/LogReader.java | 308 ------ .../xdebug/ui/views/logview/LogSession.java | 60 -- .../xdebug/ui/views/logview/LogView.java | 993 -------------------- .../ui/views/logview/LogViewContentProvider.java | 43 - .../ui/views/logview/LogViewLabelProvider.java | 68 -- .../xdebug/ui/views/logview/OpenLogDialog.java | 269 ------ 11 files changed, 0 insertions(+), 2878 deletions(-) delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/EventDetailsDialog.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/EventDetailsDialogAction.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/FilterDialog.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogEntry.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogReader.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogSession.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogView.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogViewContentProvider.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogViewLabelProvider.java delete mode 100644 net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/OpenLogDialog.java diff --git a/net.sourceforge.phpeclipse.xdebug.ui/plugin.xml b/net.sourceforge.phpeclipse.xdebug.ui/plugin.xml index eaac04e..a29c3bc 100644 --- a/net.sourceforge.phpeclipse.xdebug.ui/plugin.xml +++ b/net.sourceforge.phpeclipse.xdebug.ui/plugin.xml @@ -36,18 +36,6 @@ - - - - 0) - width -= 100; - else - width = width/2; - sashWeights = new int[]{width, getSashForm().getClientArea().width-width}; - } - getSashForm().setWeights(sashWeights); - return super.open(); - } - - public boolean close() { - storeSettings(); - isOpen = false; - imgCopyEnabled.dispose(); - imgNextEnabled.dispose(); - imgPrevEnabled.dispose(); - return super.close(); - } - - public void create() { - super.create(); - - // dialog location - if (dialogLocation != null) - getShell().setLocation(dialogLocation); - - // dialog size - if (dialogSize != null) - getShell().setSize(dialogSize); - else - getShell().setSize(500,550); - - - applyDialogFont(buttonBar); - getButton(IDialogConstants.OK_ID).setFocus(); - } - - protected void buttonPressed(int buttonId) { - if (IDialogConstants.OK_ID == buttonId) - okPressed(); - else if (IDialogConstants.CANCEL_ID == buttonId) - cancelPressed(); - else if (IDialogConstants.BACK_ID == buttonId) - backPressed(); - else if (IDialogConstants.NEXT_ID == buttonId) - nextPressed(); - else if (COPY_ID == buttonId) - copyPressed(); - } - - protected void backPressed() { - if (isChild(entry)) { - if (childIndex > 0) { - childIndex--; - entry = entryChildren[childIndex]; - } else - entry = parentEntry; - } else { - if (elementNum - 1 >= 0) - elementNum -= 1; - entry = (LogEntry) provider.getElementAt(elementNum); - } - setEntrySelectionInTable(); - } - - protected void nextPressed() { - if (isChild(entry) && childIndex < entryChildren.length-1) { - childIndex++; - entry = entryChildren[childIndex]; - } else if (elementNum + 1 < totalElementCount){ - elementNum += 1; - entry = (LogEntry) provider.getElementAt(elementNum); - } else { // at end of list but can branch into child elements - bug 58083 - setEntryChildren(entry); - entry = entryChildren[0]; - } - setEntrySelectionInTable(); - } - - protected void copyPressed() { - StringWriter writer = new StringWriter(); - PrintWriter pwriter = new PrintWriter(writer); - - entry.write(pwriter); - pwriter.flush(); - String textVersion = writer.toString(); - try { - pwriter.close(); - writer.close(); - } catch (IOException e) { - } - // set the clipboard contents - clipboard.setContents(new Object[] { textVersion }, new Transfer[] { TextTransfer.getInstance()}); - } - - public void setComparator(Comparator comparator){ - this.comparator = comparator; - updateProperties(); - } - private void setComparator(byte sortType, final int sortOrder){ - if (sortType == LogView.DATE){ - comparator = new Comparator(){ - public int compare(Object e1, Object e2) { - try { - SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss.SS"); //$NON-NLS-1$ - Date date1 = formatter.parse(((LogEntry)e1).getDate()); - Date date2 = formatter.parse(((LogEntry)e2).getDate()); - if (sortOrder == ASCENDING) - return date1.before(date2) ? -1 : 1; - return date1.after(date2) ? -1 : 1; - } catch (ParseException e) { - } - return 0; - } - }; - } else if (sortType == LogView.PLUGIN){ - comparator = new Comparator(){ - public int compare(Object e1, Object e2) { - LogEntry entry1 = (LogEntry)e1; - LogEntry entry2 = (LogEntry)e2; - return collator.compare(entry1.getPluginId(), entry2.getPluginId()) * sortOrder; - } - }; - } else { - comparator = new Comparator(){ - public int compare(Object e1, Object e2) { - LogEntry entry1 = (LogEntry)e1; - LogEntry entry2 = (LogEntry)e2; - return collator.compare(entry1.getMessage(), entry2.getMessage()) * sortOrder; - } - }; - } - } - - public void resetSelection(IAdaptable selectedEntry, byte sortType, int sortOrder){ - setComparator(sortType, sortOrder); - resetSelection(selectedEntry); - } - - public void resetSelection(IAdaptable selectedEntry){ - if (entry.equals(selectedEntry) && - elementNum == getParentElementNum()){ - updateProperties(); - return; - } - entry = (LogEntry)selectedEntry; - initialize(); - updateProperties(); - } - - public void resetButtons(){ - backButton.setEnabled(false); - nextButton.setEnabled(false); - } - - private void setEntrySelectionInTable(){ - ISelection selection = new StructuredSelection(entry); - provider.setSelection(selection); - } - - public void updateProperties() { - if (isChild(entry)){ - parentEntry = (LogEntry) entry.getParent(entry); - setEntryChildren(parentEntry); - resetChildIndex(); - } - - - totalElementCount = provider.getTableTree().getTable().getItemCount() - getVisibleChildrenCount(); - dateLabel.setText(entry.getDate()); - severityImageLabel.setImage(labelProvider.getColumnImage(entry, 1)); - severityLabel.setText(entry.getSeverityText()); - msgText.setText(entry.getMessage()); - String stack = entry.getStack(); - if (stack != null) { - stackTraceText.setText(stack); - } else { - stackTraceText.setText(XDebugUIPlugin.getString(EVENT_NO_STACK)); - } - LogSession session = entry.getSession(); - if (session != null && session.getSessionData() != null) - sessionDataText.setText(session.getSessionData()); - - updateButtons(); - } - - private void updateButtons(){ - boolean isAtEnd = elementNum == totalElementCount - 1; - if (isChild(entry)){ - backButton.setEnabled(true); - boolean isLastChild = childIndex == entryChildren.length-1; - nextButton.setEnabled(!isLastChild || !isAtEnd || entry.hasChildren()); - } else { - backButton.setEnabled(elementNum != 0); - nextButton.setEnabled(!isAtEnd || entry.hasChildren()); - } - } - - private void setEntryChildren(LogEntry parent){ - Object[] children = parent.getChildren(parent); - if (comparator != null) - Arrays.sort(children, comparator); - entryChildren = new LogEntry[children.length]; - - System.arraycopy(children,0,entryChildren,0,children.length); - } - - private int getParentElementNum(){ - LogEntry itemEntry = (LogEntry)((IStructuredSelection)provider.getSelection()).getFirstElement(); - itemEntry = getRootEntry(itemEntry); - - for (int i = 0; i 0; - } - public String toString() { - return getSeverityText(); - } - /** - * @see IWorkbenchAdapter#getChildren(Object) - */ - public Object[] getChildren(Object parent) { - if (children == null) - return new Object[0]; - return children.toArray(); - } - - /** - * @see IWorkbenchAdapter#getImageDescriptor(Object) - */ - public ImageDescriptor getImageDescriptor(Object arg0) { - return null; - } - - /** - * @see IWorkbenchAdapter#getLabel(Object) - */ - public String getLabel(Object obj) { - return getSeverityText(); - } - - /** - * @see IWorkbenchAdapter#getParent(Object) - */ - public Object getParent(Object obj) { - return parent; - } - - void setParent(LogEntry parent) { - this.parent = parent; - } - - private String getSeverityText(int severity) { - switch (severity) { - case IStatus.ERROR : - return XDebugUIPlugin.getString(KEY_ERROR); - case IStatus.WARNING : - return XDebugUIPlugin.getString(KEY_WARNING); - case IStatus.INFO : - return XDebugUIPlugin.getString(KEY_INFO); - } - return "?"; //$NON-NLS-1$ - } - - int processLogLine(String line, boolean root) { - //!ENTRY - //!SUBENTRY - StringTokenizer stok = new StringTokenizer(line, " ", true); //$NON-NLS-1$ - StringBuffer dateBuffer = new StringBuffer(); - - int dateCount = 5; - int depth = 0; - for (int i = 0; stok.hasMoreTokens();) { - String token = stok.nextToken(); - if (i >= dateCount) { - dateBuffer.append(token); - continue; - } else if (token.equals(" ")) //$NON-NLS-1$ - continue; - switch (i) { - case 0 : // entry or subentry - if (root) - i += 2; - else - i++; - break; - case 1 : // depth - depth = parseInteger(token); - i++; - break; - case 2 : - pluginId = token; - i++; - break; - case 3 : // severity - severity = parseInteger(token); - i++; - break; - case 4 : // code - code = parseInteger(token); - i++; - break; - } - } - date = dateBuffer.toString().trim(); - return depth; - } - - private int parseInteger(String token) { - try { - return Integer.parseInt(token); - } catch (NumberFormatException e) { - return 0; - } - } - - void setStack(String stack) { - this.stack = stack; - } - void setMessage(String message) { - this.message = message; - } - - private void processStatus(IStatus status) { - pluginId = status.getPlugin(); - severity = status.getSeverity(); - code = status.getCode(); - DateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss.SS"); //$NON-NLS-1$ - date = formatter.format(new Date()); - message = status.getMessage(); - Throwable throwable = status.getException(); - if (throwable != null) { - StringWriter swriter = new StringWriter(); - PrintWriter pwriter = new PrintWriter(swriter); - throwable.printStackTrace(pwriter); - pwriter.flush(); - pwriter.close(); - stack = swriter.toString(); - } - IStatus[] schildren = status.getChildren(); - if (schildren.length > 0) { - children = new ArrayList(); - for (int i = 0; i < schildren.length; i++) { - LogEntry child = new LogEntry(schildren[i]); - addChild(child); - } - } - } - void addChild(LogEntry child) { - if (children == null) - children = new ArrayList(); - children.add(child); - child.setParent(this); - } - public void write(PrintWriter writer) { - writer.print(getSeverityText()); - if (date != null) { - writer.print(" "); //$NON-NLS-1$ - writer.print(getDate()); - } - if (message != null) { - writer.print(" "); //$NON-NLS-1$ - writer.print(getMessage()); - } - writer.println(); - if (stack != null) - writer.println(stack); - } -} diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogReader.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogReader.java deleted file mode 100644 index 7a33d18..0000000 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogReader.java +++ /dev/null @@ -1,308 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpeclipse.xdebug.ui.views.logview; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.io.RandomAccessFile; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Date; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.ui.IMemento; - -class LogReader { - private static final int SESSION_STATE = 10; - public static final long MAX_FILE_LENGTH = 1024*1024; - private static final int ENTRY_STATE = 20; - private static final int SUBENTRY_STATE = 30; - private static final int MESSAGE_STATE = 40; - private static final int STACK_STATE = 50; - private static final int TEXT_STATE = 60; - private static final int UNKNOWN_STATE = 70; - - private static LogSession currentSession; - - public static void parseLargeFile(File file, ArrayList entries, IMemento memento) { - ArrayList parents = new ArrayList(); - LogEntry current = null; - LogSession session = null; - int writerState = UNKNOWN_STATE; - StringWriter swriter = null; - PrintWriter writer = null; - int state = UNKNOWN_STATE; - currentSession = null; - RandomAccessFile random = null; - try { - random = new RandomAccessFile(file, "r"); //$NON-NLS-1$ - random.seek(file.length() - MAX_FILE_LENGTH); - for (;;) { - String line = random.readLine(); - if (line == null) - break; - - line = line.trim(); - if (line.length() == 0) - continue; - - if (line.startsWith("!SESSION")) { //$NON-NLS-1$ - state = SESSION_STATE; - } else if (line.startsWith("!ENTRY")) { //$NON-NLS-1$ - state = ENTRY_STATE; - } else if (line.startsWith("!SUBENTRY")) { //$NON-NLS-1$ - state = SUBENTRY_STATE; - } else if (line.startsWith("!MESSAGE")) { //$NON-NLS-1$ - state = MESSAGE_STATE; - } else if (line.startsWith("!STACK")) { //$NON-NLS-1$ - state = STACK_STATE; - } else - state = TEXT_STATE; - - if (state == TEXT_STATE) { - if (writer != null) - writer.println(line); - continue; - } - - if (writer != null) { - if (writerState == STACK_STATE && current != null) { - current.setStack(swriter.toString()); - } else if (writerState == SESSION_STATE && session != null) { - session.setSessionData(swriter.toString()); - } else if (writerState == MESSAGE_STATE && current != null){ - String message = current.getMessage() + swriter.toString(); - message = message.trim(); - current.setMessage(message); - } - writerState = UNKNOWN_STATE; - swriter = null; - writer.close(); - writer = null; - } - - if (state == STACK_STATE) { - swriter = new StringWriter(); - writer = new PrintWriter(swriter, true); - writerState = STACK_STATE; - } else if (state == SESSION_STATE) { - session = new LogSession(); - session.processLogLine(line); - swriter = new StringWriter(); - writer = new PrintWriter(swriter, true); - writerState = SESSION_STATE; - updateCurrentSession(session); - if (currentSession.equals(session) && !memento.getString(LogView.P_SHOW_ALL_SESSIONS).equals("true")) //$NON-NLS-1$ - entries.clear(); - } else if (state == ENTRY_STATE) { - LogEntry entry = new LogEntry(); - entry.setSession(session); - entry.processLogLine(line, true); - setNewParent(parents, entry, 0); - current = entry; - addEntry(current, entries, memento, false); - } else if (state == SUBENTRY_STATE) { - LogEntry entry = new LogEntry(); - entry.setSession(session); - int depth = entry.processLogLine(line, false); - setNewParent(parents, entry, depth); - current = entry; - LogEntry parent = (LogEntry) parents.get(depth - 1); - parent.addChild(entry); - } else if (state == MESSAGE_STATE) { - swriter = new StringWriter(); - writer = new PrintWriter(swriter, true); - String message = ""; //$NON-NLS-1$ - if (line.length() > 8) - message = line.substring(9).trim(); - message = message.trim(); - if (current != null) - current.setMessage(message); - writerState = MESSAGE_STATE; - } - } - } catch (FileNotFoundException e) { - } catch (IOException e) { - } finally { - try { - if (random != null) - random.close(); - } catch (IOException e1) { - } - } - } - - public static void parseLogFile(File file, ArrayList entries, IMemento memento) { - ArrayList parents = new ArrayList(); - LogEntry current = null; - LogSession session = null; - int writerState = UNKNOWN_STATE; - StringWriter swriter = null; - PrintWriter writer = null; - int state = UNKNOWN_STATE; - currentSession = null; - BufferedReader reader = null; - try { - - reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); //$NON-NLS-1$ - while(reader.ready()) { - String line = reader.readLine(); - if (line == null) - continue; - line = line.trim(); - if (line.length() == 0) - continue; - - if (line.startsWith("!SESSION")) { //$NON-NLS-1$ - state = SESSION_STATE; - } else if (line.startsWith("!ENTRY")) { //$NON-NLS-1$ - state = ENTRY_STATE; - } else if (line.startsWith("!SUBENTRY")) { //$NON-NLS-1$ - state = SUBENTRY_STATE; - } else if (line.startsWith("!MESSAGE")) { //$NON-NLS-1$ - state = MESSAGE_STATE; - } else if (line.startsWith("!STACK")) { //$NON-NLS-1$ - state = STACK_STATE; - } else - state = TEXT_STATE; - - if (state == TEXT_STATE) { - if (writer != null) - writer.println(line); - continue; - } - - if (writer != null) { - if (writerState == STACK_STATE && current != null) { - current.setStack(swriter.toString()); - } else if (writerState == SESSION_STATE && session != null) { - session.setSessionData(swriter.toString()); - } else if (writerState == MESSAGE_STATE && current != null){ - String message = current.getMessage() + swriter.toString(); - message = message.trim(); - current.setMessage(message); - } - writerState = UNKNOWN_STATE; - swriter = null; - writer.close(); - writer = null; - } - - if (state == STACK_STATE) { - swriter = new StringWriter(); - writer = new PrintWriter(swriter, true); - writerState = STACK_STATE; - } else if (state == SESSION_STATE) { - session = new LogSession(); - session.processLogLine(line); - swriter = new StringWriter(); - writer = new PrintWriter(swriter, true); - writerState = SESSION_STATE; - updateCurrentSession(session); - if (currentSession.equals(session) && !memento.getString(LogView.P_SHOW_ALL_SESSIONS).equals("true")) //$NON-NLS-1$ - entries.clear(); - } else if (state == ENTRY_STATE) { - LogEntry entry = new LogEntry(); - entry.setSession(session); - entry.processLogLine(line, true); - setNewParent(parents, entry, 0); - current = entry; - addEntry(current, entries, memento, false); - } else if (state == SUBENTRY_STATE) { - LogEntry entry = new LogEntry(); - entry.setSession(session); - int depth = entry.processLogLine(line, false); - setNewParent(parents, entry, depth); - current = entry; - LogEntry parent = (LogEntry) parents.get(depth - 1); - parent.addChild(entry); - } else if (state == MESSAGE_STATE) { - swriter = new StringWriter(); - writer = new PrintWriter(swriter, true); - String message = ""; //$NON-NLS-1$ - if (line.length() > 8) - message = line.substring(9).trim(); - message = message.trim(); - if (current != null) - current.setMessage(message); - writerState = MESSAGE_STATE; - } - } - } catch (FileNotFoundException e) { - } catch (IOException e) { - } finally { - try { - if (reader != null) - reader.close(); - } catch (IOException e1) { - } - } - } - - private static void updateCurrentSession(LogSession session) { - if (currentSession == null) { - currentSession = session; - return; - } - Date currentDate = currentSession.getDate(); - Date sessionDate = session.getDate(); - if (currentDate == null && sessionDate != null) - currentSession = session; - else if (currentDate != null && sessionDate == null) - currentSession = session; - else if (currentDate != null && sessionDate != null && sessionDate.after(currentDate)) - currentSession = session; - } - - public static void addEntry(LogEntry current, ArrayList entries, IMemento memento, boolean useCurrentSession) { - int severity = current.getSeverity(); - boolean doAdd = true; - switch(severity) { - case IStatus.INFO: - doAdd = memento.getString(LogView.P_LOG_INFO).equals("true"); //$NON-NLS-1$ - break; - case IStatus.WARNING: - doAdd = memento.getString(LogView.P_LOG_WARNING).equals("true"); //$NON-NLS-1$ - break; - case IStatus.ERROR: - doAdd = memento.getString(LogView.P_LOG_ERROR).equals("true"); //$NON-NLS-1$ - break; - } - if (doAdd) { - if (useCurrentSession) - current.setSession(currentSession); - entries.add(0, current); - - if (memento.getString(LogView.P_USE_LIMIT).equals("true") //$NON-NLS-1$ - && entries.size() > memento.getInteger(LogView.P_LOG_LIMIT).intValue()) - entries.remove(entries.size() - 1); - } - } - - private static void setNewParent( - ArrayList parents, - LogEntry entry, - int depth) { - if (depth + 1 > parents.size()) - parents.add(entry); - else - parents.set(depth, entry); - } - - public static void reset() { - currentSession = null; - } -} diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogSession.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogSession.java deleted file mode 100644 index f4adc8c..0000000 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogSession.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpeclipse.xdebug.ui.views.logview; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.StringTokenizer; - -public class LogSession { - private String sessionData; - private Date date; - - /** - * Constructor for LogSession. - */ - public LogSession() { - } - - public Date getDate() { - return date; - } - - public void setDate(String dateString) { - SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss.SS"); //$NON-NLS-1$ - try { - date = formatter.parse(dateString); - } catch (ParseException e) { - } - } - - public String getSessionData() { - return sessionData; - } - - void setSessionData(String data) { - this.sessionData = data; - } - - public void processLogLine(String line) { - StringTokenizer tokenizer = new StringTokenizer(line); - if (tokenizer.countTokens() == 6) { - tokenizer.nextToken(); - StringBuffer dateBuffer = new StringBuffer(); - for (int i = 0; i < 4; i++) { - dateBuffer.append(tokenizer.nextToken()); - dateBuffer.append(" "); //$NON-NLS-1$ - } - setDate(dateBuffer.toString().trim()); - } - } -} diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogView.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogView.java deleted file mode 100644 index d698b1c..0000000 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogView.java +++ /dev/null @@ -1,993 +0,0 @@ -/*********************************************************************************************************************************** - * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made - * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation - **********************************************************************************************************************************/ - -package net.sourceforge.phpeclipse.xdebug.ui.views.logview; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.InvocationTargetException; -import java.text.Collator; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Date; - -import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; -import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin; -import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPluginImages; - -import org.eclipse.core.runtime.ILogListener; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.ColumnPixelData; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeViewerListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TableTreeViewer; -import org.eclipse.jface.viewers.TreeExpansionEvent; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.custom.TableTree; -import org.eclipse.swt.custom.TableTreeItem; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.program.Program; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.XMLMemento; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.part.ViewPart; - -public class LogView extends ViewPart implements ILogListener { - public final static String ID_LOGVIEW = "net.sourceforge.phpdt.internal.debug.core.logview.LogView"; //$NON-NLS-1$ - - private TableTreeViewer tableTreeViewer; - - private ArrayList logs = new ArrayList(); - - public static final String P_LOG_WARNING = "warning"; //$NON-NLS-1$ - - public static final String P_LOG_ERROR = "error"; //$NON-NLS-1$ - - public static final String P_LOG_INFO = "info"; //$NON-NLS-1$ - - public static final String P_LOG_LIMIT = "limit"; //$NON-NLS-1$ - - public static final String P_USE_LIMIT = "useLimit"; //$NON-NLS-1$ - - public static final String P_SHOW_ALL_SESSIONS = "allSessions"; //$NON-NLS-1$ - - private static final String P_COLUMN_1 = "column1"; //$NON-NLS-1$ - - private static final String P_COLUMN_2 = "column2"; //$NON-NLS-1$ - - private static final String P_COLUMN_3 = "column3"; //$NON-NLS-1$ - - private static final String P_COLUMN_4 = "column4"; //$NON-NLS-1$ - - public static final String P_ACTIVATE = "activate"; //$NON-NLS-1$ - - private int MESSAGE_ORDER = -1; - - private int PLUGIN_ORDER = -1; - - private int DATE_ORDER = -1; - - public static byte MESSAGE = 0x0; - - public static byte PLUGIN = 0x1; - - public static byte DATE = 0x2; - - private static int ASCENDING = 1; - - private static int DESCENDING = -1; - - private Action clearAction; - - private Action copyAction; - - private Action readLogAction; - - private Action deleteLogAction; - - private Action exportAction; - - private Action importAction; - - private Action activateViewAction; - - private Action propertiesAction; - - private Action viewLogAction; - - private Action filterAction; - - private Clipboard clipboard; - - private IMemento memento; - - private File inputFile; - - private String directory; - - private TableColumn column0; - - private TableColumn column1; - - private TableColumn column2; - - private TableColumn column3; - - private TableColumn column4; - - private static Font boldFont; - - private Comparator comparator; - - private Collator collator; - - // hover text - private boolean canOpenTextShell; - - private Text textLabel; - - private Shell textShell; - - private boolean firstEvent = true; - - public LogView() { - logs = new ArrayList(); - inputFile = Platform.getLogFileLocation().toFile(); - } - - public void createPartControl(Composite parent) { - readLogFile(); - TableTree tableTree = new TableTree(parent, SWT.FULL_SELECTION); - tableTree.setLayoutData(new GridData(GridData.FILL_BOTH)); - createColumns(tableTree.getTable()); - createViewer(tableTree); - createPopupMenuManager(tableTree); - makeActions(tableTree.getTable()); - fillToolBar(); - Platform.addLogListener(this); - getSite().setSelectionProvider(tableTreeViewer); - clipboard = new Clipboard(tableTree.getDisplay()); - // WorkbenchHelp.setHelp(tableTree, IHelpContextIds.LOG_VIEW); - tableTreeViewer.getTableTree().getTable().setToolTipText(""); //$NON-NLS-1$ - initializeFonts(); - applyFonts(); - } - - private void initializeFonts() { - Font tableFont = tableTreeViewer.getTableTree().getFont(); - FontData[] fontDataList = tableFont.getFontData(); - FontData fontData; - if (fontDataList.length > 0) - fontData = fontDataList[0]; - else - fontData = new FontData(); - fontData.setStyle(SWT.BOLD); - boldFont = new Font(tableTreeViewer.getTableTree().getDisplay(), fontData); - } - - /* - * Set all rows where the tableTreeItem has children to have a bold font. - */ - private void applyFonts() { - if (tableTreeViewer == null || tableTreeViewer.getTableTree().isDisposed()) - return; - int max = tableTreeViewer.getTableTree().getItemCount(); - int index = 0, tableIndex = 0; - while (index < max) { - LogEntry entry = (LogEntry) tableTreeViewer.getElementAt(index); - if (entry == null) - return; - if (entry.hasChildren()) { - tableTreeViewer.getTableTree().getItems()[index].setFont(boldFont); - tableIndex = applyChildFonts(entry, tableIndex); - } else { - tableTreeViewer.getTableTree().getItems()[index].setFont(tableTreeViewer.getTableTree().getFont()); - } - index++; - tableIndex++; - } - } - - private int applyChildFonts(LogEntry parent, int index) { - if (!tableTreeViewer.getExpandedState(parent) || !parent.hasChildren()) - return index; - LogEntry[] children = getEntryChildren(parent); - for (int i = 0; i < children.length; i++) { - index++; - if (children[i].hasChildren()) { - TableItem tableItem = getTableItem(index); - if (tableItem != null) { - tableItem.setFont(boldFont); - } - index = applyChildFonts(children[i], index); - } else { - TableItem tableItem = getTableItem(index); - if (tableItem != null) { - tableItem.setFont(tableTreeViewer.getTableTree().getFont()); - } - } - } - return index; - } - - private LogEntry[] getEntryChildren(LogEntry parent) { - Object[] entryChildren = parent.getChildren(parent); - if (comparator != null) - Arrays.sort(entryChildren, comparator); - LogEntry[] children = new LogEntry[entryChildren.length]; - System.arraycopy(entryChildren, 0, children, 0, entryChildren.length); - return children; - } - - private TableItem getTableItem(int index) { - TableItem[] tableItems = tableTreeViewer.getTableTree().getTable().getItems(); - if (index > tableItems.length - 1) - return null; - return tableItems[index]; - } - - private void fillToolBar() { - IActionBars bars = getViewSite().getActionBars(); - bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); - IToolBarManager toolBarManager = bars.getToolBarManager(); - toolBarManager.add(exportAction); - toolBarManager.add(importAction); - toolBarManager.add(new Separator()); - toolBarManager.add(clearAction); - toolBarManager.add(deleteLogAction); - toolBarManager.add(viewLogAction); - toolBarManager.add(readLogAction); - toolBarManager.add(new Separator()); - IMenuManager mgr = bars.getMenuManager(); - mgr.add(filterAction); - mgr.add(new Separator()); - mgr.add(activateViewAction); - } - - private void createViewer(TableTree tableTree) { - tableTreeViewer = new TableTreeViewer(tableTree); - tableTreeViewer.setContentProvider(new LogViewContentProvider(this)); - tableTreeViewer.setLabelProvider(new LogViewLabelProvider()); - tableTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent e) { - handleSelectionChanged(e.getSelection()); - if (propertiesAction.isEnabled()) - ((EventDetailsDialogAction) propertiesAction).resetSelection(); - } - }); - tableTreeViewer.addDoubleClickListener(new IDoubleClickListener() { - public void doubleClick(DoubleClickEvent event) { - ((EventDetailsDialogAction) propertiesAction).setComparator(comparator); - propertiesAction.run(); - } - }); - tableTreeViewer.addTreeListener(new ITreeViewerListener() { - public void treeCollapsed(TreeExpansionEvent event) { - applyFonts(); - } - - public void treeExpanded(TreeExpansionEvent event) { - applyFonts(); - } - }); - addMouseListeners(); - tableTreeViewer.setInput(Platform.class); - } - - private void createPopupMenuManager(TableTree tableTree) { - MenuManager popupMenuManager = new MenuManager(); - IMenuListener listener = new IMenuListener() { - public void menuAboutToShow(IMenuManager mng) { - fillContextMenu(mng); - } - }; - popupMenuManager.addMenuListener(listener); - popupMenuManager.setRemoveAllWhenShown(true); - Menu menu = popupMenuManager.createContextMenu(tableTree); - tableTree.setMenu(menu); - } - - private void createColumns(Table table) { - column0 = new TableColumn(table, SWT.NULL); - column0.setText(""); //$NON-NLS-1$ - column1 = new TableColumn(table, SWT.NULL); - column1.setText(XDebugUIPlugin.getString("LogView.column.severity")); //$NON-NLS-1$ - column2 = new TableColumn(table, SWT.NULL); - column2.setText(XDebugUIPlugin.getString("LogView.column.message")); //$NON-NLS-1$ - column2.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - MESSAGE_ORDER *= -1; - ViewerSorter sorter = getViewerSorter(MESSAGE); - tableTreeViewer.setSorter(sorter); - collator = sorter.getCollator(); - boolean isComparatorSet = ((EventDetailsDialogAction) propertiesAction).resetSelection(MESSAGE, MESSAGE_ORDER); - setComparator(MESSAGE); - if (!isComparatorSet) - ((EventDetailsDialogAction) propertiesAction).setComparator(comparator); - applyFonts(); - } - }); - column3 = new TableColumn(table, SWT.NULL); - column3.setText(XDebugUIPlugin.getString("LogView.column.plugin")); //$NON-NLS-1$ - column3.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - PLUGIN_ORDER *= -1; - ViewerSorter sorter = getViewerSorter(PLUGIN); - tableTreeViewer.setSorter(sorter); - collator = sorter.getCollator(); - boolean isComparatorSet = ((EventDetailsDialogAction) propertiesAction).resetSelection(PLUGIN, PLUGIN_ORDER); - setComparator(PLUGIN); - if (!isComparatorSet) - ((EventDetailsDialogAction) propertiesAction).setComparator(comparator); - applyFonts(); - } - }); - column4 = new TableColumn(table, SWT.NULL); - column4.setText(XDebugUIPlugin.getString("LogView.column.date")); //$NON-NLS-1$ - column4.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (DATE_ORDER == ASCENDING) { - DATE_ORDER = DESCENDING; - } else { - DATE_ORDER = ASCENDING; - } - ViewerSorter sorter = getViewerSorter(DATE); - tableTreeViewer.setSorter(sorter); - collator = sorter.getCollator(); - boolean isComparatorSet = ((EventDetailsDialogAction) propertiesAction).resetSelection(DATE, DATE_ORDER); - setComparator(DATE); - if (!isComparatorSet) - ((EventDetailsDialogAction) propertiesAction).setComparator(comparator); - applyFonts(); - } - }); - TableLayout tlayout = new TableLayout(); - tlayout.addColumnData(new ColumnPixelData(21)); - tlayout.addColumnData(new ColumnPixelData(memento.getInteger(P_COLUMN_1).intValue())); - tlayout.addColumnData(new ColumnPixelData(memento.getInteger(P_COLUMN_2).intValue())); - tlayout.addColumnData(new ColumnPixelData(memento.getInteger(P_COLUMN_3).intValue())); - tlayout.addColumnData(new ColumnPixelData(memento.getInteger(P_COLUMN_4).intValue())); - table.setLayout(tlayout); - table.setHeaderVisible(true); - } - - private void makeActions(Table table) { - propertiesAction = new EventDetailsDialogAction(table.getShell(), tableTreeViewer); - propertiesAction.setImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_PROPERTIES)); - propertiesAction.setDisabledImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_PROPERTIES)); - propertiesAction.setToolTipText(XDebugUIPlugin.getString("LogView.properties.tooltip")); //$NON-NLS-1$ - propertiesAction.setEnabled(false); - clearAction = new Action(XDebugUIPlugin.getString("LogView.clear")) { //$NON-NLS-1$ - public void run() { - handleClear(); - } - }; - clearAction.setImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_CLEAR)); - clearAction.setDisabledImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_CLEAR)); - clearAction.setToolTipText(XDebugUIPlugin.getString("LogView.clear.tooltip")); //$NON-NLS-1$ - clearAction.setText(XDebugUIPlugin.getString("LogView.clear")); //$NON-NLS-1$ - readLogAction = new Action(XDebugUIPlugin.getString("LogView.readLog.restore")) { //$NON-NLS-1$ - public void run() { - inputFile = Platform.getLogFileLocation().toFile(); - reloadLog(); - } - }; - readLogAction.setToolTipText(XDebugUIPlugin.getString("LogView.readLog.restore.tooltip")); //$NON-NLS-1$ - readLogAction.setImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_READ_LOG)); - readLogAction.setDisabledImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_READ_LOG)); - deleteLogAction = new Action(XDebugUIPlugin.getString("LogView.delete")) { //$NON-NLS-1$ - public void run() { - doDeleteLog(); - } - }; - deleteLogAction.setToolTipText(XDebugUIPlugin.getString("LogView.delete.tooltip")); //$NON-NLS-1$ - deleteLogAction.setImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_REMOVE_LOG)); - deleteLogAction.setDisabledImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_REMOVE_LOG)); - deleteLogAction.setEnabled(inputFile.exists() && inputFile.equals(Platform.getLogFileLocation().toFile())); - copyAction = new Action(XDebugUIPlugin.getString("LogView.copy")) { //$NON-NLS-1$ - public void run() { - copyToClipboard(tableTreeViewer.getSelection()); - } - }; - copyAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); - filterAction = new Action(XDebugUIPlugin.getString("LogView.filter")) { //$NON-NLS-1$ - public void run() { - handleFilter(); - } - }; - filterAction.setToolTipText(XDebugUIPlugin.getString("LogView.filter")); //$NON-NLS-1$ - filterAction.setImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_FILTER)); - filterAction.setDisabledImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_FILTER)); - exportAction = new Action(XDebugUIPlugin.getString("LogView.export")) { //$NON-NLS-1$ - public void run() { - handleExport(); - } - }; - exportAction.setToolTipText(XDebugUIPlugin.getString("LogView.export.tooltip")); //$NON-NLS-1$ - exportAction.setImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_EXPORT)); - exportAction.setDisabledImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_EXPORT)); - importAction = new Action(XDebugUIPlugin.getString("LogView.import")) { //$NON-NLS-1$ - public void run() { - handleImport(); - } - }; - importAction.setToolTipText(XDebugUIPlugin.getString("LogView.import.tooltip")); //$NON-NLS-1$ - importAction.setImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_IMPORT)); - importAction.setDisabledImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_IMPORT)); - activateViewAction = new Action(XDebugUIPlugin.getString("LogView.activate")) { //$NON-NLS-1$ - public void run() { - } - }; - activateViewAction.setChecked(memento.getString(P_ACTIVATE).equals("true")); //$NON-NLS-1$ - viewLogAction = new Action(XDebugUIPlugin.getString("LogView.view.currentLog")) { //$NON-NLS-1$ - public void run() { - if (inputFile.exists()) { - if (inputFile.length() > LogReader.MAX_FILE_LENGTH) { - OpenLogDialog openDialog = new OpenLogDialog(getViewSite().getShell(), inputFile); - openDialog.create(); - openDialog.open(); - } else { - boolean canLaunch = Program.launch(inputFile.getAbsolutePath()); - if (!canLaunch) { - Program p = Program.findProgram(".txt"); //$NON-NLS-1$ - if (p != null) - p.execute(inputFile.getAbsolutePath()); - else { - OpenLogDialog openDialog = new OpenLogDialog(getViewSite().getShell(), inputFile); - openDialog.create(); - openDialog.open(); - } - } - } - } - } - }; - viewLogAction.setImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_OPEN_LOG)); - viewLogAction.setDisabledImageDescriptor(XDebugUIPluginImages.getImageDescriptor(XDebugUIPluginImages.IMG_OPEN_LOG)); - viewLogAction.setEnabled(inputFile.exists()); - viewLogAction.setToolTipText(XDebugUIPlugin.getString("LogView.view.currentLog.tooltip")); //$NON-NLS-1$ - } - - public void dispose() { - Platform.removeLogListener(this); - clipboard.dispose(); - LogReader.reset(); - boldFont.dispose(); - super.dispose(); - } - - private void handleImport() { - FileDialog dialog = new FileDialog(getViewSite().getShell()); - dialog.setFilterExtensions(new String[] { "*.log" }); //$NON-NLS-1$ - if (directory != null) - dialog.setFilterPath(directory); - String path = dialog.open(); - if (path != null && new Path(path).toFile().exists()) { - inputFile = new Path(path).toFile(); - directory = inputFile.getParent(); - IRunnableWithProgress op = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - monitor.beginTask(XDebugUIPlugin.getString("LogView.operation.importing"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$ - readLogFile(); - } - }; - ProgressMonitorDialog pmd = new ProgressMonitorDialog(getViewSite().getShell()); - try { - pmd.run(true, true, op); - } catch (InvocationTargetException e) { - } catch (InterruptedException e) { - } finally { - readLogAction.setText(XDebugUIPlugin.getString("LogView.readLog.reload")); //$NON-NLS-1$ - readLogAction.setToolTipText(XDebugUIPlugin.getString("LogView.readLog.reload")); //$NON-NLS-1$ - asyncRefresh(false); - resetDialogButtons(); - } - } - } - - private void handleExport() { - FileDialog dialog = new FileDialog(getViewSite().getShell(), SWT.SAVE); - dialog.setFilterExtensions(new String[] { "*.log" }); //$NON-NLS-1$ - if (directory != null) - dialog.setFilterPath(directory); - String path = dialog.open(); - if (path != null) { - if (!path.endsWith(".log")) //$NON-NLS-1$ - path += ".log"; //$NON-NLS-1$ - File outputFile = new Path(path).toFile(); - directory = outputFile.getParent(); - if (outputFile.exists()) { - String message = "LogView.confirmOverwrite.message"; -// String message = PHPDebugUIPlugin.getFormattedMessage("LogView.confirmOverwrite.message", //$NON-NLS-1$ -// outputFile.toString()); - if (!MessageDialog.openQuestion(getViewSite().getShell(), exportAction.getText(), message)) - return; - } - copy(inputFile, outputFile); - } - } - - private void copy(File inputFile, File outputFile) { - BufferedReader reader = null; - BufferedWriter writer = null; - try { - reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), "UTF-8")); //$NON-NLS-1$ - writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); //$NON-NLS-1$ - while (reader.ready()) { - writer.write(reader.readLine()); - writer.write(System.getProperty("line.separator")); //$NON-NLS-1$ - } - } catch (IOException e) { - } finally { - try { - if (reader != null) - reader.close(); - if (writer != null) - writer.close(); - } catch (IOException e1) { - } - } - } - - private void handleFilter() { - FilterDialog dialog = new FilterDialog(XDebugCorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), memento); - dialog.create(); - dialog.getShell().setText(XDebugUIPlugin.getString("LogView.FilterDialog.title")); //$NON-NLS-1$ - if (dialog.open() == FilterDialog.OK) - reloadLog(); - } - - private void doDeleteLog() { - String title = XDebugUIPlugin.getString("LogView.confirmDelete.title"); //$NON-NLS-1$ - String message = XDebugUIPlugin.getString("LogView.confirmDelete.message"); //$NON-NLS-1$ - if (!MessageDialog.openConfirm(tableTreeViewer.getControl().getShell(), title, message)) - return; - if (inputFile.delete()) { - logs.clear(); - asyncRefresh(false); - resetDialogButtons(); - } - } - - public void fillContextMenu(IMenuManager manager) { - manager.add(copyAction); - manager.add(new Separator()); - manager.add(clearAction); - manager.add(deleteLogAction); - manager.add(viewLogAction); - manager.add(readLogAction); - manager.add(new Separator()); - manager.add(exportAction); - manager.add(importAction); - manager.add(new Separator()); - ((EventDetailsDialogAction) propertiesAction).setComparator(comparator); - manager.add(propertiesAction); - } - - public LogEntry[] getLogs() { - return (LogEntry[]) logs.toArray(new LogEntry[logs.size()]); - } - - protected void handleClear() { - BusyIndicator.showWhile(tableTreeViewer.getControl().getDisplay(), new Runnable() { - public void run() { - logs.clear(); - asyncRefresh(false); - resetDialogButtons(); - } - }); - } - - protected void reloadLog() { - IRunnableWithProgress op = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - monitor.beginTask(XDebugUIPlugin.getString("LogView.operation.reloading"), //$NON-NLS-1$ - IProgressMonitor.UNKNOWN); - readLogFile(); - } - }; - ProgressMonitorDialog pmd = new ProgressMonitorDialog(getViewSite().getShell()); - try { - pmd.run(true, true, op); - } catch (InvocationTargetException e) { - } catch (InterruptedException e) { - } finally { - readLogAction.setText(XDebugUIPlugin.getString("LogView.readLog.restore")); //$NON-NLS-1$ - readLogAction.setToolTipText(XDebugUIPlugin.getString("LogView.readLog.restore")); //$NON-NLS-1$ - asyncRefresh(false); - resetDialogButtons(); - } - } - - private void readLogFile() { - logs.clear(); - if (!inputFile.exists()) - return; - if (inputFile.length() > LogReader.MAX_FILE_LENGTH) - LogReader.parseLargeFile(inputFile, logs, memento); - else - LogReader.parseLogFile(inputFile, logs, memento); - } - - public void logging(IStatus status, String plugin) { - if (!inputFile.equals(Platform.getLogFileLocation().toFile())) - return; - if (firstEvent) { - readLogFile(); - asyncRefresh(); - firstEvent = false; - } else { - pushStatus(status); - } - } - - private void pushStatus(IStatus status) { - LogEntry entry = new LogEntry(status); - LogReader.addEntry(entry, logs, memento, true); - asyncRefresh(); - } - - private void asyncRefresh() { - asyncRefresh(true); - } - - private void asyncRefresh(final boolean activate) { - final Control control = tableTreeViewer.getControl(); - if (control.isDisposed()) - return; - Display display = control.getDisplay(); - final ViewPart view = this; - if (display != null) { - display.asyncExec(new Runnable() { - public void run() { - if (!control.isDisposed()) { - tableTreeViewer.refresh(); - deleteLogAction.setEnabled(inputFile.exists() && inputFile.equals(Platform.getLogFileLocation().toFile())); - viewLogAction.setEnabled(inputFile.exists()); - if (activate && activateViewAction.isChecked()) { - IWorkbenchPage page = XDebugCorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); - if (page != null) - page.bringToTop(view); - } - } - applyFonts(); - } - }); - } - } - - public void setFocus() { - if (tableTreeViewer != null && !tableTreeViewer.getTableTree().isDisposed()) - tableTreeViewer.getTableTree().getTable().setFocus(); - } - - private void handleSelectionChanged(ISelection selection) { - updateStatus(selection); - copyAction.setEnabled(!selection.isEmpty()); - propertiesAction.setEnabled(!selection.isEmpty()); - } - - private void updateStatus(ISelection selection) { - IStatusLineManager status = getViewSite().getActionBars().getStatusLineManager(); - if (selection.isEmpty()) - status.setMessage(null); - else { - LogEntry entry = (LogEntry) ((IStructuredSelection) selection).getFirstElement(); - status.setMessage(((LogViewLabelProvider) tableTreeViewer.getLabelProvider()).getColumnText(entry, 2)); - } - } - - private void copyToClipboard(ISelection selection) { - StringWriter writer = new StringWriter(); - PrintWriter pwriter = new PrintWriter(writer); - if (selection.isEmpty()) - return; - LogEntry entry = (LogEntry) ((IStructuredSelection) selection).getFirstElement(); - entry.write(pwriter); - pwriter.flush(); - String textVersion = writer.toString(); - try { - pwriter.close(); - writer.close(); - } catch (IOException e) { - } - if (textVersion.trim().length() > 0) { - // set the clipboard contents - clipboard.setContents(new Object[] { textVersion }, new Transfer[] { TextTransfer.getInstance() }); - } - } - - public void init(IViewSite site, IMemento memento) throws PartInitException { - super.init(site, memento); - if (memento == null) - this.memento = XMLMemento.createWriteRoot("LOGVIEW"); //$NON-NLS-1$ - else - this.memento = memento; - initializeMemento(); - } - - private void initializeMemento() { - if (memento.getString(P_USE_LIMIT) == null) - memento.putString(P_USE_LIMIT, "true"); //$NON-NLS-1$ - if (memento.getInteger(P_LOG_LIMIT) == null) - memento.putInteger(P_LOG_LIMIT, 50); - if (memento.getString(P_LOG_INFO) == null) - memento.putString(P_LOG_INFO, "true"); //$NON-NLS-1$ - if (memento.getString(P_LOG_WARNING) == null) - memento.putString(P_LOG_WARNING, "true"); //$NON-NLS-1$ - if (memento.getString(P_LOG_ERROR) == null) - memento.putString(P_LOG_ERROR, "true"); //$NON-NLS-1$ - if (memento.getString(P_SHOW_ALL_SESSIONS) == null) - memento.putString(P_SHOW_ALL_SESSIONS, "true"); //$NON-NLS-1$ - Integer width = memento.getInteger(P_COLUMN_1); - if (width == null || width.intValue() == 0) - memento.putInteger(P_COLUMN_1, 20); - width = memento.getInteger(P_COLUMN_2); - if (width == null || width.intValue() == 0) - memento.putInteger(P_COLUMN_2, 300); - width = memento.getInteger(P_COLUMN_3); - if (width == null || width.intValue() == 0) - memento.putInteger(P_COLUMN_3, 150); - width = memento.getInteger(P_COLUMN_4); - if (width == null || width.intValue() == 0) - memento.putInteger(P_COLUMN_4, 150); - if (memento.getString(P_ACTIVATE) == null) - memento.putString(P_ACTIVATE, "true"); //$NON-NLS-1$ - } - - public void saveState(IMemento memento) { - if (this.memento == null || memento == null) - return; - this.memento.putInteger(P_COLUMN_1, column1.getWidth()); - this.memento.putInteger(P_COLUMN_2, column2.getWidth()); - this.memento.putInteger(P_COLUMN_3, column3.getWidth()); - this.memento.putInteger(P_COLUMN_4, column4.getWidth()); - this.memento.putString(P_ACTIVATE, activateViewAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ - memento.putMemento(this.memento); - } - - private void addMouseListeners() { - Listener tableListener = new Listener() { - public void handleEvent(Event e) { - switch (e.type) { - case SWT.MouseMove: - onMouseMove(e); - break; - case SWT.MouseHover: - onMouseHover(e); - break; - case SWT.MouseDown: - onMouseDown(e); - break; - } - } - }; - int[] tableEvents = new int[] { SWT.MouseDown, SWT.MouseMove, SWT.MouseHover }; - for (int i = 0; i < tableEvents.length; i++) { - tableTreeViewer.getTableTree().getTable().addListener(tableEvents[i], tableListener); - } - } - - private void makeHoverShell() { - Control control = tableTreeViewer.getControl(); - textShell = new Shell(control.getShell(), SWT.NO_FOCUS | SWT.ON_TOP); - Display display = textShell.getDisplay(); - textShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - GridLayout layout = new GridLayout(1, false); - int border = ((control.getShell().getStyle() & SWT.NO_TRIM) == 0) ? 0 : 1; - layout.marginHeight = border; - layout.marginWidth = border; - textShell.setLayout(layout); - textShell.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Composite shellComposite = new Composite(textShell, SWT.NONE); - layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - shellComposite.setLayout(layout); - shellComposite.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING)); - textLabel = new Text(shellComposite, SWT.WRAP | SWT.MULTI); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.widthHint = 100; - gd.grabExcessHorizontalSpace = true; - textLabel.setLayoutData(gd); - Color c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND); - textLabel.setBackground(c); - c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND); - textLabel.setForeground(c); - textLabel.setEditable(false); - textShell.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - onTextShellDispose(e); - } - }); - } - - void onTextShellDispose(DisposeEvent e) { - canOpenTextShell = true; - setFocus(); - } - - void onMouseDown(Event e) { - if (textShell != null && !textShell.isDisposed() && !textShell.isFocusControl()) { - textShell.close(); - canOpenTextShell = true; - } - } - - void onMouseHover(Event e) { - if (!canOpenTextShell) - return; - canOpenTextShell = false; - Point point = new Point(e.x, e.y); - TableTree table = tableTreeViewer.getTableTree(); - TableTreeItem item = table.getItem(point); - if (item == null) - return; - String message = ((LogEntry) item.getData()).getStack(); - if (message == null) - return; - makeHoverShell(); - textLabel.setText(message); - int x = point.x + 5; - int y = point.y - (table.getItemHeight() * 2) - 20; - textShell.setLocation(table.toDisplay(x, y)); - textShell.setSize(tableTreeViewer.getTableTree().getSize().x - x, 125); - textShell.open(); - setFocus(); - } - - void onMouseMove(Event e) { - if (textShell != null && !textShell.isDisposed()) { - textShell.close(); - canOpenTextShell = textShell.isDisposed() && e.x > column0.getWidth() && e.x < (column0.getWidth() + column1.getWidth()); - } else { - canOpenTextShell = e.x > column0.getWidth() && e.x < (column0.getWidth() + column1.getWidth()); - } - } - - public Comparator getComparator() { - return comparator; - } - - private void setComparator(byte sortType) { - if (sortType == DATE) { - comparator = new Comparator() { - public int compare(Object e1, Object e2) { - try { - SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss.SS"); //$NON-NLS-1$ - Date date1 = formatter.parse(((LogEntry) e1).getDate()); - Date date2 = formatter.parse(((LogEntry) e2).getDate()); - if (DATE_ORDER == ASCENDING) - return date1.before(date2) ? -1 : 1; - return date1.after(date2) ? -1 : 1; - } catch (ParseException e) { - } - return 0; - } - }; - } else if (sortType == PLUGIN) { - comparator = new Comparator() { - public int compare(Object e1, Object e2) { - LogEntry entry1 = (LogEntry) e1; - LogEntry entry2 = (LogEntry) e2; - return collator.compare(entry1.getPluginId(), entry2.getPluginId()) * PLUGIN_ORDER; - } - }; - } else { - comparator = new Comparator() { - public int compare(Object e1, Object e2) { - LogEntry entry1 = (LogEntry) e1; - LogEntry entry2 = (LogEntry) e2; - return collator.compare(entry1.getMessage(), entry2.getMessage()) * MESSAGE_ORDER; - } - }; - } - } - - private ViewerSorter getViewerSorter(byte sortType) { - if (sortType == PLUGIN) { - return new ViewerSorter() { - public int compare(Viewer viewer, Object e1, Object e2) { - LogEntry entry1 = (LogEntry) e1; - LogEntry entry2 = (LogEntry) e2; - return super.compare(viewer, entry1.getPluginId(), entry2.getPluginId()) * PLUGIN_ORDER; - } - }; - } else if (sortType == MESSAGE) { - return new ViewerSorter() { - public int compare(Viewer viewer, Object e1, Object e2) { - LogEntry entry1 = (LogEntry) e1; - LogEntry entry2 = (LogEntry) e2; - return super.compare(viewer, entry1.getMessage(), entry2.getMessage()) * MESSAGE_ORDER; - } - }; - } else { - return new ViewerSorter() { - public int compare(Viewer viewer, Object e1, Object e2) { - try { - SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss.SS"); //$NON-NLS-1$ - Date date1 = formatter.parse(((LogEntry) e1).getDate()); - Date date2 = formatter.parse(((LogEntry) e2).getDate()); - if (DATE_ORDER == ASCENDING) - return date1.before(date2) ? -1 : 1; - return date1.after(date2) ? -1 : 1; - } catch (ParseException e) { - } - return 0; - } - }; - } - } - - private void resetDialogButtons() { - ((EventDetailsDialogAction) propertiesAction).resetDialogButtons(); - } -} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogViewContentProvider.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogViewContentProvider.java deleted file mode 100644 index 3a12f46..0000000 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogViewContentProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpeclipse.xdebug.ui.views.logview; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -public class LogViewContentProvider - implements ITreeContentProvider, IStructuredContentProvider { - private LogView logView; - - public LogViewContentProvider(LogView logView) { - this.logView = logView; - } - public void dispose() { - } - public Object[] getChildren(Object element) { - return ((LogEntry) element).getChildren(element); - } - public Object[] getElements(Object element) { - return logView.getLogs(); - } - public Object getParent(Object element) { - return ((LogEntry) element).getParent(element); - } - public boolean hasChildren(Object element) { - return ((LogEntry) element).hasChildren(); - } - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - public boolean isDeleted(Object element) { - return false; - } -} diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogViewLabelProvider.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogViewLabelProvider.java deleted file mode 100644 index 2cc65c3..0000000 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/LogViewLabelProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpeclipse.xdebug.ui.views.logview; - -import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPluginImages; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; - -public class LogViewLabelProvider - extends LabelProvider - implements ITableLabelProvider { - private Image infoImage; - private Image errorImage; - private Image warningImage; - private Image errorWithStackImage; - - public LogViewLabelProvider() { - errorImage = XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_ERROR_ST_OBJ); - warningImage = XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_WARNING_ST_OBJ); - infoImage = XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_INFO_ST_OBJ); - errorWithStackImage = XDebugUIPluginImages.get(XDebugUIPluginImages.IMG_ERROR_STACK_OBJ); - } - public void dispose() { - errorImage.dispose(); - infoImage.dispose(); - warningImage.dispose(); - errorWithStackImage.dispose(); - super.dispose(); - } - public Image getColumnImage(Object element, int columnIndex) { - LogEntry entry = (LogEntry) element; - if (columnIndex == 1) { - switch (entry.getSeverity()) { - case IStatus.INFO : - return infoImage; - case IStatus.WARNING : - return warningImage; - case IStatus.ERROR : - return (entry.getStack() == null ? errorImage : errorWithStackImage); - } - } - return null; - } - - public String getColumnText(Object element, int columnIndex) { - LogEntry entry = (LogEntry) element; - switch (columnIndex) { - case 2 : - return entry.getMessage(); - case 3 : - return entry.getPluginId(); - case 4 : - return entry.getDate(); - } - return ""; //$NON-NLS-1$ - } -} diff --git a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/OpenLogDialog.java b/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/OpenLogDialog.java deleted file mode 100644 index c1b0bb1..0000000 --- a/net.sourceforge.phpeclipse.xdebug.ui/src/net/sourceforge/phpeclipse/xdebug/ui/views/logview/OpenLogDialog.java +++ /dev/null @@ -1,269 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package net.sourceforge.phpeclipse.xdebug.ui.views.logview; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.RandomAccessFile; -import java.io.StringWriter; -import java.lang.reflect.InvocationTargetException; - -import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin; -import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Displays the error log in non-Win32 platforms - see bug 55314. - */ -public final class OpenLogDialog extends Dialog { - // input log file - private File logFile; - // location/size configuration - private IDialogSettings dialogSettings; - private Point dialogLocation; - private Point dialogSize; - private int DEFAULT_WIDTH = 750; - private int DEFAULT_HEIGHT = 800; - - public OpenLogDialog(Shell parentShell, File logFile) { - super(parentShell); - this.logFile = logFile; - setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN | SWT.MODELESS); - - } - - /* - * (non-Javadoc) Method declared on Window. - */ - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText(XDebugUIPlugin.getString("OpenLogDialog.title")); //$NON-NLS-1$ - readConfiguration(); - } - - /* - * (non-Javadoc) Method declared on Dialog. - */ - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL, - true); - } - - public void create() { - super.create(); - // dialog location - if (dialogLocation != null) - getShell().setLocation(dialogLocation); - // dialog size - if (dialogSize != null) - getShell().setSize(dialogSize); - else - getShell().setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); - getButton(IDialogConstants.CLOSE_ID).setFocus(); - } - - /* - * (non-Javadoc) Method declared on Dialog. - */ - protected Control createDialogArea(Composite parent) { - Composite outer = (Composite) super.createDialogArea(parent); - Text text = new Text(outer, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL - | SWT.NO_FOCUS | SWT.H_SCROLL); - text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL); - gridData.grabExcessVerticalSpace = true; - gridData.grabExcessHorizontalSpace = true; - text.setLayoutData(gridData); - text.setText(getLogSummary()); - return outer; - } - - private String getLogSummary() { - StringWriter out = new StringWriter(); - PrintWriter writer = new PrintWriter(out); - if (logFile.length() > LogReader.MAX_FILE_LENGTH) { - readLargeFileWithMonitor(writer); - } else { - readFileWithMonitor(writer); - } - writer.close(); - return out.toString(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) - */ - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.CLOSE_ID) { - storeSettings(); - close(); - } - super.buttonPressed(buttonId); - } - - //--------------- configuration handling -------------- - /** - * Stores the current state in the dialog settings. - * - * @since 2.0 - */ - private void storeSettings() { - writeConfiguration(); - } - - /** - * Returns the dialog settings object used to share state between several - * event detail dialogs. - * - * @return the dialog settings to be used - */ - private IDialogSettings getDialogSettings() { - IDialogSettings settings = XDebugCorePlugin.getDefault().getDialogSettings(); - dialogSettings = settings.getSection(getClass().getName()); - if (dialogSettings == null) - dialogSettings = settings.addNewSection(getClass().getName()); - return dialogSettings; - } - - /** - * Initializes itself from the dialog settings with the same state as at the - * previous invocation. - */ - private void readConfiguration() { - IDialogSettings s = getDialogSettings(); - try { - int x = s.getInt("x"); //$NON-NLS-1$ - int y = s.getInt("y"); //$NON-NLS-1$ - dialogLocation = new Point(x, y); - x = s.getInt("width"); //$NON-NLS-1$ - y = s.getInt("height"); //$NON-NLS-1$ - dialogSize = new Point(x, y); - } catch (NumberFormatException e) { - dialogLocation = null; - dialogSize = null; - } - } - - private void writeConfiguration() { - IDialogSettings s = getDialogSettings(); - Point location = getShell().getLocation(); - s.put("x", location.x); //$NON-NLS-1$ - s.put("y", location.y); //$NON-NLS-1$ - Point size = getShell().getSize(); - s.put("width", size.x); //$NON-NLS-1$ - s.put("height", size.y); //$NON-NLS-1$ - } - - // reading file within MAX_FILE_LENGTH size - private void readFile(PrintWriter writer) throws FileNotFoundException, IOException { - BufferedReader bReader = new BufferedReader(new FileReader(logFile)); - while (bReader.ready()) - writer.println(bReader.readLine()); - } - - // reading large files - private void readLargeFile(PrintWriter writer) throws FileNotFoundException, - IOException { - RandomAccessFile random = null; - boolean hasStarted = false; - try { - random = new RandomAccessFile(logFile, "r"); //$NON-NLS-1$ - random.seek(logFile.length() - LogReader.MAX_FILE_LENGTH); - for (;;) { - String line = random.readLine(); - if (line == null) - break; - line = line.trim(); - if (line.length() == 0) - continue; - if (!hasStarted - && (line.startsWith("!ENTRY") || line.startsWith("!SESSION"))) //$NON-NLS-1$ //$NON-NLS-2$ - hasStarted = true; - if (hasStarted) - writer.println(line); - continue; - } - } finally { - try { - if (random != null) - random.close(); - } catch (IOException e1) { - } - } - } - - private void readLargeFileWithMonitor(final PrintWriter writer) { - IRunnableWithProgress runnable = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, - InterruptedException { - monitor - .beginTask( - XDebugUIPlugin.getString("OpenLogDialog.message"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$ - try { - readLargeFile(writer); - } catch (IOException e) { - writer.println(XDebugUIPlugin.getString("OpenLogDialog.cannotDisplay")); //$NON-NLS-1$ - } - } - }; - ProgressMonitorDialog dialog = new ProgressMonitorDialog(getParentShell()); - try { - dialog.run(true, true, runnable); - } catch (InvocationTargetException e) { - } catch (InterruptedException e) { - } - } - - private void readFileWithMonitor(final PrintWriter writer) { - IRunnableWithProgress runnable = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, - InterruptedException { - monitor - .beginTask( - XDebugUIPlugin - .getString("OpenLogDialog.message"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$ - try { - readFile(writer); - } catch (IOException e) { - writer.println(XDebugUIPlugin - .getString("OpenLogDialog.cannotDisplay")); //$NON-NLS-1$ - } - } - }; - ProgressMonitorDialog dialog = new ProgressMonitorDialog(getParentShell()); - try { - dialog.run(true, true, runnable); - } catch (InvocationTargetException e) { - } catch (InterruptedException e) { - } - } -} -- 1.7.1