private GradleProject getContext() {
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    IWorkbenchPage page = win == null ? null : win.getActivePage();

    if (page != null) {
      ISelection selection = page.getSelection();
      if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        if (!ss.isEmpty()) {
          Object obj = ss.getFirstElement();
          if (obj instanceof IResource) {
            IResource rsrc = (IResource) obj;
            IProject prj = rsrc.getProject();
            if (prj != null) {
              return GradleCore.create(prj);
            }
          }
        }
      }
      IEditorPart part = page.getActiveEditor();
      if (part != null) {
        IEditorInput input = part.getEditorInput();
        IResource rsrc = (IResource) input.getAdapter(IResource.class);
        if (rsrc != null) {
          IProject prj = rsrc.getProject();
          if (prj != null) {
            return GradleCore.create(prj);
          }
        }
      }
    }
    return null;
  }
  private void edit(IStructuredSelection selection) {
    IStructuredSelection sel = (IStructuredSelection) selection;
    EnvironmentVariable var = (EnvironmentVariable) sel.getFirstElement();
    if (var == null) {
      return;
    }
    String originalName = var.getName();
    String value = var.getValue();
    MultipleInputDialog dialog =
        new MultipleInputDialog(
            fDialog.getShell(),
            InterpretersMessages.AbstractInterpreterEnvironmentVariablesBlock_editVariable);
    dialog.addTextField(NAME_LABEL, originalName, false);
    dialog.addVariablesField(VALUE_LABEL, value, true);

    if (dialog.open() != Window.OK) {
      return;
    }
    String name = dialog.getStringValue(NAME_LABEL);
    value = dialog.getStringValue(VALUE_LABEL);
    if (!originalName.equals(name)) {
      fEnvironmentVariablesContentProvider.add(
          new EnvironmentVariable[] {new EnvironmentVariable(name, value)}, selection);
    } else {
      var.setValue(value);
      fVariablesViewer.refresh(true);
    }
  }
  private List<EObject> getSelfContainedModelElementTree(ExecutionEvent event) {
    List<EObject> result = new ArrayList<EObject>();

    ISelection selection = HandlerUtil.getCurrentSelection(event);
    IStructuredSelection strucSel = null;
    EObject copyModelElement = null;

    if (selection != null && selection instanceof IStructuredSelection) {
      strucSel = (IStructuredSelection) selection;
      Object firstElement = strucSel.getFirstElement();
      if (firstElement instanceof EObject) {
        // TODO: ChainSaw - check whether specific clone functionality of ModelUtil is needed here
        copyModelElement = EcoreUtil.copy((EObject) firstElement);
        // copyModelElement = ModelUtil.clone((EObject) firstElement);

        // only export the rootnode makes xml with references, otherwise (see (commented) line two)
        // the children
        // will be "real" nested as containments of the node (is not necessary)
        result.add(copyModelElement);
        // result.addAll(copyModelElement.getAllContainedModelElements());

      } else {
        // do nothing System.out.println("NOT A MODELELEMENT");
      }
    }

    return result;
  }
  private static void buildTextQueryPart(
      Query query, Map<IQueryField, ComboViewer> operators, Map<IQueryField, Text> values) {
    for (Entry<IQueryField, Text> entry : values.entrySet()) {
      IQueryField queryField = entry.getKey();
      Text text = entry.getValue();
      ComboViewer opCombo = operators.get(queryField);

      IStructuredSelection selection = (IStructuredSelection) opCombo.getSelection();
      if (selection.getFirstElement() instanceof CompareOperator) {
        CompareOperator operator = (CompareOperator) selection.getFirstElement();
        if (queryField instanceof CustomField) {
          CustomField customField = (CustomField) queryField;
          if (customField.getFieldFormat() == CustomField.Format.BOOL) {
            query.addFilter(
                customField,
                QueryField.BOOLEAN_TYPE,
                operator,
                IRedmineConstants.BOOLEAN_TRUE_SUBMIT_VALUE);
          } else {
            QueryField definition = customField.getQueryField();
            query.addFilter(customField, definition, operator, text.getText().trim());
          }
        } else {
          query.addFilter((QueryField) queryField, operator, text.getText().trim());
        }
      }
    }
  }
  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;
  }
 /**
  * Since these actions are re-created each time the run/debug as menu is filled, the enablement of
  * this action is static.
  */
 private void updateEnablement() {
   IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
   boolean enabled = false;
   if (wb != null) {
     IWorkbenchPage page = wb.getActivePage();
     if (page != null) {
       ISelection selection = page.getSelection();
       if (selection instanceof IStructuredSelection) {
         IStructuredSelection structuredSelection = (IStructuredSelection) selection;
         try {
           // check enablement logic, if any
           Expression expression = fShortcut.getShortcutEnablementExpression();
           if (expression == null) {
             enabled = !structuredSelection.isEmpty();
           } else {
             List list = structuredSelection.toList();
             IEvaluationContext context = new EvaluationContext(null, list);
             context.addVariable("selection", list); // $NON-NLS-1$
             enabled = fShortcut.evalEnablementExpression(context, expression);
           }
         } catch (CoreException e) {
         }
       } else {
         IEditorPart editor = page.getActiveEditor();
         if (editor != null) {
           enabled = true;
         }
       }
     }
   }
   setEnabled(enabled);
 }
  protected void createNewFileFromTemplate(final TemplateElement template) {
    IStructuredSelection selection = getActiveSelection();
    if (!selection.isEmpty()) {
      Object element = selection.getFirstElement();
      if (element instanceof IAdaptable) {
        IFileStore fileStore = (IFileStore) ((IAdaptable) element).getAdapter(IFileStore.class);
        if (fileStore != null) {
          // this is a non-workspace selection
          String filetype = template.getFiletype();
          // strips the leading * before . if there is one
          int index = filetype.lastIndexOf('.');
          if (index > -1) {
            filetype = filetype.substring(index);
          }
          NewFileAction action = new NewFileAction("new_file" + filetype, template); // $NON-NLS-1$
          action.updateSelection(selection);
          action.run();
          return;
        }
      }
    }

    NewTemplateFileWizard wizard = new NewTemplateFileWizard(template);
    wizard.init(PlatformUI.getWorkbench(), selection);
    WizardDialog dialog = new WizardDialog(UIUtils.getActiveShell(), wizard);
    dialog.open();
  }
  /**
   * 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);
  }
  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);
  }
 @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;
 }
 /* (non-Javadoc)
  * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
  */
 public void debugContextChanged(DebugContextEvent event) {
   if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
     IWorkbenchPart part = event.getDebugContextProvider().getPart();
     if (part != null) {
       IWorkbenchPage page = part.getSite().getPage();
       ISelection selection = event.getContext();
       if (selection instanceof IStructuredSelection) {
         IStructuredSelection ss = (IStructuredSelection) selection;
         if (ss.size() == 1) {
           Object element = ss.getFirstElement();
           if (element instanceof IAdaptable) {
             IJavaScriptStackFrame frame =
                 (IJavaScriptStackFrame)
                     ((IAdaptable) element).getAdapter(IJavaScriptStackFrame.class);
             if (frame != null) {
               setContext(page, frame);
               return;
             }
           }
         }
       }
       // no context in the given view
       removeContext(page);
     }
   }
 }
 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;
  }
