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

The following examples show how to use org.eclipse.swt.widgets.TreeItem#getData() . 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: ExportSampleReportAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void handleEvent( Event event )
{
	if ( event.widget == null || !( event.widget instanceof TreeItem ) )
		setEnabled( false );
	TreeItem item = (TreeItem) event.widget;
	if ( item == null )
	{
		super.setEnabled( false );
		return;
	}			
	Object selectedElement = item.getData( );
	if ( selectedElement == null )
		super.setEnabled( false );
	else
		super.setEnabled( selectedElement instanceof ReportDesignHandle );
}
 
Example 2
Source File: ResourcePickerDialog.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void handleEvent(Event event) {
  if (event.widget == resourcesUI &&
      event.type == SWT.Expand) {
    TreeItem expandedNode = (TreeItem) event.item;
    TreeItem maybeDummy = expandedNode.getItem(0);
    if (null == maybeDummy.getData()) {
      maybeDummy.dispose();
      IResource parentResource = (IResource)expandedNode.getData();
      try {
        populate(expandedNode, ((IContainer)parentResource).members());
      } catch (CoreException e) {
        throw new InternalErrorCDE("unhandled exception", e);
      }
    }
  } else if (event.widget == resourcesUI && event.type == SWT.Selection) {
    copyValuesFromGUI();
  }
  super.handleEvent(event);
}
 
Example 3
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
private String getTreeDir(TreeItem item) {
	String dir = "";

	Object data = item.getData();

	if (data instanceof Integer)
		return null;
	if (data instanceof String)
		dir = (String) data;
	else if (data instanceof Project)
		dir = ((Project) data).getDir();
	else
		dir = ((Project) item.getParentItem().getData()).getDir();

	return dir;
}
 
Example 4
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
protected void removeItem(TreeItem[] selection) {
	int lastResult = RemFileShell.CANCEL;

	if (selection.length == 0)
		return;

	for (TreeItem cur : selection) {
		Object data = cur.getData();

		if (data instanceof Integer)
			removeSym(cur);
		else if (data instanceof String)
			removeDir(cur);
		else if (data instanceof Project)
			removeProject(cur);
		else
			lastResult = removeFile(cur, lastResult);
	}
}
 
Example 5
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 6
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
private void handleRenameItem(TreeItem item, String newName) {
	if (item.getData() instanceof SymitarFile) {
		// Set SymitarFile name
		if (((SymitarFile) item.getData()).saveName(newName))
			item.setText(newName); // Set name in tree

		// Now, set name in any open tabs
		for (CTabItem c : mainfolder.getItems())
			if (c.getData("file") == item.getData()) // Be sure it's the
				// exact same
				// instance, like it
				// should be
			{
				c.setText(newName);
				if (c.getControl() instanceof EditorComposite) {
					c.setData("modified", false);
					((EditorComposite) c.getControl()).updateModified();
				}
			}
	}

	if (item.getData() instanceof Project) {
		((Project) item.getData()).setName(newName);
		item.setText(newName);
	}
}
 
Example 7
Source File: TotalImpactResultPage.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public String getLabel(TreeItem treeItem, int col) {
	Item item = (Item) treeItem.getData();
	switch (col) {
	case 0:
		return label.getText(item, 0);
	case 1:
		return label.getText(item, 1);
	case 2:
		return format(item.flowAmount());
	case 3:
		if (item.flowAmount() == null)
			return "";
		return Labels.refUnit(item.flow);
	case 4:
		return format(item.impactFactor());
	case 5:
		if (item.impactFactor() == null)
			return "";
		return item.impactFactorUnit();
	case 6:
		return label.getText(item, 4);
	case 7:
		return label.getText(item, 5);
	}
	return null;
}
 
Example 8
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 9
Source File: RenameTypeWizardSimilarElementsPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void selectFirstElement() {
	if (fTreeViewer.getTree().getItemCount() > 0) {
		TreeItem item= fTreeViewer.getTree().getItem(0);
		if (item.getData() != null) {
			fTreeViewer.reveal(item.getData());
			Object data= getFirstSimilarElement(item);
			if (data != null) {
				fTreeViewer.setSelection(new StructuredSelection(data));
			}
		}
	}
	fTreeViewer.getTree().setFocus();
}
 
Example 10
Source File: UserElementDecorator.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleEvent(Event event) {

  TreeItem treeItem = (TreeItem) event.item;

  /*
   * do not adapt the object or we will draw into widget / tree items that
   * should not be *decorated*
   */

  if (!(treeItem.getData() instanceof UserElement)) return;

  User user = ((UserElement) treeItem.getData()).getUser();

  Rectangle bounds = treeItem.getBounds(event.index);

  bounds.width = 15;
  bounds.x += 15;

  /*
   * make the rectangle a little bit smaller so it does not collide with
   * the edges when the tree item is selected
   */

  bounds.y += 2;
  bounds.height -= 4;

  Color background = SarosAnnotation.getUserColor(user);
  PaintUtils.drawRoundedRectangle(event.gc, bounds, background);
  background.dispose();
}
 
