001: /*******************************************************************************
002: * Copyright (c) 2000, 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.pde.internal.ui.tests.macro;
011:
012: import org.eclipse.jface.viewers.ISelectionChangedListener;
013: import org.eclipse.jface.viewers.IStructuredContentProvider;
014: import org.eclipse.jface.viewers.IStructuredSelection;
015: import org.eclipse.jface.viewers.SelectionChangedEvent;
016: import org.eclipse.jface.viewers.TableViewer;
017: import org.eclipse.jface.viewers.Viewer;
018: import org.eclipse.jface.wizard.WizardPage;
019: import org.eclipse.swt.SWT;
020: import org.eclipse.swt.events.ModifyEvent;
021: import org.eclipse.swt.events.ModifyListener;
022: import org.eclipse.swt.layout.GridData;
023: import org.eclipse.swt.layout.GridLayout;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.swt.widgets.Label;
026: import org.eclipse.swt.widgets.Text;
027:
028: public class IndexPage extends WizardPage {
029: private String indexId;
030: private Text text;
031: private TableViewer tableViewer;
032: private String[] existingIndices;
033:
034: class ExistingProvider implements IStructuredContentProvider {
035: public Object[] getElements(Object inputElement) {
036: return existingIndices;
037: }
038:
039: public void dispose() {
040: }
041:
042: public void inputChanged(Viewer viewer, Object oldInput,
043: Object newInput) {
044: }
045: }
046:
047: public IndexPage(String[] existingIndices) {
048: super ("index");
049: setTitle("Script index");
050: setDescription("Enter a unique id for the script index. The index will be processed by index handled during execution of the script.");
051: this .existingIndices = existingIndices;
052: }
053:
054: public void createControl(Composite parent) {
055: Composite container = new Composite(parent, SWT.NULL);
056: GridLayout layout = new GridLayout();
057: layout.numColumns = 2;
058: container.setLayout(layout);
059: Label label = new Label(container, SWT.NULL);
060: label.setText("&Index identifier:");
061: text = new Text(container, SWT.SINGLE | SWT.BORDER);
062: text.addModifyListener(new ModifyListener() {
063: public void modifyText(ModifyEvent e) {
064: updateStatus();
065: }
066: });
067: text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
068: label = new Label(container, SWT.NULL);
069: label.setText("&Existing indices:");
070: tableViewer = new TableViewer(container, SWT.BORDER);
071: tableViewer.setContentProvider(new ExistingProvider());
072: tableViewer.setInput(this );
073: tableViewer.getControl().setLayoutData(
074: new GridData(GridData.FILL_BOTH));
075: tableViewer
076: .addSelectionChangedListener(new ISelectionChangedListener() {
077: public void selectionChanged(
078: SelectionChangedEvent event) {
079: IStructuredSelection sel = (IStructuredSelection) event
080: .getSelection();
081: Object obj = sel.getFirstElement();
082: if (obj != null)
083: text.setText(obj.toString());
084: }
085: });
086: setPageComplete(false);
087: setControl(container);
088: }
089:
090: public void setVisible(boolean visible) {
091: super .setVisible(visible);
092: if (visible)
093: text.setFocus();
094: }
095:
096: private void updateStatus() {
097: String id = text.getText();
098: String errorMessage = null;
099: if (id.length() == 0) {
100: errorMessage = "Index id cannot be empty.";
101: } else {
102: boolean exists = false;
103: for (int i = 0; i < existingIndices.length; i++) {
104: if (id.equals(existingIndices[i])) {
105: exists = true;
106: break;
107: }
108: }
109: if (exists)
110: errorMessage = "Index id already exists.";
111: }
112: setErrorMessage(errorMessage);
113: setPageComplete(errorMessage == null);
114: if (errorMessage == null)
115: this .indexId = id;
116: }
117:
118: public String getIndexId() {
119: return indexId;
120: }
121: }
|