private void saveColumnVisibility() {
    final boolean[] columnVisibility = new boolean[treeTableView.getColumns().size()];

    for (int i = 0; i < columnVisibility.length; i++) {
      columnVisibility[i] = treeTableView.getColumns().get(i).isVisible();
    }

    preferences.put(COLUMN_VISIBILITY, EncodeDecode.encodeBooleanArray(columnVisibility));
  }
 @Override
 public void start(Stage primaryStage) {
   primaryStage.setTitle("TreeTable View Sample");
   primaryStage.setScene(new Scene(new ChoiceBoxTreeTableSample()));
   primaryStage.sizeToScene();
   primaryStage.show();
   TreeTableView<?> treeTableView =
       (TreeTableView<?>) primaryStage.getScene().getRoot().lookup(".tree-table-view");
   treeTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
 }
  private void restoreColumnVisibility() {
    final String result = preferences.get(COLUMN_VISIBILITY, null);

    if (result != null) {
      boolean[] columnVisibility = EncodeDecode.decodeBooleanArray(result);

      if (columnVisibility.length == treeTableView.getColumns().size()) {
        for (int i = 0; i < columnVisibility.length; i++) {
          treeTableView.getColumns().get(i).setVisible(columnVisibility[i]);
        }
      }
    }
  }
  private void loadAccountTree() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

    if (engine != null) {
      RootAccount r = engine.getRootAccount();

      final TreeItem<Account> root = new TreeItem<>(r);
      root.setExpanded(true);

      treeTableView.setRoot(root);
      loadChildren(root);
    } else {
      treeTableView.setRoot(null);
    }
  }
  @FXML
  private void initialize() {
    deleteButton.setDisable(true);
    reconcileButton.setDisable(true);

    initializeTreeTableView();

    Platform.runLater(this::loadAccountTree);

    MessageBus.getInstance()
        .registerListener(
            this, MessageChannel.SYSTEM, MessageChannel.ACCOUNT, MessageChannel.TRANSACTION);

    // Register invalidation listeners to force a reload
    typeFilter.addListener(observable -> reload());

    selectedAccountProperty.addListener(
        (observable, oldValue, newValue) -> {
          updateButtonStates();
        });

    modifyButton.disableProperty().bind(selectedAccountProperty.isNull());

    AccountBalanceDisplayManager.getAccountBalanceDisplayModeProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              treeTableView.refresh();
            });
  }
  protected Node getTaskView() {

    if (taskTableView == null) {
      taskTableView = new TreeTableView<>(new TreeItem<>());
      taskTableView.setShowRoot(false);
    }

    if (taskDescriptionTreeTableColumn == null) {
      taskDescriptionTreeTableColumn = new TaskDescriptionTreeTableColumn();
      taskDescriptionTreeTableColumn.setPrefWidth(300);
      taskDescriptionTreeTableColumn.setMinWidth(300);
    }

    if (taskStatusTreeTableColumn == null) {
      taskStatusTreeTableColumn = new TaskStatusTreeTableColumn();
      taskStatusTreeTableColumn.setPrefWidth(30);
      taskStatusTreeTableColumn.setMinWidth(30);
    }

    AnchorPane anchorPane = new AnchorPane(taskTableView);
    anchorPane.setPadding(new Insets(6));

    AnchorPane.setTopAnchor(taskTableView, 0d);
    AnchorPane.setRightAnchor(taskTableView, 0d);
    AnchorPane.setBottomAnchor(taskTableView, 0d);
    AnchorPane.setLeftAnchor(taskTableView, 0d);
    return anchorPane;
  }
  private Optional<Account> getSelectedAccount() {
    final TreeItem<Account> treeItem = treeTableView.getSelectionModel().getSelectedItem();

    if (treeItem != null) {
      return Optional.ofNullable(treeItem.getValue());
    }

    return Optional.empty();
  }
  private void installListeners() {
    treeTableView
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              if (newValue != null) {
                selectedAccountProperty.setValue(newValue.getValue());
              } else {
                selectedAccountProperty.setValue(null);
              }
            });

    for (final TreeTableColumn<?, ?> treeTableColumn : treeTableView.getColumns()) {
      treeTableColumn
          .visibleProperty()
          .addListener((observable, oldValue, newValue) -> saveColumnVisibility());
    }
  }
