Skip to content

Commit

Permalink
I18N for context menus & Tree Diff View Ctx Menu bugfix
Browse files Browse the repository at this point in the history
The Tree Diff View wasn't displaying the context menus in most cases.
Tracked down the bug to the Context Menu binding code, which has now
been simplified and corrected.

As a side effect, some of the code which I had changed trying to fix the
issue, when I didn't know the root cause yet, is now cleaned up and has
been made consistent again (AbstractViewController column configuration
methods for TreeTable).

And, since the ctx menu util code had to be rewritten partially anyway,
I also put in the I18N changes.
  • Loading branch information
arickp authored and arickp committed Jan 9, 2017
1 parent 3f6082d commit 8ecdd6e
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 158 deletions.
Expand Up @@ -4,16 +4,13 @@
import static com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.TITLE_DIALOG_SPECIFYFILTERS; import static com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.TITLE_DIALOG_SPECIFYFILTERS;
import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.doubleDiffStyler; import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.doubleDiffStyler;
import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.intDiffStyler; import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.intDiffStyler;
import static com.insightfullogic.honest_profiler.ports.javafx.util.StyleUtil.stringDiffStyler;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_16; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_16;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_ACTIVE_16; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.FUNNEL_ACTIVE_16;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.viewFor; import static com.insightfullogic.honest_profiler.ports.javafx.view.Icon.viewFor;
import static com.insightfullogic.honest_profiler.ports.javafx.view.Rendering.renderPercentage;
import static javafx.scene.input.KeyCode.ENTER; import static javafx.scene.input.KeyCode.ENTER;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function;


import com.insightfullogic.honest_profiler.core.filters.Filter; import com.insightfullogic.honest_profiler.core.filters.Filter;
import com.insightfullogic.honest_profiler.core.filters.ProfileFilter; import com.insightfullogic.honest_profiler.core.filters.ProfileFilter;
Expand All @@ -31,22 +28,22 @@
import com.insightfullogic.honest_profiler.ports.javafx.view.cell.PercentageTreeTableCell; import com.insightfullogic.honest_profiler.ports.javafx.view.cell.PercentageTreeTableCell;


import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableColumn.CellDataFeatures;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TreeItemPropertyValueFactory;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;


/** /**
* Superclass for all View Controllers in the application. These controllers provide a particular view on data. The * Superclass for all View Controllers in the application. These controllers
* class holds the code for the filters and quick filter. * provide a particular view on data. The class holds the code for the filters
* and quick filter.
* *
* The superclass also provides some common UI helper methods for column configuration. * The superclass also provides some common UI helper methods for column
* configuration.
*/ */
public abstract class AbstractViewController extends AbstractController public abstract class AbstractViewController extends AbstractController
{ {
Expand All @@ -62,12 +59,16 @@ public abstract class AbstractViewController extends AbstractController
private StringFilter quickFilter; private StringFilter quickFilter;


/** /**
* This method must be called by subclasses in their FXML initialize(). It provides the controller-local UI nodes * This method must be called by subclasses in their FXML initialize(). It
* needed by the AbstractViewController. * provides the controller-local UI nodes needed by the
* AbstractViewController.
* *
* @param filterButton the button used to trigger filter editing * @param filterButton
* @param quickFilterButton the button used to apply the quick filter * the button used to trigger filter editing
* @param quickFilterText the TextField providing the value for the quick filter * @param quickFilterButton
* the button used to apply the quick filter
* @param quickFilterText
* the TextField providing the value for the quick filter
*/ */
protected void initialize(Button filterButton, Button quickFilterButton, protected void initialize(Button filterButton, Button quickFilterButton,
TextField quickFilterText) TextField quickFilterText)
Expand All @@ -87,10 +88,12 @@ protected void initialize(Button filterButton, Button quickFilterButton,
// Accessors // Accessors


/** /**
* In addition to the normal functionality, the method calls filter initialization, which needs the * In addition to the normal functionality, the method calls filter
* ApplicationContext to be present. If a particular view controller * initialization, which needs the ApplicationContext to be present. If a
* particular view controller
* *
* @param applicationContext the ApplicationContext of this application * @param applicationContext
* the ApplicationContext of this application
*/ */
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) public void setApplicationContext(ApplicationContext applicationContext)
Expand All @@ -106,8 +109,8 @@ public void setApplicationContext(ApplicationContext applicationContext)
} }


