001: /*******************************************************************************
002: * Copyright (c) 2004, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.examples.components.views.comparisons;
011:
012: import org.eclipse.core.runtime.ILog;
013: import org.eclipse.core.runtime.IStatus;
014: import org.eclipse.core.runtime.Status;
015: import org.eclipse.jface.dialogs.ErrorDialog;
016: import org.eclipse.jface.dialogs.MessageDialog;
017: import org.eclipse.swt.SWT;
018: import org.eclipse.swt.events.SelectionAdapter;
019: import org.eclipse.swt.events.SelectionEvent;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.layout.GridLayout;
022: import org.eclipse.swt.widgets.Button;
023: import org.eclipse.swt.widgets.Composite;
024: import org.eclipse.ui.examples.components.ComponentExamplesPlugin;
025: import org.eclipse.ui.part.ViewPart;
026:
027: /**
028: * @since 3.1
029: */
030: public class ErrorViewOld extends ViewPart {
031:
032: private Composite mainControl;
033:
034: /* (non-Javadoc)
035: * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
036: */
037: public void createPartControl(Composite parent) {
038: mainControl = parent;
039:
040: // Create widgets
041: GridLayout layout = new GridLayout();
042: layout.numColumns = 3;
043: parent.setLayout(layout);
044:
045: Button newButton = new Button(parent, SWT.PUSH);
046: newButton.setText("Log an error");
047: newButton.addSelectionListener(new SelectionAdapter() {
048: /* (non-Javadoc)
049: * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
050: */
051: public void widgetSelected(SelectionEvent e) {
052: logError();
053: }
054: });
055: newButton.setLayoutData(new GridData(
056: GridData.HORIZONTAL_ALIGN_BEGINNING
057: | GridData.VERTICAL_ALIGN_CENTER));
058:
059: Button displayError = new Button(parent, SWT.PUSH);
060: displayError.setText("Display an error");
061: displayError.addSelectionListener(new SelectionAdapter() {
062: /* (non-Javadoc)
063: * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
064: */
065: public void widgetSelected(SelectionEvent e) {
066: displayError();
067: }
068: });
069: displayError.setLayoutData(new GridData(
070: GridData.HORIZONTAL_ALIGN_BEGINNING
071: | GridData.VERTICAL_ALIGN_CENTER));
072:
073: Button displayMessage = new Button(parent, SWT.PUSH);
074: displayMessage.setText("Display a message");
075: displayMessage.addSelectionListener(new SelectionAdapter() {
076: /* (non-Javadoc)
077: * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
078: */
079: public void widgetSelected(SelectionEvent e) {
080: displayMessage();
081: }
082: });
083: displayMessage.setLayoutData(new GridData(
084: GridData.HORIZONTAL_ALIGN_BEGINNING
085: | GridData.VERTICAL_ALIGN_CENTER));
086:
087: }
088:
089: /* (non-Javadoc)
090: * @see org.eclipse.ui.IWorkbenchPart#setFocus()
091: */
092: public void setFocus() {
093: mainControl.setFocus();
094: }
095:
096: /**
097: * Write an exception to the error log
098: */
099: protected void logError() {
100: Exception e = new NullPointerException();
101:
102: ComponentExamplesPlugin plugin = ComponentExamplesPlugin
103: .getDefault();
104: IStatus errorStatus = new Status(IStatus.ERROR, plugin
105: .getBundle().getSymbolicName(), IStatus.OK, e
106: .getMessage() != null ? e.getMessage() : e.toString(),
107: e);
108:
109: ILog log = plugin.getLog();
110: log.log(errorStatus);
111: }
112:
113: /**
114: * Display an error dialog
115: */
116: protected void displayError() {
117: Exception e = new NullPointerException();
118:
119: ErrorDialog.openError(mainControl.getShell(), null, null,
120: new Status(IStatus.ERROR, ComponentExamplesPlugin
121: .getDefault().getBundle().getSymbolicName(),
122: IStatus.OK, "An error has occurred", e));
123: }
124:
125: /**
126: * Display an info dialog
127: */
128: protected void displayMessage() {
129: MessageDialog.openInformation(mainControl.getShell(), null,
130: "This is a message");
131: }
132: }
|