List of usage examples for com.vaadin.server VaadinSession getAttribute
public <T> T getAttribute(Class<T> type)
From source file:com.haulmont.cuba.web.sys.WebVaadinCompatibleSecurityContextHolder.java
License:Apache License
@Override public SecurityContext get() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null && vaadinSession.hasLock()) { return vaadinSession.getAttribute(SecurityContext.class); }/* w w w . ja v a2s . co m*/ return super.get(); }
From source file:com.ocs.dynamo.ui.utils.VaadinUtils.java
License:Apache License
/** * Returns the currency symbol to be used - by default this is looked up from the session, with * a fallback to the system property "default.currency.symbol" * //from w w w . ja va 2 s. c om * @return */ public static String getCurrencySymbol() { String cs = SystemPropertyUtils.getDefaultCurrencySymbol(); VaadinSession vs = VaadinSession.getCurrent(); if (vs != null && vs.getAttribute(DynamoConstants.CURRENCY_SYMBOL) != null) { cs = (String) vs.getAttribute(DynamoConstants.CURRENCY_SYMBOL); } return cs; }
From source file:com.skysql.manager.ManagerUI.java
License:Open Source License
/** * Refresh content based on session data. *//*from w ww .j ava2s. c om*/ public void refreshContentBasedOnSessionData() { /* * As the UI is regenerated upon browser refresh, we should always check in the init what content to set to our UI. * * To force our application to reuse the same UI instance, we can add the @PreserveOnRefresh-annotation to our UI class */ VaadinSession session = getSession(); AppData appData = session.getAttribute(AppData.class); if (appData == null) { setContent(new ErrorView(Notification.Type.ERROR_MESSAGE, "Cannot find configuration file")); return; } APIrestful api = session.getAttribute(APIrestful.class); if (api == null) { setContent(new ErrorView(Notification.Type.ERROR_MESSAGE, null)); return; } new Versions("gui", "MariaDB-Manager-WebUI", GUI_VERSION + (Debug.ON ? " DEBUG" : ""), GUI_RELEASE, null); SystemInfo systemInfo = new SystemInfo(SystemInfo.SYSTEM_ROOT); session.setAttribute(SystemInfo.class, systemInfo); UserInfo userInfo = session.getAttribute(UserInfo.class); if (userInfo == null || userInfo.getUsersList() == null || userInfo.getUsersList().isEmpty()) { setContent(new ErrorView(Notification.Type.HUMANIZED_MESSAGE, "Initial System Setup - Please provide your configuration information.")); new SetupDialog(); return; } UserObject userObject = session.getAttribute(UserObject.class); if (userObject == null) { setContent(new LoginView()); } else { String adjust = userObject.getProperty(UserObject.PROPERTY_TIME_ADJUST); DateConversion dateConversion = new DateConversion( (adjust == null ? GeneralSettings.DEFAULT_TIME_ADJUST : Boolean.valueOf(adjust)), userObject.getProperty(UserObject.PROPERTY_TIME_FORMAT)); session.setAttribute(DateConversion.class, dateConversion); session.setAttribute("isChartsEditing", false); initLayout(); initExecutor(); } }
From source file:com.skysql.manager.ui.components.ChartsLayout.java
License:Open Source License
/** * Refresh.// w ww .ja v a2s . c o m * * @param time the time * @param interval the interval */ public void refresh(String time, String interval) { this.time = time; this.interval = interval; // if (isChartsEditing) { // return; // } VaadinSession session = getSession(); if (session == null) { session = VaadinSession.getCurrent(); } boolean isChartsEditing2 = (Boolean) session.getAttribute("isChartsEditing"); if (isChartsEditing2) { return; } ManagerUI.log("ChartsLayout refresh()"); Iterator<Component> iter = iterator(); while (iter.hasNext()) { Component component = iter.next(); if (component instanceof ChartButton) { ChartButton chartButton = (ChartButton) component; UpdaterThread updaterThread = new UpdaterThread(chartButton); updaterThread.start(); } } }
From source file:com.skysql.manager.ui.components.ChartsLayout.java
License:Open Source License
/** * Refresh code./* w ww . jav a 2s. c o m*/ * * @param chartButton the chart button * @param updaterThread the updater thread */ public void refreshCode(ChartButton chartButton, UpdaterThread updaterThread) { String systemID, nodeID; VaadinSession session = getSession(); if (session == null) { session = VaadinSession.getCurrent(); } ManagerUI managerUI = session.getAttribute(ManagerUI.class); ClusterComponent componentInfo = session.getAttribute(ClusterComponent.class); switch (componentInfo.getType()) { case system: systemID = componentInfo.getID(); nodeID = SystemInfo.SYSTEM_NODEID; break; case node: systemID = componentInfo.getParentID(); nodeID = componentInfo.getID(); break; default: return; } final UserChart userChart = (UserChart) chartButton.getData(); final Chart chart = chartButton.getChart(); boolean needsRedraw = false; String[] timeStamps = null; final Configuration configuration = chart.getConfiguration(); for (String monitorID : userChart.getMonitorIDs()) { if (updaterThread != null && updaterThread.flagged) { ManagerUI.log(this.getClass().getName() + " - flagged is set before API call"); return; } ManagerUI.log("ChartsLayout - redraw loop MonitorID: " + monitorID); final MonitorRecord monitor = Monitors.getMonitor(monitorID); if (monitor == null) { // monitor was removed from the system: skip ManagerUI.log("monitor was removed from the system"); continue; } MonitorData monitorData = (MonitorData) userChart.getMonitorData(monitor.getID()); if (monitorData == null) { String method; if (UserChart.ChartType.LineChart.name().equals(userChart.getType())) { method = MonitorData.METHOD_AVG; } else if (UserChart.ChartType.AreaChart.name().equals(userChart.getType())) { method = MonitorData.METHOD_MINMAX; } else { continue; // unknown chart type, skip } monitorData = new MonitorData(monitor, systemID, nodeID, time, interval, userChart.getPoints(), method); needsRedraw = true; } else if (monitorData.update(systemID, nodeID, time, interval, userChart.getPoints()) == true) { // data in chart needs to be updated needsRedraw = true; } else { continue; // no update needed } if (timeStamps == null) { DateConversion dateConversion = session.getAttribute(DateConversion.class); ArrayList<Long> unixTimes = monitorData.getTimeStamps(); if (unixTimes != null) { timeStamps = new String[unixTimes.size()]; int timeSpacer = unixTimes.size() / 15; for (int x = 0; x < unixTimes.size(); x++) { timeStamps[x] = (x % timeSpacer != 0) ? "\u00A0" : dateConversion.stampToString(unixTimes.get(x)); } } } if (updaterThread != null && updaterThread.flagged) { ManagerUI.log("ChartsLayout - flagged is set before UI redraw"); return; } final MonitorData finalMonitorData = monitorData; final String finalMonitorID = monitorID; managerUI.access(new Runnable() { @Override public void run() { // Here the UI is locked and can be updated ManagerUI.log("ChartsLayout access run() monitorID: " + finalMonitorID); if (UserChart.ChartType.LineChart.name().equals(userChart.getType())) { ListSeries ls = null, testLS; List<Series> lsList = configuration.getSeries(); Iterator seriesIter = lsList.iterator(); while (seriesIter.hasNext()) { testLS = (ListSeries) seriesIter.next(); if (testLS.getName().equals(monitor.getName())) { ls = testLS; break; } } if (ls == null) { ls = new ListSeries(monitor.getName()); configuration.addSeries(ls); } userChart.setMonitorData(monitor.getID(), finalMonitorData); ArrayList<Number> avgList = finalMonitorData.getAvgPoints(); ls.setData(avgList); } else if (UserChart.ChartType.AreaChart.name().equals(userChart.getType())) { RangeSeries rs = null, testRS; List<Series> lsList = configuration.getSeries(); Iterator seriesIter = lsList.iterator(); while (seriesIter.hasNext()) { testRS = (RangeSeries) seriesIter.next(); if (testRS.getName().equals(monitor.getName())) { rs = testRS; break; } } if (rs == null) { rs = new RangeSeries(monitor.getName()); configuration.addSeries(rs); } userChart.setMonitorData(monitor.getID(), finalMonitorData); ArrayList<Number> minList = finalMonitorData.getMinPoints(); ArrayList<Number> maxList = finalMonitorData.getMaxPoints(); if (minList != null && maxList != null && minList.size() > 0 && maxList.size() > 0 && minList.size() == maxList.size()) { Object[] minArray = finalMonitorData.getMinPoints().toArray(); Object[] maxArray = finalMonitorData.getMaxPoints().toArray(); Number[][] dataList = new Number[minList.size()][2]; for (int x = 0; x < minList.size(); x++) { dataList[x][0] = (Number) minArray[x]; dataList[x][1] = (Number) maxArray[x]; } rs.setRangeData(dataList); } else { rs.setRangeData(new Number[0][0]); } } } }); } // for final boolean finalNeedsRedraw = needsRedraw; final String[] finalTimeStamps = timeStamps; final ChartButton finalChartButton = chartButton; managerUI.access(new Runnable() { @Override public void run() { // Here the UI is locked and can be updated if (finalNeedsRedraw) { ManagerUI.log("ChartsLayout needsRedraw"); if (finalTimeStamps != null) { XAxis xAxis = configuration.getxAxis(); Labels labels = new Labels(); labels.setRotation(-45); labels.setAlign(HorizontalAlign.RIGHT); xAxis.setLabels(labels); xAxis.setCategories(finalTimeStamps); } chart.drawChart(configuration); finalChartButton.setVisible(true); } } }); }
From source file:com.skysql.manager.ui.components.NodesLayout.java
License:Open Source License
/** * Instantiates a new nodes layout.// w w w . j a v a 2s . co m * * @param systemRecord the system record */ public NodesLayout(SystemRecord systemRecord) { addStyleName("network"); addLayoutClickListener(new LayoutClickListener() { public void layoutClick(LayoutClickEvent event) { Component child; VaadinSession session = getSession(); boolean isDoubleClick = event.isDoubleClick(); ManagerUI.log("is DoubleClick: " + isDoubleClick); if (event.isDoubleClick() && (child = event.getChildComponent()) != null && (child instanceof ComponentButton)) { // Get the child component which was double-clicked ComponentButton button = (ComponentButton) child; ClusterComponent clusterComponent = (ClusterComponent) button.getData(); if (isEditable) { new ComponentDialog(clusterComponent, button); } else { if (clusterComponent.getType() == ClusterComponent.CCType.system) { SystemInfo systemInfo = session.getAttribute(SystemInfo.class); String clusterID = clusterComponent.getID(); systemInfo.setCurrentSystem(clusterID); session.setAttribute(SystemInfo.class, systemInfo); ManagerUI.log("new systemID: " + clusterID); clusterComponent.setButton(button); OverviewPanel overviewPanel = session.getAttribute(OverviewPanel.class); overviewPanel.refresh(); } } } else if (!isEditable && (child = event.getChildComponent()) != null && (child instanceof ComponentButton)) { // Get the child component which was clicked ComponentButton button = (ComponentButton) child; OverviewPanel overviewPanel = session.getAttribute(OverviewPanel.class); overviewPanel.clickLayout(button, true); } } }); }
From source file:com.skysql.manager.ui.components.NodesLayout.java
License:Open Source License
/** * Refresh./* ww w . j a v a 2 s . c o m*/ * * @param updaterThread the updater thread * @param parentSystemRecord the parent system record */ public synchronized void refresh(final OverviewPanel.UpdaterThread updaterThread, final SystemRecord parentSystemRecord) { VaadinSession session = getSession(); if (session == null) { session = VaadinSession.getCurrent(); } if (session == null) { return; } ManagerUI managerUI = session.getAttribute(ManagerUI.class); SystemInfo systemInfo = session.getAttribute(SystemInfo.class); OverviewPanel overviewPanel = session.getAttribute(OverviewPanel.class); if (parentSystemRecord == null) { systemID = null; placeholderLayout("Systems"); return; } else if (parentSystemRecord.getNodes().length == 0) { placeholderLayout("Components"); return; } else { if (placeholderLayout != null) { removeComponent(placeholderLayout); placeholderLayout = null; addStyleName("network"); } } String[] newComponents = parentSystemRecord.getNodes(); if (!parentSystemRecord.getID().equals(systemID) || (newComponents != null && !Arrays.equals(newComponents, components))) { systemID = parentSystemRecord.getID(); components = newComponents; ManagerUI.log("Reload Components"); String currentSelectedID = null; CCType currentSelectedType = null; ClusterComponent currentClusterComponent = session.getAttribute(ClusterComponent.class); if (currentClusterComponent != null) { currentSelectedID = currentClusterComponent.getID(); currentSelectedType = currentClusterComponent.getType(); } session.lock(); try { // Here the UI is locked and can be updated ManagerUI.log("NodesLayout access run() removeall"); removeAllComponents(); ArrayList<ComponentButton> newButtons = new ArrayList<ComponentButton>(); for (String componentID : parentSystemRecord.getNodes()) { final ClusterComponent clusterComponent; if (parentSystemRecord.getParentID() == null) { // this is the ROOT record, where "nodes" is really the flat list of systems clusterComponent = systemInfo.getSystemRecord(componentID); } else { // this is a normal System record clusterComponent = new NodeInfo(parentSystemRecord.getID(), parentSystemRecord.getSystemType()); clusterComponent.setID(componentID); } // if (updaterThread.flagged) { // ManagerUI.log("NodesLayout - flagged is set while adding nodes"); // return; // } ComponentButton button = clusterComponent.getButton(); if (button == null) { ManagerUI.log("NodesLayout access run() button not in component"); button = findButton(clusterComponent); } if (button == null) { ManagerUI.log("NodesLayout access run() button not found"); button = new ComponentButton(clusterComponent); } addComponent(button); setComponentAlignment(button, Alignment.MIDDLE_CENTER); button.setEditable(isEditable); if (clusterComponent.getID().equals(currentSelectedID) && clusterComponent.getType().equals(currentSelectedType) && !button.isSelected()) { overviewPanel.clickLayout(button, true); } newButtons.add(button); } buttons = newButtons; } finally { session.unlock(); } } // if (updaterThread.flagged) { // ManagerUI.log("NodesLayout - flagged is set after removeall"); // return; // } ManagerUI.log("NodesLayout - before for loop - buttons: " + buttons.size()); for (final ComponentButton button : buttons) { final ClusterComponent currentComponent = (ClusterComponent) button.getData(); final ClusterComponent newComponent; switch (currentComponent.getType()) { case system: newComponent = systemInfo.updateSystem(currentComponent.getID()); break; case node: NodeInfo nodeInfo = (NodeInfo) currentComponent; newComponent = new NodeInfo(nodeInfo.getParentID(), nodeInfo.getSystemType(), nodeInfo.getID()); break; default: continue; } // if (updaterThread.flagged) { // ManagerUI.log("NodesLayout - flagged is set before run() "); // return; // } managerUI.access(new Runnable() { @Override public void run() { // Here the UI is locked and can be updated ManagerUI.log("NodesLayout access run() button " + newComponent.getName()); String newName = newComponent.getName(); if (newName != null && !newName.equals(currentComponent.getName())) { button.setName(newName); currentComponent.setName(newName); } String newState = newComponent.getState(); currentComponent.setState(newState); String toolTip = null; switch (newComponent.getType()) { case system: toolTip = ((SystemRecord) newComponent).ToolTip(); break; case node: MonitorLatest monitorLatest = newComponent.getMonitorLatest(); String newCapacity = monitorLatest.getData().get(MonitorNames.capacity.name()); button.setIcon(currentComponent.getType().toString(), newState, newCapacity); NodeInfo nodeInfo = (NodeInfo) newComponent; toolTip = nodeInfo.ToolTip(); // carry over RunningTask(s) nodeInfo.setCommandTask(((NodeInfo) currentComponent).getCommandTask()); button.setCommandLabel(nodeInfo.getTask()); break; default: toolTip = "Unknown component type"; ManagerUI.error(toolTip); break; } button.setDescription(toolTip); button.setData(newComponent); if (button.isSelected()) { getSession().setAttribute(ClusterComponent.class, newComponent); } } }); } // for all nodes }
From source file:com.skysql.manager.ui.components.ScriptingProgressLayout.java
License:Open Source License
/** * Builds the progress./*from w w w . j a va2s .c om*/ * * @param taskRecord the task record * @param command the command * @param steps the steps */ public void buildProgress(TaskRecord taskRecord, String command, String steps) { VaadinSession session = getSession(); if (session == null) { session = VaadinSession.getCurrent(); } if (observerMode) { // String userName = Users.getUserNames().get(taskRecord.getUser()); String userID = taskRecord.getUserID(); UserInfo userInfo = (UserInfo) session.getAttribute(UserInfo.class); DateConversion dateConversion = session.getAttribute(DateConversion.class); setTitle(command + " was started on " + dateConversion.adjust(taskRecord.getStart()) + " by " + userID); } else { setTitle(command); } String[] stepIDs; try { stepIDs = steps.split(","); } catch (NullPointerException npe) { stepIDs = new String[] {}; } totalSteps = stepIDs.length; primitives = new String[totalSteps]; taskImages = new Embedded[totalSteps]; // add steps icons progressIconsLayout.removeAllComponents(); for (int index = 0; index < totalSteps; index++) { String stepID = stepIDs[index].trim(); String description = Steps.getDescription(stepID); VerticalLayout stepLayout = new VerticalLayout(); progressIconsLayout.addComponent(stepLayout); stepLayout.addStyleName("stepIcons"); Label name = new Label(stepID); stepLayout.addComponent(name); stepLayout.setComponentAlignment(name, Alignment.MIDDLE_CENTER); Embedded image = new Embedded(null, new ThemeResource("img/scripting/pending.png")); image.setImmediate(true); image.setDescription(description); stepLayout.addComponent(image); primitives[index] = stepID; taskImages[index] = image; } setProgress(""); }
From source file:com.skysql.manager.ui.components.ScriptingProgressLayout.java
License:Open Source License
/** * Asynch refresh./*from w w w .ja va 2 s . c o m*/ * * @param updaterThread the updater thread */ private void asynchRefresh(final UpdaterThread updaterThread) { VaadinSession session = getSession(); if (session == null) { session = VaadinSession.getCurrent(); } ManagerUI managerUI = session.getAttribute(ManagerUI.class); managerUI.access(new Runnable() { @Override public void run() { // Here the UI is locked and can be updated VaadinSession session = getSession(); if (session == null) { session = VaadinSession.getCurrent(); } ManagerUI.log(this.getClass().getName() + " access run(): "); DateConversion dateConversion = session.getAttribute(DateConversion.class); String stateString; if ((stateString = taskRecord.getState()) == null) { return; // we're waiting for something to happen } CommandStates.States state = CommandStates.States.valueOf(stateString); setResult(CommandStates.getDescriptions().get(state.name())); String indexString; if ((indexString = taskRecord.getIndex()) == null) { return; // we're waiting for something to happen } int index = (state == States.done) ? totalSteps - 1 : Integer.parseInt(indexString) - 1; while (lastProgressIndex < index) { taskImages[lastProgressIndex].setSource(new ThemeResource("img/scripting/past.png")); lastProgressIndex++; } if (index >= 0) { switch (state) { case running: taskImages[index].setSource(new ThemeResource("img/scripting/active.png")); setProgress(taskImages[index].getDescription()); break; case done: taskImages[index].setSource(new ThemeResource("img/scripting/past.png/")); break; case error: case missing: taskImages[index].setSource(new ThemeResource("img/scripting/error.png")); break; case cancelled: case stopped: taskImages[index].setSource(new ThemeResource("img/scripting/error.png")); break; default: break; } } setResult(CommandStates.getDescriptions().get(state.name())); switch (state) { case running: break; case error: case missing: setErrorInfo(taskRecord.getError()); case done: case cancelled: case stopped: default: runningTask.close(); break; } } }); }
From source file:com.skysql.manager.ui.components.SystemLayout.java
License:Open Source License
/** * Instantiates a new system layout./* w w w.j a v a 2s. c o m*/ * * @param systemRecord the system record */ public SystemLayout(SystemRecord systemRecord) { addStyleName("systemLayout"); setWidth(Sizeable.SIZE_UNDEFINED, Sizeable.Unit.PERCENTAGE); setMargin(new MarginInfo(false, true, false, false)); final HorizontalLayout systemHeader = new HorizontalLayout(); systemHeader.addStyleName("panelHeaderLayout"); systemHeader.setSpacing(true); systemHeader.setWidth("100%"); systemHeader.setHeight("23px"); addComponent(systemHeader); backButton = new NativeButton(); backButton.setStyleName("backButton"); backButton.setDescription("Back to Systems"); systemHeader.addComponent(backButton); backButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { VaadinSession session = getSession(); SystemInfo systemInfo = session.getAttribute(SystemInfo.class); OverviewPanel overviewPanel = session.getAttribute(OverviewPanel.class); ComponentButton button = systemInfo.getCurrentSystem().getButton(); String parentID = systemInfo.getCurrentSystem().getParentID(); systemInfo.setCurrentSystem(parentID); session.setAttribute(SystemInfo.class, systemInfo); ManagerUI.log("new systemID: " + parentID); overviewPanel.clickLayout(button, false); overviewPanel.refresh(); } }); final Label systemLabel = new Label("Systems"); systemLabel.setSizeUndefined(); systemHeader.addComponent(systemLabel); systemHeader.setComponentAlignment(systemLabel, Alignment.MIDDLE_LEFT); systemHeader.setExpandRatio(systemLabel, 1.0f); systemSlot = new HorizontalLayout(); addComponent(systemSlot); // initialize System button refresh(null, null); }