/** /**
* Refreshes the view. The view should be updated based on the current state of the {@link Profile} and * Refreshes the view. The view should be updated based on the current state
* {@link ProfileFilter}. * of the {@link Profile} and {@link ProfileFilter}.
*/ */
protected abstract void refresh(); protected abstract void refresh();


Expand Down Expand Up @@ -147,60 +150,46 @@ protected <T> void cfgCntDiffCol(TableColumn<T, Number> column, String propertyN
setColumnHeader(column, title, null); setColumnHeader(column, title, null);
} }


protected <T> void cfgPctCol(TreeTableColumn<T, String> column, Function<T, Double> accessor, protected <T> void cfgPctCol(TreeTableColumn<T, Number> column, String propertyName,
ProfileContext profileContext, String title) ProfileContext profileContext, String title)
{ {
column.setCellValueFactory(data -> wrapDouble(data, accessor)); column.setCellValueFactory(new TreeItemPropertyValueFactory<>(propertyName));
column.setCellFactory(col -> new PercentageTreeTableCell<>(null)); column.setCellFactory(col -> new PercentageTreeTableCell<>(doubleDiffStyler));
setColumnHeader(column, title, profileContext); setColumnHeader(column, title, profileContext);
} }


protected <T> void cfgPctDiffCol(TreeTableColumn<T, String> column, protected <T> void cfgPctDiffCol(TreeTableColumn<T, Number> column, String propertyName,
Function<T, Double> accessor, String title) String title)
{ {
column.setCellValueFactory(data -> wrapDouble(data, accessor)); column.setCellValueFactory(new TreeItemPropertyValueFactory<>(propertyName));
column.setCellFactory(col -> new PercentageTreeTableCell<>(stringDiffStyler)); column.setCellFactory(col -> new PercentageTreeTableCell<>(doubleDiffStyler));
setColumnHeader(column, title, null); setColumnHeader(column, title, null);
} }


protected <T> void cfgCntCol(TreeTableColumn<T, String> column, Function<T, Integer> accessor, protected <T> void cfgCntCol(TreeTableColumn<T, Number> column, String propertyName,
ProfileContext profileContext, String title) ProfileContext profileContext, String title)
{ {
column.setCellValueFactory(data -> wrapInt(data, accessor)); column.setCellValueFactory(new TreeItemPropertyValueFactory<>(propertyName));
column.setCellFactory(col -> new CountTreeTableCell<>(null)); column.setCellFactory(col -> new CountTreeTableCell<>(doubleDiffStyler));
setColumnHeader(column, title, profileContext); setColumnHeader(column, title, profileContext);
} }


protected <T> void cfgCntDiffCol(TreeTableColumn<T, String> column, protected <T> void cfgCntDiffCol(TreeTableColumn<T, Number> column, String propertyName,
Function<T, Integer> accessor, String title) String title)
{ {
column.setCellValueFactory(data -> wrapInt(data, accessor)); column.setCellValueFactory(new TreeItemPropertyValueFactory<>(propertyName));
column.setCellFactory(col -> new CountTreeTableCell<>(stringDiffStyler)); column.setCellFactory(col -> new CountTreeTableCell<>(doubleDiffStyler));
setColumnHeader(column, title, null); setColumnHeader(column, title, null);
} }


private <T> StringProperty wrapDouble(CellDataFeatures<T, String> data,
Function<T, Double> accessor)
{
return new ReadOnlyStringWrapper(
data.getValue().getValue() != null
? renderPercentage(accessor.apply(data.getValue().getValue())) : "");
}