Exemplo n.º 9
0
  private TreeTableView<ITreeNode> createTreeTableView(ProfileContainer container) {

    final List<Profile> profiles = container.getProfiles();
    final MyTreeNode rootNode = new MyTreeNode(null);
    for (Profile p : profiles) {
      final MyTreeNode profileNode = new MyTreeNode(p);
      rootNode.addChild(profileNode);

      profileNode.addChild(createTreeNodes(p.getTopLevelMethod()));
    }

    final MyTreeModel model = new MyTreeModel(rootNode, new MethodStatsHelper(container));

    final TreeItem<ITreeNode> root = model.toTreeItems();
    root.setExpanded(true);

    final TreeTableView<ITreeNode> treeTableView = new TreeTableView<>(root);

    for (int i = 0; i < model.getColumnCount(); i++) {
      final int columnNo = i;
      final TreeTableColumn<ITreeNode, String> newColumn =
          new TreeTableColumn<>(model.getColumnName(i));

      newColumn.setCellValueFactory(
          new Callback<
              TreeTableColumn.CellDataFeatures<ITreeNode, String>, ObservableValue<String>>() {

            @Override
            public ObservableValue<String> call(CellDataFeatures<ITreeNode, String> param) {
              return new ReadOnlyStringWrapper(
                  model.getValue(param.getValue().getValue(), columnNo));
            }
          });
      treeTableView.getColumns().add(newColumn);
    }

    treeTableView.setShowRoot(false);
    return treeTableView;
  }
Exemplo n.º 10
0
  @Override
  public void start(Stage stage) {
    final Parameters params = getParameters();
    final List<String> parameters = params.getRaw();

    if (parameters.size() != 1) {
      throw new RuntimeException(
          "Bad command line arguments, expected exactly one argument (XML file to load)");
    }

    final String fileToLoad = parameters.get(0);

    final ProfileContainer profiles;
    try {
      FileInputStream in = new FileInputStream(fileToLoad);
      profiles = new XMLSerializer().load(in);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    final TreeTableView<ITreeNode> treeTable = createTreeTableView(profiles);

    treeTable.setPrefSize(2000, 2000);
    stage.setTitle("Profiling results: " + fileToLoad);

    stage.setResizable(true);

    final Scene scene = new Scene(new Group(), 1000, 1000);

    final Group sceneRoot = (Group) scene.getRoot();
    sceneRoot.setAutoSizeChildren(true);

    sceneRoot.getChildren().add(treeTable);

    stage.setScene(scene);
    stage.show();
  }
Exemplo n.º 11
0
  @Override
  public void messagePosted(final Message event) {

    switch (event.getEvent()) {
      case ACCOUNT_ADD:
      case ACCOUNT_MODIFY:
      case ACCOUNT_REMOVE:
        reload();
        break;
      case TRANSACTION_ADD:
      case TRANSACTION_REMOVE:
        treeTableView
            .refresh(); // TODO implement a better model that listens to account balance changes
        break;
      case FILE_CLOSING:
        Platform.runLater(() -> treeTableView.setRoot(null));
        MessageBus.getInstance()
            .unregisterListener(
                this, MessageChannel.SYSTEM, MessageChannel.ACCOUNT, MessageChannel.TRANSACTION);
        break;
      default:
        break;
    }
  }
  public void writeDataToExcel(Sheet sheet) {
    LOGGER.debug("[{}] Exporting data to excel", getText());

    List<ExcelColumnRenderer> columnRendererList = new ArrayList<>();
    columnRendererList.add(new TaskStatusExcelColumn());
    columnRendererList.add(new TaskDescriptionExcelColumn());

    TimerangeProvider timerangeProvider = fetchTimereportContext.get().getTimerangeProvider();
    LocalDate startDate = timerangeProvider.getStartDate();
    LocalDate endDate = timerangeProvider.getEndDate();

    long amountOfDaysToDisplay = ChronoUnit.DAYS.between(startDate, endDate);
    for (int days = 0; days <= amountOfDaysToDisplay; days++) {
      LocalDate currentColumnDate = timerangeProvider.getStartDate().plus(days, ChronoUnit.DAYS);
      String displayDate = FormattingUtil.formatDate(currentColumnDate);
      columnRendererList.add(new WorklogExcelColumn(displayDate, currentColumnDate));
    }

    columnRendererList.add(new TaskWorklogSummaryExcelColumn());

    TreeItem<DisplayRow> root = taskTableView.getRoot();
    ObservableList<TreeItem<DisplayRow>> children = root.getChildren();

    for (int columnIndex = 0; columnIndex < columnRendererList.size(); columnIndex++) {
      ExcelColumnRenderer excelColumnRenderer = columnRendererList.get(columnIndex);
      excelColumnRenderer.renderCells(
          columnIndex,
          sheet,
          children,
          fetchTimereportContext.get().getGroupByCategory().isPresent());
    }

    // autosize column widths
    for (int i = 0; i < columnRendererList.size(); i++) {
      sheet.autoSizeColumn(i);
    }
  }
Exemplo n.º 13
0
  @SuppressWarnings("unchecked")
  private void initializeTreeTableView() {
    treeTableView.setShowRoot(false); // don't show the root
    treeTableView.setEditable(true); // required for editable columns
    treeTableView.setTableMenuButtonVisible(true);

    // force resize policy for better default appearance
    treeTableView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);

    final TreeTableColumn<Account, String> nameColumn =
        new TreeTableColumn<>(resources.getString("Column.Account"));
    nameColumn.setCellValueFactory(
        param -> new ReadOnlyStringWrapper(param.getValue().getValue().getName()));

    final TreeTableColumn<Account, Integer> entriesColumn =
        new TreeTableColumn<>(resources.getString("Column.Entries"));
    entriesColumn.setCellValueFactory(
        param ->
            new SimpleIntegerProperty(param.getValue().getValue().getTransactionCount())
                .asObject());

    final TreeTableColumn<Account, BigDecimal> balanceColumn =
        new TreeTableColumn<>(resources.getString("Column.Balance"));
    balanceColumn.setCellValueFactory(
        param ->
            new ReadOnlyObjectWrapper<>(
                AccountBalanceDisplayManager.convertToSelectedBalanceMode(
                    param.getValue().getValue().getAccountType(),
                    param.getValue().getValue().getTreeBalance())));
    balanceColumn.setCellFactory(cell -> new AccountCommodityFormatTreeTableCell());

    final TreeTableColumn<Account, BigDecimal> reconciledBalanceColumn =
        new TreeTableColumn<>(resources.getString("Column.ReconciledBalance"));
    reconciledBalanceColumn.setCellValueFactory(
        param ->
            new ReadOnlyObjectWrapper<>(
                AccountBalanceDisplayManager.convertToSelectedBalanceMode(
                    param.getValue().getValue().getAccountType(),
                    param.getValue().getValue().getReconciledTreeBalance())));
    reconciledBalanceColumn.setCellFactory(cell -> new AccountCommodityFormatTreeTableCell());

    final TreeTableColumn<Account, String> currencyColumn =
        new TreeTableColumn<>(resources.getString("Column.Currency"));
    currencyColumn.setCellValueFactory(
        param ->
            new ReadOnlyStringWrapper(param.getValue().getValue().getCurrencyNode().getSymbol()));

    final TreeTableColumn<Account, String> typeColumn =
        new TreeTableColumn<>(resources.getString("Column.Type"));
    typeColumn.setCellValueFactory(
        param ->
            new ReadOnlyStringWrapper(param.getValue().getValue().getAccountType().toString()));

    final TreeTableColumn<Account, Integer> codeColumn =
        new TreeTableColumn<>(resources.getString("Column.Code"));
    codeColumn.setEditable(true);
    codeColumn.setCellValueFactory(
        param ->
            new SimpleIntegerProperty(param.getValue().getValue().getAccountCode()).asObject());
    codeColumn.setCellFactory(param -> new IntegerEditingTreeTableCell());
    codeColumn.setOnEditCommit(
        event -> updateAccountCode(event.getRowValue().getValue(), event.getNewValue()));

    treeTableView
        .getColumns()
        .addAll(
            nameColumn,
            codeColumn,
            entriesColumn,
            balanceColumn,
            reconciledBalanceColumn,
            currencyColumn,
            typeColumn);

    restoreColumnVisibility();

    installListeners();
  }
