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