private <T> StringProperty wrapInt(CellDataFeatures<T, String> data,
Function<T, Integer> accessor)
{
return new ReadOnlyStringWrapper(
data.getValue().getValue() != null
? Integer.toString(accessor.apply(data.getValue().getValue())) : "");
}

// Filter-related methods // Filter-related methods


/** /**
* View Controllers must implement this, and return the {@link FilterType}s which are supported by them. * View Controllers must implement this, and return the {@link FilterType}s
* which are supported by them.
* *
* @return an array containing the {@link FilterType}s supported by the view controller * @return an array containing the {@link FilterType}s supported by the view
* controller
*/ */
protected abstract FilterType[] getAllowedFilterTypes(); protected abstract FilterType[] getAllowedFilterTypes();


Expand All @@ -215,7 +204,8 @@ protected ObjectProperty<FilterSpecification> getFilterSpecification()
} }


/** /**
* Returns the currently active {@link ProfileFilter}, constructed from the current filters and the quick filter. * Returns the currently active {@link ProfileFilter}, constructed from the
* current filters and the quick filter.
* *
* @return the currently active {@link ProfileFilter} * @return the currently active {@link ProfileFilter}
*/ */
Expand All @@ -235,8 +225,10 @@ protected ProfileFilter getAdjustedProfileFilter()
/** /**
* Initializes the filters. * Initializes the filters.
* *
* @param applicationContext the {@link ApplicationContext}. The parameter is used to explicitly point out the * @param applicationContext
* dependency on the presense of the context. * the {@link ApplicationContext}. The parameter is used to
* explicitly point out the dependency on the presense of the
* context.
*/ */
private void initializeFilters(ApplicationContext applicationContext) private void initializeFilters(ApplicationContext applicationContext)
{ {
Expand Down
Expand Up @@ -53,35 +53,35 @@ public class TreeDiffViewController extends ProfileDiffViewController<Profile>
@FXML @FXML
private TreeTableColumn<NodeDiff, String> methodColumn; private TreeTableColumn<NodeDiff, String> methodColumn;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> baseSelfPct; private TreeTableColumn<NodeDiff, Number> baseSelfPct;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> newSelfPct; private TreeTableColumn<NodeDiff, Number> newSelfPct;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> selfPctDiff; private TreeTableColumn<NodeDiff, Number> selfPctDiff;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> baseTotalPct; private TreeTableColumn<NodeDiff, Number> baseTotalPct;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> newTotalPct; private TreeTableColumn<NodeDiff, Number> newTotalPct;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> totalPctDiff; private TreeTableColumn<NodeDiff, Number> totalPctDiff;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> baseSelfCnt; private TreeTableColumn<NodeDiff, Number> baseSelfCnt;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> newSelfCnt; private TreeTableColumn<NodeDiff, Number> newSelfCnt;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> selfCntDiff; private TreeTableColumn<NodeDiff, Number> selfCntDiff;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> baseTotalCnt; private TreeTableColumn<NodeDiff, Number> baseTotalCnt;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> newTotalCnt; private TreeTableColumn<NodeDiff, Number> newTotalCnt;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> totalCntDiff; private TreeTableColumn<NodeDiff, Number> totalCntDiff;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> baseParentCnt; private TreeTableColumn<NodeDiff, Number> baseParentCnt;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> newParentCnt; private TreeTableColumn<NodeDiff, Number> newParentCnt;
@FXML @FXML
private TreeTableColumn<NodeDiff, String> parentCntDiff; private TreeTableColumn<NodeDiff, Number> parentCntDiff;


private TreeProfileDiff diff; private TreeProfileDiff diff;


Expand Down Expand Up @@ -113,27 +113,27 @@ private void initializeTable()
methodColumn.setCellValueFactory( methodColumn.setCellValueFactory(
data -> new ReadOnlyStringWrapper( data -> new ReadOnlyStringWrapper(
data.getValue() == null ? null : data.getValue().getValue().getName())); data.getValue() == null ? null : data.getValue().getValue().getName()));
methodColumn.setCellFactory(col -> new MethodNameTreeTableCell<>()); methodColumn.setCellFactory(col -> new MethodNameTreeTableCell<>(appCtx()));


cfgPctCol(baseSelfPct, NodeDiff::getBaseSelfPct, baseCtx(), getText(COLUMN_SELF_PCT)); cfgPctCol(baseSelfPct, "baseSelfPct", baseCtx(), getText(COLUMN_SELF_PCT));
cfgPctCol(newSelfPct, NodeDiff::getNewSelfPct, newCtx(), getText(COLUMN_SELF_PCT)); cfgPctCol(newSelfPct, "newSelfPct", newCtx(), getText(COLUMN_SELF_PCT));
cfgPctDiffCol(selfPctDiff, NodeDiff::getSelfPctDiff, getText(COLUMN_SELF_PCT_DIFF)); cfgPctDiffCol(selfPctDiff, "selfPctDiff", getText(COLUMN_SELF_PCT_DIFF));


cfgPctCol(baseTotalPct, NodeDiff::getBaseSelfPct, baseCtx(), getText(COLUMN_TOTAL_PCT)); cfgPctCol(baseTotalPct, "baseTotalPct", baseCtx(), getText(COLUMN_TOTAL_PCT));
cfgPctCol(newTotalPct, NodeDiff::getNewSelfPct, newCtx(), getText(COLUMN_TOTAL_PCT)); cfgPctCol(newTotalPct, "newTotalPct", newCtx(), getText(COLUMN_TOTAL_PCT));
cfgPctDiffCol(totalPctDiff, NodeDiff::getSelfPctDiff, getText(COLUMN_TOTAL_PCT_DIFF)); cfgPctDiffCol(totalPctDiff, "totalPctDiff", getText(COLUMN_TOTAL_PCT_DIFF));


cfgCntCol(baseSelfCnt, NodeDiff::getBaseSelfCnt, baseCtx(), getText(COLUMN_SELF_CNT)); cfgCntCol(baseSelfCnt, "baseSelfCnt", baseCtx(), getText(COLUMN_SELF_CNT));
cfgCntCol(newSelfCnt, NodeDiff::getNewSelfCnt, newCtx(), getText(COLUMN_SELF_CNT)); cfgCntCol(newSelfCnt, "newSelfCnt", newCtx(), getText(COLUMN_SELF_CNT));
cfgCntDiffCol(selfCntDiff, NodeDiff::getSelfCntDiff, getText(COLUMN_SELF_CNT_DIFF)); cfgCntDiffCol(selfCntDiff, "selfCntDiff", getText(COLUMN_SELF_CNT_DIFF));


cfgCntCol(baseTotalCnt, NodeDiff::getBaseTotalCnt, baseCtx(), getText(COLUMN_TOTAL_CNT)); cfgCntCol(baseTotalCnt, "baseTotalCnt", baseCtx(), getText(COLUMN_TOTAL_CNT));
cfgCntCol(newTotalCnt, NodeDiff::getNewTotalCnt, newCtx(), getText(COLUMN_TOTAL_CNT)); cfgCntCol(newTotalCnt, "newTotalCnt", newCtx(), getText(COLUMN_TOTAL_CNT));
cfgCntDiffCol(totalCntDiff, NodeDiff::getTotalCntDiff, getText(COLUMN_TOTAL_CNT_DIFF)); cfgCntDiffCol(totalCntDiff, "totalCntDiff", getText(COLUMN_TOTAL_CNT_DIFF));


cfgCntCol(baseParentCnt, NodeDiff::getBaseParentCnt, baseCtx(), getText(COLUMN_PARENT_CNT)); cfgCntCol(baseParentCnt, "baseParentCnt", baseCtx(), getText(COLUMN_PARENT_CNT));
cfgCntCol(newParentCnt, NodeDiff::getNewParentCnt, newCtx(), getText(COLUMN_PARENT_CNT)); cfgCntCol(newParentCnt, "newParentCnt", newCtx(), getText(COLUMN_PARENT_CNT));
cfgCntDiffCol(parentCntDiff, NodeDiff::getParentCntDiff, getText(COLUMN_PARENT_CNT)); cfgCntDiffCol(parentCntDiff, "parentCntDiff", getText(COLUMN_PARENT_CNT));
} }


