Commit 02e0b003 authored by Patrik Meijer's avatar Patrik Meijer
Browse files

Initial work on pointer-creation

parent 035fdb89
......@@ -12,12 +12,12 @@ import MenuItem from '@material-ui/core/MenuItem';
export default class ContextMenu extends Component {
static propTypes = {
gmeClient: PropTypes.object.isRequired,
data: PropTypes.object.isRequired,
nodeId: PropTypes.string.isRequired, // FIXME: should be nodeIds
eventX: PropTypes.number.isRequired,
eventY: PropTypes.number.isRequired,
onClose: PropTypes.func.isRequired,
setActiveNode: PropTypes.func.isRequired,
createPointer: PropTypes.func.isRequired,
readOnly: PropTypes.bool,
};
......@@ -41,6 +41,13 @@ export default class ContextMenu extends Component {
onClose();
}
getCreatePointerFunc = (ptrName) => {
const {createPointer, nodeId} = this.props;
return () => {
createPointer(nodeId, ptrName);
};
}
render() {
const {
gmeClient,
......@@ -48,63 +55,32 @@ export default class ContextMenu extends Component {
eventX,
eventY,
readOnly,
data,
onClose,
} = this.props;
// console.log(data);
const menuItems = [];
const nodeObj = gmeClient.getNode(nodeId);
if (false) {
const metaNodeObj = gmeClient.getNode(nodeObj.getMetaTypeId());
const metaNodeObj = gmeClient.getNode(nodeObj.getMetaTypeId());
menuItems.push((
<MenuItem key="meta-type" onClick={this.props.onClose} disabled={readOnly}>
{`<<${metaNodeObj.getAttribute('name')}>>`}
</MenuItem>));
const pointerNames = metaNodeObj.getValidPointerNames();
if (metaNodeObj.getAttribute('name') === 'System') {
menuItems.push((
<MenuItem key="open-sub-system" onClick={this.setActiveNode} >
Open Subsystem ...
</MenuItem>));
}
} else if (data.memberAttrs && data.memberAttrs.length > 0) {
let args;
data.memberAttrs.forEach((memAttr) => {
if (memAttr.name === 'args') {
args = memAttr.value ? `(${memAttr.value})` : '()';
}
});
if (args) {
menuItems.push((
<MenuItem key="invocation-args" onClick={this.props.onClose}>
Invocation arguments: {args}
</MenuItem>));
}
} else if (data.pointerName === 'post' || data.pointerName === 'pre') {
const methodNode = gmeClient.getNode(data.source);
const modeNode = gmeClient.getNode(data.target);
if (methodNode && modeNode) {
// const parentName = gmeClient.getNode(modeNode.getParentId()).getAttribute('name');
// const modeName = modeNode.getAttribute('name');
const methodName = methodNode.getAttribute('name');
menuItems.push((
<MenuItem key="pre-post-condition" onClick={this.props.onClose}>
{`${data.pointerName}-condition for ${methodName}`}
</MenuItem>));
}
} else if (data.setName === 'network-nodes') {
menuItems.push((
<MenuItem key="meta-type" onClick={onClose} disabled={readOnly}>
{`<<${metaNodeObj.getAttribute('name')}>>`}
</MenuItem>));
menuItems.push((
<MenuItem key="open-sub-system" onClick={this.setActiveNode} >
Open Subsystem ...
</MenuItem>));
pointerNames.forEach((ptr) => {
menuItems.push((
<MenuItem key="cell-network-nodes" onClick={this.props.onClose}>
{`${data.setName}`}
<MenuItem key={`create-pointer-${ptr}`} onClick={this.getCreatePointerFunc(ptr)} >
{`Create pointer ${ptr} from here ...`}
</MenuItem>));
}
if (menuItems.length === 0) {
this.props.onClose();
return <div/>;
}
});
return (
<Menu
......@@ -116,7 +92,7 @@ export default class ContextMenu extends Component {
left: eventX,
}}
open
onClose={this.props.onClose}
onClose={onClose}
>
{menuItems}
</Menu>
......
......@@ -34,73 +34,79 @@ export default class FilterSelector extends Component {
static defaultProps = {
open: true,
}
};
render() {
const {validItems, activeItems} = this.props;
const {
validItems,
activeItems,
handleToggle,
open,
onClose,
} = this.props;
const lists = [];
Object.keys(validItems).forEach((groupName) => {
const items = [];
validItems[groupName].forEach((item) => {
if (item.hidden) {
return;
}
Object.keys(validItems)
.forEach((groupName) => {
const items = [];
validItems[groupName].forEach((item) => {
if (item.hidden) {
return;
}
const itemId = `${groupName}$${item.name}`;
let icon;
const itemId = `${groupName}$${item.name}`;
let icon;
switch (groupName) {
case 'pointers':
icon = <TrendingFlatIcon style={{color: 'rgb(85, 123, 139)'}}/>;
break;
case 'sets':
icon = (item.name === 'network-nodes') ?
<MoreHorizIcon/> :
<CallSplitIcon className="rotate-90"/>;
break;
case 'nodes':
icon = item.isConnection ? <RemoveIcon/> : <FiberManualRecordIcon/>;
break;
default:
icon = <FiberManualRecordIcon/>;
break;
}
switch (groupName) {
case 'pointers':
icon = <TrendingFlatIcon style={{color: 'rgb(85, 123, 139)'}}/>;
break;
case 'sets':
icon = (item.name === 'network-nodes')
? <MoreHorizIcon/> : <CallSplitIcon className="rotate-90"/>;
break;
case 'nodes':
icon = item.isConnection ? <RemoveIcon/> : <FiberManualRecordIcon/>;
break;
default:
icon = <FiberManualRecordIcon/>;
break;
}
items.push((
<ListItem key={itemId}>
<ListItemIcon>
{icon}
</ListItemIcon>
<ListItemText primary={item.name} style={{marginRight: 24}}/>
<ListItemSecondaryAction>
<Switch
onChange={() => {
this.props.handleToggle(itemId);
}}
checked={activeItems[itemId]}
/>
</ListItemSecondaryAction>
</ListItem>));
});
items.push((
<ListItem key={itemId}>
<ListItemIcon>
{icon}
</ListItemIcon>
<ListItemText primary={item.name} style={{marginRight: 24}}/>
<ListItemSecondaryAction>
<Switch
onChange={() => {
handleToggle(itemId);
}}
checked={activeItems[itemId]}
/>
</ListItemSecondaryAction>
</ListItem>));
});
if (items.length > 0) {
lists.push((
<div key={groupName} >
<Typography variant="subheading">
{groupName.toUpperCase()}
</Typography>
<List>
{items}
</List>
<Divider/>
</div>
));
}
});
if (items.length > 0) {
lists.push((
<div key={groupName}>
<Typography variant="subheading">
{groupName.toUpperCase()}
</Typography>
<List>
{items}
</List>
<Divider/>
</div>
));
}
});
return (
<Dialog open={this.props.open} onClose={this.props.onClose}>
<Dialog open={open} onClose={onClose}>
<DialogTitle id="filter-dialog-title">Apply Filters</DialogTitle>
<DialogContent>
{lists}
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment