diff options
Diffstat (limited to 'wizards/com/sun/star/wizards/ui')
37 files changed, 8438 insertions, 0 deletions
diff --git a/wizards/com/sun/star/wizards/ui/AggregateComponent.java b/wizards/com/sun/star/wizards/ui/AggregateComponent.java new file mode 100644 index 000000000..c9f0659f3 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/AggregateComponent.java @@ -0,0 +1,575 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import java.util.ArrayList; + +import com.sun.star.awt.FontDescriptor; +import com.sun.star.awt.VclWindowPeerAttribute; +import com.sun.star.awt.XListBox; +import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.EventObject; +import com.sun.star.sdbc.SQLException; +import com.sun.star.uno.AnyConverter; +import com.sun.star.wizards.common.HelpIds; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.common.Properties; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.common.Resource; +import com.sun.star.wizards.db.QueryMetaData; + +public class AggregateComponent extends ControlScroller +{ + + private String[] sFunctions; + private String[] sFunctionOperators = new String[] + { + "SUM", "AVG", "MIN", "MAX", "COUNT" + }; + private QueryMetaData CurDBMetaData; + private String soptDetailQuery; + private String soptSummaryQuery; + private String slblAggregate; + private String slblFieldNames; + private String sDuplicateAggregateFunction; + private static final int SOADDROW = 1; + private static final int SOREMOVEROW = 2; + private ArrayList<ControlRow> ControlRowVector; + private int lastHelpIndex; + + /** Creates a new instance of AggregateComponent */ + public AggregateComponent(WizardDialog _CurUnoDialog, QueryMetaData _CurDBMetaData, int _iStep, int _iPosX, int _iPosY, int _iWidth, int _uitextfieldcount, int _firstHelpID) + { + super(_CurUnoDialog, _iStep, _iPosX + 10, _iPosY, _iWidth - 12, _uitextfieldcount, 18, _firstHelpID + 2); + try + { + this.CurDBMetaData = _CurDBMetaData; + CurUnoDialog.insertRadioButton("optDetailQuery", 0, new ActionListenerImpl(), + new String[] + { + 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 + }, + new Object[] + { + 8, HelpIds.getHelpIdString(_firstHelpID), soptDetailQuery, Integer.valueOf(_iPosX), Integer.valueOf(iCompPosY - 42), Short.valueOf((short) 1), IStep, Short.valueOf(curtabindex++), Integer.valueOf(iCompWidth) + }); + + CurUnoDialog.insertRadioButton("optSummaryQuery", 0, new ActionListenerImpl(), + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 16, HelpIds.getHelpIdString(_firstHelpID + 1), soptSummaryQuery, Boolean.TRUE, Integer.valueOf(_iPosX), Integer.valueOf(iCompPosY - 32), IStep, Short.valueOf(curtabindex++), Integer.valueOf(iCompWidth) + }); + CurUnoDialog.insertLabel("lblAggregate", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 8, slblAggregate, Integer.valueOf(iCompPosX + 5), Integer.valueOf(iCompPosY - 10), IStep, Short.valueOf(curtabindex++), 90 + }); + CurUnoDialog.insertLabel("lblFieldnames", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 8, slblFieldNames, Integer.valueOf(iCompPosX + 101), Integer.valueOf(iCompPosY - 10), IStep, Short.valueOf(curtabindex++), 90 + }); + this.setTotalFieldCount(1); + FontDescriptor oFontDescriptor = new FontDescriptor(); + oFontDescriptor.Weight = com.sun.star.awt.FontWeight.BOLD; + oFontDescriptor.Height = (short) 14; + + int iButtonPosY = iCompPosY + iCompHeight + 3; + CurUnoDialog.insertButton("btnplus", SOADDROW, new ActionListenerImpl(), + new String[] + { + PropertyNames.FONT_DESCRIPTOR, 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 + }, + new Object[] + { + oFontDescriptor, 14, HelpIds.getHelpIdString(lastHelpIndex + 1), "+", Integer.valueOf(_iPosX + iCompWidth - 36), Integer.valueOf(iButtonPosY), IStep, Short.valueOf((curtabindex++)), 16 + }); + CurUnoDialog.insertButton("btnminus", SOREMOVEROW, new ActionListenerImpl(), + new String[] + { + PropertyNames.FONT_DESCRIPTOR, 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 + }, + new Object[] + { + oFontDescriptor, 14, HelpIds.getHelpIdString(lastHelpIndex + 2), "-", Integer.valueOf(_iPosX + iCompWidth - 16), Integer.valueOf(iButtonPosY), IStep, Short.valueOf(curtabindex++), 16 + }); + CurDBMetaData.Type = getQueryType(); + } + catch (com.sun.star.uno.Exception exception) + { + Resource.showCommonResourceError(CurDBMetaData.xMSF); + } + } + + private int getQueryType() + { + if (((Short) CurUnoDialog.getControlProperty("optDetailQuery", PropertyNames.PROPERTY_STATE)).intValue() == 1) + { + return QueryMetaData.QueryType.SODETAILQUERY; + } + else + { + return QueryMetaData.QueryType.SOSUMMARYQUERY; + } + } + + private class ActionListenerImpl implements com.sun.star.awt.XActionListener + { + + public void disposing(EventObject eventObject) + { + } + + public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) + { + try + { + int iKey = CurUnoDialog.getControlKey(actionEvent.Source, CurUnoDialog.ControlList); + switch (iKey) + { + case SOADDROW: + addRow(); + break; + + case SOREMOVEROW: + removeRow(); + break; + + default: + toggleComponent(); + break; + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + } + + @Override + protected void insertControlGroup(int i, int ypos) + { + if (i == 0) + { + soptDetailQuery = CurUnoDialog.m_oResource.getResText("RID_QUERY_11"); + soptSummaryQuery = CurUnoDialog.m_oResource.getResText("RID_QUERY_12"); + slblAggregate = CurUnoDialog.m_oResource.getResText("RID_QUERY_16"); + slblFieldNames = CurUnoDialog.m_oResource.getResText("RID_QUERY_17"); + sFunctions = new String[5]; + sFunctions[0] = CurUnoDialog.m_oResource.getResText("RID_QUERY_40"); + sFunctions[1] = CurUnoDialog.m_oResource.getResText("RID_QUERY_41"); + sFunctions[2] = CurUnoDialog.m_oResource.getResText("RID_QUERY_42"); + sFunctions[3] = CurUnoDialog.m_oResource.getResText("RID_QUERY_43"); + sFunctions[4] = CurUnoDialog.m_oResource.getResText("RID_QUERY_44"); + + sDuplicateAggregateFunction = CurUnoDialog.m_oResource.getResText("RID_QUERY_90"); + } + if (ControlRowVector == null) + { + ControlRowVector = new ArrayList<ControlRow>(); + } + int locHelpID = curHelpIndex + (i * 2); + ControlRow oControlRow = new ControlRow(i, ypos, locHelpID); + ControlRowVector.add(oControlRow); + } + + @Override + protected void setControlGroupVisible(int _index, boolean _bIsVisible) + { + ControlRow oControlRow = ControlRowVector.get(_index); + oControlRow.setVisible(_bIsVisible); + if (_index >= (this.CurDBMetaData.AggregateFieldNames.length)) + { + oControlRow.settovoid(); + } + } + + private void addRow() + { + int fieldcount = super.getTotalFieldCount(); + registerControlGroupAtIndex(fieldcount); + if (fieldcount < super.getBlockIncrementation()) + { + ControlRow oControlRow = ControlRowVector.get(fieldcount); + oControlRow.setVisible(true); + oControlRow.settovoid(); + } + else + { + ControlRow oControlRow = ControlRowVector.get(super.getBlockIncrementation() - 1); + super.setScrollValue(getScrollValue() + 1, (fieldcount + 1)); + oControlRow.settovoid(); + } + fieldcount++; + super.setTotalFieldCount(fieldcount); + toggleButtons(); + CurUnoDialog.repaintDialogStep(); + } + + private void removeRow() + { + int fieldcount = super.getTotalFieldCount(); + if (fieldcount > 0) + { + ControlRow oControlRow; + fieldcount--; + if ((fieldcount + 1) <= super.getBlockIncrementation()) + { + oControlRow = ControlRowVector.get(fieldcount); + oControlRow.setVisible(false); + } + super.setScrollValue(getScrollValue() - 1, fieldcount); + super.unregisterControlGroup(fieldcount); + + } + toggleButtons(); + CurUnoDialog.repaintDialogStep(); + } + + private void toggleButtons() + { + ControlRow curcontrolrow = null; + boolean biscomplete = true; + CurDBMetaData.Type = getQueryType(); + CurUnoDialog.setControlProperty("btnminus", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf((super.getTotalFieldCount() > 0) && (CurDBMetaData.Type == QueryMetaData.QueryType.SOSUMMARYQUERY))); + int fieldcount = super.getCurFieldCount(); + if (fieldcount > 0) + { + curcontrolrow = ControlRowVector.get(super.getCurFieldCount() - 1); + biscomplete = curcontrolrow.isComplete(); + } + CurUnoDialog.setControlProperty("btnplus", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(biscomplete && (CurDBMetaData.Type == QueryMetaData.QueryType.SOSUMMARYQUERY))); + togglefollowingDialogSteps(); + } + + private void toggleComponent() + { + CurDBMetaData.Type = getQueryType(); + boolean benableComponent = isAggregateComponentEnabled(); + CurUnoDialog.setControlProperty("lblAggregate", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(benableComponent)); + CurUnoDialog.setControlProperty("lblFieldnames", PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(benableComponent)); + toggleButtons(); + super.toggleComponent(benableComponent); + super.toggleControls(benableComponent); + togglefollowingDialogSteps(); + } + + private boolean isAggregateComponentEnabled() + { + return (CurDBMetaData.Type == QueryMetaData.QueryType.SOSUMMARYQUERY); + } + + public boolean isGroupingpossible() + { + try + { + boolean benableGroupPage = isAggregateComponentEnabled() && CurDBMetaData.xDBMetaData.supportsGroupBy() && hasonlycompletefunctions(); + String[][] sAggregateFieldNames = this.getAggregateFieldNames(); + if (benableGroupPage) + { + for (int i = 0; i < CurDBMetaData.NumericFieldNames.length; i++) + { + boolean bisthere = (JavaTools.FieldInTable(sAggregateFieldNames, CurDBMetaData.NumericFieldNames[i]) > -1); + if (!bisthere) + { + return true; + } + } + } + } + catch (SQLException e) + { + e.printStackTrace(System.err); + } + return false; + } + + private void togglefollowingDialogSteps() + { + boolean benabletherest = true; + boolean benableGroupPage = isGroupingpossible(); + CurUnoDialog.setStepEnabled(UIConsts.SOGROUPSELECTIONPAGE, benableGroupPage); + CurUnoDialog.setStepEnabled(UIConsts.SOGROUPFILTERPAGE, benableGroupPage && CurDBMetaData.GroupFieldNames.length > 0); + if (isAggregateComponentEnabled()) + { + benabletherest = hasonlycompletefunctions(); + } + CurUnoDialog.enablefromStep(UIConsts.SOTITLESPAGE, benabletherest); + CurUnoDialog.enableNextButton(benabletherest); + } + + private void hideControlRowsfromindex(int _index) + { + if (_index < this.ControlRowVector.size()) + { + for (int i = _index; i < ControlRowVector.size(); i++) + { + ControlRow oControlRow = ControlRowVector.get(i); + oControlRow.setVisible(false); + } + } + + } + + public String[][] getAggregateFieldNames() + { + try + { + CurDBMetaData.Type = getQueryType(); + if (CurDBMetaData.Type == QueryMetaData.QueryType.SOSUMMARYQUERY) + { + ArrayList<String[]> aggregatevector = new ArrayList<String[]>(); + PropertyValue[][] aggregatelist = this.getScrollFieldValues(); + PropertyValue[] currowproperties; + if (CurDBMetaData.AggregateFieldNames != null) + { + for (int i = 0; i < aggregatelist.length; i++) + { + currowproperties = aggregatelist[i]; + if ((currowproperties[0].Value != null) && (currowproperties[1].Value != null)) + { + short[] iselfield = (short[]) AnyConverter.toArray(currowproperties[1].Value); + short[] iselfunction = (short[]) AnyConverter.toArray(currowproperties[0].Value); + if ((iselfield.length > 0) && (iselfunction.length > 0)) + { + String[] curaggregatename = new String[] { + CurDBMetaData.NumericFieldNames[iselfield[0]], + this.sFunctionOperators[iselfunction[0]] }; + aggregatevector.add(curaggregatename); + } + } + } + } + CurDBMetaData.AggregateFieldNames = new String[aggregatevector.size()][2]; + aggregatevector.toArray(CurDBMetaData.AggregateFieldNames); + } + + int iduplicate = JavaTools.getDuplicateFieldIndex(CurDBMetaData.AggregateFieldNames); + if (iduplicate != -1) + { + sDuplicateAggregateFunction = JavaTools.replaceSubString(sDuplicateAggregateFunction, CurDBMetaData.AggregateFieldNames[iduplicate][0], "<NUMERICFIELD>"); + int index = JavaTools.FieldInList(sFunctionOperators, CurDBMetaData.AggregateFieldNames[iduplicate][1]); + String sDisplayFunction = sFunctions[index]; + sDuplicateAggregateFunction = JavaTools.replaceSubString(sDuplicateAggregateFunction, sDisplayFunction, "<FUNCTION>"); + CurUnoDialog.showMessageBox("WarningBox", VclWindowPeerAttribute.OK, sDuplicateAggregateFunction); + CurUnoDialog.vetoableChange(new java.beans.PropertyChangeEvent(CurUnoDialog, "Steps", 1, 2)); + return new String[][] + { + }; + } + else + { + return CurDBMetaData.AggregateFieldNames; + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + public void initialize() + { + CurDBMetaData.setNumericFields(); + initializeScrollFields(); + int icount = CurDBMetaData.AggregateFieldNames.length; + if (icount == 0) + { + super.initialize(1); + hideControlRowsfromindex(1); + } + else + { + super.initialize(icount); + hideControlRowsfromindex(icount); + } + toggleComponent(); + CurUnoDialog.repaintDialogStep(); + } + + @Override + protected void initializeScrollFields() + { + ControlRow curControlRow; + if (CurDBMetaData.AggregateFieldNames != null) + { + for (int i = 0; i < this.getBlockIncrementation(); i++) + { + curControlRow = ControlRowVector.get(i); + curControlRow.insertFieldNames(); + } + for (int i = 0; i <= CurDBMetaData.AggregateFieldNames.length; i++) + { + registerControlGroupAtIndex(i); + } + } + } + + private void registerControlGroupAtIndex(int _index) + { + short[] iselfunctionlist = new short[] + { + }; + short[] iselfieldslist = new short[] + { + }; + PropertyValue[] currowproperties = new PropertyValue[2]; + if (_index < CurDBMetaData.AggregateFieldNames.length) + { + short iselfieldsindex = (short) JavaTools.FieldInList(CurDBMetaData.NumericFieldNames, CurDBMetaData.AggregateFieldNames[_index][0]); + iselfieldslist = new short[] + { + iselfieldsindex + }; + short iselfunctionindex = (short) JavaTools.FieldInList(sFunctionOperators, CurDBMetaData.AggregateFieldNames[_index][1]); + iselfunctionlist = new short[] + { + iselfunctionindex + }; + } + currowproperties[0] = Properties.createProperty(getFunctionControlName(_index), iselfunctionlist, _index); + currowproperties[1] = Properties.createProperty(getFieldsControlName(_index), iselfieldslist, _index); //getTitleName(i) + super.registerControlGroup(currowproperties, _index); + } + + private String getFunctionControlName(int _index) + { + String namesuffix = "_" + (_index + 1); + return "lstfunctions" + namesuffix; + } + + private String getFieldsControlName(int _index) + { + String namesuffix = "_" + (_index + 1); + return "lstFieldnames" + namesuffix; + } + + private boolean hasonlycompletefunctions() + { + int maxfieldcount = super.getCurFieldCount(); + if (maxfieldcount > 0) + { + ControlRow curcontrolrow = this.ControlRowVector.get(maxfieldcount - 1); + return curcontrolrow.isComplete(); + } + else + { + return false; + } + } + + private class ControlRow + { + + private XListBox xFieldListBox; + private XListBox xFunctionListBox; + private int index; + + private ControlRow(int _index, int ypos, int _curHelpID) + { + try + { + this.index = _index; + xFunctionListBox = CurUnoDialog.insertListBox(getFunctionControlName(index), 1, null, new ItemListenerImpl(), + new String[] + { + "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.TRUE, 12, HelpIds.getHelpIdString(_curHelpID++), Integer.valueOf(iCompPosX + 4), Integer.valueOf(ypos), UIConsts.INVISIBLESTEP, sFunctions, Short.valueOf(curtabindex++), 88 + }); + + xFieldListBox = CurUnoDialog.insertListBox(getFieldsControlName(index), 1, null, new ItemListenerImpl(), + new String[] + { + "Dropdown", PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.TRUE, 12, HelpIds.getHelpIdString(_curHelpID++), Integer.valueOf(iCompPosX + 98), Integer.valueOf(ypos), UIConsts.INVISIBLESTEP, Short.valueOf(curtabindex++), 86 + }); + lastHelpIndex = _curHelpID - 1; + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + private void setVisible(boolean _bvisible) + { + CurUnoDialog.setControlVisible(getFunctionControlName(index), _bvisible); + CurUnoDialog.setControlVisible(getFieldsControlName(index), _bvisible); + } + + private void insertFieldNames() + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xFieldListBox), PropertyNames.STRING_ITEM_LIST, CurDBMetaData.NumericFieldNames); + } + + private boolean isComplete() + { + boolean bfieldnameisselected = (Helper.getUnoArrayPropertyValue(UnoDialog.getModel(xFieldListBox), PropertyNames.SELECTED_ITEMS) != null); + boolean bfunctionisselected = (Helper.getUnoArrayPropertyValue(UnoDialog.getModel(xFunctionListBox), PropertyNames.SELECTED_ITEMS) != null); + return (bfieldnameisselected && bfunctionisselected); + } + + private void settovoid() + { + UnoDialog.deselectListBox(xFieldListBox); + UnoDialog.deselectListBox(xFunctionListBox); + } + + private class ItemListenerImpl implements com.sun.star.awt.XItemListener + { + + public void itemStateChanged(com.sun.star.awt.ItemEvent EventObject) + { + try + { + toggleButtons(); + togglefollowingDialogSteps(); + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + } + } + } +} diff --git a/wizards/com/sun/star/wizards/ui/ButtonList.java b/wizards/com/sun/star/wizards/ui/ButtonList.java new file mode 100644 index 000000000..522768bf8 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/ButtonList.java @@ -0,0 +1,626 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import javax.swing.ListModel; +import com.sun.star.awt.ActionEvent; +import com.sun.star.awt.Size; +import com.sun.star.awt.XActionListener; +import com.sun.star.awt.XButton; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XControlModel; +import com.sun.star.awt.XFixedText; +import com.sun.star.awt.XItemEventBroadcaster; +import com.sun.star.awt.XItemListener; +import com.sun.star.awt.XWindow; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.HelpIds; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.IRenderer; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.common.PropertySetHelper; +import com.sun.star.wizards.ui.event.XActionListenerAdapter; + +public class ButtonList implements XItemEventBroadcaster, XActionListener +{ + + private XFixedText lblImageText; + private XButton btnBack; + private XButton btnNext; + private XFixedText lblCounter; + private XControl m_aButtons[]; + private boolean benabled = true; + private UnoDialog2 oUnoDialog; + private Size gap = new Size(4, 4); + private int cols = 4; + private int rows = 3; + private Size m_aButtonSize = new Size(20, 20); + private Size pos; + private boolean showButtons = true; + private Short step; + private static final boolean refreshOverNull = true; + private static final int imageTextLines = 1; + private boolean rowSelect = false; + public int tabIndex; + private String m_aControlName = "il"; + private int m_nCurrentSelection = -1; + private int pageStart = 0; + public int helpURL = 0; + private IRenderer renderer; + private ListModel listModel; + private IRenderer counterRenderer = new SimpleCounterRenderer(); + private static final int LINE_HEIGHT = 8; + + public void setName(String _sName) + { + m_aControlName = _sName; + } + + /** Setter for property m_aButtonSize. + * @param imageSize New value of property m_aButtonSize. + */ + public void setButtonSize(Size imageSize) + { + this.m_aButtonSize = imageSize; + } + + public void disposing(EventObject arg0) + { + } + + public void create(UnoDialog2 dialog) + { + oUnoDialog = dialog; + + int imageTextHeight = imageTextLines * LINE_HEIGHT; + + int nXPos = pos.Width + 1; + int nYPos = pos.Height + (m_aButtonSize.Height + gap.Height) * rows + gap.Height; + int nWidth = cols * (m_aButtonSize.Width + gap.Width) + gap.Width - 2; + + lblImageText = dialog.insertLabel(m_aControlName + "_imageText", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, + PropertyNames.PROPERTY_LABEL, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + "Tabstop", + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Integer.valueOf(imageTextHeight), + PropertyNames.EMPTY_STRING, + "(1)", + Integer.valueOf(nXPos), + Integer.valueOf(nYPos), + step, + Short.valueOf((short) 0), + Boolean.FALSE, + Integer.valueOf(nWidth) + }); + + + if (showButtons) + { + final String[] pNames1 = new String[] + { + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + "Tabstop", + PropertyNames.PROPERTY_WIDTH + }; + + final Integer btnSize = Integer.valueOf(14); + +// TODO: if list of strings not the same length of list object, office will die. + btnBack = dialog.insertButton(m_aControlName + "_btnBack", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + prevPage(); + } + }, pNames1, new Object[] + { + btnSize, + HelpIds.getHelpIdString(helpURL++), + Integer.valueOf(pos.Width), + Integer.valueOf(pos.Height + (m_aButtonSize.Height + gap.Height) * rows + gap.Height + imageTextHeight + 1), + step, + Short.valueOf((short) (tabIndex + 1)), + Boolean.TRUE, + btnSize + }); + + btnNext = dialog.insertButton(m_aControlName + "_btnNext", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + nextPage(); + } + }, pNames1, new Object[] + { + btnSize, + HelpIds.getHelpIdString(helpURL++), + Integer.valueOf(pos.Width + (m_aButtonSize.Width + gap.Width) * cols + gap.Width - btnSize.intValue() + 1), + Integer.valueOf(pos.Height + (m_aButtonSize.Height + gap.Height) * rows + gap.Height + imageTextHeight + 1), + step, + Short.valueOf((short) (tabIndex + 2)), + Boolean.TRUE, + btnSize + }); + + lblCounter = dialog.insertLabel(m_aControlName + "_lblCounter", pNames1, new Object[] + { + Integer.valueOf(LINE_HEIGHT), + PropertyNames.EMPTY_STRING, + Integer.valueOf(pos.Width + btnSize.intValue() + 1), + Integer.valueOf(pos.Height + (m_aButtonSize.Height + gap.Height) * rows + gap.Height + imageTextHeight + ((btnSize.intValue() - LINE_HEIGHT) / 2)), + step, + Short.valueOf((short) 0), + Boolean.FALSE, + Integer.valueOf(cols * (m_aButtonSize.Width + gap.Width) + gap.Width - 2 * btnSize.intValue() - 1) + }); + + Helper.setUnoPropertyValue(getModel(lblCounter), PropertyNames.PROPERTY_ALIGN, Short.valueOf((short) 1)); + Helper.setUnoPropertyValue(getModel(btnBack), PropertyNames.PROPERTY_LABEL, "<"); + Helper.setUnoPropertyValue(getModel(btnNext), PropertyNames.PROPERTY_LABEL, ">"); + + + } + + m_tabIndex = Short.valueOf((short) tabIndex); + + m_aButtons = new XControl[rows * cols]; + + m_aButtonHeight = Integer.valueOf(m_aButtonSize.Height); + m_aButtonWidth = Integer.valueOf(m_aButtonSize.Width); + + for (int r = 0; r < rows; r++) + { + for (int c = 0; c < cols; c++) + { + XButton aButton = createButton(dialog, r, c); + XControl aControl = UnoRuntime.queryInterface(XControl.class, aButton); + m_aButtons[r * cols + c] = aControl; + } + } + refreshImages(); + } + + private Integer m_aButtonHeight; + private Integer m_aButtonWidth; + private Short m_tabIndex; + + private XButton createButton(UnoDialog2 dialog, int _row, int _col) + { + String sButtonName = m_aControlName + "_button" + (_row * cols + _col); + int nButtonX = getButtonPosX(_col); + int nButtonY = getButtonPosY(_row); + XButton aButton = dialog.insertImageButton(sButtonName, this, + new String[] + { + /* PropertyNames.PROPERTY_BORDER, */ + /* "BackgroundColor", */ + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, + /* PropertyNames.PROPERTY_LABEL, */ + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + /* "ScaleImage", */ + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + "Tabstop", + "Toggle", + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + /* Short.valueOf((short) 1), */ /* NO_BORDER, */ + /* BACKGROUND_COLOR, */ + m_aButtonHeight, + HelpIds.getHelpIdString(helpURL++), + /* "Test", */ + Integer.valueOf(nButtonX), + Integer.valueOf(nButtonY), + /* scaleImages, */ + step, + m_tabIndex, + Boolean.TRUE, + Boolean.TRUE, /* Toggle */ + m_aButtonWidth + }); + + XWindow win = UnoRuntime.queryInterface(XWindow.class, aButton); + win.setEnable(true); + win.setVisible(true); + return aButton; + } + + private int getButtonPosX(int _col) + { + return pos.Width + _col * (m_aButtonSize.Width + gap.Width) + gap.Width; + } + + private int getButtonPosY(int _row) + { + return pos.Height + _row * (m_aButtonSize.Height + gap.Height) + gap.Height; + } + + private void refreshImages() + { + if (showButtons) + { + refreshCounterText(); + } + if (refreshOverNull) + { + for (int i = 0; i < m_aButtons.length; i++) + { + setVisible(m_aButtons[i], false); + } + } + for (int i = 0; i < m_aButtons.length; i++) + { + String oResource = getObjectFor(i); + if (oResource == null) + continue; + oUnoDialog.getPeerConfiguration().setImageUrl(m_aButtons[i].getModel(), oResource); + boolean bTabStop = Boolean.TRUE; // focusable ? Boolean.TRUE : Boolean.FALSE; + Helper.setUnoPropertyValue(m_aButtons[i].getModel(), "Tabstop", bTabStop); + if (refreshOverNull) + { + setVisible(m_aButtons[i], true); + } + } + } + + private void refreshCounterText() + { + Helper.setUnoPropertyValue(getModel(lblCounter), PropertyNames.PROPERTY_LABEL, counterRenderer.render(new Counter(pageStart + 1, pageEnd(), listModel.getSize()))); + } + + private int pageEnd() + { + int i = pageStart + cols * rows; + if (i > listModel.getSize() - 1) + { + return listModel.getSize(); + } + else + { + return i; + } + } + + /** Utility field holding list of ItemListeners. */ + private transient java.util.ArrayList<XItemListener> m_aItemListenerList; + private void setVisible(Object control, boolean visible) + { + final XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, control); + xWindow.setVisible(visible); + } + + /** + * @param i + * @return the String in the list model corresponding to the given image url + */ + private String getObjectFor(int i) + { + int ii = getIndexFor(i); + if (listModel.getSize() <= ii) + { + return null; + } + else + { + return (String)listModel.getElementAt(ii); + } + } + + /** + * @param i + * @return the index in the listModel for the given image index. + */ + private int getIndexFor(int i) + { + return pageStart + i; + } + + /** Registers ItemListener to receive events. + * @param listener The listener to register. + */ + public synchronized void addItemListener(XItemListener listener) + { + if (m_aItemListenerList == null) + { + m_aItemListenerList = new java.util.ArrayList<XItemListener>(); + } + m_aItemListenerList.add(listener); + } + + /** Removes ItemListener from the list of listeners. + * @param listener The listener to remove. + */ + public synchronized void removeItemListener(XItemListener listener) + { + if (m_aItemListenerList != null) + { + m_aItemListenerList.remove(listener); + } + } + + /** Notifies all registered listeners about the event. + * + */ + private void fireItemSelected() + { + java.util.ArrayList<XItemListener> list; + synchronized(this) + { + if (m_aItemListenerList == null) + { + return; + } + list = (java.util.ArrayList<XItemListener>) m_aItemListenerList.clone(); + } + for (int i = 0; i < list.size(); i++) + { + list.get(i).itemStateChanged(null); + } + } + + private ListModel getListModel() + { + return listModel; + } + + public int getSelected() + { + return m_nCurrentSelection; + } + + public void setCols(int i) + { + cols = i; + } + + public void setGap(Size size) + { + gap = size; + } + + public void setListModel(ListModel model) + { + listModel = model; + } + + public void setStep(Short short1) + { + step = short1; + } + + private void setPageStart(int i) + { + if (i == pageStart) + { + return; + } + pageStart = i; + enableButtons(); + refreshImages(); + } + + public void setPos(Size _size) + { + pos = _size; + } + + public void setRenderer(IRenderer _renderer) + { + this.renderer = _renderer; + } + + public void setRows(int i) + { + rows = i; + } + + public void setSelected(int i) + { + if (rowSelect && (i >= 0)) + { + i = (i / cols) * cols; + } + if (m_nCurrentSelection == i) + { + return; + } + m_nCurrentSelection = i; + refreshImageText(); + refreshSelection(); + fireItemSelected(); + } + + /** + * set the text under the button list + */ + private void refreshImageText() + { + String sText; + Object item = m_nCurrentSelection >= 0 ? getListModel().getElementAt(m_nCurrentSelection) : null; + if (item != null) { + sText = PropertyNames.SPACE + renderer.render(item); + } + else { + sText = ""; + } + Helper.setUnoPropertyValue(getModel(lblImageText), PropertyNames.PROPERTY_LABEL, sText); + } + + public void setShowButtons(boolean b) + { + showButtons = b; + } + + private void nextPage() + { + if (pageStart < getListModel().getSize() - rows * cols) + { + setPageStart(pageStart + rows * cols); + } + } + + private void prevPage() + { + if (pageStart == 0) + { + return; + } + int i = pageStart - rows * cols; + if (i < 0) + { + i = 0; + } + setPageStart(i); + } + + private void enableButtons() + { + enable(btnNext, Boolean.valueOf(pageStart + rows * cols < listModel.getSize())); + enable(btnBack, Boolean.valueOf(pageStart > 0)); + } + + private void enable(Object control, Boolean enable) + { + Helper.setUnoPropertyValue(getModel(control), PropertyNames.PROPERTY_ENABLED, enable); + } + + private Object getModel(Object control) + { + return UnoRuntime.queryInterface(XControl.class, control).getModel(); + } + + private static class SimpleCounterRenderer implements IRenderer + { + + public String render(Object counter) + { + return PropertyNames.EMPTY_STRING + ((Counter) counter).start + ".." + ((Counter) counter).end + "/" + ((Counter) counter).max; + } + } + + private static class Counter + { + + private int start, end, max; + + private Counter(int start_, int end_, int max_) + { + start = start_; + end = end_; + max = max_; + } + } + + public boolean isenabled() + { + return benabled; + } + + public void setenabled(boolean b) + { + + for (int i = 0; i < m_aButtons.length; i++) + { + UnoDialog2.setEnabled(m_aButtons[i], b); + } + UnoDialog2.setEnabled(lblImageText, b); + if (showButtons) + { + UnoDialog2.setEnabled(btnBack, b); + UnoDialog2.setEnabled(btnNext, b); + UnoDialog2.setEnabled(lblCounter, b); + } + benabled = b; + } + + /** + * refresh on all buttons, the selected button will get state pressed + */ + private void refreshSelection() + { + // reset all buttons to not set + for (int i = 0; i < m_aButtons.length; i++) + { + if (m_aButtons[i] != null) + { + XControlModel xModel = (XControlModel)UnoDialog2.getModel(m_aButtons[i]); + PropertySetHelper aHelper = new PropertySetHelper(xModel); + if (i == m_nCurrentSelection) + { + final short one = 1; + aHelper.setPropertyValueDontThrow(PropertyNames.PROPERTY_STATE, Short.valueOf(one)); + } + else + { + final short zero = 0; + aHelper.setPropertyValueDontThrow(PropertyNames.PROPERTY_STATE, Short.valueOf(zero)); + } + } + } + } + + /** + * implementation of XActionListener + * will call if a button from the m_aButtonList is pressed. + */ + public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) + { + XControlModel xModel = (XControlModel)UnoDialog2.getModel(actionEvent.Source); + PropertySetHelper aHelper = new PropertySetHelper(xModel); + + int nState = aHelper.getPropertyValueAsInteger(PropertyNames.PROPERTY_STATE, -1); + if (nState == 0) + { + // this will avoid a wrong state, if already pressed. + aHelper.setPropertyValueDontThrow(PropertyNames.PROPERTY_STATE, Short.valueOf((short)1)); + } + + // check which Button is pressed. + String sControlName = aHelper.getPropertyValueAsString(PropertyNames.PROPERTY_NAME, PropertyNames.EMPTY_STRING); + final String sButton = sControlName.substring(7 + m_aControlName.length()); + int nButton = Integer.parseInt(sButton); + + int index = getIndexFor(nButton); + if (index < listModel.getSize()) + { + setSelected(index); + } + + } + + +} diff --git a/wizards/com/sun/star/wizards/ui/CommandFieldSelection.java b/wizards/com/sun/star/wizards/ui/CommandFieldSelection.java new file mode 100644 index 000000000..8cd37ee0a --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/CommandFieldSelection.java @@ -0,0 +1,428 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import com.sun.star.wizards.common.*; +import com.sun.star.wizards.db.*; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.sdb.CommandType; +import com.sun.star.uno.AnyConverter; +import com.sun.star.awt.*; +import com.sun.star.beans.PropertyValue; + +import java.text.Collator; +import java.util.Comparator; + +public class CommandFieldSelection extends FieldSelection implements Comparator<String> +{ + + private CommandMetaData CurDBMetaData; + private XListBox xTableListBox; + private XFixedText xlblTable; + private String sTableListBoxName; + private String sQueryPrefix; + private String sTablePrefix; + private short m_iSelPos = -1; + private short iOldSelPos = -1; + private boolean bgetQueries; + private final WizardDialog oWizardDialog; + private Collator aCollator = null; + + private class ItemListenerImpl implements com.sun.star.awt.XItemListener + { + + public void itemStateChanged(com.sun.star.awt.ItemEvent EventObject) + { + short[] SelItems = (short[]) CurUnoDialog.getControlProperty(sTableListBoxName, PropertyNames.SELECTED_ITEMS); + if (SelItems.length > 0) + { + iOldSelPos = m_iSelPos; + m_iSelPos = SelItems[0]; + if ((m_iSelPos > -1) && (m_iSelPos != iOldSelPos)) + { + if (!AppendMode) + { + oWizardDialog.enablefromStep(IStep.intValue() + 1, false); + } + fillUpFieldsListbox(); + } + } + } + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + } + } + + /** + * instantiates a CommandFieldSelection with a preselected command + */ + public CommandFieldSelection(WizardDialog _CurUnoDialog, CommandMetaData _CurDBMetaData, int iStep, int _iHeight, String _reslblFields, String _reslblSelFields, String _reslblTables, boolean _bgetQueries, int _ifirstHID) + { + super(_CurUnoDialog, iStep, 95, 57, 210, _iHeight, _reslblFields, _reslblSelFields, (_ifirstHID + 1), true); + insertControls(_CurDBMetaData, _bgetQueries, _reslblTables); + oWizardDialog = (WizardDialog) CurUnoDialog; + } + + /** + * instantiates a CommandFieldSelection with a preselected command + */ + public CommandFieldSelection(UnoDialog _CurUnoDialog, CommandMetaData _CurDBMetaData, int _iHeight, String _reslblFields, String _reslblSelFields, String _reslblTables, boolean _bgetQueries, int _ifirstHID) + { + super(_CurUnoDialog, 1, 95, 57, 210, _iHeight, _reslblFields, _reslblSelFields, (_ifirstHID + 1), true); + insertControls(_CurDBMetaData, _bgetQueries, _reslblTables); + oWizardDialog = (WizardDialog) CurUnoDialog; + } + + private void insertControls(CommandMetaData _CurDBMetaData, boolean _bgetQueries, String _reslblTables) + { + try + { + this.AppendMode = !_bgetQueries; + this.bgetQueries = _bgetQueries; + this.CurDBMetaData = _CurDBMetaData; + toggleListboxControls(Boolean.FALSE); + String sTableLabelName = "lblTables_" + super.sIncSuffix; + sTableListBoxName = "lstTables_" + super.sIncSuffix; + sTablePrefix = getTablePrefix(); + sQueryPrefix = getQueryPrefix(); + Integer LabelWidth = Integer.valueOf(getListboxWidth().intValue() + 6); + // Label 'Tables or Queries' + xlblTable = CurUnoDialog.insertLabel(sTableLabelName, + new String[] + { + 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 + }, + new Object[] + { + Boolean.FALSE, 8, _reslblTables, 95, 27, IStep, Short.valueOf((short) 3), LabelWidth + }); + // DropDown Listbox TableNames + xTableListBox = CurUnoDialog.insertListBox(sTableListBoxName, 0, null, new ItemListenerImpl(), + new String[] + { + "Dropdown", PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.TRUE, Boolean.FALSE, 12, HelpIds.getHelpIdString(super.FirstHelpIndex - 1), Short.valueOf(UnoDialog.getListBoxLineCount()), 95, 37, IStep, Short.valueOf((short) 4), getListboxWidth() + }); + fillupCommandListBox(); + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + /** + * @return Returns the sQueryPrefix. + */ + private String getQueryPrefix() + { + if (sQueryPrefix == null) + { + sQueryPrefix = CurUnoDialog.m_oResource.getResText("RID_QUERY_22"); + } + return sQueryPrefix; + } + + private String getCommandPrefix(int _nCommandType) + { + if (_nCommandType == CommandType.TABLE) + { + return getTablePrefix(); + } + else if (_nCommandType == CommandType.QUERY) + { + return getQueryPrefix(); + } + else + { + return PropertyNames.EMPTY_STRING; + } + } + + /** + * @return Returns the sTablePrefix. + */ + private String getTablePrefix() + { + if (sTablePrefix == null) + { + sTablePrefix = CurUnoDialog.m_oResource.getResText("RID_QUERY_21"); + } + return sTablePrefix; + } + + private short getselectedItemPos() + { + short[] iSelPoses = ((short[]) Helper.getUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.SELECTED_ITEMS)); + if (iSelPoses.length > 0) + { + return iSelPoses[0]; + } + else + { + String[] sItemList = ((String[]) Helper.getUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.STRING_ITEM_LIST)); + if (sItemList.length > 0) + { + return (short) 0; + } + return (short) -1; + } + } + + private void fillUpFieldsListbox() + { + try + { + boolean binitialize = false; + String curCommandName = PropertyNames.EMPTY_STRING; + //As the peer of the control might not yet exist we have to query the model for the SelectedItems + short iSelPos = getselectedItemPos(); + final String sSelectedTableName = xTableListBox.getItem(iSelPos); + if (!bgetQueries) + { + curCommandName = sSelectedTableName; // sLocList[iSelPos]; + CurDBMetaData.setTableByName(curCommandName); + binitialize = CurDBMetaData.getFieldNamesOfCommand(curCommandName, CommandType.TABLE); + } + else + { + if (sSelectedTableName.startsWith(sTablePrefix)) + { + CurDBMetaData.setCommandType(CommandType.TABLE); + curCommandName = JavaTools.replaceSubString(sSelectedTableName, PropertyNames.EMPTY_STRING, sTablePrefix); + CurDBMetaData.setTableByName(curCommandName); + binitialize = CurDBMetaData.getFieldNamesOfCommand(curCommandName, CommandType.TABLE); + } + else + { + CurDBMetaData.setCommandType(CommandType.QUERY); + curCommandName = JavaTools.replaceSubString(sSelectedTableName, PropertyNames.EMPTY_STRING, sQueryPrefix); + CurDBMetaData.setQueryByName(curCommandName); + binitialize = CurDBMetaData.getFieldNamesOfCommand(curCommandName, CommandType.QUERY); + } + } + if (binitialize) + { + CurDBMetaData.setCommandName(curCommandName); + if (CurDBMetaData.m_aAllFieldNames != null) + { + if (CurDBMetaData.m_aAllFieldNames.length > 0) + { + initialize(CurDBMetaData.m_aAllFieldNames, AppendMode, CurDBMetaData.getMaxColumnsInSelect()); + return; + } + } + } + emptyFieldsListBoxes(); + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + /** returns the selected entry index in the commandListbox + * + * @return + * @throws com.sun.star.wizards.common.TerminateWizardException + */ + private short fillupCommandListBox() + { + short[] iSelArray = new short[0]; + boolean bgetFields = false; + String[] ContentList = new String[0]; + if (bgetQueries) + { + ContentList = new String[CurDBMetaData.getTableNames().length + CurDBMetaData.getQueryNames().length]; + System.arraycopy(CurDBMetaData.getQueryNames(), 0, ContentList, CurDBMetaData.getTableNames().length, CurDBMetaData.getQueryNames().length); + ContentList = setPrefixinArray(ContentList, sQueryPrefix, CurDBMetaData.getTableNames().length, CurDBMetaData.getQueryNames().length); + } + else + { + ContentList = new String[CurDBMetaData.getTableNames().length]; + } + System.arraycopy(CurDBMetaData.getTableNames(), 0, ContentList, 0, CurDBMetaData.getTableNames().length); + if (bgetQueries) + { + ContentList = setPrefixinArray(ContentList, sTablePrefix, 0, CurDBMetaData.getTableNames().length); + } + java.util.Arrays.sort(ContentList, this); + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.STRING_ITEM_LIST, ContentList); + short iSelPos = getselectedItemPos(); + if (iSelPos > -1) + { + bgetFields = true; + iSelArray = new short[] + { + iSelPos + }; + } + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.SELECTED_ITEMS, iSelArray); + toggleCommandListBox(true); + if (bgetFields) + { + fillUpFieldsListbox(); + } + return iSelPos; + } + + private Collator getCollator() + { + if (this.aCollator == null) + { + com.sun.star.lang.Locale aOfficeLocale = Configuration.getLocale(this.CurDBMetaData.xMSF); + java.util.Locale aJavaLocale = new java.util.Locale(aOfficeLocale.Language, aOfficeLocale.Country, aOfficeLocale.Variant); + //Get the Collator for US English and set its strength to PRIMARY + this.aCollator = Collator.getInstance(aJavaLocale); + aCollator.setStrength(Collator.TERTIARY); + } + return aCollator; + } + + public int compare(String _oObject1, String _oObject2) + { + return this.getCollator().compare(_oObject1, _oObject2); + } + + private String[] setPrefixinArray(String[] _ContentList, String _sprefix, int _startindex, int _nlen) + { + for (int i = _startindex; i < _startindex + _nlen; i++) + { + _ContentList[i] = _sprefix + _ContentList[i]; + } + return _ContentList; + } + + public void toggleCommandListBox(String[] _NewItems) + { + boolean bdoenable = QueryMetaData.getIncludedCommandNames(_NewItems).length < CurDBMetaData.getMaxTablesInSelect(); + toggleCommandListBox(bdoenable); + } + + private void toggleCommandListBox(boolean _bdoenable) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bdoenable)); + Helper.setUnoPropertyValue(UnoDialog.getModel(xlblTable), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bdoenable)); + } + + public String getSelectedCommandName() + { + String sCommandname = xTableListBox.getSelectedItem(); + if (sCommandname.startsWith(this.sTablePrefix)) + { + return sCommandname.substring(sTablePrefix.length()); + } + else if (sCommandname.startsWith(this.sQueryPrefix)) + { + return sCommandname.substring(sQueryPrefix.length()); + } + else + { + return sCommandname; + } + } + + public int getSelectedCommandType() + { + String sCommandname = xTableListBox.getSelectedItem(); + if (sCommandname.startsWith(this.sTablePrefix)) + { + return CommandType.TABLE; + } + else + { + return CommandType.QUERY; + } + } + + public void preselectCommand(PropertyValue[] _aPropertyValue, boolean _bReadOnly) + { + try + { + if (Properties.hasPropertyValue(_aPropertyValue, PropertyNames.COMMAND_TYPE)) + { + int nCommandType = AnyConverter.toInt(Properties.getPropertyValue(_aPropertyValue, PropertyNames.COMMAND_TYPE)); + String sCommand = AnyConverter.toString(Properties.getPropertyValue(_aPropertyValue, PropertyNames.COMMAND)); + if (sCommand != null) + { + preselectCommand(sCommand, nCommandType, _bReadOnly); + } + } + } + catch (IllegalArgumentException e) + { + e.printStackTrace(); + } + } + + private void preselectCommand(String _selitem, int _nCommandType, boolean _bReadOnly) + { + if (_selitem.length() > 0) + { + String[] sitems = (String[]) Helper.getUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.STRING_ITEM_LIST); + String sPrefix = getCommandPrefix(_nCommandType); + short iselpos = (short) JavaTools.FieldInList(sitems, sPrefix + _selitem); + if (iselpos > -1) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.SELECTED_ITEMS, new short[] + { + iselpos + }); + } + this.fillUpFieldsListbox(); + } + else + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.SELECTED_ITEMS, new short[] + { + }); + } + if (_bReadOnly) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.READ_ONLY, Boolean.valueOf(_selitem.length() > 0)); + } + } + + public void preselectCommand(String _selitem, boolean _bReadOnly) + { + if (_selitem.length() > 0) + { + String[] sitems = (String[]) Helper.getUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.STRING_ITEM_LIST); + short iselpos = (short) JavaTools.FieldInList(sitems, getTablePrefix() + _selitem); + if (iselpos > -1) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.SELECTED_ITEMS, new short[] { iselpos }); + } + this.fillUpFieldsListbox(); + } + else + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.SELECTED_ITEMS, new short[] {} ); + this.fillUpFieldsListbox(); + } + if (_bReadOnly) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xTableListBox), PropertyNames.READ_ONLY, Boolean.valueOf(_selitem.length() > 0)); + } + toggleListboxButtons((short)-1,(short)-1); + } +} diff --git a/wizards/com/sun/star/wizards/ui/ControlScroller.java b/wizards/com/sun/star/wizards/ui/ControlScroller.java new file mode 100644 index 000000000..df5131f7b --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/ControlScroller.java @@ -0,0 +1,425 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import com.sun.star.beans.*; +import com.sun.star.awt.*; +import com.sun.star.wizards.common.*; + +import java.util.*; + +public abstract class ControlScroller +{ + + protected WizardDialog CurUnoDialog; + protected int ncurfieldcount; + private int nblockincrement; + private int nlineincrement; + private int nscrollvalue = 0; + private int ntotfieldcount; + private XScrollBar xScrollBar; + private ArrayList<PropertyValue[]> scrollfields; + protected int iCompPosX; + protected int iCompPosY; + protected int iCompWidth; + protected int iCompHeight; + protected short curtabindex; + protected Integer IStep; + int iScrollBarWidth = 10; + private int SORELFIRSTPOSY = 3; + protected int curHelpIndex; + private String sIncSuffix; + protected ArrayList<Object> ControlGroupVector = new ArrayList<Object>(); + + private class AdjustmentListenerImpl implements com.sun.star.awt.XAdjustmentListener + { + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + } + + public void adjustmentValueChanged(AdjustmentEvent AdjustEvent) + { + scrollControls(); + } + } + + /** + * + * @param _CurUnoDialog + * @param _iStep + * @param _iCompPosX + * @param _iCompPosY + * @param _iCompWidth + * @param _nblockincrement + * @param _firsthelpindex + */ + // TODO add parameters for tabindices and helpindex + protected ControlScroller(WizardDialog _CurUnoDialog, int _iStep, int _iCompPosX, int _iCompPosY, int _iCompWidth, int _nblockincrement, int _nlinedistance, int _firsthelpindex) + { + this.nblockincrement = _nblockincrement; + this.CurUnoDialog = _CurUnoDialog; + this.curHelpIndex = _firsthelpindex; + curtabindex = UnoDialog.setInitialTabindex(_iStep); + IStep = Integer.valueOf(_iStep); + this.iCompPosX = _iCompPosX; + this.iCompPosY = _iCompPosY; + this.iCompWidth = _iCompWidth; + this.iCompHeight = 2 * SORELFIRSTPOSY + nblockincrement * _nlinedistance; + int iStartPosY = iCompPosY + SORELFIRSTPOSY; + int ScrollHeight = iCompHeight - 2; + nlineincrement = 1; + sIncSuffix = com.sun.star.wizards.common.Desktop.getIncrementSuffix(CurUnoDialog.getDlgNameAccess(), "TitleScrollBar"); + xScrollBar = CurUnoDialog.insertScrollBar("TitleScrollBar" + sIncSuffix, 0, + new AdjustmentListenerImpl(), + new String[] + { + PropertyNames.PROPERTY_BORDER, PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.ORIENTATION, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Short.valueOf((short) 0), Boolean.TRUE, Integer.valueOf(ScrollHeight), HelpIds.getHelpIdString(curHelpIndex), Integer.valueOf(ScrollBarOrientation.VERTICAL), Integer.valueOf(iCompPosX + iCompWidth - iScrollBarWidth - 1), Integer.valueOf(iCompPosY + 1), IStep, Integer.valueOf(iScrollBarWidth) + }); + scrollfields = new ArrayList<PropertyValue[]>(); + int ypos = iStartPosY + SORELFIRSTPOSY; + for (int i = 0; i < nblockincrement; i++) + { + insertControlGroup(i, ypos); + ypos += _nlinedistance; + } + } + + + + /** + * @param _ntotfieldcount The number of fields that are to be administered by the ControlScroller + */ + protected void initialize(int _ntotfieldcount) + { + try + { + ntotfieldcount = _ntotfieldcount; + setCurFieldCount(); + nscrollvalue = 0; + Helper.setUnoPropertyValue(UnoDialog.getModel(xScrollBar), "ScrollValue", Integer.valueOf(nscrollvalue)); + if (ntotfieldcount > nblockincrement) + { + Helper.setUnoPropertyValues(UnoDialog.getModel(xScrollBar), new String[] + { + PropertyNames.PROPERTY_ENABLED, "BlockIncrement", "LineIncrement", "ScrollValue", "ScrollValueMax" + }, new Object[] + { + Boolean.TRUE, Integer.valueOf(nblockincrement), Integer.valueOf(nlineincrement), Integer.valueOf(nscrollvalue), Integer.valueOf(ntotfieldcount - nblockincrement) + }); + } + else + { + Helper.setUnoPropertyValues(UnoDialog.getModel(xScrollBar), new String[] + { + PropertyNames.PROPERTY_ENABLED, "ScrollValue" + }, new Object[] + { + Boolean.FALSE, Integer.valueOf(nscrollvalue) + }); + } + fillupControls(true); + } + catch (java.lang.Exception ex) + { + ex.printStackTrace(); + } + } + + private void fillupControls(boolean binitialize) + { + for (int a = 0; a < this.nblockincrement; a++) + { + if (a < ncurfieldcount) + { + fillupControls(a); + } + if (binitialize) + { + setControlGroupVisible(a, (a < this.ncurfieldcount)); + } + } + if (binitialize) + { + CurUnoDialog.repaintDialogStep(); + } + } + + private void fillupControls(int guiRow) + { + PropertyValue[] nameProps = scrollfields.get(guiRow); + PropertyValue[] valueProps = scrollfields.get(guiRow + nscrollvalue); + for (int n = 0; n < nameProps.length; n++) + { + if (CurUnoDialog.getDlgNameAccess().hasByName(nameProps[n].Name)) + { + setControlData(nameProps[n].Name, valueProps[n].Value); + } + else + { + throw new IllegalArgumentException("No such control !"); + } + } + } + + private void setScrollValue(int _nscrollvalue) + { + if (_nscrollvalue >= 0) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xScrollBar), "ScrollValue", Integer.valueOf(_nscrollvalue)); + scrollControls(); + } + } + + protected void setScrollValue(int _nscrollvalue, int _ntotfieldcount) + { + setTotalFieldCount(_ntotfieldcount); + setScrollValue(_nscrollvalue); + } + + protected int getTotalFieldCount() + { + return ntotfieldcount; + } + + protected int getCurFieldCount() + { + return ncurfieldcount; + } + + private void setCurFieldCount() + { + if (ntotfieldcount > nblockincrement) + { + ncurfieldcount = nblockincrement; + } + else + { + ncurfieldcount = ntotfieldcount; + } + } + + protected void setTotalFieldCount(int _ntotfieldcount) + { + this.ntotfieldcount = _ntotfieldcount; + setCurFieldCount(); + if (ntotfieldcount > nblockincrement) + { + Helper.setUnoPropertyValues(UnoDialog.getModel(xScrollBar), new String[] + { + PropertyNames.PROPERTY_ENABLED, "ScrollValueMax" + }, new Object[] + { + Boolean.TRUE, Integer.valueOf(ntotfieldcount - nblockincrement) + }); + } + else + { + Helper.setUnoPropertyValue(UnoDialog.getModel(xScrollBar), PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); + } + } + + protected void toggleComponent(boolean _bdoenable) + { + boolean bdoenable = _bdoenable && (ntotfieldcount > nblockincrement); + CurUnoDialog.setControlProperty("TitleScrollBar" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenable)); + } + + protected void toggleControls(boolean _bdoenable) + { + for (int n = 0; n < scrollfields.size(); n++) + { + PropertyValue[] curproperties = scrollfields.get(n); + for (int m = 0; m < curproperties.length; m++) + { + PropertyValue curproperty = curproperties[m]; + CurUnoDialog.setControlProperty(curproperty.Name, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bdoenable)); + } + } + + } + + protected int getScrollValue() + { + return nscrollvalue; + } + + + + + + + + protected int getBlockIncrementation() + { + return nblockincrement; + } + + private void scrollControls() + { + try + { + scrollRowsInfo(); + nscrollvalue = ((Integer) Helper.getUnoPropertyValue(UnoDialog.getModel(xScrollBar), "ScrollValue")).intValue(); + if (nscrollvalue + nblockincrement >= ntotfieldcount) + { + nscrollvalue = (ntotfieldcount) - nblockincrement; + } + fillupControls(false); + } + catch (java.lang.Exception ex) + { + ex.printStackTrace(); + } + } + + private void scrollRowsInfo() + { + int cols = + scrollfields.size() > 0 + ? scrollfields.get(0).length + : 0; + for (int a = 0; a < ncurfieldcount; a++) + { + for (int n = 0; n < cols; n++) + { + fieldInfo(a, n); + } + } + } + + /** + * updates the corresponding data to + * the control in guiRow and column + * @param guiRow 0 based row index + * @param column 0 based column index + * @return the propertyValue object corresponding to + * this control. + */ + private PropertyValue fieldInfo(int guiRow, int column) + { + if (guiRow + nscrollvalue < scrollfields.size()) + { + return fieldInfo( + scrollfields.get(guiRow + nscrollvalue)[column], + scrollfields.get(guiRow)[column]); + } + else + { + return null; + } + } + + private PropertyValue fieldInfo(PropertyValue valueProp, PropertyValue nameProp) + { + if (CurUnoDialog.getDlgNameAccess().hasByName(nameProp.Name)) + { + valueProp.Value = getControlData(nameProp.Name); + } + else + { + valueProp.Value = nameProp.Value; + } + return valueProp; + } + + protected void unregisterControlGroup(int _index) + { + scrollfields.remove(_index); + } + + protected void registerControlGroup(PropertyValue[] _currowproperties, int _i) + { + if (_i == 0) + { + scrollfields.clear(); + } + if (_i >= scrollfields.size()) + { + scrollfields.add(_currowproperties); + } + else + { + scrollfields.set(_i, _currowproperties); + } + } + + + + private void setControlData(String controlname, Object newvalue) + { + Object oControlModel = UnoDialog.getModel(CurUnoDialog.xDlgContainer.getControl(controlname)); + String propertyname = UnoDialog.getDisplayProperty(oControlModel); + if (!propertyname.equals(PropertyNames.EMPTY_STRING)) + { + CurUnoDialog.setControlProperty(controlname, propertyname, newvalue); + } + } + + private Object getControlData(String controlname) + { + Object oControlModel = UnoDialog.getModel(CurUnoDialog.xDlgContainer.getControl(controlname)); + String propertyname = UnoDialog.getDisplayProperty(oControlModel); + if (!propertyname.equals(PropertyNames.EMPTY_STRING)) + { + return CurUnoDialog.getControlProperty(controlname, propertyname); + } + else + { + return null; + } + } + + protected PropertyValue[][] getScrollFieldValues() + { + scrollRowsInfo(); + PropertyValue[] curproperties; + PropertyValue[][] retproperties; + retproperties = new PropertyValue[scrollfields.size()][]; + try + { + for (int i = 0; i < scrollfields.size(); i++) + { + curproperties = scrollfields.get(i); + retproperties[i] = curproperties; + } + return retproperties; + } + catch (java.lang.Exception ex) + { + ex.printStackTrace(System.err); + return null; + } + } + + protected abstract void initializeScrollFields(); + + /** inserts a group of controls into the component. The group may either be a row or a column of controls + * The controls should be put on Step 99 (means made invisible at first). All the controlrows that are needed are than + * made visible automatically when calling "initialize(_fieldcount)" + * @param _index The index of the control group + * @param npos Can be an x coordinate or an y coordinate which depends on the orientation of the scrollbar + */ + protected abstract void insertControlGroup(int _index, int npos); + + protected abstract void setControlGroupVisible(int _index, boolean _bIsVisible); +} diff --git a/wizards/com/sun/star/wizards/ui/ControlScroller.py b/wizards/com/sun/star/wizards/ui/ControlScroller.py new file mode 100644 index 000000000..02eb86500 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/ControlScroller.py @@ -0,0 +1,176 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import traceback +from .UnoDialog import UnoDialog +from ..common.Desktop import Desktop +from ..common.PropertyNames import PropertyNames +from ..common.HelpIds import HelpIds + +from com.sun.star.awt.ScrollBarOrientation import VERTICAL + +class ControlScroller(object): + + SORELFIRSTPOSY = 3 + iScrollBarWidth = 10 + + # TODO add parameters for tabindices and helpindex + def __init__(self, _CurUnoDialog, _xMSF, _iStep, _iCompPosX, _iCompPosY, + _iCompWidth, _nblockincrement, _nlinedistance, _firsthelpindex): + self.xMSF = _xMSF + self.scrollfields = [] + self.ControlGroupVector = [] + ControlScroller.nblockincrement = _nblockincrement + self.CurUnoDialog = _CurUnoDialog + self.iStep = _iStep + self.curHelpIndex = _firsthelpindex + self.curtabindex = self.iStep * 100 + self.linedistance = _nlinedistance + self.iCompPosX = _iCompPosX + self.iCompPosY = _iCompPosY + self.iCompWidth = _iCompWidth + self.iCompHeight = 2 * ControlScroller.SORELFIRSTPOSY + \ + ControlScroller.nblockincrement * self.linedistance + self.iStartPosY = self.iCompPosY + ControlScroller.SORELFIRSTPOSY + ScrollHeight = self.iCompHeight - 2 + self.nlineincrement = 1 + self.sincSuffix = Desktop.getIncrementSuffix( + self.CurUnoDialog.xDialogModel, "imgBackground") + + self.xScrollBar = self.CurUnoDialog.insertScrollBar( + "TitleScrollBar" + self.sincSuffix, + ("Border", PropertyNames.PROPERTY_ENABLED, + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, "Orientation", + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_WIDTH), + (0, True, ScrollHeight, + HelpIds.getHelpIdString(self.curHelpIndex), + VERTICAL, self.iCompPosX + self.iCompWidth - \ + ControlScroller.iScrollBarWidth - 1, + self.iCompPosY + 1, self.iStep, + ControlScroller.iScrollBarWidth), 0, self) + self.nscrollvalue = 0 + ypos = self.iStartPosY + ControlScroller.SORELFIRSTPOSY + for i in range(ControlScroller.nblockincrement): + self.insertControlGroup(i, ypos) + ypos += self.linedistance + + def fillupControls(self, binitialize): + for i in range(ControlScroller.nblockincrement): + if i < self.ncurfieldcount: + self.fillupControl(i) + + if binitialize: + self.CurUnoDialog.repaintDialogStep() + + + def fillupControl(self, guiRow): + nameProps = self.scrollfields[guiRow] + valueProps = self.scrollfields[guiRow + self.nscrollvalue] + for index, item in enumerate(nameProps): + if self.CurUnoDialog.xDialogModel.hasByName(item.Name): + self.setControlData(item.Name, valueProps[index].Value) + else: + raise AttributeError("No such control !") + self.ControlGroupVector[guiRow].setEnabled(True) + + def setScrollValue(self, _nscrollvalue, _ntotfieldcount=None): + if _ntotfieldcount is not None: + self.setTotalFieldCount(_ntotfieldcount) + if _nscrollvalue >= 0: + self.xScrollBar.Model.ScrollValue = _nscrollvalue + self.scrollControls() + + def setCurFieldCount(self): + if self.ntotfieldcount > ControlScroller.nblockincrement: + self.ncurfieldcount = ControlScroller.nblockincrement + else: + self.ncurfieldcount = self.ntotfieldcount + + def setTotalFieldCount(self, _ntotfieldcount): + self.ntotfieldcount = _ntotfieldcount + self.setCurFieldCount() + if self.ntotfieldcount > ControlScroller.nblockincrement: + self.xScrollBar.Model.Enabled = True + self.xScrollBar.Model.ScrollValueMax = \ + self.ntotfieldcount - ControlScroller.nblockincrement + else: + self.xScrollBar.Model.Enabled = False + + def scrollControls(self): + try: + self.nscrollvalue = \ + int(self.xScrollBar.Model.ScrollValue) + if self.nscrollvalue + ControlScroller.nblockincrement \ + >= self.ntotfieldcount: + self.nscrollvalue = \ + self.ntotfieldcount - ControlScroller.nblockincrement + self.fillupControls(False) + except Exception: + traceback.print_exc() + + ''' + updates the corresponding data to + the control in guiRow and column + @param guiRow 0 based row index + @param column 0 based column index + @return the propertyValue object corresponding to + this control. + ''' + + def fieldInfo(self, guiRow, column): + if guiRow + self.nscrollvalue < len(self.scrollfields): + valueProp = (self.scrollfields[guiRow + self.nscrollvalue])[column] + nameProp = (self.scrollfields[guiRow])[column] + if self.CurUnoDialog.xDialogModel.hasByName(nameProp.Name): + valueProp.Value = self.getControlData(nameProp.Name) + else: + valueProp.Value = nameProp.Value + return valueProp + else: + return None + + def unregisterControlGroup(self, _index): + del self.scrollfields[_index] + + def registerControlGroup(self, _currowproperties, _i): + if _i == 0: + del self.scrollfields[:] + + if _i >= len(self.scrollfields): + self.scrollfields.append(_currowproperties) + else: + self.scrollfields.insert(_currowproperties, _i) + + def setControlData(self, controlname, newvalue): + oControlModel = self.CurUnoDialog.xUnoDialog.getControl( + controlname).Model + propertyname = UnoDialog.getDisplayProperty(oControlModel) + if propertyname: + setattr(oControlModel, propertyname, newvalue) + + def getControlData(self, controlname): + oControlModel = self.CurUnoDialog.xUnoDialog.getControl( + controlname).Model + propertyname = UnoDialog.getDisplayProperty(oControlModel) + if propertyname: + return getattr(oControlModel, propertyname) + else: + return None diff --git a/wizards/com/sun/star/wizards/ui/DBLimitedFieldSelection.java b/wizards/com/sun/star/wizards/ui/DBLimitedFieldSelection.java new file mode 100644 index 000000000..f7c8e942e --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/DBLimitedFieldSelection.java @@ -0,0 +1,120 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import com.sun.star.awt.XListBox; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.common.PropertyNames; + +/** + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public abstract class DBLimitedFieldSelection +{ + + protected WizardDialog CurUnoDialog; + private String sNoField; + protected Integer IStep; + protected static final int rowcount = 4; + private static final int MAXSELINDEX = rowcount - 1; + protected short curtabindex; + protected int iCurPosY; + protected int FirstHelpIndex; + + public DBLimitedFieldSelection(WizardDialog _CurUnoDialog, int iStep, int iCompPosY, int _FirstHelpIndex) + { + this.CurUnoDialog = _CurUnoDialog; + FirstHelpIndex = _FirstHelpIndex; + curtabindex = (short) (iStep * 100); + sNoField = CurUnoDialog.m_oResource.getResText("RID_REPORT_8"); + IStep = Integer.valueOf(iStep); + iCurPosY = iCompPosY; + for (int i = 0; i < rowcount; i++) + { + insertControlGroup(i); + } + } + + protected abstract void insertControlGroup(int index); + + protected abstract void toggleControlRow(int CurIndex, boolean bDoEnable); + + protected abstract void enableNextControlRow(int CurIndex); + + protected abstract void updateFromNextControlRow(int CurIndex); + + + protected abstract int getMaxSelIndex(); + + protected void moveupSelectedItems(int CurIndex, boolean bDoEnable) + { + if ((!bDoEnable) && (MAXSELINDEX > CurIndex)) + { + for (int i = CurIndex; i < MAXSELINDEX; i++) + { + updateFromNextControlRow(i); + } + if (getMaxSelIndex() < rowcount - 2) + { + toggleControlRow(getMaxSelIndex() + 2, false); + } + } + else + { + toggleControlRow(CurIndex + 1, bDoEnable); + } + } + + protected String[] addNoneFieldItemToList(String[] _FieldNames) + { + int FieldCount = _FieldNames.length; + String[] ViewFieldNames = new String[FieldCount + 1]; + ViewFieldNames[0] = sNoField; + System.arraycopy(_FieldNames, 0, ViewFieldNames, 1, FieldCount); + return ViewFieldNames; + } + + protected void initializeListBox(XListBox xListBox, String[] _AllFieldNames, String[] _SelFieldNames, int curindex) + { + short[] SelList = null; + Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.STRING_ITEM_LIST, _AllFieldNames); + if (_SelFieldNames != null && curindex < _SelFieldNames.length) + { + int index = JavaTools.FieldInList(_AllFieldNames, _SelFieldNames[curindex]); + if (index > -1) + { + SelList = new short[] { (short) (index) }; + } + else + { + SelList = new short[] { (short) (0) }; + } + Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.SELECTED_ITEMS, SelList); + return; + } + SelList = new short[] { (short) (0) }; + Helper.setUnoPropertyValue(UnoDialog.getModel(xListBox), PropertyNames.SELECTED_ITEMS, SelList); + + } + + +} + + diff --git a/wizards/com/sun/star/wizards/ui/DocumentPreview.py b/wizards/com/sun/star/wizards/ui/DocumentPreview.py new file mode 100644 index 000000000..280fac6df --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/DocumentPreview.py @@ -0,0 +1,96 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import traceback +from ..common.Properties import Properties + +from com.sun.star.awt import WindowDescriptor +from com.sun.star.awt import Rectangle +from com.sun.star.awt.WindowClass import SIMPLE +from com.sun.star.awt.VclWindowPeerAttribute import CLIPCHILDREN +from com.sun.star.awt.WindowAttribute import SHOW + +''' +To change the template for this generated type comment go to +Window>Preferences>Java>Code Generation>Code and Comments +''' + +class DocumentPreview(object): + PREVIEW_MODE = 1 + + ''' + create new frame with window inside + load a component as preview into this frame + ''' + + def __init__(self, xmsf, control): + self.xControl = control + self.createPreviewFrame(xmsf, self.xControl) + + def setDocument(self, url_, propNames, propValues=None): + if propValues is None: + if propNames == DocumentPreview.PREVIEW_MODE: + self.setDocument(url_, ("Preview", "ReadOnly"), (True, True)) + else: + self.loadArgs = propNames + self.xFrame.activate() + self.xComponent = self.xFrame.loadComponentFromURL(url_, "_self", 0, tuple(self.loadArgs)) + return self.xComponent + else: + self.url = url_ + ps = Properties() + for index,item in enumerate(propNames): + ps[item] = propValues[index] + return self.setDocument(self.url, ps.getProperties1()) + + def closeFrame(self): + if self.xFrame is not None: + self.xFrame.close(False) + + ''' + create a new frame with a new container window inside, + which is not part of the global frame tree. + + Attention: + a) This frame won't be destroyed by the office. It must be closed by you! + Do so - please call XCloseable::close(). + b) The container window is part of the frame. Don't hold it alive - nor try to kill it. + It will be destroyed inside close(). + ''' + + def createPreviewFrame(self, xmsf, xControl): + controlPeer = xControl.Peer + r = xControl.PosSize + toolkit = xmsf.createInstance("com.sun.star.awt.Toolkit") + aDescriptor = WindowDescriptor() + aDescriptor.Type = SIMPLE + aDescriptor.WindowServiceName = "window" + aDescriptor.ParentIndex = -1 + aDescriptor.Parent = controlPeer + #xWindowPeer; #argument ! + aDescriptor.Bounds = Rectangle(0, 0, r.Width, r.Height) + aDescriptor.WindowAttributes = CLIPCHILDREN | SHOW + self.xWindow = toolkit.createWindow(aDescriptor) + self.xFrame = xmsf.createInstance("com.sun.star.frame.Frame") + self.xFrame.initialize(self.xWindow) + self.xWindow.setVisible(True) + + def dispose(self): + try: + self.closeFrame() + except Exception: + traceback.print_exc() diff --git a/wizards/com/sun/star/wizards/ui/FieldSelection.java b/wizards/com/sun/star/wizards/ui/FieldSelection.java new file mode 100644 index 000000000..1f2179f08 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/FieldSelection.java @@ -0,0 +1,640 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import com.sun.star.awt.FontDescriptor; +import com.sun.star.awt.XListBox; +import com.sun.star.wizards.common.*; + +import java.util.*; + +public class FieldSelection +{ + public XListBox xFieldsListBox; // Left ListBox + public XListBox xSelectedFieldsListBox; // right (selected) ListBox + + protected UnoDialog CurUnoDialog; + protected String sIncSuffix; + protected int FirstHelpIndex; + protected boolean AppendMode = false; + protected Integer IStep; + + private int CompPosY; + private int CompHeight; + + private XFieldSelectionListener xFieldSelection; + private int maxfieldcount = 10000000; + private String[] AllFieldNames; + private Integer ListBoxWidth; + + private boolean bisModified = false; + + private static final int SOCMDMOVESEL = 1; + private static final int SOCMDMOVEALL = 2; + private static final int SOCMDREMOVESEL = 3; + private static final int SOCMDREMOVEALL = 4; + private static final int SOCMDMOVEUP = 5; + private static final int SOCMDMOVEDOWN = 6; + private static final int SOFLDSLST = 7; + private static final int SOSELFLDSLST = 8; + + + private class ItemListenerImpl implements com.sun.star.awt.XItemListener + { + + public void itemStateChanged(com.sun.star.awt.ItemEvent EventObject) + { + com.sun.star.wizards.common.Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); + int iKey = CurUnoDialog.getControlKey(EventObject.Source, CurUnoDialog.ControlList); + switch (iKey) + { + case SOFLDSLST: + case SOSELFLDSLST: + toggleListboxButtons((short) - 1, (short) - 1); + break; + + default: + break; + } + com.sun.star.wizards.common.Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); + } + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + } + } + + private class ActionListenerImpl implements com.sun.star.awt.XActionListener + { + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + } + + public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) + { + try + { + int iKey = CurUnoDialog.getControlKey(actionEvent.Source, CurUnoDialog.ControlList); + switch (iKey) + { + case SOCMDMOVESEL: + case SOFLDSLST: + selectFields(false); + break; + + case SOCMDMOVEALL: + selectFields(true); + break; + + case SOCMDREMOVESEL: + case SOSELFLDSLST: + deselectFields(false); + break; + + case SOCMDREMOVEALL: + deselectFields(true); + break; + + case SOCMDMOVEUP: + changeSelectionOrder(-1); + break; + + case SOCMDMOVEDOWN: + changeSelectionOrder(1); + break; + + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + } + + public void addFieldSelectionListener(XFieldSelectionListener xFieldSelection) + { + this.xFieldSelection = xFieldSelection; + this.xFieldSelection.setID(sIncSuffix); + } + + public void setAppendMode(boolean _AppendMode) + { + AppendMode = _AppendMode; + } + + public FieldSelection(UnoDialog CurUnoDialog, int _iStep, int CompPosX, int CompPosY, int CompWidth, int CompHeight, String slblFields, String slblSelFields, int _FirstHelpIndex, boolean bshowFourButtons) + { + try + { + final String AccessTextMoveSelected = CurUnoDialog.m_oResource.getResText("RID_DB_COMMON_39"); + final String AccessTextRemoveSelected = CurUnoDialog.m_oResource.getResText("RID_DB_COMMON_40"); + final String AccessTextMoveAll = CurUnoDialog.m_oResource.getResText("RID_DB_COMMON_41"); + final String AccessTextRemoveAll = CurUnoDialog.m_oResource.getResText("RID_DB_COMMON_42"); + final String AccessMoveFieldUp = CurUnoDialog.m_oResource.getResText("RID_DB_COMMON_43"); + final String AccessMoveFieldDown = CurUnoDialog.m_oResource.getResText("RID_DB_COMMON_44"); + + FirstHelpIndex = _FirstHelpIndex; + short curtabindex = UnoDialog.setInitialTabindex(_iStep); + int ShiftButtonCount = 2; + int a = 0; + this.CurUnoDialog = CurUnoDialog; + this.CompPosY = CompPosY; + this.CompHeight = CompHeight; + Object btnmoveall = null; + Object btnremoveall = null; + + final int cmdButtonWidth = 16; + final int cmdButtonHoriDist = 4; + final int lblHeight = 8; + final int lblVertiDist = 2; + + ListBoxWidth = Integer.valueOf(((CompWidth - 3 * cmdButtonHoriDist - 2 * cmdButtonWidth) / 2)); + Integer cmdShiftButtonPosX = Integer.valueOf((CompPosX + ListBoxWidth.intValue() + cmdButtonHoriDist)); + Integer ListBoxPosY = Integer.valueOf(CompPosY + lblVertiDist + lblHeight); + Integer ListBoxHeight = Integer.valueOf(CompHeight - 8 - 2); + Integer SelListBoxPosX = Integer.valueOf(cmdShiftButtonPosX.intValue() + cmdButtonWidth + cmdButtonHoriDist); + + IStep = Integer.valueOf(_iStep); + if (bshowFourButtons) + { + ShiftButtonCount = 4; + } + Integer[] ShiftButtonPosY = getYButtonPositions(ShiftButtonCount); + Integer[] MoveButtonPosY = getYButtonPositions(2); + Integer cmdMoveButtonPosX = Integer.valueOf(SelListBoxPosX.intValue() + ListBoxWidth.intValue() + cmdButtonHoriDist); + + Integer CmdButtonWidth = Integer.valueOf(cmdButtonWidth); + + sIncSuffix = "_" + com.sun.star.wizards.common.Desktop.getIncrementSuffix(CurUnoDialog.getDlgNameAccess(), "lblFields_"); + + // Label + CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblFields" + sIncSuffix, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 8, slblFields, Integer.valueOf(CompPosX), Integer.valueOf(CompPosY), IStep, Short.valueOf(curtabindex), 109 + }); + + // Listbox 'Available fields' + xFieldsListBox = CurUnoDialog.insertListBox("lstFields" + sIncSuffix, SOFLDSLST, new ActionListenerImpl(), new ItemListenerImpl(), + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "MultiSelection", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + ListBoxHeight, HelpIds.getHelpIdString(_FirstHelpIndex), Boolean.TRUE, Integer.valueOf(CompPosX), ListBoxPosY, IStep, Short.valueOf((curtabindex++)), ListBoxWidth + }); + + Object btnmoveselected = CurUnoDialog.insertButton("cmdMoveSelected" + sIncSuffix, SOCMDMOVESEL, new ActionListenerImpl(), + new String[] + { + 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 + }, + new Object[] + { + Boolean.FALSE, 14, HelpIds.getHelpIdString(_FirstHelpIndex + 1), ">", cmdShiftButtonPosX, ShiftButtonPosY[a++], IStep, Short.valueOf(curtabindex++), CmdButtonWidth + }); + + if (bshowFourButtons) + { + btnmoveall = CurUnoDialog.insertButton("cmdMoveAll" + sIncSuffix, SOCMDMOVEALL, new ActionListenerImpl(), + new String[] + { + 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 + }, + new Object[] + { + 14, HelpIds.getHelpIdString(_FirstHelpIndex + 2), ">>", cmdShiftButtonPosX, ShiftButtonPosY[a++], IStep, Short.valueOf(curtabindex++), CmdButtonWidth + }); + } + Object btnremoveselected = CurUnoDialog.insertButton("cmdRemoveSelected" + sIncSuffix, SOCMDREMOVESEL, new ActionListenerImpl(), + new String[] + { + 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 + }, + new Object[] + { + Boolean.FALSE, 14, HelpIds.getHelpIdString(_FirstHelpIndex + 3), "<", cmdShiftButtonPosX, ShiftButtonPosY[a++], IStep, Short.valueOf(curtabindex++), CmdButtonWidth + }); + + if (bshowFourButtons) + { + btnremoveall = CurUnoDialog.insertButton("cmdRemoveAll" + sIncSuffix, SOCMDREMOVEALL, new ActionListenerImpl(), + new String[] + { + 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 + }, + new Object[] + { + 14, HelpIds.getHelpIdString(_FirstHelpIndex + 4), "<<", cmdShiftButtonPosX, ShiftButtonPosY[a++], IStep, Short.valueOf(curtabindex++), CmdButtonWidth + }); + } + + FontDescriptor oFontDesc = new FontDescriptor(); + oFontDesc.Name = "StarSymbol"; + + // Label 'Fields in the form' + CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblSelFields" + sIncSuffix, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 8, slblSelFields, SelListBoxPosX, Integer.valueOf(CompPosY), IStep, Short.valueOf(curtabindex++), ListBoxWidth + }); + + // ListBox 'Fields in the form' + xSelectedFieldsListBox = CurUnoDialog.insertListBox("lstSelFields" + sIncSuffix, SOSELFLDSLST, new ActionListenerImpl(), new ItemListenerImpl(), + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "MultiSelection", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + ListBoxHeight, HelpIds.getHelpIdString(_FirstHelpIndex + 5), Boolean.TRUE, SelListBoxPosX, ListBoxPosY, IStep, Short.valueOf(curtabindex++), ListBoxWidth + }); + + Object btnmoveup = CurUnoDialog.insertButton("cmdMoveUp" + sIncSuffix, SOCMDMOVEUP, new ActionListenerImpl(), + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.FONT_DESCRIPTOR, 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 + }, + new Object[] + { + Boolean.FALSE, oFontDesc, 14, HelpIds.getHelpIdString(_FirstHelpIndex + 6), String.valueOf((char) 8743), cmdMoveButtonPosX, MoveButtonPosY[0], IStep, Short.valueOf(curtabindex++), CmdButtonWidth + }); + + Object btnmovedown = CurUnoDialog.insertButton("cmdMoveDown" + sIncSuffix, SOCMDMOVEDOWN, new ActionListenerImpl(), + new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.FONT_DESCRIPTOR, 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 + }, + new Object[] + { + Boolean.FALSE, oFontDesc, 14, HelpIds.getHelpIdString(_FirstHelpIndex + 7), String.valueOf((char) 8744), cmdMoveButtonPosX, MoveButtonPosY[1], IStep, Short.valueOf(curtabindex++), CmdButtonWidth + }); + + CurUnoDialog.getPeerConfiguration().setAccessibleName(btnmoveselected, AccessTextMoveSelected); + CurUnoDialog.getPeerConfiguration().setAccessibleName(btnremoveselected, AccessTextRemoveSelected); + CurUnoDialog.getPeerConfiguration().setAccessibleName(xFieldsListBox, JavaTools.replaceSubString(slblFields, PropertyNames.EMPTY_STRING, "~")); + CurUnoDialog.getPeerConfiguration().setAccessibleName(xSelectedFieldsListBox, JavaTools.replaceSubString(slblSelFields, PropertyNames.EMPTY_STRING, "~")); + if (btnmoveall != null) + { + CurUnoDialog.getPeerConfiguration().setAccessibleName(btnmoveall, AccessTextMoveAll); + } + if (btnremoveall != null) + { + CurUnoDialog.getPeerConfiguration().setAccessibleName(btnremoveall, AccessTextRemoveAll); + } + if (btnmoveup != null) + { + CurUnoDialog.getPeerConfiguration().setAccessibleName(btnmoveup, AccessMoveFieldUp); + } + if (btnmovedown != null) + { + CurUnoDialog.getPeerConfiguration().setAccessibleName(btnmovedown, AccessMoveFieldDown); + } + + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + // TODO: If Value is getting smaller than zero -> throw exception + private Integer[] getYButtonPositions(int ButtonCount) + { + Integer[] YPosArray; + if (ButtonCount > 0) + { + YPosArray = new Integer[ButtonCount]; + final int cmdButtonHeight = 14; + final int cmdButtonVertiDist = 2; + + YPosArray[0] = Integer.valueOf( (CompPosY + 10 + (((CompHeight - 10) - (ButtonCount * cmdButtonHeight) - ((ButtonCount - 1) * cmdButtonVertiDist)) / 2))); + if (ButtonCount > 1) + { + for (int i = 1; i < ButtonCount; i++) + { + YPosArray[i] = Integer.valueOf(YPosArray[i - 1].intValue() + cmdButtonHeight + cmdButtonVertiDist); + } + } + return YPosArray; + } + return null; + } + + public Integer getListboxWidth() + { + return this.ListBoxWidth; + } + + private void changeSelectionOrder(int iNeighbor) + { + short[] iSelIndices = xSelectedFieldsListBox.getSelectedItemsPos(); + // TODO: we are assuming that the array starts with the lowest index. Verify this assumption!!!!! + if (iSelIndices.length == 1) + { + short iSelIndex = iSelIndices[0]; + String[] NewItemList = xSelectedFieldsListBox.getItems(); + String CurItem = NewItemList[iSelIndex]; + String NeighborItem = NewItemList[iSelIndex + iNeighbor]; + NewItemList[iSelIndex + iNeighbor] = CurItem; + NewItemList[iSelIndex] = NeighborItem; + CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, NewItemList); + xSelectedFieldsListBox.selectItem(CurItem, true); + if (xFieldSelection != null) + { + if (iNeighbor < 0) + { + xFieldSelection.moveItemUp(CurItem); + } + else + { + xFieldSelection.moveItemDown(CurItem); + } + } + } + } + + public void toggleListboxControls(Boolean BDoEnable) + { + try + { + CurUnoDialog.setControlProperty("lblFields" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable); + CurUnoDialog.setControlProperty("lblSelFields" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable); + CurUnoDialog.setControlProperty("lstFields" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable); + CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable); + + if (BDoEnable.booleanValue()) + { + toggleListboxButtons((short) - 1, (short) - 1); + } + else + { + CurUnoDialog.setControlProperty("cmdRemoveAll" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable); + CurUnoDialog.setControlProperty("cmdRemoveSelected" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, BDoEnable); + toggleMoveButtons(BDoEnable.booleanValue(), BDoEnable.booleanValue()); + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + // Enable or disable the buttons used for moving the available + // fields between the two list boxes. + protected void toggleListboxButtons(short iFieldsSelIndex, short iSelFieldsSelIndex) + { + try + { + boolean bmoveUpenabled = false; + boolean bmoveDownenabled = false; + CurUnoDialog.selectListBoxItem(xFieldsListBox, iFieldsSelIndex); + CurUnoDialog.selectListBoxItem(xSelectedFieldsListBox, iSelFieldsSelIndex); + int SelListBoxSelLength = xSelectedFieldsListBox.getSelectedItems().length; + int ListBoxSelLength = xFieldsListBox.getSelectedItems().length; + boolean bIsFieldSelected = (ListBoxSelLength > 0); + int FieldCount = xFieldsListBox.getItemCount(); + boolean bSelectSelected = (SelListBoxSelLength > 0); + int SelectCount = xSelectedFieldsListBox.getItemCount(); + if (bSelectSelected) + { + short[] iSelIndices = xSelectedFieldsListBox.getSelectedItemsPos(); + bmoveUpenabled = ((iSelIndices[0] > 0) && (iSelIndices.length == 1)); + bmoveDownenabled = (((iSelIndices[SelListBoxSelLength - 1]) < (short) (SelectCount - 1)) && (iSelIndices.length == 1)); + } + CurUnoDialog.setControlProperty("cmdRemoveAll" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(SelectCount >= 1)); + CurUnoDialog.setControlProperty("cmdRemoveSelected" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bSelectSelected)); + toggleMoveButtons((FieldCount >= 1), bIsFieldSelected); + CurUnoDialog.setControlProperty("cmdMoveUp" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bmoveUpenabled)); + CurUnoDialog.setControlProperty("cmdMoveDown" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bmoveDownenabled)); + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + protected void toggleMoveButtons(boolean _btoggleMoveAll, boolean _btoggleMoveSelected) + { + boolean btoggleMoveAll = (((xFieldsListBox.getItemCount() + xSelectedFieldsListBox.getItemCount()) < maxfieldcount) && (_btoggleMoveAll)); + boolean btoggleMoveSelected = (((xFieldsListBox.getSelectedItems().length + xSelectedFieldsListBox.getItemCount()) < maxfieldcount) && (_btoggleMoveSelected)); + CurUnoDialog.setControlProperty("cmdMoveAll" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(btoggleMoveAll)); + CurUnoDialog.setControlProperty("cmdMoveSelected" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(btoggleMoveSelected)); + } + + public void setMultipleMode(boolean _bisMultiple) + { + xFieldsListBox.setMultipleMode(_bisMultiple); + xSelectedFieldsListBox.setMultipleMode(_bisMultiple); + } + + public void emptyFieldsListBoxes() + { + try + { + toggleListboxControls(Boolean.FALSE); + CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, new String[] + { + }); + CurUnoDialog.setControlProperty("lstFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, new String[] + { + }); + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + + + public void intializeSelectedFields(String[] _SelectedFieldNames) + { + xSelectedFieldsListBox.addItems(_SelectedFieldNames, xSelectedFieldsListBox.getItemCount()); + } + + private void removeAllItems(XListBox _xListBox) + { + _xListBox.removeItems((short) 0, _xListBox.getItemCount()); + } + + // Note Boolean Parameter + public void initialize(String[] _AllFieldNames, boolean _AppendMode) + { + AppendMode = _AppendMode; + removeAllItems(xFieldsListBox); + xFieldsListBox.addItems(_AllFieldNames, (short) 0); + AllFieldNames = xFieldsListBox.getItems(); + if ((xSelectedFieldsListBox.getItemCount() > 0) && (!AppendMode)) + { + removeAllItems(xSelectedFieldsListBox); + } + toggleListboxControls(Boolean.TRUE); + } + + + + public void initialize(String[] _AllFieldNames, boolean _AppendMode, int _maxfieldcount) + { + maxfieldcount = _maxfieldcount; + initialize(_AllFieldNames, _AppendMode); + } + + public void initialize(String[] _AllFieldNames, String[] _SelFieldNames, boolean _AppendMode) + { + removeAllItems(xSelectedFieldsListBox); + xSelectedFieldsListBox.addItems(_SelFieldNames, (short) 0); + initialize(_AllFieldNames, _AppendMode); + } + + public void selectFields(boolean bMoveAll) + { + short iFieldSelected = (short) - 1; + short iSelFieldSelected = (short) - 1; + String[] SelFieldItems; + if (bMoveAll) + { + SelFieldItems = xFieldsListBox.getItems(); + removeAllItems(xFieldsListBox); + if (!AppendMode) + { + removeAllItems(xSelectedFieldsListBox); + xSelectedFieldsListBox.addItems(AllFieldNames, (short) 0); + } + else + { + xSelectedFieldsListBox.addItems(SelFieldItems, xSelectedFieldsListBox.getItemCount()); + } + } + else + { + SelFieldItems = xFieldsListBox.getSelectedItems(); + int MaxSourceSelected = SelFieldItems.length; + if (MaxSourceSelected > 0) + { + iFieldSelected = xFieldsListBox.getSelectedItemPos(); + iSelFieldSelected = xSelectedFieldsListBox.getSelectedItemPos(); + xSelectedFieldsListBox.addItems(SelFieldItems, xSelectedFieldsListBox.getItemCount()); + CurUnoDialog.removeSelectedItems(xFieldsListBox); + xSelectedFieldsListBox.selectItemPos((short) 0, xSelectedFieldsListBox.getSelectedItems().length > 0); + } + } + toggleListboxButtons(iFieldSelected, iSelFieldSelected); + if (xFieldSelection != null) + { + xFieldSelection.shiftFromLeftToRight(SelFieldItems, xSelectedFieldsListBox.getItems()); + } + } + + private void deselectFields(boolean bMoveAll) + { + String SearchString; + short iOldFieldSelected = xFieldsListBox.getSelectedItemPos(); + short iOldSelFieldSelected = xSelectedFieldsListBox.getSelectedItemPos(); + String[] OldSelFieldItems = xSelectedFieldsListBox.getSelectedItems(); + if (bMoveAll) + { + OldSelFieldItems = xSelectedFieldsListBox.getItems(); + removeAllItems(xFieldsListBox); + xFieldsListBox.addItems(AllFieldNames, (short) 0); + removeAllItems(xSelectedFieldsListBox); + } + else + { + int MaxOriginalCount = AllFieldNames.length; + String[] SelList = xFieldsListBox.getItems(); + ArrayList<String> NewSourceVector = new ArrayList<String>(); + for (int i = 0; i < MaxOriginalCount; i++) + { + SearchString = AllFieldNames[i]; + if (JavaTools.FieldInList(SelList, SearchString) != -1) + { + NewSourceVector.add(SearchString); + } + else if (JavaTools.FieldInList(OldSelFieldItems, SearchString) != -1) + { + NewSourceVector.add(SearchString); + } + } + xFieldsListBox.removeItems((short) 0, xFieldsListBox.getItemCount()); + if (NewSourceVector.size() > 0) + { + String[] NewSourceList = new String[NewSourceVector.size()]; + NewSourceVector.toArray(NewSourceList); + xFieldsListBox.addItems(NewSourceList, (short) 0); + } + CurUnoDialog.removeSelectedItems(xSelectedFieldsListBox); + } + toggleListboxButtons(iOldFieldSelected, iOldSelFieldSelected); + String[] NewSelFieldItems = xSelectedFieldsListBox.getItems(); + if (xFieldSelection != null) + { + xFieldSelection.shiftFromRightToLeft(OldSelFieldItems, NewSelFieldItems); + } + } + + public void addItemsToFieldsListbox(String[] _sItems) + { + String[] sOldList = xFieldsListBox.getItems(); + for (int i = 0; i < _sItems.length; i++) + { + if (JavaTools.FieldInList(sOldList, _sItems[i]) < 0) + { + xFieldsListBox.addItem(_sItems[i], xFieldsListBox.getItemCount()); + } + } + } + + public String[] getSelectedFieldNames() + { + return (String[]) CurUnoDialog.getControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST); + } + + public void setSelectedFieldNames(String[] _sfieldnames) + { + CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, _sfieldnames); + String[] sleftboxfieldnames = JavaTools.removefromList(xFieldsListBox.getItems(), _sfieldnames); + CurUnoDialog.setControlProperty("lstFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, sleftboxfieldnames); + } + + public void setModified(boolean _bModified) + { + bisModified = _bModified; + } + + public boolean isModified() + { + return bisModified; + } + + public void changeSelectedFieldNames(String[] _sfieldnames) + { + CurUnoDialog.setControlProperty("lstSelFields" + sIncSuffix, PropertyNames.STRING_ITEM_LIST, _sfieldnames); + } +} diff --git a/wizards/com/sun/star/wizards/ui/FilterComponent.java b/wizards/com/sun/star/wizards/ui/FilterComponent.java new file mode 100644 index 000000000..f70714a31 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/FilterComponent.java @@ -0,0 +1,938 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import com.sun.star.awt.TextEvent; +import com.sun.star.awt.VclWindowPeerAttribute; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XListBox; +import com.sun.star.awt.XRadioButton; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertyContainer; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.sdb.SQLFilterOperator; +import com.sun.star.sdbc.DataType; +import com.sun.star.uno.Any; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.TypeClass; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.wizards.common.NumberFormatter; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.HelpIds; +import com.sun.star.wizards.common.JavaTools; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.db.FieldColumn; +import com.sun.star.wizards.db.QueryMetaData; +import com.sun.star.wizards.db.SQLQueryComposer; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class FilterComponent +{ + + private final Integer IStep; + private final int RowCount; + private static String[] sLogicOperators; + private final XRadioButton optMatchAny; + private final String slblFieldNames; + private final String slblOperators; + private final String slblValue; + private WizardDialog CurUnoDialog; + private final String sIncSuffix; + private final ControlRow[] oControlRows; + private final String sDuplicateCondition; + private static final int SOOPTORMODE = 100; + private static final int SOOPTANDMODE = 101; + private QueryMetaData oQueryMetaData; + private int iDateFormat; + private int iTimeFormat; + private PropertyValue[][] filterconditions; + private short curtabindex; + private static final int SO_FIRSTFIELDNAME = 1; + private static final int SO_SECONDFIELDNAME = 2; + private static final int SO_THIRDFIELDNAME = 3; + private static final int SO_FOURTHFIELDNAME = 4; + private int[] SO_FIELDNAMELIST = new int[] + { + SO_FIRSTFIELDNAME, SO_SECONDFIELDNAME, SO_THIRDFIELDNAME, SO_FOURTHFIELDNAME + }; + private static final int SO_FIRSTCONDITION = 5; + private static final int SO_SECONDCONDITION = 6; + private static final int SO_THIRDCONDITION = 7; + private static final int SO_FOURTHCONDITION = 8; + private int[] SO_CONDITIONLIST = new int[] + { + SO_FIRSTCONDITION, SO_SECONDCONDITION, SO_THIRDCONDITION, SO_FOURTHCONDITION + }; + private static final int SO_FIRSTTEXTFIELD = 1; + private static final int SO_SECONDTEXTFIELD = 2; + private static final int SO_THIRDTEXTFIELD = 3; + private static final int SO_FOURTHTEXTFIELD = 4; + private int[] SO_TEXTFIELDLIST = new int[] + { + SO_FIRSTTEXTFIELD, SO_SECONDTEXTFIELD, SO_THIRDTEXTFIELD, SO_FOURTHTEXTFIELD + }; + private static final int SO_FIRSTBOOLFIELDNAME = 256 + 1; + private static final int SO_SECONDBOOLFIELDNAME = 256 + 2; + private static final int SO_THIRDBOOLFIELDNAME = 256 + 3; + private static final int SO_FOURTHBOOLFIELDNAME = 256 + 4; + private int SOI_MATCHALL = 0; + private int SOI_MATCHANY = 1; + + class ItemListenerImpl implements com.sun.star.awt.XItemListener + { + + public void itemStateChanged(com.sun.star.awt.ItemEvent EventObject) + { + if (EventObject == null) { + return; + } + + int iKey = CurUnoDialog.getControlKey(EventObject.Source, CurUnoDialog.ControlList); + String sControlName = PropertyNames.EMPTY_STRING; + switch (iKey) + { + case SO_FIRSTFIELDNAME: + case SO_SECONDFIELDNAME: + case SO_THIRDFIELDNAME: + case SO_FOURTHFIELDNAME: + sControlName = getControlName(EventObject.Source); + String sControlNameSuffix = sIncSuffix + "_" + getIndexNumber(sControlName); + XListBox xCurFieldListBox = UnoRuntime.queryInterface(XListBox.class, CurUnoDialog.xDlgContainer.getControl(sControlName)); + String CurDisplayFieldName = xCurFieldListBox.getSelectedItem(); + FieldColumn CurFieldColumn = oQueryMetaData.getFieldColumnByDisplayName(CurDisplayFieldName); + + String sControlNameTextValue = "txtValue" + sControlNameSuffix; + XControl xValueControl = CurUnoDialog.xDlgContainer.getControl(sControlNameTextValue); + XInterface xValueModel = (XInterface) UnoDialog.getModel(xValueControl); + Helper.setUnoPropertyValue(xValueModel, "TreatAsNumber", Boolean.valueOf(CurFieldColumn.isNumberFormat())); + final NumberFormatter aNumberFormatter = oQueryMetaData.getNumberFormatter(); + aNumberFormatter.setNumberFormat(xValueModel, CurFieldColumn.getDBFormatKey(), aNumberFormatter); + + break; + + case SO_FIRSTCONDITION: + case SO_SECONDCONDITION: + case SO_THIRDCONDITION: + case SO_FOURTHCONDITION: + case SO_FIRSTBOOLFIELDNAME: + case SO_SECONDBOOLFIELDNAME: + case SO_THIRDBOOLFIELDNAME: + case SO_FOURTHBOOLFIELDNAME: + sControlName = getControlName(EventObject.Source); + break; + + case SOOPTORMODE: + case SOOPTANDMODE: + return; + + default: + break; + } + togglefollowingControlRow(sControlName); + } + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + } + } + + class TextListenerImpl implements com.sun.star.awt.XTextListener + { + + public void textChanged(TextEvent EventObject) + { + String sName = getControlName(EventObject.Source); + togglefollowingControlRow(sName); + } + + public void disposing(EventObject eventObject) + { + } + + + } + + private static String getIndexNumber(String _sStr) + { + return _sStr.substring(_sStr.length() - 1, _sStr.length()); + } + + /** + * Enable the next ControlRow if the Condition is complete in the current line + * + * @param _scurName every control name ends with something like _1, _2, _3 this is the index number + * we try to interpret to check which line we currently use. (number - 1) + */ + private void togglefollowingControlRow(String _scurName) + { + int Index = Integer.parseInt(getIndexNumber(_scurName)); + if (Index < oControlRows.length) + { + boolean bValue = oControlRows[Index - 1].isConditionComplete(); + oControlRows[Index].setEnabled(bValue); + } + } + + private String getControlName(Object _oSourceevent) + { + try + { + XControl xControl = UnoRuntime.queryInterface(XControl.class, _oSourceevent); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel()); + return AnyConverter.toString(xPSet.getPropertyValue(PropertyNames.PROPERTY_NAME)); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + return PropertyNames.EMPTY_STRING; + } + + public PropertyValue[][] getFilterConditions() + { + int nFilterCount = getFilterCount(); + if (nFilterCount > 0) + { + final SQLQueryComposer composer = oQueryMetaData.getSQLQueryComposer(); + try + { + final String serviceName = "com.sun.star.beans.PropertyBag"; + final XPropertyContainer column = UnoRuntime.queryInterface(XPropertyContainer.class, oQueryMetaData.xMSF.createInstance(serviceName)); + + column.addProperty("Type", PropertyAttribute.BOUND, DataType.VARCHAR); + column.addProperty(PropertyNames.PROPERTY_NAME, PropertyAttribute.BOUND, PropertyNames.EMPTY_STRING); + column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), null); + final XPropertySet columnSet = UnoRuntime.queryInterface(XPropertySet.class, column); + + if (composer.getQuery().length() == 0) + { + StringBuilder sql = new StringBuilder(); + sql.append(composer.getSelectClause(true)); + sql.append(' '); + sql.append(composer.getFromClause()); + composer.getQueryComposer().setElementaryQuery(sql.toString()); + } + composer.getQueryComposer().setStructuredFilter(new PropertyValue[][] + { + }); + for (int i = 0; i < RowCount; i++) + { + ControlRow currentControlRow = oControlRows[i]; + if (currentControlRow.isEnabled() && currentControlRow.isConditionComplete()) + { + String sFieldName = currentControlRow.getSelectedFieldName(); + int nOperator = currentControlRow.getSelectedOperator(); + FieldColumn aFieldColumn = oQueryMetaData.getFieldColumnByDisplayName(sFieldName); + columnSet.setPropertyValue(PropertyNames.PROPERTY_NAME, aFieldColumn.getFieldName()); + columnSet.setPropertyValue("Type", aFieldColumn.getXColumnPropertySet().getPropertyValue("Type")); + Object value = currentControlRow.getValue(); + switch (aFieldColumn.getFieldType()) + { + case DataType.TIMESTAMP: + case DataType.DATE: + value = ((Double) value) - oQueryMetaData.getNullDateCorrection(); + break; + // TODO: TIME case? + } + column.removeProperty("Value"); + final short operator = currentControlRow.getSelectedOperator(); + if ((operator == SQLFilterOperator.SQLNULL) + || (operator == SQLFilterOperator.NOT_SQLNULL) + || AnyConverter.isVoid(value)) + { + column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), ""); + value = new Any(new Type(TypeClass.VOID), null); + } + else + { + column.addProperty("Value", (short) (PropertyAttribute.MAYBEVOID | PropertyAttribute.REMOVABLE), value); + } + columnSet.setPropertyValue("Value", value); + composer.getQueryComposer().appendFilterByColumn(columnSet, getfilterstate() == this.SOI_MATCHALL, nOperator); + } + } + filterconditions = composer.getQueryComposer().getStructuredFilter(); + int[] iduplicate = JavaTools.getDuplicateFieldIndex(filterconditions); + if (iduplicate[0] != -1) + { + PropertyValue aduplicatecondition = filterconditions[iduplicate[0]][iduplicate[1]]; + String smsgDuplicateCondition = getDisplayCondition(sDuplicateCondition, aduplicatecondition, null); + CurUnoDialog.showMessageBox("WarningBox", VclWindowPeerAttribute.OK, smsgDuplicateCondition); + CurUnoDialog.vetoableChange(new java.beans.PropertyChangeEvent(CurUnoDialog, "Steps", Integer.valueOf(1), Integer.valueOf(2))); + return new PropertyValue[][] + { + }; + } + } + catch (Exception ex) + { + Logger.getLogger(FilterComponent.class.getName()).log(Level.SEVERE, null, ex); + } + } + else + { + filterconditions = new PropertyValue[0][0]; + } + return filterconditions; + } + + public static String getDisplayCondition(String _BaseString, PropertyValue _filtercondition, QueryMetaData _CurDBMetaData) + { + try + { + String FieldName; + if (_CurDBMetaData != null) + { + FieldColumn CurDBFieldColumn = _CurDBMetaData.getFieldColumnByFieldName(_filtercondition.Name); + FieldName = CurDBFieldColumn.getFieldTitle(); + } + else + { + FieldName = _filtercondition.Name; + } + String sreturn = JavaTools.replaceSubString(_BaseString, FieldName, "<FIELDNAME>"); + String soperator = sLogicOperators[_filtercondition.Handle - 1]; + sreturn = JavaTools.replaceSubString(sreturn, soperator, "<LOGICOPERATOR>"); + String sDisplayValue = PropertyNames.EMPTY_STRING; + if ((_filtercondition.Handle != SQLFilterOperator.SQLNULL) + && (_filtercondition.Handle != SQLFilterOperator.NOT_SQLNULL) + && !AnyConverter.isVoid(_filtercondition.Value)) + { + sDisplayValue = AnyConverter.toString(_filtercondition.Value); + } + sreturn = JavaTools.replaceSubString(sreturn, sDisplayValue, "<VALUE>"); + return sreturn; + } + catch (IllegalArgumentException e) + { + e.printStackTrace(System.err); + } + return PropertyNames.EMPTY_STRING; + } + + private int getfilterstate() + { + boolean bisany = true; + int ifilterstate = SOI_MATCHALL; + bisany = this.optMatchAny.getState(); + if (bisany) + { + ifilterstate = SOI_MATCHANY; + } + else + { + ifilterstate = SOI_MATCHALL; + } + return ifilterstate; + } + + private int getFilterCount() + { + int a = 0; + for (int i = 0; i < RowCount; i++) + { + if (oControlRows[i].isEnabled() && oControlRows[i].isConditionComplete()) + { + a++; + } + } + return a; + } + + /** Creates a new instance of FilterComponent + */ + public FilterComponent(WizardDialog CurUnoDialog, int iStep, int iPosX, int iPosY, int FilterCount, QueryMetaData _oQueryMetaData, int _firstHelpID) + { + int curHelpID = _firstHelpID; + this.IStep = Integer.valueOf(iStep); + + curtabindex = UnoDialog.setInitialTabindex(iStep); + this.CurUnoDialog = CurUnoDialog; + this.RowCount = FilterCount; + this.oQueryMetaData = _oQueryMetaData; + boolean bEnabled; + sIncSuffix = com.sun.star.wizards.common.Desktop.getIncrementSuffix(CurUnoDialog.getDlgNameAccess(), "optMatchAll"); + + String soptMatchAll = CurUnoDialog.m_oResource.getResText("RID_QUERY_9"); + String soptMatchAny = CurUnoDialog.m_oResource.getResText("RID_QUERY_10"); + slblFieldNames = CurUnoDialog.m_oResource.getResText("RID_QUERY_17"); + slblOperators = CurUnoDialog.m_oResource.getResText("RID_QUERY_24"); + slblValue = CurUnoDialog.m_oResource.getResText("RID_QUERY_25"); + sLogicOperators = new String[10]; // =, <>, <, >, <=, >=, like, !like, is null, !is null + sLogicOperators[0] = CurUnoDialog.m_oResource.getResText("RID_QUERY_26"); + sLogicOperators[1] = CurUnoDialog.m_oResource.getResText("RID_QUERY_27"); + sLogicOperators[2] = CurUnoDialog.m_oResource.getResText("RID_QUERY_28"); + sLogicOperators[3] = CurUnoDialog.m_oResource.getResText("RID_QUERY_29"); + sLogicOperators[4] = CurUnoDialog.m_oResource.getResText("RID_QUERY_30"); + sLogicOperators[5] = CurUnoDialog.m_oResource.getResText("RID_QUERY_31"); + sLogicOperators[6] = CurUnoDialog.m_oResource.getResText("RID_QUERY_32"); + sLogicOperators[7] = CurUnoDialog.m_oResource.getResText("RID_QUERY_33"); + sLogicOperators[8] = CurUnoDialog.m_oResource.getResText("RID_QUERY_34"); + sLogicOperators[9] = CurUnoDialog.m_oResource.getResText("RID_QUERY_35"); + sDuplicateCondition = CurUnoDialog.m_oResource.getResText("RID_QUERY_89"); + + // create Radiobuttons + // * match all + // * match one + CurUnoDialog.insertRadioButton("optMatchAll" + sIncSuffix, SOOPTANDMODE, new ItemListenerImpl(), + new String[] + { + 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 + }, + new Object[] + { + Integer.valueOf(9), + HelpIds.getHelpIdString(curHelpID++), + soptMatchAll, + Integer.valueOf(iPosX), + Integer.valueOf(iPosY), + Short.valueOf((short) 1), + IStep, + Short.valueOf(curtabindex++), + Integer.valueOf(203) + }); + optMatchAny = CurUnoDialog.insertRadioButton("optMatchAny" + sIncSuffix, SOOPTORMODE, new ItemListenerImpl(), + new String[] + { + 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 + }, + new Object[] + { + Integer.valueOf(9), + HelpIds.getHelpIdString(curHelpID++), + soptMatchAny, + Integer.valueOf(iPosX), + Integer.valueOf(iPosY + 12), + IStep, + Short.valueOf(curtabindex++), + Integer.valueOf(203) + }); + getfilterstate(); + + oControlRows = new ControlRow[FilterCount]; + for (int i = 0; i < FilterCount; i++) + { + bEnabled = (i == 0); + oControlRows[i] = new ControlRow(iPosX, iPosY + 20, i, bEnabled, (curHelpID + (i * 3))); + iPosY += 43; + } + } + + public void initialize(PropertyValue[][] _filterconditions, String[] _fieldnames) + { + int i; + for (i = 0; i < RowCount; i++) + { + oControlRows[i].setFieldNames(_fieldnames); + // oControlRows[i].setFieldNames(aFieldNamesWithAdditionalEmpty); + } + this.filterconditions = _filterconditions; + PropertyValue[] curfilterconditions; + // int a; + if (_filterconditions.length == 1) + { + curfilterconditions = filterconditions[0]; + for (i = 0; i < curfilterconditions.length; i++) + { + oControlRows[i].setCondition(filterconditions[0][i]); + } + } + else + { + for (i = 0; i < filterconditions.length; i++) + { + oControlRows[i].setCondition(filterconditions[i][0]); + } + } + while (i < oControlRows.length) + { + oControlRows[i].settovoid(); + boolean bdoenable; + if (i > 0) + { + bdoenable = oControlRows[i - 1].isConditionComplete(); + } + else + { + bdoenable = true; + } + oControlRows[i].setEnabled(bdoenable); + i++; + } + } + + public void addNumberFormats() + { + iDateFormat = oQueryMetaData.getNumberFormatter().defineNumberFormat("YYYY-MM-DD"); + iTimeFormat = oQueryMetaData.getNumberFormatter().defineNumberFormat("HH:MM:SS"); + oQueryMetaData.getNumberFormatter().defineNumberFormat("YYYY-MM-DD HH:MM:SS"); + } + + + + + + private final class ControlRow + { + + private static final int SOLSTFIELDNAME = 3; + private static final int SOLSTOPERATOR = 4; + private static final int SOTXTVALUE = 5; + private XInterface[] ControlElements = new XInterface[6]; + private boolean m_bEnabled; + private String[] FieldNames; + + private ControlRow(int iCompPosX, int iCompPosY, int Index, boolean _bEnabled, int _firstRowHelpID) + { + int nFieldWidth = 71; + int nOperatorWidth = 70; + int nValueWidth = 44; + + int nPosX1 = iCompPosX + 10; + int nPosX2 = iCompPosX + 10 + nFieldWidth + 6; // 87 + int nPosX3 = iCompPosX + 10 + nFieldWidth + 6 + nOperatorWidth + 6; + + + try + { + String sCompSuffix = sIncSuffix + "_" + (Index + 1); + m_bEnabled = _bEnabled; + + // Label Field + ControlElements[0] = CurUnoDialog.insertLabel("lblFieldNames" + sCompSuffix, + new String[] + { + 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 + }, + new Object[] + { + Boolean.valueOf(isEnabled()), + Integer.valueOf(9), + slblFieldNames, + Integer.valueOf(nPosX1), + Integer.valueOf(iCompPosY + 13), + IStep, + Short.valueOf(curtabindex++), + Integer.valueOf(nFieldWidth) + }); + + // Label Operator + ControlElements[1] = CurUnoDialog.insertLabel("lblOperators" + sCompSuffix, + new String[] + { + 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 + }, + new Object[] + { + Boolean.valueOf(isEnabled()), + Integer.valueOf(9), + slblOperators, + Integer.valueOf(nPosX2), + Integer.valueOf(iCompPosY + 13), + IStep, + Short.valueOf(curtabindex++), + Integer.valueOf(nOperatorWidth) + }); + + // Label Value + ControlElements[2] = CurUnoDialog.insertLabel("lblValue" + sCompSuffix, + new String[] + { + 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 + }, + new Object[] + { + Boolean.valueOf(isEnabled()), + Integer.valueOf(9), + slblValue, + Integer.valueOf(nPosX3), + Integer.valueOf(iCompPosY + 13), + IStep, + Short.valueOf(curtabindex++), + Integer.valueOf(nValueWidth) + }); + + // Listbox Fields + ControlElements[SOLSTFIELDNAME] = CurUnoDialog.insertListBox("lstFieldName" + sCompSuffix, SO_FIELDNAMELIST[Index], null, new ItemListenerImpl(), + new String[] + { + PropertyNames.PROPERTY_ENABLED, + "Dropdown", + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, + "LineCount", + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.valueOf(isEnabled()), + Boolean.TRUE, + Integer.valueOf(13), + HelpIds.getHelpIdString(_firstRowHelpID++), + Short.valueOf(UnoDialog.getListBoxLineCount() /* 7 */), + Integer.valueOf(nPosX1), + Integer.valueOf(iCompPosY + 23), + IStep, + Short.valueOf(curtabindex++), + Integer.valueOf(nFieldWidth) + }); + + // Listbox Operators + ControlElements[SOLSTOPERATOR] = CurUnoDialog.insertListBox("lstOperator" + sCompSuffix, SO_CONDITIONLIST[Index], null, new ItemListenerImpl(), + new String[] + { + PropertyNames.PROPERTY_ENABLED, + "Dropdown", + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, + "LineCount", + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.STRING_ITEM_LIST, + PropertyNames.PROPERTY_TABINDEX, + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Boolean.valueOf(isEnabled()), + Boolean.TRUE, + Integer.valueOf(13), + HelpIds.getHelpIdString(_firstRowHelpID++), + Short.valueOf((short) sLogicOperators.length /* 7 */), + Integer.valueOf(nPosX2), + Integer.valueOf(iCompPosY + 23), + IStep, + sLogicOperators, + Short.valueOf(curtabindex++), + Integer.valueOf(nOperatorWidth) + }); + ControlElements[SOTXTVALUE] = CurUnoDialog.insertFormattedField("txtValue" + sCompSuffix, SO_TEXTFIELDLIST[Index], new TextListenerImpl(), + new String[] + { + 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 + }, + new Object[] + { + Boolean.valueOf(isEnabled()), + Integer.valueOf(13), + HelpIds.getHelpIdString(_firstRowHelpID++), + Integer.valueOf(nPosX3), + Integer.valueOf(iCompPosY + 23), + IStep, + Short.valueOf(curtabindex++), + Integer.valueOf(nValueWidth) + }); + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + /** + * @return true if the current condition is complete, all needed fields are filled with values. + * So we can enable the next. + */ + private boolean isConditionComplete() + { + try + { + short[] SelFields = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTFIELDNAME]), PropertyNames.SELECTED_ITEMS)); + if (SelFields.length > 0) + { + int nSelOperator = getSelectedOperator(); + // short[] SelOperator = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTOPERATOR]), PropertyNames.SELECTED_ITEMS)); + if (nSelOperator == com.sun.star.sdb.SQLFilterOperator.SQLNULL + || /* is null */ nSelOperator == com.sun.star.sdb.SQLFilterOperator.NOT_SQLNULL) /* is not null */ + + { + // disable value field + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[2]), PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); + + return true; + } + else + { + // enable value field + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[2]), PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); + } + if (nSelOperator != -1) + { + Object oValue = Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue"); + if (!AnyConverter.isVoid(oValue)) + { + String sValue = String.valueOf(oValue); + return !sValue.equals(PropertyNames.EMPTY_STRING); + } + } + } + return false; + } + catch (IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + return false; + } + } + + private void setCondition(PropertyValue _filtercondition) + { + try + { + XListBox xFieldsListBox = UnoRuntime.queryInterface(XListBox.class, ControlElements[SOLSTFIELDNAME]); + xFieldsListBox.selectItem(_filtercondition.Name, true); + XListBox xOperatorListBox = UnoRuntime.queryInterface(XListBox.class, ControlElements[SOLSTOPERATOR]); + xOperatorListBox.selectItemPos((short) (_filtercondition.Handle - 1), true); + + if (AnyConverter.isString(_filtercondition.Value)) + { + String sValue = AnyConverter.toString(_filtercondition.Value); + if (sValue.indexOf("{D '") > -1) + { + // TODO: this seems to never happen? + sValue = JavaTools.replaceSubString(sValue, PropertyNames.EMPTY_STRING, "{D '"); + sValue = JavaTools.replaceSubString(sValue, PropertyNames.EMPTY_STRING, "' }"); + try + { + //Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", ); + oQueryMetaData.getNumberFormatter().convertStringToNumber(iDateFormat, sValue); + } + catch (java.lang.Exception ex) + { + Logger.getLogger(FilterComponent.class.getName()).log(Level.SEVERE, null, ex); + } + } + else if (sValue.indexOf("{T '") > -1) + { + // TODO: this seems to never happen? + sValue = JavaTools.replaceSubString(sValue, PropertyNames.EMPTY_STRING, "{T '"); + sValue = JavaTools.replaceSubString(sValue, PropertyNames.EMPTY_STRING, "' }"); + try + { + //Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", ); + oQueryMetaData.getNumberFormatter().convertStringToNumber(iTimeFormat, sValue); + } + catch (java.lang.Exception ex) + { + Logger.getLogger(FilterComponent.class.getName()).log(Level.SEVERE, null, ex); + } + } + // TODO: TS case? + //TODO: other datetime formats? + else + { + //Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", sValue); + } + } + else if (AnyConverter.isBoolean(_filtercondition.Value)) + { + boolean b = AnyConverter.toBoolean(_filtercondition.Value); + double nValue = 0.0; + if (b) + { + nValue = 1.0; + } + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", nValue); + } + else + { + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", _filtercondition.Value); + } + } + catch (IllegalArgumentException e) + { + e.printStackTrace(System.err); + } + } + + private void setFieldNames(String[] _FieldNames) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTFIELDNAME]), PropertyNames.STRING_ITEM_LIST, _FieldNames); + FieldNames = _FieldNames; + } + + private boolean isEnabled() + { + return m_bEnabled; + } + + private void settovoid() + { + WizardDialog.deselectListBox(ControlElements[SOLSTFIELDNAME]); + WizardDialog.deselectListBox(ControlElements[SOLSTOPERATOR]); + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue", com.sun.star.uno.Any.VOID); + } + + private void setEnabled(boolean _bEnabled) + { + // enable all Controls Fieldname, operator, value + for (int i = 0; i < ControlElements.length; i++) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[i]), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bEnabled)); + } + m_bEnabled = _bEnabled; + if (isEnabled()) + { + short[] iselected = new short[] + { + }; + try + { + iselected = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTOPERATOR]), PropertyNames.SELECTED_ITEMS)); + } + catch (IllegalArgumentException e) + { + e.printStackTrace(System.err); + } + if ((iselected.length) == 0) + { + Helper.setUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTOPERATOR]), PropertyNames.SELECTED_ITEMS, new short[] + { + 0 + }); + } + } + else if (!isConditionComplete()) + { + WizardDialog.deselectListBox(ControlElements[SOLSTOPERATOR]); + } + } + + private String getSelectedFieldName() + { + try + { + short[] SelFields = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTFIELDNAME]), PropertyNames.SELECTED_ITEMS)); + return FieldNames[SelFields[0]]; + } + catch (IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + } + return null; + } + + // TODO: check if it is really useful to match the indices of the listbox the API constants + // =, <>, <, >, <=, >=, like, !like, is null, !is null + private short getSelectedOperator() + { + try + { + short[] SelFields = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOLSTOPERATOR]), PropertyNames.SELECTED_ITEMS)); + switch (SelFields[0]) + { + case 0: + return com.sun.star.sdb.SQLFilterOperator.EQUAL; + case 1: + return com.sun.star.sdb.SQLFilterOperator.NOT_EQUAL; + case 2: + return com.sun.star.sdb.SQLFilterOperator.LESS; + case 3: + return com.sun.star.sdb.SQLFilterOperator.GREATER; + case 4: + return com.sun.star.sdb.SQLFilterOperator.LESS_EQUAL; + case 5: + return com.sun.star.sdb.SQLFilterOperator.GREATER_EQUAL; + case 6: + return com.sun.star.sdb.SQLFilterOperator.LIKE; + case 7: + return com.sun.star.sdb.SQLFilterOperator.NOT_LIKE; + case 8: + return com.sun.star.sdb.SQLFilterOperator.SQLNULL; + case 9: + return com.sun.star.sdb.SQLFilterOperator.NOT_SQLNULL; + default: + return -1; + } + } + catch (IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + } + return -1; + } + + // TODO make a difference between Text and Numbers + private Object getValue() + { + return Helper.getUnoPropertyValue(UnoDialog.getModel(ControlElements[SOTXTVALUE]), "EffectiveValue"); + } + + + + + } +} diff --git a/wizards/com/sun/star/wizards/ui/PathSelection.py b/wizards/com/sun/star/wizards/ui/PathSelection.py new file mode 100644 index 000000000..1467085f9 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/PathSelection.py @@ -0,0 +1,137 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import traceback +from ..common.PropertyNames import PropertyNames +from ..common.FileAccess import FileAccess +from ..common.SystemDialog import SystemDialog + +class PathSelection(object): + + class DialogTypes(object): + FOLDER = 0 + FILE = 1 + + class TransferMode(object): + SAVE = 0 + LOAD = 1 + + def __init__(self, xMSF, CurUnoDialog, TransferMode, DialogType): + self.CurUnoDialog = CurUnoDialog + self.xMSF = xMSF + self.iDialogType = DialogType + self.iTransferMode = TransferMode + self.sDefaultDirectory = "" + self.sDefaultName = "" + self.sDefaultFilter = "" + self.usedPathPicker = False + self.CMDSELECTPATH = 1 + self.TXTSAVEPATH = 1 + + def insert( + self, DialogStep, XPos, YPos, Width, + CurTabIndex, LabelText, Enabled, TxtHelpURL, BtnHelpURL): + + self.CurUnoDialog.insertControlModel( + "com.sun.star.awt.UnoControlFixedTextModel", "lblSaveAs", + (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), + (Enabled, 8, LabelText, XPos, YPos, DialogStep, + CurTabIndex, Width)) + self.xSaveTextBox = self.CurUnoDialog.insertTextField( + "txtSavePath", "callXPathSelectionListener", + (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), + (Enabled, 12, TxtHelpURL, XPos, YPos + 10, DialogStep, + (CurTabIndex + 1), Width - 26), self) + + self.CurUnoDialog.xDialogModel.txtSavePath.Enabled = False + self.CurUnoDialog.insertButton("cmdSelectPath", "triggerPathPicker", + (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), + (Enabled, 14, BtnHelpURL, "...",XPos + Width - 16, YPos + 9, + DialogStep, (CurTabIndex + 2), 16), self) + + def addSelectionListener(self, xAction): + self.xAction = xAction + + def getSelectedPath(self): + return self.xSaveTextBox.Text + + def initializePath(self): + try: + myFA = FileAccess(self.xMSF) + self.xSaveTextBox.setText( + myFA.getPath(self.sDefaultDirectory + \ + "/" + \ + self.sDefaultName, None)) + except Exception: + traceback.print_exc() + + def triggerPathPicker(self): + try: + if self.iTransferMode == self.TransferMode.SAVE: + if self.iDialogType == self.DialogTypes.FOLDER: + #TODO: write code for picking a folder for saving + return + elif self.iDialogType == self.DialogTypes.FILE: + self.usedPathPicker = True + myFilePickerDialog = \ + SystemDialog.createStoreDialog(self.xMSF) + myFilePickerDialog.callStoreDialog( + self.sDefaultDirectory, + self.sDefaultName, self.sDefaultFilter) + sStorePath = myFilePickerDialog.sStorePath + if sStorePath is not None: + myFA = FileAccess(self.xMSF) + self.xSaveTextBox.Text = myFA.getPath(sStorePath, None) + self.sDefaultDirectory = \ + FileAccess.getParentDir(sStorePath) + self.sDefaultName = myFA.getFilename(sStorePath) + return + elif self.iTransferMode == self.TransferMode.LOAD: + if self.iDialogType == self.DialogTypes.FOLDER: + #TODO: write code for picking a folder for loading + return + elif self.iDialogType == self.DialogTypes.FILE: + #TODO: write code for picking a file for loading + return + except Exception: + traceback.print_exc() + + def callXPathSelectionListener(self): + if self.xAction is not None: + self.xAction.validatePath() diff --git a/wizards/com/sun/star/wizards/ui/PeerConfig.java b/wizards/com/sun/star/wizards/ui/PeerConfig.java new file mode 100644 index 000000000..8f0e2680a --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/PeerConfig.java @@ -0,0 +1,151 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import java.util.ArrayList; + +import com.sun.star.awt.WindowEvent; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XVclWindowPeer; +import com.sun.star.awt.XWindowListener; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.PropertyNames; + +public class PeerConfig implements XWindowListener +{ + + private final ArrayList<PeerTask> m_aPeerTasks = new ArrayList<PeerTask>(); + private ArrayList<ImageUrlTask> aImageUrlTasks = new ArrayList<ImageUrlTask>(); + private UnoDialog oUnoDialog = null; + + public PeerConfig(UnoDialog _oUnoDialog) + { + oUnoDialog = _oUnoDialog; + oUnoDialog.xWindow.addWindowListener(this); + } + + private static class PeerTask + { + + private XControl xControl; + private String[] propnames; + private Object[] propvalues; + + public PeerTask(XControl _xControl, String[] propNames_, Object[] propValues_) + { + propnames = propNames_; + propvalues = propValues_; + xControl = _xControl; + } + } + + private static class ImageUrlTask + { + Object oModel; + String oResource; + + public ImageUrlTask(Object _oModel, String _oResource) + { + oResource = _oResource; + oModel = _oModel; + } + } + + public void windowResized(WindowEvent arg0) + { + } + + public void windowMoved(WindowEvent arg0) + { + } + + public void windowShown(EventObject arg0) + { + try + { + for (int i = 0; i < this.m_aPeerTasks.size(); i++) + { + PeerTask aPeerTask = m_aPeerTasks.get(i); + XVclWindowPeer xVclWindowPeer = UnoRuntime.queryInterface(XVclWindowPeer.class, aPeerTask.xControl.getPeer()); + for (int n = 0; n < aPeerTask.propnames.length; n++) + { + xVclWindowPeer.setProperty(aPeerTask.propnames[n], aPeerTask.propvalues[n]); + } + } + for (int i = 0; i < this.aImageUrlTasks.size(); i++) + { + ImageUrlTask aImageUrlTask = aImageUrlTasks.get(i); + String sImageUrl = aImageUrlTask.oResource; + if (!sImageUrl.equals(PropertyNames.EMPTY_STRING)) + { + Helper.setUnoPropertyValue(aImageUrlTask.oModel, PropertyNames.PROPERTY_IMAGEURL, sImageUrl); + } + } + + } + catch (RuntimeException re) + { + re.printStackTrace(System.err); + throw re; + } + } + + public void windowHidden(EventObject arg0) + { + } + + public void disposing(EventObject arg0) + { + } + + /** + * @param oAPIControl an API control that the interface XControl can be derived from + */ + public void setAccessibleName(Object oAPIControl, String _saccessname) + { + XControl xControl = UnoRuntime.queryInterface(XControl.class, oAPIControl); + setPeerProperties(xControl, new String[] + { + "AccessibleName" + }, new String[] + { + _saccessname + }); + } + + + + private void setPeerProperties(XControl _xControl, String[] propnames, Object[] propvalues) + { + PeerTask oPeerTask = new PeerTask(_xControl, propnames, propvalues); + this.m_aPeerTasks.add(oPeerTask); + } + + /** + * Assigns an image to the property 'ImageUrl' of a dialog control. The image ids that the Resource urls point to + * may be assigned in a Resource file outside the wizards project + */ + public void setImageUrl(Object _ocontrolmodel, String _sResourceUrl) + { + ImageUrlTask oImageUrlTask = new ImageUrlTask(_ocontrolmodel, _sResourceUrl); + this.aImageUrlTasks.add(oImageUrlTask); + } +} diff --git a/wizards/com/sun/star/wizards/ui/PeerConfig.py b/wizards/com/sun/star/wizards/ui/PeerConfig.py new file mode 100644 index 000000000..1383b283a --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/PeerConfig.py @@ -0,0 +1,61 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import traceback + +from .event.CommonListener import WindowListenerProcAdapter + +''' +To change the template for this generated type comment go to +Window>Preferences>Java>Code Generation>Code and Comments +''' + +class PeerConfig(object): + + def __init__(self, _oUnoDialog): + self.oUnoDialog = _oUnoDialog + self.oUnoDialog.xUnoDialog.addWindowListener( + WindowListenerProcAdapter(self.windowShown)) + self.m_aPeerTasks = [] + self.aImageUrlTasks = [] + + class PeerTask(object): + + def __init__(self, _xControl, _propNames, _propValues): + self.propnames = _propNames + self.propvalues = _propValues + self.xControl = _xControl + + class ImageUrlTask(object): + + def __init__(self, _oModel, _oResource): + self.oModel = _oModel + self.oResource = _oResource + + def windowShown(self): + try: + for i in self.m_aPeerTasks: + xVclWindowPeer = i.xControl.Peer + xVclWindowPeer.setProperty(i.propnames, i.propvalues) + + for aImageUrlTask in self.aImageUrlTasks: + sImageUrl = aImageUrlTask.oResource + if sImageUrl != "": + aImageUrlTask.oModel.ImageURL = sImageUrl + + except Exception: + traceback.print_exc() diff --git a/wizards/com/sun/star/wizards/ui/SortingComponent.java b/wizards/com/sun/star/wizards/ui/SortingComponent.java new file mode 100644 index 000000000..a08729fd9 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/SortingComponent.java @@ -0,0 +1,336 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import java.beans.PropertyChangeEvent; + +import com.sun.star.wizards.common.*; +import com.sun.star.awt.*; + +import java.util.ArrayList; + +public class SortingComponent +{ + + private WizardDialog CurUnoDialog; + private int MaxSortIndex = -1; + private static String sNoSorting; + private static String sSortCriteriaisduplicate; + private static String[] sSortHeader = new String[4]; + private static String[] sSortAscend = new String[4]; + private static String[] sSortDescend = new String[4]; + private int MAXSORTCRITERIAINDEX = 3; + private static final int SOFIRSTSORTLST = 0; + private static final int SOSECSORTLST = 1; + private static final int SOTHIRDSORTLST = 2; + private static final int SOFOURTHSORTLST = 3; + private static final int[] SOSORTLST = new int[] + { + SOFIRSTSORTLST, SOSECSORTLST, SOTHIRDSORTLST, SOFOURTHSORTLST + }; + private XListBox[] xSortListBox = new XListBox[4]; + + class ItemListenerImpl implements com.sun.star.awt.XItemListener + { + + public void itemStateChanged(ItemEvent EventObject) + { + Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); + int ikey = CurUnoDialog.getControlKey(EventObject.Source, CurUnoDialog.ControlList); + enableNextSortListBox(ikey); + Helper.setUnoPropertyValue(CurUnoDialog.xDialogModel, PropertyNames.PROPERTY_ENABLED, Boolean.TRUE); + } + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + } + } + + public SortingComponent(WizardDialog CurUnoDialog, int iStep, int iCompPosX, int iCompPosY, int iCompWidth, int FirstHelpIndex) + { + try + { + this.CurUnoDialog = CurUnoDialog; + short curtabindex = UnoDialog.setInitialTabindex(iStep); + Integer IStep = Integer.valueOf(iStep); + Integer ICompPosX = Integer.valueOf(iCompPosX); + Integer ICompWidth = Integer.valueOf(iCompWidth); + + Integer IListBoxPosX = Integer.valueOf(iCompPosX + 6); + int iOptButtonWidth = 65; + Integer IOptButtonWidth = Integer.valueOf(iOptButtonWidth); + Integer IListBoxWidth = Integer.valueOf(iCompWidth - iOptButtonWidth - 12); + Integer IOptButtonPosX = Integer.valueOf(IListBoxPosX.intValue() + IListBoxWidth.intValue() + 6); + getResources(); + boolean bDoEnable; + String HIDString; + int iCurPosY = iCompPosY; + for (int i = 0; i < 4; i++) + { + bDoEnable = (i < 2); + CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lblSort" + Integer.toString(i + 1), new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.ORIENTATION, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, new Object[] + { + Boolean.valueOf(bDoEnable), 8, sSortHeader[i], 0, ICompPosX, Integer.valueOf(iCurPosY), IStep, Short.valueOf(curtabindex++), ICompWidth + }); + + HIDString = HelpIds.getHelpIdString(FirstHelpIndex); + xSortListBox[i] = CurUnoDialog.insertListBox("lstSort" + Integer.toString(i + 1), SOSORTLST[i], null, new ItemListenerImpl(), new String[] + { + "Dropdown", PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, "LineCount", PropertyNames.PROPERTY_NAME, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, new Object[] + { + true, bDoEnable, 12, HIDString, Short.valueOf(UnoDialog.getListBoxLineCount()), "lstSort" + Integer.valueOf(i + 1), IListBoxPosX, Integer.valueOf(iCurPosY + 14), IStep, Short.valueOf(curtabindex++), IListBoxWidth + }); //Short.valueOf((short) (17+i*4)) + + HIDString = HelpIds.getHelpIdString(FirstHelpIndex + 1); + CurUnoDialog.insertRadioButton("optAscend" + Integer.toString(i + 1), 0, new String[] + { + 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, "Tag", PropertyNames.PROPERTY_WIDTH + }, new Object[] + { + bDoEnable, 10, HIDString, sSortAscend[i], IOptButtonPosX, Integer.valueOf(iCurPosY + 10), Short.valueOf((short) 1), IStep, Short.valueOf(curtabindex++), PropertyNames.ASC, IOptButtonWidth + }); //, Short.valueOf((short) (18+i*4)) + + HIDString = HelpIds.getHelpIdString(FirstHelpIndex + 2); + CurUnoDialog.insertRadioButton("optDescend" + Integer.toString(i + 1), 0, new String[] + { + 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, "Tag", PropertyNames.PROPERTY_WIDTH + }, new Object[] + { + bDoEnable, 10, HIDString, sSortDescend[i], IOptButtonPosX, Integer.valueOf(iCurPosY + 24), Short.valueOf((short) 0), IStep, Short.valueOf(curtabindex++), "DESC", IOptButtonWidth + }); //, Short.valueOf((short) (19+i*4)) + iCurPosY = iCurPosY + 36; + FirstHelpIndex += 3; + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + private boolean getResources() + { + sSortHeader[0] = CurUnoDialog.m_oResource.getResText("RID_REPORT_20"); + sSortHeader[1] = CurUnoDialog.m_oResource.getResText("RID_REPORT_21"); + sSortHeader[2] = CurUnoDialog.m_oResource.getResText("RID_REPORT_51"); + sSortHeader[3] = CurUnoDialog.m_oResource.getResText("RID_REPORT_52"); + sSortAscend[0] = CurUnoDialog.m_oResource.getResText("RID_REPORT_36"); + sSortAscend[1] = CurUnoDialog.m_oResource.getResText("RID_REPORT_53"); + sSortAscend[2] = CurUnoDialog.m_oResource.getResText("RID_REPORT_54"); + sSortAscend[3] = CurUnoDialog.m_oResource.getResText("RID_REPORT_55"); + sSortDescend[0] = CurUnoDialog.m_oResource.getResText("RID_REPORT_37"); + sSortDescend[1] = CurUnoDialog.m_oResource.getResText("RID_REPORT_56"); + sSortDescend[2] = CurUnoDialog.m_oResource.getResText("RID_REPORT_57"); + sSortDescend[3] = CurUnoDialog.m_oResource.getResText("RID_REPORT_58"); + sSortCriteriaisduplicate = CurUnoDialog.m_oResource.getResText("RID_REPORT_74"); + sNoSorting = CurUnoDialog.m_oResource.getResText("RID_REPORT_8"); + return true; + } + + public void initialize(String[] _FieldNames, String[][] _SortFieldNames) + { + int FieldCount = _FieldNames.length; + String[] ViewFieldNames = new String[FieldCount + 1]; + ViewFieldNames[0] = sNoSorting; + System.arraycopy(_FieldNames, 0, ViewFieldNames, 1, FieldCount); + short[] SelList = null; + for (int i = 0; i < 4; i++) + { + if (i < _SortFieldNames.length) + { + SelList = new short[] + { + (short) (JavaTools.FieldInList(_FieldNames, _SortFieldNames[i][0]) + 1) + }; + } + else + { + SelList = new short[] + { + (short) 0 + }; + } + CurUnoDialog.setControlProperty("lstSort" + Integer.toString(i + 1), PropertyNames.STRING_ITEM_LIST, ViewFieldNames); + CurUnoDialog.setControlProperty("lstSort" + Integer.toString(i + 1), PropertyNames.SELECTED_ITEMS, SelList); + toggleSortListBox(i, (i <= _SortFieldNames.length)); + } + } + + private void setMaxSortIndex() + { + MaxSortIndex = -1; + for (int i = 0; i <= MAXSORTCRITERIAINDEX; i++) + { + if (xSortListBox[i].getSelectedItemPos() > 0) + { + MaxSortIndex += 1; + } + } + } + + /** + * sets the controls of a Sorting criterion to readonly or not. + * @param _index index of the Sorting criterion + */ + private void setReadOnly(int _index, boolean _breadonly) + { + CurUnoDialog.setControlProperty("lstSort" + Integer.toString(_index + 1), PropertyNames.READ_ONLY, Boolean.valueOf(_breadonly)); + } + + /** + * + * @param _index the first Sorting criterion in which 'ReadOnly is set to 'false' + */ + public void setReadOnlyUntil(int _index) + { + for (int i = 0; i <= 4; i++) + { + boolean breadonly = i < _index; + setReadOnly(i, breadonly); + } + } + + private void enableNextSortListBox(int CurIndex) + { + try + { + setMaxSortIndex(); + boolean bDoEnable = (xSortListBox[CurIndex].getSelectedItemPos() != 0); + if (!bDoEnable) + { + moveupSortItems(CurIndex, bDoEnable); //disableListBoxesfromIndex(CurIndex); + } + else + { + toggleSortListBox(CurIndex + 1, true); + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + public String[][] getSortFieldNames() + { + try + { + short iCurState; + String CurFieldName; + setMaxSortIndex(); + ArrayList<String[]> SortFieldNames = new ArrayList<String[]>(); + ArrayList<String> SortDescriptions = new ArrayList<String>(); + for (int i = 0; i <= MaxSortIndex; i++) + { + CurFieldName = xSortListBox[i].getSelectedItem(); + SortDescriptions.add(CurFieldName); + iCurState = ((Short) CurUnoDialog.getControlProperty("optAscend" + Integer.toString(i + 1), PropertyNames.PROPERTY_STATE)).shortValue(); + SortFieldNames.add(new String[]{CurFieldName,iCurState == 1 ? PropertyNames.ASC :"DESC" }); + } + // When searching for a duplicate entry we can neglect whether the entries are to be sorted ascending or descending + // TODO for the future we should deliver a messagebox when two different sorting modes have been applied to one field + int iduplicate = JavaTools.getDuplicateFieldIndex(SortDescriptions.toArray(new String[SortDescriptions.size()])); + if (iduplicate != -1) + { + String sLocSortCriteriaisduplicate = JavaTools.replaceSubString(sSortCriteriaisduplicate, SortFieldNames.get(iduplicate)[0], "<FIELDNAME>"); + CurUnoDialog.showMessageBox("WarningBox", VclWindowPeerAttribute.OK, sLocSortCriteriaisduplicate); + CurUnoDialog.vetoableChange(new PropertyChangeEvent(CurUnoDialog, "Steps", 1, 2)); + CurUnoDialog.setFocus("lstSort" + (iduplicate + 1)); + return new String[][] + { + }; + } + else + { + return SortFieldNames.toArray(new String[SortFieldNames.size()][2]); + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + + + // The following code can be reactivated in a future version when task #100799 will be fixed + private void moveupSortItems(int CurIndex, boolean bDoEnable) + { + short iNextItemPos; + if ((!bDoEnable) && (MAXSORTCRITERIAINDEX > CurIndex)) + { + for (int i = CurIndex; i < MAXSORTCRITERIAINDEX; i++) + { + iNextItemPos = xSortListBox[i + 1].getSelectedItemPos(); + if (iNextItemPos != 0) + { + CurUnoDialog.setControlProperty("lstSort" + Integer.toString(i + 1), PropertyNames.SELECTED_ITEMS, new short[] + { + iNextItemPos + }); + CurUnoDialog.setControlProperty("lstSort" + Integer.toString(i + 2), PropertyNames.SELECTED_ITEMS, new short[] + { + }); + toggleSortListBox(i, true); + CurUnoDialog.setControlProperty("lstSort" + Integer.toString(i + 2), PropertyNames.SELECTED_ITEMS, new short[] + { + 0 + }); + } + } + if (MaxSortIndex < xSortListBox.length - 2) + { + toggleSortListBox(MaxSortIndex + 2, false); + } + } + else + { + toggleSortListBox(CurIndex + 1, bDoEnable); + } + } + + private void toggleSortListBox(int CurIndex, boolean bDoEnable) + { + try + { + if (CurIndex < xSortListBox.length) + { + CurUnoDialog.setControlProperty("lblSort" + Integer.toString(CurIndex + 1), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); + CurUnoDialog.setControlProperty("lstSort" + Integer.toString(CurIndex + 1), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); + CurUnoDialog.setControlProperty("optAscend" + Integer.toString(CurIndex + 1), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); + CurUnoDialog.setControlProperty("optDescend" + Integer.toString(CurIndex + 1), PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bDoEnable)); + if (!bDoEnable) + { + CurUnoDialog.setControlProperty("lstSort" + Integer.toString(CurIndex + 1), PropertyNames.SELECTED_ITEMS, new short[] + { + 0 + }); + } + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + } +} diff --git a/wizards/com/sun/star/wizards/ui/TitlesComponent.java b/wizards/com/sun/star/wizards/ui/TitlesComponent.java new file mode 100644 index 000000000..b9003f60d --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/TitlesComponent.java @@ -0,0 +1,240 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import com.sun.star.wizards.common.Properties; +import com.sun.star.wizards.common.*; +import com.sun.star.beans.*; +import com.sun.star.awt.Size; +import com.sun.star.awt.XTextComponent; +import com.sun.star.awt.XTextListener; + +import java.util.*; + +public class TitlesComponent extends ControlScroller +{ + + private int iLabelPosX; + private static final int iRelLabelPosXDist = 6; + private String[] fieldnames; + private Map<String, String> fieldtitleset; + private String[] fieldtitles; + private static final String SOLABELPREFIX = "lblColumnName_"; + private static final String SOTITLEPREFIX = "lblTitleName_"; + + public TitlesComponent(WizardDialog _CurUnoDialog, int _iStep, int _iCompPosX, int _iCompPosY, int _iCompWidth, int _uitextfieldcount, String _slblColumnNames, String _slblColumnTitles, int _firsthelpindex) + { + super(_CurUnoDialog, _iStep, _iCompPosX, _iCompPosY, _iCompWidth, _uitextfieldcount, 18, _firsthelpindex); + CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblColumnNames", new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH + }, new Object[] + { + 8, _slblColumnNames, Integer.valueOf(iLabelPosX), Integer.valueOf(iCompPosY - 10), IStep, 60 + }); + CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", "lblColumnTitles", new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH + }, new Object[] + { + 8, _slblColumnTitles, 90, Integer.valueOf(iCompPosY - 10), IStep, 152 + }); + } + + @Override + protected void insertControlGroup(int i, int ypos) + { + iLabelPosX = iCompPosX + iRelLabelPosXDist; + ControlRow oControlRow = new ControlRow(i, ypos); + ControlGroupVector.add(oControlRow); + + } + + @Override + protected void setControlGroupVisible(int _index, boolean _bIsVisible) + { + CurUnoDialog.setControlVisible(getColumnName(_index), _bIsVisible); + CurUnoDialog.setControlVisible(getTitleName(_index), _bIsVisible); + } + + public void addTextListener(XTextListener _xTextListener) + { + for (int i = 0; i < super.ControlGroupVector.size(); i++) + { + ControlRow curControlRow = (ControlRow) ControlGroupVector.get(i); + XTextComponent xTextBox = curControlRow.xTextComponent; + if ((xTextBox != null) && (_xTextListener != null)) + { + xTextBox.addTextListener(_xTextListener); + } + } + } + + class ControlRow + { + + private XTextComponent xTextComponent; + + public ControlRow(int _index, int _iCompPosY) + { + String slabelname = getColumnName(_index); + String stextfieldname = getTitleName(_index); + + CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", slabelname, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_MULTILINE, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 16, Boolean.TRUE, Integer.valueOf(iLabelPosX), Integer.valueOf(_iCompPosY + 1), UIConsts.INVISIBLESTEP, Short.valueOf(curtabindex++), 30 + }); + + xTextComponent = CurUnoDialog.insertTextField(stextfieldname, 0, null, + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 12, HelpIds.getHelpIdString(curHelpIndex++), Integer.valueOf(iLabelPosX + 30), Integer.valueOf(_iCompPosY), UIConsts.INVISIBLESTEP, Short.valueOf(curtabindex++), Integer.valueOf(iCompWidth - 90 - 20) + }); + } + } + + private String getColumnName(int _index) + { + return SOLABELPREFIX + Integer.toString(_index + 1); + } + + private String getTitleName(int _index) + { + return SOTITLEPREFIX + Integer.toString(_index + 1); + } + + @Override + protected void initializeScrollFields() + { + for (int i = 0; i < fieldnames.length; i++) + { + PropertyValue[] currowproperties = new PropertyValue[2]; + currowproperties[0] = Properties.createProperty(getColumnName(i), fieldnames[i], i); + currowproperties[1] = Properties.createProperty(getTitleName(i), fieldtitles[i], i); //getTitleName(i) + registerControlGroup(currowproperties, i); + } + } + + private void adjustPosSizes() + { + String sLongestFieldName = JavaTools.getlongestArrayItem(fieldnames); + Size aSize = CurUnoDialog.getpreferredLabelSize(getColumnName(0), sLongestFieldName); + double dblMAPConversion = CurUnoDialog.getMAPConversionFactor(getColumnName(0)); + int iFieldNameWidth = getFieldNameWidth(aSize.Width, dblMAPConversion) + 10; + Integer FieldNameWidth = Integer.valueOf(iFieldNameWidth); + Integer TitlePosX = Integer.valueOf(iLabelPosX + iFieldNameWidth + 2); + Integer TitleWidth = Integer.valueOf(iCompPosX + iCompWidth - TitlePosX.intValue() - iScrollBarWidth - 6); + for (short i = 0; i <= ncurfieldcount; i++) + { + CurUnoDialog.setControlProperty(getColumnName(i), PropertyNames.PROPERTY_WIDTH, FieldNameWidth); + CurUnoDialog.setControlProperties(getTitleName(i), new String[] + { + PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_WIDTH + }, new Object[] + { + TitlePosX, TitleWidth + }); + } + CurUnoDialog.setControlProperty("lblColumnNames", PropertyNames.PROPERTY_WIDTH, FieldNameWidth); + CurUnoDialog.setControlProperty("lblColumnTitles", PropertyNames.PROPERTY_POSITION_X, TitlePosX); + } + + public void initialize(String[] _fieldnames, Map<String, String> _fieldtitleset) + { + this.fieldnames = _fieldnames; + this.fieldtitleset = _fieldtitleset; + setFieldTitles(); + initializeScrollFields(); + super.initialize(fieldnames.length); + adjustPosSizes(); + } + + private void setFieldTitles() + { + fieldtitles = new String[fieldnames.length]; + for (int i = 0; i < fieldnames.length; i++) + { + if (this.fieldtitleset.containsKey(fieldnames[i])) + { + Object curvalue = fieldtitleset.get(fieldnames[i]); + if (curvalue != null) + { + fieldtitles[i] = (String) curvalue; + } + else + { + fieldtitles[i] = fieldnames[i]; + } + } + else + { + fieldtitles[i] = fieldnames[i]; + } + } + } + + public String getFieldNameByTitleControl(Object _fieldtitlemodel) + { + String sTitleModelName = (String) Helper.getUnoPropertyValue(_fieldtitlemodel, PropertyNames.PROPERTY_NAME); + String sindex = JavaTools.getSuffixNumber(sTitleModelName); + return (String) CurUnoDialog.getControlProperty(SOLABELPREFIX + sindex, PropertyNames.PROPERTY_LABEL); + } + + public String[] getFieldTitles() + { + PropertyValue[][] titlelist = this.getScrollFieldValues(); + PropertyValue[] currowproperties; + PropertyValue curtitleproperty; + for (int i = 0; i < titlelist.length; i++) + { + currowproperties = titlelist[i]; + curtitleproperty = currowproperties[1]; + fieldtitles[i] = (String) curtitleproperty.Value; + } + refreshtitleset(); + return fieldtitles; + } + + private void refreshtitleset() + { + for (int i = 0; i < fieldnames.length; i++) + { + fieldtitleset.put(fieldnames[i], fieldtitles[i]); + } + } + + private int getFieldNameWidth(int iMAPControlWidth, double dblMAPConversion) + { + int iFieldNameWidth = (int) (1.15 * (iMAPControlWidth) / dblMAPConversion); + double dblAvailableWidth = (iCompWidth - iScrollBarWidth - iRelLabelPosXDist); + if (iFieldNameWidth > (0.5 * (dblAvailableWidth))) + { + iFieldNameWidth = (int) (0.5 * (dblAvailableWidth)); + } + return iFieldNameWidth; + } +} diff --git a/wizards/com/sun/star/wizards/ui/UIConsts.java b/wizards/com/sun/star/wizards/ui/UIConsts.java new file mode 100644 index 000000000..eb57fefa8 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/UIConsts.java @@ -0,0 +1,66 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.wizards.ui; + +public interface UIConsts +{ + Integer INVISIBLESTEP = 99; + String INFOIMAGEURL = "private:graphicrepository/dbaccess/res/exinfo.png"; + /** + * The tabindex of the navigation buttons in a wizard must be assigned a very + * high tabindex because on every step their taborder must appear at the end + */ + short SOFIRSTWIZARDNAVITABINDEX = 30000; + Integer INTEGER_12 = 12; + /**Steps of the QueryWizard + * + */ + int SOGROUPSELECTIONPAGE = 5; + int SOGROUPFILTERPAGE = 6; + int SOTITLESPAGE = 7; + Integer[] INTEGERS = new Integer[] + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 + }; + + class CONTROLTYPE + { + + public static final int BUTTON = 1; + public static final int IMAGECONTROL = 2; + public static final int LISTBOX = 3; + public static final int COMBOBOX = 4; + public static final int CHECKBOX = 5; + public static final int RADIOBUTTON = 6; + public static final int DATEFIELD = 7; + public static final int EDITCONTROL = 8; + public static final int FIXEDLINE = 10; + public static final int FIXEDTEXT = 11; + public static final int FORMATTEDFIELD = 12; + public static final int HYPERTEXT = 14; + public static final int NUMERICFIELD = 15; + public static final int PATTERNFIELD = 16; + public static final int PROGRESSBAR = 17; + public static final int ROADMAP = 18; + public static final int SCROLLBAR = 19; + public static final int TIMEFIELD = 20; + public static final int CURRENCYFIELD = 21; + public static final int UNKNOWN = -1; + } +} diff --git a/wizards/com/sun/star/wizards/ui/UIConsts.py b/wizards/com/sun/star/wizards/ui/UIConsts.py new file mode 100644 index 000000000..e5a4e25e2 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/UIConsts.py @@ -0,0 +1,38 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +class UIConsts(): + + INVISIBLESTEP = 99 + INFOIMAGEURL = "private:graphicrepository/dbaccess/res/exinfo.png" + + ''' + The tabindex of the navigation buttons in a wizard must be assigned a very + high tabindex because on every step their taborder must appear at the end + ''' + SOFIRSTWIZARDNAVITABINDEX = 30000 + + # Steps of the QueryWizard + + SOFIELDSELECTIONPAGE = 1 + SOSORTINGPAGE = 2 + SOFILTERPAGE = 3 + SOAGGREGATEPAGE = 4 + SOGROUPSELECTIONPAGE = 5 + SOGROUPFILTERPAGE = 6 + SOTITLESPAGE = 7 + SOSUMMARYPAGE = 8 diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog.java b/wizards/com/sun/star/wizards/ui/UnoDialog.java new file mode 100644 index 000000000..404f3b619 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/UnoDialog.java @@ -0,0 +1,836 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import com.sun.star.awt.*; +import com.sun.star.beans.XMultiPropertySet; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.*; +import com.sun.star.frame.XFrame; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.*; +import com.sun.star.wizards.common.*; +import java.util.HashMap; + +public class UnoDialog +{ + + public XMultiServiceFactory xMSF; + XMultiServiceFactory MSFDialogModel; + private XNameContainer xDlgNames; + XControlContainer xDlgContainer; + private XNameAccess m_xDlgNameAccess; + public XControl xControl; + public XDialog xDialog; + public XReschedule xReschedule; + public XWindow xWindow; + public XComponent xComponent; + public XInterface xDialogModel; + private XInterface xUnoDialog; + private XVclWindowPeer xVclWindowPeer; + public HashMap<String, Integer> ControlList; + public Resource m_oResource; + public XWindowPeer xWindowPeer = null; + private PeerConfig m_oPeerConfig; + + public UnoDialog(XMultiServiceFactory xMSF) + { + try + { + this.xMSF = xMSF; + ControlList = new HashMap<String, Integer>(); + xDialogModel = (XInterface) xMSF.createInstance("com.sun.star.awt.UnoControlDialogModel"); + XMultiPropertySet xMultiPSetDlg = UnoRuntime.queryInterface(XMultiPropertySet.class, xDialogModel); + xMultiPSetDlg.setPropertyValues(new String[0], new Object[0]); + MSFDialogModel = UnoRuntime.queryInterface(XMultiServiceFactory.class, xDialogModel); + xUnoDialog = (XInterface) xMSF.createInstance("com.sun.star.awt.UnoControlDialog"); + xControl = UnoRuntime.queryInterface(XControl.class, xUnoDialog); + XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class, xDialogModel); + xControl.setModel(xControlModel); + UnoRuntime.queryInterface(XPropertySet.class, xDialogModel); + xDlgContainer = UnoRuntime.queryInterface(XControlContainer.class, xUnoDialog); + xDlgNames = UnoRuntime.queryInterface(XNameContainer.class, xDialogModel); + xComponent = UnoRuntime.queryInterface(XComponent.class, xUnoDialog); + xWindow = UnoRuntime.queryInterface(XWindow.class, xUnoDialog); + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + } + } + + public int getControlKey(Object EventObject, HashMap<String, Integer> ControlList) + { + int iKey; + XControl xContrl = UnoRuntime.queryInterface(XControl.class, EventObject); + XControlModel xControlModel = xContrl.getModel(); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel); + try + { + String sName = (String) xPSet.getPropertyValue(PropertyNames.PROPERTY_NAME); + Integer KeyObject = ControlList.get(sName); + iKey = KeyObject.intValue(); + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + iKey = 2000; + } + return iKey; + } + + private void createPeerConfiguration() + { + m_oPeerConfig = new PeerConfig(this); + } + + public PeerConfig getPeerConfiguration() + { + if (m_oPeerConfig == null) + { + createPeerConfiguration(); + } + return m_oPeerConfig; + } + + XNameAccess getDlgNameAccess() + { + if (m_xDlgNameAccess == null) + { + m_xDlgNameAccess = UnoRuntime.queryInterface(XNameAccess.class, xDialogModel); + } + return m_xDlgNameAccess; + } + public void setControlProperty(String ControlName, String PropertyName, Object PropertyValue) + { + try + { + if (PropertyValue != null) + { + if (!getDlgNameAccess().hasByName(ControlName)) + { + return; + } + Object xControlModel = getDlgNameAccess().getByName(ControlName); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel); + if (AnyConverter.isArray(PropertyValue)) + { + com.sun.star.uno.Type seqType = new com.sun.star.uno.Type(PropertyValue.getClass()); + PropertyValue = new com.sun.star.uno.Any(seqType, PropertyValue); + } + xPSet.setPropertyValue(PropertyName, PropertyValue); + } + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + } + } + + public Resource getResource() + { + return m_oResource; + } + + public void setControlProperties(String ControlName, String[] PropertyNames, Object[] PropertyValues) + { + try + { + if (PropertyValues != null) + { + if (!getDlgNameAccess().hasByName(ControlName)) + { + return; + } + Object xControlModel = getDlgNameAccess().getByName(ControlName); + XMultiPropertySet xMultiPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, xControlModel); + xMultiPSet.setPropertyValues(PropertyNames, PropertyValues); + } + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + } + } + + public Object getControlProperty(String ControlName, String PropertyName) + { + try + { + Object xControlModel = getDlgNameAccess().getByName(ControlName); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel); + return xPSet.getPropertyValue(PropertyName); + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + + + public double getMAPConversionFactor(String ControlName) + { + XControl xControl2 = xDlgContainer.getControl(ControlName); + XView xView = UnoRuntime.queryInterface(XView.class, xControl2); + Size aSize = xView.getSize(); + double dblMAPWidth = ((Integer) Helper.getUnoPropertyValue(xControl2.getModel(), PropertyNames.PROPERTY_WIDTH)).intValue(); + return ((aSize.Width) / dblMAPWidth); + } + + public Size getpreferredLabelSize(String LabelName, String sLabel) + { + XControl xControl2 = xDlgContainer.getControl(LabelName); + XFixedText xFixedText = UnoRuntime.queryInterface(XFixedText.class, xControl2); + String OldText = xFixedText.getText(); + xFixedText.setText(sLabel); + XLayoutConstrains xLayoutConstrains = UnoRuntime.queryInterface(XLayoutConstrains.class, xControl2); + Size aSize = xLayoutConstrains.getPreferredSize(); + xFixedText.setText(OldText); + return aSize; + } + + public void removeSelectedItems(XListBox xListBox) + { + short[] SelList = xListBox.getSelectedItemsPos(); + int Sellen = SelList.length; + for (int i = Sellen - 1; i >= 0; i--) + { + xListBox.removeItems(SelList[i], (short) 1); + } + } + + public static int getListBoxItemCount(XListBox _xListBox) + { + // This function may look ugly, but this is the only way to check the count + // of values in the model,which is always right. + // the control is only a view and could be right or not. + final String[] fieldnames = (String[]) Helper.getUnoPropertyValue(getModel(_xListBox), PropertyNames.STRING_ITEM_LIST); + return fieldnames.length; + } + + public static short getSelectedItemPos(XListBox _xListBox) + { + short ipos[] = (short[]) Helper.getUnoPropertyValue(getModel(_xListBox), PropertyNames.SELECTED_ITEMS); + return ipos[0]; + } + + public static boolean isListBoxSelected(XListBox _xListBox) + { + short ipos[] = (short[]) Helper.getUnoPropertyValue(getModel(_xListBox), PropertyNames.SELECTED_ITEMS); + return ipos.length > 0; + } + + + + public XFixedText insertLabel(String sName, String[] sPropNames, Object[] oPropValues) + { + try + { + Object oFixedText = insertControlModel("com.sun.star.awt.UnoControlFixedTextModel", sName, sPropNames, oPropValues); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, oFixedText); + xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, sName); + Object oLabel = xDlgContainer.getControl(sName); + return UnoRuntime.queryInterface(XFixedText.class, oLabel); + } + catch (java.lang.Exception ex) + { + ex.printStackTrace(); + return null; + } + } + + public XButton insertButton(String sName, int iControlKey, XActionListener xActionListener, String[] sProperties, Object[] sValues) throws com.sun.star.uno.Exception + { + Object oButtonModel = insertControlModel("com.sun.star.awt.UnoControlButtonModel", sName, sProperties, sValues); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, oButtonModel); + xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, sName); + Object objectButton = xDlgContainer.getControl(sName); + XButton xButton = UnoRuntime.queryInterface(XButton.class, objectButton); + if (xActionListener != null) + { + xButton.addActionListener(xActionListener); + } + Integer ControlKey = Integer.valueOf(iControlKey); + if (ControlList != null) + { + ControlList.put(sName, ControlKey); + } + return xButton; + } + + public XScrollBar insertScrollBar(String sName, int iControlKey, XAdjustmentListener xAdjustmentListener, String[] sProperties, Object[] sValues) + { + try + { + Object oScrollModel = insertControlModel("com.sun.star.awt.UnoControlScrollBarModel", sName, sProperties, sValues); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, oScrollModel); + xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, sName); + Object oScrollBar = xDlgContainer.getControl(sName); + XScrollBar xScrollBar = UnoRuntime.queryInterface(XScrollBar.class, oScrollBar); + if (xAdjustmentListener != null) + { + xScrollBar.addAdjustmentListener(xAdjustmentListener); + } + Integer ControlKey = Integer.valueOf(iControlKey); + if (ControlList != null) + { + ControlList.put(sName, ControlKey); + } + return xScrollBar; + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + public XTextComponent insertTextField(String sName, int iControlKey, XTextListener xTextListener, String[] sProperties, Object[] sValues) + { + return insertEditField("com.sun.star.awt.UnoControlEditModel", sName, iControlKey, xTextListener, sProperties, sValues); + } + + public XTextComponent insertFormattedField(String sName, int iControlKey, XTextListener xTextListener, String[] sProperties, Object[] sValues) + { + return insertEditField("com.sun.star.awt.UnoControlFormattedFieldModel", sName, iControlKey, xTextListener, sProperties, sValues); + } + + private XTextComponent insertEditField(String ServiceName, String sName, int iControlKey, XTextListener xTextListener, String[] sProperties, Object[] sValues) + { + try + { + XInterface xTextModel = insertControlModel(ServiceName, sName, sProperties, sValues); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xTextModel); + xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, sName); + XControl xTextField = xDlgContainer.getControl(sName); + XTextComponent xTextBox = UnoRuntime.queryInterface(XTextComponent.class, xTextField); + if (xTextListener != null) + { + xTextBox.addTextListener(xTextListener); + } + Integer ControlKey = Integer.valueOf(iControlKey); + ControlList.put(sName, ControlKey); + return xTextBox; + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + public XListBox insertListBox(String sName, int iControlKey, XActionListener xActionListener, XItemListener xItemListener, String[] sProperties, Object[] sValues) throws com.sun.star.uno.Exception + { + XInterface xListBoxModel = insertControlModel("com.sun.star.awt.UnoControlListBoxModel", sName, sProperties, sValues); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xListBoxModel); + xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, sName); + XControl xControlListBox = xDlgContainer.getControl(sName); + XListBox xListBox = UnoRuntime.queryInterface(XListBox.class, xControlListBox); + if (xItemListener != null) + { + xListBox.addItemListener(xItemListener); + } + if (xActionListener != null) + { + xListBox.addActionListener(xActionListener); + } + Integer ControlKey = Integer.valueOf(iControlKey); + ControlList.put(sName, ControlKey); + return xListBox; + } + + public XRadioButton insertRadioButton(String sName, int iControlKey, XItemListener xItemListener, String[] sProperties, Object[] sValues) + { + XRadioButton xRadioButton = insertRadioButton(sName, iControlKey, sProperties, sValues); + if (xItemListener != null) + { + xRadioButton.addItemListener(xItemListener); + } + return xRadioButton; + } + + public XButton insertRadioButton(String sName, int iControlKey, XActionListener xActionListener, String[] sProperties, Object[] sValues) + { + XRadioButton xRadioButton = insertRadioButton(sName, iControlKey, sProperties, sValues); + XButton xButton = UnoRuntime.queryInterface(XButton.class, xRadioButton); + if (xActionListener != null) + { + xButton.addActionListener(xActionListener); + } + return xButton; + } + + public XRadioButton insertRadioButton(String sName, int iControlKey, String[] sProperties, Object[] sValues) + { + XRadioButton xRadioButton = insertRadioButton(sName, sProperties, sValues); + Integer ControlKey = Integer.valueOf(iControlKey); + ControlList.put(sName, ControlKey); + return xRadioButton; + } + + public XRadioButton insertRadioButton(String sName, String[] sProperties, Object[] sValues) + { + try + { + XInterface oRadioButtonModel = insertControlModel("com.sun.star.awt.UnoControlRadioButtonModel", sName, sProperties, sValues); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, oRadioButtonModel); + xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, sName); + XControl xControlRadioButton = xDlgContainer.getControl(sName); + return UnoRuntime.queryInterface(XRadioButton.class, xControlRadioButton); + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + /** + * The problem with setting the visibility of controls is that changing the current step + * of a dialog will automatically make all controls visible. The PropertyNames.PROPERTY_STEP property always wins against + * the property "visible". Therefore a control meant to be invisible is placed on a step far far away. + * Afterwards the step property of the dialog has to be set with "repaintDialogStep". As the performance + * of that method is very bad it should be used only once for all controls + * @param controlname the name of the control + * @param bIsVisible sets the control visible or invisible + */ + public void setControlVisible(String controlname, boolean bIsVisible) + { + try + { + int iCurDialogStep = AnyConverter.toInt(Helper.getUnoPropertyValue(this.xDialogModel, PropertyNames.PROPERTY_STEP)); + if (bIsVisible) + { + setControlProperty(controlname, PropertyNames.PROPERTY_STEP, Integer.valueOf(iCurDialogStep)); + } + else + { + setControlProperty(controlname, PropertyNames.PROPERTY_STEP, UIConsts.INVISIBLESTEP); + } + } + catch (com.sun.star.lang.IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + } + } + + /** + * repaints the currentDialogStep + */ + public void repaintDialogStep() + { + try + { + int ncurstep = AnyConverter.toInt(Helper.getUnoPropertyValue(this.xDialogModel, PropertyNames.PROPERTY_STEP)); + Helper.setUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_STEP, 99); + Helper.setUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_STEP, Integer.valueOf(ncurstep)); + } + catch (com.sun.star.lang.IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + } + } + + public XInterface insertControlModel(String ServiceName, String sName, String[] sProperties, Object[] sValues) + { + try + { + XInterface xControlModel = (XInterface) MSFDialogModel.createInstance(ServiceName); + Helper.setUnoPropertyValues(xControlModel, sProperties, sValues); + xDlgNames.insertByName(sName, xControlModel); + return xControlModel; + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + public void setFocus(String ControlName) + { + Object oFocusControl = xDlgContainer.getControl(ControlName); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, oFocusControl); + xWindow.setFocus(); + } + + public void selectListBoxItem(XListBox xListBox, short iFieldsSelIndex) + { + if (iFieldsSelIndex > -1) + { + int FieldCount = xListBox.getItemCount(); + if (FieldCount > 0) + { + if (iFieldsSelIndex < FieldCount) + { + xListBox.selectItemPos(iFieldsSelIndex, true); + } + else + { + xListBox.selectItemPos((short) (iFieldsSelIndex - 1), true); + } + } + } + } + + /** deselects a Listbox. MultipleMode is not supported + */ + public static void deselectListBox(XInterface _xBasisListBox) + { + Object oListBoxModel = getModel(_xBasisListBox); + Object sList = Helper.getUnoPropertyValue(oListBoxModel, PropertyNames.STRING_ITEM_LIST); + Helper.setUnoPropertyValue(oListBoxModel, PropertyNames.STRING_ITEM_LIST, new String[] + { + }); + Helper.setUnoPropertyValue(oListBoxModel, PropertyNames.STRING_ITEM_LIST, sList); + } + + public void calculateDialogPosition(Rectangle FramePosSize) + { + // TODO: check if it would be useful or possible to create a dialog peer, that can be used for the messageboxes to + // maintain modality when they pop up. + Rectangle CurPosSize = xWindow.getPosSize(); + int WindowHeight = FramePosSize.Height; + int WindowWidth = FramePosSize.Width; + int DialogWidth = CurPosSize.Width; + int DialogHeight = CurPosSize.Height; + int iXPos = ((WindowWidth / 2) - (DialogWidth / 2)); + int iYPos = ((WindowHeight / 2) - (DialogHeight / 2)); + xWindow.setPosSize(iXPos, iYPos, DialogWidth, DialogHeight, PosSize.POS); + } + + /** + * + * @return 0 for cancel, 1 for ok + */ + public short executeDialog(Rectangle FramePosSize) throws com.sun.star.uno.Exception + { + if (xControl.getPeer() == null) + { + throw new java.lang.IllegalArgumentException("Please create a peer, using your own frame"); + } + calculateDialogPosition(FramePosSize); + if (xWindowPeer == null) + { + createWindowPeer(); + } + xVclWindowPeer = UnoRuntime.queryInterface(XVclWindowPeer.class, xWindowPeer); + this.BisHighContrastModeActivated = Boolean.valueOf(this.isHighContrastModeActivated()); + xDialog = UnoRuntime.queryInterface(XDialog.class, xUnoDialog); + return xDialog.execute(); + } + + /** + * @return 0 for cancel, 1 for ok. + */ + public short executeDialog(XInterface xComponent) throws com.sun.star.uno.Exception + { + XFrame frame = UnoRuntime.queryInterface(XFrame.class, xComponent); + if (frame != null) + { + XWindow w = frame.getComponentWindow(); + if (w != null) + { + return executeDialog(w.getPosSize()); + } + } + + return executeDialog(new Rectangle(0, 0, 640, 400)); + } + + /** + * When possible, use the other executeDialog methods, since + * there may be problems retrieving the actual active frame, + * for example under linux. + * @return 0 for cancel, 1 for ok + */ + public short executeDialog() throws com.sun.star.uno.Exception + { + return executeDialog(Desktop.getActiveFrame(xMSF)); + } + + public void modifyFontWeight(String ControlName, float FontWeight) + { + FontDescriptor oFontDesc = new FontDescriptor(); + oFontDesc.Weight = FontWeight; + setControlProperty(ControlName, PropertyNames.FONT_DESCRIPTOR, oFontDesc); + } + + /** + * create a peer for this dialog, using the given peer as a parent. + */ + public XWindowPeer createWindowPeer(XWindowPeer parentPeer) throws com.sun.star.uno.Exception + { + xWindow.setVisible(false); + Object tk = xMSF.createInstance("com.sun.star.awt.Toolkit"); + if (parentPeer == null) + { + parentPeer = UnoRuntime.queryInterface(XToolkit.class, tk).getDesktopWindow(); + } + XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, tk); + xReschedule = UnoRuntime.queryInterface(XReschedule.class, xToolkit); + // TEUER! + xControl.createPeer(xToolkit, parentPeer); + xWindowPeer = xControl.getPeer(); + return xControl.getPeer(); + } + + /** + * Creates a peer for this dialog, using the active OO frame as the parent window. + */ + public XWindowPeer createWindowPeer() throws com.sun.star.uno.Exception + { + return createWindowPeer(null); + } + + public static Object getModel(Object control) + { + XControl xControl = UnoRuntime.queryInterface(XControl.class, control); + return xControl.getModel(); + } + + public static void setEnabled(Object control, boolean enabled) + { + setEnabled(control, enabled ? Boolean.TRUE : Boolean.FALSE); + } + + private static void setEnabled(Object control, Boolean enabled) + { + Helper.setUnoPropertyValue(getModel(control), PropertyNames.PROPERTY_ENABLED, enabled); + } + + /** + * @param oControlModel the model of a control + * @return the LabelType according to UIConsts.CONTROLTYPE + */ + private static int getControlModelType(Object oControlModel) + { + XServiceInfo xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, oControlModel); + if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlFixedTextModel")) + { + return UIConsts.CONTROLTYPE.FIXEDTEXT; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlButtonModel")) + { + return UIConsts.CONTROLTYPE.BUTTON; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlCurrencyFieldModel")) + { + return UIConsts.CONTROLTYPE.CURRENCYFIELD; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlDateFieldModel")) + { + return UIConsts.CONTROLTYPE.DATEFIELD; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlFixedLineModel")) + { + return UIConsts.CONTROLTYPE.FIXEDLINE; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlFormattedFieldModel")) + { + return UIConsts.CONTROLTYPE.FORMATTEDFIELD; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlRoadmapModel")) + { + return UIConsts.CONTROLTYPE.ROADMAP; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlNumericFieldModel")) + { + return UIConsts.CONTROLTYPE.NUMERICFIELD; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlPatternFieldModel")) + { + return UIConsts.CONTROLTYPE.PATTERNFIELD; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlHyperTextModel")) + { + return UIConsts.CONTROLTYPE.HYPERTEXT; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlProgressBarModel")) + { + return UIConsts.CONTROLTYPE.PROGRESSBAR; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlTimeFieldModel")) + { + return UIConsts.CONTROLTYPE.TIMEFIELD; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlImageControlModel")) + { + return UIConsts.CONTROLTYPE.IMAGECONTROL; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlRadioButtonModel")) + { + return UIConsts.CONTROLTYPE.RADIOBUTTON; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlCheckBoxModel")) + { + return UIConsts.CONTROLTYPE.CHECKBOX; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlEditModel")) + { + return UIConsts.CONTROLTYPE.EDITCONTROL; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlComboBoxModel")) + { + return UIConsts.CONTROLTYPE.COMBOBOX; + } + else if (xServiceInfo.supportsService("com.sun.star.awt.UnoControlListBoxModel")) // TODO Comboboxes?? + { + return UIConsts.CONTROLTYPE.LISTBOX; + } + else + { + return UIConsts.CONTROLTYPE.UNKNOWN; + } + } + + /** + * @return the name of the property that contains the value of a controlmodel + */ + public static String getDisplayProperty(Object oControlModel) + { + int itype = getControlModelType(oControlModel); + return getDisplayProperty(itype); + } + + /** + * @param itype The type of the control conforming to UIConst.ControlType + * @return the name of the property that contains the value of a controlmodel + */ + private static String getDisplayProperty(int itype) + { + switch (itype) + { + case UIConsts.CONTROLTYPE.FIXEDTEXT: + return PropertyNames.PROPERTY_LABEL; + case UIConsts.CONTROLTYPE.BUTTON: + return PropertyNames.PROPERTY_LABEL; + case UIConsts.CONTROLTYPE.FIXEDLINE: + return PropertyNames.PROPERTY_LABEL; + case UIConsts.CONTROLTYPE.NUMERICFIELD: + return "Value"; + case UIConsts.CONTROLTYPE.CURRENCYFIELD: + return "Value"; + case UIConsts.CONTROLTYPE.FORMATTEDFIELD: + return "EffectiveValue"; + case UIConsts.CONTROLTYPE.DATEFIELD: + return "Date"; + case UIConsts.CONTROLTYPE.TIMEFIELD: + return "Time"; + case UIConsts.CONTROLTYPE.SCROLLBAR: + return "ScrollValue"; + case UIConsts.CONTROLTYPE.PROGRESSBAR: + return "ProgressValue"; + case UIConsts.CONTROLTYPE.IMAGECONTROL: + return PropertyNames.PROPERTY_IMAGEURL; + case UIConsts.CONTROLTYPE.RADIOBUTTON: + return PropertyNames.PROPERTY_STATE; + case UIConsts.CONTROLTYPE.CHECKBOX: + return PropertyNames.PROPERTY_STATE; + case UIConsts.CONTROLTYPE.EDITCONTROL: + return "Text"; + case UIConsts.CONTROLTYPE.COMBOBOX: + return "Text"; + case UIConsts.CONTROLTYPE.PATTERNFIELD: + return "Text"; + case UIConsts.CONTROLTYPE.LISTBOX: + return PropertyNames.SELECTED_ITEMS; + default: + return PropertyNames.EMPTY_STRING; + } + } + + public void addResourceHandler() + { + m_oResource = new Resource(xMSF); + } + + public static short setInitialTabindex(int _istep) + { + return (short) (_istep * 100); + } + private Boolean BisHighContrastModeActivated = null; + + private boolean isHighContrastModeActivated() + { + if (xVclWindowPeer != null) + { + if (BisHighContrastModeActivated == null) + { + int nUIColor; + try + { + nUIColor = AnyConverter.toInt(this.xVclWindowPeer.getProperty("DisplayBackgroundColor")); + } + catch (IllegalArgumentException e) + { + e.printStackTrace(System.err); + return false; + } + //TODO: The following methods could be wrapped in an own class implementation + int nRed = getRedColorShare(nUIColor); + int nGreen = getGreenColorShare(nUIColor); + int nBlue = getBlueColorShare(nUIColor); + int nLuminance = ((nBlue * 28 + nGreen * 151 + nRed * 77) / 256); + boolean bisactivated = (nLuminance <= 25); + BisHighContrastModeActivated = Boolean.valueOf(bisactivated); + return bisactivated; + } + else + { + return BisHighContrastModeActivated.booleanValue(); + } + } + else + { + return false; + } + } + + private static int getRedColorShare(int _nColor) + { + int nRed = _nColor / 65536; + return nRed; + } + + private static int getGreenColorShare(int _nColor) + { + int nRedModulo = _nColor % 65536; + int nGreen = nRedModulo / 256; + return nGreen; + } + + private static int getBlueColorShare(int _nColor) + { + int nRedModulo = _nColor % 65536; + int nGreenModulo = (nRedModulo % 256); + int nBlue = nGreenModulo; + return nBlue; + } + + public static short getListBoxLineCount() + { + return (short)20; + } +} diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog.py b/wizards/com/sun/star/wizards/ui/UnoDialog.py new file mode 100644 index 000000000..37376f1ee --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/UnoDialog.py @@ -0,0 +1,254 @@ +# +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import uno +import traceback +from .PeerConfig import PeerConfig +from .UIConsts import UIConsts +from ..common.PropertyNames import PropertyNames + +from com.sun.star.awt import Rectangle +from com.sun.star.awt.PosSize import POS + +class UnoDialog(object): + + createDict = False + dictProperties = None + BisHighContrastModeActivated = None + xVclWindowPeer = None + + def __init__(self, xMSF, PropertyNames, PropertyValues): + try: + self.xMSF = xMSF + self.ControlList = {} + self.xDialogModel = xMSF.createInstance( + "com.sun.star.awt.UnoControlDialogModel") + self.xUnoDialog = xMSF.createInstance( + "com.sun.star.awt.UnoControlDialog") + self.xUnoDialog.setModel(self.xDialogModel) + self.m_oPeerConfig = None + self.xWindowPeer = None + except Exception: + traceback.print_exc() + + # repaints the currentDialogStep + def repaintDialogStep(self): + try: + ncurstep = int(self.xDialogModel.Step) + self.xDialogModel.Step = 99 + self.xDialogModel.Step = ncurstep + except Exception: + traceback.print_exc() + + def insertControlModel(self, serviceName, componentName, sPropNames, oPropValues): + try: + xControlModel = self.xDialogModel.createInstance(serviceName) + uno.invoke(xControlModel, "setPropertyValues", + (sPropNames, oPropValues)) + self.xDialogModel.insertByName(componentName, xControlModel) + xControlModel.Name = componentName + except Exception: + traceback.print_exc() + + aObj = self.xUnoDialog.getControl(componentName) + return aObj + + def setFocus(self, ControlName): + oFocusControl = self.xUnoDialog.getControl(ControlName) + oFocusControl.setFocus() + + def calculateDialogPosition(self, FramePosSize): + # Todo:check if it would be useful or possible to create a dialog peer + # that can be used for the messageboxes to + # maintain modality when they pop up. + CurPosSize = self.xUnoDialog.getPosSize() + WindowHeight = FramePosSize.Height + WindowWidth = FramePosSize.Width + DialogWidth = CurPosSize.Width + DialogHeight = CurPosSize.Height + iXPos = ((WindowWidth / 2) - (DialogWidth / 2)) + iYPos = ((WindowHeight / 2) - (DialogHeight / 2)) + self.xUnoDialog.setPosSize( + iXPos, iYPos, DialogWidth, DialogHeight, POS) + + ''' + @param FramePosSize + @return 0 for cancel, 1 for ok + @throws com.sun.star.uno.Exception + ''' + + def executeDialog(self, FramePosSize): + if self.xUnoDialog.getPeer() is None: + raise AttributeError( + "Please create a peer, using your own frame") + + self.calculateDialogPosition(FramePosSize) + + if self.xWindowPeer is None: + self.createWindowPeer() + + self.xVclWindowPeer = self.xWindowPeer + self.BisHighContrastModeActivated = self.isHighContrastModeActivated() + return self.xUnoDialog.execute() + + def setVisible(self, parent): + self.calculateDialogPosition(parent.xUnoDialog.getPosSize()) + if self.xWindowPeer == None: + self.createWindowPeer() + + self.xUnoDialog.setVisible(True) + + ''' + @param XComponent + @return 0 for cancel, 1 for ok + @throws com.sun.star.uno.Exception + ''' + + def executeDialogFromComponent(self, xComponent): + if xComponent is not None: + w = xComponent.ComponentWindow + if w is not None: + return self.executeDialog(w.PosSize) + + return self.executeDialog( Rectangle (0, 0, 640, 400)) + + ''' + create a peer for this + dialog, using the given + peer as a parent. + @param parentPeer + @return + @throws java.lang.Exception + ''' + + def createWindowPeer(self, parentPeer=None): + self.xUnoDialog.setVisible(False) + xToolkit = self.xMSF.createInstance("com.sun.star.awt.Toolkit") + if parentPeer is None: + parentPeer = xToolkit.getDesktopWindow() + + self.xUnoDialog.createPeer(xToolkit, parentPeer) + self.xWindowPeer = self.xUnoDialog.getPeer() + return self.xUnoDialog.getPeer() + + @classmethod + def setEnabled(self, control, enabled): + control.Model.Enabled = enabled + + @classmethod + def getModel(self, control): + return control.getModel() + + @classmethod + def getDisplayProperty(self, xServiceInfo): + if xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlFixedTextModel"): + return PropertyNames.PROPERTY_LABEL + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlButtonModel"): + return PropertyNames.PROPERTY_LABEL + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlCurrencyFieldModel"): + return "Value" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlDateFieldModel"): + return "Date" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlFixedLineModel"): + return PropertyNames.PROPERTY_LABEL + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlFormattedFieldModel"): + return "EffectiveValue" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlNumericFieldModel"): + return "Value" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlPatternFieldModel"): + return "Text" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlProgressBarModel"): + return "ProgressValue" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlTimeFieldModel"): + return "Time" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlImageControlModel"): + return PropertyNames.PROPERTY_IMAGEURL + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlRadioButtonModel"): + return PropertyNames.PROPERTY_STATE + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlCheckBoxModel"): + return PropertyNames.PROPERTY_STATE + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlEditModel"): + return "Text" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlComboBoxModel"): + return "Text" + elif xServiceInfo.supportsService( + "com.sun.star.awt.UnoControlListBoxModel"): + return "SelectedItems" + else: + return "" + + def isHighContrastModeActivated(self): + if (self.xVclWindowPeer is not None): + if (self.BisHighContrastModeActivated is None): + nUIColor = 0 + try: + nUIColor = self.xVclWindowPeer.getProperty("DisplayBackgroundColor") + except Exception: + traceback.print_exc() + return False + + # TODO: The following methods could be wrapped in an own class implementation + nRed = self.getRedColorShare(nUIColor) + nGreen = self.getGreenColorShare(nUIColor) + nBlue = self.getBlueColorShare(nUIColor) + nLuminance = ((nBlue * 28 + nGreen * 151 + nRed * 77) / 256) + bisactivated = (nLuminance <= 25) + self.BisHighContrastModeActivated = bool(bisactivated) + return bisactivated; + else: + return self.BisHighContrastModeActivated + else: + return False + + + def getRedColorShare(self, _nColor): + nRed = _nColor / 65536 + nRedModulo = _nColor % 65536 + nGreen = nRedModulo / 256 + nGreenModulo = (nRedModulo % 256) + nBlue = nGreenModulo + return nRed + + def getGreenColorShare(self, _nColor): + nRed = _nColor / 65536 + nRedModulo = _nColor % 65536 + nGreen = nRedModulo / 256 + return nGreen + + def getBlueColorShare(self, _nColor): + nRed = _nColor / 65536 + nRedModulo = _nColor % 65536 + nGreen = nRedModulo / 256 + nGreenModulo = (nRedModulo % 256) + nBlue = nGreenModulo + return nBlue diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog2.java b/wizards/com/sun/star/wizards/ui/UnoDialog2.java new file mode 100644 index 000000000..24064585a --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/UnoDialog2.java @@ -0,0 +1,195 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import com.sun.star.awt.XActionListener; +import com.sun.star.awt.XButton; +import com.sun.star.awt.XCheckBox; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XItemListener; +import com.sun.star.awt.XListBox; +import com.sun.star.awt.XRadioButton; +import com.sun.star.awt.XTextComponent; +import com.sun.star.awt.XTextListener; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.wizards.common.Desktop; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.common.SystemDialog; + +/** + * This class contains convenience methods for inserting components to a dialog. + * <p>It was created for use with the automatic conversion of Basic XML Dialog + * description files to a Java class which builds the same dialog through the UNO API.</p> + * <p>It uses an Event-Listener method, which calls a method through reflection + * when an event on a component is triggered. + * see the classes CommonListener, MethodInvocation for details.</p> + */ +public class UnoDialog2 extends UnoDialog +{ + + public UnoDialog2(XMultiServiceFactory xmsf) + { + super(xmsf); + } + + public XButton insertButton(String sName, XActionListener actionListener, String[] sPropNames, Object[] oPropValues) + { + XButton xButton = (XButton) insertControlModel2("com.sun.star.awt.UnoControlButtonModel", sName, sPropNames, oPropValues, XButton.class); + + if (actionListener != null) + { + xButton.addActionListener(actionListener); + } + return xButton; + } + + public XButton insertImageButton(String sName, com.sun.star.awt.XActionListener actionPerformed, String[] sPropNames, Object[] oPropValues) + { + XButton xButton = (XButton) insertControlModel2("com.sun.star.awt.UnoControlButtonModel", sName, sPropNames, oPropValues, XButton.class); + + if (actionPerformed != null) + { + xButton.addActionListener(actionPerformed); + } + return xButton; + } + + public XCheckBox insertCheckBox(String sName, XItemListener itemListener, String[] sPropNames, Object[] oPropValues) + { + XCheckBox xCheckBox = (XCheckBox) insertControlModel2("com.sun.star.awt.UnoControlCheckBoxModel", sName, sPropNames, oPropValues, XCheckBox.class); + + if (itemListener != null) + { + xCheckBox.addItemListener(itemListener); + } + return xCheckBox; + } + + public XListBox insertListBox(String sName, XActionListener actionListener, XItemListener itemListener, String[] sPropNames, Object[] oPropValues) + { + XListBox xListBox = (XListBox) insertControlModel2("com.sun.star.awt.UnoControlListBoxModel", sName, sPropNames, oPropValues, XListBox.class); + if (actionListener != null) + { + xListBox.addActionListener(actionListener); + } + if (itemListener != null) + { + xListBox.addItemListener(itemListener); + } + return xListBox; + } + + public XRadioButton insertRadioButton(String sName, XItemListener itemListener, String[] sPropNames, Object[] oPropValues) + { + XRadioButton xRadioButton = (XRadioButton) insertControlModel2("com.sun.star.awt.UnoControlRadioButtonModel", sName, sPropNames, oPropValues, XRadioButton.class); + if (itemListener != null) + { + xRadioButton.addItemListener(itemListener); + } + return xRadioButton; + } + + + + public XTextComponent insertTextField(String sName, XTextListener textListener, String[] sPropNames, Object[] oPropValues) + { + return (XTextComponent) insertEditField(sName, textListener, "com.sun.star.awt.UnoControlEditModel", sPropNames, oPropValues, XTextComponent.class); + } + + private XControl insertImage(String sName, String[] sPropNames, Object[] oPropValues) + { + return (XControl) insertControlModel2("com.sun.star.awt.UnoControlImageControlModel", sName, sPropNames, oPropValues, XControl.class); + } + + public XControl insertInfoImage(int _posx, int _posy, int _iStep) + { + XControl xImgControl = insertImage(Desktop.getUniqueName(getDlgNameAccess(), "imgHint"), + new String[] + { + PropertyNames.PROPERTY_BORDER, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_IMAGEURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, "ScaleImage", PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Short.valueOf((short) 0), 10, UIConsts.INFOIMAGEURL, Integer.valueOf(_posx), Integer.valueOf(_posy), Boolean.FALSE, Integer.valueOf(_iStep), 10 + }); + super.getPeerConfiguration().setImageUrl(getModel(xImgControl), UIConsts.INFOIMAGEURL); + return xImgControl; + } + + /** + * This method is used for creating Edit, Currency, Date, Formatted, Pattern, File + * and Time edit components. + */ + private Object insertEditField(String sName, XTextListener textListener, String sModelClass, String[] sPropNames, Object[] oPropValues, Class<? extends XInterface> type) + { + XTextComponent xField = (XTextComponent) insertControlModel2(sModelClass, sName, sPropNames, oPropValues, XTextComponent.class); + if (textListener != null) + { + xField.addTextListener(textListener); + } + return UnoRuntime.queryInterface(type, xField); + } + + public XControl insertFixedLine(String sName, String[] sPropNames, Object[] oPropValues) + { + Object oLine = insertControlModel2("com.sun.star.awt.UnoControlFixedLineModel", sName, sPropNames, oPropValues); + return UnoRuntime.queryInterface(XControl.class, oLine); + } + + + + + + + + private Object insertControlModel2(String serviceName, String componentName, String[] sPropNames, Object[] oPropValues) + { + try + { + XInterface xControlModel = insertControlModel(serviceName, componentName, new String[] + { + }, new Object[] + { + }); + Helper.setUnoPropertyValues(xControlModel, sPropNames, oPropValues); + Helper.setUnoPropertyValue(xControlModel, PropertyNames.PROPERTY_NAME, componentName); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + return xDlgContainer.getControl(componentName); + } + + private Object insertControlModel2(String serviceName, String componentName, String[] sPropNames, Object[] oPropValues, Class<? extends XInterface> type) + { + return UnoRuntime.queryInterface(type, insertControlModel2(serviceName, componentName, sPropNames, oPropValues)); + } + + + + + + public int showMessageBox(String windowServiceName, int windowAttribute, String MessageText) + { + return SystemDialog.showMessageBox(xMSF, this.xControl.getPeer(), windowServiceName, windowAttribute, MessageText); + } +} diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog2.py b/wizards/com/sun/star/wizards/ui/UnoDialog2.py new file mode 100644 index 000000000..42aee8c5f --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/UnoDialog2.py @@ -0,0 +1,204 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +from .UnoDialog import UnoDialog, UIConsts +from ..common.Desktop import Desktop +from ..common.PropertyNames import PropertyNames +from ..common.SystemDialog import SystemDialog +from .event.CommonListener import ItemListenerProcAdapter, \ + ActionListenerProcAdapter, TextListenerProcAdapter, \ + AdjustmentListenerProcAdapter + +''' +This class contains convenience methods for inserting components to a dialog. +It was created for use with the automatic conversion of Basic XML Dialog +description files to a Java class which builds +the same dialog through the UNO API.<br/> +It uses an Event-Listener method, which calls a method through reflection +when an event on a component is triggered. +see the classes CommonListener for details +''' + +class UnoDialog2(UnoDialog): + + ''' + Override this method to return another listener. + @return + ''' + + def __init__(self, xmsf): + super(UnoDialog2,self).__init__(xmsf,(), ()) + ControlList = {} + + def insertButton( + self, sName, actionPerformed, sPropNames, oPropValues, listener): + xButton = self.insertControlModel( + "com.sun.star.awt.UnoControlButtonModel", + sName, sPropNames, oPropValues) + if actionPerformed is not None: + actionPerformed = getattr(listener, actionPerformed) + xButton.addActionListener( + ActionListenerProcAdapter(actionPerformed)) + + return xButton + + def insertCheckBox( + self, sName, itemChanged, sPropNames, oPropValues, listener): + xCheckBox = self.insertControlModel( + "com.sun.star.awt.UnoControlCheckBoxModel", + sName, sPropNames, oPropValues) + if itemChanged is not None: + itemChanged = getattr(listener, itemChanged) + xCheckBox.addItemListener(ItemListenerProcAdapter(itemChanged)) + + return xCheckBox + + def insertComboBox( + self, sName, actionPerformed, itemChanged, + textChanged, sPropNames, oPropValues, listener): + xComboBox = self.insertControlModel( + "com.sun.star.awt.UnoControlComboBoxModel", + sName, sPropNames, oPropValues) + if actionPerformed is not None: + actionPerformed = getattr(listener, actionPerformed) + xComboBox.addActionListener( + ActionListenerProcAdapter(actionPerformed)) + + if itemChanged is not None: + itemChanged = getattr(listener, itemChanged) + xComboBox.addItemListener(ItemListenerProcAdapter(itemChanged)) + + if textChanged is not None: + textChanged = getattr(listener, textChanged) + xComboBox.addTextListener(TextListenerProcAdapter(textChanged)) + + return xComboBox + + def insertListBox( + self, sName, actionPerformed, itemChanged, + sPropNames, oPropValues, listener): + xListBox = self.insertControlModel( + "com.sun.star.awt.UnoControlListBoxModel", + sName, sPropNames, oPropValues) + + if itemChanged is not None: + itemChanged = getattr(listener, itemChanged) + xListBox.addItemListener(ItemListenerProcAdapter(itemChanged)) + + return xListBox + + def insertRadioButton( + self, sName, itemChanged, sPropNames, oPropValues, listener): + xRadioButton = self.insertControlModel( + "com.sun.star.awt.UnoControlRadioButtonModel", + sName, sPropNames, oPropValues) + if itemChanged is not None: + itemChanged = getattr(listener, itemChanged) + xRadioButton.addItemListener( + ItemListenerProcAdapter(itemChanged)) + + return xRadioButton + + def insertTextField( + self, sName, sTextChanged, sPropNames, oPropValues, listener): + return self.insertEditField( + sName, sTextChanged, "com.sun.star.awt.UnoControlEditModel", + sPropNames, oPropValues, listener) + + def insertImage(self, sName, sPropNames, oPropValues): + return self.insertControlModel( + "com.sun.star.awt.UnoControlImageControlModel", + sName, sPropNames, oPropValues) + + def insertInfoImage(self, _posx, _posy, _iStep): + xImgControl = self.insertImage( + Desktop.getUniqueName(self.xDialogModel, "imgHint"), + ("Border", + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_IMAGEURL, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, "ScaleImage", + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_WIDTH), + (0, 10, UIConsts.INFOIMAGEURL, _posx, _posy, False, _iStep, 10)) + return xImgControl + + ''' + This method is used for creating Edit, Currency, Date, Formatted, + Pattern, File and Time edit components. + ''' + + def insertEditField( + self, sName, sTextChanged, sModelClass, + sPropNames, oPropValues, listener): + xField = self.insertControlModel(sModelClass, + sName, sPropNames, oPropValues) + if sTextChanged is not None: + sTextChanged = getattr(listener, sTextChanged) + xField.addTextListener(TextListenerProcAdapter(sTextChanged)) + return xField + + def insertDateField( + self, sName, sTextChanged, sPropNames, oPropValues, listener): + return self.insertEditField( + sName, sTextChanged, + "com.sun.star.awt.UnoControlDateFieldModel", + sPropNames, oPropValues, listener) + + def insertNumericField( + self, sName, sTextChanged, sPropNames, oPropValues, listener): + return self.insertEditField( + sName, sTextChanged, + "com.sun.star.awt.UnoControlNumericFieldModel", + sPropNames, oPropValues, listener) + + def insertTimeField( + self, sName, sTextChanged, sPropNames, oPropValues, listener): + return self.insertEditField( + sName, sTextChanged, + "com.sun.star.awt.UnoControlTimeFieldModel", + sPropNames, oPropValues, listener) + + def insertFixedLine(self, sName, sPropNames, oPropValues): + oLine = self.insertControlModel( + "com.sun.star.awt.UnoControlFixedLineModel", + sName, sPropNames, oPropValues) + return oLine + + def insertLabel(self, sName, sPropNames, oPropValues): + oFixedText = self.insertControlModel( + "com.sun.star.awt.UnoControlFixedTextModel", + sName, sPropNames, oPropValues) + return oFixedText + + def insertScrollBar(self, sName, sPropNames, oPropValues, + iControlKey, listener): + oScrollBar = self.insertControlModel( + "com.sun.star.awt.UnoControlScrollBarModel", + sName, sPropNames, oPropValues) + if listener is not None: + method = getattr(listener, "scrollControls") + oScrollBar.addAdjustmentListener( + AdjustmentListenerProcAdapter(method)) + if self.ControlList is not None: + self.ControlList[sName] = iControlKey + return oScrollBar + + def showMessageBox(self, windowServiceName, windowAttribute, MessageText): + return SystemDialog.showMessageBox( + super().xMSF, self.xControl.Peer, + windowServiceName, windowAttribute, MessageText) diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.java b/wizards/com/sun/star/wizards/ui/WizardDialog.java new file mode 100644 index 000000000..69fbf5ab7 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/WizardDialog.java @@ -0,0 +1,685 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui; + +import java.beans.VetoableChangeListener; +import com.sun.star.awt.ActionEvent; +import com.sun.star.awt.FontDescriptor; +import com.sun.star.awt.PushButtonType; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XItemEventBroadcaster; +import com.sun.star.awt.XTopWindow; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XIndexContainer; +import com.sun.star.frame.TerminationVetoException; +import com.sun.star.frame.XTerminateListener; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.wizards.common.Desktop; +import com.sun.star.wizards.common.HelpIds; +import com.sun.star.wizards.common.Helper; +import com.sun.star.wizards.common.PropertyNames; +import com.sun.star.wizards.common.Resource; +import com.sun.star.wizards.ui.event.XActionListenerAdapter; +import com.sun.star.wizards.ui.event.XItemListenerAdapter; + +public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeListener, XTerminateListener +{ + + private static final int iButtonWidth = 50; + private int nNewStep = 1; + private int nOldStep = 1; + private int nMaxStep = 1; + private String[] sRMItemLabels; + private Object oRoadmap; + private XSingleServiceFactory xSSFRoadmap; + public XIndexContainer xIndexContRoadmap; + private final Resource oWizardResource; + private final int hid; + private boolean bTerminateListenermustberemoved = true; + + /** Creates a new instance of WizardDialog + * the hid is used as following : + * "HID:(hid)" - the dialog + * "HID:(hid+1) - the help button + * "HID:(hid+2)" - the back button + * "HID:(hid+3)" - the next button + * "HID:(hid+4)" - the create button + * "HID:(hid+5)" - the cancel button + */ + public WizardDialog(XMultiServiceFactory xMSF, int hid_) + { + super(xMSF); + hid = hid_; + oWizardResource = new Resource(xMSF); + oWizardResource.getResText("RID_DB_COMMON_33"); + } + + @Override + public Resource getResource() + { + return oWizardResource; + } + + private void activate() + { + try + { + XTopWindow top = UnoRuntime.queryInterface(XTopWindow.class, xWindow); + if (top != null) + { + top.toFront(); + } + } + catch (Exception ex) + { + // do nothing; + } + } + + public void setMaxStep(int i) + { + nMaxStep = i; + } + + public int getNewStep() + { + return nNewStep; + } + + /** + * @see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent) + */ + public void vetoableChange(java.beans.PropertyChangeEvent arg0) + { + nNewStep = nOldStep; + } + + public void setRoadmapInteractive(boolean _bInteractive) + { + Helper.setUnoPropertyValue(oRoadmap, "Activated", Boolean.valueOf(_bInteractive)); + } + + public void setRoadmapComplete(boolean bComplete) + { + Helper.setUnoPropertyValue(oRoadmap, "Complete", Boolean.valueOf(bComplete)); + } + + private boolean isRoadmapComplete() + { + try + { + return AnyConverter.toBoolean(Helper.getUnoPropertyValue(oRoadmap, "Complete")); + } + catch (IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + return false; + } + } + + public void setCurrentRoadmapItemID(short ID) + { + if (oRoadmap != null) + { + int nCurItemID = getCurrentRoadmapItemID(); + if (nCurItemID != ID) + { + Helper.setUnoPropertyValue(oRoadmap, "CurrentItemID", Short.valueOf(ID)); + } + } + } + + private int getCurrentRoadmapItemID() + { + try + { + return AnyConverter.toInt(Helper.getUnoPropertyValue(oRoadmap, "CurrentItemID")); + } + catch (com.sun.star.lang.IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + return -1; + } + } + + public void addRoadmap() + { + try + { + int iDialogHeight = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, PropertyNames.PROPERTY_HEIGHT)).intValue(); + + // the roadmap control has got no real TabIndex ever + // that is not correct, but changing this would need time, so it is used + // without TabIndex as before + oRoadmap = insertControlModel("com.sun.star.awt.UnoControlRoadmapModel", "rdmNavi", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + "Tabstop", + PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Integer.valueOf(iDialogHeight - 26), + 0, + 0, + 0, + Short.valueOf((short)0), + Boolean.TRUE, + 85 + }); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, oRoadmap); + xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, "rdmNavi"); + + xSSFRoadmap = UnoRuntime.queryInterface(XSingleServiceFactory.class, oRoadmap); + xIndexContRoadmap = UnoRuntime.queryInterface(XIndexContainer.class, oRoadmap); + + XControl xRoadmapControl = this.xDlgContainer.getControl("rdmNavi"); + XItemEventBroadcaster xRoadmapBroadcaster = UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRoadmapControl); + xRoadmapBroadcaster.addItemListener(new XItemListenerAdapter() { + @Override + public void itemStateChanged(com.sun.star.awt.ItemEvent itemEvent) { + try + { + nNewStep = itemEvent.ItemId; + nOldStep = AnyConverter.toInt(Helper.getUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_STEP)); + if (nNewStep != nOldStep) + { + switchToStep(); + } + } + catch (com.sun.star.lang.IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + } + } + }); + + Helper.setUnoPropertyValue(oRoadmap, "Text", oWizardResource.getResText("RID_COMMON_16")); + } + catch (java.lang.Exception jexception) + { + jexception.printStackTrace(System.err); + } + } + + public void setRMItemLabels(Resource _oResource) + { + sRMItemLabels = new String[nMaxStep]; + for (int i = 0; i < nMaxStep; ++i) { + sRMItemLabels[i] = _oResource.getResText("RID_QUERY_" + String.valueOf(i + 80)); + } + } + + public int insertRoadmapItem(int _Index, boolean _bEnabled, int _LabelID, int _CurItemID) + { + return insertRoadmapItem(_Index, _bEnabled, sRMItemLabels[_LabelID], _CurItemID); + } + + public int insertRoadmapItem(int Index, boolean _bEnabled, String _sLabel, int _CurItemID) + { + try + { + Object oRoadmapItem = xSSFRoadmap.createInstance(); + Helper.setUnoPropertyValue(oRoadmapItem, PropertyNames.PROPERTY_LABEL, _sLabel); + Helper.setUnoPropertyValue(oRoadmapItem, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bEnabled)); + Helper.setUnoPropertyValue(oRoadmapItem, "ID", Integer.valueOf(_CurItemID)); + xIndexContRoadmap.insertByIndex(Index, oRoadmapItem); + return Index + 1; + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + return -1; + } + } + + public int getRMItemCount() + { + return xIndexContRoadmap.getCount(); + } + + public XInterface getRoadmapItemByID(int _ID) + { + try + { + int CurID; + XInterface CurRoadmapItem; + for (int i = 0; i < xIndexContRoadmap.getCount(); i++) + { + CurRoadmapItem = (XInterface) xIndexContRoadmap.getByIndex(i); + CurID = AnyConverter.toInt(Helper.getUnoPropertyValue(CurRoadmapItem, "ID")); + if (CurID == _ID) + { + return CurRoadmapItem; + } + } + return null; + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + public boolean switchToStep(int _nOldStep, int _nNewStep) + { + nOldStep = _nOldStep; + nNewStep = _nNewStep; + return switchToStep(); + } + + private boolean switchToStep() + { + leaveStep(nOldStep, nNewStep); + if (nNewStep != nOldStep) + { + if (nNewStep == nMaxStep) + { + setControlProperty("btnWizardNext", "DefaultButton", Boolean.FALSE); + setControlProperty("btnWizardFinish", "DefaultButton", Boolean.TRUE); + } + else + { + setControlProperty("btnWizardNext", "DefaultButton", Boolean.TRUE); + setControlProperty("btnWizardFinish", "DefaultButton", Boolean.FALSE); + } + changeToStep(nNewStep); + enterStep(nOldStep, nNewStep); + return true; + } + return false; + } + + abstract protected void leaveStep(int nOldStep, int nNewStep); + + abstract protected void enterStep(int nOldStep, int nNewStep); + + private void changeToStep(int nNewStep) + { + Helper.setUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_STEP, Integer.valueOf(nNewStep)); + setCurrentRoadmapItemID((short) (nNewStep)); + enableNextButton(getNextAvailableStep() > 0); + enableBackButton(nNewStep != 1); + } + + + public void drawNaviBar() + { + + try + { + short curtabindex = UIConsts.SOFIRSTWIZARDNAVITABINDEX; + Integer IButtonWidth = Integer.valueOf(iButtonWidth); + int iButtonHeight = 14; + Integer IButtonHeight = Integer.valueOf(iButtonHeight); + Integer ICurStep = 0; + int iDialogHeight = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, PropertyNames.PROPERTY_HEIGHT)).intValue(); + int iDialogWidth = ((Integer) Helper.getUnoPropertyValue(this.xDialogModel, PropertyNames.PROPERTY_WIDTH)).intValue(); + int iHelpPosX = 8; + int iBtnPosY = iDialogHeight - iButtonHeight - 6; + int iCancelPosX = iDialogWidth - iButtonWidth - 6; + int iFinishPosX = iCancelPosX - 6 - iButtonWidth; + int iNextPosX = iFinishPosX - 6 - iButtonWidth; + int iBackPosX = iNextPosX - 3 - iButtonWidth; + + insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lnNaviSep", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.ORIENTATION, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + 1, 0, 0, Integer.valueOf(iDialogHeight - 26), ICurStep, Integer.valueOf(iDialogWidth) + }); + + insertControlModel("com.sun.star.awt.UnoControlFixedLineModel", "lnRoadSep", + new String[] + { + PropertyNames.PROPERTY_HEIGHT, PropertyNames.ORIENTATION, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + Integer.valueOf(iBtnPosY - 6), 1, 85, 0, ICurStep, 1 + }); + + String[] propNames = new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, "PushButtonType", PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }; + + Helper.setUnoPropertyValue(super.xDialogModel, PropertyNames.PROPERTY_HELPURL, HelpIds.getHelpIdString(hid)); + insertButton("btnWizardHelp", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + callHelp(); + } + }, new String[] + { + PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, "PushButtonType", PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH + }, + new Object[] + { + true, IButtonHeight, oWizardResource.getResText("RID_COMMON_15"), Integer.valueOf(iHelpPosX), Integer.valueOf(iBtnPosY), Short.valueOf((short) PushButtonType.HELP_value), ICurStep, Short.valueOf(curtabindex++), IButtonWidth + }); + insertButton("btnWizardBack", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + gotoPreviousAvailableStep(); + } + }, propNames, + new Object[] + { + false, IButtonHeight, HelpIds.getHelpIdString(hid + 2), oWizardResource.getResText("RID_COMMON_13"), Integer.valueOf(iBackPosX), Integer.valueOf(iBtnPosY), Short.valueOf((short) PushButtonType.STANDARD_value), ICurStep, Short.valueOf(curtabindex++), IButtonWidth + }); + + insertButton("btnWizardNext", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + gotoNextAvailableStep(); + } + }, propNames, + new Object[] + { + true, IButtonHeight, HelpIds.getHelpIdString(hid + 3), oWizardResource.getResText("RID_COMMON_14"), Integer.valueOf(iNextPosX), Integer.valueOf(iBtnPosY), Short.valueOf((short) PushButtonType.STANDARD_value), ICurStep, Short.valueOf(curtabindex++), IButtonWidth + }); + + insertButton("btnWizardFinish", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + finishWizard_1(); + } + }, propNames, + new Object[] + { + true, IButtonHeight, HelpIds.getHelpIdString(hid + 4), oWizardResource.getResText("RID_COMMON_12"), Integer.valueOf(iFinishPosX), Integer.valueOf(iBtnPosY), Short.valueOf((short) PushButtonType.STANDARD_value), ICurStep, Short.valueOf(curtabindex++), IButtonWidth + }); + + insertButton("btnWizardCancel", new XActionListenerAdapter() { + @Override + public void actionPerformed(ActionEvent event) { + cancelWizard_1(); + } + }, propNames, + new Object[] + { + true, IButtonHeight, HelpIds.getHelpIdString(hid + 5), oWizardResource.getResText("RID_COMMON_11"), Integer.valueOf(iCancelPosX), Integer.valueOf(iBtnPosY), Short.valueOf((short) PushButtonType.STANDARD_value), ICurStep, Short.valueOf(curtabindex++), IButtonWidth + }); + + setControlProperty("btnWizardNext", "DefaultButton", Boolean.TRUE); + } + catch (java.lang.Exception jexception) + { + jexception.printStackTrace(System.err); + } + } + + + + public void enableNavigationButtons(boolean _bEnableBack, boolean _bEnableNext, boolean _bEnableFinish) + { + enableBackButton(_bEnableBack); + enableNextButton(_bEnableNext); + enableFinishButton(_bEnableFinish); + } + + private void enableBackButton(boolean enabled) + { + setControlProperty("btnWizardBack", PropertyNames.PROPERTY_ENABLED, enabled ? Boolean.TRUE : Boolean.FALSE); + } + + public void enableNextButton(boolean enabled) + { + setControlProperty("btnWizardNext", PropertyNames.PROPERTY_ENABLED, enabled ? Boolean.TRUE : Boolean.FALSE); + } + + public void enableFinishButton(boolean enabled) + { + setControlProperty("btnWizardFinish", PropertyNames.PROPERTY_ENABLED, enabled ? Boolean.TRUE : Boolean.FALSE); + } + + public void setStepEnabled(int _nStep, boolean bEnabled) + { + XInterface xRoadmapItem = getRoadmapItemByID(_nStep); + if (xRoadmapItem != null) + { + Helper.setUnoPropertyValue(xRoadmapItem, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bEnabled)); + } + } + + public void enablefromStep(int _iStep, boolean _bDoEnable) + { + if (_iStep <= this.nMaxStep) + { + for (int i = _iStep; i <= nMaxStep; i++) + { + setStepEnabled(i, _bDoEnable); + } + enableFinishButton(_bDoEnable); + if (!_bDoEnable) + { + enableNextButton(_iStep > getCurrentStep() + 1); + } + else + { + enableNextButton(getCurrentStep() != nMaxStep); + } + } + } + + private boolean isStepEnabled(int _nStep) + { + try + { + boolean bIsEnabled; + XInterface xRoadmapItem = getRoadmapItemByID(_nStep); + if (xRoadmapItem == null) + // Todo: In this case an exception should be thrown + { + return false; + } + bIsEnabled = AnyConverter.toBoolean(Helper.getUnoPropertyValue(xRoadmapItem, PropertyNames.PROPERTY_ENABLED)); + return bIsEnabled; + } + catch (com.sun.star.lang.IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + return false; + } + } + + private synchronized void gotoPreviousAvailableStep() + { + boolean bIsEnabled; + if (nNewStep > 1) + { + nOldStep = nNewStep; + nNewStep--; + while (nNewStep > 0) + { + bIsEnabled = isStepEnabled(nNewStep); + if (bIsEnabled) + { + break; + } + nNewStep--; + } + if (nNewStep == 0) // Exception??? + { + nNewStep = nOldStep; + } + switchToStep(); + } + } + + //TODO discuss with rp + private int getNextAvailableStep() + { + if (isRoadmapComplete()) + { + for (int i = nNewStep + 1; i <= nMaxStep; i++) + { + if (isStepEnabled(i)) + { + return i; + } + } + } + return -1; + } + + private synchronized void gotoNextAvailableStep() + { + nOldStep = nNewStep; + nNewStep = getNextAvailableStep(); + if (nNewStep > -1) + { + switchToStep(); + } + } + + public abstract boolean finishWizard(); + + /** + * This function will call if the finish button is pressed on the UI. + */ + private void finishWizard_1() + { + enableFinishButton(false); + boolean success = false; + try + { + success = finishWizard(); + } + finally + { + if ( !success ) + enableFinishButton( true ); + } + if ( success ) + removeTerminateListener(); + } + + public int getCurrentStep() + { + try + { + return AnyConverter.toInt(Helper.getUnoPropertyValue(this.MSFDialogModel, PropertyNames.PROPERTY_STEP)); + } + catch (com.sun.star.lang.IllegalArgumentException exception) + { + exception.printStackTrace(System.err); + return -1; + } + } + + public void setCurrentStep(int _nNewstep) + { + nNewStep = _nNewstep; + changeToStep(nNewStep); + } + + public void setRightPaneHeaders(Resource _oResource, String ResNameBase, int StartResID, int _nMaxStep) + { + String[] sRightPaneHeaders = new String[_nMaxStep]; + for (int i = 0; i < _nMaxStep; ++i) { + sRightPaneHeaders[i] = _oResource.getResText(ResNameBase + String.valueOf(i + StartResID)); + } + setRightPaneHeaders(sRightPaneHeaders); + } + + public void setRightPaneHeaders(String[] _sRightPaneHeaders) + { + this.nMaxStep = _sRightPaneHeaders.length; + FontDescriptor oFontDesc = new FontDescriptor(); + oFontDesc.Weight = com.sun.star.awt.FontWeight.BOLD; + + for (int i = 0; i < _sRightPaneHeaders.length; i++) + { + insertLabel("lblQueryTitle" + i, + new String[] + { + PropertyNames.FONT_DESCRIPTOR, 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 + }, + new Object[] + { + oFontDesc, 16, _sRightPaneHeaders[i], Boolean.TRUE, 91, 8, Integer.valueOf(i + 1), Short.valueOf((short) 12), 212 + }); + } + } + + public void cancelWizard() + { + //can be overridden by extending class + xDialog.endExecute(); + } + + private void callHelp() + { + //should be overridden by extending class + } + + private void removeTerminateListener() + { + if (bTerminateListenermustberemoved) + { + Desktop.getDesktop(xMSF).removeTerminateListener(this); + bTerminateListenermustberemoved = false; + } + } + + /** + * called by the cancel button and + * by the window hidden event. + * if this method was not called before, + * perform a cancel. + */ + private void cancelWizard_1() + { + cancelWizard(); + removeTerminateListener(); + } + + public void notifyTermination(EventObject arg0) + { + cancelWizard_1(); + } + + public void queryTermination(EventObject arg0) + throws TerminationVetoException + { + activate(); + throw new TerminationVetoException(); + } + + public void disposing(EventObject arg0) + { + cancelWizard_1(); + } +} diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.py b/wizards/com/sun/star/wizards/ui/WizardDialog.py new file mode 100644 index 000000000..7f0060bdc --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/WizardDialog.py @@ -0,0 +1,447 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import uno +import traceback +from abc import ABCMeta, abstractmethod +from .UnoDialog2 import UnoDialog2, Desktop, PropertyNames, UIConsts, \ + ItemListenerProcAdapter +from ..common.HelpIds import HelpIds +from ..common.FileAccess import FileAccess + +from com.sun.star.lang import NoSuchMethodException +from com.sun.star.frame import TerminationVetoException +from com.sun.star.awt.PushButtonType import HELP, STANDARD +from com.sun.star.awt.FontWeight import BOLD + +import imp, os +imp.load_source('strings', os.path.join(os.path.dirname(__file__), '../common/strings.hrc')) +import strings + +class WizardDialog(UnoDialog2): + + __metaclass__ = ABCMeta + + __NEXT_ACTION_PERFORMED = "gotoNextAvailableStep" + __BACK_ACTION_PERFORMED = "gotoPreviousAvailableStep" + __FINISH_ACTION_PERFORMED = "finishWizard_1" + __CANCEL_ACTION_PERFORMED = "cancelWizard_1" + __HELP_ACTION_PERFORMED = None + + ''' + Creates a new instance of WizardDialog + the hid is used as following : + "HID:(hid)" - the dialog + "HID:(hid+1) - the help button + "HID:(hid+2)" - the back button + "HID:(hid+3)" - the next button + "HID:(hid+4)" - the create button + "HID:(hid+5)" - the cancel button + @param xMSF + @param hid_ + ''' + + def __init__(self, xMSF, hid_): + super(WizardDialog,self).__init__(xMSF) + self.__hid = hid_ + self.iButtonWidth = 50 + self.nNewStep = 1 + self.nOldStep = 1 + self.nMaxStep = 1 + self.bTerminateListenermustberemoved = True + self.oRoadmap = None + self.terminateListener = None + + def activate(self): + try: + self.xUnoDialog.toFront() + except Exception: + pass + # do nothing; + + def itemStateChanged(self, itemEvent): + try: + self.nNewStep = itemEvent.ItemId + self.nOldStep = int(self.xDialogModel.Step) + if self.nNewStep != self.nOldStep: + self.switchToStep() + + except Exception: + traceback.print_exc() + + def setDialogProperties(self, closeable, height, moveable, position_x, + position_Y, step, tabIndex, title, width): + uno.invoke(self.xDialogModel, "setPropertyValues", + ((PropertyNames.PROPERTY_CLOSEABLE, + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_MOVEABLE, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + PropertyNames.PROPERTY_TITLE, + PropertyNames.PROPERTY_WIDTH), + (closeable, height, moveable, position_x, position_Y, step, + tabIndex, title, width))) + + def setRoadmapInteractive(self, _bInteractive): + self.oRoadmap.Activated = _bInteractive + + def setRoadmapComplete(self, bComplete): + self.oRoadmap.Complete = bComplete + + def isRoadmapComplete(self): + try: + return bool(self.oRoadmap.Complete) + except Exception: + traceback.print_exc() + return False + + def setCurrentRoadmapItemID(self, ID): + if self.oRoadmap is not None: + nCurItemID = self.getCurrentRoadmapItemID() + if nCurItemID != ID: + self.oRoadmap.CurrentItemID = ID + + def getCurrentRoadmapItemID(self): + try: + return int(self.oRoadmap.CurrentItemID) + except Exception: + traceback.print_exc() + return -1 + + + def initializePaths(self): + xPropertySet = \ + self.xMSF.createInstance("com.sun.star.util.PathSettings") + self.sUserTemplatePath = \ + xPropertySet.getPropertyValue("Template_writable") + myFA = FileAccess(self.xMSF) + aInternalPaths = xPropertySet.getPropertyValue("Template_internal") + self.sTemplatePath = "" + for path in aInternalPaths: + if myFA.exists(path + "/wizard", False): + self.sTemplatePath = path + break + if self.sTemplatePath == "": + raise Exception("could not find wizard templates") + + def addRoadmap(self): + try: + iDialogHeight = self.xDialogModel.Height + # the roadmap control has got no real TabIndex ever + # that is not correct, but changing this would need time, + # so it is used without TabIndex as before + + xRoadmapControl = self.insertControlModel( + "com.sun.star.awt.UnoControlRoadmapModel", + "rdmNavi", + (PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, "Tabstop", + PropertyNames.PROPERTY_WIDTH), + ((iDialogHeight - 26), 0, 0, 0, + 0, True, 85)) + self.oRoadmap = xRoadmapControl.Model + method = getattr(self, "itemStateChanged") + xRoadmapControl.addItemListener( + ItemListenerProcAdapter(method)) + + self.oRoadmap.Text = strings.RID_COMMON_START_16 + except NoSuchMethodException: + from com.sun.star.awt.VclWindowPeerAttribute import OK + from .SystemDialog import SystemDialog + sError = "The files required could not be found.\n" + \ + "Please start the LibreOffice Setup and choose 'Repair'." + SystemDialog.showMessageBox(super().xMSF, "ErrorBox", OK, sError) + except Exception: + traceback.print_exc() + + def getRoadmapItemByID(self, _ID): + try: + getByIndex = self.oRoadmap.getByIndex + for i in list(range(self.oRoadmap.Count)): + CurRoadmapItem = getByIndex(i) + CurID = int(CurRoadmapItem.ID) + if CurID == _ID: + return CurRoadmapItem + + return None + except Exception: + traceback.print_exc() + return None + + def switchToStep(self,_nOldStep=None, _nNewStep=None): + if _nOldStep is not None and _nNewStep is not None: + self.nOldStep = _nOldStep + self.nNewStep = _nNewStep + + self.leaveStep(self.nOldStep, self.nNewStep) + if self.nNewStep != self.nOldStep: + if self.nNewStep == self.nMaxStep: + self.xDialogModel.btnWizardNext.DefaultButton = False + self.xDialogModel.btnWizardFinish.DefaultButton = True + else: + self.xDialogModel.btnWizardNext.DefaultButton = True + self.xDialogModel.btnWizardFinish.DefaultButton = False + + self.changeToStep(self.nNewStep) + self.enterStep(self.nOldStep, self.nNewStep) + return True + + return False + + @abstractmethod + def leaveStep(self, nOldStep, nNewStep): + pass + + @abstractmethod + def enterStep(self, nOldStep, nNewStep): + pass + + def changeToStep(self, nNewStep): + self.xDialogModel.Step = nNewStep + self.setCurrentRoadmapItemID(nNewStep) + self.enableNextButton(self.getNextAvailableStep() > 0) + self.enableBackButton(nNewStep != 1) + + def drawNaviBar(self): + try: + curtabindex = UIConsts.SOFIRSTWIZARDNAVITABINDEX + iButtonWidth = self.iButtonWidth + iButtonHeight = 14 + iCurStep = 0 + iDialogHeight = self.xDialogModel.Height + iDialogWidth = self.xDialogModel.Width + iHelpPosX = 8 + iBtnPosY = iDialogHeight - iButtonHeight - 6 + iCancelPosX = iDialogWidth - self.iButtonWidth - 6 + iFinishPosX = iCancelPosX - 6 - self.iButtonWidth + iNextPosX = iFinishPosX - 6 - self.iButtonWidth + iBackPosX = iNextPosX - 3 - self.iButtonWidth + self.insertControlModel( + "com.sun.star.awt.UnoControlFixedLineModel", + "lnNaviSep", + (PropertyNames.PROPERTY_HEIGHT, "Orientation", + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_WIDTH), + (1, 0, 0, iDialogHeight - 26, iCurStep, iDialogWidth)) + self.insertControlModel( + "com.sun.star.awt.UnoControlFixedLineModel", + "lnRoadSep", + (PropertyNames.PROPERTY_HEIGHT, + "Orientation", + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_WIDTH), + (iBtnPosY - 6, 1, 85, 0, iCurStep, 1)) + propNames = (PropertyNames.PROPERTY_ENABLED, + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_HELPURL, + PropertyNames.PROPERTY_LABEL, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + "PushButtonType", + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + PropertyNames.PROPERTY_WIDTH) + self.xDialogModel.HelpURL = HelpIds.getHelpIdString(self.__hid) + self.insertButton("btnWizardHelp", + WizardDialog.__HELP_ACTION_PERFORMED, + (PropertyNames.PROPERTY_ENABLED, + PropertyNames.PROPERTY_HEIGHT, + PropertyNames.PROPERTY_LABEL, + PropertyNames.PROPERTY_POSITION_X, + PropertyNames.PROPERTY_POSITION_Y, + "PushButtonType", + PropertyNames.PROPERTY_STEP, + PropertyNames.PROPERTY_TABINDEX, + PropertyNames.PROPERTY_WIDTH), + (True, iButtonHeight, + strings.RID_COMMON_START_15, + iHelpPosX, iBtnPosY, + uno.Any("short",HELP), iCurStep, + uno.Any("short",(curtabindex + 1)), iButtonWidth), self) + self.insertButton("btnWizardBack", + WizardDialog.__BACK_ACTION_PERFORMED, propNames, + (False, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 2), + strings.RID_COMMON_START_13, + iBackPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep, + uno.Any("short",(curtabindex + 1)), iButtonWidth), self) + self.insertButton("btnWizardNext", + WizardDialog.__NEXT_ACTION_PERFORMED, propNames, + (True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 3), + strings.RID_COMMON_START_14, + iNextPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep, + uno.Any("short",(curtabindex + 1)), iButtonWidth), self) + self.insertButton("btnWizardFinish", + WizardDialog.__FINISH_ACTION_PERFORMED, propNames, + (True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 4), + strings.RID_COMMON_START_12, + iFinishPosX, iBtnPosY, uno.Any("short",STANDARD), + iCurStep, + uno.Any("short",(curtabindex + 1)), + iButtonWidth), self) + self.insertButton("btnWizardCancel", + WizardDialog.__CANCEL_ACTION_PERFORMED, propNames, + (True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 5), + strings.RID_COMMON_START_11, + iCancelPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep, + uno.Any("short",(curtabindex + 1)), + iButtonWidth), self) + self.xDialogModel.btnWizardNext.DefaultButton = True + except Exception: + traceback.print_exc() + + def insertRoadMapItems(self, items, enabled): + for index, item in enumerate(items): + try: + oRoadmapItem = self.oRoadmap.createInstance() + oRoadmapItem.Label = item + oRoadmapItem.Enabled = enabled[index] + oRoadmapItem.ID = index + 1 + self.oRoadmap.insertByIndex(index, oRoadmapItem) + except Exception: + traceback.print_exc() + + def enableBackButton(self, enabled): + self.xDialogModel.btnWizardBack.Enabled = enabled + + def enableNextButton(self, enabled): + self.xDialogModel.btnWizardNext.Enabled = enabled + + def enableFinishButton(self, enabled): + self.xDialogModel.btnWizardFinish.Enabled = enabled + + def isStepEnabled(self, _nStep): + try: + xRoadmapItem = self.getRoadmapItemByID(_nStep) + # Todo: In this case an exception should be thrown + if xRoadmapItem is None: + return False + bIsEnabled = bool(xRoadmapItem.Enabled) + return bIsEnabled + except Exception: + traceback.print_exc() + return False + + def gotoPreviousAvailableStep(self): + try: + if self.nNewStep > 1: + self.nOldStep = self.nNewStep + self.nNewStep -= 1 + while self.nNewStep > 0: + bIsEnabled = self.isStepEnabled(self.nNewStep) + if bIsEnabled: + break; + + self.nNewStep -= 1 + if (self.nNewStep == 0): + self.nNewStep = self.nOldStep + self.switchToStep() + except Exception: + traceback.print_exc() + + def getNextAvailableStep(self): + if self.isRoadmapComplete(): + i = self.nNewStep + 1 + while i <= self.nMaxStep: + if self.isStepEnabled(i): + return i + i += 1 + return -1 + + def gotoNextAvailableStep(self): + try: + self.nOldStep = self.nNewStep + self.nNewStep = self.getNextAvailableStep() + if self.nNewStep > -1: + self.switchToStep() + except Exception: + traceback.print_exc() + + @abstractmethod + def finishWizard(self): + pass + + def finishWizard_1(self): + '''This function will call + if the finish button is pressed on the UI''' + try: + self.enableFinishButton(False) + success = False + try: + success = self.finishWizard() + finally: + if not success: + self.enableFinishButton(True) + + if success: + self.removeTerminateListener() + except Exception: + traceback.print_exc() + + def getCurrentStep(self): + try: + return int(self.xDialogModel.Step) + except Exception: + traceback.print_exc() + return -1 + + def cancelWizard(self): + #can be overwritten by extending class + self.xUnoDialog.endExecute() + + def removeTerminateListener(self): + if self.bTerminateListenermustberemoved: + Desktop.getDesktop(self.xMSF).removeTerminateListener(self.terminateListener) + self.bTerminateListenermustberemoved = False + + ''' + called by the cancel button and + by the window hidden event. + if this method was not called before, + perform a cancel. + ''' + + def cancelWizard_1(self): + try: + self.cancelWizard() + self.removeTerminateListener() + except Exception: + traceback.print_exc() + + def windowHidden(self): + self.cancelWizard_1() + + def queryTermination(self): + self.activate() + raise TerminationVetoException() + + def disposing(self, arg0): + self.cancelWizard_1() + + def optCreateFromTemplateItemChanged(self): + self.bEditTemplate = False + + def optMakeChangesItemChanged(self): + self.bEditTemplate = True diff --git a/wizards/com/sun/star/wizards/ui/XFieldSelectionListener.java b/wizards/com/sun/star/wizards/ui/XFieldSelectionListener.java new file mode 100644 index 000000000..4a592b3a7 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/XFieldSelectionListener.java @@ -0,0 +1,35 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.wizards.ui; + +public interface XFieldSelectionListener +{ + + void shiftFromLeftToRight(String[] SelItems, String[] NewItems); + + void shiftFromRightToLeft(String[] OldSelItems, String[] NewItems); + + void moveItemUp(String Selitem); + + void moveItemDown(String Selitem); + + void setID(String sIncSuffix); + + +} diff --git a/wizards/com/sun/star/wizards/ui/__init__.py b/wizards/com/sun/star/wizards/ui/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/__init__.py diff --git a/wizards/com/sun/star/wizards/ui/event/CommonListener.py b/wizards/com/sun/star/wizards/ui/event/CommonListener.py new file mode 100644 index 000000000..c13119571 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/CommonListener.py @@ -0,0 +1,125 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import unohelper + +from com.sun.star.awt import XActionListener +class ActionListenerProcAdapter( unohelper.Base, XActionListener ): + def __init__(self, oProcToCall): + self.oProcToCall = oProcToCall + + def actionPerformed( self, oActionEvent ): + if callable( self.oProcToCall ): + self.oProcToCall() + + def disposing(self, Event): + # TODO: Implement ? + pass + +from com.sun.star.awt import XItemListener +class ItemListenerProcAdapter( unohelper.Base, XItemListener ): + def __init__(self, oProcToCall): + self.oProcToCall = oProcToCall + + def itemStateChanged( self, oItemEvent ): + if callable( self.oProcToCall ): + try: + self.oProcToCall() + except: + self.oProcToCall(oItemEvent) + + def disposing(self, Event): + # TODO: Implement ? + pass + +from com.sun.star.awt import XTextListener +class TextListenerProcAdapter( unohelper.Base, XTextListener ): + def __init__(self, oProcToCall): + self.oProcToCall = oProcToCall + + def textChanged( self, oTextEvent ): + if callable( self.oProcToCall ): + self.oProcToCall() + + def disposing(self, Event): + # TODO: Implement ? + pass + +from com.sun.star.frame import XTerminateListener +class TerminateListenerProcAdapter( unohelper.Base, XTerminateListener ): + def __init__(self, oProcToCall): + self.oProcToCall = oProcToCall + + def queryTermination(self, TerminateEvent): + if callable( self.oProcToCall ): + self.oProcToCall() + +from com.sun.star.awt import XWindowListener +class WindowListenerProcAdapter( unohelper.Base, XWindowListener ): + def __init__(self, oProcToCall): + self.oProcToCall = oProcToCall + + def windowShown(self, TerminateEvent): + if callable( self.oProcToCall ): + self.oProcToCall() + + def windowHidden(self, Event): + # TODO: Implement ? + pass + + def windowResized(self, Event): + # TODO: Implement ? + pass + + def windowMoved(self, Event): + # TODO: Implement ? + pass + + def disposing(self, Event): + # TODO: Implement ? + pass + +from com.sun.star.awt import XAdjustmentListener +class AdjustmentListenerProcAdapter( unohelper.Base, XAdjustmentListener ): + def __init__(self, oProcToCall): + self.oProcToCall = oProcToCall + + def adjustmentValueChanged(self, TerminateEvent): + if callable( self.oProcToCall ): + self.oProcToCall() + +from com.sun.star.awt import XFocusListener +class FocusListenerProcAdapter( unohelper.Base, XFocusListener ): + def __init__( self, oProcToCall): + self.oProcToCall = oProcToCall + + def focusGained(self, FocusEvent): + if callable( self.oProcToCall ): + self.oProcToCall(FocusEvent) + +from com.sun.star.awt import XKeyListener +class KeyListenerProcAdapter( unohelper.Base, XKeyListener ): + def __init__(self, oProcToCall): + self.oProcToCall = oProcToCall + + def keyPressed(self, KeyEvent): + if callable( self.oProcToCall ): + self.oProcToCall(KeyEvent) + + def disposing(self, Event): + # TODO: Implement ? + pass diff --git a/wizards/com/sun/star/wizards/ui/event/DataAware.py b/wizards/com/sun/star/wizards/ui/event/DataAware.py new file mode 100644 index 000000000..e062b48bd --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/DataAware.py @@ -0,0 +1,117 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import traceback +import uno +from abc import ABCMeta, abstractmethod + +from com.sun.star.util import Date +from com.sun.star.util import Time +from datetime import datetime + +''' +DataAware objects are used to live-synchronize UI and DataModel/DataObject. +It is used as listener on UI events, to keep the DataObject up to date. +This class, as a base abstract class, sets a frame of functionality, +delegating the data Object get/set methods to a Value object, +and leaving the UI get/set methods abstract. +Note that event listening is *not* a part of this model. +the updateData() or updateUI() methods should be programmatically called. +in child classes, the updateData() will be bound to UI event calls. +<br><br> +This class holds references to a Data Object and a Value object. +The Value object "knows" how to get and set a value from the +Data Object. +''' + +class DataAware(object): + __metaclass__ = ABCMeta + + ''' + creates a DataAware object for the given data object and Value object. + @param dataObject_ + @param value_ + ''' + + def __init__(self, dataObject_, field_): + self._dataObject = dataObject_ + self._field = field_ + + ''' + sets the given value to the UI control + @param newValue the value to set to the ui control. + ''' + @abstractmethod + def setToUI (self,newValue): + pass + + ''' + gets the current value from the UI control. + @return the current value from the UI control. + ''' + + @abstractmethod + def getFromUI (self): + pass + + ''' + updates the UI control according to the + current state of the data object. + ''' + + def updateUI(self): + try: + data = getattr(self._dataObject, self._field) + except Exception: + data = uno.invoke(self._dataObject, "get" + self._field, ()) + ui = self.getFromUI() + if data is not ui: + try: + self.setToUI(data) + except Exception: + traceback.print_exc() + + ''' + updates the DataObject according to + the current state of the UI control. + ''' + + def updateData(self): + useUno = False + try: + try: + data = getattr(self._dataObject, self._field) + except Exception: + useUno = True + data = uno.invoke(self._dataObject, "get" + self._field, ()) + ui = self.getFromUI() + if data is not ui: + if isinstance(ui,Date): + d = datetime(ui.Year, ui.Month, ui.Day) + ui = d.strftime('%d/%m/%y') + elif isinstance(ui,Time): + t = datetime(1, 1, 1, ui.Hours, ui.Minutes) + ui = t.strftime('%H:%M') + if useUno: + uno.invoke(self._dataObject, "set" + self._field, (ui,)) + else: + if isinstance(ui,tuple): + #Listbox Element + ui = ui[0] + setattr(self._dataObject, self._field, ui) + except Exception: + traceback.print_exc() diff --git a/wizards/com/sun/star/wizards/ui/event/EventListenerList.py b/wizards/com/sun/star/wizards/ui/event/EventListenerList.py new file mode 100644 index 000000000..e30536044 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/EventListenerList.py @@ -0,0 +1,27 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +class EventListenerList(object): + + def __init__(self): + self.list = [] + + def add(self, listener): + self.list.append(listener) + + def remove(self, listener): + self.list.remove(listener) diff --git a/wizards/com/sun/star/wizards/ui/event/ListModelBinder.py b/wizards/com/sun/star/wizards/ui/event/ListModelBinder.py new file mode 100644 index 000000000..a6f13e77d --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/ListModelBinder.py @@ -0,0 +1,67 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +from abc import abstractmethod + +from .ListDataListener import ListDataListener + +class ListModelBinder(ListDataListener): + + def __init__(self, unoListBox, listModel_): + self.unoList = unoListBox + self.unoListModel = unoListBox.Model + self.listModel = None + self.setListModel(listModel_) + self.renderer = self.Renderer() + + def setListModel(self, newListModel): + if self.listModel is not None: + self.listModel.removeListDataListener(self) + + self.listModel = newListModel + self.listModel.addListDataListener(self) + + def update(self, i): + self.remove(i, i) + self.insert(i) + + def remove(self, i1, i2): + self.unoList.removeItems(i1, i2 - i1 + 1) + + def insert(self, i): + self.unoList.addItem(self.getItemString(i), i) + + def getItemString(self, i): + return self.getItemString1(self.listModel.getElementAt(i)) + + def getItemString1(self, item): + return self.renderer.render(item) + + def getSelectedItems(self): + return self.unoListModel.SelectedItems + + class Renderer: + + @abstractmethod + def render(self, item): + if (item is None): + return "" + elif (isinstance(item, int)): + return str(item) + else: + return item.toString() diff --git a/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py new file mode 100644 index 000000000..67ba0ceb8 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py @@ -0,0 +1,48 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +from .CommonListener import ItemListenerProcAdapter +from .DataAware import DataAware + +class RadioDataAware(DataAware): + + def __init__(self, data, value, radioButtons): + super(RadioDataAware,self).__init__(data, value) + self.radioButtons = radioButtons + + def setToUI(self, value): + selected = int(value) + if selected == -1: + for i in self.radioButtons: + i.State = False + else: + self.radioButtons[selected].State = True + + def getFromUI(self): + for index, workwith in enumerate(self.radioButtons): + if workwith.State: + return index + + return -1 + + @classmethod + def attachRadioButtons(self, data, prop, buttons, field): + da = RadioDataAware(data, prop, buttons) + method = getattr(da,"updateData") + for i in da.radioButtons: + i.addItemListener(ItemListenerProcAdapter(method)) + return da diff --git a/wizards/com/sun/star/wizards/ui/event/Task.py b/wizards/com/sun/star/wizards/ui/event/Task.py new file mode 100644 index 000000000..aa44ed314 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/Task.py @@ -0,0 +1,76 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +import traceback + +from .TaskEvent import TaskEvent + +class Task: + successful = 0 + failed = 0 + maximum = 0 + taskName = "" + listeners = [] + subtaskName = "" + + def __init__(self, taskName_, subtaskName_, max_): + self.taskName = taskName_ + self.subtaskName = subtaskName_ + self.maximum = max_ + + def start(self): + self.fireTaskStarted() + + def fail(self): + self.fireTaskFailed() + + def getMax(self): + return self.maximum + + def setMax(self, max_): + self.maximum = max_ + self.fireTaskStatusChanged() + + def advance(self, success_): + if success_: + self.successful += 1 + print ("Success :", self.successful) + else: + self.failed += 1 + print ("Failed :", self.failed) + self.fireTaskStatusChanged() + if (self.failed + self.successful == self.maximum): + self.fireTaskFinished() + + def fireTaskStatusChanged(self): + te = TaskEvent(self, TaskEvent.TASK_STATUS_CHANGED) + for i in range(len(self.listeners)): + self.listeners[i].taskStatusChanged(te) + + def fireTaskStarted(self): + te = TaskEvent(self, TaskEvent.TASK_STARTED) + for i in range(len(self.listeners)): + self.listeners[i].taskStarted(te) + + def fireTaskFailed(self): + te = TaskEvent(self, TaskEvent.TASK_FAILED) + for i in range(len(self.listeners)): + self.listeners[i].taskFinished(te) + + def fireTaskFinished(self): + te = TaskEvent(self, TaskEvent.TASK_FINISHED) + for i in range(len(self.listeners)): + self.listeners[i].taskFinished(te) diff --git a/wizards/com/sun/star/wizards/ui/event/TaskEvent.py b/wizards/com/sun/star/wizards/ui/event/TaskEvent.py new file mode 100644 index 000000000..765bb07c9 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/TaskEvent.py @@ -0,0 +1,34 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . + +class TaskEvent: + + TASK_STARTED = 1 + TASK_FINISHED = 2 + TASK_STATUS_CHANGED = 3 + SUBTASK_NAME_CHANGED = 4 + TASK_FAILED = 5 + taskType = 0 + source = None + + #general constructor- + # @param source + # @param type_ + def __init__(self, source_, type_): + #super(TaskEvent, self).__init__(source) + self.taskType = type_ + self.source = source_ diff --git a/wizards/com/sun/star/wizards/ui/event/TaskListener.py b/wizards/com/sun/star/wizards/ui/event/TaskListener.py new file mode 100644 index 000000000..210bac4db --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/TaskListener.py @@ -0,0 +1,35 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +from abc import abstractmethod +from com.sun.star.script import EventListener + +class TaskListener(EventListener): + + @abstractmethod + def taskStarted(self, te): + pass + + @abstractmethod + def taskFinished(self, te): + pass + + # is called when the status of the task has advanced. + # @param te + @abstractmethod + def taskStatusChanged(self, te): + pass diff --git a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py new file mode 100644 index 000000000..945c2cef2 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py @@ -0,0 +1,104 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import uno +from .CommonListener import ItemListenerProcAdapter, TextListenerProcAdapter +from .DataAware import DataAware, datetime, Date, Time +from ...common.PropertyNames import PropertyNames + +''' +This class supports simple cases where a UI control can +be directly synchronized with a data property. +Such controls are: the different text controls +(synchronizing the "Text" , "Value", "Date", "Time" property), +Checkbox controls, Dropdown listbox controls (synchronizing the +SelectedItems[] property. +For those controls, static convenience methods are offered, to simplify use. +''' + +class UnoDataAware(DataAware): + + def __init__(self, dataObject, field, unoObject_, unoPropName_, isShort=False): + super(UnoDataAware,self).__init__(dataObject, field) + self.unoControl = unoObject_ + self.unoModel = self.unoControl.Model + self.unoPropName = unoPropName_ + self.isShort = isShort + + def setToUI(self, value): + if (isinstance(value, list)): + value = tuple(value) + elif self.isShort: + value = uno.Any("[]short", (value,)) + if value: + if(hasattr(self.unoModel, self.unoPropName)): + if self.unoPropName == "Date": + d = datetime.strptime(value, '%d/%m/%y') + value = Date(d.day, d.month, d.year) + elif self.unoPropName == "Time": + t = datetime.strptime(value, '%H:%M') + value = Time(0, 0, t.minute, t.hour, False) + + setattr(self.unoModel, self.unoPropName, value) + else: + uno.invoke(self.unoModel, "set" + self.unoPropName, (value,)) + + def getFromUI(self): + return getattr(self.unoModel, self.unoPropName) + + @classmethod + def __attachTextControl( + self, data, prop, unoText, unoProperty, field, value): + uda = UnoDataAware(data, prop, unoText, unoProperty) + method = getattr(uda,"updateData") + unoText.addTextListener(TextListenerProcAdapter(method)) + return uda + + @classmethod + def attachEditControl(self, data, prop, unoControl, field): + return self.__attachTextControl( + data, prop, unoControl, "Text", field, "") + + @classmethod + def attachDateControl(self, data, prop, unoControl, field): + return self.__attachTextControl( + data, prop, unoControl, "Date", field, 0) + + @classmethod + def attachTimeControl(self, data, prop, unoControl, field): + return self.__attachTextControl( + data, prop, unoControl, "Time", field, 0) + + @classmethod + def attachNumericControl(self, data, prop, unoControl, field): + return self.__attachTextControl( + data, prop, unoControl, "Value", field, float(0)) + + @classmethod + def attachCheckBox( + self, data, prop, checkBox, field): + uda = UnoDataAware(data, prop, checkBox, PropertyNames.PROPERTY_STATE) + method = getattr(uda,"updateData") + checkBox.addItemListener(ItemListenerProcAdapter(method)) + return uda + + @classmethod + def attachListBox(self, data, prop, listBox, field): + uda = UnoDataAware(data, prop, listBox, "SelectedItems", True) + method = getattr(uda,"updateData") + listBox.addItemListener(ItemListenerProcAdapter(method)) + return uda diff --git a/wizards/com/sun/star/wizards/ui/event/XActionListenerAdapter.java b/wizards/com/sun/star/wizards/ui/event/XActionListenerAdapter.java new file mode 100644 index 000000000..b7dfddbb8 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/XActionListenerAdapter.java @@ -0,0 +1,32 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui.event; + +import com.sun.star.awt.ActionEvent; +import com.sun.star.awt.XActionListener; +import com.sun.star.lang.EventObject; + +public class XActionListenerAdapter implements XActionListener { + + public void disposing(EventObject event) { + } + + public void actionPerformed(ActionEvent event) { + } + +} diff --git a/wizards/com/sun/star/wizards/ui/event/XItemListenerAdapter.java b/wizards/com/sun/star/wizards/ui/event/XItemListenerAdapter.java new file mode 100644 index 000000000..160ecdb4f --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/XItemListenerAdapter.java @@ -0,0 +1,32 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui.event; + +import com.sun.star.awt.ItemEvent; +import com.sun.star.awt.XItemListener; +import com.sun.star.lang.EventObject; + +public class XItemListenerAdapter implements XItemListener { + + public void disposing(EventObject event) { + } + + public void itemStateChanged(ItemEvent event) { + } + +} diff --git a/wizards/com/sun/star/wizards/ui/event/XTextListenerAdapter.java b/wizards/com/sun/star/wizards/ui/event/XTextListenerAdapter.java new file mode 100644 index 000000000..af95771af --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/XTextListenerAdapter.java @@ -0,0 +1,32 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.ui.event; + +import com.sun.star.awt.TextEvent; +import com.sun.star.awt.XTextListener; +import com.sun.star.lang.EventObject; + +public class XTextListenerAdapter implements XTextListener { + + public void disposing(EventObject event) { + } + + public void textChanged(TextEvent event) { + } + +} diff --git a/wizards/com/sun/star/wizards/ui/event/__init__.py b/wizards/com/sun/star/wizards/ui/event/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/__init__.py |