Java Code Examples for javafx.scene.control.TreeTableColumn#setCellValueFactory()

The following examples show how to use javafx.scene.control.TreeTableColumn#setCellValueFactory() . 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: NumberRangeType.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
@Nonnull
public List<TreeTableColumn<ModularFeatureListRow, Object>> createSubColumns(
    @Nullable RawDataFile raw) {
  List<TreeTableColumn<ModularFeatureListRow, Object>> cols = new ArrayList<>();

  // create column per name
  TreeTableColumn<ModularFeatureListRow, Object> min = new TreeTableColumn<>("min");
  DataTypeCellValueFactory cvFactoryMin = new DataTypeCellValueFactory(raw, this);
  min.setCellValueFactory(cvFactoryMin);
  min.setCellFactory(new DataTypeCellFactory(raw, this, 0));

  TreeTableColumn<ModularFeatureListRow, Object> max = new TreeTableColumn<>("max");
  DataTypeCellValueFactory cvFactoryMax = new DataTypeCellValueFactory(raw, this);
  max.setCellValueFactory(cvFactoryMax);
  max.setCellFactory(new DataTypeCellFactory(raw, this, 1));

  // add all
  cols.add(min);
  cols.add(max);

  return cols;
}
 
Example 2
Source File: ServiceViewer.java    From diirt with MIT License 6 votes vote down vote up
public ServiceViewer() {
    FXMLLoader fxmlLoader = new FXMLLoader(
            getClass().getResource("ServiceViewer.fxml"));

    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);

    try {
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }

    TreeItem<BrowserItem> root = new TreeBrowserItem(new ServiceRootBrowserItem());
    root.setExpanded(true);
    servicesTreeTable.setRoot(root);
    servicesTreeTable.setShowRoot(false);
    servicesTreeTable.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
    TreeTableColumn<BrowserItem,String> nameCol = new TreeTableColumn<>("Name");
    TreeTableColumn<BrowserItem,String> descriptionCol = new TreeTableColumn<>("Description");

    servicesTreeTable.getColumns().setAll(nameCol, descriptionCol);

    nameCol.setCellValueFactory(new TreeItemPropertyValueFactory<>("name"));
    descriptionCol.setCellValueFactory(new TreeItemPropertyValueFactory<>("description"));
}
 
Example 3
Source File: EditableTreeTable.java    From Open-Lowcode with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * generates the root column showing label of line elements
 */
private void generateRootColumn() {

	TreeTableColumn<
			EditableTreeTableLineItem<Wrapper<E>>,
			String> rootcolumn = new TreeTableColumn<EditableTreeTableLineItem<Wrapper<E>>, String>("Item");
	rootcolumn.setCellValueFactory(new Callback<
			CellDataFeatures<EditableTreeTableLineItem<Wrapper<E>>, String>, ObservableValue<String>>() {

		@Override
		public ObservableValue<String> call(CellDataFeatures<EditableTreeTableLineItem<Wrapper<E>>, String> param) {
			return new SimpleStringProperty(param.getValue().getValue().getLabel());
		}
	});

	treetableview.getColumns().add(rootcolumn);
}
 
