org.openxma.xmadsl.GuidesignExtension Maven / Gradle / Ivy
package org.openxma.xmadsl;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.openxma.dsl.common.Strings;
import org.openxma.dsl.core.model.SimpleType;
import org.openxma.dsl.core.model.TrueLiteral;
import org.openxma.dsl.core.model.ValidatorReference;
import org.openxma.dsl.generator.helper.Util;
import org.openxma.dsl.generator.helper.ValidatorExtension;
import org.openxma.dsl.generator.helper.WidgetExtension;
import org.openxma.dsl.pom.model.CenterProperty;
import org.openxma.dsl.pom.model.Component;
import org.openxma.dsl.pom.model.DropDownMenu;
import org.openxma.dsl.pom.model.HeightProperty;
import org.openxma.dsl.pom.model.ImageProperty;
import org.openxma.dsl.pom.model.Menu;
import org.openxma.dsl.pom.model.MenuItem;
import org.openxma.dsl.pom.model.ModalityProperty;
import org.openxma.dsl.pom.model.ObjectProperty;
import org.openxma.dsl.pom.model.Page;
import org.openxma.dsl.pom.model.PageProperty;
import org.openxma.dsl.pom.model.ResizeableProperty;
import org.openxma.dsl.pom.model.StatusBarProperty;
import org.openxma.dsl.pom.model.TabAlignment;
import org.openxma.dsl.pom.model.TabMenu;
import org.openxma.dsl.pom.model.TabPage;
import org.openxma.dsl.pom.model.TitleButton;
import org.openxma.dsl.pom.model.TitleButtonsProperty;
import org.openxma.dsl.pom.model.TreeMenu;
import org.openxma.dsl.pom.model.WidthProperty;
import org.openxma.dsl.pom.model.XmadslComposite;
import org.openxma.dsl.pom.model.XmadslPage;
import org.openxma.dsl.pom.validation.PomStringConstants;
import at.spardat.xma.guidesign.AppShell;
import at.spardat.xma.guidesign.BcdValidator;
import at.spardat.xma.guidesign.GuidesignFactory;
import at.spardat.xma.guidesign.HiddenWidget;
import at.spardat.xma.guidesign.NotebookPage;
import at.spardat.xma.guidesign.PageComposite;
import at.spardat.xma.guidesign.State;
import at.spardat.xma.guidesign.Validator;
import at.spardat.xma.guidesign.XMACompProperty;
import at.spardat.xma.guidesign.XMAComponent;
import at.spardat.xma.guidesign.XMAComposite;
import at.spardat.xma.guidesign.XMADialogPage;
import at.spardat.xma.guidesign.XMAPage;
import at.spardat.xma.guidesign.XMAWidget;
import at.spardat.xma.guidesign.flex.FlexFactory;
import at.spardat.xma.guidesign.flex.XMAApplicationContext;
import at.spardat.xma.guidesign.flex.type.CompositeMenuType;
import at.spardat.xma.guidesign.types.KeyboardKeyCode;
import at.spardat.xma.guidesign.types.MenuType;
import at.spardat.xma.guidesign.types.ModalityType;
import at.spardat.xma.guidesign.types.PropertyDirection;
import at.spardat.xma.guidesign.types.PropertyType;
import at.spardat.xma.guidesign.types.TypesFactory;
public class GuidesignExtension {
public static final String GENERATED_PAGE_EXTENSION = "_generatedXMAPage";
/**
* Find the XMAPage which belongs to a Xmadsl-Page.
*
* @param c
* @param p
* @return
*/
public static XMAPage findXMAPage(XMAComponent c, Page p) {
String pageId = Strings.capitalize(LinkerUtil.getId(p));
TreeIterator allContents = c.eAllContents();
while (allContents.hasNext()) {
EObject obj = allContents.next();
if (obj instanceof NotebookPage && ((NotebookPage)obj).getNamInstance().equals(pageId)) {
return (XMAPage)obj;
}
if (obj instanceof XMAPage && ((XMAPage)obj).getNamClass().equals(pageId)) {
return (XMAPage)obj;
}
}
return null;
}
public static XMAPage findOrCreateXmaPage(XMAComponent xmaComponent, Page page) {
XMAPage xmaPage = findXMAPage(xmaComponent,page);
if (xmaPage != null) {
return xmaPage;
} else {
return createXMAPage(xmaComponent,page);
}
}
public static XMAPage createXMAPage(XMAComponent xmaComponent, Page page) {
if (page instanceof XmadslPage == false) {
throw new RuntimeException("Can only create a XMAPage for a XmadslPage");
}
XmadslPage xmadslPage = (XmadslPage)page;
// Do not create a abstract XmadslPage
if (xmadslPage.isAbstract()) {
return null;
}
boolean hasMenus = xmadslPage.getMenus() != null && xmadslPage.getMenus().size() > 0;
XMADialogPage xmaPage = hasMenus
? GuidesignFactory.eINSTANCE.createAppShell()
: GuidesignFactory.eINSTANCE.createXMADialogPage();
xmaPage.setYnGenerated(true);
// Set the names and the label
xmaPage.setNamClass(Strings.capitalize(xmadslPage.getName()));
xmaPage.setNamInstance(Strings.uncapitalize(xmadslPage.getName()+GENERATED_PAGE_EXTENSION));
if (xmadslPage.getLabelText() != null && xmadslPage.getLabelText().getString() != null && xmadslPage.getLabelText().getString().length()>0) {
xmaPage.setLabelName(xmadslPage.getLabelText().getString());
} else {
xmaPage.setLabelName(xmadslPage.getName());
}
xmaPage.setComponent(xmaComponent);
// Build the help uri
StringBuffer uri = new StringBuffer(32);
uri.append("help/");
uri.append(xmaComponent.getNamPackageAsPath());
uri.append("/");
uri.append(xmadslPage.getName());
uri.append(".html");
xmaPage.setUriHelp(uri.toString());
// Create the PageComposite
PageComposite pageComposite = GuidesignFactory.eINSTANCE.createPageComposite();
pageComposite.setNamInstance(xmaPage.getNamClass()+"Comp");
pageComposite.setYnGenerated(true);
xmaPage.setComposite(pageComposite);
// Create init State
State state = GuidesignFactory.eINSTANCE.createState();
state.setNamState("init");
xmaPage.getState().add(state);
// On default all titlebuttons are set to true (can be overwritten by
// the titlebuttons-property)
xmaPage.setYnClose(true);
xmaPage.setYnMin(true);
xmaPage.setYnMax(true);
// Set page properties
List pageProperties = xmadslPage.getPageProperty();
for (PageProperty prop : pageProperties) {
if (prop instanceof WidthProperty) {
xmaPage.setQntWidth(((WidthProperty)prop).getWidth());
} else if (prop instanceof HeightProperty) {
xmaPage.setQntHeight(((HeightProperty)prop).getHeight());
} else if (prop instanceof TitleButtonsProperty) {
xmaPage.setYnClose(false);
xmaPage.setYnMin(false);
xmaPage.setYnMax(false);
TitleButtonsProperty titleButtons = (TitleButtonsProperty)prop;
for (TitleButton tb : titleButtons.getButton()) {
if (tb.getValue() == TitleButton.MINIMIZE_VALUE) {
xmaPage.setYnMin(true);
} else if (tb.getValue() == TitleButton.MAXIMIZE_VALUE) {
xmaPage.setYnMax(true);
} else if (tb.getValue() == TitleButton.CLOSE_VALUE) {
xmaPage.setYnClose(true);
}
}
} else if (prop instanceof ResizeableProperty) {
ResizeableProperty resizeableProperty = (ResizeableProperty)prop;
xmaPage.setYnResize(resizeableProperty.isResizeable()) ;
} else if (prop instanceof StatusBarProperty) {
StatusBarProperty statusBarProperty = (StatusBarProperty)prop;
xmaPage.setYnStatusBar(statusBarProperty.isStatusBar());
} else if (prop instanceof CenterProperty) {
CenterProperty centerProperty = (CenterProperty)prop;
xmaPage.setYnCenter(centerProperty.isCenter());
} else if (prop instanceof ModalityProperty) {
ModalityProperty mp = (ModalityProperty)prop;
if (PomStringConstants.APPLICATION_MODAL.equals(mp.getModality())) {
xmaPage.setCodModality(ModalityType.APPLICATION_MODAL_LITERAL);
} else if (PomStringConstants.PRIMARY_MODAL.equals(mp.getModality())) {
xmaPage.setCodModality(ModalityType.PRIMARY_MODAL_LITERAL);
} else if (PomStringConstants.MODELESS.equals(mp.getModality())) {
xmaPage.setCodModality(ModalityType.MODELESS_LITERAL);
} else {
throw new RuntimeException("Not supported modality-value: "+mp.getModality());
}
} else if (prop instanceof ImageProperty) {
ImageProperty ip = (ImageProperty)prop;
String imageUri = null;
if (ip.getImageUri() != null) {
imageUri = ip.getImageUri();
} else if (ip.getImageUriReference() != null) {
imageUri = ip.getImageUriReference().getSource();
}
if (imageUri != null) {
xmaPage.setUriImage(imageUri);
}
}
}
xmaComponent.getPage().add(xmaPage);
return xmaPage;
}
public static void addMenusToPage(Page page, XMAPage xmaPage) {
if ( xmaPage instanceof AppShell && page instanceof XmadslPage) {
XmadslPage xmadslPage = (XmadslPage)page;
addMenus((AppShell)xmaPage,xmadslPage.getMenus());
}
}
private static void addMenus(AppShell appShell, EList