Skip to content
Permalink
Browse files
Added some initial right-click support in the project tree view.
  • Loading branch information
mrg committed Jul 1, 2017
1 parent 4b66c8b commit 9fc39d3e877e5f357a073422de57a9744a6aa4bd
Showing 8 changed files with 138 additions and 0 deletions.
@@ -38,6 +38,7 @@
import org.apache.cayenne.modeler.project.DataNodeTreeItem;
import org.apache.cayenne.modeler.project.DatabaseEntityTreeItem;
import org.apache.cayenne.modeler.project.ObjectEntityTreeItem;
import org.apache.cayenne.modeler.project.ProjectTreeCell;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@@ -48,10 +49,12 @@
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Callback;

public class MainWindowLayout
extends AbstractWindowLayout
@@ -174,6 +177,15 @@ public void displayCayenneProject(final CayenneProject cayenneProject) throws IO
treeView.setRoot(treeRoot);
treeView.setShowRoot(false);

treeView.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>()
{
@Override
public TreeCell<String> call(TreeView<String> p)
{
return new ProjectTreeCell();
}
});

// addDataDomain(CayenneModelManager.getModels().get(0));
// System.out.println(CayenneModelManager.getModels().size());

@@ -21,10 +21,23 @@

import org.apache.cayenne.modeler.adapters.CayennePropertyAdapter;

import javafx.scene.control.ContextMenu;

//public class CayenneTreeItem<T> extends TreeItem<T>
public interface CayenneTreeItem<T extends CayennePropertyAdapter>
{
// static final Log LOGGER = LogFactory.getLog(CayenneTreeItem.class);

public static final String TREE_ICON_SIZE = "16px";

T getPropertyAdapter();

ContextMenu getContextMenu();

// default ContextMenu getContextMenu()
// {
// MenuItem addInbox = new MenuItem("add inbox");
// addInbox.setOnAction(event -> LOGGER.debug("default context menu - event: " + event));
// return new ContextMenu(addInbox);
// }
}
@@ -20,14 +20,20 @@
package org.apache.cayenne.modeler.project;

import org.apache.cayenne.modeler.adapters.DataDomainAdapter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TreeItem;

//public class DataDomainTreeItem extends CayenneTreeItem<String>
public class DataDomainTreeItem extends TreeItem<String> implements CayenneTreeItem<DataDomainAdapter>
{
private static final Log LOGGER = LogFactory.getLog(DataDomainTreeItem.class);

private final DataDomainAdapter dataDomainAdapter;

public DataDomainTreeItem(final DataDomainAdapter dataDomainAdapter, final TreeItem<String> treeRoot)
@@ -52,4 +58,12 @@ public DataDomainAdapter getPropertyAdapter()
{
return dataDomainAdapter;
}

@Override
public ContextMenu getContextMenu()
{
MenuItem addInbox = new MenuItem("Data Domain Menu");
addInbox.setOnAction(event -> LOGGER.debug("Data Domain Context Menu Event: " + event));
return new ContextMenu(addInbox);
}
}
@@ -20,13 +20,19 @@
package org.apache.cayenne.modeler.project;

import org.apache.cayenne.modeler.adapters.DataMapAdapter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TreeItem;

public class DataMapTreeItem extends TreeItem<String> implements CayenneTreeItem<DataMapAdapter>
{
private static final Log LOGGER = LogFactory.getLog(DataMapTreeItem.class);

private final DataMapAdapter dataMapAdapter;

public DataMapTreeItem(final DataMapAdapter dataMapAdapter, final TreeItem<String> parent)
@@ -44,4 +50,12 @@ public DataMapAdapter getPropertyAdapter()
{
return dataMapAdapter;
}

@Override
public ContextMenu getContextMenu()
{
MenuItem addInbox = new MenuItem("Data Map Menu");
addInbox.setOnAction(event -> LOGGER.debug("Data Map Context Menu Event: " + event));
return new ContextMenu(addInbox);
}
}
@@ -20,13 +20,19 @@
package org.apache.cayenne.modeler.project;

