mercredi 3 juin 2015

ProgressBar in Eclipse mit Wizard page?

Hallo
ich versuche einen ProgressBar einzubauen ,der bis 10 hochzählen dann abbrechen kann.
Mein Code kann das leider nicht. Es wäre super, wenn ihr mir helfen könnt.




Java Code:

  1.  
  2. public class WizardProgress {
  3.  
  4. private static class MyWizard extends Wizard {
  5.  
  6. public MyWizard() {
  7.  
  8. }
  9.  
  10. /*
  11.   * (non-Javadoc)
  12.   * @see org.eclipse.jface.wizard.Wizard#addPages()
  13.   */
  14. @Override
  15. public void addPages() {
  16.  
  17. addPage(new MyWizardPageThread("Progress"));
  18. }
  19.  
  20. @Override
  21. public boolean performFinish() {
  22. return true;
  23. }
  24.  
  25. };
  26.  
  27. private static class MyWizardPageThread extends WizardPage {
  28.  
  29. private boolean loading = true;
  30.  
  31. protected MyWizardPageThread(String pageName) {
  32. super(pageName);
  33.  
  34. setTitle(pageName);
  35. }
  36.  
  37. @Override
  38. public void createControl(final Composite parent) { // control
  39. final Composite comp = new Composite(parent, SWT.NONE);
  40. comp.setLayout(new GridLayout(1, false));
  41.  
  42. final Composite barContainer = new Composite(comp, SWT.NONE);
  43. barContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  44. barContainer.setLayout(new GridLayout(2, false));
  45.  
  46. Label l = new Label(barContainer, SWT.NONE);
  47. l.setText("Loading...");
  48.  
  49. final ProgressBar bar = new ProgressBar(barContainer, SWT.INDETERMINATE);
  50. bar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  51. bar.setMaximum(10);
  52.  
  53. setControl(comp);
  54.  
  55. Thread t = new Thread() {
  56.  
  57. @Override
  58. public void run() { // run
  59.  
  60.  
  61. parent.getDisplay().syncExec(new Runnable() {
  62.  
  63. @Override
  64. public void run() {
  65. loading = false;
  66. getWizard().getContainer().updateButtons();
  67. }
  68. });
  69. }
  70.  
  71. };
  72.  
  73. t.start();
  74. }
  75.  
  76. }
  77.  
  78. public static void main(String[] args) {
  79. Display display = new Display();
  80.  
  81. final Shell shell = new Shell(display);
  82. shell.setLayout(new FillLayout());
  83. WizardDialog dialog = new WizardDialog(shell, new MyWizard());
  84. dialog.open();
  85. shell.open();
  86.  
  87. while (!shell.isDisposed()) {
  88. if (!display.readAndDispatch())
  89. display.sleep();
  90. }
  91.  
  92. display.dispose();
  93. }
  94. }


ProgressBar in Eclipse mit Wizard page?

0 commentaires:

Enregistrer un commentaire