/**
   * Runs the organize manifest operation for projects in the provided selection. Public to allow
   * editors to call this action
   *
   * <p>TODO This could be done better using the ICommandService
   *
   * @param selection selection to run organize manifest operation on
   */
  public void runOrganizeManfestsAction(ISelection selection) {
    if (!PlatformUI.getWorkbench().saveAllEditors(true)) return;

    if (selection instanceof IStructuredSelection) {
      IStructuredSelection ssel = (IStructuredSelection) selection;
      Iterator<?> it = ssel.iterator();
      ArrayList<IProject> projects = new ArrayList<>();
      while (it.hasNext()) {
        Object element = it.next();
        IProject proj = null;
        if (element instanceof IFile) proj = ((IFile) element).getProject();
        else if (element instanceof IProject) proj = (IProject) element;
        else if (element instanceof IJavaProject) {
          proj = ((IJavaProject) element).getProject();
        }
        if (proj != null && PDEProject.getManifest(proj).exists()) projects.add(proj);
      }
      if (projects.size() > 0) {
        OrganizeManifestsProcessor processor = new OrganizeManifestsProcessor(projects);
        PDERefactor refactor = new PDERefactor(processor);
        OrganizeManifestsWizard wizard = new OrganizeManifestsWizard(refactor);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);

        try {
          op.run(PDEPlugin.getActiveWorkbenchShell(), ""); // $NON-NLS-1$
        } catch (final InterruptedException irex) {
        }
      } else
        MessageDialog.openInformation(
            PDEPlugin.getActiveWorkbenchShell(),
            PDEUIMessages.OrganizeManifestsWizardPage_title,
            PDEUIMessages.OrganizeManifestsWizardPage_errorMsg);
    }
  }
  public void dragSetData(DragSourceEvent event) {
    IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
    Iterator<?> iterator = selection.iterator();

    if (PluginTransfer.getInstance().isSupportedType(event.dataType)) {
      try {
        List<Reachable> objectURIs = new ArrayList<Reachable>();
        while (iterator.hasNext()) {
          Object next = iterator.next();
          ReachableObject fromObject;
          try {
            fromObject = manager.getHandlerFromObject(next).getFromObject(next);
            if (fromObject.getReachable() != null) {
              objectURIs.add(fromObject.getReachable());
            }
          } catch (IReachableHandlerException e) {
            e.printStackTrace();
          }
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream buffered;
        buffered = new ObjectOutputStream(bos);
        buffered.writeObject(objectURIs.toArray());
        byte[] data = bos.toByteArray();
        bos.close();
        buffered.close();

        event.data = new PluginTransferData(PLUGIN_TRANSFER_ACTION_ID, data);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 3
0
  private static File[] convertSelectionToFiles(ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) return new File[0];

    IStructuredSelection structSel = (IStructuredSelection) selection;
    List<File> files = new ArrayList<File>(structSel.size());

    for (Iterator<?> iter = structSel.iterator(); iter.hasNext(); ) {
      Object element = iter.next();
      if (element instanceof IFile) files.add(((IFile) element).getLocation().toFile());
      else if (element instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) element;
        IFile ifile = (IFile) adaptable.getAdapter(IFile.class);
        if (ifile != null) {
          files.add(ifile.getLocation().toFile());
        } else {
          File file = (File) adaptable.getAdapter(File.class);
          if (file != null) {
            files.add(file);
          }
        }
      }
    }

    return files.toArray(new File[files.size()]);
  }
  private void addNewFileAction(IMenuManager manager) {
    ISelection selection = myViewer.getSelection();
    if (selection == null || selection.isEmpty()) {
      return;
    }

    if (selection instanceof IStructuredSelection == false) {
      return;
    }

    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    Object obj = structuredSelection.iterator().next();
    if (obj instanceof IContainer == false) {
      return;
    }

    IContainer cont = (IContainer) obj;

    IAction newFileAction = new NewFileAction(this, cont, myDefaultFileName);
    newFileAction.setText(Messages.SelectFileControl_NewFile);
    newFileAction.setImageDescriptor(
        PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE));

    manager.add(newFileAction);
  }
  /** 编辑转换配置XML文件 ; */
  public void editConfigXml() {
    ISelection selection = tableViewer.getSelection();
    if (!selection.isEmpty() && selection != null && selection instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      @SuppressWarnings("unchecked")
      Iterator<String[]> iter = structuredSelection.iterator();
      String convertXml = iter.next()[1];

      AddOrEditXmlConvertConfigDialog dialog =
          new AddOrEditXmlConvertConfigDialog(getShell(), false);
      dialog.create();
      String convertXmlLoaction =
          root.getLocation()
              .append(ADConstants.AD_xmlConverterConfigFolder)
              .append(convertXml)
              .toOSString();
      if (dialog.setInitEditData(convertXmlLoaction)) {
        int result = dialog.open();
        // 如果点击的是确定按钮,那么更新列表
        if (result == IDialogConstants.OK_ID) {
          String curentConvertXMl = dialog.getCurentConverXML();
          refreshTable();
          setTableSelection(curentConvertXMl);
        }
      }
    } else {
      MessageDialog.openInformation(
          getShell(),
          Messages.getString("dialogs.XmlConverterConfigurationDialog.msgTitle"),
          Messages.getString("dialogs.XmlConverterConfigurationDialog.msg2"));
    }
  }
 @Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
   if (!selection.isEmpty()) {
     IStructuredSelection sSelection = (IStructuredSelection) selection;
     boolean confirmed =
         MessageDialog.openConfirm(
             HandlerUtil.getActiveShell(event),
             "Confirm Delete",
             "Please confirm that you wish to delete this metadata.");
     if (!confirmed) return null;
     MetsProjectNature mpn =
         MetsProjectNature.getNatureForMetsObject((EObject) sSelection.getFirstElement());
     HashSet<SmLinkType> del = new HashSet<SmLinkType>();
     Iterator it = sSelection.iterator();
     while (it.hasNext()) {
       Object sel = it.next();
       if (sel instanceof SmLinkType) {
         del.add((SmLinkType) sel);
       }
     }
     Command c =
         RemoveCommand.create(
             mpn.getEditingDomain(),
             mpn.getMets().getStructLink(),
             MetsPackage.eINSTANCE.getStructLinkType_SmLink(),
             del);
     mpn.getCommandStack().execute(c);
   }
   return null;
 }
  private void COMM_COMM_NewClassParticipant(IStructuredSelection selection) {
    // Assign the context selection variables with the action context
    // Assign the context selection variable with the action context
    Object context = selection.iterator().next();
    Communication_c v_comm = (Communication_c) context;
    PersistableModelComponent.ensureCoreDataTypesAvailable(v_comm.getModelRoot());

    TransactionUtil.TransactionGroup transactionGroup =
        TransactionUtil.startTransactionsOnSelectedModelRoots("New Class Participant");
    try {
      // Ensure that actions take place between Verifier Activity executions
      Ooaofooa.beginSaveOperation();
      if (((v_comm != null))) {

        if (v_comm != null) {
          v_comm.Newclassparticipant();
        } else {
          Throwable t = new Throwable();
          t.fillInStackTrace();
          CorePlugin.logError("Attempted to call an operation on a null instance.", t);
        }
      }

      // end critical section
      Ooaofooa.endSaveOperation();
      // catch all exceptions and cancel the transactions
    } catch (Exception e) {
      Ooaofooa.endSaveOperation();
      TransactionUtil.cancelTransactions(transactionGroup, e);
      CorePlugin.logError("Transaction: New Class Participant failed", e); // $NON-NLS-1$
    }
    TransactionUtil.endTransactions(transactionGroup);
  }
  /**
   * Adds a duplicate of the selected VM to the block
   *
   * @since 3.2
   */
  protected void copyVM() {
    IStructuredSelection selection = (IStructuredSelection) fVMList.getSelection();
    Iterator<IVMInstall> it = selection.iterator();

    ArrayList<VMStandin> newEntries = new ArrayList<VMStandin>();
    while (it.hasNext()) {
      IVMInstall selectedVM = it.next();
      // duplicate & add VM
      VMStandin standin = new VMStandin(selectedVM, createUniqueId(selectedVM.getVMInstallType()));
      standin.setName(generateName(selectedVM.getName()));
      EditVMInstallWizard wizard =
          new EditVMInstallWizard(standin, fVMs.toArray(new IVMInstall[fVMs.size()]));
      WizardDialog dialog = new WizardDialog(getShell(), wizard);
      int dialogResult = dialog.open();
      if (dialogResult == Window.OK) {
        VMStandin result = wizard.getResult();
        if (result != null) {
          newEntries.add(result);
        }
      } else if (dialogResult == Window.CANCEL) {
        // Canceling one wizard should cancel all subsequent wizards
        break;
      }
    }
    if (newEntries.size() > 0) {
      fVMs.addAll(newEntries);
      fVMList.refresh();
      fVMList.setSelection(new StructuredSelection(newEntries.toArray()));
    } else {
      fVMList.setSelection(selection);
    }
    fVMList.refresh(true);
  }
  /**
   * Returns true if given structured selection matches the conditions specified in the registry for
   * this action.
   */
  private boolean isEnabledFor(IStructuredSelection ssel) {
    int count = ssel.size();

    if (verifySelectionCount(count) == false) {
      return false;
    }

    // Compare selection to enablement expression.
    if (enablementExpression != null) {
      return enablementExpression.isEnabledFor(ssel);
    }

    // Compare selection to class requirements.
    if (classes.isEmpty()) {
      return true;
    }
    for (Iterator elements = ssel.iterator(); elements.hasNext(); ) {
      Object obj = elements.next();
      if (obj instanceof IAdaptable) {
        IAdaptable element = (IAdaptable) obj;
        if (verifyElement(element) == false) {
          return false;
        }
      } else {
        return false;
      }
    }

    return true;
  }
  /**
   * Action is enabled when only items of the same type are selected.
   *
   * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
   *     org.eclipse.jface.viewers.ISelection)
   */
  public void selectionChanged(IWorkbenchPart part, ISelection input) {
    if (input instanceof IStructuredSelection) {
      IStructuredSelection selection = (IStructuredSelection) input;

      if (selection.size() < 2) {
        setEnabled(false);
        return;
      }

      String kapitel = null;
      for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
        Object o = iter.next();
        if (o instanceof BausteinUmsetzung) {
          BausteinUmsetzung bst = (BausteinUmsetzung) o;
          if (kapitel == null) {
            kapitel = bst.getKapitel();
          } else {
            if (!bst.getKapitel().equals(kapitel)) {
              setEnabled(false);
              return;
            }
          }
        } else {
          setEnabled(false);
          return;
        }
      }
      if (checkRights()) {
        setEnabled(true);
      }
      return;
    }
    // no structured selection:
    setEnabled(false);
  }
  @SuppressWarnings("unchecked")
  private Set<EObject> getTargetsFromSelection(IStructuredSelection iStructuredSelection) {
    Set<EObject> targets = new HashSet<EObject>();
    for (Iterator<Object> iterator = iStructuredSelection.iterator(); iterator.hasNext(); /**/ ) {
      Object element = iterator.next();
      DSemanticDecorator decorator = null;
      if (element instanceof DSemanticDecorator) {
        decorator = (DSemanticDecorator) element;
      } else if (element instanceof IAdaptable) {
        decorator = ((IAdaptable) element).getAdapter(DSemanticDecorator.class);
      }

      if (decorator != null) {
        // If the selection is the representation, we want to select the
        // representation descriptor node and not its semantic element.
        if (decorator instanceof DRepresentation) {
          targets.add(
              new DRepresentationQuery((DRepresentation) decorator).getRepresentationDescriptor());
        } else {
          targets.add(decorator.getTarget());
        }
      }
    }
    return targets;
  }
 public IStructuredSelection getSelection() {
   IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
   ArrayList<Object> externalSelection = new ArrayList<Object>();
   for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
     Object element = iter.next();
     if (element instanceof JavaElement) {
       IJavaElement javaElement = ((JavaElement) element).getJavaElement();
       if (javaElement != null
           && !(javaElement
               instanceof
               IJavaModel)) // various selection listeners assume getJavaProject() is non-null
       externalSelection.add(javaElement);
     } else if (element instanceof JEResource) {
       IResource resource = ((JEResource) element).getResource();
       if (resource != null
           && !(resource
               instanceof
               IWorkspaceRoot)) // various selection listeners assume getProject() is non-null
       externalSelection.add(resource);
     } else if (element instanceof JEAttribute) {
       Object wrappedObject = ((JEAttribute) element).getWrappedObject();
       if (wrappedObject != null) {
         externalSelection.add(wrappedObject);
       }
     }
   }
   return new StructuredSelection(externalSelection);
 }
  public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();
    if (selection instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection = ((IStructuredSelection) selection);
      if (structuredSelection.size() >= 1) {
        List<Object> input = new ArrayList<Object>();
        for (Iterator<?> iter = structuredSelection.iterator(); iter.hasNext(); ) {
          Object item = iter.next();
          if (item instanceof IJavaElement
              || item instanceof IResource
              || item instanceof IJarEntryResource) {
            input.add(item);
          }
        }
        if (input.size() > 0) {
          setInput(input);
          return true;
        }
      }
    }

    Object input = context.getInput();
    if (input instanceof IEditorInput) {
      Object elementOfInput = getElementOfInput((IEditorInput) context.getInput());
      if (elementOfInput != null) {
        setSingleInput(elementOfInput);
        return true;
      }
    }

    return false;
  }
