예제 #1
0
파일: NewVersion.java 프로젝트: rraaff/wtf
 /** @see ActionDelegate#run(IAction) */
 public void run(IAction action) {
   if (this.selection instanceof StructuredSelection) {
     StructuredSelection selection = (StructuredSelection) this.selection;
     if (!selection.isEmpty()) {
       IWorkbench workbench = PlatformUI.getWorkbench();
       Shell shell = workbench.getActiveWorkbenchWindow().getShell();
       IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
       InputDialog inputDialog =
           new InputDialog(
               Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell(),
               "Ingreso de version",
               "Ingrese la version a generar",
               "",
               null);
       int manual = inputDialog.open();
       if (manual == 0) {
         String value = inputDialog.getValue();
         IFolder folder = (IFolder) selection.getFirstElement();
         try {
           IFolder folder1 = folder.getFolder(new Path(value));
           folder1.create(true, false, new NullProgressMonitor());
           IFile file = folder1.getFile(new Path("000_db_version_insert.sql"));
           file.create(
               new ByteArrayInputStream(VERSION_SCRIPT.replace("DBVERSION", value).getBytes()),
               true,
               new NullProgressMonitor());
         } catch (CoreException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       }
     }
   }
 }
예제 #2
0
 /** Test the receiver against the selected property */
 @Override
 public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
   // Ensure Papyrus is the active editor
   IEditorPart editor =
       PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
   if ((editor == null) || (!(editor instanceof IMultiDiagramEditor))) {
     return false;
   }
   Object currentValue = null;
   if (IS_CALL_ACTION.equals(property)) {
     if (receiver instanceof StructuredSelection) {
       StructuredSelection structuredSelection = (StructuredSelection) receiver;
       Object obj = structuredSelection.getFirstElement();
       EObject element = null;
       if (obj instanceof IAdaptable) {
         element = (EObject) ((IAdaptable) obj).getAdapter(EObject.class);
         if (element instanceof View) {
           element = ((View) element).getElement();
         }
       }
       currentValue = element instanceof InvocationAction;
     }
     return (currentValue == expectedValue);
   }
   return false;
 }
  @Override
  public void fillContextMenu(IMenuManager menu) {
    boolean onlyEnvironmentsSelected = true;
    StructuredSelection selection =
        (StructuredSelection) getActionSite().getStructuredViewer().getSelection();
    Iterator iterator = selection.iterator();
    List<EnvironmentDescription> environments = new ArrayList<EnvironmentDescription>();
    while (iterator.hasNext()) {
      Object obj = iterator.next();
      if (obj instanceof EnvironmentDescription) {
        environments.add((EnvironmentDescription) obj);
      } else {
        onlyEnvironmentsSelected = false;
      }
    }

    if (onlyEnvironmentsSelected) {
      if (environments.size() == 1) {
        menu.add(new OpenEnvironmentEditorAction(environments.get(0)));
        menu.add(new Separator());
      }

      menu.add(new TerminateEnvironmentsAction(environments));
    }
  }
예제 #4
0
 /**
  * @return the {@link #getViewerWidget()} current selections first element or <code>null</code>
  * @since 3.2.0
  */
 public Object getViewerWidgetFirstSelection() {
   StructuredSelection selection = (StructuredSelection) viewer.getSelection();
   if (selection == null || selection.size() == 0) {
     return null;
   }
   return selection.getFirstElement();
 }
예제 #5
0
  public void testModelChanged(TestModelChange change) {
    switch (change.getKind()) {
      case TestModelChange.INSERT:
        doInsert(change);
        break;
      case TestModelChange.REMOVE:
        doRemove(change);
        break;
      case TestModelChange.STRUCTURE_CHANGE:
        doStructureChange(change);
        break;
      case TestModelChange.NON_STRUCTURE_CHANGE:
        doNonStructureChange(change);
        break;
      default:
        throw new IllegalArgumentException("Unknown kind of change");
    }

    StructuredSelection selection = new StructuredSelection(change.getChildren());
    if ((change.getModifiers() & TestModelChange.SELECT) != 0) {
      ((StructuredViewer) fViewer).setSelection(selection);
    }
    if ((change.getModifiers() & TestModelChange.REVEAL) != 0) {
      Object element = selection.getFirstElement();
      if (element != null) {
        ((StructuredViewer) fViewer).reveal(element);
      }
    }
  }
  private IModelNode getFirstElementInSelection() {
    StructuredSelection currentSelection = (StructuredSelection) getSelection();
    if (currentSelection == null || currentSelection.isEmpty()) {
      return null;
    }

    return (IModelNode) currentSelection.getFirstElement();
  }
