Java Code Examples for org.eclipse.swt.widgets.TreeItem#getParentItem()

The following examples show how to use org.eclipse.swt.widgets.TreeItem#getParentItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabaseExplorerDialog.java    From hop with Apache License 2.0 6 votes vote down vote up
public void openSchema( SelectionEvent e ) {
  TreeItem sel = (TreeItem) e.item;

  TreeItem up1 = sel.getParentItem();
  if ( up1 != null ) {
    TreeItem up2 = up1.getParentItem();
    if ( up2 != null ) {
      TreeItem up3 = up2.getParentItem();
      if ( up3 != null ) {
        tableName = sel.getText();
        if ( !justLook ) {
          handleOK();
        } else {
          previewTable( tableName, false );
        }
      }
    }
  }
}
 
Example 2
Source File: ParameterSettingsSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the selected model parameter.
 *
 * @return the selected model parameter
 */
public ConfigurationParameter getSelectedModelParameter() {
  TreeItem[] items = tree.getSelection();
  if (items.length == 0)
    return null;

  TreeItem item = items[0];
  if (isParameter(item)) {
    TreeItem group = item.getParentItem();
    ConfigurationParameterDeclarations cpds = getConfigurationParameterDeclarations();
    String groupName = (null == group) ? null : getName(group.getText());
    if (NOT_IN_ANY_GROUP.equals(groupName))
      return cpds.getConfigurationParameter(null, getName(item.getText()));
    return cpds.getConfigurationParameter(groupName, getName(item.getText()));
  }
  return null;
}
 
Example 3
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
private void removeProject(TreeItem cur) {
	while (cur != null && !(cur.getData() instanceof Project))
		cur = cur.getParentItem();

	if (cur == null)
		return;

	Project proj = (Project) cur.getData();
	RemProjShell.Result result = RemProjShell.confirm(display, shell, proj);

	if (result == RemProjShell.Result.OK_KEEP) {
		cur.dispose();
		ProjectManager.removeProject(proj, false);
	} else if (result == RemProjShell.Result.OK_DELETE) {
		cur.dispose();
		ProjectManager.removeProject(proj, true);
	}

	tree.notifyListeners(SWT.Selection, null);
}
 
Example 4
Source File: SpoonSlave.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public TreeEntry( TreeItem treeItem ) {
  TreeItem treeIt = treeItem;
  path = ConstUI.getTreeStrings( treeIt );
  this.length = path.length;
  if ( path.length > 0 ) {
    itemType = path[0];
  }
  if ( path.length > 1 ) {
    name = path[1];
  }
  if ( path.length == 3 ) {
    treeIt = treeIt.getParentItem();
  }
  status = treeIt.getText( 9 );
  id = treeIt.getText( 13 );
}
 
Example 5
Source File: PriorityListSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void enable() {

  if (tree.getSelectionCount() == 1) {
    addButton.setEnabled(true);
    TreeItem item = tree.getSelection()[0];
    removeButton.setEnabled(true);
    if (null != item.getParentItem()) {
      TreeItem[] items = item.getParentItem().getItems();
      int i = getItemIndex(items, item);
      upButton.setEnabled(i > 0);
      downButton.setEnabled(i < (items.length - 1));
    }
  } else {
    addButton.setEnabled(false);
    removeButton.setEnabled(false);
    upButton.setEnabled(false);
    downButton.setEnabled(false);
  }
  exportButton.setEnabled(tree.getItemCount() > 0);
}
 
Example 6
Source File: UserDefinedJavaClassDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void treeDblClick( Event event ) {
  StyledTextComp wScript = getStyledTextComp();
  Point point = new Point( event.x, event.y );
  TreeItem item = wTree.getItem( point );

  // Qualification where the Click comes from
  if ( item != null && item.getParentItem() != null ) {
    if ( item.getParentItem().equals( wTreeClassesItem ) ) {
      setActiveCtab( item.getText() );
    } else if ( !item.getData().equals( "Snippit" ) ) {
      int iStart = wScript.getCaretOffset();
      int selCount = wScript.getSelectionCount(); // this selection
      // will be replaced
      // by wScript.insert
      iStart = iStart - selCount; // when a selection is already there
      // we need to subtract the position
      if ( iStart < 0 ) {
        iStart = 0; // just safety
      }
      String strInsert = (String) item.getData();
      wScript.insert( strInsert );
      wScript.setSelection( iStart, iStart + strInsert.length() );
    }
  }
}
 
