Unterschiede
Hier werden die Unterschiede zwischen der gewählten und der aktuellen Version gezeigt.
| eclipse-rcp:wizard 2007/12/17 13:37 | eclipse-rcp:wizard 2020/01/22 20:59 aktuell | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | [[eclipse-rcp|Java - Eclipse-RCP]]\\ | ||
| ====== Java - Eclipse-RCP - Wizards ====== | ====== Java - Eclipse-RCP - Wizards ====== | ||
| + | Basis dieses Beispiels ist wieder die [[source-example-application|Beispiel-Applikation]].\\ | ||
| + | \\ | ||
| + | <html> | ||
| + | <script type="text/javascript"><!-- | ||
| + | google_ad_client="pub-9681858985507948"; | ||
| + | google_ad_width = 468; | ||
| + | google_ad_height = 60; | ||
| + | google_ad_format = "468x60_as"; | ||
| + | google_ad_type = "text"; | ||
| + | google_ad_channel = ""; | ||
| + | google_color_border = "cccccc"; | ||
| + | google_color_bg = "FFFFFF"; | ||
| + | google_color_link = "1d2d8c"; | ||
| + | google_color_text = "000000"; | ||
| + | google_color_url = "1d2d8c"; | ||
| + | //--> | ||
| + | </script> | ||
| + | <script type="text/javascript" | ||
| + | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> | ||
| + | </script> | ||
| + | </html> | ||
| + | \\ | ||
| + | \\ | ||
| + | Der (leere) Wizard:\\ | ||
| + | <code java> | ||
| + | package com.sowas.javawiki.rcpbaseapplication.wizard; | ||
| + | |||
| + | import org.eclipse.jface.viewers.IStructuredSelection; | ||
| + | import org.eclipse.jface.wizard.Wizard; | ||
| + | import org.eclipse.ui.INewWizard; | ||
| + | import org.eclipse.ui.IWorkbench; | ||
| + | |||
| + | public class MyWizard extends Wizard implements INewWizard{ | ||
| + | |||
| + | @Override | ||
| + | public boolean performFinish(){ | ||
| + | return false; | ||
| + | } | ||
| + | |||
| + | @Override | ||
| + | public void init(IWorkbench workbench, IStructuredSelection selection){ | ||
| + | } | ||
| + | |||
| + | @Override | ||
| + | public void addPages() { | ||
| + | // Hier können die WizardPages hinzugefügt werden (Siehe weiter unten) | ||
| + | } | ||
| + | |||
| + | public Object getResult() { | ||
| + | return null; // Sollte natürlich die im Wizard erstellten Daten zurückliefern | ||
| + | } | ||
| + | } | ||
| + | </code>\\ | ||
| + | \\ | ||
| + | Der dazugehörige Handler:\\ | ||
| + | <code java> | ||
| + | package com.sowas.javawiki.rcpbaseapplication.wizard; | ||
| + | |||
| + | import org.eclipse.core.commands.ExecutionEvent; | ||
| + | import org.eclipse.core.commands.ExecutionException; | ||
| + | import org.eclipse.core.commands.IHandler; | ||
| + | import org.eclipse.core.commands.IHandlerListener; | ||
| + | import org.eclipse.jface.wizard.WizardDialog; | ||
| + | import org.eclipse.swt.graphics.Point; | ||
| + | import org.eclipse.swt.widgets.Display; | ||
| + | |||
| + | public class MyWizardHandler implements IHandler{ | ||
| + | @Override | ||
| + | public void addHandlerListener(IHandlerListener handlerListener){ | ||
| + | } | ||
| + | |||
| + | @Override | ||
| + | public void dispose(){ | ||
| + | } | ||
| + | |||
| + | @Override | ||
| + | public Object execute(ExecutionEvent event) throws ExecutionException{ | ||
| + | MyWizard myWizard = new MyWizard(); //(person); | ||
| + | |||
| + | WizardDialog wizardDialog = new WizardDialog(Display.getDefault().getActiveShell(), myWizard); | ||
| + | wizardDialog.create(); | ||
| + | Point defaultSize = wizardDialog.getShell().getSize(); | ||
| + | wizardDialog.getShell().setSize( | ||
| + | Math.max(400, defaultSize.x), | ||
| + | Math.max(600, defaultSize.y)); | ||
| + | |||
| + | wizardDialog.setBlockOnOpen(true); | ||
| + | |||
| + | Object result = null; | ||
| + | if (WizardDialog.OK == wizardDialog.open()) { | ||
| + | result = myWizard.getResult(); | ||
| + | } | ||
| + | return result; | ||
| + | } | ||
| + | |||
| + | @Override | ||
| + | public boolean isEnabled(){ | ||
| + | return true; | ||
| + | } | ||
| + | |||
| + | @Override | ||
| + | public boolean isHandled(){ | ||
| + | return true; // Muss true sein, sonst gibt's eine Exception | ||
| + | } | ||
| + | |||
| + | @Override | ||
| + | public void removeHandlerListener(IHandlerListener handlerListener){ | ||
| + | } | ||
| + | } | ||
| + | </code>\\ | ||
| + | \\ | ||
| + | und die angepasste plugin.xml: | ||
| + | <code xml> | ||
| + | <?xml version="1.0" encoding="UTF-8"?> | ||
| + | <?eclipse version="3.2"?> | ||
| + | <plugin> | ||
| + | |||
| + | <extension | ||
| + | id="application" | ||
| + | point="org.eclipse.core.runtime.applications"> | ||
| + | <application> | ||
| + | <run | ||
| + | class="com.sowas.javawiki.rcpbaseapplication.Application"> | ||
| + | </run> | ||
| + | </application> | ||
| + | </extension> | ||
| + | <extension | ||
| + | point="org.eclipse.ui.perspectives"> | ||
| + | <perspective | ||
| + | name="Perspective" | ||
| + | class="com.sowas.javawiki.rcpbaseapplication.MyPerspective" | ||
| + | id="BaseApplication.perspective"> | ||
| + | </perspective> | ||
| + | </extension> | ||
| + | <extension | ||
| + | point="org.eclipse.ui.views"> | ||
| + | <view | ||
| + | name="MyView" | ||
| + | class="com.sowas.javawiki.rcpbaseapplication.MyView" | ||
| + | id="com.sowas.javawiki.rcpbaseapplication.MyView"> | ||
| + | </view> | ||
| + | </extension> | ||
| + | <extension | ||
| + | point="org.eclipse.ui.editors"> | ||
| + | <editor | ||
| + | class="com.sowas.javawiki.rcpbaseapplication.MyEditor" | ||
| + | default="false" | ||
| + | id="com.sowas.javawiki.rcpbaseapplication.MyEditor" | ||
| + | name="MyEditor"> | ||
| + | </editor> | ||
| + | </extension> | ||
| + | <extension | ||
| + | point="org.eclipse.ui.menus"> | ||
| + | <menuContribution | ||
| + | locationURI="menu:org.eclipse.ui.main.menu?after=additions"> | ||
| + | <menu | ||
| + | label="Wizard"> | ||
| + | <command | ||
| + | commandId="com.sowas.javawiki.rcpbaseapplication.wizard.Wizard" | ||
| + | style="push"> | ||
| + | </command> | ||
| + | </menu> | ||
| + | </menuContribution> | ||
| + | </extension> | ||
| + | <extension | ||
| + | point="org.eclipse.ui.commands"> | ||
| + | <command | ||
| + | defaultHandler="com.sowas.javawiki.rcpbaseapplication.wizard.MyWizardHandler" | ||
| + | id="com.sowas.javawiki.rcpbaseapplication.wizard.Wizard" | ||
| + | name="Start Wizard"> | ||
| + | </command> | ||
| + | </extension> | ||
| + | |||
| + | </plugin> | ||
| + | </code>\\ | ||
| + | Nun kann man den noch leeren Wizard bereits starten.\\ | ||
| + | \\ | ||
| + | \\ | ||
| Um den Finish-Button in einem Wizard zu enablen, muss die Methode isPageComplete() true zurückliefern. | Um den Finish-Button in einem Wizard zu enablen, muss die Methode isPageComplete() true zurückliefern. | ||
| - | Soll der Button bei geöffnetem Wizard enabled/disabled werden, so muss updateButtons() aufgerufen werden. (Dies resultiert dann in einem Aufruf von isPageComplete()). | + | Soll der Button bei geöffnetem Wizard enabled/disabled werden, so muss updateButtons() aufgerufen werden. (Dies resultiert dann in einem Aufruf von isPageComplete()).\\ |
| <code java> | <code java> | ||
| private boolean m_isPageComplete = false; | private boolean m_isPageComplete = false; | ||
| /** Diese Methode enabled den Finish-Button **/ | /** Diese Methode enabled den Finish-Button **/ | ||
| - | void myMethod(){ | + | private void myMethod(){ |
| - | m_isPageComplete = true; // Das Flag, welches enabld/disabled | + | m_isPageComplete = true; // Das Flag, welches enabled/disabled |
| getWizard().getContainer().updateButtons(); | getWizard().getContainer().updateButtons(); | ||
| } | } | ||
| Zeile 16: | Zeile 195: | ||
| return m_isPageComplete; | return m_isPageComplete; | ||
| } | } | ||
| - | </code> | + | </code>\\ |