예제 #7
0
  private void processSelection(ExecutionEvent event) {

    this.desProject = null;

    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection instanceof StructuredSelection) {

      StructuredSelection ss = (StructuredSelection) selection;

      IProject project = null;

      List<?> list = ss.toList();

      // Check to determine first project
      for (Object o : list) {

        if (o instanceof IFile) {

          IFile file = (IFile) o;

          if (project == null) {
            project = file.getProject();
          }
        }
      }

      // if we found the project, assign the this.desProject
      if (project != null) {

        if (DominoResourcesPlugin.isDominoDesignerProject(project)) {
          try {
            this.desProject = DominoResourcesPlugin.getDominoDesignerProject(project);
          } catch (NsfException e) {
            SwiperUtil.logError(e.getMessage());
          }
        }

      } else {
        // If we can't figure out the project then it is no good
        return;
      }

      // Add files that belong to that project
      for (Object o : list) {

        if (o instanceof IFile) {

          IFile file = (IFile) o;

          if (file.getProject() == project) {
            filesTofilter.add(file);
          }
        }
      }
    }
  }
예제 #8
0
 @Override
 public boolean test() throws Exception {
   StructuredSelection eventsTableSelection = getEventsTableSelection();
   if (eventsTableSelection.isEmpty()) {
     return false;
   }
   fCurValue = ((ITmfEvent) eventsTableSelection.getFirstElement()).getTimestamp().getValue();
   return fCurValue == fSelectionTime;
 }
  private File extractAbsolutePathFromSelection(StructuredSelection selection) {
    File result = null;

    if (selection.getFirstElement() instanceof IFile) {
      IFile commandFile = (IFile) selection.getFirstElement();
      result = new File(commandFile.getLocation().toOSString());
    }

    return result;
  }
 @Override
 public void doubleClick(final DoubleClickEvent event) {
   final Playlist playlist = player.getPlaylist();
   if (!playlist.isEmpty()) {
     final StructuredSelection selection = (StructuredSelection) event.getSelection();
     playlist.setCurrentTrack((PlaylistItem) selection.getFirstElement());
     player.play();
     event.getViewer().refresh();
   }
 }
  /** {@inheritDoc} */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    StructuredSelection selection =
        (StructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
    AbstractRootEditor rootEditor = (AbstractRootEditor) HandlerUtil.getActiveEditor(event);
    RepositoryDefinition repositoryDefinition =
        rootEditor.getInputDefinition().getRepositoryDefinition();

    Object selectedObject = selection.getFirstElement();
    ExceptionSensorData dataToNavigateTo = null;
    if (selectedObject instanceof ExceptionSensorData) {
      dataToNavigateTo = (ExceptionSensorData) selectedObject;
    } else if (selectedObject instanceof InvocationSequenceData) {
      List<ExceptionSensorData> exceptions =
          ((InvocationSequenceData) selectedObject).getExceptionSensorDataObjects();
      if ((null != exceptions) && !exceptions.isEmpty()) {
        for (ExceptionSensorData exSensorData : exceptions) {
          if (0 != exSensorData.getMethodIdent()) {
            dataToNavigateTo = exSensorData;
            break;
          }
        }
      }
    }

    if (null != dataToNavigateTo) {
      ExceptionSensorData exceptionSensorData = dataToNavigateTo;

      // exit if the object does not carry the methodIdent
      if (null == exceptionSensorData.getThrowableType()) {
        return null;
      }

      InputDefinition inputDefinition =
          getInputDefinition(repositoryDefinition, exceptionSensorData);

      // open the view via command
      IHandlerService handlerService =
          (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
      ICommandService commandService =
          (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);

      Command command = commandService.getCommand(OpenViewHandler.COMMAND);
      ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, new Event());
      IEvaluationContext context = (IEvaluationContext) executionEvent.getApplicationContext();
      context.addVariable(OpenViewHandler.INPUT, inputDefinition);

      try {
        command.executeWithChecks(executionEvent);
      } catch (NotDefinedException | NotEnabledException | NotHandledException e) {
        throw new ExecutionException("Error opening the exception type view.", e);
      }
    }
    return null;
  }
 private boolean checkAllElements(ISelection selection, Class className) {
   if (selection instanceof StructuredSelection) {
     StructuredSelection ss = (StructuredSelection) selection;
     for (Object o : ss.toList()) {
       if (!o.getClass().equals(className)) {
         return false;
       }
     }
   }
   return true;
 }
 public void setTreeSelection(ISelection s) {
   if (s != null && s instanceof StructuredSelection && outline instanceof Tree) {
     StructuredSelection sel = (StructuredSelection) s;
     List<?> sobj = sel.toList();
     List<TreeItem> toSelect = new ArrayList<TreeItem>();
     Tree tree = (Tree) outline;
     tree.getItemCount();
     checkItems(tree.getItems(), toSelect, sobj);
     if (!toSelect.isEmpty()) tree.setSelection(toSelect.toArray(new TreeItem[toSelect.size()]));
   } else setSelection(s);
 }
 @SuppressWarnings("unchecked")
 private void openKontaktDialog() {
   final StructuredSelection selection = (StructuredSelection) kontakteTableViewer.getSelection();
   if (!selection.isEmpty()) {
     Iterator<KontaktEntry> iterator = selection.iterator();
     while (iterator.hasNext()) {
       final KontaktEntry selectedKontakt = iterator.next();
       searchForm.openKontaktDialog(selectedKontakt);
     }
   }
 }
 /* (non-Javadoc)
  * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#appliesTo(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
  */
 public boolean appliesTo(IWorkbenchPart part, ISelection selection) {
   Object object = null;
   if (selection instanceof StructuredSelection) {
     StructuredSelection structuredSelection = (StructuredSelection) selection;
     object = structuredSelection.getFirstElement();
     if (object instanceof XSDConcreteComponent || object instanceof Element) {
       return true;
     }
   }
   return false;
 }
 protected void buttonPressed(int buttonId) {
   if (buttonId == IDialogConstants.OK_ID) {
     StructuredSelection sel = (StructuredSelection) listViewer.getSelection();
     Object[] objs = sel.toArray();
     selectedSkills = new int[objs.length];
     for (int i = 0; i < objs.length; i++) {
       selectedSkills[i] = ((SkillConfig) objs[i]).id;
     }
   }
   super.buttonPressed(buttonId);
 }