Beispiel #15
0
        @Override
        public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
          if (ViewPicture.this.listenToSelectionListener
              && part instanceof IMixedMediaItemDbEditor) {
            if (selection == null || selection.isEmpty()) {
              return;
            }

            IMixedMediaItemDbEditor editor = (IMixedMediaItemDbEditor) part;
            IMediaItemDb<?, ? extends IMediaPicture> list = editor.getMediaList();

            if (selection instanceof IStructuredSelection) {
              IStructuredSelection iSel = (IStructuredSelection) selection;
              ArrayList<IMediaPicture> sel = new ArrayList<IMediaPicture>();
              for (Object selectedObject : iSel.toList()) {
                if (selectedObject != null) {
                  if (selectedObject instanceof IMediaPicture) {
                    IMediaPicture track = (IMediaPicture) selectedObject;
                    sel.add(track);
                  }
                }
              }

              setInput(list, sel);
            }
          }
        }
 protected Object getSelection() {
   IStructuredSelection selection = (IStructuredSelection) transfer.getSelection();
   if (selection != null) {
     return selection.getFirstElement();
   }
   return null;
 }
 private boolean isOneFeatureSelected(IStructuredSelection selection) {
   return selection.size() == 1
       && (selection.getFirstElement() instanceof FeatureEditPart
           || selection.getFirstElement() instanceof ConnectionEditPart
           || selection.getFirstElement() instanceof FmOutlineGroupStateStorage
           || selection.getFirstElement() instanceof IFeature);
 }
