Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #161 from phantomjinx/master
Browse files Browse the repository at this point in the history
TEIIDTOOLS-467: Adds selection handling to model
  • Loading branch information
mdrillin committed Jul 13, 2018
2 parents 0d7c36d + b1e0f88 commit a8960c4
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 36 deletions.
Expand Up @@ -53,7 +53,15 @@ export class CanvasService {

this.canvasGraph = new CanvasGraph(this, options);
this.canvasGraph.nodesSelected.subscribe((nodes) => {
const event = ViewCanvasEvent.create(ViewCanvasEventType.CANVAS_SELECTION_CHANGED, nodes);

const selection = [];
if (nodes) {
nodes.forEach((node) => {
selection.push(node.decodedId);
});
}

const event = ViewCanvasEvent.create(ViewCanvasEventType.CANVAS_SELECTION_CHANGED, selection);
this.canvasEvent.emit(event);
});

Expand Down
Expand Up @@ -93,7 +93,7 @@ export class CanvasGraph {
.flowLayout("x", 150)
.symmetricDiffLinkLengths(30)
.avoidOverlaps(true)
.handleDisconnected(true)
.handleDisconnected(false)
.nodes(this.nodes)
.links(this.links);

Expand Down
Expand Up @@ -37,11 +37,11 @@ export class CanvasNode implements cola.Node {
private _root = false;

public static encodeId(id: string): string {
return btoa(id);
return id.replace(/\//g, '5X5').replace(/=/g, '6X6');
}

public static decodeId(id: string): string {
return atob(id);
return id.replace('/5X5/g', '/').replace('/6X6/g', '=');
}

constructor(id: string, type: string, label: string, root?: boolean) {
Expand Down
Expand Up @@ -150,22 +150,8 @@ export class ViewCanvasComponent implements OnInit, AfterViewInit, OnDestroy {
this.editorService.editorEvent.emit(deleteEvt);
break;
case ViewCanvasEventType.CANVAS_SELECTION_CHANGED:

//
// TODO
// Need to work out what to place inside the event
// for other compomenents to make use of
//
// const selectEvent = ViewEditorEvent.create(ViewEditorPart.CANVAS, ViewEditorEventType.CANVAS_SELECTION_CHANGED, event.args);
// this.editorService.editorEvent.emit(srcEvent);
// break;

const selected = <Array<CanvasNode>> event.args;
this.logger.debug("ViewCanvasComponent selected " + selected.length + " nodes");
selected.forEach((node) => {
this.logger.debug("Selected: " + node.label);
});

const selectEvent = ViewEditorEvent.create(ViewEditorPart.CANVAS, ViewEditorEventType.CANVAS_SELECTION_CHANGED, event.args);
this.editorService.editorEvent.emit(selectEvent);
break;
default:
this.logger.debug("ViewCanvasComponent not handling received canvas event: " + event.toString());
Expand Down
Expand Up @@ -120,8 +120,10 @@ export class ViewEditorComponent implements DoCheck, OnDestroy, OnInit {
}

private canDelete(): boolean {
// TODO implement canDelete
return !this.fatalErrorOccurred && !this.editorService.isReadOnly() && this.isShowingCanvas;
return !this.fatalErrorOccurred &&
!this.editorService.isReadOnly() &&
this.isShowingCanvas &&
this.editorService.hasSelection();
}

private canRedo(): boolean {
Expand Down Expand Up @@ -168,17 +170,20 @@ export class ViewEditorComponent implements DoCheck, OnDestroy, OnInit {
});
}

private doDelete(ident: string): void {
private doDelete(idents: string[]): void {

if (!ident) {
if (!idents || idents.length === 0) {
alert("Nothing selected for delete");
return;
}

const identBits = ident.split(Command.identDivider);

// Dialog Content
const message = "Do you really want to delete '" + identBits[0] + "'?";
let message = "Do you really want to delete the " + idents.length;
if (idents.length > 1)
message = message + " items?";
else
message = message + " item?";

const initialState = {
title: "Confirm Delete",
bodyContent: message,
Expand All @@ -189,16 +194,25 @@ export class ViewEditorComponent implements DoCheck, OnDestroy, OnInit {
// Show Dialog, act upon confirmation click
const modalRef = this.modalService.show(ConfirmDialogComponent, {initialState});
modalRef.content.confirmAction.take(1).subscribe((value) => {
const tempCmd = CommandFactory.createRemoveSourcesCommand(identBits[1], identBits[0]);
if ( tempCmd instanceof Command ) {
const cmd = tempCmd as Command;
this.editorService.fireViewStateHasChanged( ViewEditorPart.EDITOR, cmd );
} else {
this.logger.error( "Failed to create RemoveSourcesCommand");
}
idents.forEach((ident) => {
const identBits = ident.split(Command.identDivider);
const tempCmd = CommandFactory.createRemoveSourcesCommand(identBits[1], identBits[0]);
if ( tempCmd instanceof Command ) {
const cmd = tempCmd as Command;
this.editorService.fireViewStateHasChanged( ViewEditorPart.EDITOR, cmd );
} else {
this.logger.error( "Failed to create RemoveSourcesCommand");
}

this.editorService.select(null);
});
});
}

private doSelection(selection: string[]) {
this.editorService.select(selection);
}

private doDisplayLogMessages( actionId: string ): void {
this.editorService.fire( ViewEditorEvent.create( ViewEditorPart.EDITOR,
ViewEditorEventType.SHOW_EDITOR_PART,
Expand Down Expand Up @@ -356,7 +370,8 @@ export class ViewEditorComponent implements DoCheck, OnDestroy, OnInit {
this.doAddSource();
break;
case this.deleteActionId:
this.doDelete(null);
const selection = this.editorService.getSelection();
this.doDelete(selection);
break;
case this.errorsActionId:
this.doDisplayLogMessages( this.errorsActionId );
Expand Down Expand Up @@ -403,7 +418,12 @@ export class ViewEditorComponent implements DoCheck, OnDestroy, OnInit {
this.doAddComposition();
}
else if (event.typeIsDeleteNode()) {
this.doDelete(event.args[0]);
const selection = [];
selection.push(event.args[0]);
this.doDelete(selection);
}
else if (event.typeIsCanvasSelectionChanged()) {
this.doSelection(event.args);
}
else if ( event.typeIsEditorViewSaveProgressChanged() ) {
if ( event.args.length !== 0 ) {
Expand Down
Expand Up @@ -61,6 +61,7 @@ export class ViewEditorService {
private readonly _undoMgr: UndoManager;
private readonly _vdbService: VdbService;
private _warningMsgCount = 0;
private _selection: string[] = [];

constructor( logger: LoggerService,
vdbService: VdbService ) {
Expand Down Expand Up @@ -532,4 +533,33 @@ export class ViewEditorService {
);
}

/**
* Access the current selection
*/
public getSelection(): string[] {
return this._selection;
}

/**
* Update the node selection
*/
public select(selection: string[]) {
if (!selection)
selection = [];

this._selection = selection;

let msg = "View Editor selection updated to: [ ";
this._selection.forEach((id) => {
msg = msg + id + " ";
});

msg = msg + "]";

this._logger.debug(msg);
}

public hasSelection(): boolean {
return this._selection.length > 0;
}
}

0 comments on commit a8960c4

Please sign in to comment.