예제 #17
0
  /**
   * Get a {@link ITeiidServer} from the given selection if one can be adapted
   *
   * @param selection
   * @return server or null
   */
  public static ITeiidServer getServerFromSelection(ISelection selection) {
    if (selection == null || !(selection instanceof StructuredSelection)) return null;

    if (selection.isEmpty()) {
      return null;
    }

    StructuredSelection ss = (StructuredSelection) selection;
    Object element = ss.getFirstElement();

    return adapt(element, ITeiidServer.class);
  }
 public void toggleExpandState(int state, StructuredSelection selection) {
   TreeItem[] items = fExtensionTree.getTree().getSelection();
   if (state == NEEDS_EXPAND) { // expand sub tree
     traverseChildrenAndSetExpanded(items); // load non-expanded children
     fExtensionTree.refresh();
     expandChildrenElements(selection.toArray(), true);
     fExtensionTree.setSelection(selection, false);
   } else { // collapse sub tree
     for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
       fExtensionTree.setExpandedState(iterator.next(), false);
     }
   }
 }
 /** @generated */
 public void setInput(IWorkbenchPart part, ISelection selection) {
   if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
     super.setInput(part, selection);
     return;
   }
   final StructuredSelection structuredSelection = ((StructuredSelection) selection);
   ArrayList transformedSelection = new ArrayList(structuredSelection.size());
   for (Iterator it = structuredSelection.iterator(); it.hasNext(); ) {
     Object r = transformSelection(it.next());
     if (r != null) {
       transformedSelection.add(r);
     }
   }
   super.setInput(part, new StructuredSelection(transformedSelection));
 }
