示例#1
0
 public static void disableKB(IProject project) {
   try {
     EclipseUtil.removeNatureFromProject(project, IKbProject.NATURE_ID);
   } catch (CoreException e) {
     getDefault().logError(e);
   }
 }
 public void init(String wizardId) {
   wizard = (NewBeansXMLCreationWizard) WorkbenchUtils.findWizardByDefId(wizardId);
   tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
   jp = EclipseUtil.getJavaProject(tck);
   wizard.init(CDIUIPlugin.getDefault().getWorkbench(), new StructuredSelection(jp));
   dialog =
       new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
   wizard.setOpenEditorAfterFinish(false);
   dialog.setBlockOnOpen(false);
   dialog.open();
 }
  public void testPreferredPackageManager() throws JavaModelException {
    BatchArtifactType type = BatchArtifactType.BATCHLET;

    IJavaProject javaProject = EclipseUtil.getJavaProject(project);

    javaProject.getPackageFragmentRoots()[0].createPackageFragment(
        "batch.artifact", true, new NullProgressMonitor());

    PreferredPackageManager.savePreferredPackage(project, type, TEST_PACKAGE_NAME);

    IPackageFragment suggestedPackageName =
        PreferredPackageManager.getPackageSuggestion(project, type);

    assertEquals(
        "Unexpected suggested package name",
        TEST_PACKAGE_NAME,
        suggestedPackageName.getPath().toString());
  }
    public void init(String wizardId, String packName, String typeName) {
      wizard = (NewElementWizard) WorkbenchUtils.findWizardByDefId(wizardId);
      tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
      jp = EclipseUtil.getJavaProject(tck);
      wizard.init(CDIUIPlugin.getDefault().getWorkbench(), new StructuredSelection(jp));
      if (wizard instanceof NewCDIElementWizard) {
        ((NewCDIElementWizard) wizard).setOpenEditorAfterFinish(false);
      } else if (wizard instanceof NewAnnotationLiteralCreationWizard) {
        ((NewAnnotationLiteralCreationWizard) wizard).setOpenEditorAfterFinish(false);
      }
      dialog =
          new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
      dialog.setBlockOnOpen(false);
      dialog.open();

      page = (NewTypeWizardPage) dialog.getSelectedPage();

      setTypeName(packName, typeName);
    }
 public NewWizardContext() {
   project = ResourcesPlugin.getWorkspace().getRoot().getProject("BatchTestProject");
   jp = EclipseUtil.getJavaProject(project);
 }
  public void run(IMarker marker) {
    IFile file = (IFile) javaDeclaration.getResource();
    try {
      ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
      if (original == null) {
        return;
      }
      ICompilationUnit compilationUnit = original.getWorkingCopy(new NullProgressMonitor());

      String lineDelim = JavaPropertyGenerator.getLineDelimiterUsed(compilationUnit);

      Hashtable<String, String> options = JavaCore.getOptions();

      int tabSize = new Integer(options.get("org.eclipse.jdt.core.formatter.tabulation.size"));

      StringBuffer tabBuf = new StringBuffer();

      for (int i = 0; i < tabSize; i++) tabBuf.append(" ");

      String tab = tabBuf.toString();

      IType type = compilationUnit.findPrimaryType();

      IField field = type.getField(property.getName());

      String propertyType = "";
      if (field != null && field.exists()) {
        propertyType = field.getTypeSignature();
      } else {
        propertyType = "String"; // $NON-NLS-1$

        StringBuffer buf = new StringBuffer();

        buf.append(
            tab
                + "private "
                + propertyType
                + " "
                + property.getName()
                + ";"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        buf.append(lineDelim);

        field = type.createField(buf.toString(), null, false, new NullProgressMonitor());
        if (field != null) {
          IBuffer buffer = compilationUnit.getBuffer();

          buffer.replace(
              field.getSourceRange().getOffset(),
              field.getSourceRange().getLength(),
              buf.toString());
          synchronized (compilationUnit) {
            compilationUnit.reconcile(ICompilationUnit.NO_AST, true, null, null);
          }
        }
      }

      IMethod oldMethod = GetterSetterUtil.getSetter(field);
      if (oldMethod == null || !oldMethod.exists()) {
        String setterName = GetterSetterUtil.getSetterName(field, null);
        // JavaPropertyGenerator.createSetter(compilationUnit, type, "public",
        // field.getTypeSignature(), setterName, lineDelim);

        String stub = GetterSetterUtil.getSetterStub(field, setterName, true, Flags.AccPublic);
        IMethod newMethod = type.createMethod(stub, null, false, new NullProgressMonitor());
        if (newMethod != null) {
          IBuffer buffer = compilationUnit.getBuffer();
          // format
          StringBuffer buf = new StringBuffer();

          buf.append(lineDelim);
          buf.append(
              tab
                  + "public void "
                  + setterName
                  + "("
                  + propertyType
                  + " "
                  + property.getName()
                  + "){"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          buf.append(lineDelim);
          buf.append(tab + tab + "this." + property.getName() + " = " + property.getName() + ";");
          buf.append(lineDelim);
          buf.append(tab + "}");
          buf.append(lineDelim);

          buffer.replace(
              newMethod.getSourceRange().getOffset(),
              newMethod.getSourceRange().getLength(),
              buf.toString());
        }
      }

      compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
      compilationUnit.discardWorkingCopy();

    } catch (CoreException ex) {
      SeamGuiPlugin.getPluginLog().logError(ex);
    }
  }