1*a1b4a26bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a1b4a26bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a1b4a26bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a1b4a26bSAndrew Rist * distributed with this work for additional information 6*a1b4a26bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a1b4a26bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a1b4a26bSAndrew Rist * "License"); you may not use this file except in compliance 9*a1b4a26bSAndrew Rist * with the License. You may obtain a copy of the License at 10*a1b4a26bSAndrew Rist * 11*a1b4a26bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a1b4a26bSAndrew Rist * 13*a1b4a26bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a1b4a26bSAndrew Rist * software distributed under the License is distributed on an 15*a1b4a26bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a1b4a26bSAndrew Rist * KIND, either express or implied. See the License for the 17*a1b4a26bSAndrew Rist * specific language governing permissions and limitations 18*a1b4a26bSAndrew Rist * under the License. 19*a1b4a26bSAndrew Rist * 20*a1b4a26bSAndrew Rist *************************************************************/ 21*a1b4a26bSAndrew Rist 22*a1b4a26bSAndrew Rist 23cdf0e10cSrcweir package com.sun.star.wizards.form; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.awt.ItemEvent; 26cdf0e10cSrcweir import com.sun.star.awt.VclWindowPeerAttribute; 27cdf0e10cSrcweir import com.sun.star.awt.XFixedText; 28cdf0e10cSrcweir import com.sun.star.awt.XListBox; 29cdf0e10cSrcweir import com.sun.star.uno.Exception; 30cdf0e10cSrcweir import com.sun.star.wizards.common.Helper; 31cdf0e10cSrcweir import com.sun.star.wizards.common.HelpIds; 32cdf0e10cSrcweir import com.sun.star.wizards.common.JavaTools; 33cdf0e10cSrcweir import com.sun.star.wizards.db.RelationController; 34cdf0e10cSrcweir import com.sun.star.wizards.ui.UnoDialog; 35cdf0e10cSrcweir import com.sun.star.wizards.ui.WizardDialog; 36cdf0e10cSrcweir import com.sun.star.wizards.ui.UIConsts; 37cdf0e10cSrcweir import com.sun.star.wizards.ui.DBLimitedFieldSelection; 38cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames; 39cdf0e10cSrcweir 40cdf0e10cSrcweir public class FieldLinker extends DBLimitedFieldSelection 41cdf0e10cSrcweir { 42cdf0e10cSrcweir 43cdf0e10cSrcweir private XFixedText[] lblSlaveFields; 44cdf0e10cSrcweir private XFixedText[] lblMasterFields; 45cdf0e10cSrcweir private XListBox[] lstSlaveFields; 46cdf0e10cSrcweir private XListBox[] lstMasterFields; 47cdf0e10cSrcweir private int[] SOLINKLST = null; 48cdf0e10cSrcweir private String[] sSlaveListHeader; 49cdf0e10cSrcweir private String[] sMasterListHeader; //CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 40); 50cdf0e10cSrcweir FieldLinker(WizardDialog _CurUnoDialog, int iStep, int iCompPosX, int iCompPosY, int iCompWidth, int _firsthelpid)51cdf0e10cSrcweir public FieldLinker(WizardDialog _CurUnoDialog, int iStep, int iCompPosX, int iCompPosY, int iCompWidth, int _firsthelpid) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir super(_CurUnoDialog, iStep, iCompPosX, iCompPosY, iCompWidth, _firsthelpid); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir insertControlGroup(int i)56cdf0e10cSrcweir protected void insertControlGroup(int i) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir try 59cdf0e10cSrcweir { 60cdf0e10cSrcweir if (i == 0) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir lblSlaveFields = new XFixedText[rowcount]; 63cdf0e10cSrcweir lblMasterFields = new XFixedText[rowcount]; 64cdf0e10cSrcweir lstSlaveFields = new XListBox[rowcount]; 65cdf0e10cSrcweir lstMasterFields = new XListBox[rowcount]; 66cdf0e10cSrcweir int SOFIRSTLINKLST = 0; 67cdf0e10cSrcweir int SOSECLINKLST = 1; 68cdf0e10cSrcweir int SOTHIRDLINKLST = 2; 69cdf0e10cSrcweir int SOFOURTHLINKLST = 3; 70cdf0e10cSrcweir Integer IListBoxPosX = new Integer(iCompPosX + 6); 71cdf0e10cSrcweir sSlaveListHeader = CurUnoDialog.m_oResource.getResArray(UIConsts.RID_FORM + 20, 4); //new String[rowcount];PropertyNames.EMPTY_STRING; //CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 40); 72cdf0e10cSrcweir sMasterListHeader = CurUnoDialog.m_oResource.getResArray(UIConsts.RID_FORM + 24, 4);// new String[rowcount];PropertyNames.EMPTY_STRING; //CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 40); 73cdf0e10cSrcweir SOLINKLST = new int[] 74cdf0e10cSrcweir { 75cdf0e10cSrcweir SOFIRSTLINKLST, SOSECLINKLST, SOTHIRDLINKLST, SOFOURTHLINKLST 76cdf0e10cSrcweir }; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir String sSlaveHidString = HelpIds.getHelpIdString(FirstHelpIndex + (i * 2)); 79cdf0e10cSrcweir String sMasterHidString = HelpIds.getHelpIdString(FirstHelpIndex + (i * 2) + 1); 80cdf0e10cSrcweir boolean bDoEnable = (i < 2); 81cdf0e10cSrcweir lblSlaveFields[i] = CurUnoDialog.insertLabel("lblSlaveFieldLink" + Integer.toString(i + 1), 82cdf0e10cSrcweir new String[] 83cdf0e10cSrcweir { 84cdf0e10cSrcweir PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 85cdf0e10cSrcweir }, 86cdf0e10cSrcweir new Object[] 87cdf0e10cSrcweir { 88cdf0e10cSrcweir Boolean.valueOf(bDoEnable), 8, sSlaveListHeader[i], 97, new Integer(iCurPosY), IStep, new Short(curtabindex++), 97 89cdf0e10cSrcweir }); 90cdf0e10cSrcweir lstSlaveFields[i] = CurUnoDialog.insertListBox("lstSlaveFieldLink" + (i + 1), SOLINKLST[i], null, new ItemListenerImpl(), 91cdf0e10cSrcweir new String[] 92cdf0e10cSrcweir { 93cdf0e10cSrcweir "Dropdown", 94cdf0e10cSrcweir PropertyNames.PROPERTY_ENABLED, 95cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, 96cdf0e10cSrcweir PropertyNames.PROPERTY_HELPURL, 97cdf0e10cSrcweir "LineCount", 98cdf0e10cSrcweir PropertyNames.PROPERTY_POSITION_X, 99cdf0e10cSrcweir PropertyNames.PROPERTY_POSITION_Y, 100cdf0e10cSrcweir PropertyNames.PROPERTY_STEP, 101cdf0e10cSrcweir PropertyNames.PROPERTY_TABINDEX, 102cdf0e10cSrcweir PropertyNames.PROPERTY_WIDTH 103cdf0e10cSrcweir }, 104cdf0e10cSrcweir new Object[] 105cdf0e10cSrcweir { 106cdf0e10cSrcweir Boolean.TRUE, 107cdf0e10cSrcweir Boolean.valueOf(bDoEnable), 108cdf0e10cSrcweir UIConsts.INTEGER_12, 109cdf0e10cSrcweir sSlaveHidString, 110cdf0e10cSrcweir Short.valueOf(UnoDialog.getListBoxLineCount()), 111cdf0e10cSrcweir 97, 112cdf0e10cSrcweir new Integer(iCurPosY + 10), 113cdf0e10cSrcweir IStep, 114cdf0e10cSrcweir new Short(curtabindex++), 115cdf0e10cSrcweir 97 116cdf0e10cSrcweir }); 117cdf0e10cSrcweir 118cdf0e10cSrcweir lblMasterFields[i] = CurUnoDialog.insertLabel("lblMasterFieldLink" + Integer.toString(i + 1), 119cdf0e10cSrcweir new String[] 120cdf0e10cSrcweir { 121cdf0e10cSrcweir PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH 122cdf0e10cSrcweir }, 123cdf0e10cSrcweir new Object[] 124cdf0e10cSrcweir { 125cdf0e10cSrcweir Boolean.valueOf(bDoEnable), 8, sMasterListHeader[i], 206, new Integer(iCurPosY), IStep, new Short(curtabindex++), 97 126cdf0e10cSrcweir }); 127cdf0e10cSrcweir 128cdf0e10cSrcweir lstMasterFields[i] = CurUnoDialog.insertListBox("lstMasterFieldLink" + Integer.toString(i + 1), SOLINKLST[i], null, new ItemListenerImpl(), 129cdf0e10cSrcweir new String[] 130cdf0e10cSrcweir { 131cdf0e10cSrcweir "Dropdown", 132cdf0e10cSrcweir PropertyNames.PROPERTY_ENABLED, 133cdf0e10cSrcweir PropertyNames.PROPERTY_HEIGHT, 134cdf0e10cSrcweir PropertyNames.PROPERTY_HELPURL, 135cdf0e10cSrcweir "LineCount", 136cdf0e10cSrcweir PropertyNames.PROPERTY_POSITION_X, 137cdf0e10cSrcweir PropertyNames.PROPERTY_POSITION_Y, 138cdf0e10cSrcweir PropertyNames.PROPERTY_STEP, 139cdf0e10cSrcweir PropertyNames.PROPERTY_TABINDEX, 140cdf0e10cSrcweir PropertyNames.PROPERTY_WIDTH 141cdf0e10cSrcweir }, 142cdf0e10cSrcweir new Object[] 143cdf0e10cSrcweir { 144cdf0e10cSrcweir Boolean.TRUE, 145cdf0e10cSrcweir Boolean.valueOf(bDoEnable), 146cdf0e10cSrcweir UIConsts.INTEGER_12, 147cdf0e10cSrcweir sMasterHidString, 148cdf0e10cSrcweir Short.valueOf(UnoDialog.getListBoxLineCount()), 149cdf0e10cSrcweir 206, 150cdf0e10cSrcweir new Integer(iCurPosY + 10), 151cdf0e10cSrcweir IStep, 152cdf0e10cSrcweir new Short(curtabindex++), 153cdf0e10cSrcweir 97 154cdf0e10cSrcweir }); 155cdf0e10cSrcweir iCurPosY = iCurPosY + 38; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir catch (Exception e) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir e.printStackTrace(System.out); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir enableNextControlRow(int curindex)163cdf0e10cSrcweir protected void enableNextControlRow(int curindex) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir // setMaxSelIndex(); 166cdf0e10cSrcweir boolean bSlaveField = lstSlaveFields[curindex].getSelectedItemPos() > 0; 167cdf0e10cSrcweir boolean bMasterField = lstMasterFields[curindex].getSelectedItemPos() > 0; 168cdf0e10cSrcweir boolean bDoEnable = (bSlaveField && bMasterField); 169cdf0e10cSrcweir if (!bDoEnable) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir moveupSelectedItems(curindex, bDoEnable); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir else 174cdf0e10cSrcweir { 175cdf0e10cSrcweir toggleControlRow(curindex + 1, true); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir getMaxSelIndex()179cdf0e10cSrcweir protected int getMaxSelIndex() 180cdf0e10cSrcweir { 181cdf0e10cSrcweir int MaxSelIndex = -1; 182cdf0e10cSrcweir for (int i = 0; i < rowcount; i++) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir if ((lstSlaveFields[i].getSelectedItemPos() > 0) && (lstMasterFields[i].getSelectedItemPos() > 0)) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir MaxSelIndex += 1; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir } 189cdf0e10cSrcweir return MaxSelIndex; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir toggleControlRow(int i, boolean bDoEnable)192cdf0e10cSrcweir protected void toggleControlRow(int i, boolean bDoEnable) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir if (i < rowcount) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lblSlaveFields[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); 197cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lstSlaveFields[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); 198cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lblMasterFields[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); 199cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lstMasterFields[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); 200cdf0e10cSrcweir if (!bDoEnable) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lstSlaveFields[i]), PropertyNames.SELECTED_ITEMS, new short[] { 0 }); 203cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lstMasterFields[i]), PropertyNames.SELECTED_ITEMS, new short[] { 0 }); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir } 206cdf0e10cSrcweir } 207cdf0e10cSrcweir updateFromNextControlRow(int curindex)208cdf0e10cSrcweir protected void updateFromNextControlRow(int curindex) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir short iNextMasterItemPos = lstMasterFields[curindex + 1].getSelectedItemPos(); 211cdf0e10cSrcweir short iNextSlaveItemPos = lstSlaveFields[curindex + 1].getSelectedItemPos(); 212cdf0e10cSrcweir 213cdf0e10cSrcweir if ((iNextMasterItemPos != 0) && (iNextSlaveItemPos != 0)) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lstMasterFields[curindex]), PropertyNames.SELECTED_ITEMS, new short[] {iNextMasterItemPos }); 216cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lstSlaveFields[curindex]), PropertyNames.SELECTED_ITEMS, new short[] {iNextSlaveItemPos}); 217cdf0e10cSrcweir 218cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lstMasterFields[curindex + 1]), PropertyNames.SELECTED_ITEMS, new short[] { 0 }); 219cdf0e10cSrcweir Helper.setUnoPropertyValue(UnoDialog.getModel(lstSlaveFields[curindex + 1]), PropertyNames.SELECTED_ITEMS, new short[] { 0 }); 220cdf0e10cSrcweir toggleControlRow(curindex, true); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir } 223cdf0e10cSrcweir initialize(String[] _AllMasterFieldNames, String[] _AllSlaveFieldNames, String[][] _LinkFieldNames)224cdf0e10cSrcweir public void initialize(String[] _AllMasterFieldNames, String[] _AllSlaveFieldNames, String[][] _LinkFieldNames) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir // short[] MasterSelList = null; 227cdf0e10cSrcweir // short[] SlaveSelList = null; 228cdf0e10cSrcweir int SOMASTERINDEX = 1; 229cdf0e10cSrcweir String[] MasterLinkNames = JavaTools.ArrayOutOfMultiDimArray(_LinkFieldNames, SOMASTERINDEX); 230cdf0e10cSrcweir int SOSLAVEINDEX = 0; 231cdf0e10cSrcweir String[] SlaveLinkNames = JavaTools.ArrayOutOfMultiDimArray(_LinkFieldNames, SOSLAVEINDEX); 232cdf0e10cSrcweir String[] ViewMasterFieldNames = addNoneFieldItemToList(_AllMasterFieldNames); // add '-undefiened-' 233cdf0e10cSrcweir String[] ViewSlaveFieldNames = addNoneFieldItemToList(_AllSlaveFieldNames); 234cdf0e10cSrcweir for (int i = 0; i < super.rowcount; i++) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir super.initializeListBox(lstMasterFields[i], ViewMasterFieldNames, MasterLinkNames, i); 237cdf0e10cSrcweir super.initializeListBox(lstSlaveFields[i], ViewSlaveFieldNames, SlaveLinkNames, i); 238cdf0e10cSrcweir if (_LinkFieldNames != null) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir toggleControlRow(i, (i <= _LinkFieldNames.length)); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir else 243cdf0e10cSrcweir { 244cdf0e10cSrcweir toggleControlRow(i, i == 0); 245cdf0e10cSrcweir } 246cdf0e10cSrcweir } 247cdf0e10cSrcweir } 248cdf0e10cSrcweir getLinkFieldNames(RelationController _oRelationController, String _sReferencedTableName)249cdf0e10cSrcweir public String[][] getLinkFieldNames(RelationController _oRelationController, String _sReferencedTableName) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir return _oRelationController.getImportedKeyColumns(_sReferencedTableName); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir /** 255cdf0e10cSrcweir * @return the LinkFieldnames of the joins. When no LinkFieldNames were selected the returned Array is empty. 256cdf0e10cSrcweir * When Joins were assigned duplicate a null value is returned 257cdf0e10cSrcweir * 258cdf0e10cSrcweir */ getLinkFieldNames()259cdf0e10cSrcweir public String[][] getLinkFieldNames() 260cdf0e10cSrcweir { 261cdf0e10cSrcweir // setMaxSelIndex(); 262cdf0e10cSrcweir int nSelectedIndex = getMaxSelIndex(); 263cdf0e10cSrcweir String[][] LinkFieldNames = new String[2][nSelectedIndex + 1]; 264cdf0e10cSrcweir for (int i = 0; i <= nSelectedIndex; i++) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir LinkFieldNames[0][i] = lstSlaveFields[i].getSelectedItem(); 267cdf0e10cSrcweir LinkFieldNames[1][i] = lstMasterFields[i].getSelectedItem(); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir int iduplicate = JavaTools.getDuplicateFieldIndex(LinkFieldNames); 270cdf0e10cSrcweir if (iduplicate != -1) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir String sLinkFieldsAreDuplicate = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 19); 273cdf0e10cSrcweir String sLocLinkFieldsAreDuplicate = JavaTools.replaceSubString(sLinkFieldsAreDuplicate, LinkFieldNames[0][iduplicate], "<FIELDNAME1>"); 274cdf0e10cSrcweir sLocLinkFieldsAreDuplicate = JavaTools.replaceSubString(sLocLinkFieldsAreDuplicate, LinkFieldNames[1][iduplicate], "<FIELDNAME2>"); 275cdf0e10cSrcweir CurUnoDialog.setCurrentStep(FormWizard.SOFIELDLINKER_PAGE); 276cdf0e10cSrcweir CurUnoDialog.enableNavigationButtons(true, true, true); 277cdf0e10cSrcweir CurUnoDialog.showMessageBox("WarningBox", VclWindowPeerAttribute.OK, sLocLinkFieldsAreDuplicate); 278cdf0e10cSrcweir CurUnoDialog.setFocus("lstSlaveFieldLink" + (iduplicate + 1)); 279cdf0e10cSrcweir return null; 280cdf0e10cSrcweir } 281cdf0e10cSrcweir return LinkFieldNames; 282cdf0e10cSrcweir 283cdf0e10cSrcweir } 284cdf0e10cSrcweir enable(boolean _bdoenable)285cdf0e10cSrcweir public void enable(boolean _bdoenable) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir CurUnoDialog.setStepEnabled(IStep.intValue(), _bdoenable); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir class ItemListenerImpl implements com.sun.star.awt.XItemListener 291cdf0e10cSrcweir { 292cdf0e10cSrcweir itemStateChanged(ItemEvent EventObject)293cdf0e10cSrcweir public void itemStateChanged(ItemEvent EventObject) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir int ikey = CurUnoDialog.getControlKey(EventObject.Source, CurUnoDialog.ControlList); 296cdf0e10cSrcweir enableNextControlRow(ikey); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir disposing(com.sun.star.lang.EventObject eventObject)299cdf0e10cSrcweir public void disposing(com.sun.star.lang.EventObject eventObject) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir } 302cdf0e10cSrcweir } 303cdf0e10cSrcweir } 304