Example 7
Source File: UserDefinedJavaClassDialog.java    From hop with Apache License 2.0 6 votes vote down vote up
private void treeDblClick( Event event ) {
  StyledTextComp wScript = getStyledTextComp();
  Point point = new Point( event.x, event.y );
  TreeItem item = wTree.getItem( point );

  // Qualification where the Click comes from
  if ( item != null && item.getParentItem() != null ) {
    if ( item.getParentItem().equals( wTreeClassesItem ) ) {
      setActiveCtab( item.getText() );
    } else if ( !item.getData().equals( "Snippit" ) ) {
      int iStart = wScript.getCaretOffset();
      int selCount = wScript.getSelectionCount(); // this selection
      // will be replaced
      // by wScript.insert
      iStart = iStart - selCount; // when a selection is already there
      // we need to subtract the position
      if ( iStart < 0 ) {
        iStart = 0; // just safety
      }
      String strInsert = (String) item.getData();
      wScript.insert( strInsert );
      wScript.setSelection( iStart, iStart + strInsert.length() );
    }
  }
}
 
Example 8
Source File: ExtnlResBindSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Bind button - enabled only when one dependency is selected, and one External Resource, not
 * already bound to this key, is selected.
 */
private void handleBind() {
  TreeItem xrItem = tree.getSelection()[0];
  if (null != xrItem.getParentItem())
    xrItem = xrItem.getParentItem();
  ExternalResourceDescription xrd = getXRDescriptionFromTreeItem(xrItem);

  TableItem keyItem = resourceDependencySection.getTable().getSelection()[0];

  ExternalResourceBinding xrb = new ExternalResourceBinding_impl();
  String key = keyItem.getText(ResourceDependencySection.KEY_COL);
  xrb.setKey(key);
  xrb.setResourceName(xrd.getName());
  getResourceManagerConfiguration().addExternalResourceBinding(xrb);
  addBindingToGUI(xrItem, key, xrb);
  xrItem.setExpanded(true);
  keyItem.setText(0, "Bound");
  keyItem.getParent().getColumn(0).pack();
  setFileDirty();
}
 
Example 9
Source File: CapabilitySection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Handle add lang.
 *
 * @param selItem the sel item
 * @param itemKind the item kind
 */
private void handleAddLang(TreeItem selItem, int itemKind) {
  if (itemKind == CS)
    selItem = selItem.getItems()[0]; // lang is 1st item in capability set
  else if (itemKind == LANG_ITEM)
    selItem = selItem.getParentItem();
  else if (itemKind == TYPE || itemKind == SOFA)
    selItem = selItem.getParentItem().getItems()[0];
  else if (itemKind == FEAT || itemKind == SOFA_ITEM)
    selItem = selItem.getParentItem().getParentItem().getItems()[0];
  Capability c = getCapabilityFromTreeItem(selItem.getParentItem());
  CommonInputDialog dialog = new CommonInputDialog(
          this,
          "Add Language",
          "Enter a two letter ISO-639 language code, followed optionally by a two-letter ISO-3166 country code (Examples: fr or fr-CA)",
          CommonInputDialog.LANGUAGE);
  if (dialogForLanguage(c, dialog) == Window.CANCEL)
    return;

  c.setLanguagesSupported(stringArrayAdd(c.getLanguagesSupported(), dialog.getValue()));

  // update GUI
  TreeItem lItem = new TreeItem(selItem, SWT.NONE);
  lItem.setData(LANG_TITLE);
  lItem.setText(NAME_COL, dialog.getValue());
  selItem.setExpanded(true);
  pack04();
  finishAction();
}
 
Example 10
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Handle remove.
 */
