use of org.entirej.applicationframework.rwt.application.EJRWTApplicationManager in project rap by entirej.
the class EJRWTRCPApplication method run.
public void run() {
final Display display = new Display();
EJRWTImageRetriever.setGraphicsProvider(new EJRWTGraphicsProvider() {
private final ImageRegistry PLUGIN_REGISTRY = new ImageRegistry();
public Image getImage(String name, ClassLoader loader) {
Image image = PLUGIN_REGISTRY.get(name);
if (image == null || image.isDisposed()) {
if (name.startsWith("/") || name.startsWith("\\")) {
image = new Image(display, loader.getResourceAsStream(name.substring(1)));
} else
image = new Image(display, loader.getResourceAsStream(name));
PLUGIN_REGISTRY.put(name, image);
}
return image;
}
@Override
public void open(String output, String name) {
try {
Desktop.getDesktop().open(new File(output));
} catch (IOException e) {
e.printStackTrace();
}
}
public float getAvgCharWidth(Font font) {
GC gc = new GC(display);
try {
gc.setFont(font);
return gc.getFontMetrics().getAverageCharWidth();
} finally {
gc.dispose();
}
}
public int getCharHeight(Font font) {
if (font.getFontData().length > 0) {
return font.getFontData()[0].getHeight();
}
return 13;
}
public void rendererSection(Section section) {
// IGNOTE
}
});
EJRWTApplicationManager applicationManager = null;
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");
}
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()");
}
Shell shell = new Shell(display);
shell.setImage(EJRWTImageRetriever.get(getShellIcon()));
shell.setText(layoutContainer.getTitle());
preApplicationBuild(applicationManager);
applicationManager.buildApplication(appContainer, shell);
postApplicationBuild(applicationManager);
shell.layout();
shell.pack();
shell.setMaximized(true);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
use of org.entirej.applicationframework.rwt.application.EJRWTApplicationManager in project rap by entirej.
the class EJRWTListRecordBlockRenderer method notifyStatus.
protected void notifyStatus() {
if (hasFocus()) {
EJRWTApplicationManager mng = (EJRWTApplicationManager) _block.getFrameworkManager().getApplicationManager();
int displayedRecordCount = getDisplayedRecordCount();
if (mng.getStatusbar() != null) {
EJDataRecord focusedRecord = getFocusedRecord();
int displayedRecordNumber = getDisplayedRecordNumber(focusedRecord);
if (displayedRecordCount > 0 && displayedRecordNumber == -1) {
mng.getStatusbar().setStatus2("");
} else {
mng.getStatusbar().setStatus2(String.format("%s of %s", String.valueOf(displayedRecordNumber + 1), String.valueOf(displayedRecordCount)));
}
}
} else {
EJRWTApplicationManager mng = (EJRWTApplicationManager) _block.getFrameworkManager().getApplicationManager();
if (mng.getStatusbar() != null) {
mng.getStatusbar().setStatus2("");
}
}
}
use of org.entirej.applicationframework.rwt.application.EJRWTApplicationManager in project rap by entirej.
the class EJRWTMobileApplicationLauncher 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");
}
EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
properties.put(WebClient.PAGE_TITLE, layoutContainer.getTitle());
properties.put(WebClient.FAVICON, getFavicon());
properties.put(WebClient.BODY_HTML, getBodyHtml());
properties.put(WebClient.THEME_ID, THEME_DEFAULT);
addOtherResources(configuration);
configuration.addResource(getFavicon(), new FileResource());
configuration.addResource(getLoadingImage(), new FileResource());
configuration.addStyleSheet(THEME_DEFAULT, "resource/theme/default.css");
configuration.addStyleSheet(THEME_DEFAULT, getBaseThemeCSSLocation());
configuration.addResource(getBaseThemeCSSLocation(), new FileResource());
configuration.addStyleSheet(THEME_DEFAULT, "org/entirej/rwt/mobile/mobile.css");
configuration.addResource("org/entirej/rwt/mobile/mobile.css", 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();
return new EntryPoint() {
public int createUI() {
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);
}
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);
}
@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();
}
}
});
}
});
EJRWTApplicationManager applicationManager = null;
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);
EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
// Now build the application container
EJRWTApplicationContainer appContainer = new EJRWTApplicationContainer(layoutContainer) {
@Override
protected void buildApplicationContainer() {
_mainPane.setLayout(new FillLayout());
_mainPane.setData(RWT.CUSTOM_VARIANT, null);
_formContainer = createFormContainer(_applicationManager, _mainPane);
}
};
// 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();
final Shell shell = new Shell(display, SWT.NO_TRIM);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 1;
gridLayout.verticalSpacing = 0;
shell.setLayout(gridLayout);
final Composite nav = new Composite(shell, SWT.NONE);
nav.setLayout(new FillLayout());
final GridData navData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
navData.widthHint = getSidebarWidth();
navData.heightHint = SWT.MAX;
// nav.setLayoutData(navData);
final GridData navEmptyData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
navEmptyData.minimumWidth = 0;
navEmptyData.widthHint = 0;
nav.setLayoutData(navEmptyData);
nav.setVisible(false);
Composite page = new Composite(shell, SWT.NONE);
GridLayout gridLayoutPage = new GridLayout(1, false);
gridLayoutPage.marginHeight = 0;
gridLayoutPage.marginWidth = 0;
gridLayoutPage.verticalSpacing = 1;
page.setLayout(gridLayoutPage);
GridData pageData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
page.setLayoutData(pageData);
Composite pageHeader = new Composite(page, SWT.NONE);
GridData pageHData = new GridData(GridData.FILL_HORIZONTAL);
pageHData.heightHint = 40;
pageHData.minimumHeight = 40;
pageHeader.setLayoutData(pageHData);
GridLayout gridLayoutHeader = new GridLayout(8, false);
pageHeader.setLayout(gridLayoutHeader);
gridLayoutHeader.marginHeight = 1;
gridLayoutHeader.marginWidth = 1;
Button pageB = new Button(pageHeader, SWT.PUSH);
pageB.setImage(EJRWTImageRetriever.get("icons/menu-32.png"));
pageB.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
nav.setVisible(!nav.isVisible());
nav.setLayoutData(nav.isVisible() ? navData : navEmptyData);
shell.layout();
}
});
ui = new UI() {
@Override
public void showMenu(boolean show) {
nav.setVisible(show);
nav.setLayoutData(show ? navData : navEmptyData);
shell.layout();
}
};
final GridData actioBData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
actioBData.widthHint = 40;
actioBData.heightHint = 40;
pageB.setLayoutData(actioBData);
Text headerText = new Text(pageHeader, SWT.SINGLE | SWT.READ_ONLY | SWT.CENTER);
final GridData headerTextData = new GridData(SWT.FILL, SWT.FILL, true, true);
headerTextData.heightHint = 40;
headerTextData.grabExcessHorizontalSpace = true;
headerText.setLayoutData(headerTextData);
headerText.setText(layoutContainer.getTitle());
createToolBar(applicationManager, pageHeader);
Composite pageBody = new Composite(page, SWT.NONE);
GridData pageBData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
pageBody.setLayoutData(pageBData);
pageBody.setLayout(new FillLayout());
nav.setData(RWT.CUSTOM_VARIANT, "sidebar");
pageHeader.setData(RWT.CUSTOM_VARIANT, "drawerHeader");
// pageBody.setData(RWT.CUSTOM_VARIANT, "applayout");
pageB.setData(RWT.CUSTOM_VARIANT, "drawerAction");
headerText.setData(RWT.CUSTOM_VARIANT, "drawerTitle");
EJRWTContext.getPageContext().setManager(applicationManager);
getContext().getUISession().setAttribute("ej.MobileMode", true);
try {
preApplicationBuild(applicationManager);
} finally {
applicationManager.getConnection().close();
}
createNavigator(applicationManager, nav);
createDrawerBody(applicationManager, appContainer, pageBody);
try {
postApplicationBuild(applicationManager);
} finally {
applicationManager.getConnection().close();
}
shell.layout();
shell.setMaximized(true);
return openShell(display, shell);
}
};
}
}, properties);
}
use of org.entirej.applicationframework.rwt.application.EJRWTApplicationManager in project rap by entirej.
the class EJRWTSingleRecordBlockRenderer method notifyStatus.
protected void notifyStatus() {
if (hasFocus()) {
EJRWTApplicationManager mng = (EJRWTApplicationManager) _block.getFrameworkManager().getApplicationManager();
int displayedRecordCount = getDisplayedRecordCount();
if (mng.getStatusbar() != null) {
EJDataRecord focusedRecord = getFocusedRecord();
int displayedRecordNumber = getDisplayedRecordNumber(focusedRecord);
if (displayedRecordCount > 0 && displayedRecordNumber == -1) {
mng.getStatusbar().setStatus2("");
} else {
mng.getStatusbar().setStatus2(String.format("%s of %s", String.valueOf(displayedRecordNumber + 1), String.valueOf(displayedRecordCount)));
}
}
} else {
EJRWTApplicationManager mng = (EJRWTApplicationManager) _block.getFrameworkManager().getApplicationManager();
if (mng.getStatusbar() != null) {
mng.getStatusbar().setStatus2("");
}
}
}
use of org.entirej.applicationframework.rwt.application.EJRWTApplicationManager in project rap by entirej.
the class EJRWTDateItemRenderer method createCustomButtonControl.
@Override
public Control createCustomButtonControl(final Composite parent) {
final Label label = new Label(parent, SWT.NONE);
label.setImage(EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_DATE_SELECTION));
label.addMouseListener(new MouseListener() {
private final DateFormat format = new SimpleDateFormat("yyyy/MM/dd");
private void selectDate(final Shell abstractDialog, final DateTime calendar) {
try {
Object old = _baseValue;
Date newValue = format.parse(String.format("%d/%d/%d", calendar.getYear(), calendar.getMonth() + 1, calendar.getDay()));
newValue = converType(newValue);
setValue(newValue);
_item.itemValueChaged(newValue);
} catch (ParseException e1) {
// ignore
}
abstractDialog.close();
abstractDialog.dispose();
_item.gainFocus();
}
@Override
public void mouseUp(MouseEvent arg0) {
{
Shell shell = ((EJRWTApplicationManager) _item.getForm().getFrameworkManager().getApplicationManager()).getShell();
final Shell abstractDialog = new Shell(shell, SWT.ON_TOP | SWT.APPLICATION_MODAL | SWT.TITLE);
abstractDialog.setLayout(new GridLayout(3, false));
GridData gridData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
new Label(abstractDialog, SWT.NONE).setLayoutData(gridData);
Link today = new Link(abstractDialog, SWT.PUSH);
today.setText("<A>Today</A>");
today.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
Object old = _baseValue;
Date newValue = format.parse(format.format(new Date()));
newValue = converType(newValue);
setValue(newValue);
_item.itemValueChaged(newValue);
} catch (ParseException e1) {
// ignore
}
if (!abstractDialog.isDisposed()) {
abstractDialog.close();
abstractDialog.dispose();
}
_item.gainFocus();
}
});
Link clear = new Link(abstractDialog, SWT.PUSH);
clear.setText("<A>Clear</A>");
clear.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Object old = _baseValue;
setValue(null);
_item.itemValueChaged(null);
if (!abstractDialog.isDisposed()) {
abstractDialog.close();
abstractDialog.dispose();
}
_item.gainFocus();
}
});
final DateTime calendar = new DateTime(abstractDialog, SWT.CALENDAR | SWT.BORDER);
if (_baseValue != null && _baseValue instanceof Date) {
Date currentDate = (Date) _baseValue;
if (currentDate != null) {
String dateText = format.format(currentDate);
String[] split = dateText.split("/");
if (split.length == 3) {
calendar.setYear(Integer.parseInt(split[0]));
// month
calendar.setMonth(Integer.parseInt(split[1]) - 1);
// index
// from
// 0
calendar.setDay(Integer.parseInt(split[2]));
}
}
}
calendar.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
if (e.y >= 40) {
selectDate(abstractDialog, calendar);
}
}
});
String[] keys = new String[] { "ENTER", "RETURN", "CR" };
calendar.setData(EJ_RWT.ACTIVE_KEYS, keys);
calendar.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
}
});
gridData = new GridData();
gridData.horizontalSpan = 3;
calendar.setLayoutData(gridData);
gridData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
new Label(abstractDialog, SWT.NONE).setLayoutData(gridData);
Button ok = new Button(abstractDialog, SWT.PUSH);
ok.setText("OK");
ok.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
Date newValue = format.parse(String.format("%d/%d/%d", calendar.getYear(), calendar.getMonth() + 1, calendar.getDay()));
Object old = _baseValue;
newValue = converType(newValue);
setValue(newValue);
_item.itemValueChaged(newValue);
} catch (ParseException e1) {
// ignore
}
if (!abstractDialog.isDisposed()) {
abstractDialog.close();
abstractDialog.dispose();
}
_item.gainFocus();
}
});
Button close = new Button(abstractDialog, SWT.PUSH);
close.setText("Cancel");
close.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!abstractDialog.isDisposed()) {
abstractDialog.close();
abstractDialog.dispose();
}
_item.gainFocus();
}
});
abstractDialog.pack();
Rectangle shellBounds = shell.getBounds();
Point dialogSize = abstractDialog.getSize();
abstractDialog.setLocation(shellBounds.x + (shellBounds.width - dialogSize.x) / 2, shellBounds.y + (shellBounds.height - dialogSize.y) / 2);
abstractDialog.setText("Date Selection");
abstractDialog.open();
}
}
@Override
public void mouseDown(MouseEvent arg0) {
}
@Override
public void mouseDoubleClick(MouseEvent arg0) {
}
});
return label;
}
Aggregations