Example 11
Source File: OffsetDialog.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void setBasicMode() {
    fAdvancedMode = false;
    fRefTimeColumn.setData(WIDTH_KEY, fRefTimeColumn.getWidth());
    fTargetTimeColumn.setData(WIDTH_KEY, fTargetTimeColumn.getWidth());
    for (TreeItem treeItem : fViewer.getViewer().getTree().getItems()) {
        Control editor = (Control) treeItem.getData(EDITOR_KEY);
        editor.setVisible(false);
    }
    fTargetTimeColumn.setWidth(0);
    fTargetTimeColumn.setResizable(false);
    fRefTimeColumn.setWidth(0);
    fRefTimeColumn.setResizable(false);
    fButtonViewerColumn.getColumn().setWidth(0);
    fAdvancedMessageLabel.setText(""); //$NON-NLS-1$
}
 
Example 12
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 13
Source File: Navigator.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static boolean itemEqualsElement(TreeItem item,
		INavigationElement<?> element) {
	INavigationElement<?> data = (INavigationElement<?>) item.getData();
	if (data == null)
		return false;
	return Objects.equal(data.getContent(), element.getContent());
}
 
Example 14
Source File: IndentGuidePreferencePage.java    From IndentGuide with MIT License 5 votes vote down vote up
private String getContentTypes(final TreeItem item, final String types) {
  String result = types;
  if (item.getChecked() && !item.getGrayed()) {
    if (!"".equals(types)) {
      result += "|";
    }
    result += item.getData();
  }
  for (final TreeItem child : item.getItems()) {
    result = getContentTypes(child, result);
  }
  return result;
}
 
Example 15
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 5 votes vote down vote up
private boolean isItemLocal(TreeItem item) {
	Object data = item.getData();

	if (data instanceof String)
		return true;
	else if (data instanceof Integer)
		return false;
	else if (data instanceof Project)
		return ((Project) data).getDir() != null;
	else
		return ((SymitarFile) data).isLocal();
}
 
Example 16
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 4 votes vote down vote up
private void addProject() {
	int sym = -1;
	String dir = null;

	TreeItem[] selection = tree.getSelection();
	if (selection.length != 1)
		return;

	TreeItem cur = selection[0];
	while (cur.getParentItem() != null)
		cur = cur.getParentItem();

	if (cur.getData() instanceof Integer)
		sym = (Integer) cur.getData();
	else if (cur.getData() instanceof String)
		dir = (String) cur.getData();

	if( dir == null && sym != -1 && !RepDevMain.SYMITAR_SESSIONS.get(sym).isConnected() ) {
		MessageBox err = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR );
		err.setText("Can not create project");
		err.setMessage("Unable to create project when not connected to a sym");
		err.open();
		return;
	}

	String str = NewProjShell.askForName(display, shell);

	if (str != null) {
		Project proj = null;

		// TODO: Add error message for already existing projects
		if (cur.getData() instanceof Integer) {
			if (ProjectManager.containsProject(sym, str))
				return;

			proj = ProjectManager.createProject(str, sym);
		} else if (cur.getData() instanceof String) {
			if (ProjectManager.containsProject(dir, str))
				return;

			proj = ProjectManager.createProject(str, dir);
		}

		if (proj != null) {
			TreeItem item = new TreeItem(cur, SWT.NONE);
			item.setText(proj.getName());
			item.setData(proj);
			item.setImage(RepDevMain.smallProjectImage);
			new TreeItem(item, SWT.NONE).setText("Loading...");
		}
	}
}
 
Example 17
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 4 votes vote down vote up
private void newFileInProject() {
	FileDialog dialog;

	if (isCurrentItemLocal())
		dialog = new FileDialog(shell, FileDialog.Mode.SAVE, getCurrentTreeDir());
	else
		dialog = new FileDialog(shell, FileDialog.Mode.SAVE, getCurrentTreeSym());

	ArrayList<SymitarFile> files = dialog.open();

	if (files.size() > 0) {
		SymitarFile file = files.get(0);

		TreeItem[] selection = tree.getSelection();
		if (selection.length != 1)
			return;

		TreeItem cur = selection[0];
		while (cur != null && !(cur.getData() instanceof Project))
			cur = cur.getParentItem();

		if (cur == null)
			return;

		Project proj = (Project) cur.getData();

		SessionError error = file.saveFile("");

		if (error == SessionError.NONE) {
			if (!proj.hasFile(file)) {
				proj.addFile(file);
				TreeItem item = new TreeItem(cur, SWT.NONE);
				item.setText(file.getName());
				item.setData(file);
				item.setImage(getFileImage(file));

				if (proj.isLocal())
					ProjectManager.saveProjects(proj.getDir());
				else
					ProjectManager.saveProjects(proj.getSym());
			}

			openFile(file);
			tree.notifyListeners(SWT.Selection, null);
		}

	}
}
 
Example 18
Source File: ColumnChooserDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
private void selectedTreeCollapsed(TreeEvent event) {
	TreeItem item = (TreeItem) event.item;
	ColumnGroupEntry columnGroupEntry = (ColumnGroupEntry) item.getData();
	fireGroupCollapsed(columnGroupEntry);
}
 
Example 19
Source File: ParameterDelegatesSection.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the key name from tree item.
 *
 * @param item the item
 * @return the key name from tree item
 */
private String getKeyNameFromTreeItem(TreeItem item) {
  return (String) item.getData();
}
 
Example 20
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the feature description from table tree item.
 *
 * @param item the item
 * @return the feature description from table tree item
 */
public FeatureDescription getFeatureDescriptionFromTableTreeItem(TreeItem item) {
  return (FeatureDescription) item.getData();
}