use of org.netxms.client.SessionNotification in project netxms by netxms.
the class SessionStore method registerSession.
/**
* @param s
*/
public synchronized SessionToken registerSession(final NXCSession session) {
if (sessionManager == null) {
sessionManager = new Thread(new Runnable() {
@Override
public void run() {
sessionManagerThread();
}
}, "Session Manager");
sessionManager.setDaemon(true);
sessionManager.start();
}
final SessionToken token = new SessionToken(session);
sessions.put(token.getGuid(), token);
session.addListener(new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
log.info("Received disconnect notification for session " + token.getGuid());
session.disconnect();
unregisterSession(token.getGuid());
}
}
});
log.info("Session " + token.getGuid() + " registered");
return token;
}
use of org.netxms.client.SessionNotification in project netxms by netxms.
the class EventProcessingPolicyEditor method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
session = (NXCSession) ConsoleSharedData.getSession();
IDialogSettings settings = Activator.getDefault().getDialogSettings();
// $NON-NLS-1$
filterEnabled = settings.getBoolean("EventProcessingPolicyEditor.filterEnabled");
// Initiate loading of required plugins if they was not loaded yet
try {
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(new ServerAction(0), "org.eclipse.ui.model.IWorkbenchAdapter");
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(session.getTopLevelObjects()[0], "org.eclipse.ui.model.IWorkbenchAdapter");
} catch (Exception e) {
}
// $NON-NLS-1$
imageStop = Activator.getImageDescriptor("icons/stop.png").createImage();
// $NON-NLS-1$
imageAlarm = Activator.getImageDescriptor("icons/alarm.png").createImage();
// $NON-NLS-1$
imageSituation = Activator.getImageDescriptor("icons/situation.gif").createImage();
// $NON-NLS-1$
imageExecute = Activator.getImageDescriptor("icons/execute.png").createImage();
// $NON-NLS-1$
imageTerminate = Activator.getImageDescriptor("icons/terminate.png").createImage();
imageCollapse = SharedIcons.COLLAPSE.createImage();
imageExpand = SharedIcons.EXPAND.createImage();
imageEdit = SharedIcons.EDIT.createImage();
parent.setLayout(new FormLayout());
// Create filter area
filterControl = new FilterText(parent, SWT.NONE);
filterControl.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterControl.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
}
});
scroller = new ScrolledComposite(parent, SWT.V_SCROLL);
dataArea = new Composite(scroller, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
dataArea.setLayout(layout);
dataArea.setBackground(BACKGROUND_COLOR);
scroller.setContent(dataArea);
scroller.setExpandVertical(true);
scroller.setExpandHorizontal(true);
scroller.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle r = scroller.getClientArea();
scroller.setMinSize(dataArea.computeSize(r.width, SWT.DEFAULT));
}
});
// Setup layout
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(filterControl);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
scroller.setLayoutData(fd);
fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
filterControl.setLayoutData(fd);
normalFont = JFaceResources.getDefaultFont();
boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
sessionListener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
processSessionNotification(n);
}
};
session.addListener(sessionListener);
selection = new TreeSet<RuleEditor>(new Comparator<RuleEditor>() {
@Override
public int compare(RuleEditor arg0, RuleEditor arg1) {
return arg0.getRuleNumber() - arg1.getRuleNumber();
}
});
createActions();
contributeToActionBars();
openEventProcessingPolicy();
activateContext();
// Set initial focus to filter input line
if (filterEnabled)
filterControl.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
}
use of org.netxms.client.SessionNotification in project netxms by netxms.
the class ApplicationWorkbenchAdvisor method doLogin.
/**
* Show login dialog and perform login
*/
private void doLogin() {
boolean success = false;
final Properties properties = new AppPropertiesLoader().load();
String password = "";
// $NON-NLS-1$
boolean autoLogin = (Application.getParameter("auto") != null);
String ssoTicket = Application.getParameter("ticket");
if (ssoTicket != null) {
autoLogin = true;
// $NON-NLS-1$
String server = Application.getParameter("server");
if (server == null)
// $NON-NLS-1$ //$NON-NLS-2$
server = properties.getProperty("server", "127.0.0.1");
success = connectToServer(server, null, ssoTicket);
} else if (autoLogin) {
// $NON-NLS-1$
String server = Application.getParameter("server");
if (server == null)
// $NON-NLS-1$ //$NON-NLS-2$
server = properties.getProperty("server", "127.0.0.1");
// $NON-NLS-1$
String login = Application.getParameter("login");
if (login == null)
login = "guest";
// $NON-NLS-1$
password = Application.getParameter("password");
if (password == null)
password = "";
success = connectToServer(server, login, password);
}
if (!autoLogin || !success) {
Window loginDialog;
do {
loginDialog = BrandingManager.getInstance().getLoginForm(Display.getCurrent().getActiveShell(), properties);
if (loginDialog.open() != Window.OK)
continue;
password = ((LoginForm) loginDialog).getPassword();
success = connectToServer(// $NON-NLS-1$ //$NON-NLS-2$
properties.getProperty("server", "127.0.0.1"), ((LoginForm) loginDialog).getLogin(), password);
} while (!success);
}
if (success) {
final NXCSession session = (NXCSession) RWT.getUISession().getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
final Display display = Display.getCurrent();
session.addListener(new SessionListener() {
private final Object MONITOR = new Object();
@Override
public void notificationHandler(final SessionNotification n) {
if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
display.asyncExec(new Runnable() {
@Override
public void run() {
RWT.getUISession().setAttribute("NoPageReload", Boolean.TRUE);
PlatformUI.getWorkbench().close();
String productName = BrandingManager.getInstance().getProductName();
String msg = (n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName) : ((n.getCode() == SessionNotification.SESSION_KILLED) ? "Communication session was terminated by system administrator" : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName));
JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
if (executor != null)
executor.execute("document.body.innerHTML='" + "<div style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: none; background-color: white;\">" + "<p style=\"margin-top: 30px; margin-left: 30px; color: #800000; font-family: \"Segoe UI\", Verdana, Arial, sans-serif; font-weight: bold; font-size: 2em;\">" + msg + "</p><br/>" + "<button style=\"margin-left: 30px\" onclick=\"location.reload(true)\">RELOAD</button>" + "</div>';");
synchronized (MONITOR) {
MONITOR.notifyAll();
}
}
});
synchronized (MONITOR) {
try {
MONITOR.wait(5000);
} catch (InterruptedException e) {
}
}
((UISessionImpl) RWT.getUISession(display)).shutdown();
}
}
});
try {
RWT.getSettingStore().loadById(session.getUserName() + "@" + session.getServerId());
} catch (IOException e) {
}
// Suggest user to change password if it is expired
if (session.isPasswordExpired()) {
final PasswordExpiredDialog dlg = new PasswordExpiredDialog(null, session.getGraceLogins());
while (true) {
if (dlg.open() != Window.OK)
return;
final String currentPassword = password;
IRunnableWithProgress job = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
NXCSession session = (NXCSession) RWT.getUISession(display).getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
session.setUserPassword(session.getUserId(), dlg.getPassword(), currentPassword);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
ProgressMonitorDialog pd = new ProgressMonitorDialog(null);
pd.run(false, false, job);
MessageDialog.openInformation(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Information, Messages.get().ApplicationWorkbenchWindowAdvisor_PasswordChanged);
return;
} catch (InvocationTargetException e) {
MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Error, Messages.get().ApplicationWorkbenchWindowAdvisor_CannotChangePswd + e.getCause().getLocalizedMessage());
} catch (InterruptedException e) {
MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Exception, e.toString());
}
}
}
}
}
use of org.netxms.client.SessionNotification in project netxms by netxms.
the class DashboardView method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
selectionProvider = new IntermediateSelectionProvider();
getSite().setSelectionProvider(selectionProvider);
ConsoleJob job = new ConsoleJob(Messages.get().DashboardView_GetEffectiveRights, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
readOnly = ((dashboard.getEffectiveRights() & UserAccessRights.OBJECT_ACCESS_MODIFY) == 0);
}
@Override
protected String getErrorMessage() {
return Messages.get().DashboardView_GetEffectiveRightsError;
}
};
job.start();
// FIXME: rewrite waiting
try {
job.join();
} catch (InterruptedException e) {
}
parentComposite = parent;
dbc = new DashboardControl(parent, SWT.NONE, dashboard, this, selectionProvider, false);
if (!readOnly) {
dbcModifyListener = new DashboardModifyListener() {
@Override
public void save() {
actionSave.setEnabled(false);
firePropertyChange(PROP_DIRTY);
}
@Override
public void modify() {
actionSave.setEnabled(true);
firePropertyChange(PROP_DIRTY);
}
};
dbc.setModifyListener(dbcModifyListener);
}
activateContext();
createActions();
contributeToActionBars();
clientListener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if (n.getCode() == SessionNotification.OBJECT_CHANGED && dashboard.getObjectId() == n.getSubCode()) {
parentComposite.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
rebuildDashboard(true);
}
});
}
}
};
session.addListener(clientListener);
}
use of org.netxms.client.SessionNotification in project netxms by netxms.
the class AbstractNetworkMapView method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.ViewPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public final void createPartControl(Composite parent) {
FillLayout layout = new FillLayout();
parent.setLayout(layout);
viewer = new ExtendedGraphViewer(parent, SWT.NONE);
viewer.setContentProvider(new MapContentProvider(viewer));
labelProvider = new MapLabelProvider(viewer);
viewer.setLabelProvider(labelProvider);
viewer.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB());
IDialogSettings settings = Activator.getDefault().getDialogSettings();
try {
// $NON-NLS-1$
alwaysFitLayout = settings.getBoolean(viewId + ".alwaysFitLayout");
} catch (Exception e) {
}
// Zoom level restore and save
try {
// $NON-NLS-1$
viewer.zoomTo(settings.getDouble(viewId + ".zoom"));
} catch (NumberFormatException e) {
}
viewer.getGraphControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
IDialogSettings settings = Activator.getDefault().getDialogSettings();
// $NON-NLS-1$
settings.put(viewId + ".zoom", viewer.getZoom());
}
});
getSite().setSelectionProvider(this);
ISelectionChangedListener listener = new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent e) {
if (bendpointEditor != null) {
bendpointEditor.stop();
bendpointEditor = null;
}
currentSelection = transformSelection(e.getSelection());
if (currentSelection.size() == 1) {
int selectionType = analyzeSelection(currentSelection);
if (selectionType == SELECTION_OBJECTS) {
AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
actionOpenDrillDownObject.setEnabled(object.getDrillDownObjectId() != 0);
} else {
actionOpenDrillDownObject.setEnabled(false);
if (selectionType == SELECTION_LINKS) {
NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
actionLockLink.setChecked(link.isLocked());
if (!link.isLocked() && link.getRouting() == NetworkMapLink.ROUTING_BENDPOINTS) {
bendpointEditor = new BendpointEditor(link, (GraphConnection) viewer.getGraphControl().getSelection().get(0), viewer);
}
}
}
} else {
actionOpenDrillDownObject.setEnabled(false);
}
if (selectionListeners.isEmpty())
return;
SelectionChangedEvent event = new SelectionChangedEvent(AbstractNetworkMapView.this, currentSelection);
for (ISelectionChangedListener l : selectionListeners) {
l.selectionChanged(event);
}
}
};
viewer.addPostSelectionChangedListener(listener);
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
int selectionType = analyzeSelection(currentSelection);
if (selectionType == SELECTION_EMPTY)
return;
if (selectionType == SELECTION_OBJECTS) {
AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
if (object instanceof Rack) {
openRackView(Long.toString(object.getObjectId()));
return;
}
for (DoubleClickHandlerData h : doubleClickHandlers) {
if ((h.enabledFor == null) || (h.enabledFor.isInstance(object))) {
if (h.handler.onDoubleClick(object)) {
return;
}
}
}
} else if (((NetworkMapLink) currentSelection.getFirstElement()).isLocked() && selectionType == SELECTION_LINKS) {
openLinkDci();
}
// Default behavior
actionOpenDrillDownObject.run();
}
});
sessionListener = new SessionListener() {
@Override
public void notificationHandler(final SessionNotification n) {
if (n.getCode() == SessionNotification.OBJECT_CHANGED) {
viewer.getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
onObjectChange((AbstractObject) n.getObject());
}
});
}
}
};
session.addListener(sessionListener);
createActions();
contributeToActionBars();
createPopupMenu();
if (automaticLayoutEnabled) {
setLayoutAlgorithm(layoutAlgorithm, true);
} else {
viewer.setLayoutAlgorithm(new ManualLayout());
}
activateContext();
registerDoubleClickHandlers();
setupMapControl();
refreshMap();
}
Aggregations