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