import org.apache.cayenne.modeler.adapters.DataNodeAdapter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TreeItem;

public class DataNodeTreeItem extends TreeItem<String> implements CayenneTreeItem<DataNodeAdapter>
{
private static final Log LOGGER = LogFactory.getLog(DataNodeTreeItem.class);

private final DataNodeAdapter dataNodeAdapter;

public DataNodeTreeItem(final DataNodeAdapter dataNodeAdapter, final TreeItem<String> parent)
@@ -44,4 +50,12 @@ public DataNodeAdapter getPropertyAdapter()
{
return dataNodeAdapter;
}

@Override
public ContextMenu getContextMenu()
{
MenuItem addInbox = new MenuItem("Data Node Menu");
addInbox.setOnAction(event -> LOGGER.debug("Data Node Context Menu Event: " + event));
return new ContextMenu(addInbox);
}
}
@@ -20,13 +20,19 @@
package org.apache.cayenne.modeler.project;

import org.apache.cayenne.modeler.adapters.DatabaseEntityAdapter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TreeItem;

public class DatabaseEntityTreeItem extends TreeItem<String> implements CayenneTreeItem<DatabaseEntityAdapter>
{
private static final Log LOGGER = LogFactory.getLog(DatabaseEntityTreeItem.class);

private final DatabaseEntityAdapter databaseEntityAdapter;

public DatabaseEntityTreeItem(final DatabaseEntityAdapter databaseEntityAdapter, final TreeItem<String> parent)
@@ -44,4 +50,12 @@ public DatabaseEntityAdapter getPropertyAdapter()
{
return databaseEntityAdapter;
}

@Override
public ContextMenu getContextMenu()
{
MenuItem addInbox = new MenuItem("Database Entity Menu");
addInbox.setOnAction(event -> LOGGER.debug("Database Entity Context Menu Event: " + event));
return new ContextMenu(addInbox);
}
}
@@ -19,14 +19,22 @@

package org.apache.cayenne.modeler.project;

import org.apache.cayenne.map.ObjEntity;
import org.apache.cayenne.modeler.adapters.ObjectEntityAdapter;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TreeItem;

public class ObjectEntityTreeItem extends TreeItem<String> implements CayenneTreeItem<ObjectEntityAdapter>
{
private static final Log LOGGER = LogFactory.getLog(DataDomainTreeItem.class);

private final ObjectEntityAdapter objectEntityAdapter;

public ObjectEntityTreeItem(final ObjectEntityAdapter objectEntityAdapter, final TreeItem<String> parent)
@@ -44,4 +52,29 @@ public ObjectEntityAdapter getPropertyAdapter()
{
return objectEntityAdapter;
}

@Override
public ContextMenu getContextMenu()
{
ContextMenu contextMenu = new ContextMenu();
ObjEntity objectEntity = (ObjEntity) getPropertyAdapter().getWrappedObject();

getPropertyAdapter().getDataMapAdapter().getDatabaseEntityAdapters().stream().forEach(databaseEntity ->
{
if (StringUtils.equals(databaseEntity.getName(), objectEntity.getDbEntityName()))
{
MenuItem jumpTo = new MenuItem("Jump To Database Entity: " + databaseEntity.getName());

jumpTo.setMnemonicParsing(false);
jumpTo.setOnAction(event ->
{
LOGGER.debug("Jumping to DB Entity: " + databaseEntity.getName());
});

contextMenu.getItems().add(jumpTo);
}
});

return contextMenu;
}
}
@@ -0,0 +1,24 @@
package org.apache.cayenne.modeler.project;

import javafx.scene.control.TreeCell;

public class ProjectTreeCell extends TreeCell<String>
{
@Override
public void updateItem(String item, boolean empty)
{
super.updateItem(item, empty);

if (empty)
{
setText(null);
setGraphic(null);
}
else
{
setText(getItem() == null ? "" : getItem().toString());
setGraphic(getTreeItem().getGraphic());
setContextMenu(((CayenneTreeItem<?>) getTreeItem()).getContextMenu());
}
}
}

0 comments on commit 9fc39d3

Please sign in to comment.