示例#1
0
 @Override
 public void widgetSelected(SelectionEvent e) {
   TreeViewer constTreeViewer = this.getViewPage().getConstTreeViewer();
   TreeViewer varTreeViewer = this.getViewPage().getVarTreeViewer();
   TreeSelection constSelect = (TreeSelection) constTreeViewer.getSelection();
   TreeSelection varSelect = (TreeSelection) varTreeViewer.getSelection();
   ConstBeanBridge atConst = null;
   VarBeanBridge beforeVar = null;
   //
   if (constSelect == null || constSelect.isEmpty() == true) return;
   atConst = (ConstBeanBridge) constSelect.getFirstElement();
   if (varSelect != null && varSelect.isEmpty() == false)
     beforeVar = (VarBeanBridge) varSelect.getFirstElement();
   //
   int index = -1;
   if (beforeVar != null) {
     atConst = beforeVar.getConst();
     index = atConst.getVarRoots().indexOf(beforeVar);
   }
   //
   VarBeanBridge newVar = new VarBeanBridge(atConst, null, atConst.getSource());
   atConst.addVar(index + 1, newVar);
   newVar.doEdit();
   varTreeViewer.refresh();
   varTreeViewer.setSelection(new TreeSelection(new TreePath(new Object[] {newVar})), true);
   varTreeViewer.editElement(newVar, 0);
 }
 @Override
 public void fillContextMenu(IMenuManager menu) {
   // MOD mzhao user readonly role on svn repository mode.
   if (!isShowMenu()) {
     return;
   }
   TreeSelection treeSelection = ((TreeSelection) this.getContext().getSelection());
   if (!treeSelection.isEmpty()) {
     Iterator iterator = treeSelection.iterator();
     while (iterator.hasNext()) {
       Object obj = iterator.next();
       if (obj instanceof ReportAnalysisRepNode) {
         ReportAnalysisRepNode repAnaNode = (ReportAnalysisRepNode) obj;
         TDQReportItem reportItem = repAnaNode.getReportItem();
         if (CorePlugin.getDefault().itemIsOpening(reportItem, false)) {
           // if the report's editor is opening, don't show the menu
           return;
         }
       } else {
         // if include other type node, don't show the menu
         return;
       }
     }
   }
   // show the menu
   menu.add(new RemoveAnalysisAction());
 }
  /*
   * (non-Javadoc)
   *
   * @see org.talend.designer.fileoutputxml.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
   */
  @Override
  protected void updateStatus(TreeSelection selection) {
    if (selection.isEmpty()) {
      getButton().setEnabled(false);
      return;
    }
    final TreePath[] paths = selection.getPaths();
    boolean sameSegment = true;
    for (int i = 0; i < paths.length - 1; i++) {
      if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
        sameSegment = false;
      }
    }
    if (sameSegment) {
      getButton().setEnabled(true);
    } else {
      getButton().setEnabled(false);
      return;
    }

    // if same segment ,they have the same parent and parent must be an element
    final Element parent = (Element) ((FOXTreeNode) selection.getFirstElement()).getParent();
    if (parent == null) {
      getButton().setEnabled(false);
      return;
    }
    final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
    final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
    final List<FOXTreeNode> elementChildren = parent.getElementChildren();
    final Iterator iterator = selection.iterator();
    while (iterator.hasNext()) {
      final Object next = iterator.next();
      if (next instanceof Attribute) {
        if (attrChildren.contains(next) && attrChildren.indexOf(next) == 0) {
          getButton().setEnabled(false);
          return;
        }
      } else if (next instanceof NameSpaceNode) {
        if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == 0) {
          getButton().setEnabled(false);
          return;
        }
      } else if (next instanceof Element) {
        if (elementChildren.contains(next) && elementChildren.indexOf(next) == 0) {
          getButton().setEnabled(false);
          return;
        }
      }
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see org.talend.designer.fileoutputxml.ui.footer.AbstractTreeNodeButton#handleSelectionEvent()
   */
  @Override
  protected void handleSelectionEvent(TreeSelection selection) {
    if (!selection.isEmpty()) {
      final Element parentNode = (Element) ((FOXTreeNode) selection.getFirstElement()).getParent();
      final List<? extends FOXTreeNode> attrChildren = parentNode.getAttributeChildren();
      final List<? extends FOXTreeNode> nameSpaceChildren = parentNode.getNameSpaceChildren();
      final List<FOXTreeNode> elementChildren = parentNode.getElementChildren();
      List<Integer> attrIndices = new ArrayList<Integer>();
      List<Integer> nameSpaceIndices = new ArrayList<Integer>();
      List<Integer> elementIndices = new ArrayList<Integer>();
      final Iterator iterator = selection.iterator();
      while (iterator.hasNext()) {
        final Object next = iterator.next();
        if (next instanceof Attribute) {
          if (attrChildren.contains(next)) {
            attrIndices.add(attrChildren.indexOf(next));
          }
        } else if (next instanceof NameSpaceNode) {
          if (nameSpaceChildren.contains(next)) {
            nameSpaceIndices.add(nameSpaceChildren.indexOf(next));
          }
        } else if (next instanceof Element) {
          if (elementChildren.contains(next)) {
            elementIndices.add(elementChildren.indexOf(next));
          }
        }
      }
      Collections.sort(attrIndices);
      Collections.sort(nameSpaceIndices);
      Collections.sort(elementIndices);

      swapElements(attrChildren, attrIndices);
      swapElements(nameSpaceChildren, nameSpaceIndices);
      swapElements(elementChildren, elementIndices);

      treeViewer.refresh(parentNode);
      treeViewer.expandAll();
      manager.getUiManager().getFoxUI().redrawLinkers();
      treeViewer.setSelection(selection);
    }
  }
  @Override
  public void selectionChanged(SelectionChangedEvent event) {
    TreeSelection selection = (TreeSelection) event.getSelection();
    if (selection.isEmpty()) {
      this.selectedTranslator = null;
      this.translatorNameText.setText(UNDEFINED);
      updateOnSelection(null);
      return;
    }

    Object firstElement = selection.getFirstElement();

    if (!(firstElement instanceof TeiidTranslator)) {
      this.selectedTranslator = null;
      this.translatorNameText.setText(UNDEFINED);
    } else {
      this.selectedTranslator = (TeiidTranslator) selection.getFirstElement();
      this.translatorNameText.setText(selectedTranslator.getName());
    }

    updateOnSelection(firstElement);
  }