下面列出了怎么用org.eclipse.ui.IWorkbenchWizard的API类实例代码及写法,或者点击链接到github查看源代码。
public static void openWizard(final String id, final IStructuredSelection selection) {
// First see if this is a "new wizard".
IWizardDescriptor descriptor = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(id);
// If not check if it is an "import wizard".
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(id);
}
// Or maybe an export wizard
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getExportWizardRegistry().findWizard(id);
}
try {
// Then if we have a wizard, open it.
if (descriptor != null) {
final IWorkbenchWizard wizard = descriptor.createWizard();
wizard.init(PlatformUI.getWorkbench(), selection);
final WizardDialog wd = new WizardDialog(WorkbenchHelper.getDisplay().getActiveShell(), wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();
}
} catch (final CoreException e) {
e.printStackTrace();
}
}
public ICreateTargetQuery createNewPackageQuery() {
return new ICreateTargetQuery() {
public Object getCreatedTarget(Object selection) {
IWorkbenchWizard packageCreationWizard= new NewPackageCreationWizard();
IWizardPage[] pages= openNewElementWizard(packageCreationWizard, getShell(), selection);
NewPackageWizardPage page= (NewPackageWizardPage) pages[0];
return page.getNewPackageFragment();
}
public String getNewButtonLabel() {
return ReorgMessages.ReorgMoveWizard_newPackage;
}
};
}
private void openProcessWizard() {
Flow flow = getModel();
try {
String wizardId = "wizards.new.process";
IWorkbenchWizard w = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(wizardId).createWizard();
if (!(w instanceof ProcessWizard))
return;
ProcessWizard wizard = (ProcessWizard) w;
wizard.setRefFlow(flow);
WizardDialog dialog = new WizardDialog(UI.shell(), wizard);
if (dialog.open() == Window.OK) {
Navigator.refresh(Navigator.findElement(ModelType.PROCESS));
}
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(getClass());
log.error("failed to open process dialog from flow " + flow, e);
}
}
static void createSystem(Process process) {
if (process == null)
return;
try {
String wizardId = "wizards.new.productsystem";
IWorkbenchWizard wizard = PlatformUI.getWorkbench()
.getNewWizardRegistry().findWizard(wizardId).createWizard();
if (!(wizard instanceof ProductSystemWizard))
return;
ProductSystemWizard systemWizard = (ProductSystemWizard) wizard;
systemWizard.setProcess(process);
WizardDialog dialog = new WizardDialog(UI.shell(), wizard);
if (dialog.open() == Window.OK) {
Navigator.refresh(Navigator.findElement(ModelType.PRODUCT_SYSTEM));
}
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(ProcessToolbar.class);
log.error("failed to open product system dialog for process", e);
}
}
/**
* Opens the wizard with the given id and passes it the selection.
*
* @param wizardId
* The wizard id of the eclipse newWizard registry
* @param selection
* The selection
*/
private void openWizardForModule(String wizardId, IStructuredSelection selection, boolean nested) {
// Retrieve wizard from registry
IWizardDescriptor wizardDescriptor = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(wizardId);
if (wizardDescriptor == null) {
return;
}
try {
IWorkbenchWizard wizard = wizardDescriptor.createWizard();
// Inject wizard members
injector.injectMembers(wizard);
// Create and open a new wizard dialog
WizardDialog wizardDialog = new WizardDialog(UIUtils.getShell(), wizard);
// If the wizard supports it, enable in module option
if (wizard instanceof N4JSNewClassifierWizard<?>) {
((N4JSNewClassifierWizard<?>) wizard).init(PlatformUI.getWorkbench(), selection, nested);
} else {
// Otherwise just pass it the initial selection
wizard.init(PlatformUI.getWorkbench(), selection);
}
// wizardDialog.setTitle(wizard.getWindowTitle());
wizardDialog.open();
} catch (CoreException e) {
/** Failed to create the wizard */
Shell workbenchShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MessageDialog.open(MessageDialog.ERROR, workbenchShell, "Failed to launch wizard",
String.format("Failed to launch wizard %s", wizardId), SWT.SHEET);
return;
}
}
@Override
public void run ( final IAction action )
{
if ( this.selection == null )
{
return;
}
final IWorkbenchWizard wiz = new WriteAttributesOperationWizard ();
wiz.init ( this.site.getWorkbenchWindow ().getWorkbench (), this.selection );
// Embed the wizard into a dialog
final WizardDialog dialog = new WizardDialog ( this.site.getShell (), wiz );
dialog.open ();
}
@Override
public void run ( final IAction action )
{
if ( this.selection == null )
{
return;
}
final IWorkbenchWizard wiz = new WriteOperationWizard ();
wiz.init ( this.site.getWorkbenchWindow ().getWorkbench (), this.selection );
// Embed the wizard into a dialog
final WizardDialog dialog = new WizardDialog ( this.site.getShell (), wiz );
dialog.open ();
}
public static void openWizard(String wizardId, Shell parentShell, ISelection selection) {
// First see if this is a "new wizard".
IWizardDescriptor descriptor = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(wizardId);
// If not check if it is an "import wizard".
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(wizardId);
}
// Or maybe an export wizard
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getExportWizardRegistry().findWizard(wizardId);
}
try {
// Then if we have a wizard, open it.
if (descriptor != null) {
IWizard wizard = descriptor.createWizard();
if (wizard instanceof IWorkbenchWizard) {
IStructuredSelection structuredSelection = selection instanceof IStructuredSelection? (IStructuredSelection)selection : new StructuredSelection();
((IWorkbenchWizard)wizard).init(PlatformUI.getWorkbench(), structuredSelection);
WizardDialog wd = new WizardDialog(parentShell, wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();
}
else {
Assert.isTrue(false, "Attempt to call not IWorkbenchWizard"); //$NON-NLS-1$
}
}
} catch (CoreException e) {
e.printStackTrace();
}
}
private IWizardPage[] openNewElementWizard(IWorkbenchWizard wizard, Shell shell, Object selection) {
wizard.init(JavaPlugin.getDefault().getWorkbench(), new StructuredSelection(selection));
WizardDialog dialog= new WizardDialog(shell, wizard);
PixelConverter converter= new PixelConverter(JFaceResources.getDialogFont());
dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20));
dialog.create();
dialog.open();
IWizardPage[] pages= wizard.getPages();
return pages;
}