Example 4
Source File: CIntegerField.java    From Open-Lowcode with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TreeTableColumn<ObjectDataElt, Integer> getTreeTableColumn(
		PageActionManager pageactionmanager,
		String actionkeyforupdate) {
	TreeTableColumn<
			ObjectDataElt, Integer> thiscolumn = new TreeTableColumn<ObjectDataElt, Integer>(this.getLabel());
	if (actionkeyforupdate != null)
		thiscolumn.setEditable(true);
	int length = 110;
	thiscolumn.setMinWidth(length);
	CIntegerField thisdecimalfield = this;
	thiscolumn.setCellValueFactory(
			new Callback<TreeTableColumn.CellDataFeatures<ObjectDataElt, Integer>, ObservableValue<Integer>>() {

				@Override
				public ObservableValue<Integer> call(
						javafx.scene.control.TreeTableColumn.CellDataFeatures<ObjectDataElt, Integer> p) {
					ObjectDataElt line = p.getValue().getValue();
					String fieldname = thisdecimalfield.getFieldname();
					if (line == null)
						return new SimpleObjectProperty<Integer>(null);
					SimpleDataElt lineelement = line.lookupEltByName(fieldname);

					if (lineelement == null)
						return new SimpleObjectProperty<Integer>(null);
					if (!(lineelement instanceof IntegerDataElt))
						return new SimpleObjectProperty<Integer>(null);
					IntegerDataElt linedataelt = (IntegerDataElt) lineelement;
					return new SimpleObjectProperty<Integer>(linedataelt.getPayload());
				}

			});

	return thiscolumn;
}
 
Example 5
Source File: FeaturesType.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
@Nonnull
public List<TreeTableColumn<ModularFeatureListRow, Object>> createSubColumns(
    final @Nullable RawDataFile raw) {
  List<TreeTableColumn<ModularFeatureListRow, Object>> cols = new ArrayList<>();
  // create bar chart
  TreeTableColumn<ModularFeatureListRow, Object> barsCol = new TreeTableColumn<>("Area Bars");
  barsCol.setCellValueFactory(new DataTypeCellValueFactory(null, this));
  barsCol.setCellFactory(new DataTypeCellFactory(null, this, cols.size()));
  cols.add(barsCol);

  TreeTableColumn<ModularFeatureListRow, Object> sharesCol = new TreeTableColumn<>("Area Share");
  sharesCol.setCellValueFactory(new DataTypeCellValueFactory(null, this));
  sharesCol.setCellFactory(new DataTypeCellFactory(null, this, cols.size()));
  cols.add(sharesCol);

  TreeTableColumn<ModularFeatureListRow, Object> shapes = new TreeTableColumn<>("Shapes");
  shapes.setCellValueFactory(new DataTypeCellValueFactory(null, this));
  shapes.setCellFactory(new DataTypeCellFactory(null, this, cols.size()));
  cols.add(shapes);

  /*
   * sample columns are created in the FeatureListFX class
   */

  return cols;
}
 
Example 6
Source File: DataType.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a TreeTableColumn or null if the value is not represented in a column. A
 * {@link SubColumnsFactory} DataType can also add multiple sub columns to the main column
 * generated by this class.
 * 
 * @param raw null if this is a FeatureListRow column. For Feature columns: the raw data file
 *        specifies the feature.
 * 
 * @return the TreeTableColumn or null if this DataType.value is not represented in a column
 */
@Nullable
public TreeTableColumn<ModularFeatureListRow, Object> createColumn(
    final @Nullable RawDataFile raw) {
  if (this instanceof NullColumnType)
    return null;
  // create column
  TreeTableColumn<ModularFeatureListRow, Object> col = new TreeTableColumn<>(getHeaderString());

  if (this instanceof SubColumnsFactory) {
    col.setSortable(false);
    // add sub columns (no value factory needed for parent column)
    List<TreeTableColumn<ModularFeatureListRow, ?>> children =
        ((SubColumnsFactory) this).createSubColumns(raw);
    col.getColumns().addAll(children);
    return col;
  } else {
    col.setSortable(true);
    // define observable
    DataTypeCellValueFactory cvFactory = new DataTypeCellValueFactory(raw, this);
    col.setCellValueFactory(cvFactory);
    // value representation
    if (this instanceof EditableColumnType) {
      col.setCellFactory(new EditableDataTypeCellFactory(raw, this));
      col.setEditable(true);
      col.setOnEditCommit(event -> {
        Object data = event.getNewValue();
        if (data != null) {
          if (raw == null)
            event.getRowValue().getValue().set(this, data);
          else
            event.getRowValue().getValue().getFeatures().get(raw).set(this, data);
        }
      });
    } else
      col.setCellFactory(new DataTypeCellFactory(raw, this));
  }
  return col;
}
 
