/** * Returns a list of all legal parameter values for {@link ShowPlotViewHandler}. The key is the * display name and the value is the parameter value to {@link * ShowPlotViewHandler#VIEW_NAME_PARAM}. * * <p>The list of legal values is made up of the following sources: * * <ul> * <li>All of the Plot Views that have been activated and registered themselves * PlotWindowManager * <li>All views in the view registry whose ID starts with {@link IPlotWindowManager#ID} * <li>All the view references whose primary ID is {@link * IPlotWindowManager#PLOT_VIEW_MULTIPLE_ID} * <li>All Gui Names from {@link PlotService#getGuiNames()}. These are suffixed with {@link * ShowPlotViewHandler#IN_PLOT_SERVER_SUFFIX} * <li>A <code>null</code> value for a option to open a new unique view name. * </ul> */ @Override public Map<String, String> getParameterValues() { PlotWindowManager manager = PlotWindowManager.getPrivateManager(); String[] views = manager.getAllPossibleViews(null, false); Set<String> guiNamesWithData = Collections.emptySet(); try { String[] names = PlotServerProvider.getPlotServer().getGuiNames(); if (names != null) guiNamesWithData = new HashSet<String>(Arrays.asList(names)); } catch (Exception e) { // non-fatal, just means no IN_PLOT_SERVER_SUFFIX next to view name, still shouldn't happen logger.debug("Failed to get list of Gui Names from Plot Server", e); } Map<String, String> values = new HashMap<String, String>(); for (String view : views) { String viewDisplay = view; DATA_BLOCK: if (guiNamesWithData.contains(view)) { try { DataBean db = PlotServerProvider.getPlotServer().getData(view); if (db == null || db.getData() == null || db.getData().isEmpty()) break DATA_BLOCK; viewDisplay = view + IN_PLOT_SERVER_SUFFIX; } catch (Exception ne) { break DATA_BLOCK; } } values.put(viewDisplay, view); } // null is a legal argument, means open a new view values.put(NEW_PLOT_VIEW, null); return values; }
private void processNewFile(DataBean bean) { try { locker.acquire(); } catch (InterruptedException e) { e.printStackTrace(); } playback.addFile((String) bean.getGuiParameters().get(GuiParameters.FILENAME)); String colourScheme = getPreferenceColourMapChoice(); SWTGridEntry entry = new SWTGridEntry( (String) bean.getGuiParameters().get(GuiParameters.FILENAME), bean.getData().get(0), canvas, colourScheme, getPreferenceAutoContrastLo(), getPreferenceAutoContrastHi()); Integer xPos = (Integer) bean.getGuiParameters().get(GuiParameters.IMAGEGRIDXPOS); Integer yPos = (Integer) bean.getGuiParameters().get(GuiParameters.IMAGEGRIDYPOS); if (xPos != null && yPos != null) imageGrid.addEntry(entry, xPos, yPos); else imageGrid.addEntry(entry); imageGrid.setThumbnailSize(getPreferenceImageSize()); locker.release(); if (liveActive) playback.moveToLast(); }
@SuppressWarnings("unchecked") @Override public void update(Object source, Object changeCode) { if (stopLoading) return; if (source == ImageExplorerView.FOLDER_UPDATE_MARKER) { // Folder Update if (changeCode instanceof List<?>) { playback.clearPlayback(); btnPlay .getDisplay() .asyncExec( new Runnable() { @Override public void run() { resetPlaying(false); if (isLive) { playback.setDelay(50); playback.setStepping(1); playback.start(); btnPlay.setSelection(true); btnPlay.setImage(imgStill); execSvc.execute(playback); if (!monActive) CommandExecutor.executeCommand( getViewSite(), "uk.ac.diamond.scisoft.analysis.rcp.MontorDirectoryAction"); cmbDirectoryLocation.setText(currentDir); isLive = false; } } }); filesToLoad = (List<String>) changeCode; processClientLocalUpdate(); } } else { if (source instanceof RMIPlotServer && changeCode instanceof String) { String viewName = (String) changeCode; if (!viewName.startsWith("Image Explorer")) return; RMIPlotServer server = (RMIPlotServer) source; try { String[] names = server.getGuiNames(); final DataBean bean = server.getData(names[0]); // when imagegrid size is set it means we need to reset the grid if (bean != null && bean.getGuiParameters().get(GuiParameters.IMAGEGRIDSIZE) != null) { Display.getDefault() .syncExec( new Runnable() { @Override public void run() { Integer[] gridDim = (Integer[]) bean.getGuiParameters().get(GuiParameters.IMAGEGRIDSIZE); if (imageGrid != null) imageGrid.dispose(); imageGrid = new PlotServerSWTImageGrid( gridDim[0], gridDim[1], canvas, plotViewName); imageGrid.setThumbnailSize(getPreferenceImageSize()); } }); } if (bean != null) { if (bean.getData().isEmpty()) { // We try to load the data from the filename if data not in the databean String filename = (String) bean.getGuiParameters().get(GuiParameters.FILENAME); if (filename == null) return; List<DatasetWithAxisInformation> data = new ArrayList<>(); DatasetWithAxisInformation dwai = new DatasetWithAxisInformation(); IDataHolder holder = LoaderFactory.getData(filename); IDataset loadedData = holder.getDataset(0); dwai.setData(loadedData); data.add(dwai); bean.setData(data); } processUpdate(bean); } else { throw new Exception("Databean is null. This image grid use is not supported."); } } catch (Exception e) { logger.error("Error updating data from server: ", e); } } } }