예제 #20
0
 @SuppressWarnings("unchecked")
 protected void removePerson() {
   StructuredSelection selection = (StructuredSelection) viewer.getSelection();
   if (selection != null && !selection.isEmpty()) {
     for (Iterator<PersonInfo> iterator = selection.iterator(); iterator.hasNext(); ) {
       PersonInfo permission = iterator.next();
       this.personSet.remove(permission);
     }
     try {
       refreshTable();
     } catch (Throwable t) {
       log.error("Error while setting table data", t); // $NON-NLS-1$
     }
   }
 }
 /**
  * @param selection
  * @return first element of the selection
  */
 public static Object getFirstSelectedElement(ISelection selection) {
   if (selection instanceof TreeSelection) {
     TreeSelection treeSelection = (TreeSelection) selection;
     return treeSelection.getFirstElement();
   } else if (selection instanceof StructuredSelection) {
     StructuredSelection structuredSelection = (StructuredSelection) selection;
     return structuredSelection.getFirstElement();
   } else if (selection instanceof IFileEditorInput) {
     IFileEditorInput editorInput = (FileEditorInput) selection;
     return editorInput.getFile();
   } else if (selection instanceof TextSelection) {
     return null;
   } else {
     throw new RuntimeException(Messages.GeneratorUtils_SelectionNotSupported);
   }
 }
예제 #22
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 public void setInput(final IWorkbenchPart part, final ISelection selection) {
   if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
     super.setInput(part, selection);
     return;
   }
   final StructuredSelection structuredSelection = ((StructuredSelection) selection);
   final ArrayList transformedSelection = new ArrayList(structuredSelection.size());
   for (final Iterator it = structuredSelection.iterator(); it.hasNext(); ) {
     final Object r = transformSelection(it.next());
     if (r != null) {
       transformedSelection.add(r);
     }
   }
   super.setInput(part, new StructuredSelection(transformedSelection));
 }
예제 #23
0
  /** Displays the appropriate UI for the current model state. */
  void displayElementSymbol() {
    CoreArgCheck.isNotNull(viewer);

    StructuredSelection selection = StructuredSelection.EMPTY;

    if (model.getElementSymbol() != null) {
      strategy.setTreeViewer(viewer); // make sure this viewer is set before using strategy
      Object node = strategy.getNode(model.getElementSymbol());

      if (node != null) {
        selection = new StructuredSelection(node);
      }

      if (!selection.equals(viewer.getSelection())) {
        viewer.setSelection(selection);
      }
    }
  }
