Java tutorial
/******************************************************************************* * Copyright (c) 2009 Siemens AG * * 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: * Kai Tdter - initial API and implementation *******************************************************************************/ package com.siemens.ct.mp3m.ui.wizards; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; /** * A wizard page for renaming an album. * * @author Kai Toedter * @author $LastChangedBy: toedter_k $ * @version $LastChangedDate: 2009-01-07 14:13:52 +0100 (Mi, 07 Jan 2009) $ * @version $LastChangedRevision: 771 $ * */ public class AlbumRenamePage extends WizardPage implements KeyListener { private Status albumError = new Status(IStatus.ERROR, "not_used", 0, //$NON-NLS-1$ Messages.getString("AlbumRenamePage.albumError"), null); //$NON-NLS-1$ private IStatus ok = new Status(IStatus.OK, "not_used", 0, Messages.getString("AlbumRenamePage.description"), null); private AlbumWizardModel model; private StringFieldEditor artist; private StringFieldEditor oldName; private StringFieldEditor newName; public AlbumRenamePage(AlbumWizardModel model) { super(""); this.model = model; setTitle(Messages.getString("AlbumRenamePage.title")); //$NON-NLS-1$ setDescription(Messages.getString("AlbumRenamePage.description")); //$NON-NLS-1$ } public void createControl(Composite parent) { // create the composite to hold the widgets Composite composite = new Composite(parent, SWT.NONE); // create the desired layout for this wizard page GridLayout gl = new GridLayout(2, false); composite.setLayout(gl); // artist artist = new StringFieldEditor("Artist", Messages.getString("AlbumRenamePage.artist"), composite);//$NON-NLS-1$ artist.setEnabled(false, composite); // old name oldName = new StringFieldEditor("Old Name", Messages.getString("AlbumRenamePage.oldName"), composite);//$NON-NLS-1$ oldName.setEnabled(false, composite); // new name newName = new StringFieldEditor("New Name", Messages.getString("AlbumRenamePage.newName"), composite);//$NON-NLS-1$ newName.getTextControl(composite).addKeyListener(this); // set the composite as the control for this page setControl(composite); } @Override public void setVisible(boolean visible) { artist.setStringValue(model.getArtist()); oldName.setStringValue(model.getOldName()); super.setVisible(visible); } public IStatus checkStatus(boolean applyToStatusline) { IStatus status = ok; String name = newName.getStringValue(); if (name.length() == 0 || name.equals(model.getOldName())) status = albumError; if (applyToStatusline) StatusUtil.applyToStatusLine(this, status); return status; } public boolean canFlipToNextPage() { return false; } /* * (non-Javadoc) * * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent) */ public void keyPressed(KeyEvent e) { } /* * (non-Javadoc) * * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent) */ public void keyReleased(KeyEvent e) { model.setNewName(newName.getStringValue()); checkStatus(true); getWizard().getContainer().updateButtons(); } }