Example 7
Source File: DefaultTreeTable.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
protected void addColumnString (String heading, int width, Justification justification,
    String propertyName)
{
  TreeTableColumn<T, String> column = new TreeTableColumn<> (heading);
  column.setPrefWidth (width);
  column
      .setCellValueFactory (new TreeItemPropertyValueFactory<T, String> (propertyName));
  getColumns ().add (column);

  if (justification == Justification.CENTER)
    column.setStyle ("-fx-alignment: CENTER;");
}
 
Example 8
Source File: DefaultTreeTable.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
protected void addColumnNumber (String heading, int width, String propertyName)
{
  TreeTableColumn<T, Number> column = new TreeTableColumn<> (heading);
  column.setPrefWidth (width);
  column
      .setCellValueFactory (new TreeItemPropertyValueFactory<T, Number> (propertyName));
  getColumns ().add (column);
  column.setStyle ("-fx-alignment: CENTER-RIGHT;");
}
 
Example 9
Source File: DefaultTreeTable.java    From dm3270 with Apache License 2.0 5 votes vote down vote up
protected void addColumnString (String heading, int width, Justification justification,
    String propertyName)
{
  TreeTableColumn<T, String> column = new TreeTableColumn<> (heading);
  column.setPrefWidth (width);
  column
      .setCellValueFactory (new TreeItemPropertyValueFactory<T, String> (propertyName));
  getColumns ().add (column);

  if (justification == Justification.CENTER)
    column.setStyle ("-fx-alignment: CENTER;");
}
 
Example 10
Source File: DefaultTreeTable.java    From dm3270 with Apache License 2.0 5 votes vote down vote up
protected void addColumnNumber (String heading, int width, String propertyName)
{
  TreeTableColumn<T, Number> column = new TreeTableColumn<> (heading);
  column.setPrefWidth (width);
  column
      .setCellValueFactory (new TreeItemPropertyValueFactory<T, Number> (propertyName));
  getColumns ().add (column);
  column.setStyle ("-fx-alignment: CENTER-RIGHT;");
}
 
Example 11
Source File: FormulaFunctionViewer.java    From diirt with MIT License 5 votes vote down vote up
public FormulaFunctionViewer() {
        FXMLLoader fxmlLoader = new FXMLLoader(
                getClass().getResource("FormulaFunctionViewer.fxml"));

        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);

        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
//        functionsTreeTable = new TreeTableView<>();
//        setHgrow(functionsTreeTable, Priority.ALWAYS);
        TreeItem<BrowserItem> root = new TreeBrowserItem(new FormulaFunctionRootBrowserItem());
        root.setExpanded(true);
        functionsTreeTable.setRoot(root);
        functionsTreeTable.setShowRoot(false);
        functionsTreeTable.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
        TreeTableColumn<BrowserItem,String> nameCol = new TreeTableColumn<>("Name");
        TreeTableColumn<BrowserItem,String> descriptionCol = new TreeTableColumn<>("Description");

        functionsTreeTable.getColumns().setAll(nameCol, descriptionCol);

        nameCol.setCellValueFactory(new TreeItemPropertyValueFactory<>("name"));
        descriptionCol.setCellValueFactory(new TreeItemPropertyValueFactory<>("description"));
    }
 