Beispiel #18
0
  private Collection<Artifact> getSelectedArtifacts() {
    IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();

    Object[] objects = selection.toArray();
    if (objects.length == 0) {
      return Collections.emptyList();
    }

    AbstractArtifactSearchResult resultInput = getInput();
    if (resultInput == null) {
      return Collections.emptyList();
    }

    Set<Artifact> artifacts = new LinkedHashSet<>();
    for (Object object : objects) {
      Artifact toAdd = null;
      if (object instanceof AttributeLineElement) {
        toAdd = (Artifact) ((IAdaptable) object).getAdapter(Artifact.class);
        artifacts.add(toAdd);
      } else if (object instanceof IAdaptable) {
        toAdd = (Artifact) ((IAdaptable) object).getAdapter(Artifact.class);
      } else if (object instanceof Match) {
        toAdd = (Artifact) ((Match) object).getElement();
      }
      if (toAdd != null) {
        artifacts.add(toAdd);
      }
    }
    return artifacts;
  }
    /** @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;
    }
  /**
   * 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;
  }
  /** Constructor for JCPWizard. */
  public DownloadSpectraWizard(IWorkbenchPart view) {
    super();
    setNeedsProgressMonitor(true);
    this.view = view;
    ISelection sel =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
    if (sel.isEmpty() == false) {
      if (sel instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) sel;
        try {
          IFile cdkres = (IFile) ssel.getFirstElement();
          Activator.getDefault()
              .getJavaCDKManager()
              .loadMolecule(
                  cdkres,
                  new BioclipseUIJob<ICDKMolecule>() {

                    @Override
                    public void runInUI() {
                      ac = getReturnValue().getAtomContainer();
                    }
                  });
        } catch (Exception e) {
          throw new RuntimeException(e.getMessage());
        }
      }
    }
  }