/*
 * Note that the Remove action is disabled if the item selected is imported only
 */
private void handleRemove() {
  TreeItem item = tt.getSelection()[0];
  TreeItem parent = item.getParentItem();

  if (null == parent)
    handleRemoveType(item);
  else if (item.getText(NAME_COL).equals(HEADER_ALLOWED_VALUE))
    handleRemoveAllowedValue(item);
  else
    handleRemoveFeature(item);
}
 
Example 11
Source File: ScriptValuesModDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
private void treeDblClick( Event event ) {
  StyledTextComp wScript = getStyledTextComp();
  Point point = new Point( event.x, event.y );
  TreeItem item = wTree.getItem( point );

  // Qualifikation where the Click comes from
  if ( item != null && item.getParentItem() != null ) {
    if ( item.getParentItem().equals( wTreeScriptsItem ) ) {
      setActiveCtab( item.getText() );
    } else if ( !item.getData().equals( "Function" ) ) {
      int iStart = wScript.getCaretOffset();
      int selCount = wScript.getSelectionCount(); // this selection will be replaced by wScript.insert
      iStart = iStart - selCount; // when a selection is already there we need to subtract the position
      if ( iStart < 0 ) {
        iStart = 0; // just safety
      }
      String strInsert = (String) item.getData();
      if ( strInsert.equals( "jsFunction" ) ) {
        strInsert = item.getText();
      }
      wScript.insert( strInsert );
      wScript.setSelection( iStart, iStart + strInsert.length() );
    }
  }
  /*
   * if (item != null && item.getParentItem()!=null && !item.getData().equals("Function")) { int iStart =
   * wScript.getCaretOffset(); String strInsert =(String)item.getData(); if(strInsert.equals("jsFunction")) strInsert
   * = (String)item.getText(); wScript.insert(strInsert); wScript.setSelection(iStart,iStart+strInsert.length()); }
   */
}
 
Example 12
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Swap tree items.
 *
 * @param itemBelow the item below
 * @param newSelection the new selection
 */
public static void swapTreeItems(TreeItem itemBelow, int newSelection) {
  TreeItem parent = itemBelow.getParentItem();
  if (null == parent)
    throw new InternalErrorCDE("invalid arg");
  int i = getIndex(itemBelow);
  TreeItem itemAbove = parent.getItems()[i - 1];
  TreeItem newItemAbove = new TreeItem(parent, SWT.NONE, i - 1);
  copyTreeItem(newItemAbove, itemBelow);
  TreeItem newItemBelow = new TreeItem(parent, SWT.NONE, i);
  copyTreeItem(newItemBelow, itemAbove);
  itemAbove.dispose();
  itemBelow.dispose();
  parent.getParent().setSelection(new TreeItem[] { parent.getItems()[newSelection] });
}
 
Example 13
Source File: TreeClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static int getLevel(TreeItem item) {
	if (item == null)
		return -1;
	int level = 0;
	TreeItem parent = item.getParentItem();
	while (parent != null) {
		level++;
		parent = parent.getParentItem();
	}
	return level;
}
 
Example 14
Source File: ScriptValuesModDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void treeDblClick( Event event ) {
  StyledTextComp wScript = getStyledTextComp();
  Point point = new Point( event.x, event.y );
  TreeItem item = wTree.getItem( point );

  // Qualifikation where the Click comes from
  if ( item != null && item.getParentItem() != null ) {
    if ( item.getParentItem().equals( wTreeScriptsItem ) ) {
      setActiveCtab( item.getText() );
    } else if ( !item.getData().equals( "Function" ) ) {
      int iStart = wScript.getCaretOffset();
      int selCount = wScript.getSelectionCount(); // this selection will be replaced by wScript.insert
      iStart = iStart - selCount; // when a selection is already there we need to subtract the position
      if ( iStart < 0 ) {
        iStart = 0; // just safety
      }
      String strInsert = (String) item.getData();
      if ( strInsert.equals( "jsFunction" ) ) {
        strInsert = item.getText();
      }
      wScript.insert( strInsert );
      wScript.setSelection( iStart, iStart + strInsert.length() );
    }
  }
  /*
   * if (item != null && item.getParentItem()!=null && !item.getData().equals("Function")) { int iStart =
   * wScript.getCaretOffset(); String strInsert =(String)item.getData(); if(strInsert.equals("jsFunction")) strInsert
   * = (String)item.getText(); wScript.insert(strInsert); wScript.setSelection(iStart,iStart+strInsert.length()); }
   */
}
 
