예제 #1
0
  /**
   * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
   *     org.eclipse.jface.viewers.IStructuredSelection)
   * @since 4.0
   */
  @Override
  public void init(final IWorkbench workbench, final IStructuredSelection originalSelection) {

    IStructuredSelection selection = originalSelection;
    openProjectExists = ModelerUiViewUtils.workspaceHasOpenModelProjects();
    if (!openProjectExists) {
      newProject = ModelerUiViewUtils.queryUserToCreateModelProject();

      if (newProject != null) {
        selection = new StructuredSelection(newProject);
        openProjectExists = true;
      } else {
        openProjectExists = false;
      }
    }

    if (isAllModelsSelected(selection)) {
      initialSelection = new StructuredSelection(selection.toArray());
    }
    if (selection != null && !selection.isEmpty()) {
      this.folder = ModelUtil.getContainer(selection.getFirstElement());
    }

    if (folder != null && !folderInModelProject()) {
      // Create empty page
      this.mainPage =
          new WizardPage(NewVdbWizard.class.getSimpleName(), PAGE_TITLE, null) {
            @Override
            public void createControl(final Composite parent) {
              setControl(createEmptyPageControl(parent));
            }
          };
      this.mainPage.setMessage(NOT_MODEL_PROJECT_MSG, IMessageProvider.ERROR);
    } else {

      // Create and add page
      this.mainPage =
          new WizardPage(NewVdbWizard.class.getSimpleName(), PAGE_TITLE, null) {
            @Override
            public void createControl(final Composite parent) {
              setControl(createPageControl(parent));
            }
          };
      this.mainPage.setMessage(INITIAL_MESSAGE);

      // If current selection not null, set folder to selection if a folder, or to containing folder
      // if not
      if (this.folder != null) {
        if (!projectValidator.validate(new Object[] {this.folder}).isOK()) {
          this.folder = null;
        }
      } else { // folder == null
        this.mainPage.setMessage(SELECT_FOLDER_MESSAGE, IMessageProvider.ERROR);
      }
    }

    this.mainPage.setPageComplete(false);
    addPage(mainPage);
  }
예제 #2
0
  /** @since 4.0 */
  private void validatePage() {
    final IContainer folder;
    try {
      folder =
          WizardUtil.validateFileAndFolder(
              this.nameText, this.folderText, this.mainPage, ModelerCore.VDB_FILE_EXTENSION, false);
      if (this.mainPage.getMessageType() == IMessageProvider.ERROR) {
        // WizardUtil.validateFileAndFolder can set error message and message type so no need to do
        // further
        // validation if an error was already found (JBEDSP-588)
        return;
      }

      IStatus status = projectValidator.validate(new Object[] {folder});
      String proposedName = this.nameText.getText();

      if (!status.isOK()) {
        // only update the message if the vFolder is non-null;
        // if WizardUtil returned null, it already set the status
        // this corrects the case where the wrong message shows for
        // a bad filename.
        if (folder != null) {
          this.mainPage.setErrorMessage(status.getMessage());
          this.mainPage.setPageComplete(false);
        } // endif
      } else if (!nameValidator.isValidName(proposedName)) {
        this.mainPage.setErrorMessage(VDB_NAME_ERROR);
        this.mainPage.setPageComplete(false);
      } else if (ModelUtilities.vdbNameReservedValidation(proposedName) != null) {
        this.mainPage.setErrorMessage(ModelUtilities.vdbNameReservedValidation(proposedName));
        this.mainPage.setPageComplete(false);
      } else {
        this.mainPage.setErrorMessage(null);
        this.mainPage.setPageComplete(true);
      }

      if (this.mainPage.isPageComplete()) {
        this.name = proposedName;
        this.folder = folder;
      }
    } catch (final CoreException err) {
      VdbUiConstants.Util.log(err);
      WizardUtil.setPageComplete(this.mainPage, err.getLocalizedMessage(), IMessageProvider.ERROR);
    }
  }
 /** Validate the receiver and update the status with the result. */
 protected void updateOKStatus() {
   if (!fIsEmpty) {
     if (fValidator != null) {
       fCurrStatus = fValidator.validate(fViewer.getCheckedElements());
       updateStatus(fCurrStatus);
     } else if (!fCurrStatus.isOK()) {
       fCurrStatus =
           new Status(
               IStatus.OK,
               PlatformUI.PLUGIN_ID,
               IStatus.OK,
               "", //$NON-NLS-1$
               null);
     }
   } else {
     fCurrStatus =
         new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, fEmptyListMessage, null);
   }
   updateStatus(fCurrStatus);
 }
 protected void handleWidgetSelected(TypeNameMatch[] selection) {
   IStatus status = null;
   if (selection.length == 0) {
     status =
         new Status(
             IStatus.ERROR,
             JavaScriptPlugin.getPluginId(),
             IStatus.ERROR,
             "",
             null); //$NON-NLS-1$
   } else {
     if (fValidator != null) {
       List jElements = new ArrayList();
       for (int i = 0; i < selection.length; i++) {
         IType type = selection[i].getType();
         if (type != null) {
           jElements.add(type);
         } else {
           status =
               new Status(
                   IStatus.ERROR,
                   JavaScriptPlugin.getPluginId(),
                   IStatus.ERROR,
                   Messages.format(
                       JavaUIMessages.TypeSelectionDialog_error_type_doesnot_exist,
                       selection[i].getFullyQualifiedName()),
                   null);
           break;
         }
       }
       if (status == null) {
         status = fValidator.validate(jElements.toArray());
       }
     } else {
       status =
           new Status(
               IStatus.OK, JavaScriptPlugin.getPluginId(), IStatus.OK, "", null); // $NON-NLS-1$
     }
   }
   updateStatus(status);
 }