Beispiel #22
0
  /* (non-Javadoc)
   * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    // clear console
    Console.getInstance().clear();

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
      Activator.getDefault().testsStarted();

      // get the selections in the Project explorer
      IStructuredSelection selection =
          (IStructuredSelection)
              window.getSelectionService().getSelection("org.eclipse.ui.navigator.ProjectExplorer");
      final Object[] selectedElements = selection.toArray();

      BusyIndicator.showWhile(
          null,
          new Runnable() {
            @Override
            public void run() {
              // go through each open selected project
              for (int index = 0; index < selectedElements.length; index++) {
                Object element = selectedElements[index];
                log.debug("Calling runTestsObject on " + selectedElements[index]);
                runTestsObject(element);
              }
            }
          });
    }
    return null;
  }
 @Override
 public void fillContextMenu(IMenuManager aMenu) {
   IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
   if (selection.size() != 1) {
     return;
   }
   Object object = selection.getFirstElement();
   IFolder folder = Adapters.adapt(object, IFolder.class);
   if (folder == null) {
     return;
   }
   if (folder.getFile(IProjectDescription.DESCRIPTION_FILE_NAME).exists()) {
     for (IProject project : folder.getWorkspace().getRoot().getProjects()) {
       if (project.getLocation().equals(folder.getLocation())) {
         // project already in workspace
         SelectProjectForFolderAction action =
             new SelectProjectForFolderAction(project, this.viewer);
         aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, action);
         return;
       }
     }
     OpenFolderAsProjectAction action = new OpenFolderAsProjectAction(folder, this.viewer);
     aMenu.prependToGroup(ICommonMenuConstants.GROUP_PORT, action);
   }
 }
  @Override
  public void doRun(
      IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) {

    instrumentation.metric("command", command);

    if (!selection.isEmpty() && selection.getFirstElement() instanceof IResource) {
      Object object = selection.getFirstElement();
      if (object instanceof IFile) {
        object = ((IFile) object).getParent();
      }
      while (object != null
          && ((IContainer) object).findMember(DartCore.PUBSPEC_FILE_NAME) == null) {
        object = ((IContainer) object).getParent();
      }
      if (object instanceof IContainer) {
        IContainer container = (IContainer) object;
        instrumentation.data("name", container.getName());
        savePubspecFile(container);
        runPubJob(container);
        return;
      } else {
        instrumentation.metric("Problem", "Object was null").log();
      }
    }

    instrumentation.metric("Problem", "pubspec.yaml file not selected, showing dialog");

    MessageDialog.openError(
        getShell(), ActionMessages.RunPubAction_fail, ActionMessages.RunPubAction_fileNotFound);

    instrumentation.log();
  }
  protected void okPressed() {
    boolean hasErrors = popupValidationErrorDialogIfNecessary();

    if (!hasErrors) {
      try {
        conceptUtil.setId(wId.getText());
      } catch (ObjectAlreadyExistsException e) {
        if (logger.isErrorEnabled()) {
          logger.error("an exception occurred", e);
        }
        MessageDialog.openError(
            getShell(),
            Messages.getString("General.USER_TITLE_ERROR"),
            Messages.getString(
                "PhysicalTableDialog.USER_ERROR_PHYSICAL_TABLE_ID_EXISTS", wId.getText()));
        return;
      }

      // attempt to set the connection
      IStructuredSelection selection = (IStructuredSelection) comboViewer.getSelection();
      DatabaseMeta con = (DatabaseMeta) selection.getFirstElement();
      BusinessModel busModel = (BusinessModel) conceptUtil;
      if (!DUMMY_CON_NAME.equals(con.getName())) {
        busModel.setConnection((DatabaseMeta) con);
      } else {
        busModel.clearConnection();
      }

      super.okPressed();
    }
  }
  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()]);
    }
  }
 /** 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);
 }
  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;
  }
  /** 编辑转换配置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"));
    }
  }
 private void addOpenWithMenu(IMenuManager menu) {
   ISelection selection = getContext().getSelection();
   if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) return;
   IStructuredSelection ss = (IStructuredSelection) selection;
   if (ss.size() != 1) return;
   Object o = ss.getFirstElement();
   if (!(o instanceof IAdaptable)) return;
   IAdaptable element = (IAdaptable) o;
   Object resource = element.getAdapter(IResource.class);
   if (element instanceof IStorage && !(resource instanceof IFile)) {
     // Create a menu.
     IMenuManager submenu = new MenuManager(ActionMessages.OpenWithMenu_label);
     submenu.add(new OpenStorageWithMenu(fSite.getPage(), element));
     // Add the submenu.
     menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
   } else if ((element instanceof IModelElement)
       || (element.getAdapter(IModelElement.class) != null)) {
     // Create a menu.
     IMenuManager submenu = new MenuManager(ActionMessages.OpenWithMenu_label);
     submenu.add(
         new OpenModelElementWithMenu(
             fSite.getPage(), (IModelElement) element.getAdapter(IModelElement.class)));
     // Add the submenu.
     menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
   } else if ((resource instanceof IFile)) {
     // Create a menu.
     IMenuManager submenu = new MenuManager(ActionMessages.OpenWithMenu_label);
     submenu.add(new OpenWithMenu(fSite.getPage(), (IFile) resource));
     // Add the submenu.
     menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
   }
 }