Example 12
Source File: CChoiceField.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TreeTableColumn<ObjectDataElt, String> getTreeTableColumn(
		PageActionManager pageactionmanager,
		String actionkeyforupdate) {

	TreeTableColumn<ObjectDataElt, String> thiscolumn = new TreeTableColumn<ObjectDataElt, String>(this.getLabel());
	thiscolumn.setEditable(true);
	int length = (this.maxcharlength * 7);
	if (length > 300)
		length = 300;
	if (this.prefereddisplaysizeintable >= 0) {
		length = this.prefereddisplaysizeintable * 7;

	}
	logger.fine(" --**-- length for field" + this.getLabel() + " maxcharlength:" + maxcharlength
			+ " pref display in table " + this.prefereddisplaysizeintable + " final length = " + length);

	thiscolumn.setMinWidth(length);
	thiscolumn.setPrefWidth(length);
	CChoiceField thischoicefield = this;
	thiscolumn.setCellValueFactory(
			new Callback<TreeTableColumn.CellDataFeatures<ObjectDataElt, String>, ObservableValue<String>>() {

				@Override
				public ObservableValue<String> call(
						javafx.scene.control.TreeTableColumn.CellDataFeatures<ObjectDataElt, String> p) {

					ObjectDataElt line = p.getValue().getValue();
					String fieldname = thischoicefield.getFieldname();
					if (line == null)
						return new SimpleStringProperty("");
					SimpleDataElt lineelement = line.lookupEltByName(fieldname);
					if (lineelement == null) {

						return new SimpleStringProperty("Field Not found !" + fieldname);
					}
					String code = lineelement.defaultTextRepresentation();
					String displaystring = "Invalid code: " + code; // by default code is invalid
					if (code.length() == 0)
						displaystring = ""; // or empty
					CChoiceFieldValue displayvalue = valuesbycode.get(code); // try to get display value
					if (displayvalue != null)
						displaystring = displayvalue.getDisplayvalue();
					return new SimpleStringProperty(displaystring);
				}

			});
	return thiscolumn;
}
 
Example 13
Source File: CTextField.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TreeTableColumn<ObjectDataElt, ?> getTreeTableColumn(
		PageActionManager pageactionmanager,
		String actionkeyforupdate) {
	TreeTableColumn<ObjectDataElt, String> thiscolumn = new TreeTableColumn<ObjectDataElt, String>(this.getLabel());

	if (actionkeyforupdate != null)
		thiscolumn.setEditable(true);
	int length = 20 + this.maxlength * 6;

	if (length > 150)
		length = 150;
	if (this.prefereddisplaysizeintable >= 0) {
		logger.severe(
				"dirty log: prefereddisplayintable " + this.prefereddisplaysizeintable + "," + this.getLabel());
		length = this.prefereddisplaysizeintable * 5;
	}

	if (length > MAXROWWIDTH) {
		length = MAXROWWIDTH;
		LOGGER.finer("for column " + this.getFieldname() + ", reduced max row width to " + length);

	}

	thiscolumn.setMinWidth(length);
	thiscolumn.setPrefWidth(length);
	CTextField thistextfield = this;
	thiscolumn.setCellValueFactory(
			new Callback<TreeTableColumn.CellDataFeatures<ObjectDataElt, String>, ObservableValue<String>>() {

				@Override
				public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<ObjectDataElt, String> p) {
					try {
						ObjectDataElt line = p.getValue().getValue();
						String fieldname = thistextfield.getFieldname();
						if (line == null)
							return new SimpleStringProperty("");
						SimpleDataElt lineelement = line.lookupEltByName(fieldname);
						if (lineelement == null)
							return new SimpleStringProperty("Field Not found !" + fieldname);
						if (!richtextedit)
							return new SimpleStringProperty(lineelement.defaultTextRepresentation());
						String text = lineelement.defaultTextRepresentation();
						RichText richtext = new RichText(text);
						return new SimpleStringProperty(richtext.generatePlainString());
					} catch (Exception e) {
						logger.warning("Exception while building observable value " + e.getMessage());
						for (int i = 0; i < e.getStackTrace().length; i++)
							logger.warning("    " + e.getStackTrace()[i]);
						pageactionmanager.getClientSession().getActiveClientDisplay()
								.updateStatusBar("Error in building cell value " + e.getMessage(), true);
						return new SimpleStringProperty("ERROR");
					}
				}

			});

	return thiscolumn;
}
 