Example 15
Source File: JavaOutlineInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void internalExpandToLevel(Widget node, int level) {
	if (!fIsFiltering && node instanceof TreeItem && getMatcher() == null) {
		TreeItem treeItem= (TreeItem)node;
		if (treeItem.getParentItem() != null && treeItem.getData() instanceof IJavaElement) {
			IJavaElement je= (IJavaElement) treeItem.getData();
			if (je.getElementType() == IJavaElement.IMPORT_CONTAINER || isInnerType(je)) {
				setExpanded(treeItem, false);
				return;
			}
		}
	}
	super.internalExpandToLevel(node, level);
}
 
Example 16
Source File: ColumnMappingWizardPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private IMappingSource[] getMappingPath( TreeItem item )
{
	List<Member> backs = new ArrayList<Member>( );
	while ( item != null
			&& item.getData( ) instanceof TreeData
			&& ( (TreeData) item.getData( ) ).getWrappedObject( ) instanceof Member )
	{
		backs.add( (Member) ( (TreeData) item.getData( ) ).getWrappedObject( ) );
		item = item.getParentItem( );
	}
	IMappingSource[] result = helper.createMappingPath( backs );

	return result;
}
 
Example 17
Source File: ConstUi.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the level of where the TreeItem is position in a tree.
 *
 * @param ti The TreeItem
 * @return The level of the item in the tree
 */
public static final int getTreeLevel( TreeItem ti ) {
  int level = 0;
  TreeItem parent = ti.getParentItem();
  while ( parent != null ) {
    level++;
    parent = parent.getParentItem();
  }

  return level;
}
 
Example 18
Source File: ScriptDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void treeDblClick( Event event ) {
  StyledTextComp wScript = getStyledTextComp();
  Point point = new Point( event.x, event.y );
  TreeItem item = wTree.getItem( point );

  // Qualifikation where the Click comes from
  if ( item != null && item.getParentItem() != null ) {
    if ( item.getParentItem().equals( wTreeScriptsItem ) ) {
      setActiveCtab( item.getText() );
    } else if ( !item.getData().equals( "Function" ) ) {
      int iStart = wScript.getCaretOffset();
      int selCount = wScript.getSelectionCount(); // this selection will be replaced by wScript.insert
      iStart = iStart - selCount; // when a selection is already there we need to subtract the position
      if ( iStart < 0 ) {
        iStart = 0; // just safety
      }
      String strInsert = (String) item.getData();
      if ( strInsert.equals( "jsFunction" ) ) {
        strInsert = item.getText();
      }
      wScript.insert( strInsert );
      wScript.setSelection( iStart, iStart + strInsert.length() );
    }
  }
  /*
   * if (item != null && item.getParentItem()!=null && !item.getData().equals("Function")) { int iStart =
   * wScript.getCaretOffset(); String strInsert =(String)item.getData(); if(strInsert.equals("jsFunction")) strInsert
   * = (String)item.getText(); wScript.insert(strInsert); wScript.setSelection(iStart,iStart+strInsert.length()); }
   */
}
 
Example 19
Source File: AbstractSectionParm.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a parameter from all groups it lives in the Settings. If settings page is shown, also
 * update the GUI.
 *
 * @param parmItem          in ParameterSection of parameter belonging to (multiple) groups
 * @param removeFromGUI the remove from GUI
 */
