public class invokatrondocument
extends properties
{
public static final string package = "package";
public static final string superclass = "superclass";
public static final string interfaces = "interfaces";
}
string package =
document.getproperty(invokatrondocument.package);
public class invokatronwizard extends wizard
implements inewwizard {
private invokatronwizardpage page;
private invokatronwizardpage2 page2;
private iselection selection;
public invokatronwizard() {
super();
setneedsprogressmonitor(true);
imagedescriptor image =
abstractuiplugin.
imagedescriptorfromplugin("invokatron",
"icons/invokatronicon32.gif");
setdefaultpageimagedescriptor(image);
}
public void init(iworkbench workbench,
istructuredselection selection) {
this.selection = selection;
}
public void addpages() {
page=new invokatronwizardpage(selection);
addpage(page);
page2 = new invokatronwizardpage2(
selection);
addpage(page2);
}public boolean performfinish() {
//first save all the page data as variables.
final string containername =
page.getcontainername();
final string filename =
page.getfilename();
final invokatrondocument properties =
new invokatrondocument();
properties.setproperty(
invokatrondocument.package,
page2.getpackage());
properties.setproperty(
invokatrondocument.superclass,
page2.getsuperclass());
properties.setproperty(
invokatrondocument.interfaces,
page2.getinterfaces());
//now invoke the finish method.
irunnablewithprogress op =
new irunnablewithprogress() {
public void run(
iprogressmonitor monitor)
throws invocationtargetexception {
try {
dofinish(
containername,
filename,
properties,
monitor);
} catch (coreexception e) {
throw new invocationtargetexception(e);
} finally {
monitor.done();
}
}
};
try {
getcontainer().run(true, false, op);
} catch (interruptedexception e) {
return false;
} catch (invocationtargetexception e) {
throwable realexception =
e.gettargetexception();
messagedialog.openerror(
getshell(),
"error",
realexception.getmessage());
return false;
}
return true;
}private void dofinish(
string containername,
string filename,
properties properties,
iprogressmonitor monitor)
throws coreexception {
// create a sample file
monitor.begintask("creating " + filename, 2);
iworkspaceroot root = resourcesplugin.
getworkspace().getroot();
iresource resource = root.findmember(
new path(containername));
if (!resource.exists()
!(resource instanceof icontainer)) {
throwcoreexception("container \"" +
containername +
"\" does not exist.");
}
icontainer container =
(icontainer)resource;
final ifile ifile = container.getfile(
new path(filename));
final file file =
ifile.getlocation().tofile();
try {
outputstream os =
new fileoutputstream(file, false);
properties.store(os, null);
os.close();
} catch (ioexception e) {
e.printstacktrace();
throwcoreexception(
"error writing to file " +
file.tostring());
}
//make sure the project is refreshed
//as the file was created outside the
//eclipse api.
container.refreshlocal(
iresource.depth_infinite, monitor);
monitor.worked(1);
monitor.settaskname(
"opening file for editing...");
getshell().getdisplay().asyncexec(
new runnable() {
public void run() {
iworkbenchpage page =
platformui.getworkbench().
getactiveworkbenchwindow().
getactivepage();
try {
ide.openeditor(
page,
ifile,
true);
} catch (partinitexception e) {
}
}
});
monitor.worked(1);
}
private void throwcoreexception(
string message) throws coreexception {
istatus status =
new status(
istatus.error,
"invokatron",
istatus.ok,
message,
null);
throw new coreexception(status);
}
}
public class invokatronwizardpage2 extends wizardpage {
private text packagetext;
private text superclasstext;
private text interfacestext;
private iselection selection;
public invokatronwizardpage2(iselection selection) {
super("wizardpage2");
settitle("invokatron wizard");
setdescription("this wizard creates a new"+
" file with *.invokatron extension.");
this.selection = selection;
}
private void updatestatus(string message) {
seterrormessage(message);
setpagecomplete(message == null);
}
public string getpackage() {
return packagetext.gettext();
}
public string getsuperclass() {
return superclasstext.gettext();
}
public string getinterfaces() {
return interfacestext.gettext();
}public void createcontrol(composite parent) {
composite controls =
new composite(parent, swt.null);
gridlayout layout = new gridlayout();
controls.setlayout(layout);
layout.numcolumns = 3;
layout.verticalspacing = 9;
label label =
new label(controls, swt.null);
label.settext("&package:");
packagetext = new text(
controls,
swt.border swt.single);
griddata gd = new griddata(
griddata.fill_horizontal);
packagetext.setlayoutdata(gd);
packagetext.addmodifylistener(
new modifylistener() {
public void modifytext(
modifyevent e) {
dialogchanged();
}
});
label = new label(controls, swt.null);
label.settext("blank = default package");
label = new label(controls, swt.null);
label.settext("&superclass:");
superclasstext = new text(
controls,
swt.border swt.single);
gd = new griddata(
griddata.fill_horizontal);
superclasstext.setlayoutdata(gd);
superclasstext.addmodifylistener(
new modifylistener() {
public void modifytext(
modifyevent e) {
dialogchanged();
}
});
label = new label(controls, swt.null);
label.settext("blank = object");
label = new label(controls, swt.null);
label.settext("&interfaces:");
interfacestext = new text(
controls,
swt.border swt.single);
gd = new griddata(
griddata.fill_horizontal);
interfacestext.setlayoutdata(gd);
interfacestext.addmodifylistener(
new modifylistener() {
public void modifytext(
modifyevent e) {
dialogchanged();
}
});
label = new label(controls, swt.null);
label.settext("separated by ','");
dialogchanged();
setcontrol(controls);
}private void dialogchanged() {
string apackage = getpackage();
string asuperclass = getsuperclass();
string interfaces = getinterfaces();
string status = new packagevalidator().isvalid(apackage);
if(status != null) {
updatestatus(status);
return;
}
status = new superclassvalidator().isvalid(asuperclass);
if(status != null) {
updatestatus(status);
return;
}
status = new interfacesvalidator().isvalid(interfaces);
if(status != null) {
updatestatus(status);
return;
}
updatestatus(null);
}
}public class interfacesvalidator implements icelleditorvalidator
{
public string isvalid(object value)
{
if( !( value instanceof string) )
return null;
string interfaces = ((string)value).trim();
if( interfaces.equals(""))
return null;
string[] interfacearray = interfaces.split(",");
for (int i = 0; i < interfacearray.length; i++)
{
istatus status = javaconventions
.validatejavatypename(interfacearray[i]);
if (status.getcode() != istatus.ok)
return "validation of interface " + interfacearray[i]
+ ": " + status.getmessage();
}
return null;
}
}
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器