Esempio n. 14
0
  @Override
  public void selectionChanged(IAction action, ISelection selection) {
    super.selectionChanged(action, selection);

    task = null;

    if (selection instanceof IStructuredSelection) {

      IStructuredSelection ss = (IStructuredSelection) selection;

      if (!ss.isEmpty()) {

        Iterator<?> iter = ss.iterator();
        while (iter.hasNext()) {
          Object sel = iter.next();
          if (sel instanceof IJiraTask) {
            task = ((IJiraTask) sel).getTask();
            try {
              taskData = TasksUiPlugin.getTaskDataManager().getTaskData(task);
            } catch (CoreException e) {
              handleError(
                  Messages.JiraConnectorUiActions_Cannot_get_task_data + task.getTaskKey(), e);
            }

            break;
          }
        }
      }
    }

    update(action);
  }
  /**
   * Validates if the drop is valid by validating the local selection transfer to ensure that a
   * watch expression can be created for each contained IVariable.
   *
   * @param target target of the drop
   * @return whether the drop is valid
   */
  private boolean validateVariableDrop(Object target) {
    // Target must be null or an IExpression, you cannot add a new watch expression inside another
    if (target != null && getTargetExpression(target) == null) {
      return false;
    }

    IStructuredSelection selection =
        (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
    int enabled = 0;
    int size = -1;
    if (selection != null) {
      size = selection.size();
      IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager();
      Iterator iterator = selection.iterator();
      while (iterator.hasNext()) {
        Object element = iterator.next();
        if (element instanceof IVariable) {
          IVariable variable = (IVariable) element;
          if (variable instanceof IndexedVariablePartition) {
            break;
          } else if (manager.hasWatchExpressionDelegate(variable.getModelIdentifier())
              && isFactoryEnabled(variable)) {
            enabled++;
          } else {
            break;
          }
        }
      }
    }
    return enabled == size;
  }
  protected IWatchExpression[] getSelectedExpressions() {
    List list = new LinkedList();
    IStructuredSelection currentSelection = getCurrentSelection();
    if (currentSelection == null) {
      return EMPTY_EXPRESSION_ARRAY;
    }

    for (Iterator iter = currentSelection.iterator(); iter.hasNext(); ) {
      Object element = iter.next();
      if (element instanceof IWatchExpression) {
        list.add(element);
      } else if (element instanceof IAdaptable) {
        IWatchExpression expr =
            (IWatchExpression) ((IAdaptable) element).getAdapter(IWatchExpression.class);
        if (expr != null) {
          list.add(expr);
        } else {
          return EMPTY_EXPRESSION_ARRAY;
        }
      } else {
        return EMPTY_EXPRESSION_ARRAY;
      }
    }

    return (IWatchExpression[]) list.toArray(new IWatchExpression[list.size()]);
  }
  /*
   * @see org.eclipse.swt.dnd.DragSourceListener#dragStart
   */
  @Override
  public void dragStart(DragSourceEvent event) {
    fEditorInputDatas = new ArrayList<EditorInputData>();

    ISelection selection = fProvider.getSelection();
    if (selection instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      for (Iterator<?> iter = structuredSelection.iterator(); iter.hasNext(); ) {
        Object element = iter.next();
        IEditorInput editorInput = EditorUtility.getEditorInput(element);
        if (editorInput != null && editorInput.getPersistable() != null) {
          try {
            String editorId = EditorUtility.getEditorID(editorInput);
            // see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..):
            IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
            IEditorDescriptor editorDesc = editorReg.findEditor(editorId);
            if (editorDesc != null && !editorDesc.isOpenExternal()) {
              fEditorInputDatas.add(
                  EditorInputTransfer.createEditorInputData(editorId, editorInput));
            }
          } catch (PartInitException e) {
            JavaPlugin.log(e);
          }
        }
      }
    }

    event.doit = fEditorInputDatas.size() > 0;
  }
    /** @generated */
    protected List getObjectsBeingDropped() {
      TransferData data = getCurrentEvent().currentDataType;
      Collection uris = new HashSet();

      List result = new ArrayList();
      Object transferedObject = getJavaObject(data);
      if (transferedObject instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) transferedObject;
        for (Iterator it = selection.iterator(); it.hasNext(); ) {
          Object nextSelectedObject = it.next();
          if (nextSelectedObject instanceof SqlmodelNavigatorItem) {
            View view = ((SqlmodelNavigatorItem) nextSelectedObject).getView();
            nextSelectedObject = view.getElement();
          } else if (nextSelectedObject instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) nextSelectedObject;
            nextSelectedObject = adaptable.getAdapter(EObject.class);
          }

          if (nextSelectedObject instanceof EObject) {
            EObject modelElement = (EObject) nextSelectedObject;
            Resource modelElementResource = modelElement.eResource();
            uris.add(
                modelElementResource
                    .getURI()
                    .appendFragment(modelElementResource.getURIFragment(modelElement)));
          }

          if (nextSelectedObject instanceof EObject) {
            result.add(nextSelectedObject);
          }
        }
      }
      return result;
    }
