blob: 5cc00d7a6c0857783805adf11b84440d4d357480 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010 BSI Business Systems Integration 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:
* BSI Business Systems Integration AG - initial API and implementation
******************************************************************************/
package org.eclipse.scout.sdk.ui.wizard.form.fields.htmlfield;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.jdt.core.IType;
import org.eclipse.scout.commons.StringUtility;
import org.eclipse.scout.nls.sdk.model.INlsEntry;
import org.eclipse.scout.sdk.Texts;
import org.eclipse.scout.sdk.extensions.runtime.classes.IRuntimeClasses;
import org.eclipse.scout.sdk.extensions.runtime.classes.RuntimeClasses;
import org.eclipse.scout.sdk.operation.form.field.HtmlFieldNewOperation;
import org.eclipse.scout.sdk.ui.fields.StyledTextField;
import org.eclipse.scout.sdk.ui.fields.proposal.ContentProposalEvent;
import org.eclipse.scout.sdk.ui.fields.proposal.IProposalAdapterListener;
import org.eclipse.scout.sdk.ui.fields.proposal.ProposalTextField;
import org.eclipse.scout.sdk.ui.fields.proposal.SiblingProposal;
import org.eclipse.scout.sdk.ui.wizard.AbstractWorkspaceWizardPage;
import org.eclipse.scout.sdk.util.NamingUtility;
import org.eclipse.scout.sdk.util.ScoutUtility;
import org.eclipse.scout.sdk.util.SdkProperties;
import org.eclipse.scout.sdk.util.signature.SignatureCache;
import org.eclipse.scout.sdk.util.typecache.IWorkingCopyManager;
import org.eclipse.scout.sdk.workspace.type.IStructuredType;
import org.eclipse.scout.sdk.workspace.type.IStructuredType.CATEGORIES;
import org.eclipse.scout.sdk.workspace.type.ScoutTypeUtility;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
/**
* <h3>HtmlFieldNewWizardPage</h3> ...
*/
public class HtmlFieldNewWizardPage extends AbstractWorkspaceWizardPage {
private INlsEntry m_nlsName;
private String m_typeName;
private IType m_superType;
private SiblingProposal m_sibling;
private ProposalTextField m_nlsNameField;
private StyledTextField m_typeNameField;
private ProposalTextField m_siblingField;
// process members
private final IType m_declaringType;
private IType m_createdField;
public HtmlFieldNewWizardPage(IType declaringType) {
super(HtmlFieldNewWizardPage.class.getName());
setTitle(Texts.get("NewHTMLField"));
setDescription(Texts.get("CreateANewHTMLField"));
m_declaringType = declaringType;
setSuperType(RuntimeClasses.getSuperType(IRuntimeClasses.IHtmlField, m_declaringType.getJavaProject()));
m_sibling = SiblingProposal.SIBLING_END;
}
@Override
protected void createContent(Composite parent) {
m_nlsNameField = getFieldToolkit().createNlsProposalTextField(parent, ScoutTypeUtility.findNlsProject(m_declaringType), Texts.get("PropLabel"));
m_nlsNameField.acceptProposal(m_nlsName);
m_nlsNameField.addProposalAdapterListener(new IProposalAdapterListener() {
@Override
public void proposalAccepted(ContentProposalEvent event) {
try {
setStateChanging(true);
INlsEntry oldEntry = getNlsName();
m_nlsName = (INlsEntry) event.proposal;
if (m_nlsName != null) {
if (oldEntry == null || oldEntry.getKey().equals(m_typeNameField.getModifiableText()) || StringUtility.isNullOrEmpty(m_typeNameField.getModifiableText())) {
m_typeNameField.setText(NamingUtility.toJavaCamelCase(m_nlsName.getKey(), false));
}
}
}
finally {
setStateChanging(false);
}
}
});
m_typeNameField = getFieldToolkit().createStyledTextField(parent, Texts.get("TypeName"));
m_typeNameField.setReadOnlySuffix(SdkProperties.SUFFIX_FORM_FIELD);
m_typeNameField.setText(m_typeName);
m_typeNameField.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
m_typeName = m_typeNameField.getText();
pingStateChanging();
}
});
m_siblingField = getFieldToolkit().createFormFieldSiblingProposalField(parent, m_declaringType);
m_siblingField.addProposalAdapterListener(new IProposalAdapterListener() {
@Override
public void proposalAccepted(ContentProposalEvent event) {
m_sibling = (SiblingProposal) event.proposal;
pingStateChanging();
}
});
m_sibling = (SiblingProposal) m_siblingField.getSelectedProposal();
// layout
parent.setLayout(new GridLayout(1, true));
m_nlsNameField.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL));
m_typeNameField.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL));
m_siblingField.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL));
}
@Override
public boolean performFinish(IProgressMonitor monitor, IWorkingCopyManager workingCopyManager) throws CoreException {
HtmlFieldNewOperation operation = new HtmlFieldNewOperation(getTypeName(), m_declaringType, true);
// write back members
if (getNlsName() != null) {
operation.setNlsEntry(getNlsName());
}
if (getSuperType() != null) {
operation.setSuperTypeSignature(SignatureCache.createTypeSignature(getSuperType().getFullyQualifiedName()));
}
if (getSibling() == SiblingProposal.SIBLING_END) {
IStructuredType structuredType = ScoutTypeUtility.createStructuredCompositeField(m_declaringType);
operation.setSibling(structuredType.getSibling(CATEGORIES.TYPE_FORM_FIELD));
}
else {
operation.setSibling(getSibling().getElement());
}
operation.run(monitor, workingCopyManager);
m_createdField = operation.getCreatedField();
return true;
}
@Override
protected void validatePage(MultiStatus multiStatus) {
multiStatus.add(getStatusNameField());
}
protected IStatus getStatusNameField() {
return ScoutUtility.validateFormFieldName(getTypeName(), SdkProperties.SUFFIX_FORM_FIELD, m_declaringType);
}
/**
* @return the createdField
*/
public IType getCreatedField() {
return m_createdField;
}
public INlsEntry getNlsName() {
return m_nlsName;
}
public void setNlsName(INlsEntry nlsName) {
try {
setStateChanging(true);
m_nlsName = nlsName;
if (isControlCreated()) {
m_nlsNameField.acceptProposal(nlsName);
}
}
finally {
setStateChanging(false);
}
}
public String getTypeName() {
return m_typeName;
}
public void setTypeName(String typeName) {
try {
setStateChanging(true);
m_typeName = typeName;
if (isControlCreated()) {
m_typeNameField.setText(typeName);
}
}
finally {
setStateChanging(false);
}
}
public IType getSuperType() {
return m_superType;
}
public void setSuperType(IType superType) {
m_superType = superType;
pingStateChanging();
}
public SiblingProposal getSibling() {
return m_sibling;
}
public void setSibling(SiblingProposal sibling) {
try {
setStateChanging(true);
m_sibling = sibling;
if (isControlCreated()) {
m_siblingField.acceptProposal(sibling);
}
}
finally {
setStateChanging(false);
}
}
}