use of org.entirej.framework.core.EJActionProcessorException in project rap by entirej.
the class EJRWTApplicationContainer method createTabLayout.
private void createTabLayout(Composite parent, final EJCoreLayoutItem.TabGroup group) {
final CTabFolder layoutBody = new CTabFolder(parent, SWT.BORDER | (group.getOrientation() == TabGroup.ORIENTATION.TOP ? SWT.TOP : SWT.BOTTOM));
final EJAppTabFolder appTabFolder = new EJAppTabFolder(this, layoutBody);
_tabFolders.put(group.getName(), appTabFolder);
EJ_RWT.setTestId(layoutBody, group.getName());
layoutBody.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EJApplicationActionProcessor applicationActionProcessor = _applicationManager.getApplicationActionProcessor();
if (applicationActionProcessor != null) {
CTabItem selection = layoutBody.getSelection();
if (selection == null) {
return;
}
try {
String pageName = (String) selection.getData("TAB_KEY");
applicationActionProcessor.preShowTabPage(_applicationManager.getFrameworkManager(), group.getName(), pageName);
} catch (EJActionProcessorException e1) {
if (appTabFolder.getLastSelection() != null) {
appTabFolder.showPage(appTabFolder.getLastSelection());
}
if (e1.getFrameworkMessage() != null)
_applicationManager.handleMessage(e1.getFrameworkMessage());
return;
}
try {
String pageName = (String) selection.getData("TAB_KEY");
appTabFolder.setLastSelection(pageName);
applicationActionProcessor.tabPageChanged(_applicationManager.getFrameworkManager(), group.getName(), pageName);
} catch (EJActionProcessorException e1) {
e1.printStackTrace();
}
}
}
});
layoutBody.setLayoutData(createGridData(group));
List<EJCoreLayoutItem> items = group.getItems();
for (EJCoreLayoutItem item : items) {
CTabItem tabItem = new CTabItem(layoutBody, SWT.NONE);
appTabFolder.put(item.getName(), tabItem);
Composite composite = new Composite(layoutBody, SWT.NO_FOCUS);
composite.setData(EJ_RWT.CUSTOM_VARIANT, "applayout");
composite.setData("TAB_ITEM", tabItem);
composite.setData("TAB_KEY", item.getName());
EJ_RWT.setTestId(tabItem, group.getName() + "." + item.getName());
tabItem.setData("TAB_KEY", item.getName());
composite.setLayout(new GridLayout());
tabItem.setControl(composite);
tabItem.setText(item.getTitle() != null ? item.getTitle() : item.getName());
switch(item.getType()) {
case GROUP:
createGroupLayout(composite, (LayoutGroup) item);
break;
case SPACE:
createSpace(composite, (LayoutSpace) item);
break;
case COMPONENT:
createComponent(composite, (LayoutComponent) item);
break;
case SPLIT:
createSplitLayout(composite, (SplitGroup) item);
break;
case TAB:
createTabLayout(composite, (TabGroup) item);
break;
}
}
if (items.size() > 0) {
layoutBody.setSelection(0);
}
}
use of org.entirej.framework.core.EJActionProcessorException in project rap by entirej.
the class EJRWTBanner method createContainer.
@Override
public void createContainer(final EJRWTApplicationManager manager, Composite parent, final EJFrameworkExtensionProperties rendererprop) {
canvas = new Label(parent, getComponentStyle(rendererprop.getStringProperty(PROPERTY_ALIGNMENT), SWT.NONE));
canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
String imagePath = null;
if (rendererprop != null) {
String paramName = rendererprop.getStringProperty(IMAGE_PARAM);
final String action = rendererprop.getStringProperty(ACTION);
if (action != null && !action.isEmpty()) {
final Cursor cursor = new Cursor(canvas.getDisplay(), SWT.CURSOR_HAND);
canvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent event) {
cursor.dispose();
}
});
canvas.setCursor(cursor);
canvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
EJApplicationActionProcessor applicationActionProcessor = manager.getApplicationActionProcessor();
if (applicationActionProcessor != null) {
try {
applicationActionProcessor.executeActionCommand(manager.getFrameworkManager(), action);
} catch (EJActionProcessorException e1) {
e1.printStackTrace();
}
}
}
});
}
if (paramName != null && paramName.length() > 0) {
final EJApplicationLevelParameter applicationLevelParameter = manager.getApplicationLevelParameter(paramName);
if (applicationLevelParameter != null) {
Object value = applicationLevelParameter.getValue();
imagePath = (String) value;
if (imagePath != null) {
updateImage(manager, imagePath);
} else {
imagePath = rendererprop.getStringProperty(IMAGE_PATH);
updateImage(manager, imagePath);
}
applicationLevelParameter.addParameterChangedListener(new ParameterChangedListener() {
@Override
public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
if (newValue != null) {
updateImage(manager, (String) newValue);
} else {
updateImage(manager, rendererprop.getStringProperty(IMAGE_PATH));
}
}
});
} else {
imagePath = rendererprop.getStringProperty(IMAGE_PATH);
updateImage(manager, imagePath);
}
} else {
imagePath = rendererprop.getStringProperty(IMAGE_PATH);
updateImage(manager, imagePath);
}
}
}
use of org.entirej.framework.core.EJActionProcessorException in project rap by entirej.
the class EJRWTApplicationLauncher method createEntryPoint.
public void createEntryPoint(final Application configuration) {
configuration.setOperationMode(getOperationMode());
Map<String, String> properties = new HashMap<String, String>();
if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
EJFrameworkInitialiser.initialiseFramework("application.ejprop");
} else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
} else {
throw new RuntimeException("application.ejprop not found");
}
final EJCoreProperties coreProperties = EJCoreProperties.getInstance();
EJCoreLayoutContainer layoutContainer = coreProperties.getLayoutContainer();
properties.put(WebClient.PAGE_TITLE, layoutContainer.getTitle());
String favicon = getFavicon();
if (favicon == null) {
favicon = ICONS_FAVICON_ICO;
}
properties.put(WebClient.FAVICON, favicon);
properties.put(WebClient.BODY_HTML, getBodyHtml());
properties.put(WebClient.THEME_ID, THEME_DEFAULT);
addOtherResources(configuration);
configuration.addResource(favicon, new FileResource());
configuration.addResource(getLoadingImage(), new FileResource());
configuration.addStyleSheet(THEME_DEFAULT, "resource/theme/default.css");
String baseThemeCSSLocation = getBaseThemeCSSLocation();
if (baseThemeCSSLocation == null) {
baseThemeCSSLocation = THEME_DEFAULT_CSS;
}
configuration.addStyleSheet(THEME_DEFAULT, baseThemeCSSLocation);
properties.put(WebClient.PAGE_OVERFLOW, "scrollY");
configuration.addResource(baseThemeCSSLocation, new FileResource());
if (getThemeCSSLocation() != null) {
configuration.addStyleSheet(THEME_DEFAULT, getThemeCSSLocation());
configuration.addResource(getThemeCSSLocation(), new FileResource());
}
configuration.addEntryPoint(String.format("/%s", getWebPathContext()), new EntryPointFactory() {
public EntryPoint create() {
try {
RWT.getServiceManager().registerServiceHandler(VACSSServiceHandler.SERVICE_HANDLER, new VACSSServiceHandler());
RWT.getServiceManager().registerServiceHandler(EJRWTFileDownload.SERVICE_HANDLER, EJRWTFileDownload.newServiceHandler());
registerServiceHandlers();
} catch (java.lang.IllegalArgumentException e) {
// ignore if already registered
}
registerWidgetHandlers();
final EntryPoint wrapped = newEntryPoint();
return new EntryPoint() {
public int createUI() {
BrowserNavigation service = RWT.getClient().getService(BrowserNavigation.class);
BrowserNavigationListener listener = new BrowserNavigationListener() {
@Override
public void navigated(BrowserNavigationEvent event) {
EJRWTContext.getPageContext().setState(event.getState());
}
};
service.addBrowserNavigationListener(listener);
int createUI = wrapped.createUI();
return createUI;
}
};
}
private EntryPoint newEntryPoint() {
return new EntryPoint() {
public int createUI() {
{
// connect BaseURL
StringBuffer url = new StringBuffer();
url.append(RWT.getRequest().getContextPath());
url.append(RWT.getRequest().getServletPath());
String encodeURL = RWT.getResponse().encodeURL(url.toString());
if (encodeURL.contains("jsessionid")) {
encodeURL = encodeURL.substring(0, encodeURL.indexOf("jsessionid"));
}
int patchIndex = encodeURL.lastIndexOf(getWebPathContext());
if (patchIndex > -1) {
encodeURL = encodeURL.substring(0, patchIndex);
}
_baseURL = encodeURL;
}
RWTUtils.patchClient(getWebPathContext(), getTimeoutUrl());
EJRWTImageRetriever.setGraphicsProvider(new EJRWTGraphicsProvider() {
@Override
public void promptFileUpload(final EJFileUpload fileUpload, final Callable<Object> callable) {
if (fileUpload.isMultiSelection()) {
EJRWTFileUpload.promptMultipleFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {
@Override
public void select(String[] files) {
try {
fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
callable.call();
} catch (Exception e) {
e.printStackTrace();
}
}
});
} else {
EJRWTFileUpload.promptFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {
@Override
public void select(String[] files) {
try {
fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
callable.call();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
public Image getImage(String name, ClassLoader loader) {
return RWTUtils.getImage(name, loader);
}
@Override
public void open(final String output, String outputName) {
EJRWTFileDownload.download(output, outputName);
RWT.getUISession().addUISessionListener(new UISessionListener() {
private static final long serialVersionUID = 1L;
@Override
public void beforeDestroy(UISessionEvent arg0) {
File f = new File(output);
if (f.exists()) {
f.delete();
}
}
});
}
public float getAvgCharWidth(Font font) {
return RWTUtils.getAvgCharWidth(font);
}
public int getCharHeight(Font font) {
return RWTUtils.getCharHeight(font);
}
public void rendererSection(final Section section) {
section.removeListener(SWT.Dispose, section.getListeners(SWT.Dispose)[0]);
section.removeListener(SWT.Resize, section.getListeners(SWT.Resize)[0]);
section.setFont(section.getParent().getFont());
section.setForeground(section.getParent().getForeground());
Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
gfxAdapter.setRoundedBorder(1, section.getTitleBarBackground(), 2, 2, 0, 0);
Listener listener = new Listener() {
public void handleEvent(Event e) {
Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
Color[] gradientColors = new Color[] { section.getTitleBarBorderColor(), section.getBackground(), section.getTitleBarBackground(), section.getBackground(), section.getBackground() };
int gradientPercent = 0;
Rectangle bounds = section.getClientArea();
if (bounds.height != 0) {
gradientPercent = 30 * 100 / bounds.height;
if (gradientPercent > 100) {
gradientPercent = 100;
}
}
int[] percents = new int[] { 0, 1, 2, gradientPercent, 100 };
gfxAdapter.setBackgroundGradient(gradientColors, percents, true);
gfxAdapter.setRoundedBorder(1, section.getBackground(), 4, 4, 0, 0);
}
};
section.addListener(SWT.Dispose, listener);
section.addListener(SWT.Resize, listener);
}
});
final EJRWTApplicationManager applicationManager;
if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("application.ejprop");
} else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
} else {
throw new RuntimeException("application.ejprop not found");
}
EJRWTContext.getPageContext().setManager(applicationManager);
getContext().getUISession().setAttribute("ej.applicationManager", applicationManager);
EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
// Now build the application container
EJRWTApplicationContainer appContainer = new EJRWTApplicationContainer(layoutContainer);
// Add the application menu and status bar to the app
// container
EJMessenger messenger = applicationManager.getApplicationMessenger();
if (messenger == null) {
throw new NullPointerException("The ApplicationComponentProvider must provide an Messenger via method: getApplicationMessenger()");
}
Display display = Display.getDefault();
if (display.isDisposed())
display = new Display();
Shell shell = new Shell(display, SWT.NO_TRIM);
// check test mode
StartupParameters service = RWT.getClient().getService(StartupParameters.class);
if (service != null && Boolean.valueOf(service.getParameter("TEST_MODE"))) {
EJ_RWT.setTestMode(true);
}
try {
preApplicationBuild(applicationManager);
} finally {
applicationManager.getConnection().close();
}
applicationManager.buildApplication(appContainer, shell);
final EJRWTApplicationManager appman = applicationManager;
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
try {
postApplicationBuild(appman);
} finally {
appman.getConnection().close();
}
}
});
shell.layout();
shell.setMaximized(true);
// disable due to RWT bug
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=410895
// ExitConfirmation confirmation =
// RWT.getClient().getService(ExitConfirmation.class);
// String message = getDefaultTabCloseMessage();
// if ("__DEFAULT__".equals(message))
// {
// confirmation.setMessage(String.format("Do you want to close %s ?",
// EJCoreProperties.getInstance().getLayoutContainer().getTitle()));
// }
// else if (message != null)
// {
// confirmation.setMessage(message);
// }
final ServerPushSession pushSession = new ServerPushSession();
RWT.getUISession().addUISessionListener(new UISessionListener() {
public void beforeDestroy(UISessionEvent event) {
if (applicationManager.getApplicationActionProcessor() != null)
try {
applicationManager.getApplicationActionProcessor().whenApplicationEnd(applicationManager);
} catch (EJActionProcessorException e) {
e.printStackTrace();
}
pushSession.stop();
}
});
if (applicationManager.getApplicationActionProcessor() != null)
try {
applicationManager.getApplicationActionProcessor().whenApplicationStart(applicationManager);
} catch (EJActionProcessorException e) {
e.printStackTrace();
}
EJFrameworkExtensionProperties definedProperties = coreProperties.getApplicationDefinedProperties();
if (definedProperties != null && definedProperties.getBooleanProperty("LIVE_CONNECTION", false))
pushSession.start();
return openShell(display, shell);
}
};
}
}, properties);
// services
{
final String SERVICE = "SERVICE";
final String SERVICE_LIST = "SERVICE_LIST";
final String SERVICE_PATH = "SERVICE_PATH";
final String SERVICE_FORM = "SERVICE_FORM";
final String SERVICE_NAME = "SERVICE_NAME";
EJFrameworkExtensionProperties definedProperties = coreProperties.getApplicationDefinedProperties();
if (canLoadServices() && definedProperties != null) {
EJFrameworkExtensionProperties group = definedProperties.getPropertyGroup(SERVICE);
if (group != null && group.getPropertyList(SERVICE_LIST) != null) {
EJCoreFrameworkExtensionPropertyList list = group.getPropertyList(SERVICE_LIST);
List<EJFrameworkExtensionPropertyListEntry> allListEntries = list.getAllListEntries();
for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
final String formId = entry.getProperty(SERVICE_FORM);
HashMap<String, String> srvproperties = new HashMap<String, String>(properties);
srvproperties.put(WebClient.PAGE_TITLE, entry.getProperty(SERVICE_NAME));
if (entry.getProperty(SERVICE_PATH) != null && formId != null && formId != null) {
configuration.addEntryPoint(String.format("/%s", entry.getProperty(SERVICE_PATH)), new EntryPointFactory() {
public EntryPoint create() {
try {
RWT.getServiceManager().registerServiceHandler(VACSSServiceHandler.SERVICE_HANDLER, new VACSSServiceHandler());
RWT.getServiceManager().registerServiceHandler(EJRWTFileDownload.SERVICE_HANDLER, EJRWTFileDownload.newServiceHandler());
registerServiceHandlers();
} catch (java.lang.IllegalArgumentException e) {
// ignore if already registered
}
registerWidgetHandlers();
final EntryPoint wrapped = newServiceEntryPoint(formId);
return new EntryPoint() {
public int createUI() {
BrowserNavigation service = RWT.getClient().getService(BrowserNavigation.class);
BrowserNavigationListener listener = new BrowserNavigationListener() {
@Override
public void navigated(BrowserNavigationEvent event) {
EJRWTContext.getPageContext().setState(event.getState());
}
};
service.addBrowserNavigationListener(listener);
int createUI = wrapped.createUI();
return createUI;
}
};
}
private EntryPoint newServiceEntryPoint(String serviceFormID) {
return new EntryPoint() {
public int createUI() {
RWTUtils.patchClient(getWebPathContext(), null);
EJRWTImageRetriever.setGraphicsProvider(new EJRWTGraphicsProvider() {
@Override
public void promptFileUpload(final EJFileUpload fileUpload, final Callable<Object> callable) {
if (fileUpload.isMultiSelection()) {
EJRWTFileUpload.promptMultipleFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {
@Override
public void select(String[] files) {
try {
fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
callable.call();
} catch (Exception e) {
e.printStackTrace();
}
}
});
} else {
EJRWTFileUpload.promptFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {
@Override
public void select(String[] files) {
try {
fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
callable.call();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
public Image getImage(String name, ClassLoader loader) {
return RWTUtils.getImage(name, loader);
}
@Override
public void open(final String output, String outputName) {
EJRWTFileDownload.download(output, outputName);
RWT.getUISession().addUISessionListener(new UISessionListener() {
private static final long serialVersionUID = 1L;
@Override
public void beforeDestroy(UISessionEvent arg0) {
File f = new File(output);
if (f.exists()) {
f.delete();
}
}
});
}
public float getAvgCharWidth(Font font) {
return RWTUtils.getAvgCharWidth(font);
}
public int getCharHeight(Font font) {
return RWTUtils.getCharHeight(font);
}
public void rendererSection(final Section section) {
section.removeListener(SWT.Dispose, section.getListeners(SWT.Dispose)[0]);
section.removeListener(SWT.Resize, section.getListeners(SWT.Resize)[0]);
section.setFont(section.getParent().getFont());
section.setForeground(section.getParent().getForeground());
Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
gfxAdapter.setRoundedBorder(1, section.getTitleBarBackground(), 2, 2, 0, 0);
Listener listener = new Listener() {
public void handleEvent(Event e) {
Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
Color[] gradientColors = new Color[] { section.getTitleBarBorderColor(), section.getBackground(), section.getTitleBarBackground(), section.getBackground(), section.getBackground() };
int gradientPercent = 0;
Rectangle bounds = section.getClientArea();
if (bounds.height != 0) {
gradientPercent = 30 * 100 / bounds.height;
if (gradientPercent > 100) {
gradientPercent = 100;
}
}
int[] percents = new int[] { 0, 1, 2, gradientPercent, 100 };
gfxAdapter.setBackgroundGradient(gradientColors, percents, true);
gfxAdapter.setRoundedBorder(1, section.getBackground(), 4, 4, 0, 0);
}
};
section.addListener(SWT.Dispose, listener);
section.addListener(SWT.Resize, listener);
}
});
final EJRWTApplicationManager applicationManager;
if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("application.ejprop");
} else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
} else {
throw new RuntimeException("application.ejprop not found");
}
EJRWTContext.getPageContext().setManager(applicationManager);
getContext().getUISession().setAttribute("ej.applicationManager", applicationManager);
EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
// Now build the application container
EJRWTApplicationContainer appContainer = new EJRWTApplicationContainer(layoutContainer);
// Add the application menu and status bar to the app
// container
EJMessenger messenger = applicationManager.getApplicationMessenger();
if (messenger == null) {
throw new NullPointerException("The ApplicationComponentProvider must provide an Messenger via method: getApplicationMessenger()");
}
Display display = Display.getDefault();
if (display.isDisposed())
display = new Display();
Shell shell = new Shell(display, SWT.NO_TRIM);
applicationManager.buildServiceApplication(appContainer, shell, formId);
final EJRWTApplicationManager appman = applicationManager;
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
try {
postApplicationBuild(appman);
} finally {
appman.getConnection().close();
}
}
});
shell.layout();
shell.setMaximized(true);
final ServerPushSession pushSession = new ServerPushSession();
RWT.getUISession().addUISessionListener(new UISessionListener() {
public void beforeDestroy(UISessionEvent event) {
pushSession.stop();
}
});
pushSession.start();
return openShell(display, shell);
}
};
}
}, srvproperties);
}
}
}
}
}
}
use of org.entirej.framework.core.EJActionProcessorException in project rap by entirej.
the class EJRWTStatusbar method createContainer.
@Override
public void createContainer(final EJRWTApplicationManager manager, Composite parent, EJFrameworkExtensionProperties rendererprop) {
int style = SWT.NONE;
panel = new Composite(parent, style);
panel.setData(EJ_RWT.CUSTOM_VARIANT, "applayout");
actionProcessor = manager.getApplicationActionProcessor();
final EJFrameworkExtensionPropertyList propertyList = rendererprop.getPropertyList(SECTIONS);
if (propertyList == null) {
return;
}
List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
GridLayout layout = new GridLayout(allListEntries.size(), false);
panel.setLayout(layout);
for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
Control control;
final String action = entry.getProperty(ACTION);
if (action != null && action.trim().length() > 0) {
final Link linkField;
String alignmentProperty = entry.getProperty(PROPERTY_ALIGNMENT);
// use workaround to make sure link also provide alignment
if (alignmentProperty != null && alignmentProperty.trim().length() > 0) {
if (alignmentProperty.equals(PROPERTY_ALIGNMENT_LEFT)) {
control = linkField = new Link(panel, style);
} else if (alignmentProperty.equals(PROPERTY_ALIGNMENT_RIGHT)) {
EJRWTEntireJGridPane sub = new EJRWTEntireJGridPane(panel, 3);
control = sub;
sub.cleanLayout();
new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
linkField = new Link(sub, style);
} else if (alignmentProperty.equals(PROPERTY_ALIGNMENT_CENTER)) {
EJRWTEntireJGridPane sub = new EJRWTEntireJGridPane(panel, 3);
control = sub;
sub.cleanLayout();
new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
linkField = new Link(sub, style);
new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
} else {
control = linkField = new Link(panel, style);
}
} else {
control = linkField = new Link(panel, style);
}
String paramName = entry.getProperty(PARAMETER);
if (paramName != null && paramName.length() > 0) {
final EJApplicationLevelParameter applicationLevelParameter = manager.getApplicationLevelParameter(paramName);
if (applicationLevelParameter != null) {
Object value = applicationLevelParameter.getValue();
linkField.setText(String.format("<a>%s</a>", (value == null ? "" : value.toString())));
applicationLevelParameter.addParameterChangedListener(new ParameterChangedListener() {
@Override
public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
linkField.setText(String.format("<a>%s</a>", (newValue == null ? "" : newValue.toString())));
}
});
}
}
if (actionProcessor != null) {
linkField.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
actionProcessor.executeActionCommand(manager.getFrameworkManager(), action);
} catch (EJActionProcessorException e1) {
logger.error(e1.getMessage(), e);
}
}
});
}
// set VA
String visualAttribute = entry.getProperty(VISUAL_ATTRIBUTE_PROPERTY);
if (visualAttribute != null && visualAttribute.length() > 0) {
EJCoreVisualAttributeProperties va = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
if (va != null) {
Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(va);
if (background != null) {
linkField.setBackground(background);
}
Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(va);
if (foreground != null) {
linkField.setForeground(foreground);
}
linkField.setFont(EJRWTVisualAttributeUtils.INSTANCE.getFont(va, linkField.getFont()));
}
}
linkField.setData(EJ_RWT.CUSTOM_VARIANT, "applayout");
control.setData(EJ_RWT.CUSTOM_VARIANT, "applayout");
} else {
final Label section = new Label(panel, getComponentStyle(entry.getProperty(PROPERTY_ALIGNMENT), SWT.NONE));
control = section;
section.setData(EJ_RWT.MARKUP_ENABLED, Boolean.TRUE);
String paramName = entry.getProperty(PARAMETER);
if (paramName != null && paramName.length() > 0) {
final EJApplicationLevelParameter applicationLevelParameter = manager.getApplicationLevelParameter(paramName);
if (applicationLevelParameter != null) {
Object value = applicationLevelParameter.getValue();
section.setText(value == null ? "" : value.toString());
applicationLevelParameter.addParameterChangedListener(new ParameterChangedListener() {
@Override
public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
section.setText(newValue == null ? "" : newValue.toString());
}
});
}
}
// set VA
String visualAttribute = entry.getProperty(VISUAL_ATTRIBUTE_PROPERTY);
if (visualAttribute != null && visualAttribute.length() > 0) {
EJCoreVisualAttributeProperties va = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
if (va != null) {
Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(va);
if (background != null) {
section.setBackground(background);
}
Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(va);
if (foreground != null) {
section.setForeground(foreground);
}
section.setFont(EJRWTVisualAttributeUtils.INSTANCE.getFont(va, section.getFont()));
}
}
}
GridData gridData = new GridData();
gridData.verticalAlignment = SWT.CENTER;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = SWT.FILL;
control.setLayoutData(gridData);
boolean expand = Boolean.valueOf(entry.getProperty(EXPAND_X));
if (expand) {
gridData.grabExcessHorizontalSpace = true;
}
String width = entry.getProperty(WIDTH);
if (width != null && width.length() > 0) {
try {
gridData.widthHint = (Integer.parseInt(width));
} catch (Exception ex) {
// ignore
}
}
//
}
}
use of org.entirej.framework.core.EJActionProcessorException in project rap by entirej.
the class EJRWTDefaultMenuBuilder method createMenuTree.
private TreeViewer createMenuTree(EJRWTMenuTreeRoot root, boolean tselectionMode) {
_menuTree = new TreeViewer(_parent);
_menuTree.setContentProvider(new EJRWTMenuTreeContentProvider());
_menuTree.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof EJRWTMenuTreeElement) {
return ((EJRWTMenuTreeElement) element).getText();
}
return "<EMPTY>";
}
@Override
public Image getImage(Object element) {
if (element instanceof EJRWTMenuTreeElement) {
return ((EJRWTMenuTreeElement) element).getImage();
}
return super.getImage(element);
}
});
_menuTree.setAutoExpandLevel(2);
_menuTree.setInput(root);
EJMenuActionProcessor actionProcessor = null;
if (root.getActionProcessorClassName() != null && root.getActionProcessorClassName().length() > 0) {
try {
Class<?> processorClass = Class.forName(root.getActionProcessorClassName());
try {
Object processorObject = processorClass.newInstance();
if (processorObject instanceof EJMenuActionProcessor) {
actionProcessor = (EJMenuActionProcessor) processorObject;
} else {
throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_ACTION_PROCESSOR_NAME, processorClass.getName(), "EJMenuActionProcessor"));
}
} catch (InstantiationException e) {
throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.UNABLE_TO_CREATE_ACTION_PROCESSOR, processorClass.getName()), e);
} catch (IllegalAccessException e) {
throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.UNABLE_TO_CREATE_ACTION_PROCESSOR, processorClass.getName()), e);
}
} catch (ClassNotFoundException e) {
throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_ACTION_PROCESSOR_FOR_MENU, root.getActionProcessorClassName()));
}
}
final EJMenuActionProcessor menuActionProcessor = actionProcessor;
if (tselectionMode) {
_menuTree.getTree().addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent event) {
ISelection selection = _menuTree.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.getFirstElement() instanceof EJRWTMenuTreeElement) {
EJRWTMenuTreeElement element = (EJRWTMenuTreeElement) structuredSelection.getFirstElement();
if (element.getType() == Type.FORM) {
_applicationManager.getFrameworkManager().openForm(element.getActionCommand(), null, false);
} else if (element.getType() == Type.ACTION && menuActionProcessor != null) {
try {
menuActionProcessor.executeActionCommand(element.getActionCommand());
} catch (EJActionProcessorException e) {
_applicationManager.getApplicationMessenger().handleException(e, true);
}
}
}
}
}
});
}
_menuTree.getTree().addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent arg0) {
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
ISelection selection = _menuTree.getSelection();
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.getFirstElement() instanceof EJRWTMenuTreeElement) {
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
try {
EJRWTMenuTreeElement element = (EJRWTMenuTreeElement) structuredSelection.getFirstElement();
if (element.getType() == Type.FORM) {
_applicationManager.getFrameworkManager().openForm(element.getActionCommand(), null, false);
} else if (element.getType() == Type.ACTION && menuActionProcessor != null) {
try {
menuActionProcessor.executeActionCommand(element.getActionCommand());
} catch (EJActionProcessorException e) {
_applicationManager.getApplicationMessenger().handleException(e, true);
}
}
} catch (EJApplicationException e) {
_applicationManager.handleException(e);
}
}
});
}
}
}
});
return _menuTree;
}
Aggregations