Esempio n. 19
0
  public void selectionChanged(IAction action, ISelection selection) {
    ArrayList<IFolder> sFolders = new ArrayList<IFolder>();
    IFolder folder = null;
    if (selection != null && selection instanceof IStructuredSelection) {
      IStructuredSelection ss = (IStructuredSelection) selection;

      for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
        Object obj = iter.next();
        if (obj instanceof IFolder) {
          folder = (IFolder) obj;
        } else if (obj instanceof IAdaptable) {
          IAdaptable a = (IAdaptable) obj;
          IResource res = (IResource) a.getAdapter(IResource.class);
          if (res instanceof IFolder) {
            folder = (IFolder) res;
          }
        }

        if (folder != null && folder.isSynchronized(IResource.DEPTH_ZERO)) {
          sFolders.add(folder);
        } else if (!folder.isSynchronized(IResource.DEPTH_ZERO)) {
          MessageDialog.openInformation(
              shell,
              "Synchronization error",
              "The selected folder is not synchronized with the system file, please refresh the project!");
        }
      }
    }

    if (sFolders.isEmpty()) {
      selectedFolders = null;
    } else {
      selectedFolders = sFolders.toArray(new IFolder[sFolders.size()]);
    }
  }
  public static boolean enableDelete(IStructuredSelection graphicalSelection) {

    boolean enableDel = false;
    List<Object> elements = new ArrayList<Object>();
    IStructuredSelection selection = Selection.getInstance().getStructuredSelection();

    if (!selection.isEmpty()) {
      if (graphicalSelection.getFirstElement() instanceof DiagramEditPart) return false;
      enableDel = true;
      // Iterate through removing elements that are only graphical
      for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
        Object current = iter.next();
        if (current instanceof GraphicalElement_c) {
          GraphicalElement_c ge = (GraphicalElement_c) current;
          if (ge.getRepresents() == null) {
            elements.add(current);
            Selection.getInstance().removeFromSelection(ge);
          }
        }
      }
    }

    selection = Selection.getInstance().getStructuredSelection();
    if (!selection.isEmpty()) {
      // Check the remaining items against the usual DeleteAction,
      enableDel = DeleteAction.canDeleteAction();
    }

    // Add the graphical only elements back to the selection
    for (int i = 0; i < elements.size(); ++i) {
      Selection.getInstance().addToSelection(elements.get(i));
    }

    return enableDel;
  }