Example 14
Source File: CDecimalField.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TreeTableColumn<ObjectDataElt, LockableBigDecimal> getTreeTableColumn(
		PageActionManager pageactionmanager,
		String actionkeyforupdate) {
	TreeTableColumn<
			ObjectDataElt, LockableBigDecimal> thiscolumn = new TreeTableColumn<ObjectDataElt, LockableBigDecimal>(
					this.getLabel());
	thiscolumn.setEditable(true);
	thiscolumn.setStyle("-fx-alignment: CENTER-RIGHT;");
	int length = 110;
	thiscolumn.setMinWidth(length);
	CDecimalField thisdecimalfield = this;

	BigDecimalFormatValidator validator = new BigDecimalFormatValidator(precision, scale);
	// big display disabled as hardcoded
	thiscolumn.setCellFactory(column -> {
		return new LargeTextTreeTableCell<ObjectDataElt, LockableBigDecimal>(
				new NiceLockableBigDecimalStringConverter(precision, scale), validator, this.decimalformatter,
				false, true,1) {
			@Override
			public void updateItem(LockableBigDecimal decimal, boolean empty) {
				logger.fine("Updating field for decimal = " + decimal + " empty = " + empty);
				super.updateItem(decimal, empty);

				super.setMaxHeight(12);
				super.setPrefHeight(12);
				super.setMinHeight(12);
				if (decimal != null) {
					if (decimal.isLocked()) {
						logger.fine("set to lock");

						super.setEditable(false);
					} else {
						logger.fine("set to unlock");

						super.setEditable(true);
					}
				}

			}

		};
	});

	thiscolumn.setCellValueFactory(new Callback<
			TreeTableColumn.CellDataFeatures<ObjectDataElt, LockableBigDecimal>,
			ObservableValue<LockableBigDecimal>>() {

		@Override
		public ObservableValue<LockableBigDecimal> call(
				TreeTableColumn.CellDataFeatures<ObjectDataElt, LockableBigDecimal> p) {

			SimpleDataElt lineelement = p.getValue().getValue().lookupEltByName(thisdecimalfield.getFieldname());
			if (lineelement == null)
				return new SimpleObjectProperty<LockableBigDecimal>(null);
			if (!(lineelement instanceof DecimalDataElt))
				return new SimpleObjectProperty<LockableBigDecimal>(null);
			DecimalDataElt linedataelt = (DecimalDataElt) lineelement;
			boolean locked = true;

			logger.finest("      *-*-*-* processing DecimalDataElt " + Integer.toHexString(linedataelt.hashCode())
					+ " locked = " + linedataelt.islocked() + ", payload = " + linedataelt.getPayload() + " name = "
					+ linedataelt.getName());
			return new SimpleObjectProperty<LockableBigDecimal>(
					new LockableBigDecimal(locked, linedataelt.getPayload()));

		}

	});

	return thiscolumn;
}
 
Example 15
Source File: CDateField.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TreeTableColumn<ObjectDataElt, Date> getTreeTableColumn(
		PageActionManager pageactionmanager,
		String actionkeyforupdate) {
	TreeTableColumn<ObjectDataElt, Date> thiscolumn = new TreeTableColumn<ObjectDataElt, Date>(this.getLabel());
	thiscolumn.setEditable(true);
	int length = 110;
	thiscolumn.setMinWidth(length);
	thiscolumn.setCellFactory(column -> {
		return new TreeTableCell<ObjectDataElt, Date>() {
			@Override
			protected void updateItem(Date date, boolean empty) {
				super.updateItem(date, empty);
				if (date == null || empty) {
					setText(null);

				} else {
					setText(dateformat.format(date));

					this.setTooltip(new Tooltip(fulldateformat.format(date)));
				}

			}
		};
	});
	CDateField thisdatefield = this;
	thiscolumn.setCellValueFactory(
			new Callback<TreeTableColumn.CellDataFeatures<ObjectDataElt, Date>, ObservableValue<Date>>() {

				@Override
				public ObservableValue<Date> call(
						javafx.scene.control.TreeTableColumn.CellDataFeatures<ObjectDataElt, Date> p) {
					ObjectDataElt line = p.getValue().getValue();
					String fieldname = thisdatefield.getFieldname();
					if (line == null)
						return new SimpleObjectProperty<Date>(null);
					SimpleDataElt lineelement = line.lookupEltByName(fieldname);

					if (lineelement == null)
						return new SimpleObjectProperty<Date>(null);
					if (!(lineelement instanceof DateDataElt))
						return new SimpleObjectProperty<Date>(null);
					DateDataElt linedataelt = (DateDataElt) lineelement;
					return new SimpleObjectProperty<Date>(linedataelt.getPayload());
				}

			});

	return thiscolumn;
}
 