public void removeParmSettingFromMultipleGroups(TreeItem parmItem, boolean removeFromGUI) {
  if (!isParameter(parmItem))
    throw new InternalErrorCDE("invalid argument"); //$NON-NLS-1$

  ConfigurationParameterSettings modelSettings = getModelSettings();
  String parmName = getName(parmItem);
  TreeItem parent = parmItem.getParentItem();
  String groupName = getName(parent.getText());
  if (!groupName.equals(NOT_IN_ANY_GROUP)) {
    String[] groupNames = (getName(parent.getText()).equals(COMMON_GROUP)) ? getAllGroupNames()
            : getCorrespondingModelGroup(parent).getNameArray();

    for (int i = 0; i < groupNames.length; i++) {
      modelSettings.setParameterValue(groupNames[i], parmName, null);
    }
  } else {
    modelSettings.setParameterValue(parmName, null);
  }

  if (null != settings) {
    if (removeFromGUI) {
      TreeItem[] settingsTreeParms = getSettingsParameter(parent, parmName);
      for (int i = 0; i < settingsTreeParms.length; i++) {
        settingsTreeParms[i].dispose();
      }
    } else { // leave parm but remove value
      editor.getSettingsPage().getValueSection().refresh();
    }
  }
}
 
Example 20
Source File: RepositoryExplorerDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private int getItemCategory( TreeItem ti ) {
  int cat = ITEM_CATEGORY_NONE;

  int level = ConstUI.getTreeLevel( ti );
  String[] path = ConstUI.getTreeStrings( ti );

  String item = "";
  String parent = "";

  if ( ti != null ) {
    item = ti.getText();
    if ( ti.getParentItem() != null ) {
      parent = ti.getParentItem().getText();
    }
  }

  // Level 1:
  if ( level == 0 ) {
    cat = ITEM_CATEGORY_ROOT;
  } else if ( level == 1 ) {
    if ( item.equals( STRING_USERS ) ) {
      cat = ITEM_CATEGORY_USERS_ROOT;
    } else if ( item.equals( STRING_DATABASES ) ) {
      cat = ITEM_CATEGORY_DATABASES_ROOT;
    } else if ( item.equals( STRING_PARTITIONS ) ) {
      cat = ITEM_CATEGORY_PARTITIONS_ROOT;
    } else if ( item.equals( STRING_SLAVES ) ) {
      cat = ITEM_CATEGORY_SLAVES_ROOT;
    } else if ( item.equals( STRING_CLUSTERS ) ) {
      cat = ITEM_CATEGORY_CLUSTERS_ROOT;
    } else if ( item.equals( STRING_TRANSFORMATIONS ) ) {
      cat = ITEM_CATEGORY_TRANSFORMATIONS_ROOT;
    } else if ( item.equals( STRING_JOBS ) ) {
      cat = ITEM_CATEGORY_JOBS_ROOT;
    }
  } else if ( level >= 2 ) {
    if ( parent.equals( STRING_USERS ) ) {
      cat = ITEM_CATEGORY_USER;
    } else if ( parent.equals( STRING_DATABASES ) ) {
      cat = ITEM_CATEGORY_DATABASE;
    } else if ( parent.equals( STRING_PARTITIONS ) ) {
      cat = ITEM_CATEGORY_PARTITION;
    } else if ( parent.equals( STRING_SLAVES ) ) {
      cat = ITEM_CATEGORY_SLAVE;
    } else if ( parent.equals( STRING_CLUSTERS ) ) {
      cat = ITEM_CATEGORY_CLUSTER;
    }

    final Color dircolor = GUIResource.getInstance().getColorDirectory();
    if ( path[1].equals( STRING_TRANSFORMATIONS ) ) {
      if ( ti.getForeground().equals( dircolor ) ) {
        cat = ITEM_CATEGORY_TRANSFORMATION_DIRECTORY;
      } else {
        cat = ITEM_CATEGORY_TRANSFORMATION;
      }
    } else if ( path[1].equals( STRING_JOBS ) ) {
      if ( ti.getForeground().equals( dircolor ) ) {
        cat = ITEM_CATEGORY_JOB_DIRECTORY;
      } else {
        cat = ITEM_CATEGORY_JOB;
      }
    }
  }

  return cat;
}