Esempio n. 21
0
  /**
   * @param selection
   * @param collector
   */
  private void initSelectedVjoType(
      IStructuredSelection selection, final ModuleCollector collector) {
    for (Iterator i = selection.iterator(); i.hasNext(); ) {
      final Object obj = i.next();

      // Add by Oliver. 2009-06-23. When the selected element is
      // VjoSourceType, we need to get the VjoSourceModel and then handle
      // accept() metheod. BEGIN.
      if (obj instanceof JSSourceType) {
        try {
          ((JSSourceType) obj).getSourceModule().accept(collector);
        } catch (ModelException e) {
          DLTKUIPlugin.log(e);
        }
      }
      // Add by Oliver. 2009-06-23. When the selected element is
      // VjoSourceType, we need to get the VjoSourceModel and then handle
      // accept() metheod. END.

      if (obj instanceof IModelElement) {
        try {
          ((IModelElement) obj).accept(collector);
        } catch (ModelException e) {
          DLTKUIPlugin.log(e);
        }
      }
    }
  }
 /** Refresh the enable/disable state for the buttons. */
 private void updateButtons() {
   IStructuredSelection selection = (IStructuredSelection) fVariablesViewer.getSelection();
   fRemoveButton.setEnabled(!selection.isEmpty());
   boolean enableUp = true, enableDown = true;
   Object[] libraries = fEnvironmentVariablesContentProvider.getElements(null);
   if (selection.isEmpty() || libraries.length == 0) {
     enableUp = false;
     enableDown = false;
   } else {
     Object first = libraries[0];
     Object last = libraries[libraries.length - 1];
     for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
       Object element = iter.next();
       Object lib;
       lib = element;
       if (lib == first) {
         enableUp = false;
       }
       if (lib == last) {
         enableDown = false;
       }
     }
   }
   // fUpButton.setEnabled(enableUp);
   // fDownButton.setEnabled(enableDown);
 }
 /**
  * Determine if a multiple object selection has been passed to the label provider. If the objects
  * is a IStructuredSelection, see if all the objects in the selection are the same and if so, we
  * want to provide labels for the common selected element.
  *
  * @param objects a single object or a IStructuredSelection.
  * @param multiple first element in the array is true if there is multiple unequal selected
  *     elements in a IStructuredSelection.
  * @return the object to get labels for.
  */
 private Object getObject(Object objects, boolean[] multiple) {
   Assert.isNotNull(objects);
   Object object = null;
   if (objects instanceof IStructuredSelection) {
     IStructuredSelection selection = (IStructuredSelection) objects;
     object = selection.getFirstElement();
     if (selection.size() == 1) {
       // one element selected
       multiple[0] = false;
       return object;
     }
     // multiple elements selected
     multiple[0] = true;
     Class firstClass = typeMapper.mapType(object);
     // determine if all the objects in the selection are the same type
     if (selection.size() > 1) {
       for (Iterator i = selection.iterator(); i.hasNext(); ) {
         Object next = i.next();
         Class nextClass = typeMapper.mapType(next);
         if (!nextClass.equals(firstClass)) {
           multiple[0] = false;
           object = null;
           break;
         }
       }
     }
   } else {
     multiple[0] = false;
     object = objects;
   }
   return object;
 }