Example 16
Source File: CMultipleChoiceField.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TreeTableColumn<ObjectDataElt, ?> getTreeTableColumn(
		PageActionManager pageactionmanager,
		String actionkeyforupdate) {
	TreeTableColumn<ObjectDataElt, String> thiscolumn = new TreeTableColumn<ObjectDataElt, String>(this.getLabel());
	thiscolumn.setEditable(true);
	int length = (this.maxcharlength * 7);
	if (length > 300)
		length = 300;
	if (this.prefereddisplayintable >= 0) {
		length = this.prefereddisplayintable * 7;

	}
	logger.fine(" --**-- length for field" + this.getLabel() + " maxcharlength:" + maxcharlength
			+ " pref display in table " + this.prefereddisplayintable + " final length = " + length);

	thiscolumn.setMinWidth(length);
	thiscolumn.setPrefWidth(length);
	CMultipleChoiceField thischoicefield = this;
	thiscolumn.setCellValueFactory(
			new Callback<TreeTableColumn.CellDataFeatures<ObjectDataElt, String>, ObservableValue<String>>() {

				@SuppressWarnings("unchecked")
				@Override
				public ObservableValue<String> call(
						javafx.scene.control.TreeTableColumn.CellDataFeatures<ObjectDataElt, String> p) {

					ObjectDataElt line = p.getValue().getValue();
					String fieldname = thischoicefield.getFieldname();
					if (line == null)
						return new SimpleStringProperty("");
					SimpleDataElt lineelement = line.lookupEltByName(fieldname);
					if (lineelement == null) {

						return new SimpleStringProperty("Field Not found !" + fieldname);
					}
					if (!(lineelement instanceof MultipleChoiceDataElt))
						return new SimpleStringProperty("Invalid type " + lineelement.getType());

					return new SimpleStringProperty(thischoicefield
							.displayMultiValue((MultipleChoiceDataElt<CChoiceFieldValue>) lineelement));
				}

			});
	return thiscolumn;
}
 
