xworker.swt.util.SwtDialog Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2007-2013 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package xworker.swt.util;
import ognl.OgnlException;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.xmeta.ActionContext;
import org.xmeta.ActionException;
import org.xmeta.Thing;
import org.xmeta.World;
import org.xmeta.util.UtilData;
import org.xmeta.util.UtilString;
public class SwtDialog extends Dialog{
Shell shell;
ActionContext actionContext;
public SwtDialog(Shell shell, ActionContext actionContext){
super((Shell) shell.getParent());
this.actionContext = actionContext;
this.shell = shell;
}
public SwtDialog(Shell parent, Shell shell, ActionContext actionContext) {
super(parent);
this.actionContext = actionContext;
this.shell = shell;
}
public Object open(){
Shell parent = getParent();
shell.open();
Display display = parent.getDisplay();
try{
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}catch(Exception e){
}
return actionContext.get("result");
}
public static Object open(Shell shell, ActionContext actionContext){
SwtDialog dialog = new SwtDialog(shell, actionContext);
return dialog.open();
}
/**
* 打开对话框的动作。
*
* @param actionContext
* @return
* @throws OgnlException
*/
public static Object openDialogAction(ActionContext actionContext) throws OgnlException{
Thing self = (Thing) actionContext.get("self");
Shell parentShell = (Shell) UtilData.getData(self, "parentShell", actionContext);
String shellPath = UtilString.getString(self, "shellPath", actionContext);
String vars = UtilString.getString(self, "vars", actionContext);
ActionContext ac = new ActionContext();
if(vars != null && !"".equals(vars)){
for(String var : vars.split("[,]")){
ac.put(var, actionContext.get(var));
}
}
ac.put("parent", parentShell);
Thing shellThing = World.getInstance().getThing(shellPath);
if(shellThing == null){
throw new ActionException("Shell thing is null, shellPath=" + shellPath + ", actionPath=" + self.getMetadata().getPath());
}
Shell shell = (Shell) shellThing.doAction("create", ac);
SwtDialog dialog = new SwtDialog(parentShell, shell, ac);
return dialog.open();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy