forked from stevewirts/snap-and-dock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocking.js
115 lines (96 loc) · 4.05 KB
/
Docking.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* globals fin, window, document, screen, console */
/* eslint-disable no-console */
import DockingManager from './lib/DockingManager.js';
import {GroupEventMemberOf, GroupEventReason} from "./lib/OpenFinWrapper.js";
/**
* Created by haseebriaz on 03/03/15.
*/
let dockingManager;
function getDockingManager() {
// Apply any of the following options
// if you want to modify the docking parameters
const dockingOptions = {
// range: 20,
// spacing: 0,
// undockOffsetX: 25,
// undockOffsetY: 25,
// movingOpacity: 0.6,
// snappedMovingOpacity: 0.8,
// snappedTargetOpacity: 1
};
if (!dockingManager) {
dockingManager = new DockingManager(dockingOptions);
}
return dockingManager;
}
function onGroupChanged(groupEvent) {
// leaving is simple ... if member of 'nothing', then this window is leaving
if (groupEvent.memberOf === GroupEventMemberOf.NOTHING) {
console.log('group-changed event: ' + groupEvent.name + ' left group');
return;
}
// joining is a little more complicated ...
// if sourceWindowName is the same as name, that is a primary join event
// but at group setup, the first window is only a 'target' of a join
// (for the 2 setup events, the target group has just those 2 members)
if (groupEvent.reason === GroupEventReason.JOIN) {
if (groupEvent.sourceWindowName === groupEvent.name ||
groupEvent.targetGroup.length === 2 &&
groupEvent.targetWindowName === groupEvent.name) {
console.log('group-changed event: ' + groupEvent.name + ' joined group');
}
}
}
function createAndRegister(windowNameSuffix) {
const windowOptions = {
name: `child${windowNameSuffix}`,
url: 'child.html',
defaultWidth: 200,
defaultHeight: 150,
defaultTop: (screen.availHeight - 200) / 2,
defaultLeft: (screen.availWidth - 150) / 2,
frame: false,
shadow: true,
autoShow: true
};
const openfinWindow = new fin.desktop.Window(
windowOptions,
function() {
dockingManager.register(openfinWindow);
}
);
// To test using DockingWindow to create the OpenFin window
//
// dockingManager.register(windowOptions);
openfinWindow.addEventListener('group-changed', onGroupChanged);
}
function onOpenFinReady() {
const dockingManager = getDockingManager();
dockingManager.register(fin.desktop.Window.getCurrent(), false);
let counter = 0;
document.getElementById('createWindows').onclick = () => { createAndRegister(++counter); };
// convenience to restore up to 10 docked child windows from previous persistance
// for (let tempCounter = 0; tempCounter < 10; tempCounter++) {
// const DOCKING_MANAGER_NAMESPACE_PREFIX = 'dockingManager.';
// const windowStorageKey = `${DOCKING_MANAGER_NAMESPACE_PREFIX}${fin.desktop.Application.getCurrent().uuid}.child${tempCounter}`;
// if (localStorage.getItem(windowStorageKey)) {
// createAndRegister(tempCounter);
// counter = tempCounter;
// }
// }
fin.desktop.InterApplicationBus.subscribe('*', 'window-docked', function(message) {
console.log('window-docked subscription: ' + message.windowName + ' joined group');
});
fin.desktop.InterApplicationBus.subscribe('*', 'window-undocked', function(message) {
console.log('window-undocked subscription: ' + message.windowName + ' left group');
});
// bus-based handling for external java application docking
fin.desktop.InterApplicationBus.subscribe('*', 'register-docking-window', function(message) {
const { appUuid, name } = message;
console.log('Registering external window', appUuid, name);
const javaWindow = fin.desktop.Window.wrap(appUuid, name);
dockingManager.register(javaWindow);
});
fin.desktop.InterApplicationBus.publish('status-update', {status: 'ready'});
}
window.addEventListener('DOMContentLoaded', () => fin.desktop.main(onOpenFinReady));