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.dialog; 016 017import java.util.ArrayList; 018import java.util.Vector; 019 020import org.eclipse.swt.SWT; 021import org.eclipse.swt.layout.FillLayout; 022import org.eclipse.swt.layout.GridData; 023import org.eclipse.swt.layout.GridLayout; 024import org.eclipse.swt.widgets.Combo; 025import org.eclipse.swt.widgets.Composite; 026import org.eclipse.swt.widgets.Control; 027 028import hdf.view.ViewProperties; 029 030 031/** 032 * UserOptionsViewModulesPage.java - Configuration page for user-implementable 033 * modules. 034 */ 035public class UserOptionsViewModulesPage extends UserOptionsDefaultPage { 036 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(UserOptionsViewModulesPage.class); 037 038 private Combo choiceTreeView, choiceMetaDataView, choiceTableView, choiceImageView, choicePaletteView; 039 040 /** A list of Tree view implementations. */ 041 private static ArrayList<String> treeViews; 042 043 /** A list of Image view implementations. */ 044 private static ArrayList<String> imageViews; 045 046 /** A list of Table view implementations. */ 047 private static ArrayList<String> tableViews; 048 049 /** A list of metadata view implementations. */ 050 private static ArrayList<String> metaDataViews; 051 052 /** A list of palette view implementations. */ 053 private static ArrayList<String> paletteViews; 054 055 /** 056 * Configuration page for user-implementable modules. 057 */ 058 public UserOptionsViewModulesPage() { 059 super("View Modules Settings"); 060 } 061 062 /** 063 * Performs special processing when this page's Defaults button has been pressed. 064 */ 065 @Override 066 public void performDefaults() { 067 super.performDefaults(); 068 } 069 070 /** 071 * Notifies that the OK button of this page's container has been pressed. 072 * 073 * @return <code>false</code> to abort the container's OK processing and <code>true</code> to allow 074 * the OK to happen 075 */ 076 @SuppressWarnings({ "unchecked", "rawtypes" }) 077 @Override 078 public boolean performOk() { 079 getPreferenceStore(); 080 081 ArrayList[] moduleList = { treeViews, metaDataViews, tableViews, imageViews, paletteViews }; 082 Combo[] choiceList = { choiceTreeView, choiceMetaDataView, choiceTableView, choiceImageView, choicePaletteView }; 083 for (int i = 0; i < moduleList.length; i++) { 084 Combo curModuleCombo = choiceList[i]; 085 if (curModuleCombo != null) { 086 Object theModule = curModuleCombo.getItem(curModuleCombo.getSelectionIndex()); 087 moduleList[i].remove(theModule); 088 moduleList[i].add(0, theModule); 089 } 090 } 091 092 return true; 093 } 094 095 /** 096 * Loads all stored values in the <code>FieldEditor</code>s. 097 */ 098 @SuppressWarnings({ "unchecked", "rawtypes" }) 099 protected void load() { 100 getPreferenceStore(); 101 102 treeViews = (ArrayList<String>) ViewProperties.getTreeViewList(); 103 metaDataViews = (ArrayList<String>) ViewProperties.getMetaDataViewList(); 104 tableViews = (ArrayList<String>) ViewProperties.getTableViewList(); 105 imageViews = (ArrayList<String>) ViewProperties.getImageViewList(); 106 paletteViews = (ArrayList<String>) ViewProperties.getPaletteViewList(); 107 // srbVector = (ArrayList<String>)ViewProperties.getSrbAccount(); 108 109 choiceTreeView.setItems(treeViews.toArray(new String[0])); 110 choiceTreeView.select(0); 111 choiceMetaDataView.setItems(metaDataViews.toArray(new String[0])); 112 choiceMetaDataView.select(0); 113 choiceTableView.setItems(tableViews.toArray(new String[0])); 114 choiceTableView.select(0); 115 choiceImageView.setItems(imageViews.toArray(new String[0])); 116 choiceImageView.select(0); 117 choicePaletteView.setItems(paletteViews.toArray(new String[0])); 118 choicePaletteView.select(0); 119 120 ArrayList[] moduleList = { treeViews, metaDataViews, tableViews, imageViews, paletteViews }; 121 Combo[] choiceList = { choiceTreeView, choiceMetaDataView, choiceTableView, choiceImageView, choicePaletteView }; 122 for (int i = 0; i < moduleList.length; i++) { 123 Object theModule = choiceList[i].getItem(choiceList[i].getSelectionIndex()); 124 moduleList[i].remove(theModule); 125 moduleList[i].add(0, theModule); 126 } 127 } 128 129 /** 130 * Creates and returns the SWT control for the customized body of this 131 * preference page under the given parent composite. 132 * 133 * @param parent the parent composite 134 * @return the new control 135 */ 136 @Override 137 protected Control createContents(Composite parent) { 138 shell = parent.getShell(); 139 Composite composite = new Composite(parent, SWT.NONE); 140 composite.setLayout(new GridLayout()); 141 142 org.eclipse.swt.widgets.Group treeViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); 143 treeViewGroup.setLayout(new FillLayout()); 144 treeViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 145 treeViewGroup.setFont(curFont); 146 treeViewGroup.setText("TreeView Provider"); 147 148 choiceTreeView = new Combo(treeViewGroup, SWT.SINGLE | SWT.READ_ONLY); 149 choiceTreeView.setFont(curFont); 150 151 org.eclipse.swt.widgets.Group metadataViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); 152 metadataViewGroup.setLayout(new FillLayout()); 153 metadataViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 154 metadataViewGroup.setFont(curFont); 155 metadataViewGroup.setText("MetaDataView Provider"); 156 157 choiceMetaDataView = new Combo(metadataViewGroup, SWT.SINGLE | SWT.READ_ONLY); 158 choiceMetaDataView.setFont(curFont); 159 160 org.eclipse.swt.widgets.Group tableViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); 161 tableViewGroup.setLayout(new FillLayout()); 162 tableViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 163 tableViewGroup.setFont(curFont); 164 tableViewGroup.setText("TableView Provider"); 165 166 choiceTableView = new Combo(tableViewGroup, SWT.SINGLE | SWT.READ_ONLY); 167 choiceTableView.setFont(curFont); 168 169 org.eclipse.swt.widgets.Group imageViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); 170 imageViewGroup.setLayout(new FillLayout()); 171 imageViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 172 imageViewGroup.setFont(curFont); 173 imageViewGroup.setText("ImageView Provider"); 174 175 choiceImageView = new Combo(imageViewGroup, SWT.SINGLE | SWT.READ_ONLY); 176 choiceImageView.setFont(curFont); 177 178 org.eclipse.swt.widgets.Group paletteViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE); 179 paletteViewGroup.setLayout(new FillLayout()); 180 paletteViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 181 paletteViewGroup.setFont(curFont); 182 paletteViewGroup.setText("PaletteView Provider"); 183 184 choicePaletteView = new Combo(paletteViewGroup, SWT.SINGLE | SWT.READ_ONLY); 185 choicePaletteView.setFont(curFont); 186 187 load(); 188 return composite; 189 190 } 191}