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;
011:
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.core.runtime.MultiStatus;
014: import org.eclipse.core.runtime.Status;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.events.ModifyEvent;
017: import org.eclipse.swt.events.ModifyListener;
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.swt.widgets.Label;
025: import org.eclipse.swt.widgets.Text;
026: import org.eclipse.ui.IMemento;
027: import org.eclipse.ui.IPersistable;
028: import org.eclipse.ui.internal.part.components.services.INameable;
029: import org.eclipse.ui.internal.part.components.services.ISavedState;
030: import org.eclipse.ui.internal.part.components.services.ISystemLog;
031:
032: /**
033: * @since 3.1
034: */
035: public class NewStyleView implements IPersistable {
036: private static String SOMETEXT = "sometext";
037: private String textValue;
038: private ISystemLog log;
039:
040: public NewStyleView(Composite parent, INameable name,
041: ISavedState savedState, ISystemLog log) {
042:
043: this .log = log;
044: // Initialize title
045: name.setContentDescription("I am a content description");
046:
047: IMemento state = savedState.getState();
048:
049: // Set top-level layout
050: GridLayout layout = new GridLayout(1, true);
051: parent.setLayout(layout);
052:
053: // Initialize widgets
054: Label testLabel = new Label(parent, SWT.NONE);
055: testLabel.setText("Hello world");
056:
057: final Text textField = new Text(parent, SWT.NONE);
058: textField.setLayoutData(new GridData(GridData.FILL_BOTH));
059: textField.addModifyListener(new ModifyListener() {
060: /* (non-Javadoc)
061: * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
062: */
063: public void modifyText(ModifyEvent e) {
064: textValue = textField.getText();
065: }
066: });
067:
068: if (state != null) {
069: String currentName = state.getString(SOMETEXT);
070: if (currentName != null) {
071: textField.setText(currentName);
072: }
073: }
074:
075: Button writeAnException = new Button(parent, SWT.PUSH);
076: writeAnException.setText("Write exception");
077: writeAnException.addSelectionListener(new SelectionAdapter() {
078: /* (non-Javadoc)
079: * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
080: */
081: public void widgetSelected(SelectionEvent e) {
082: super .widgetSelected(e);
083:
084: writeAnException();
085: }
086: });
087: }
088:
089: /**
090: * @since 3.1
091: *
092: *
093: */
094: protected void writeAnException() {
095: IStatus toLog = new MultiStatus("blah", 0,
096: new IStatus[] { new Status(IStatus.ERROR, "foo", 432,
097: "foo", null) }, "blah", null);
098:
099: log.log(toLog);
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.ui.internal.part.components.interfaces.IPersistable#saveState(org.eclipse.ui.IMemento)
104: */
105: public void saveState(IMemento memento) {
106: memento.putString(SOMETEXT, textValue);
107: }
108: }
|