private void updateDiff(Profile profile, boolean base) private void updateDiff(Profile profile, boolean base)
Expand Down
Expand Up @@ -35,11 +35,12 @@


import com.insightfullogic.honest_profiler.core.profiles.Profile; import com.insightfullogic.honest_profiler.core.profiles.Profile;
import com.insightfullogic.honest_profiler.core.profiles.ProfileNode; import com.insightfullogic.honest_profiler.core.profiles.ProfileNode;
import com.insightfullogic.honest_profiler.ports.javafx.model.ApplicationContext;
import com.insightfullogic.honest_profiler.ports.javafx.model.filter.FilterType; import com.insightfullogic.honest_profiler.ports.javafx.model.filter.FilterType;
import com.insightfullogic.honest_profiler.ports.javafx.model.task.CopyAndFilterProfile; import com.insightfullogic.honest_profiler.ports.javafx.model.task.CopyAndFilterProfile;
import com.insightfullogic.honest_profiler.ports.javafx.util.TreeUtil; import com.insightfullogic.honest_profiler.ports.javafx.util.TreeUtil;
import com.insightfullogic.honest_profiler.ports.javafx.view.cell.TreeViewCell;
import com.insightfullogic.honest_profiler.ports.javafx.view.cell.MethodNameTreeTableCell; import com.insightfullogic.honest_profiler.ports.javafx.view.cell.MethodNameTreeTableCell;
import com.insightfullogic.honest_profiler.ports.javafx.view.cell.TreeViewCell;
import com.insightfullogic.honest_profiler.ports.javafx.view.tree.MethodNodeAdapter; import com.insightfullogic.honest_profiler.ports.javafx.view.tree.MethodNodeAdapter;
import com.insightfullogic.honest_profiler.ports.javafx.view.tree.RootNodeAdapter; import com.insightfullogic.honest_profiler.ports.javafx.view.tree.RootNodeAdapter;
import com.insightfullogic.honest_profiler.ports.javafx.view.tree.ThreadNodeAdapter; import com.insightfullogic.honest_profiler.ports.javafx.view.tree.ThreadNodeAdapter;
Expand Down Expand Up @@ -89,7 +90,12 @@ protected void initialize()
filterButton, filterButton,
quickFilterButton, quickFilterButton,
quickFilterText); quickFilterText);
}


@Override
public void setApplicationContext(ApplicationContext applicationContext)
{
super.setApplicationContext(applicationContext);
initializeTable(); initializeTable();
} }


Expand All @@ -100,7 +106,7 @@ private void initializeTable()
rootNode = new RootNodeAdapter(getFilterSpecification()); rootNode = new RootNodeAdapter(getFilterSpecification());
treeView.setRoot(rootNode); treeView.setRoot(rootNode);


methodColumn.setCellFactory(column -> new MethodNameTreeTableCell<>()); methodColumn.setCellFactory(column -> new MethodNameTreeTableCell<>(appCtx()));
methodColumn.setCellValueFactory(data -> buildProfileNodeCell(data.getValue())); methodColumn.setCellValueFactory(data -> buildProfileNodeCell(data.getValue()));


totalColumn.setCellValueFactory(data -> wrapDouble(data, ProfileNode::getTotalTimeShare)); totalColumn.setCellValueFactory(data -> wrapDouble(data, ProfileNode::getTotalTimeShare));
Expand Down

0 comments on commit 8ecdd6e

Please sign in to comment.