Java tutorial
/******************************************************************************* * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH . * 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: * s IT Solutions AT Spardat GmbH - initial API and implementation *******************************************************************************/ /* * @(#) * * * * * */ package at.spardat.xma.guidesign.presentation.dialog.newpage; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import at.spardat.xma.guidesign.GuidesignPackage; import at.spardat.xma.guidesign.XMAPage; import at.spardat.xma.guidesign.XMAWizardPage; import at.spardat.xma.guidesign.presentation.GuidesignEditor; import at.spardat.xma.guidesign.presentation.dialog.IValidCompositeListener; import at.spardat.xma.guidesign.presentation.dialog.XMADialog; import at.spardat.xma.guidesign.provider.XMAPageItemProvider; import at.spardat.xma.guidesign.provider.XMAWizardPageItemProvider; /** * * * @author S1462 * @since guidesign.editor */ public class NewPageDialog extends XMADialog { /** * hold the New Widget Coposite */ protected NewPageComposite newWcomposite; /** * @param shell * @param _lblProvider * @param _object * @param _feature * @param _name * @param _editor */ public NewPageDialog(Shell shell, EObject _object, EReference _feature, String _name, GuidesignEditor _editor) { super(shell, _object, _feature, _name, _editor); } /* (non-Javadoc) * @see at.spardat.xma.guidesign.presentation.XMADialog#isDialogComplete() */ protected boolean isDialogComplete() { if (newWcomposite.isCompositeComplete()) { setTitle(getText("_UI_NewPageDialog_title")); setMessage(getText("_UI_NewPageDialog_description")); //setDefaultImage(...); return true; } return false; } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell(Shell shell) { super.configureShell(shell, 0, 0); shell.setText(getText("_UI_NewPageDialog_title")); shell.setImage(lblProvider.getImage(object)); } /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea(Composite parent) { super.createDialogArea(parent); newWcomposite = new NewPageComposite(); newWcomposite.createComposite(content); //initControls(); newWcomposite.setControls((XMAPage) object); newWcomposite.addListener((IValidCompositeListener) this); return content; } /* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { XMAPage page = (XMAPage) newWcomposite.getControlValues(object); //and finally somewhat tricky to notify about the changes // TODO Prio 1: correct NewPage.okPressed + CreatePageAction.run <-- should use createPage commands GuidesignPackage desingPackage = GuidesignPackage.eINSTANCE; EAttribute feature = desingPackage.getXMAPage_NamClass(); XMAPageItemProvider provider = (page instanceof XMAWizardPage) ? new XMAWizardPageItemProvider(adapterFactory) : new XMAPageItemProvider(adapterFactory); Command cmd = provider.createSetCommand(editingDomain, page, feature, page.getNamClass()); editingDomain.getCommandStack().execute(cmd); super.okPressed(); } /** * @return the result of the dialog */ public XMAPage getResult() { return (XMAPage) object; } /** * Create a button bar with only a ok button * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar(Composite parent) { // create OK button createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); } }