예제 #24
0
 @Override
 public void setSelection(ISelection selection) {
   if (selection instanceof StructuredSelection) {
     StructuredSelection sel = (StructuredSelection) selection;
     if (sel.isEmpty()) productTypeGUIList.setSelection(-1);
     else {
       ProductType spi = (ProductType) sel.getFirstElement();
       int idx = 0;
       for (Iterator it = productTypeItemList.iterator(); it.hasNext(); ++idx) {
         ProductType pi = (ProductType) it.next();
         if (spi.getPrimaryKey().equals(pi.getPrimaryKey())) {
           productTypeGUIList.setSelection(idx);
           break;
         }
       }
     }
   }
 }
 public Object execute(ExecutionEvent event) throws ExecutionException {
   StructuredSelection mainViewSelection =
       (StructuredSelection)
           PlatformUI.getWorkbench()
               .getActiveWorkbenchWindow()
               .getSelectionService()
               .getSelection("de.berlios.quotations.ui.MainView");
   if (!mainViewSelection.isEmpty()) {
     Quotation quotation = (Quotation) mainViewSelection.getFirstElement();
     if (quotation.getId() != null) {
       if (MessageBoxes.question(Messages.getString("DeleteRecordAction.Question"))
           == SWT.YES) { //$NON-NLS-1$
         Activator.getDB().deleteById(quotation.getId());
         Activator.refresh();
       }
     }
   }
   return null;
 }
 @Override
 public void init(ICommonActionExtensionSite site) {
   if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) {
     StructuredSelection selection =
         (StructuredSelection) site.getStructuredViewer().getSelection();
     Object fe = selection.getFirstElement();
     if (fe instanceof IRepositoryNode) {
       IRepositoryViewObject object = ((IRepositoryNode) fe).getObject();
       if (object instanceof TdTableRepositoryObject) {
         TdTableRepositoryObject tableObject = (TdTableRepositoryObject) object;
         modelElement = tableObject.getTdTable();
       } else if (object instanceof TdViewRepositoryObject) {
         TdViewRepositoryObject viewObject = (TdViewRepositoryObject) object;
         modelElement = viewObject.getTdView();
       }
     }
   }
   super.init(site);
 }
예제 #27
0
  /** @see IActionDelegate#selectionChanged(IAction, ISelection) */
  public void selectionChanged(IAction action, ISelection selection) {

    if (selection instanceof StructuredSelection) {
      currentSelection = (StructuredSelection) selection;
      Iterator<StructuredSelection> it = currentSelection.iterator();

      while (it.hasNext()) {
        file = (IFile) it.next();
      }
    }
  }
  /**
   * Handle the selection changed event. This won't do anything unless both a selection occured and
   * the mouse or key was pressed.
   */
  public void handleSelectionChanged() {
    if (selectionChangedEvent != null && mouseOrKeyPressed) {
      StructuredSelection s = (StructuredSelection) selectionChangedEvent.getSelection();
      s.getFirstElement();

      assert (s.getFirstElement() instanceof SelectableElement);
      SelectableElement element = (SelectableElement) s.getFirstElement();

      switchCheckType(element);

      setSelectedTypeForChildren(element);
      setSelectedTypeForParent(element);

      viewer.refresh();

      // reset since processed
      selectionChangedEvent = null;
      mouseOrKeyPressed = false;
    }
  }
  private void doInsert() {

    try {
      final StructuredSelection sel = (StructuredSelection) viewer.getSelection();
      if (sel == null) return;
      final IVariable var = (IVariable) sel.getFirstElement();
      final IDocument doc = getTextViewer().getDocument();
      final String rep = "${" + var.getVariableName() + "}";

      if (currentSelectedText != null) {
        final int total = currentSelectedText.getOffset() + currentSelectedText.getLength();
        int len = currentSelectedText.getLength();
        final int tLen = doc.getLength();
        if (total > tLen) len = tLen - currentSelectedText.getOffset();
        if (len < 0) len = 0;
        doc.replace(currentSelectedText.getOffset(), len, rep);
      }
    } catch (BadLocationException e) {
      logger.error("Cannot replace selection " + getTextViewer().getSelectedRange(), e);
    }
  }
  /** @return the selected pictogram element. */
  protected PictogramElement getSelectedPictogramElement() {
    if (getSelection() instanceof StructuredSelection) {
      StructuredSelection structuredSelection = (StructuredSelection) getSelection();

      Object firstElement = structuredSelection.getFirstElement();

      if (firstElement instanceof PictogramElement) {
        return (PictogramElement) firstElement;
      }

      EditPart editPart = null;
      if (firstElement instanceof EditPart) {
        editPart = (EditPart) firstElement;
      } else if (firstElement instanceof IAdaptable) {
        editPart = (EditPart) ((IAdaptable) firstElement).getAdapter(EditPart.class);
      }
      if (editPart != null && editPart.getModel() instanceof PictogramElement) {
        return (PictogramElement) editPart.getModel();
      }
    }
    return null;
  }