List of usage examples for java.util LinkedHashMap remove
V remove(Object key);
From source file:ubic.gemma.datastructure.matrix.ExpressionDataMatrixColumnSort.java
/** * Divide the biomaterials up into chunks based on the experimental factor given, keeping everybody in order. * /*from w ww . jav a 2 s . c o m*/ * @param ef * @param bms * @return ordered map of fv->bm where fv is of ef, or null if it couldn't be done properly. */ private static LinkedHashMap<FactorValueValueObject, List<BioMaterialValueObject>> chunkOnFactorVO( ExperimentalFactor ef, List<BioMaterialValueObject> bms) { if (bms == null) { return null; } LinkedHashMap<FactorValueValueObject, List<BioMaterialValueObject>> chunks = new LinkedHashMap<FactorValueValueObject, List<BioMaterialValueObject>>(); /* * Get the factor values in the order we have things right now */ Collection<Long> factorValueIds = EntityUtils.getIds(ef.getFactorValues()); for (BioMaterialValueObject bm : bms) { for (FactorValueValueObject fv : bm.getFactorValueObjects()) { if (!factorValueIds.contains(fv.getId())) { continue; } if (chunks.keySet().contains(fv)) { continue; } chunks.put(fv, new ArrayList<BioMaterialValueObject>()); } } /* * What if bm doesn't have a value for the factorvalue. Need a dummy value. */ FactorValueValueObject dummy = new FactorValueValueObject(); dummy.setFactorId(ef.getId()); dummy.setValue(""); dummy.setId(-1L); chunks.put(dummy, new ArrayList<BioMaterialValueObject>()); for (BioMaterialValueObject bm : bms) { boolean found = false; for (FactorValueValueObject fv : bm.getFactorValueObjects()) { if (factorValueIds.contains(fv.getId())) { found = true; assert chunks.containsKey(fv); chunks.get(fv).add(bm); } } if (!found) { if (log.isDebugEnabled()) log.debug(bm + " has no value for factor=" + ef + "; using dummy value"); chunks.get(dummy).add(bm); } } if (chunks.get(dummy).size() == 0) { if (log.isDebugEnabled()) log.debug("removing dummy"); chunks.remove(dummy); } log.debug(chunks.size() + " chunks for " + ef + ", from current chunk of size " + bms.size()); /* * Sanity check */ int total = 0; for (FactorValueValueObject fv : chunks.keySet()) { List<BioMaterialValueObject> chunk = chunks.get(fv); total += chunk.size(); } assert total == bms.size() : "expected " + bms.size() + ", got " + total; return chunks; }
From source file:org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator.java
@Override protected LinkedHashMap<String, ZuulRoute> locateRoutes() { LinkedHashMap<String, ZuulRoute> routesMap = new LinkedHashMap<String, ZuulRoute>(); routesMap.putAll(super.locateRoutes()); if (this.discovery != null) { Map<String, ZuulRoute> staticServices = new LinkedHashMap<String, ZuulRoute>(); for (ZuulRoute route : routesMap.values()) { String serviceId = route.getServiceId(); if (serviceId == null) { serviceId = route.getId(); }/*from ww w.j a va2s . c om*/ if (serviceId != null) { staticServices.put(serviceId, route); } } // Add routes for discovery services by default List<String> services = this.discovery.getServices(); String[] ignored = this.properties.getIgnoredServices().toArray(new String[0]); for (String serviceId : services) { // Ignore specifically ignored services and those that were manually // configured String key = "/" + mapRouteToService(serviceId) + "/**"; if (staticServices.containsKey(serviceId) && staticServices.get(serviceId).getUrl() == null) { // Explicitly configured with no URL, cannot be ignored // all static routes are already in routesMap // Update location using serviceId if location is null ZuulRoute staticRoute = staticServices.get(serviceId); if (!StringUtils.hasText(staticRoute.getLocation())) { staticRoute.setLocation(serviceId); } } if (!PatternMatchUtils.simpleMatch(ignored, serviceId) && !routesMap.containsKey(key)) { // Not ignored routesMap.put(key, new ZuulRoute(key, serviceId)); } } } if (routesMap.get(DEFAULT_ROUTE) != null) { ZuulRoute defaultRoute = routesMap.get(DEFAULT_ROUTE); // Move the defaultServiceId to the end routesMap.remove(DEFAULT_ROUTE); routesMap.put(DEFAULT_ROUTE, defaultRoute); } LinkedHashMap<String, ZuulRoute> values = new LinkedHashMap<>(); for (Entry<String, ZuulRoute> entry : routesMap.entrySet()) { String path = entry.getKey(); // Prepend with slash if not already present. if (!path.startsWith("/")) { path = "/" + path; } if (StringUtils.hasText(this.properties.getPrefix())) { path = this.properties.getPrefix() + path; if (!path.startsWith("/")) { path = "/" + path; } } values.put(path, entry.getValue()); } return values; }
From source file:edu.csun.ecs.cs.multitouchj.ui.event.ObjectEventManager.java
protected void handleEvent() { setRunning(true);//from w w w . j av a 2 s .com for (ObjectType objectType : ObjectType.values()) { eventsCleaned.put(objectType, true); } while (isRunning()) { synchronized (activeObjects) { // check for "started" or "moved" if (isUpdated()) { for (ObjectType objectType : activeObjects.keySet()) { LinkedHashMap<Integer, ObjectObserverEvent> objects = activeObjects.get(objectType); if (objects.size() > 0) { LinkedList<ObjectObserverEvent> ooes = new LinkedList<ObjectObserverEvent>( objects.values()); ObjectEvent objectEvent = null; if (ObjectType.Floated.equals(objectType)) { objectEvent = new FloatEvent(this, ooes.getLast(), ooes, (eventsCleaned.get(objectType)) ? ObjectEvent.Status.Started : ObjectEvent.Status.Moved); } else { objectEvent = new TouchEvent(this, ooes.getLast(), ooes, (eventsCleaned.get(objectType)) ? ObjectEvent.Status.Started : ObjectEvent.Status.Moved); } notifyEventListeners(objectEvent); eventsCleaned.put(objectType, false); } } setUpdated(false); } // check for "ended" for (ObjectType objectType : activeObjects.keySet()) { LinkedHashMap<Integer, ObjectObserverEvent> objects = activeObjects.get(objectType); if (objects.size() > 0) { LinkedList<ObjectObserverEvent> ooes = new LinkedList<ObjectObserverEvent>( objects.values()); // check for ones expired long currentTime = (new Date()).getTime(); LinkedList<Integer> deletedIds = new LinkedList<Integer>(); for (ObjectObserverEvent ooe : ooes) { if ((currentTime - ooe.getTime()) >= CLEAN_UP_TIME) { deletedIds.add(ooe.getId()); } } for (int deletedId : deletedIds) { objects.remove(deletedId); } // check if all expired if (objects.size() == 0) { ObjectEvent objectEvent = null; if (ObjectType.Floated.equals(objectType)) { objectEvent = new FloatEvent(this, ooes.getLast(), ooes, ObjectEvent.Status.Ended); } else { objectEvent = new TouchEvent(this, ooes.getLast(), ooes, ObjectEvent.Status.Ended); } notifyEventListeners(objectEvent); eventsCleaned.put(objectType, true); } } } } try { Thread.sleep(15); } catch (Exception exception) { } } }
From source file:org.dcm4che3.tool.unvscp.UnvSCP.java
public Attributes calculateStorageCommitmentResult(String calledAET, Attributes actionInfo) throws DicomServiceException { Sequence requestSeq = actionInfo.getSequence(Tag.ReferencedSOPSequence); int size = requestSeq.size(); String[] sopIUIDs = new String[size]; Attributes eventInfo = new Attributes(6); eventInfo.setString(Tag.RetrieveAETitle, VR.AE, calledAET); eventInfo.setString(Tag.StorageMediaFileSetID, VR.SH, ddReader.getFileSetID()); eventInfo.setString(Tag.StorageMediaFileSetUID, VR.SH, ddReader.getFileSetUID()); eventInfo.setString(Tag.TransactionUID, VR.UI, actionInfo.getString(Tag.TransactionUID)); Sequence successSeq = eventInfo.newSequence(Tag.ReferencedSOPSequence, size); Sequence failedSeq = eventInfo.newSequence(Tag.FailedSOPSequence, size); LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(size * 4 / 3); for (int i = 0; i < sopIUIDs.length; i++) { Attributes item = requestSeq.get(i); map.put(sopIUIDs[i] = item.getString(Tag.ReferencedSOPInstanceUID), item.getString(Tag.ReferencedSOPClassUID)); }//ww w. j a v a 2 s . c o m IDicomReader ddr = ddReader; try { Attributes patRec = ddr.findPatientRecord(); while (patRec != null) { Attributes studyRec = ddr.findStudyRecord(patRec); while (studyRec != null) { Attributes seriesRec = ddr.findSeriesRecord(studyRec); while (seriesRec != null) { Attributes instRec = ddr.findLowerInstanceRecord(seriesRec, true, sopIUIDs); while (instRec != null) { String iuid = instRec.getString(Tag.ReferencedSOPInstanceUIDInFile); String cuid = map.remove(iuid); if (cuid.equals(instRec.getString(Tag.ReferencedSOPClassUIDInFile))) successSeq.add(refSOP(iuid, cuid, Status.Success)); else failedSeq.add(refSOP(iuid, cuid, Status.ClassInstanceConflict)); instRec = ddr.findNextInstanceRecord(instRec, true, sopIUIDs); } seriesRec = ddr.findNextSeriesRecord(seriesRec); } studyRec = ddr.findNextStudyRecord(studyRec); } patRec = ddr.findNextPatientRecord(patRec); } } catch (IOException e) { LOG.info("Failed to M-READ " + dicomDir, e); throw new DicomServiceException(Status.ProcessingFailure, e); } for (Map.Entry<String, String> entry : map.entrySet()) { failedSeq.add(refSOP(entry.getKey(), entry.getValue(), Status.NoSuchObjectInstance)); } if (failedSeq.isEmpty()) eventInfo.remove(Tag.FailedSOPSequence); return eventInfo; }
From source file:org.cyberoam.iview.charts.Chart.java
/** * Function to write a given ChartID to pdf file * @param pdfFileName specifies the pdf where chart is written.Please specify full path with the filename. * @param reportGroup id specifies the chart to be generated * @param startdate specifies start date * @param enddate specifies end date//from w w w .j a v a 2 s.c o m * @param limit specifies number of records per record to be written in report */ public static void generatePDFReportGroup(OutputStream out, int reportGroupID, String applianceID, String startDate, String endDate, String limit, int[] deviceIDs, HttpServletRequest request, LinkedHashMap paramMap) throws Exception { float width = 768; float height = 1024; float rec_hieght = 470; Rectangle pagesize = new Rectangle(768, 1024); Document document = new Document(pagesize, 30, 30, 30, 30); JFreeChart chart = null; SqlReader sqlReader = new SqlReader(false); //CyberoamLogger.sysLog.debug("pdf:"+pdfFileName); CyberoamLogger.sysLog.debug("reportGroupID:" + reportGroupID); CyberoamLogger.sysLog.debug("applianceID:" + applianceID); CyberoamLogger.sysLog.debug("startDate:" + startDate); CyberoamLogger.sysLog.debug("endDate:" + endDate); CyberoamLogger.sysLog.debug("limit:" + limit); try { //PdfWriter writer = PdfWriter.getInstance(document, response!=null ? response.getOutputStream():new FileOutputStream(pdfFileName)); PdfWriter writer = PdfWriter.getInstance(document, out); writer.setPageEvent(new Chart()); document.addAuthor("iView"); document.addSubject("iView Report"); document.open(); PdfContentByte contentByte = writer.getDirectContent(); ReportGroupBean reportGroupBean = ReportGroupBean.getRecordbyPrimarykey(reportGroupID); ArrayList reportList = reportGroupBean.getReportIdByReportGroupId(reportGroupID); ReportBean reportBean; ResultSetWrapper rsw = null; String seperator = System.getProperty("file.separator"); //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator + "iViewPDF.jpg"; String path = InitServlet.contextPath + seperator + "images" + seperator + "iViewPDF.jpg"; Image iViewImage = Image.getInstance(path); iViewImage.scaleAbsolute(750, 900); //iViewImage.scaleAbsolute(600,820); iViewImage.setAbsolutePosition(10, 10); document.add(iViewImage); document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); /* * Generating Table on the First Page of Report providing summary of Content */ PdfPTable frontPageTable = new PdfPTable(2); PdfPCell dataCell; ReportGroupRelationBean reportGroupRelationBean; String reportName = ""; Color tableHeadBackColor = new Color(150, 174, 190); Color tableContentBackColor = new Color(229, 232, 237); Color tableBorderColor = new Color(229, 232, 237); dataCell = new PdfPCell(new Phrase(new Chunk("Report Profile", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255))))); dataCell.setBackgroundColor(tableHeadBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); /** * Getting dynamic title. */ String title = ""; if (paramMap != null) { title = paramMap.get("title").toString(); paramMap.remove("title"); } if (request != null) title = getFormattedTitle(request, reportGroupBean, true); dataCell = new PdfPCell(new Phrase(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255))))); dataCell.setBackgroundColor(tableHeadBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Start Date", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(startDate)); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("End Date", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(endDate)); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("iView Server Time", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); java.util.Date currentDate = new java.util.Date(); dataCell = new PdfPCell(new Phrase(currentDate.toString())); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Reports", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); int len = reportList.size(); for (int k = 0; k < len; k++) { reportGroupRelationBean = (ReportGroupRelationBean) reportList.get(k); reportName += " " + (k + 1) + ". " + ReportBean.getRecordbyPrimarykey(reportGroupRelationBean.getReportId()).getTitle() + "\n"; } dataCell = new PdfPCell(new Phrase("\n" + reportName + "\n")); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Device Names (IP Address)", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); DeviceBean deviceBean = null; String deviceNameWithIP = ""; if (deviceIDs != null) { for (int i = 0; i < deviceIDs.length; i++) { deviceBean = DeviceBean.getRecordbyPrimarykey(deviceIDs[i]); if (deviceBean != null) { deviceNameWithIP += " " + (i + 1) + ". " + deviceBean.getName() + " (" + deviceBean.getIp() + ")\n"; } } } dataCell = new PdfPCell(new Phrase("\n" + deviceNameWithIP + "\n")); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); /* * Adding Table to PDF */ document.add(frontPageTable); /* * Adding Charts and Table to PDF */ for (int i = 0; i < reportList.size(); i++) { document.newPage(); reportBean = ReportBean .getRecordbyPrimarykey(((ReportGroupRelationBean) reportList.get(i)).getReportId()); String query = null; if (request == null) { query = PrepareQuery.getQuery(reportBean, startDate, endDate, applianceID, null, null, "0", limit, paramMap); } else { PrepareQuery prepareQuery = new PrepareQuery(); query = prepareQuery.getQuery(reportBean, request); } CyberoamLogger.sysLog.debug("PDF:ReportID:" + reportBean.getReportId() + "Query->" + query); try { rsw = sqlReader.getInstanceResultSetWrapper(query); } catch (org.postgresql.util.PSQLException e) { if (query.indexOf("5min_ts_20") > -1) { query = query.substring(0, query.indexOf("5min_ts_20")) + "4hr" + query.substring(query.indexOf("5min_ts_20") + 16, query.length()); CyberoamLogger.appLog.debug("New query : " + query); rsw = sqlReader.getInstanceResultSetWrapper(query); } else { CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e); } } catch (Exception e) { CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e); rsw.close(); } /* * PDF Rendering work starts here */ for (int j = 0; j < (int) (rec_hieght / 16) + 1; j++) { document.add(new Paragraph("\n")); } // This fix is to resolve the problems associated with reports which don't have graphs. // If there is no graph associated with the report than no need to generate //a chart for it. GraphBean graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getReportId()); //if(graphBean!=null) if (reportBean.getReportFormatId() != 2) { chart = Chart.getChart(reportBean.getReportId(), rsw, null); PdfTemplate pdfTemplate = contentByte.createTemplate(width, height); Graphics2D graphics2D = pdfTemplate.createGraphics(width, height); Rectangle2D rectangle = new Rectangle2D.Double(100, 85, 540, rec_hieght); chart.draw(graphics2D, rectangle); graphics2D.dispose(); contentByte.addTemplate(pdfTemplate, 0, 0); } else { Paragraph p = new Paragraph(reportBean.getTitle() + "\n\n", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD)); p.setAlignment("center"); document.add(p); } // Retrieving PdfPTable PdfPTable pdfTable = getPdfPTable(reportBean, rsw); rsw.close(); /* * Adding Table to PDF */ document.add(pdfTable); } CyberoamLogger.appLog.info("*************Finishing Chart****************"); } catch (Exception e) { CyberoamLogger.sysLog.debug("Chart.writeChartToPDF.e" + e.getMessage(), e); } finally { sqlReader.close(); } document.close(); }
From source file:org.cyberoam.iview.charts.Chart.java
public static void generatePDFReport(OutputStream out, int reportID, String applianceID, String startDate, String endDate, String limit, int[] deviceIDs, HttpServletRequest request, int reportGroupID, LinkedHashMap paramMap) throws Exception { float width = 768; float height = 1024; float rec_hieght = 470; Rectangle pagesize = new Rectangle(768, 1024); Document document = new Document(pagesize, 30, 30, 30, 30); IndexManager indexManager = null;/* w ww . java 2s. co m*/ JFreeChart chart = null; SqlReader sqlReader = new SqlReader(false); CyberoamLogger.sysLog.debug("reportID:" + reportID); CyberoamLogger.sysLog.debug("applianceID:" + applianceID); CyberoamLogger.sysLog.debug("startDate:" + startDate); CyberoamLogger.sysLog.debug("endDate:" + endDate); CyberoamLogger.sysLog.debug("limit:" + limit); try { //PdfWriter writer = PdfWriter.getInstance(document, response!=null ? response.getOutputStream():new FileOutputStream(pdfFileName)); PdfWriter writer = PdfWriter.getInstance(document, out); writer.setPageEvent(new Chart()); document.addAuthor("iView"); document.addSubject("iView Report"); document.open(); PdfContentByte contentByte = writer.getDirectContent(); //ReportGroupBean reportGroupBean=ReportGroupBean.getRecordbyPrimarykey(reportGroupID); //ArrayList reportList=reportGroupBean.getReportIdByReportGroupId(reportGroupID); ReportBean reportBean; ResultSetWrapper rsw = null; String seperator = System.getProperty("file.separator"); // String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator; String path = InitServlet.contextPath + seperator + "images" + seperator + "iViewPDF.jpg"; /* * Loading Image to add into PDF */ Image iViewImage = Image.getInstance(path); iViewImage.scaleAbsolute(750, 900); //iViewImage.scaleAbsolute(600,820); iViewImage.setAbsolutePosition(10, 10); /*Image headerImage= Image.getInstance(path+ "iViewPDFHeader.jpg"); PdfPTable headerTable = new PdfPTable(2); PdfPCell cell = new PdfPCell(headerImage); headerTable.addCell(cell); HeaderFooter docHeader=null; //document.setHeader(new HeaderFooter(new Phrase(new Chunk())), true); */ document.add(iViewImage); document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); /* * Generating Table on the First Page of Report providing summary of Content */ PdfPTable frontPageTable = new PdfPTable(2); PdfPCell dataCell; String reportName = ""; Color tableHeadBackColor = new Color(150, 174, 190); Color tableContentBackColor = new Color(229, 232, 237); Color tableBorderColor = new Color(229, 232, 237); dataCell = new PdfPCell(new Phrase(new Chunk("Report Profile", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255))))); dataCell.setBackgroundColor(tableHeadBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); if (paramMap != null) { reportName = paramMap.get("title").toString(); paramMap.remove("title"); } if (request != null) { ReportGroupBean reportGroupBean = ReportGroupBean.getRecordbyPrimarykey(reportGroupID); reportName = getFormattedTitle(request, reportGroupBean, true); } dataCell = new PdfPCell(); dataCell.addElement(new Phrase(new Chunk(reportName, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255))))); //dataCell.addElement(new Phrase(new Chunk(ReportBean.getRecordbyPrimarykey(reportID).getTitle(), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11, Font.PLAIN, new Color(10,10,10))))); if (request != null) { dataCell.addElement(new Phrase(new Chunk(reportName + " >> ", FontFactory .getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255))))); dataCell.addElement( new Phrase(new Chunk(ReportBean.getRecordbyPrimarykey(reportID).getTitle(), FontFactory .getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255))))); } dataCell.setBackgroundColor(tableHeadBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Start Date", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(startDate)); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("End Date", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(endDate)); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("iView Server Time", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); java.util.Date currentDate = new java.util.Date(); dataCell = new PdfPCell(new Phrase(currentDate.toString())); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); dataCell = new PdfPCell(new Phrase(new Chunk("Device Names (IP Address)", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0))))); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); DeviceBean deviceBean = null; String deviceNameWithIP = ""; if (deviceIDs != null) { for (int i = 0; i < deviceIDs.length; i++) { deviceBean = DeviceBean.getRecordbyPrimarykey(deviceIDs[i]); if (deviceBean != null) { deviceNameWithIP += " " + (i + 1) + ". " + deviceBean.getName() + " (" + deviceBean.getIp() + ")\n"; } } } dataCell = new PdfPCell(new Phrase("\n" + deviceNameWithIP + "\n")); dataCell.setBackgroundColor(tableContentBackColor); dataCell.setBorderColor(tableBorderColor); frontPageTable.addCell(dataCell); /* * Adding Table to PDF */ document.add(frontPageTable); /* * Adding Charts and Table to PDF */ document.newPage(); reportBean = ReportBean.getRecordbyPrimarykey(reportID); String query = null; if (request == null) { query = PrepareQuery.getQuery(reportBean, startDate, endDate, applianceID, null, null, "0", limit, paramMap); } else { PrepareQuery prepareQuery = new PrepareQuery(); query = prepareQuery.getQuery(reportBean, request); } String searchQuery = ""; if (request == null) { searchQuery = null; } else { searchQuery = request.getParameter("searchquery"); } if (searchQuery != null && !"".equalsIgnoreCase(searchQuery)) { query = query.replaceFirst("where", "where " + searchQuery + " and"); } CyberoamLogger.sysLog.debug("PDF:ReportID:" + reportBean.getReportId() + "Query->" + query); try { if (query.indexOf("select") == -1 && query.indexOf("SELECT") == -1) { indexManager = new IndexManager(); rsw = indexManager.getSearch(query); //rsw=indexManager.getResutSetFromArrayList(searchRecord); } else { rsw = sqlReader.getInstanceResultSetWrapper(query); } } catch (org.postgresql.util.PSQLException e) { if (query.indexOf("5min_ts_20") > -1) { query = query.substring(0, query.indexOf("5min_ts_20")) + "4hr" + query.substring(query.indexOf("5min_ts_20") + 16, query.length()); CyberoamLogger.appLog.debug("New query : " + query); rsw = sqlReader.getInstanceResultSetWrapper(query); } else { CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e); } } catch (Exception e) { CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e); rsw.close(); } /* * PDF Rendering work starts here */ //if(Integer.parseInt(limit)<=10 && query.indexOf("where")>-1){ if (reportBean.getReportFormatId() != 2) { chart = Chart.getChart(reportBean.getReportId(), rsw, null); PdfTemplate pdfTemplate = contentByte.createTemplate(width, height); Graphics2D graphics2D = pdfTemplate.createGraphics(width, height); Rectangle2D rectangle = new Rectangle2D.Double(100, 85, 540, rec_hieght); chart.draw(graphics2D, rectangle); graphics2D.dispose(); contentByte.addTemplate(pdfTemplate, 0, 0); for (int j = 0; j < (int) (rec_hieght / 16) + 1; j++) { document.add(new Paragraph("\n")); } } else document.add(new Paragraph("\n")); // Retrieving PdfPTable PdfPTable pdfTable = getPdfPTable(reportBean, rsw); rsw.close(); document.add(pdfTable); CyberoamLogger.appLog.info("*************Finishing PDF Work****************"); } catch (Exception e) { CyberoamLogger.sysLog.debug("Chart.writeChartToPDF.e" + e.getMessage(), e); } finally { sqlReader.close(); } document.close(); }
From source file:org.broad.igv.track.PackedFeatures.java
/** * Allocates each feature to the rows such that there is no overlap. * * @param iter TabixLineReader wrapping the collection of alignments. Note that this should * really be an Iterator<T>, but it can't be subclassed if that's the case. *//* w w w .j a v a 2 s . c o m*/ List<FeatureRow> packFeatures(Iterator iter) { List<FeatureRow> rows = new ArrayList(10); if (iter == null || !iter.hasNext()) { return rows; } maxFeatureLength = 0; int totalCount = 0; LinkedHashMap<Integer, PriorityQueue<T>> bucketArray = new LinkedHashMap(); Comparator pqComparator = new Comparator<T>() { public int compare(Feature row1, Feature row2) { return (row2.getEnd() - row2.getStart()) - (row1.getEnd() - row2.getStart()); } }; // Allocate features to buckets, 1 bucket per base position while (iter.hasNext()) { T feature = (T) iter.next(); maxFeatureLength = Math.max(maxFeatureLength, getFeatureEndForPacking(feature) - getFeatureStartForPacking(feature)); features.add(feature); int bucketNumber = getFeatureStartForPacking(feature); PriorityQueue<T> bucket = bucketArray.get(bucketNumber); if (bucket == null) { bucket = new PriorityQueue<T>(5, pqComparator); bucketArray.put(bucketNumber, bucket); } bucket.add(feature); totalCount++; } // Allocate features to rows, pulling at most 1 per bucket for each row FeatureRow currentRow = new FeatureRow(); int allocatedCount = 0; int nextStart = Integer.MIN_VALUE; int lastKey = 0; int lastAllocatedCount = -1; while (allocatedCount < totalCount && rows.size() < maxLevels) { // Check to prevent infinite loops if (lastAllocatedCount == allocatedCount) { if (IGV.hasInstance()) { String msg = "Infinite loop detected while packing features for track: " + getTrackName() + ".<br>Not all features will be shown." + "<br>Please contact igv-team@broadinstitute.org"; log.error(msg); MessageUtils.showMessage(msg); } break; } lastAllocatedCount = allocatedCount; // Next row Loop through alignments until we reach the end of the interval PriorityQueue<T> bucket = null; // Advance to nextLine occupied bucket ArrayList<Integer> emptyBucketKeys = new ArrayList(); for (Integer key : bucketArray.keySet()) { //if (key < lastKey) { // String msg = "Features from track: " + trackName + " are not sorted. Some features might not be shown.<br>" + // "Please notify igv-help@broadinstitute.org"; // MessageUtils.showMessage(msg); //} lastKey = key; if (key >= nextStart) { bucket = bucketArray.get(key); T feature = bucket.poll(); if (bucket.isEmpty()) { emptyBucketKeys.add(key); } currentRow.addFeature(feature); nextStart = currentRow.end + FeatureTrack.MINIMUM_FEATURE_SPACING; allocatedCount++; } } for (Integer key : emptyBucketKeys) { bucketArray.remove(key); } // We've reached the end of the interval, start a new row if (currentRow.features.size() > 0) { rows.add(currentRow); lastAllocatedCount = 0; } currentRow = new FeatureRow(); nextStart = 0; lastKey = 0; } // Add the last row if (currentRow.features.size() > 0) { rows.add(currentRow); } return rows; }
From source file:nzilbb.csv.CsvDeserializer.java
/** * Sets parameters for deserializer as a whole. This might include database connection parameters, locations of supporting files, etc. * <p>When the deserializer is installed, this method should be invoked with an empty parameter * set, to discover what (if any) general configuration is required. If parameters are * returned, and user interaction is possible, then the user may be presented with an * interface for setting/confirming these parameters. * @param configuration The configuration for the deserializer. * @param schema The layer schema, definining layers and the way they interrelate. * @return A list of configuration parameters (still) must be set before {@link IDeserializer#setParameters(ParameterSet)} can be invoked. If this is an empty list, {@link IDeserializer#setParameters(ParameterSet)} can be invoked. If it's not an empty list, this method must be invoked again with the returned parameters' values set. */// w ww .j a va 2 s . com public ParameterSet configure(ParameterSet configuration, Schema schema) { setSchema(schema); setParticipantLayer(schema.getParticipantLayer()); setTurnLayer(schema.getTurnLayer()); setUtteranceLayer(schema.getUtteranceLayer()); setWordLayer(schema.getWordLayer()); // set any values that have been passed in for (Parameter p : configuration.values()) try { p.apply(this); } catch (Exception x) { } // create a list of layers we need and possible matching layer names LinkedHashMap<Parameter, List<String>> layerToPossibilities = new LinkedHashMap<Parameter, List<String>>(); HashMap<String, LinkedHashMap<String, Layer>> layerToCandidates = new HashMap<String, LinkedHashMap<String, Layer>>(); // do we need to ask for participant/turn/utterance/word layers? LinkedHashMap<String, Layer> possibleParticipantLayers = new LinkedHashMap<String, Layer>(); LinkedHashMap<String, Layer> possibleTurnLayers = new LinkedHashMap<String, Layer>(); LinkedHashMap<String, Layer> possibleTurnChildLayers = new LinkedHashMap<String, Layer>(); LinkedHashMap<String, Layer> wordTagLayers = new LinkedHashMap<String, Layer>(); LinkedHashMap<String, Layer> participantTagLayers = new LinkedHashMap<String, Layer>(); if (getParticipantLayer() == null || getTurnLayer() == null || getUtteranceLayer() == null || getWordLayer() == null) { for (Layer top : schema.getRoot().getChildren().values()) { if (top.getAlignment() == Constants.ALIGNMENT_NONE) { if (top.getChildren().size() == 0) { // unaligned childless children of graph participantTagLayers.put(top.getId(), top); } else { // unaligned children of graph, with children of their own possibleParticipantLayers.put(top.getId(), top); for (Layer turn : top.getChildren().values()) { if (turn.getAlignment() == Constants.ALIGNMENT_INTERVAL && turn.getChildren().size() > 0) { // aligned children of who with their own children possibleTurnLayers.put(turn.getId(), turn); for (Layer turnChild : turn.getChildren().values()) { if (turnChild.getAlignment() == Constants.ALIGNMENT_INTERVAL) { // aligned children of turn possibleTurnChildLayers.put(turnChild.getId(), turnChild); for (Layer tag : turnChild.getChildren().values()) { if (tag.getAlignment() == Constants.ALIGNMENT_NONE) { // unaligned children of word wordTagLayers.put(tag.getId(), tag); } } // next possible word tag layer } } // next possible turn child layer } } // next possible turn layer } // with children } // unaligned } // next possible participant layer } // missing special layers else { for (Layer turnChild : getTurnLayer().getChildren().values()) { if (turnChild.getAlignment() == Constants.ALIGNMENT_INTERVAL) { possibleTurnChildLayers.put(turnChild.getId(), turnChild); } } // next possible word tag layer for (Layer tag : getWordLayer().getChildren().values()) { if (tag.getAlignment() == Constants.ALIGNMENT_NONE && tag.getChildren().size() == 0) { wordTagLayers.put(tag.getId(), tag); } } // next possible word tag layer for (Layer tag : getParticipantLayer().getChildren().values()) { if (tag.getAlignment() == Constants.ALIGNMENT_NONE && tag.getChildren().size() == 0) { participantTagLayers.put(tag.getId(), tag); } } // next possible word tag layer } participantTagLayers.remove("main_participant"); if (getParticipantLayer() == null) { layerToPossibilities.put( new Parameter("participantLayer", Layer.class, "Participant layer", "Layer for speaker/participant identification", true), Arrays.asList("participant", "participants", "who", "speaker", "speakers")); layerToCandidates.put("participantLayer", possibleParticipantLayers); } if (getTurnLayer() == null) { layerToPossibilities.put( new Parameter("turnLayer", Layer.class, "Turn layer", "Layer for speaker turns", true), Arrays.asList("turn", "turns")); layerToCandidates.put("turnLayer", possibleTurnLayers); } if (getUtteranceLayer() == null) { layerToPossibilities.put(new Parameter("utteranceLayer", Layer.class, "Utterance layer", "Layer for speaker utterances", true), Arrays.asList("utterance", "utterances", "line", "lines")); layerToCandidates.put("utteranceLayer", possibleTurnChildLayers); } if (getWordLayer() == null) { layerToPossibilities.put( new Parameter("wordLayer", Layer.class, "Word layer", "Layer for individual word tokens", true), Arrays.asList("transcript", "word", "words", "w")); layerToCandidates.put("wordLayer", possibleTurnChildLayers); } LinkedHashMap<String, Layer> graphTagLayers = new LinkedHashMap<String, Layer>(); for (Layer top : schema.getRoot().getChildren().values()) { if (top.getAlignment() == Constants.ALIGNMENT_NONE && top.getChildren().size() == 0) { // unaligned childless children of graph graphTagLayers.put(top.getId(), top); } } // next top level layer graphTagLayers.remove("corpus"); graphTagLayers.remove("transcript_type"); // other layers... // add parameters that aren't in the configuration yet, and set possibile/default values for (Parameter p : layerToPossibilities.keySet()) { List<String> possibleNames = layerToPossibilities.get(p); LinkedHashMap<String, Layer> candidateLayers = layerToCandidates.get(p.getName()); if (configuration.containsKey(p.getName())) { p = configuration.get(p.getName()); } else { configuration.addParameter(p); } if (p.getValue() == null) { p.setValue(Utility.FindLayerById(candidateLayers, possibleNames)); } p.setPossibleValues(candidateLayers.values()); } return configuration; }
From source file:ma.glasnost.orika.metadata.ScoringClassMapBuilder.java
/** * Gets all of the property expressions for a given type, including all nested properties. * If the type of a property is not immutable and has any nested properties, it will not * be included. (Note that the 'class' property is explicitly excluded.) * //w ww. ja v a 2 s . c o m * @param type the type for which to gather properties * @return the map of nested properties keyed by expression name */ protected Map<String, Property> getPropertyExpressions(Type<?> type) { PropertyResolverStrategy propertyResolver = getPropertyResolver(); Map<String, Property> properties = new HashMap<String, Property>(); LinkedHashMap<String, Property> toProcess = new LinkedHashMap<String, Property>( propertyResolver.getProperties(type)); if (type.isMap() || type.isList() || type.isArray()) { Property selfReferenceProperty = new Property.Builder().name("").getter("").setter(" = %s") .type(TypeFactory.valueOf(type)).build((PropertyResolver) propertyResolver); toProcess.put("", selfReferenceProperty); } while (!toProcess.isEmpty()) { Entry<String, Property> entry = toProcess.entrySet().iterator().next(); if (!entry.getKey().equals("class")) { Property owningProperty = entry.getValue(); Type<?> propertyType = owningProperty.getType(); if (!ClassUtil.isImmutable(propertyType)) { Map<String, Property> props = propertyResolver.getProperties(propertyType); if (propertyType.isMap()) { Map<String, Property> valueProperties = getPropertyExpressions( propertyType.getNestedType(1)); for (Entry<String, Property> prop : valueProperties.entrySet()) { Property elementProp = new NestedElementProperty(entry.getValue(), prop.getValue(), propertyResolver); String key = entry.getKey() + PropertyResolver.ELEMENT_PROPERT_PREFIX + prop.getKey() + PropertyResolver.ELEMENT_PROPERT_SUFFIX; toProcess.put(key, elementProp); } } else if (propertyType.isList()) { Map<String, Property> valueProperties = getPropertyExpressions( propertyType.getNestedType(0)); for (Entry<String, Property> prop : valueProperties.entrySet()) { Property elementProp = new NestedElementProperty(owningProperty, prop.getValue(), propertyResolver); String key = entry.getKey() + PropertyResolver.ELEMENT_PROPERT_PREFIX + prop.getValue().getExpression() + PropertyResolver.ELEMENT_PROPERT_SUFFIX; toProcess.put(key, elementProp); } } else if (propertyType.isArray()) { Map<String, Property> valueProperties = getPropertyExpressions( propertyType.getComponentType()); for (Entry<String, Property> prop : valueProperties.entrySet()) { Property elementProp = new NestedElementProperty(entry.getValue(), prop.getValue(), propertyResolver); String key = entry.getKey() + PropertyResolver.ELEMENT_PROPERT_PREFIX + prop.getKey() + PropertyResolver.ELEMENT_PROPERT_SUFFIX; toProcess.put(key, elementProp); } } else if (!props.isEmpty()) { for (Entry<String, Property> property : props.entrySet()) { if (!property.getKey().equals("class")) { String expression = entry.getKey() + "." + property.getKey(); toProcess.put(expression, resolveProperty(type, expression)); } } } else { properties.put(entry.getKey(), resolveProperty(type, entry.getKey())); } } else { properties.put(entry.getKey(), resolveProperty(type, entry.getKey())); } } toProcess.remove(entry.getKey()); } return properties; }
From source file:com.amalto.workbench.dialogs.MenuEntryDialog.java
@Override protected Control createDialogArea(Composite parent) { // Should not really be here but well,.... parent.getShell().setText(this.title); Composite composite = (Composite) super.createDialogArea(parent); GridLayout layout = (GridLayout) composite.getLayout(); layout.numColumns = 3;// w w w . j a va 2 s . co m // layout.verticalSpacing = 10; Label idLabel = new Label(composite, SWT.NONE); idLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); idLabel.setText(Messages.MenuEntryDialog_Id); if (this.isChanged) { idText = new Text(composite, SWT.NONE); } else { idText = new Text(composite, SWT.NONE | SWT.READ_ONLY); } idText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); ((GridData) idText.getLayoutData()).widthHint = 300; idText.setDoubleClickEnabled(false); Label contextLabel = new Label(composite, SWT.NONE); contextLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); contextLabel.setText(Messages.MenuEntryDialog_Context); contextText = new Text(composite, SWT.NONE); contextText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); contextText.setDoubleClickEnabled(false); Label applicationNameLabel = new Label(composite, SWT.NONE); applicationNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); applicationNameLabel.setText(Messages.MenuEntryDialog_Application); applicationNameText = new Text(composite, SWT.NONE); applicationNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); Label iconPathLabel = new Label(composite, SWT.NONE); iconPathLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); iconPathLabel.setText(Messages.MenuEntryDialog_IconPath); iconPathText = new FileSelectWidget(composite, "", new String[] { "*.png", "*.gif", "*.jpg" }, "", true);//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$ // Labels descriptionsComposite = new Composite(composite, SWT.BORDER); descriptionsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); descriptionsComposite.setLayout(new GridLayout(3, false)); Label descriptionsLabel = new Label(descriptionsComposite, SWT.NULL); descriptionsLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); descriptionsLabel.setText(Messages.MenuEntryDialog_MenuEntryLabels); languagesCombo = new Combo(descriptionsComposite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE); languagesCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1)); Set<String> languages = Util.lang2iso.keySet(); for (Object element : languages) { String language = (String) element; languagesCombo.add(language); } languagesCombo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { } }); languagesCombo.select(0); labelText = new Text(descriptionsComposite, SWT.BORDER | SWT.SINGLE); labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); labelText.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { if ((e.stateMask == 0) && (e.character == SWT.CR)) { String isoCode = Util.lang2iso.get(languagesCombo.getText()); descriptionsMap.put(isoCode, labelText.getText()); descriptionsViewer.refresh(); } } }); Button addLabelButton = new Button(descriptionsComposite, SWT.PUSH); addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath())); addLabelButton.setToolTipText(Messages.MenuEntryDialog_Add); addLabelButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String isoCode = Util.lang2iso.get(languagesCombo.getText()); descriptionsMap.put(isoCode, labelText.getText()); descriptionsViewer.refresh(); }; }); final String LANGUAGE = Messages.MenuEntryDialog_Language; final String LABEL = Messages.MenuEntryDialog_Label; descriptionsViewer = new TableViewer(descriptionsComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); ((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100; // Set up the underlying table Table table = descriptionsViewer.getTable(); // table.setLayoutData(new GridData(GridData.FILL_BOTH)); new TableColumn(table, SWT.LEFT).setText(LANGUAGE); new TableColumn(table, SWT.CENTER).setText(LABEL); table.getColumn(0).setWidth(150); table.getColumn(1).setWidth(150); for (int i = 2, n = table.getColumnCount(); i < n; i++) { table.getColumn(i).pack(); } table.setHeaderVisible(true); table.setLinesVisible(true); // Create the cell editors --> We actually discard those later: not natural for an user CellEditor[] editors = new CellEditor[2]; editors[0] = new TextCellEditor(table); editors[1] = new TextCellEditor(table); descriptionsViewer.setCellEditors(editors); // set the content provider descriptionsViewer.setContentProvider(new IStructuredContentProvider() { public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } public Object[] getElements(Object inputElement) { // System.out.println("getElements() "); LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) inputElement; Set<String> languages = descs.keySet(); ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>(); for (Object element : languages) { String language = (String) element; DescriptionLine line = new DescriptionLine(Util.iso2lang.get(language), descs.get(language)); lines.add(line); } // we return an instance line made of a Sring and a boolean return lines.toArray(new DescriptionLine[lines.size()]); } }); // set the label provider descriptionsViewer.setLabelProvider(new ITableLabelProvider() { public boolean isLabelProperty(Object element, String property) { return false; } public void dispose() { } public void addListener(ILabelProviderListener listener) { } public void removeListener(ILabelProviderListener listener) { } public String getColumnText(Object element, int columnIndex) { // System.out.println("getColumnText() "+columnIndex); DescriptionLine line = (DescriptionLine) element; switch (columnIndex) { case 0: return line.getLanguage(); case 1: return line.getLabel(); } return "";//$NON-NLS-1$ } public Image getColumnImage(Object element, int columnIndex) { return null; } }); // Set the column properties descriptionsViewer.setColumnProperties(new String[] { LANGUAGE, LABEL }); // set the Cell Modifier descriptionsViewer.setCellModifier(new ICellModifier() { public boolean canModify(Object element, String property) { // if (INSTANCE_ACCESS.equals(property)) return true; Deactivated return false; } public void modify(Object element, String property, Object value) { // System.out.println("modify() "+element.getClass().getName()+": "+property+": "+value); // DescriptionLine line = // (DescriptionLine)((IStructuredSelection)instancesViewer.getSelection()).getFirstElement(); // deactivated: editing in places is not natural for users } public Object getValue(Object element, String property) { // System.out.println("getValue() "+property); DescriptionLine line = (DescriptionLine) element; if (LANGUAGE.equals(property)) { return line.getLanguage(); } if (LABEL.equals(property)) { return line.getLabel(); } return null; } }); // Listen for changes in the selection of the viewer to display additional parameters descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { } }); // display for Delete Key events to delete an instance descriptionsViewer.getTable().addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { // System.out.println("Table keyReleased() "); if ((e.stateMask == 0) && (e.character == SWT.DEL) && (descriptionsViewer.getSelection() != null)) { DescriptionLine line = (DescriptionLine) ((IStructuredSelection) descriptionsViewer .getSelection()).getFirstElement(); String isoCode = Util.lang2iso.get(line.getLanguage()); LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) descriptionsViewer .getInput(); descs.remove(isoCode); descriptionsViewer.refresh(); } } }); descriptionsViewer.refresh(); if (wsMenuEntry != null) { idText.setText(wsMenuEntry.getId() == null ? "" : wsMenuEntry.getId());//$NON-NLS-1$ contextText.setText(wsMenuEntry.getContext() == null ? "" : wsMenuEntry.getContext());//$NON-NLS-1$ applicationNameText.setText(wsMenuEntry.getApplication() == null ? "" : wsMenuEntry.getApplication());//$NON-NLS-1$ iconPathText.setFilename(wsMenuEntry.getIcon() == null ? "" : wsMenuEntry.getIcon());//$NON-NLS-1$ descriptionsViewer.setInput(descriptionsMap); } idText.setFocus(); return composite; }