Example 17
Source File: FileBrowserController.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@FXML
public void initialize() {
    treeView.setShowRoot(false);
    treeView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    // Create table columns
    final TreeTableColumn<FileInfo, File> name_col = new TreeTableColumn<>(Messages.ColName);
    name_col.setPrefWidth(200);
    name_col.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().getValue().file));
    name_col.setCellFactory(info -> new FileTreeCell());
    name_col.setComparator(FileTreeItem.fileTreeItemComparator);
    treeView.getColumns().add(name_col);

    // Linux (Gnome) and Mac file browsers list size before time
    final TreeTableColumn<FileInfo, Number> size_col = new TreeTableColumn<>(Messages.ColSize);
    size_col.setCellValueFactory(p -> p.getValue().getValue().size);
    size_col.setCellFactory(info -> new FileSizeCell());
    treeView.getColumns().add(size_col);

    final TreeTableColumn<FileInfo, String> time_col = new TreeTableColumn<>(Messages.ColTime);
    time_col.setCellValueFactory(p -> p.getValue().getValue().time);
    treeView.getColumns().add(time_col);

    // This would cause columns to fill table width,
    // but _always_ does that, not allowing us to restore
    // saved widths from memento:
    // treeView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);

    // Last column fills remaining space

    final InvalidationListener resize = prop ->
    {
        // Available with, less space used for the TableMenuButton '+' on the right
        // so that the up/down column sort markers remain visible
        double available = treeView.getWidth() - 10;
        if (name_col.isVisible())
        {
            // Only name visible? Use the space!
            if (!size_col.isVisible() && !time_col.isVisible())
                name_col.setPrefWidth(available);
            else
                available -= name_col.getWidth();
        }
        if (size_col.isVisible())
        {
            if (! time_col.isVisible())
                size_col.setPrefWidth(available);
            else
                available -= size_col.getWidth();
        }
        if (time_col.isVisible())
            time_col.setPrefWidth(available);
    };
    treeView.widthProperty().addListener(resize);
    name_col.widthProperty().addListener(resize);
    size_col.widthProperty().addListener(resize);
    name_col.visibleProperty().addListener(resize);
    size_col.visibleProperty().addListener(resize);
    time_col.visibleProperty().addListener(resize);

    // Allow users to show/hide columns
    treeView.setTableMenuButtonVisible(true);

    // Prepare ContextMenu items
    open.setOnAction(event -> openSelectedResources());
    contextMenu.getItems().addAll(open, openWith);

    treeView.setOnKeyPressed(this::handleKeys);
}
 
Example 18
Source File: FxTreeTable.java    From FxDock with Apache License 2.0 4 votes vote down vote up
public void setCellValueFactory(FxTreeTableCellValueFactory<T> f)
{
	 TreeTableColumn c = lastColumn();
	 c.setCellValueFactory(f);
}
 
Example 19
Source File: CTimePeriodField.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TreeTableColumn<ObjectDataElt, ?> getTreeTableColumn(
		PageActionManager pageactionmanager,
		String actionkeyforupdate) {
	TreeTableColumn<ObjectDataElt, String> thiscolumn = new TreeTableColumn<ObjectDataElt, String>(this.getLabel());
	thiscolumn.setEditable(true);
	int length = 20 * 7;
	if (this.prefereddisplayintable >= 0) {
		length = this.prefereddisplayintable * 7;

	}

	thiscolumn.setMinWidth(length);
	thiscolumn.setPrefWidth(length);
	CTimePeriodField thistimeperiodfield = this;
	thiscolumn.setCellValueFactory(new javafx.util.Callback<
			TreeTableColumn.CellDataFeatures<ObjectDataElt, String>, ObservableValue<String>>() {

		@Override
		public ObservableValue<String> call(
				javafx.scene.control.TreeTableColumn.CellDataFeatures<ObjectDataElt, String> p) {

			ObjectDataElt line = p.getValue().getValue();
			String fieldname = thistimeperiodfield.getFieldname();
			if (line == null)
				return new SimpleStringProperty("");
			SimpleDataElt lineelement = line.lookupEltByName(fieldname);
			String displayasstring = "Field Not found or bad type: " + fieldname + "/"
					+ (lineelement != null ? lineelement.getClass() : "NULL");

			if (lineelement != null)
				if (lineelement instanceof TimePeriodDataElt) {
					TimePeriodDataElt tpelement = (TimePeriodDataElt) lineelement;
					return new SimpleStringProperty(
							tpelement.getPayload() != null ? tpelement.getPayload().toString() : "");
				}
			if (lineelement != null)
				if (lineelement instanceof TextDataElt) {
					TextDataElt text = (TextDataElt) lineelement;
					TimePeriod tp = TimePeriod.generateFromString(text.getPayload());
					return new SimpleStringProperty(tp != null ? tp.toString() : "");
				}

			return new SimpleStringProperty(displayasstring);
		}

	});
	return thiscolumn;
}