1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.wizards.form; 24 25 import com.sun.star.awt.XCheckBox; 26 import com.sun.star.awt.XFixedText; 27 import com.sun.star.awt.XListBox; 28 import com.sun.star.awt.XRadioButton; 29 import com.sun.star.wizards.common.Helper; 30 import com.sun.star.wizards.common.PropertyNames; 31 import com.sun.star.wizards.ui.CommandFieldSelection; 32 import com.sun.star.wizards.ui.UIConsts; 33 import com.sun.star.wizards.ui.UnoDialog; 34 import com.sun.star.wizards.ui.WizardDialog; 35 import com.sun.star.wizards.db.RelationController; 36 37 /** 38 * @author Administrator 39 * 40 * To change the template for this generated type comment go to 41 * Window>Preferences>Java>Code Generation>Code and Comments 42 */ 43 public class FormConfiguration 44 { 45 46 WizardDialog CurUnoDialog; 47 short curtabindex; 48 XRadioButton optOnExistingRelation; 49 XCheckBox chkcreateSubForm; 50 XRadioButton optSelectManually; 51 XFixedText lblSubFormDescription; 52 XFixedText lblRelations; 53 XListBox lstRelations; 54 String[] sreferencedTables; 55 // Integer ISubFormStep; 56 CommandFieldSelection CurSubFormFieldSelection; 57 String SSUBFORMMODE = "toggleSubFormMode"; 58 String STOGGLESTEPS = "toggleSteps"; 59 String SONEXISTINGRELATIONSELECTION = "onexistingRelationSelection"; 60 boolean bsupportsRelations; 61 RelationController oRelationController = null; 62 FormConfiguration(WizardDialog _CurUnoDialog)63 public FormConfiguration(WizardDialog _CurUnoDialog) 64 { 65 this.CurUnoDialog = _CurUnoDialog; 66 curtabindex = (short) (FormWizard.SOSUBFORM_PAGE * 100); 67 Integer ISubFormStep = new Integer(FormWizard.SOSUBFORM_PAGE); 68 String sOnExistingRelation = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 5); 69 String sOnManualRelation = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 7); 70 String sSelectManually = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 4); 71 String sSelectRelation = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 8); 72 String sSubFormDescription = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 3); 73 74 // CheckBox 'Add sub form' 75 chkcreateSubForm = CurUnoDialog.insertCheckBox("chkcreateSubForm", SSUBFORMMODE, this, 76 new String[] 77 { 78 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 79 }, 80 new Object[] 81 { 82 UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_CHKCREATESUBFORM", sSelectManually, 97, 26, ISubFormStep, new Short(curtabindex++), 160 83 }); 84 optOnExistingRelation = CurUnoDialog.insertRadioButton("optOnExistingRelation", STOGGLESTEPS, this, 85 new String[] 86 { 87 PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 88 }, 89 new Object[] 90 { 91 Boolean.FALSE, UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_OPTONEXISTINGRELATION", sOnExistingRelation, 107, 43, ISubFormStep, new Short(curtabindex++), 160 92 }); 93 optSelectManually = CurUnoDialog.insertRadioButton("optSelectManually", STOGGLESTEPS, this, 94 new String[] 95 { 96 PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 97 }, 98 new Object[] 99 { 100 Boolean.FALSE, UIConsts.INTEGERS[8], "HID:WIZARDS_HID_DLGFORM_OPTSELECTMANUALLY", sOnManualRelation, 107, 99, new Short((short) 1), ISubFormStep, new Short(curtabindex++), 160 101 }); 102 lblRelations = CurUnoDialog.insertLabel("lblSelectRelation", 103 new String[] 104 { 105 PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 106 }, 107 new Object[] 108 { 109 Boolean.FALSE, 19, sSelectRelation, Boolean.TRUE, 119, 56, ISubFormStep, new Short(curtabindex++), 80 110 }); 111 lstRelations = CurUnoDialog.insertListBox("lstrelations", SONEXISTINGRELATIONSELECTION, SONEXISTINGRELATIONSELECTION, this, 112 new String[] 113 { 114 PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 115 }, 116 new Object[] 117 { 118 Boolean.FALSE, 37, "HID:WIZARDS_HID_DLGFORM_lstRELATIONS", 201, 55, ISubFormStep, new Short(curtabindex++), 103 119 }); 120 lblSubFormDescription = CurUnoDialog.insertLabel("lblSubFormDescription", 121 new String[] 122 { 123 PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 124 }, 125 new Object[] 126 { 127 59, sSubFormDescription, Boolean.TRUE, 110, 120, ISubFormStep, new Short(curtabindex++), 190 128 }); 129 CurUnoDialog.insertInfoImage(97, 120, ISubFormStep.intValue()); 130 } 131 132 // public void disableSubFormCheckBox() 133 // { 134 // Helper.setUnoPropertyValue(UnoDialog.getModel(chkcreateSubForm), PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 135 // } 136 getRelationController()137 public RelationController getRelationController() 138 { 139 return oRelationController; 140 } 141 areexistingRelationsdefined()142 public boolean areexistingRelationsdefined() 143 { 144 return ((chkcreateSubForm.getState() == 1) && (optOnExistingRelation.getState())); 145 } 146 toggleSubFormMode()147 public void toggleSubFormMode() 148 { 149 boolean bdoEnable = (this.chkcreateSubForm.getState() == 1); 150 Helper.setUnoPropertyValue(UnoDialog.getModel(optOnExistingRelation), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoEnable && bsupportsRelations)); 151 Helper.setUnoPropertyValue(UnoDialog.getModel(optSelectManually), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoEnable)); 152 toggleSteps(); 153 } 154 initialize(CommandFieldSelection _CurSubFormFieldSelection, RelationController _oRelationController)155 public void initialize(CommandFieldSelection _CurSubFormFieldSelection, RelationController _oRelationController) 156 { 157 oRelationController = _oRelationController; 158 sreferencedTables = oRelationController.getExportedKeys(); 159 bsupportsRelations = (sreferencedTables.length > 0); 160 Helper.setUnoPropertyValue(UnoDialog.getModel(lstRelations), PropertyNames.STRING_ITEM_LIST, sreferencedTables); 161 this.CurSubFormFieldSelection = _CurSubFormFieldSelection; 162 toggleRelationsListbox(); 163 Helper.setUnoPropertyValue(UnoDialog.getModel(optOnExistingRelation), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bsupportsRelations && (chkcreateSubForm.getState() == 1))); 164 } 165 toggleSteps()166 public void toggleSteps() 167 { 168 boolean bDoEnableFollowingSteps; 169 if (chkcreateSubForm.getState() == 1) 170 { 171 if (optOnExistingRelation.getState()) 172 { 173 onexistingRelationSelection(); 174 } 175 else if (optSelectManually.getState()) 176 { 177 CurUnoDialog.enablefromStep(FormWizard.SOFIELDLINKER_PAGE, (CurSubFormFieldSelection.getSelectedFieldNames().length > 0)); 178 CurUnoDialog.setStepEnabled(FormWizard.SOSUBFORMFIELDS_PAGE, true); 179 } 180 } 181 else 182 { 183 CurUnoDialog.setStepEnabled(FormWizard.SOSUBFORMFIELDS_PAGE, false); 184 CurUnoDialog.setStepEnabled(FormWizard.SOFIELDLINKER_PAGE, false); 185 CurUnoDialog.enablefromStep(FormWizard.SOCONTROL_PAGE, true); 186 } 187 toggleRelationsListbox(); 188 } 189 getreferencedTableName()190 public String getreferencedTableName() 191 { 192 if (areexistingRelationsdefined()) 193 { 194 short[] iselected = (short[]) Helper.getUnoArrayPropertyValue(UnoDialog.getModel(lstRelations), PropertyNames.SELECTED_ITEMS); 195 if (iselected != null) 196 { 197 if (iselected.length > 0) 198 { 199 return sreferencedTables[iselected[0]]; 200 } 201 } 202 } 203 return PropertyNames.EMPTY_STRING; 204 } 205 onexistingRelationSelection()206 public void onexistingRelationSelection() 207 { 208 String scurreferencedTableName = getreferencedTableName(); 209 if (scurreferencedTableName.length() > 0) 210 { 211 if (CurSubFormFieldSelection.getSelectedCommandName().equals(scurreferencedTableName)) 212 { 213 CurUnoDialog.enablefromStep(FormWizard.SOSUBFORMFIELDS_PAGE, true); 214 CurUnoDialog.setStepEnabled(FormWizard.SOFIELDLINKER_PAGE, false); 215 return; 216 } 217 else 218 { 219 CurUnoDialog.setStepEnabled(FormWizard.SOSUBFORMFIELDS_PAGE, true); 220 CurUnoDialog.enablefromStep(FormWizard.SOFIELDLINKER_PAGE, false); 221 return; 222 } 223 } 224 CurUnoDialog.enablefromStep(FormWizard.SOSUBFORMFIELDS_PAGE, false); 225 } 226 toggleRelationsListbox()227 private void toggleRelationsListbox() 228 { 229 boolean bdoenable = bsupportsRelations && this.optOnExistingRelation.getState() && (chkcreateSubForm.getState() == 1); 230 Helper.setUnoPropertyValue(UnoDialog.getModel(lblRelations), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenable)); 231 Helper.setUnoPropertyValue(UnoDialog.getModel(lstRelations), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenable)); 232 } 233 hasSubForm()234 public boolean hasSubForm() 235 { 236 return (this.chkcreateSubForm.getState() == 1); 237 } 238 } 239