25#include <com/sun/star/sdbc/DataType.hpp>
26#include <com/sun/star/form/XGridColumnFactory.hpp>
27#include <com/sun/star/awt/MouseWheelBehavior.hpp>
28#include <com/sun/star/container/XNameContainer.hpp>
34#define GW_STATE_DATASOURCE_SELECTION 0
35#define GW_STATE_FIELDSELECTION 1
51 const Reference< XPropertySet >& _rxObjectModel,
const Reference< XComponentContext >& _rxContext )
53 , m_bHadDataSelection(true)
73 if (FormComponentType::GRIDCONTROL != _nClassId)
76 Reference< XGridColumnFactory > xColumnFactory(
getContext().xObjectModel, UNO_QUERY);
77 return xColumnFactory.is();
85 Reference< XGridColumnFactory > xColumnFactory(rContext.
xObjectModel, UNO_QUERY);
86 DBG_ASSERT(xColumnFactory.is(),
"OGridWizard::implApplySettings: should never have made it 'til here!");
90 Reference< XNameContainer > xColumnContainer(rContext.
xObjectModel, UNO_QUERY);
91 DBG_ASSERT(xColumnContainer.is(),
"OGridWizard::implApplySettings: no container!");
93 if (!xColumnFactory.is() || !xColumnContainer.is())
96 static constexpr OUStringLiteral s_sMouseWheelBehavior =
u"MouseWheelBehavior";
97 static constexpr OUStringLiteral s_sEmptyString =
u"";
100 std::vector< OUString > aColumnServiceNames;
101 std::vector< OUString > aColumnLabelPostfixes;
102 std::vector< OUString > aFormFieldNames;
104 aColumnServiceNames.reserve(
getSettings().aSelectedFields.getLength());
105 aColumnLabelPostfixes.reserve(
getSettings().aSelectedFields.getLength());
106 aFormFieldNames.reserve(
getSettings().aSelectedFields.getLength());
111 for (;pSelectedFields < pEnd; ++pSelectedFields)
114 sal_Int32 nFieldType = DataType::OTHER;
115 OControlWizardContext::TNameTypeMap::const_iterator aFind = rContext.
aTypes.find(*pSelectedFields);
116 if ( aFind != rContext.
aTypes.end() )
117 nFieldType = aFind->second;
119 aFormFieldNames.push_back(*pSelectedFields);
123 case DataType::BOOLEAN:
124 aColumnServiceNames.push_back(OUString(
"CheckBox"));
125 aColumnLabelPostfixes.push_back(s_sEmptyString);
128 case DataType::TINYINT:
129 case DataType::SMALLINT:
130 case DataType::INTEGER:
131 aColumnServiceNames.push_back(OUString(
"NumericField"));
132 aColumnLabelPostfixes.push_back(s_sEmptyString);
135 case DataType::FLOAT:
137 case DataType::DOUBLE:
138 case DataType::NUMERIC:
139 case DataType::DECIMAL:
140 aColumnServiceNames.push_back(OUString(
"FormattedField"));
141 aColumnLabelPostfixes.push_back(s_sEmptyString);
145 aColumnServiceNames.push_back(OUString(
"DateField"));
146 aColumnLabelPostfixes.push_back(s_sEmptyString);
150 aColumnServiceNames.push_back(OUString(
"TimeField"));
151 aColumnLabelPostfixes.push_back(s_sEmptyString);
154 case DataType::TIMESTAMP:
155 aColumnServiceNames.push_back(OUString(
"DateField"));
158 aFormFieldNames.push_back(*pSelectedFields);
159 aColumnServiceNames.push_back(OUString(
"TimeField"));
164 aColumnServiceNames.push_back(OUString(
"TextField"));
165 aColumnLabelPostfixes.push_back(s_sEmptyString);
169 DBG_ASSERT( aFormFieldNames.size() == aColumnServiceNames.size()
170 && aColumnServiceNames.size() == aColumnLabelPostfixes.size(),
171 "OGridWizard::implApplySettings: inconsistent descriptor sequences!");
175 Reference< XNameAccess > xExistenceChecker(xColumnContainer);
177 std::vector< OUString >::const_iterator pColumnLabelPostfix = aColumnLabelPostfixes.begin();
178 std::vector< OUString >::const_iterator pFormFieldName = aFormFieldNames.begin();
180 for (
const auto& rColumnServiceName : aColumnServiceNames)
185 Reference< XPropertySet >
xColumn( xColumnFactory->createColumn(rColumnServiceName), UNO_SET_THROW );
186 Reference< XPropertySetInfo > xColumnPSI(
xColumn->getPropertySetInfo(), UNO_SET_THROW );
188 OUString sColumnName(rColumnServiceName);
192 xColumn->setPropertyValue(
"DataField",
Any(*pFormFieldName));
194 xColumn->setPropertyValue(
"Label",
Any(*pFormFieldName + *pColumnLabelPostfix));
198 if ( xColumnPSI->hasPropertyByName( s_sMouseWheelBehavior ) )
199 xColumn->setPropertyValue( s_sMouseWheelBehavior,
Any( MouseWheelBehavior::SCROLL_DISABLED ) );
202 xColumnContainer->insertByName(sColumnName,
Any(
xColumn));
206 SAL_WARN(
"extensions.dbpilots",
"OGridWizard::implApplySettings: "
207 "unexpected exception while creating the grid column for field " <<
211 ++pColumnLabelPostfix;
219 OUString sIdent(OUString::number(_nState));
225 return std::make_unique<OTableSelectionPage>(pPageContainer,
this);
227 return std::make_unique<OGridFieldsSelection>(pPageContainer,
this);
235 switch (_nCurrentState)
283 :
OGridPage(pPage, pWizard,
"modules/sabpilot/ui/gridfieldsselectionpage.ui",
"GridFieldsSelection")
284 , m_xExistFields(m_xBuilder->weld_tree_view(
"existingfields"))
285 , m_xSelectOne(m_xBuilder->weld_button(
"fieldright"))
286 , m_xSelectAll(m_xBuilder->weld_button(
"allfieldsright"))
287 , m_xDeselectOne(m_xBuilder->weld_button(
"fieldleft"))
288 , m_xDeselectAll(m_xBuilder->weld_button(
"allfieldsleft"))
289 , m_xSelFields(m_xBuilder->weld_tree_view(
"selectedfields"))
330 const OUString* pEnd = pSelected + rSettings.
aSelectedFields.getLength();
331 for (; pSelected < pEnd; ++pSelected)
351 for (sal_Int32
i=0;
i<nSelected; ++
i, ++pSelected)
370 weld::Button* pSimulateButton = m_xExistFields.get() == &rList ? m_xSelectOne.get() : m_xDeselectOne.get();
372 OnMoveOneEntry(*pSimulateButton);
383 bool bMoveRight = (m_xSelectOne.get() == &rButton);
384 weld::TreeView& rMoveTo = bMoveRight ? *m_xSelFields : *m_xExistFields;
387 const sal_Int32 nSelected = bMoveRight ? m_xExistFields->
get_selected_index() : m_xSelFields->get_selected_index();
389 int nRelativeIndex = bMoveRight ? m_xExistFields->get_id(nSelected).toInt32() : m_xSelFields->get_id(nSelected).toInt32();
391 sal_Int32 nInsertPos = -1;
397 if (rMoveTo.
get_id(nInsertPos).toInt32() > nRelativeIndex)
404 OUString sMovingEntry = bMoveRight ? m_xExistFields->get_text(nSelected) : m_xSelFields->get_text(nSelected);
407 OUString
sId(OUString::number(nRelativeIndex));
408 rMoveTo.
insert(
nullptr, nInsertPos, &sMovingEntry, &
sId,
nullptr,
nullptr,
false,
nullptr);
413 sal_Int32 nSelectPos = m_xExistFields->get_selected_index();
414 m_xExistFields->remove(nSelected);
415 if ((nSelectPos != -1) && (nSelectPos < m_xExistFields->n_children()))
416 m_xExistFields->select(nSelectPos);
418 m_xExistFields->grab_focus();
422 sal_Int32 nSelectPos = m_xSelFields->get_selected_index();
423 m_xSelFields->remove(nSelected);
424 if ((nSelectPos != -1) && (nSelectPos < m_xSelFields->n_children()))
425 m_xSelFields->select(nSelectPos);
427 m_xSelFields->grab_focus();
435 bool bMoveRight = (m_xSelectAll.get() == &rButton);
436 m_xExistFields->clear();
437 m_xSelFields->clear();
438 fillListBox(bMoveRight ? *m_xSelFields : *m_xExistFields, getContext().
aFieldNames);
const char *const aFieldNames[]
OControlWizard * getDialog()
virtual void initializePage() override
const OControlWizardContext & getContext() const
void enableFormDatasourceDisplay()
static void fillListBox(weld::TreeView &_rList, const css::uno::Sequence< OUString > &_rItems)
void initControlSettings(OControlWizardSettings *_pSettings)
bool needDatasourceSelection()
const OControlWizardContext & getContext() const
std::unique_ptr< weld::Button > m_xDeselectAll
std::unique_ptr< weld::TreeView > m_xExistFields
virtual ~OGridFieldsSelection() override
OGridFieldsSelection(weld::Container *pPage, OGridWizard *pWizard)
virtual void Activate() override
std::unique_ptr< weld::TreeView > m_xSelFields
std::unique_ptr< weld::Button > m_xDeselectOne
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
virtual bool canAdvance() const override
virtual void initializePage() override
std::unique_ptr< weld::Button > m_xSelectOne
std::unique_ptr< weld::Button > m_xSelectAll
OGridSettings & getSettings()
virtual bool leaveState(WizardState _nState) override
virtual void enterState(WizardState _nState) override
OGridSettings & getSettings()
virtual bool onFinish() override
virtual std::unique_ptr< BuilderPage > createPage(WizardState _nState) override
virtual WizardState determineNextState(WizardState _nCurrentState) const override
virtual bool approveControl(sal_Int16 _nClassId) override
OGridWizard(weld::Window *_pParent, const css::uno::Reference< css::beans::XPropertySet > &_rxObjectModel, const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
OGridSettings m_aSettings
virtual bool commitPage(WizardTypes::CommitPageReason _eReason) override
virtual void Activate() override
virtual bool leaveState(WizardTypes::WizardState nState)
std::unique_ptr< weld::Button > m_xNextPage
std::unique_ptr< weld::Button > m_xCancel
void defaultButton(WizardButtonFlags _nWizardButtonFlags)
std::unique_ptr< weld::Button > m_xPrevPage
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
std::unique_ptr< weld::Button > m_xFinish
virtual void enterState(WizardTypes::WizardState _nState)
void setTitleBase(const OUString &_rTitleBase)
std::unique_ptr< weld::Assistant > m_xAssistant
virtual int n_children() const=0
virtual void insert(const TreeIter *pParent, int pos, const OUString *pStr, const OUString *pId, const OUString *pIconName, VirtualDevice *pImageSurface, bool bChildrenOnDemand, TreeIter *pRet)=0
virtual int get_selected_index() const=0
virtual OUString get_id(int pos) const=0
#define DBG_ASSERT(sCon, aError)
#define GW_STATE_FIELDSELECTION
#define GW_STATE_DATASOURCE_SELECTION
constexpr OUStringLiteral HID_GRIDWIZARD_NEXT
constexpr OUStringLiteral HID_GRIDWIZARD_FINISH
constexpr OUStringLiteral HID_GRIDWIZARD_PREVIOUS
constexpr OUStringLiteral HID_GRIDWIZARD_CANCEL
#define LINK(Instance, Class, Member)
#define SAL_WARN(area, stream)
OUString ModuleRes(TranslateId pId)
IMPL_LINK_NOARG(OTableSelectionPage, OnSearchClicked, weld::Button &, void)
void disambiguateName(const Reference< XNameAccess > &_rxContainer, OUString &_rElementsName)
IMPL_LINK(OTableSelectionPage, OnListboxDoubleClicked, weld::TreeView &, _rBox, bool)
css::uno::Reference< css::beans::XPropertySet > xObjectModel
css::uno::Sequence< OUString > aFieldNames
css::uno::Sequence< OUString > aSelectedFields
#define WZS_INVALID_STATE