Exemplo n.º 14
0
  public void assignSampleData(FXOMObject startObject) {
    assert startObject != null;

    final Object sceneGraphObject = startObject.getSceneGraphObject();
    final AbstractSampleData currentData = sampleDataMap.get(startObject);
    final AbstractSampleData newData;

    if (sceneGraphObject == null) {
      // startObject is unresolved
      newData = null;
    } else {
      final Class<?> sceneGraphClass = sceneGraphObject.getClass();
      if (sceneGraphClass == ChoiceBox.class) {
        final ChoiceBox<?> choiceBox = (ChoiceBox) sceneGraphObject;
        if (choiceBox.getItems().isEmpty()) {
          if (currentData instanceof ChoiceBoxSampleData) {
            newData = currentData;
          } else {
            newData = new ChoiceBoxSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == ComboBox.class) {
        final ComboBox<?> comboBox = (ComboBox) sceneGraphObject;
        if (comboBox.getItems().isEmpty()) {
          if (currentData instanceof ComboBoxSampleData) {
            newData = currentData;
          } else {
            newData = new ComboBoxSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == ListView.class) {
        final ListView<?> listView = (ListView) sceneGraphObject;
        if (listView.getItems().isEmpty()) {
          if (currentData instanceof ListViewSampleData) {
            newData = currentData;
          } else {
            newData = new ListViewSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == TreeView.class) {
        final TreeView<?> treeView = (TreeView) sceneGraphObject;
        if (treeView.getRoot() == null) {
          if (currentData instanceof TreeViewSampleData) {
            newData = currentData;
          } else {
            newData = new TreeViewSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == TableView.class) {
        final TableView<?> treeView = (TableView) sceneGraphObject;
        if (TableViewSampleData.canApplyTo(treeView)) {
          if (currentData instanceof TableViewSampleData) {
            newData = currentData;
          } else {
            newData = new TableViewSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == TreeTableView.class) {
        final TreeTableView<?> treeTableView = (TreeTableView) sceneGraphObject;
        if (treeTableView.getRoot() == null) {
          if (currentData instanceof TreeTableViewSampleData) {
            newData = currentData;
          } else {
            newData = new TreeTableViewSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == PieChart.class) {
        final PieChart pieChart = (PieChart) sceneGraphObject;
        if (pieChart.getData().isEmpty()) {
          if (currentData instanceof PieChartSampleData) {
            newData = currentData;
          } else {
            newData = new PieChartSampleData();
          }
        } else {
          newData = null;
        }
      } else if (XYChartSampleData.isKnownXYChart(sceneGraphObject)) {
        final XYChart<?, ?> xyChart = (XYChart) sceneGraphObject;
        if (xyChart.getData().isEmpty()) {
          if (currentData instanceof XYChartSampleData) {
            newData = currentData;
          } else {
            newData = new XYChartSampleData();
          }
        } else {
          newData = null;
        }
      } else {
        newData = null;
      }
    }

    if (newData == null) {
      if (currentData != null) {
        sampleDataMap.remove(startObject);
      }
    } else {
      newData.applyTo(sceneGraphObject);
      sampleDataMap.put(startObject, newData);
    }

    if (startObject instanceof FXOMInstance) {
      final FXOMInstance fxomInstance = (FXOMInstance) startObject;
      for (FXOMProperty p : fxomInstance.getProperties().values()) {
        if (p instanceof FXOMPropertyC) {
          final FXOMPropertyC pc = (FXOMPropertyC) p;
          for (FXOMObject v : pc.getValues()) {
            assignSampleData(v);
          }
        }
      }
    } else if (startObject instanceof FXOMCollection) {
      final FXOMCollection fxomCollection = (FXOMCollection) startObject;
      for (FXOMObject i : fxomCollection.getItems()) {
        assignSampleData(i);
      }
    }
  }
  protected void refreshWorklogTableViewAndResults() {

    // return early if no data present or still the same data
    // as the last time this tab was active
    Optional<FetchTimereportContext> reportContextOptional = this.fetchTimereportContext;
    if (!reportContextOptional.isPresent()
        || !reportContextOptional.get().getResult().isPresent()
        || !resultToDisplayChangedSinceLastRender) {
      LOGGER.debug(
          "[{}] No results to display or data not changed. Not refreshing TableView and data",
          getText());
      return;
    }

    SettingsUtil.Settings settings = SettingsUtil.loadSettings();
    if (settings.isShowStatistics() && statisticsView == null
        || !settings.isShowStatistics() && statisticsView != null) {
      // statistics are disabled and were previously rendered
      // or statistics are enabled and weren't rendered before
      // update content view
      LOGGER.debug("Updating contentView since settings for statistics seemed to have changed");
      setContent(getContentNode());
    }

    FetchTimereportContext timereportContext = reportContextOptional.get();
    TimerangeProvider timerangeProvider = timereportContext.getTimerangeProvider();

    // render the table columns if the timerange changed from last result
    if (!lastUsedTimerangeProvider.isPresent()
        || !lastUsedTimerangeProvider.get().equals(timerangeProvider)
        || (lastCollapseState.isPresent() && lastCollapseState.get() != settings.getCollapseState())
        || (lastHighlightState.isPresent()
            && lastHighlightState.get() != settings.getHighlightState())) {

      LOGGER.debug(
          "[{}] Regenerating columns for timerange {}",
          getText(),
          timerangeProvider.getReportTimerange().name());
      taskTableView.getColumns().clear();
      taskTableView.getColumns().add(taskStatusTreeTableColumn);
      taskTableView.getColumns().add(taskDescriptionTreeTableColumn);

      // render tables for all days in the selected timerange
      // e.g. timerange current month renders a column for
      // each day of the current month
      long amountOfDaysToDisplay =
          ChronoUnit.DAYS.between(timerangeProvider.getStartDate(), timerangeProvider.getEndDate());

      for (int days = 0; days <= amountOfDaysToDisplay; days++) {
        LocalDate currentColumnDate = timerangeProvider.getStartDate().plus(days, ChronoUnit.DAYS);
        String displayDate = FormattingUtil.formatDate(currentColumnDate);

        // worklog column
        taskTableView.getColumns().add(new WorklogTreeTableColumn(displayDate, currentColumnDate));
      }

      // also add another summary per task column
      taskTableView.getColumns().add(new TaskWorklogSummaryTreeTableColumn());

      lastUsedTimerangeProvider = Optional.of(timerangeProvider);
      lastCollapseState = Optional.of(settings.getCollapseState());
      lastHighlightState = Optional.of(settings.getHighlightState());
    }

    // refresh data
    LOGGER.debug("[{}] Refreshing items in TableView", getText());

    TreeItem<DisplayRow> root = taskTableView.getRoot();
    root.getChildren().clear();

    DisplayData displayData =
        getDisplayData(timereportContext, resultToDisplayChangedSinceLastRender);
    root.getChildren().addAll(displayData.getTreeRows());

    resultToDisplayChangedSinceLastRender = false;
  }