List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:com.skysql.manager.ui.NodeDialog.java
License:Open Source License
/** * Save node.//from w w w .j a v a 2 s .co m * * @param okButtonCaption the ok button caption */ private void saveNode(final String okButtonCaption) { final Button okButton = new Button(okButtonCaption); final Button cancelButton = new Button("Cancel"); buttonsBar.addComponent(cancelButton); buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT); cancelButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { windowClose(null); } }); okButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { if (nodeForm.validateNode()) { if (nodeInfo.save()) { if (button != null) { button.setName(nodeInfo.getName()); button.setDescription(nodeInfo.ToolTip()); if (button.isSelected()) { TabbedPanel tabbedPanel = VaadinSession.getCurrent() .getAttribute(TabbedPanel.class); tabbedPanel.refresh(); } } else { OverviewPanel overviewPanel = VaadinSession.getCurrent() .getAttribute(OverviewPanel.class); overviewPanel.refresh(); } windowClose(null); if (nodeForm.runConnect) { UserObject userObject = VaadinSession.getCurrent().getAttribute(UserObject.class); String userID = userObject.getUserID(); APIrestful api = new APIrestful(); String password = nodeForm.connectPassword.getValue(); String sshkey = nodeForm.connectKey.getValue(); if (!password.isEmpty() || !sshkey.isEmpty()) { Map<String, String> params = new HashMap<String, String>(); Encryption encryption = new Encryption(); if (nodeForm.usePassword) { params.put(ParametersLayout.PARAM_CONNECT_ROOTPASSWORD, encryption.encrypt(password, APIrestful.getKey())); } else { params.put(ParametersLayout.PARAM_CONNECT_SSHKEY, encryption.encrypt(sshkey, APIrestful.getKey())); } TaskRun taskRun = new TaskRun(nodeInfo.getParentID(), nodeInfo.getID(), userID, "connect", params, null); } } } } } }); buttonsBar.addComponent(okButton); buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT); }
From source file:com.skysql.manager.ui.OverviewPanel.java
License:Open Source License
/** * Instantiates a new overview panel./*from w w w. j a va 2 s.c o m*/ */ public OverviewPanel() { HorizontalLayout overviewContainer = new HorizontalLayout(); overviewContainer.addStyleName("overviewPanel"); overviewContainer.setWidth("100%"); setContent(overviewContainer); systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class); systemRecord = systemInfo.getCurrentSystem(); systemLayout = new SystemLayout(systemRecord); overviewContainer.addComponent(systemLayout); VerticalLayout nodesSlot = new VerticalLayout(); nodesSlot.addStyleName("nodesSlot"); nodesSlot.setMargin(new MarginInfo(false, false, false, false)); overviewContainer.addComponent(nodesSlot); overviewContainer.setExpandRatio(nodesSlot, 1.0f); final HorizontalLayout nodesHeader = new HorizontalLayout(); nodesHeader.setStyleName("panelHeaderLayout"); nodesHeader.setWidth("100%"); nodesSlot.addComponent(nodesHeader); nodesLabel = new Label(" "); nodesLabel.setSizeUndefined(); nodesHeader.addComponent(nodesLabel); nodesHeader.setComponentAlignment(nodesLabel, Alignment.MIDDLE_CENTER); nodesHeader.setExpandRatio(nodesLabel, 1.0f); final HorizontalLayout buttonsLayout = new HorizontalLayout(); buttonsLayout.setSpacing(true); buttonsLayout.setMargin(new MarginInfo(false, true, false, false)); nodesHeader.addComponent(buttonsLayout); nodesHeader.setComponentAlignment(buttonsLayout, Alignment.MIDDLE_RIGHT); addSystemButton = new Button("Add System..."); addSystemButton.setDescription("Add System"); addSystemButton.setVisible(false); buttonsLayout.addComponent(addSystemButton); addSystemButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { new SystemDialog(null, null); } }); addNodeButton = new Button("Add Node..."); addNodeButton.setDescription("Add Node to the current System"); addNodeButton.setVisible(false); buttonsLayout.addComponent(addNodeButton); addNodeButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { new NodeDialog(null, null); } }); final Button editButton = new Button("Edit"); editButton.setDescription("Enter Editing mode"); final Button saveButton = new Button("Done"); saveButton.setDescription("Exit Editing mode"); buttonsLayout.addComponent(editButton); editButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { buttonsLayout.replaceComponent(editButton, saveButton); isEditable = true; systemLayout.setEditable(true); nodesLayout.setEditable(true); nodesHeader.setStyleName("panelHeaderLayout-editable"); if (systemRecord != null && !SystemInfo.SYSTEM_ROOT.equals(systemRecord.getID())) { addNodeButton.setVisible(true); } else { addSystemButton.setVisible(true); } if (systemRecord == null || (systemRecord != null && systemRecord.getNodes().length == 0)) { nodesLayout.placeholderLayout(null); } } }); saveButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { buttonsLayout.replaceComponent(saveButton, editButton); isEditable = false; systemLayout.setEditable(false); nodesLayout.setEditable(false); nodesHeader.setStyleName("panelHeaderLayout"); if (systemRecord != null && systemRecord.getNodes().length == 0) { nodesLayout.placeholderLayout(null); } addNodeButton.setVisible(false); addSystemButton.setVisible(false); } }); Panel panel = new Panel(); panel.setHeight(PANEL_HEIGHT, Unit.PIXELS); panel.addStyleName(Runo.PANEL_LIGHT); nodesSlot.addComponent(panel); nodesLayout = new NodesLayout(systemRecord); nodesLayout.addStyleName("nodesLayout"); nodesLayout.setWidth("100%"); panel.setContent(nodesLayout); }
From source file:com.skysql.manager.ui.RunningTask.java
License:Open Source License
/** * Start.//from w w w.j a v a 2 s . com */ void start() { // disable further command selection immediately commandSelect.setEnabled(false); if (parametersLayout != null) { parametersLayout.setEnabled(false); } scriptingProgressLayout.start(); UserObject userObject = VaadinSession.getCurrent().getAttribute(UserObject.class); String userID = userObject.getUserID(); // we used to look up user-settable setting of loose/strict; after discussion with Mark on Nov 15, // we make is strict only for backup, which currently is the only command where different steps sequences apply depending on node state String state = (command.equals(Command.backup) ? nodeInfo.getState() : null); taskRun = new TaskRun(nodeInfo.getParentID(), nodeInfo.getID(), userID, command, params, state); if (taskRun.getTaskRecord() == null) { command = null; commandSelect.select(null); commandSelect.setEnabled(true); if (parametersLayout != null) { parametersLayout.setEnabled(true); } scriptingProgressLayout.setResult("Failed to launch"); scriptingProgressLayout.setErrorInfo(taskRun.getError()); overviewPanel.refresh(); return; } String taskSteps = taskRun.getTaskRecord().getSteps(); String nodeSteps = nodeInfo.getCommands().getSteps(command); if (!taskSteps.equals(nodeSteps)) { scriptingProgressLayout.buildProgress(taskRecord, command, taskSteps); scriptingProgressLayout.setTitle(command + " (Updated Steps)"); } nodeInfo.setTask(taskRun.getTaskRecord()); taskRecord = taskRun.getTaskRecord(); scriptingControlsLayout.enableControls(true, Controls.Stop); activateTimer(); }
From source file:com.skysql.manager.ui.SettingsDialog.java
License:Open Source License
public void windowClose(CloseEvent e) { if (refresh) { OverviewPanel overviewPanel = VaadinSession.getCurrent().getAttribute(OverviewPanel.class); overviewPanel.refresh();/*from www. ja va 2s . com*/ } }
From source file:com.skysql.manager.ui.SetupDialog.java
License:Open Source License
/** * Next form.//from w w w . ja v a 2 s .com */ private void nextForm() { UserInfo userInfo = new UserInfo(null); if (userInfo == null || userInfo.getUsersList() == null || userInfo.getUsersList().size() == 0) { inputUser(); } else { // we are done windowClose(null); VaadinSession.getCurrent().setAttribute(UserInfo.class, userInfo); ManagerUI current = (ManagerUI) UI.getCurrent(); current.refreshContentBasedOnSessionData(); } }
From source file:com.skysql.manager.ui.SetupDialog.java
License:Open Source License
/** * Add user./*from ww w . ja v a 2 s. c o m*/ */ private void inputUser() { final Button finishedButton = new Button("Add User"); final UserObject user = new UserObject(); final UserForm userForm = new UserForm(null, user, "Add User to the System", finishedButton); wrapper.replaceComponent(currentForm, userForm); currentForm = userForm; buttonsBar.addComponent(finishedButton); buttonsBar.setComponentAlignment(finishedButton, Alignment.MIDDLE_RIGHT); finishedButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { if (userForm.validateUser() && user.set()) { VaadinSession.getCurrent().setAttribute(UserObject.class, user); nextForm(); } } }); }
From source file:com.skysql.manager.ui.SystemDialog.java
License:Open Source License
/** * Save system./*w ww.jav a2 s.c o m*/ * * @param okButtonCaption the ok button caption */ private void saveSystem(final String okButtonCaption) { commitButton.setCaption(okButtonCaption); final Button cancelButton = new Button("Cancel"); buttonsBar.addComponent(cancelButton); buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT); cancelButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { windowClose(null); } }); commitButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { if (systemForm.validateSystem()) { if (systemRecord.save()) { if (button != null) { button.setName(systemRecord.getName()); button.setDescription(systemRecord.ToolTip()); if (button.isSelected()) { TabbedPanel tabbedPanel = VaadinSession.getCurrent() .getAttribute(TabbedPanel.class); tabbedPanel.refresh(); } } else { OverviewPanel overviewPanel = VaadinSession.getCurrent() .getAttribute(OverviewPanel.class); overviewPanel.refresh(); } windowClose(null); } } } }); buttonsBar.addComponent(commitButton); buttonsBar.setComponentAlignment(commitButton, Alignment.MIDDLE_RIGHT); }
From source file:com.skysql.manager.ui.TimelineLayout.java
License:Open Source License
/** * Initialize containers.//www . j a v a2s . com * * @param monitorIDs the monitor i ds */ private void initializeContainers(ArrayList<String> monitorIDs) { ClusterComponent componentInfo = VaadinSession.getCurrent().getAttribute(ClusterComponent.class); String systemID, nodeID; switch (componentInfo.getType()) { case system: systemID = componentInfo.getID(); nodeID = SystemInfo.SYSTEM_NODEID; break; case node: systemID = componentInfo.getParentID(); nodeID = componentInfo.getID(); break; default: return; } containers = new LinkedHashMap<MonitorRecord, IndexedContainer>(monitorIDs.size()); for (String monitorID : monitorIDs) { MonitorRecord monitor = Monitors.getMonitor(monitorID); IndexedContainer container = createIndexedContainer(); MonitorDataRaw monitorData = new MonitorDataRaw(monitor, systemID, nodeID, null, MAX_TIMESPAN); monitorData.fillDataSource(container); containers.put(monitor, container); Long latestTime = monitorData.getLatestTime(); if (latestTime != null) { //Calendar cal = new GregorianCalendar(); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(latestTime * 1000L); if (latestCal == null || cal.after(latestCal)) { latestCal = cal; } } } }
From source file:com.skysql.manager.ui.TopPanel.java
License:Open Source License
/** * Instantiates a new top panel./* w w w . jav a2s . c o m*/ */ public TopPanel() { setSpacing(true); addStyleName("titleLayout"); setWidth("100%"); Embedded logo = new Embedded(null, new ThemeResource("img/productlogo.png")); addComponent(logo); setComponentAlignment(logo, Alignment.BOTTOM_LEFT); // LINKS AREA (TOP-RIGHT) HorizontalLayout userSettingsLayout = new HorizontalLayout(); userSettingsLayout.setSizeUndefined(); userSettingsLayout.setSpacing(true); addComponent(userSettingsLayout); setComponentAlignment(userSettingsLayout, Alignment.MIDDLE_RIGHT); // User icon and name VerticalLayout userLayout = new VerticalLayout(); userSettingsLayout.addComponent(userLayout); userSettingsLayout.setComponentAlignment(userLayout, Alignment.BOTTOM_CENTER); UserObject userObject = VaadinSession.getCurrent().getAttribute(UserObject.class); String name = userObject.getAnyName(); userName = new Label("Welcome, " + name); userName.setSizeUndefined(); userLayout.addComponent(userName); // buttons HorizontalLayout buttonsLayout = new HorizontalLayout(); buttonsLayout.setSizeUndefined(); buttonsLayout.setSpacing(true); userSettingsLayout.addComponent(buttonsLayout); userSettingsLayout.setComponentAlignment(buttonsLayout, Alignment.MIDDLE_CENTER); // Settings button SettingsDialog settingsDialog = new SettingsDialog("Settings"); Button settingsButton = settingsDialog.getButton(); buttonsLayout.addComponent(settingsButton); buttonsLayout.setComponentAlignment(settingsButton, Alignment.MIDDLE_CENTER); // Logout Button logoutButton = new Button("Logout"); logoutButton.setSizeUndefined(); buttonsLayout.addComponent(logoutButton); buttonsLayout.setComponentAlignment(logoutButton, Alignment.MIDDLE_CENTER); logoutButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { UI.getCurrent().getPage().setLocation(""); UI.getCurrent().close(); getSession().setAttribute(UserObject.class, null); getSession().close(); } }); }
From source file:com.skysql.manager.ui.UsersSettings.java
License:Open Source License
/** * Instantiates a new users settings.//ww w. j a va 2s . com */ UsersSettings() { addStyleName("usersTab"); setSizeFull(); setSpacing(true); setMargin(true); UserObject currentUser = VaadinSession.getCurrent().getAttribute(UserObject.class); currentUserID = currentUser.getUserID(); HorizontalLayout usersLayout = new HorizontalLayout(); addComponent(usersLayout); usersLayout.setSizeFull(); usersLayout.setSpacing(true); // make sure we're working with current info userInfo = new UserInfo(null); VaadinSession.getCurrent().setAttribute(UserInfo.class, userInfo); select = new ListSelect("Users"); select.setImmediate(true); for (UserObject user : userInfo.getUsersList().values()) { String id = user.getUserID(); select.addItem(id); if (id.equals(currentUserID)) { select.select(id); userName.setValue(user.getName()); selectedUserID = id; } } select.setNullSelectionAllowed(false); select.setWidth("14em"); usersLayout.addComponent(select); select.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void valueChange(ValueChangeEvent event) { selectedUserID = (String) event.getProperty().getValue(); if (selectedUserID == null || selectedUserID.equals(currentUserID)) { removeUser.setEnabled(false); } else { removeUser.setEnabled(true); } if (selectedUserID == null) { editUser.setEnabled(false); userName.setEnabled(false); userName.setValue(""); } else { editUser.setEnabled(true); userName.setValue(userInfo.findNameByID(selectedUserID)); userName.setEnabled(true); } } }); usersLayout.addLayoutClickListener(new LayoutClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void layoutClick(LayoutClickEvent event) { Component child; if (event.isDoubleClick() && (child = event.getChildComponent()) != null && (child instanceof ListSelect)) { // Get the child component which was double-clicked ListSelect select = (ListSelect) child; String userID = (String) select.getValue(); new UserDialog(userInfo, userInfo.getUsersList().get(selectedUserID), thisObject); } } }); userLayout = new FormLayout(); usersLayout.addComponent(userLayout); usersLayout.setExpandRatio(userLayout, 1.0f); userLayout.setSpacing(false); userName.setCaption("Full Name:"); userLayout.addComponent(userName); HorizontalLayout userButtonsLayout = new HorizontalLayout(); userButtonsLayout.setSpacing(true); addComponent(userButtonsLayout); Button addUser = new Button("Add..."); addUser.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { new UserDialog(userInfo, null, thisObject); } }); userButtonsLayout.addComponent(addUser); userButtonsLayout.setComponentAlignment(addUser, Alignment.MIDDLE_LEFT); removeUser = new Button("Delete"); removeUser.setEnabled(false); removeUser.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { removeUser(event); } }); userButtonsLayout.addComponent(removeUser); userButtonsLayout.setComponentAlignment(removeUser, Alignment.MIDDLE_LEFT); editUser = new Button("Edit..."); editUser.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { new UserDialog(userInfo, userInfo.getUsersList().get(selectedUserID), thisObject); } }); userButtonsLayout.addComponent(editUser); userButtonsLayout.setComponentAlignment(editUser, Alignment.MIDDLE_CENTER); }