blob: 2af9e60dfbbd5e6511502cb3cb1b6bc2caa9134d [file] [log] [blame]
// NewModelWizard.java
package org.eclipse.stem.ui.wizards;
/*******************************************************************************
* Copyright (c) 2007, 2008 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.stem.core.STEMURI;
import org.eclipse.stem.core.common.Identifiable;
import org.eclipse.stem.core.model.Model;
import org.eclipse.stem.core.model.ModelFactory;
import org.eclipse.stem.core.model.ModelPackage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* This class is a {@link NewIdentifiableWizard} for that creates new STEM
* {@link Model}s.
*/
public class NewModelWizard extends NewIdentifiableWizard {
/**
* @see org.eclipse.stem.ui.wizards.NewIdentifiableWizard#getWizardTitle()
*/
@Override
protected String getWizardTitle() {
return Messages.getString("NModelWiz.wizard_title"); //$NON-NLS-1$
} // getWizardTitle
/**
* @see org.eclipse.stem.ui.wizards.NewIdentifiableWizard#createNewIdentifiablePage()
*/
@Override
protected NewIdentifiablePage createNewIdentifiablePage() {
this.setHelpContextId("org.eclipse.stem.doc.newmodel_contextid");
return new NewModelPage();
} // createNewIdentifiablePage
/**
* @see org.eclipse.stem.ui.wizards.NewIdentifiableWizard#createDublinCorePage()
*/
@Override
protected DublinCorePage createDublinCorePage() {
return new DublinCorePage() {
@Override
protected void initializeDCAttributes() {
super.initializeDCAttributes();
format.setText(ModelPackage.eNS_URI);
format.setEnabled(false);
type.setText(STEMURI.MODEL_TYPE_URI.toString());
type.setEnabled(false);
titleTextField.setText(Messages.getString("dc_title_model"));
source.setText(Messages.getString("dc_source_model"));
descriptionTextField.setText(Messages.getString("dc_desc_model"));
}
};
} // createDublinCorePage
/**
* @see org.eclipse.stem.ui.wizards.NewIdentifiableWizard#createIdentifiable()
*/
@Override
protected Identifiable createIdentifiable() {
final Model retValue = ModelFactory.eINSTANCE.createModel();
retValue.setDublinCore(newDublinCorePage.createDublinCore());
return retValue;
} // createSpecificIdentifiable
/**
* @see org.eclipse.stem.ui.wizards.NewIdentifiableWizard#getSerializationFolderName()
*/
@Override
protected String getSerializationFolderName() {
return NewSTEMProjectWizard.MODELS_FOLDER_NAME;
}
/**
* @see org.eclipse.stem.ui.wizards.NewIdentifiableWizard#getSerializationFileNameExtension()
*/
@Override
protected String getSerializationFileNameExtension() {
return ModelPackage.eNAME;
}
protected static class NewModelPage extends NewIdentifiablePage {
/**
* Default Constructor
*/
protected NewModelPage() {
super(Messages.getString("NModelWiz.page_title")); //$NON-NLS-1$
setTitle(Messages.getString("NModelWiz.page_title")); //$NON-NLS-1$
setDescription(Messages.getString("NModelWiz.page_description")); //$NON-NLS-1$
} // NewModelPage
@Override
protected Composite createSpecificComposite(final Composite parent) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, "org.eclipse.stem.doc.newmodel_contextid");
return new Composite(parent, SWT.NONE);
} // createSpecificComposite
/**
* This moved to initializeDCAttributes()
* @see org.eclipse.stem.ui.wizards.NewIdentifiableWizard.NewIdentifiablePage#getDCDescription()
*/
@Override
protected String getDCDescription() {
// Leave description/title blank
return "";
// return MessageFormat.format(Messages
// .getString("NModelWiz.DC_DESCRIPTION"),
// new Object[] { serializationFileNameField.getText() });
} // getDCDescription
} // NewModelPage
/**
* This class is a {@link IHandler} for the command that creates a
* {@link NewModelWizard}
*/
public static class NewModelWizardCommandHandler extends AbstractHandler
implements IHandler {
/**
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(final ExecutionEvent executionEvent)
throws ExecutionException {
final IWorkbenchWindow window = HandlerUtil
.getActiveWorkbenchWindowChecked(executionEvent);
final NewModelWizard wizard = new NewModelWizard();
wizard.init(window.getWorkbench(), StructuredSelection.EMPTY);
final WizardDialog wizardDialog = new STEMWizardDialog(window
.getShell(), wizard);
wizardDialog.open();
return null;
} // execute
} // NewModelWizardCommandHandler
} // NewModelWizard