Esempio n. 24
0
 @SuppressWarnings("unchecked")
 public static boolean checkResourceSet(ISelection selection, boolean guvnorControlled) {
   boolean res = true;
   try {
     if (!(selection instanceof IStructuredSelection)) {
       return false;
     }
     IStructuredSelection sel = (IStructuredSelection) selection;
     for (Iterator<Object> it = sel.iterator(); it.hasNext(); ) {
       Object oneSelection = it.next();
       if (oneSelection instanceof IFile) {
         if (!(((IFile) oneSelection).getName().indexOf(".") > 0)) {
           res = false;
           break;
         }
         GuvnorMetadataProps props = GuvnorMetadataUtils.getGuvnorMetadata((IFile) oneSelection);
         if ((guvnorControlled && props == null) || (!guvnorControlled && props != null)) {
           res = false;
           break;
         }
       }
     }
   } catch (Exception e) {
     Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
     res = false;
   }
   return res;
 }
Esempio n. 25
0
 @Override
 public void run() {
   IStructuredSelection sel = viewer.getListSelection();
   Iterator it = sel.iterator();
   while (it.hasNext()) {
     open((SimpleUserNode) it.next());
   }
 }
Esempio n. 26
0
 private CustomizeData getCustTableSelection() {
   IStructuredSelection selection = (IStructuredSelection) custTable.getViewer().getSelection();
   if (selection.isEmpty()) {
     return null;
   }
   Iterator<?> i = selection.iterator();
   return (CustomizeData) i.next();
 }
 private ISchemaObject[] createObjectRepresentation(IStructuredSelection selection) {
   ArrayList<Object> objects = new ArrayList<>();
   for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
     Object obj = iter.next();
     if (obj instanceof ISchemaObject) objects.add(obj);
     else return new ISchemaObject[0];
   }
   return objects.toArray(new ISchemaObject[objects.size()]);
 }
 private String createTextualRepresentation(IStructuredSelection sel) {
   StringBuffer buf = new StringBuffer();
   for (Iterator<?> iter = sel.iterator(); iter.hasNext(); ) {
     String name = iter.next().toString();
     buf.append(name);
     buf.append(" "); // $NON-NLS-1$
   }
   return buf.toString();
 }
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());
    final List<IProject> projects;
    if (selection instanceof IStructuredSelection) {
      final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      projects = new ArrayList<>(structuredSelection.size());
      for (final Iterator<?> iter = structuredSelection.iterator(); iter.hasNext(); ) {
        final Object obj = iter.next();
        if (obj instanceof IAdaptable) {
          final IProject project = (IProject) ((IAdaptable) obj).getAdapter(IProject.class);
          if (project != null) {
            projects.add(project);
          }
        }
      }
    } else {
      return null;
    }

    final WorkspaceModifyOperation op =
        new WorkspaceModifyOperation() {

          @Override
          protected void execute(final IProgressMonitor monitor)
              throws CoreException, InvocationTargetException, InterruptedException {
            final SubMonitor m =
                SubMonitor.convert(monitor, TexUIMessages.TexProject_ConvertTask_label, 100);
            try {
              final SubMonitor mProjects = m.newChild(100).setWorkRemaining(projects.size());
              for (final IProject project : projects) {
                if (m.isCanceled()) {
                  throw new InterruptedException();
                }
                TexProjects.setupTexProject(project, mProjects.newChild(1));
              }
            } finally {
              m.done();
            }
          }
        };
    try {
      UIAccess.getActiveWorkbenchWindow(true).run(true, true, op);
    } catch (final InvocationTargetException e) {
      StatusManager.getManager()
          .handle(
              new Status(
                  IStatus.ERROR,
                  TexUI.PLUGIN_ID,
                  TexUIMessages.TexProject_ConvertTask_error_message,
                  e.getTargetException()));
    } catch (final InterruptedException e) {
      // cancelled
    }

    return null;
  }
  /**
   * The framework calls this to create the contents of the wizard.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  @Override
  public void addPages() {
    // Create a page, set the title, and the initial model file name.
    //
    newFileCreationPage = new RecordModelWizardNewFileCreationPage("Whatever", selection);
    newFileCreationPage.setTitle(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordModelWizard_label"));
    newFileCreationPage.setDescription(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordModelWizard_description"));
    newFileCreationPage.setFileName(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordEditorFilenameDefaultBase")
            + "."
            + Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordEditorFilenameExtension"));
    addPage(newFileCreationPage);

    // Try and get the resource selection to determine a current directory for the file dialog.
    //
    if (selection != null && !selection.isEmpty()) {
      // Get the resource...
      //
      Object selectedElement = selection.iterator().next();
      if (selectedElement instanceof IResource) {
        // Get the resource parent, if its a file.
        //
        IResource selectedResource = (IResource) selectedElement;
        if (selectedResource.getType() == IResource.FILE) {
          selectedResource = selectedResource.getParent();
        }

        // This gives us a directory...
        //
        if (selectedResource instanceof IFolder || selectedResource instanceof IProject) {
          // Set this for the container.
          //
          newFileCreationPage.setContainerFullPath(selectedResource.getFullPath());

          // Make up a unique new name here.
          //
          String defaultModelBaseFilename =
              Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordEditorFilenameDefaultBase");
          String defaultModelFilenameExtension =
              Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordEditorFilenameExtension");
          String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension;
          for (int i = 1; ((IContainer) selectedResource).findMember(modelFilename) != null; ++i) {
            modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension;
          }
          newFileCreationPage.setFileName(modelFilename);
        }
      }
    }
    initialObjectCreationPage = new RecordModelWizardInitialObjectCreationPage("Whatever2");
    initialObjectCreationPage.setTitle(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_RecordModelWizard_label"));
    initialObjectCreationPage.setDescription(
        Cwm_mipEditorPlugin.INSTANCE.getString("_UI_Wizard_initial_object_description"));
    addPage(initialObjectCreationPage);
  }