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

The following examples show how to use javafx.scene.control.TreeTableColumn#setEditable() . 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: 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 2
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 3
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 4
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;
}
 
Example 5
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 6
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 7
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 8
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;
}