xworker.swt.actions.DialogActions Maven / Gradle / Ivy
package xworker.swt.actions;
import ognl.OgnlException;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Shell;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import org.xmeta.util.UtilData;
import org.xmeta.util.UtilMap;
public class DialogActions {
public static Object openColorDialog(ActionContext actionContext){
Thing self = (Thing) actionContext.get("self");
Shell shell = (Shell) self.doAction("getShell", actionContext);
ColorDialog dialog = new ColorDialog(shell);
if(self.getStringBlankAsNull("text") != null){
dialog.setText(self.getString("text"));
}
RGB rgb = dialog.open();
self.doAction("open", actionContext, UtilMap.toMap("color", rgb));
return rgb;
}
public static Object openFontDialog(ActionContext actionContext){
Thing self = (Thing) actionContext.get("self");
Shell shell = (Shell) self.doAction("getShell", actionContext);
FontDialog dialog = new FontDialog(shell);
if(self.getStringBlankAsNull("text") != null){
dialog.setText(self.getString("text"));
}
FontData data = dialog.open();
self.doAction("open", actionContext, UtilMap.toMap("font", data));
return data;
}
public static Object openPrintDialog(ActionContext actionContext) throws OgnlException{
Thing self = (Thing) actionContext.get("self");
Shell shell = (Shell) self.doAction("getShell", actionContext);
PrintDialog dialog = new PrintDialog(shell);
if(self.getStringBlankAsNull("text") != null){
dialog.setText(self.getString("text"));
}
if(self.getStringBlankAsNull("startPage") != null){
dialog.setStartPage(self.getInt("startPage"));
}
if(self.getStringBlankAsNull("endPage") != null){
dialog.setEndPage(self.getInt("endPage"));
}
if(self.getStringBlankAsNull("printToFile") != null){
dialog.setPrintToFile(self.getBoolean("printToFile"));
}
PrinterData pdata = UtilData.getObjectByType(self, "printData", PrinterData.class, actionContext);
if(pdata != null){
dialog.setPrinterData(pdata);
}
if(self.getStringBlankAsNull("scope") != null){
dialog.setScope(self.getInt("scope"));
}
PrinterData data = dialog.open();
self.doAction("open", actionContext, UtilMap.toMap("printData", data));
return data;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy