001/***************************************************************************** 002 * Copyright by The HDF Group. * 003 * Copyright by the Board of Trustees of the University of Illinois. * 004 * All rights reserved. * 005 * * 006 * This file is part of the HDF Java Products distribution. * 007 * The full copyright notice, including terms governing use, modification, * 008 * and redistribution, is contained in the COPYING file, which can be found * 009 * at the root of the source code distribution tree, * 010 * or in https://www.hdfgroup.org/licenses. * 011 * If you do not have access to either file, you may request a copy from * 012 * help@hdfgroup.org. * 013 ****************************************************************************/ 014 015package hdf.view.MetaDataView; 016 017import java.util.List; 018 019import hdf.object.Dataset; 020import hdf.object.Datatype; 021import hdf.object.Group; 022import hdf.object.HObject; 023import hdf.object.h5.H5Link; 024import hdf.object.nc2.NC2Group; 025import hdf.view.DataView.DataViewManager; 026import hdf.view.ViewProperties; 027 028import hdf.hdf5lib.H5; 029import hdf.hdf5lib.HDF5Constants; 030 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033 034import org.eclipse.swt.SWT; 035import org.eclipse.swt.custom.ScrolledComposite; 036import org.eclipse.swt.layout.GridData; 037import org.eclipse.swt.layout.GridLayout; 038import org.eclipse.swt.widgets.Composite; 039import org.eclipse.swt.widgets.Label; 040import org.eclipse.swt.widgets.Table; 041import org.eclipse.swt.widgets.TableColumn; 042import org.eclipse.swt.widgets.TableItem; 043import org.eclipse.swt.widgets.Text; 044 045/** 046 * 047 * The metadata view interface for displaying group metadata information 048 */ 049public class DefaultGroupMetaDataView extends DefaultLinkMetaDataView implements MetaDataView { 050 051 private static final Logger log = LoggerFactory.getLogger(DefaultGroupMetaDataView.class); 052 053 /** 054 *The metadata view interface for displaying metadata information 055 * 056 * @param parentComposite 057 * the parent visual object 058 * @param viewer 059 * the viewer to use 060 * @param theObj 061 * the object to display the metadata info 062 */ 063 public DefaultGroupMetaDataView(Composite parentComposite, DataViewManager viewer, HObject theObj) 064 { 065 super(parentComposite, viewer, theObj); 066 } 067 068 @Override 069 protected void addObjectSpecificContent() 070 { 071 super.addObjectSpecificContent(); 072 073 Group g = (Group)dataObject; 074 List<?> mlist = g.getMemberList(); 075 int n = mlist.size(); 076 077 log.trace("addObjectSpecificContent(): group object extra info mlist size = {}", n); 078 079 Label label; 080 081 if (isH5) { 082 StringBuilder objCreationStr = new StringBuilder("Creation Order NOT Tracked"); 083 084 long ocplID = -1; 085 try { 086 if (g.isRoot()) { 087 ocplID = H5.H5Fget_create_plist(g.getFID()); 088 } 089 else { 090 long objid = -1; 091 try { 092 objid = g.open(); 093 if (objid >= 0) { 094 ocplID = H5.H5Gget_create_plist(objid); 095 } 096 } 097 finally { 098 g.close(objid); 099 } 100 } 101 if (ocplID >= 0) { 102 int creationOrder = H5.H5Pget_link_creation_order(ocplID); 103 log.trace("createGeneralObjectInfoPane(): creationOrder={}", creationOrder); 104 if ((creationOrder & HDF5Constants.H5P_CRT_ORDER_TRACKED) > 0) { 105 objCreationStr.setLength(0); 106 objCreationStr.append("Creation Order Tracked"); 107 if ((creationOrder & HDF5Constants.H5P_CRT_ORDER_INDEXED) > 0) 108 objCreationStr.append(" and Indexed"); 109 } 110 } 111 } 112 finally { 113 H5.H5Pclose(ocplID); 114 } 115 116 /* Creation order section */ 117 label = new Label(generalObjectInfoPane, SWT.LEFT); 118 label.setFont(curFont); 119 label.setText("Link Creation Order: "); 120 121 Text text = new Text(generalObjectInfoPane, SWT.SINGLE | SWT.BORDER); 122 text.setEditable(false); 123 text.setFont(curFont); 124 text.setText(objCreationStr.toString()); 125 text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 126 } 127 if (isN3) { 128 StringBuilder objDimensionStr = new StringBuilder("No Dimensions"); 129 int[] listDimSelector = {0, 0, 1}; 130 try { 131 List ncDimensions = ((NC2Group)g).getMetadata(listDimSelector); 132 if (ncDimensions != null) { 133 int listCnt = ncDimensions.size(); 134 log.trace("createGeneralObjectInfoPane(): ncDimensions={}", listCnt); 135 if (listCnt > 0) 136 objDimensionStr.setLength(0); 137 for (int i = 0; i < listCnt; i++) { 138 objDimensionStr.append(((NC2Group)g).netcdfDimensionString(i)); 139 if (i < listCnt - 1) 140 objDimensionStr.append("\n"); 141 } 142 } 143 } 144 catch (Exception e) { 145 log.debug("Error retrieving dimensions of object '" + dataObject.getName() + "':", e); 146 } 147 148 /* Dimensions section */ 149 label = new Label(generalObjectInfoPane, SWT.LEFT); 150 label.setFont(curFont); 151 label.setText("Dimensions: "); 152 153 ScrolledComposite dimensionScroller = 154 new ScrolledComposite(generalObjectInfoPane, SWT.V_SCROLL | SWT.BORDER); 155 dimensionScroller.setExpandHorizontal(true); 156 dimensionScroller.setExpandVertical(true); 157 dimensionScroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1)); 158 159 Text text = new Text(dimensionScroller, SWT.MULTI | SWT.BORDER); 160 text.setEditable(false); 161 text.setFont(curFont); 162 text.setText(objDimensionStr.toString()); 163 text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 164 dimensionScroller.setContent(text); 165 166 StringBuilder objEnumTypedefStr = new StringBuilder("No Enums"); 167 int[] listEnumSelector = {0, 0, 0, 1}; 168 try { 169 List ncEnums = ((NC2Group)g).getMetadata(listEnumSelector); 170 if (ncEnums != null) { 171 int listCnt = ncEnums.size(); 172 log.trace("createGeneralObjectInfoPane(): ncEnums={}", listCnt); 173 if (listCnt > 0) 174 objEnumTypedefStr.setLength(0); 175 for (int i = 0; i < listCnt; i++) { 176 objEnumTypedefStr.append(((NC2Group)g).netcdfTypedefString(i)); 177 if (i < listCnt - 1) 178 objEnumTypedefStr.append("\n"); 179 } 180 } 181 } 182 catch (Exception e) { 183 log.debug("Error retrieving enums of object '" + dataObject.getName() + "':", e); 184 } 185 186 /* Dimensions section */ 187 label = new Label(generalObjectInfoPane, SWT.LEFT); 188 label.setFont(curFont); 189 label.setText("Enums: "); 190 191 ScrolledComposite enumScroller = 192 new ScrolledComposite(generalObjectInfoPane, SWT.V_SCROLL | SWT.BORDER); 193 enumScroller.setExpandHorizontal(true); 194 enumScroller.setExpandVertical(true); 195 enumScroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1)); 196 197 text = new Text(enumScroller, SWT.MULTI | SWT.BORDER); 198 text.setEditable(false); 199 text.setFont(curFont); 200 text.setText(objEnumTypedefStr.toString()); 201 text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 202 enumScroller.setContent(text); 203 } 204 org.eclipse.swt.widgets.Group groupInfoGroup = 205 new org.eclipse.swt.widgets.Group(generalObjectInfoPane, SWT.NONE); 206 groupInfoGroup.setFont(curFont); 207 groupInfoGroup.setText("Group Members"); 208 groupInfoGroup.setLayout(new GridLayout(1, true)); 209 groupInfoGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 210 211 if (g.getNumberOfMembersInFile() < ViewProperties.getMaxMembers()) { 212 label = new Label(groupInfoGroup, SWT.RIGHT); 213 label.setFont(curFont); 214 label.setText("Number of members: " + n); 215 } 216 else { 217 label = new Label(groupInfoGroup, SWT.RIGHT); 218 label.setFont(curFont); 219 label.setText("Number of members: " + n + " (in memory)," 220 + "" + g.getNumberOfMembersInFile() + " (in file)"); 221 } 222 223 String[] columnNames = {"Name", "Type"}; 224 225 Table memberTable = new Table(groupInfoGroup, SWT.BORDER); 226 memberTable.setLinesVisible(true); 227 memberTable.setHeaderVisible(true); 228 memberTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 229 memberTable.setFont(curFont); 230 231 for (int i = 0; i < columnNames.length; i++) { 232 TableColumn column = new TableColumn(memberTable, SWT.NONE); 233 column.setText(columnNames[i]); 234 column.setMoveable(false); 235 } 236 237 if (mlist != null && n > 0) { 238 String rowData[][] = new String[n][2]; 239 for (int i = 0; i < n; i++) { 240 HObject theObj = (HObject)mlist.get(i); 241 rowData[i][0] = theObj.getName(); 242 if (theObj instanceof Group) { 243 rowData[i][1] = "Group"; 244 } 245 else if (theObj instanceof Dataset) { 246 rowData[i][1] = "Dataset"; 247 } 248 else if (theObj instanceof Datatype) { 249 rowData[i][1] = "Datatype"; 250 } 251 else if (theObj instanceof H5Link) { 252 rowData[i][1] = "Link"; 253 } 254 else 255 rowData[i][1] = "Unknown"; 256 } 257 258 for (int i = 0; i < rowData.length; i++) { 259 TableItem item = new TableItem(memberTable, SWT.NONE); 260 item.setFont(curFont); 261 item.setText(0, rowData[i][0]); 262 item.setText(1, rowData[i][1]); 263 } 264 265 // set cell height for large fonts 266 // int cellRowHeight = Math.max(16, 267 // table.getFontMetrics(table.getFont()).getHeight()); 268 // table.setRowHeight(cellRowHeight); 269 } 270 271 for (int i = 0; i < columnNames.length; i++) { 272 memberTable.getColumn(i).pack(); 273 } 274 } 275}