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.ui; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.awt.XTextComponent; 26cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 27cdf0e10cSrcweir import com.sun.star.uno.Exception; 28cdf0e10cSrcweir import com.sun.star.wizards.common.FileAccess; 29cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames; 30cdf0e10cSrcweir import com.sun.star.wizards.common.SystemDialog; 31cdf0e10cSrcweir 32cdf0e10cSrcweir public class PathSelection 33cdf0e10cSrcweir { 34cdf0e10cSrcweir 35cdf0e10cSrcweir UnoDialog2 CurUnoDialog; 36cdf0e10cSrcweir XMultiServiceFactory xMSF; 37cdf0e10cSrcweir int iDialogType; 38cdf0e10cSrcweir int iTransferMode; 39cdf0e10cSrcweir public String sDefaultDirectory = PropertyNames.EMPTY_STRING; 40cdf0e10cSrcweir public String sDefaultName = PropertyNames.EMPTY_STRING; 41cdf0e10cSrcweir public String sDefaultFilter = PropertyNames.EMPTY_STRING; 42cdf0e10cSrcweir public boolean usedPathPicker = false; 43cdf0e10cSrcweir public XPathSelectionListener xAction; 44cdf0e10cSrcweir public XTextComponent xSaveTextBox; 45cdf0e10cSrcweir private final int CMDSELECTPATH = 1; 46cdf0e10cSrcweir private final int TXTSAVEPATH = 1; 47cdf0e10cSrcweir 48cdf0e10cSrcweir public static class DialogTypes 49cdf0e10cSrcweir { 50cdf0e10cSrcweir 51cdf0e10cSrcweir public static final int FOLDER = 0; 52cdf0e10cSrcweir public static final int FILE = 1; 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir public static class TransferMode 56cdf0e10cSrcweir { 57cdf0e10cSrcweir 58cdf0e10cSrcweir public static final int SAVE = 0; 59cdf0e10cSrcweir public static final int LOAD = 1; 60cdf0e10cSrcweir } 61cdf0e10cSrcweir PathSelection(XMultiServiceFactory xMSF, UnoDialog2 CurUnoDialog, int TransferMode, int DialogType)62cdf0e10cSrcweir public PathSelection(XMultiServiceFactory xMSF, UnoDialog2 CurUnoDialog, int TransferMode, int DialogType) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir this.CurUnoDialog = CurUnoDialog; 65cdf0e10cSrcweir this.xMSF = xMSF; 66cdf0e10cSrcweir this.iDialogType = DialogType; 67cdf0e10cSrcweir this.iTransferMode = TransferMode; 68cdf0e10cSrcweir 69cdf0e10cSrcweir } 70cdf0e10cSrcweir insert(int DialogStep, int XPos, int YPos, int Width, short CurTabIndex, String LabelText, boolean Enabled, String TxtHelpURL, String BtnHelpURL)71cdf0e10cSrcweir public void insert(int DialogStep, int XPos, int YPos, int Width, short CurTabIndex, String LabelText, boolean Enabled, String TxtHelpURL, String BtnHelpURL) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir 74cdf0e10cSrcweir CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblSaveAs", new String[] 75cdf0e10cSrcweir { 76cdf0e10cSrcweir 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 77cdf0e10cSrcweir }, new Object[] 78cdf0e10cSrcweir { 79cdf0e10cSrcweir Boolean.valueOf(Enabled), 8, LabelText, new Integer(XPos), new Integer(YPos), new Integer(DialogStep), new Short(CurTabIndex), new Integer(Width) 80cdf0e10cSrcweir }); 81cdf0e10cSrcweir 82cdf0e10cSrcweir xSaveTextBox = CurUnoDialog.insertTextField("txtSavePath", "callXPathSelectionListener", this, new String[] 83cdf0e10cSrcweir { 84cdf0e10cSrcweir 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 85cdf0e10cSrcweir }, new Object[] 86cdf0e10cSrcweir { 87cdf0e10cSrcweir Boolean.valueOf(Enabled), 12, TxtHelpURL, new Integer(XPos), new Integer(YPos + 10), new Integer(DialogStep), new Short((short) (CurTabIndex + 1)), new Integer(Width - 26) 88cdf0e10cSrcweir }); 89cdf0e10cSrcweir //CurUnoDialog.setControlProperty("txtSavePath", PropertyNames.READ_ONLY, Boolean.TRUE); 90cdf0e10cSrcweir CurUnoDialog.setControlProperty("txtSavePath", PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 91cdf0e10cSrcweir CurUnoDialog.insertButton("cmdSelectPath", "triggerPathPicker", this, new String[] 92cdf0e10cSrcweir { 93cdf0e10cSrcweir 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 94cdf0e10cSrcweir }, new Object[] 95cdf0e10cSrcweir { 96cdf0e10cSrcweir Boolean.valueOf(Enabled), 14, BtnHelpURL, "...", new Integer(XPos + Width - 16), new Integer(YPos + 9), new Integer(DialogStep), new Short((short) (CurTabIndex + 2)), 16 97cdf0e10cSrcweir }); 98cdf0e10cSrcweir 99cdf0e10cSrcweir } 100cdf0e10cSrcweir addSelectionListener(XPathSelectionListener xAction)101cdf0e10cSrcweir public void addSelectionListener(XPathSelectionListener xAction) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir this.xAction = xAction; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir getSelectedPath()106cdf0e10cSrcweir public String getSelectedPath() 107cdf0e10cSrcweir { 108cdf0e10cSrcweir return xSaveTextBox.getText(); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir initializePath()111cdf0e10cSrcweir public void initializePath() 112cdf0e10cSrcweir { 113cdf0e10cSrcweir try 114cdf0e10cSrcweir { 115cdf0e10cSrcweir FileAccess myFA = new FileAccess(xMSF); 116cdf0e10cSrcweir xSaveTextBox.setText(myFA.getPath(sDefaultDirectory + "/" + sDefaultName, null)); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir catch (Exception e) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir e.printStackTrace(); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123cdf0e10cSrcweir triggerPathPicker()124cdf0e10cSrcweir public void triggerPathPicker() 125cdf0e10cSrcweir { 126cdf0e10cSrcweir try 127cdf0e10cSrcweir { 128cdf0e10cSrcweir switch (iTransferMode) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir case TransferMode.SAVE: 131cdf0e10cSrcweir switch (iDialogType) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir case DialogTypes.FOLDER: 134cdf0e10cSrcweir //TODO: write code for picking a folder for saving 135cdf0e10cSrcweir break; 136cdf0e10cSrcweir case DialogTypes.FILE: 137cdf0e10cSrcweir usedPathPicker = true; 138cdf0e10cSrcweir SystemDialog myFilePickerDialog = SystemDialog.createStoreDialog(xMSF); 139cdf0e10cSrcweir myFilePickerDialog.callStoreDialog(sDefaultDirectory, sDefaultName, sDefaultFilter); 140cdf0e10cSrcweir String sStorePath = myFilePickerDialog.sStorePath; 141cdf0e10cSrcweir if (sStorePath != null) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir FileAccess myFA = new FileAccess(xMSF); 144cdf0e10cSrcweir xSaveTextBox.setText(myFA.getPath(sStorePath, null)); 145cdf0e10cSrcweir sDefaultDirectory = FileAccess.getParentDir(sStorePath); 146cdf0e10cSrcweir sDefaultName = myFA.getFilename(sStorePath); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir break; 149cdf0e10cSrcweir default: 150cdf0e10cSrcweir break; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir break; 153cdf0e10cSrcweir case TransferMode.LOAD: 154cdf0e10cSrcweir switch (iDialogType) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir case DialogTypes.FOLDER: 157cdf0e10cSrcweir //TODO: write code for picking a folder for loading 158cdf0e10cSrcweir break; 159cdf0e10cSrcweir case DialogTypes.FILE: 160cdf0e10cSrcweir //TODO: write code for picking a file for loading 161cdf0e10cSrcweir break; 162cdf0e10cSrcweir default: 163cdf0e10cSrcweir break; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir break; 166cdf0e10cSrcweir default: 167cdf0e10cSrcweir break; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } 170cdf0e10cSrcweir catch (Exception e) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir // TODO Auto-generated catch block 173cdf0e10cSrcweir e.printStackTrace(); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir callXPathSelectionListener()177cdf0e10cSrcweir public void callXPathSelectionListener() 178cdf0e10cSrcweir { 179cdf0e10cSrcweir if (xAction != null) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir xAction.validatePath(); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir } 184cdf0e10cSrcweir } 185