21#include <com/sun/star/sdb/CommandType.hpp>
22#include <com/sun/star/sdb/XDocumentDataSource.hpp>
30#include <core_resource.hxx>
44using namespace datatransfer;
47using namespace container;
52 rUnsetDragIcon =
false;
53 if (m_xListBox->get_selected_index() == -1)
59 m_xHelper->setDescriptors(getSelectedFieldDescriptors());
64 : GenericDialogController(pParent,
"modules/dbreport/ui/floatingfield.ui",
"FloatingField")
67 , m_xRowSet(
std::move(xRowSet))
68 , m_xActions(m_xBuilder->weld_toolbar(
"toolbox"))
69 , m_xListBox(m_xBuilder->weld_tree_view(
"treeview"))
71 , m_bEscapeProcessing(false)
74 m_xListBox->set_selection_mode(SelectionMode::Multiple);
77 m_xListBox->enable_drag_source(xHelper, DND_ACTION_COPYMOVE | DND_ACTION_LINK);
78 m_xListBox->connect_drag_begin(
LINK(
this, OAddFieldWindow, DragBeginHdl));
80 m_xDialog->connect_container_focus_changed(
LINK(
this, OAddFieldWindow, FocusChangeHdl));
84 m_xActions->connect_clicked(
LINK(
this, OAddFieldWindow, OnSortAction));
85 m_xActions->set_item_active(
"up",
true);
86 m_xListBox->make_sorted();
87 m_xActions->set_item_sensitive(
"insert",
false);
89 m_xListBox->connect_row_activated(
LINK(
this, OAddFieldWindow, OnDoubleClickHdl ) );
90 m_xListBox->connect_changed(
LINK(
this, OAddFieldWindow, OnSelectHdl ) );
91 m_xListBox->set_size_request(m_xListBox->get_approximate_digit_width() * 45, m_xListBox->get_height_rows(8));
99 m_pChangeListener = new ::comphelper::OPropertyChangeMultiplexer(
this, m_xRowSet );
105 catch(
const Exception& )
111OAddFieldWindow::~OAddFieldWindow()
113 m_aListBoxData.clear();
114 if (m_pChangeListener.is())
115 m_pChangeListener->dispose();
116 if ( m_pContainerListener.is() )
117 m_pContainerListener->dispose();
123 m_xListBox->grab_focus();
126uno::Sequence< beans::PropertyValue > OAddFieldWindow::getSelectedFieldDescriptors()
128 std::vector<beans::PropertyValue> aArgs;
130 m_xListBox->selected_foreach([
this, &aArgs](
weld::TreeIter& rEntry){
133 fillDescriptor(rEntry, aDescriptor);
134 aArgs.push_back(beans::PropertyValue());
143void OAddFieldWindow::_propertyChanged(
const beans::PropertyChangeEvent& _evt )
145 OSL_ENSURE( _evt.Source == m_xRowSet,
"OAddFieldWindow::_propertyChanged: where did this come from?" );
149void OAddFieldWindow::addToList(
const uno::Sequence< OUString >& rEntries)
151 for (
const OUString& rEntry : rEntries)
153 m_aListBoxData.emplace_back(
new ColumnInfo(rEntry));
155 m_xListBox->append(sId, rEntry);
159void OAddFieldWindow::addToList(
const uno::Reference< container::XNameAccess>& i_xColumns)
161 const uno::Sequence< OUString >
aEntries = i_xColumns->getElementNames();
162 for (
const OUString& rEntry : aEntries )
164 uno::Reference< beans::XPropertySet>
xColumn(i_xColumns->getByName(rEntry),UNO_QUERY_THROW);
168 m_aListBoxData.emplace_back(
new ColumnInfo(rEntry, sLabel));
170 if ( !sLabel.isEmpty() )
171 m_xListBox->append(sId, sLabel);
173 m_xListBox->append(sId, rEntry);
177void OAddFieldWindow::Update()
181 if ( m_pContainerListener.is() )
182 m_pContainerListener->dispose();
183 m_pContainerListener =
nullptr;
190 m_aListBoxData.clear();
191 const OUString aIds[] = {
"up",
"down" };
192 for (
size_t j = 0; j< std::size(aIds); ++j)
193 m_xActions->set_item_sensitive(aIds[j],
false);
195 OUString aTitle(
RptResId(RID_STR_FIELDSELECTION));
197 if ( m_xRowSet.is() )
199 OUString sCommand( m_aCommandName );
201 bool bEscapeProcessing( m_bEscapeProcessing );
207 OSL_VERIFY( m_xRowSet->getPropertyValue(
PROPERTY_FILTER ) >>= sFilter );
209 m_aCommandName = sCommand;
211 m_bEscapeProcessing = bEscapeProcessing;
216 if ( xCon.is() && !m_aCommandName.isEmpty() )
218 if ( m_xColumns.is() )
220 addToList(m_xColumns);
221 uno::Reference< container::XContainer> xContainer(m_xColumns,uno::UNO_QUERY);
222 if ( xContainer.is() )
223 m_pContainerListener = new ::comphelper::OContainerListenerAdapter(
this,xContainer);
227 uno::Reference< css::sdbc::XRowSet > xRowSet(m_xRowSet,uno::UNO_QUERY);
229 addToList(aParamNames);
232 aTitle +=
" " + m_aCommandName;
234 if ( !m_aCommandName.isEmpty() )
236 for (
size_t i = 0;
i < std::size(aIds); ++
i)
237 m_xActions->set_item_sensitive(aIds[
i],
true);
239 OnSelectHdl(*m_xListBox);
248uno::Reference< sdbc::XConnection> OAddFieldWindow::getConnection()
const
255 if (!m_xColumns.is())
258 uno::Reference<container::XChild> xChild(
getConnection(),uno::UNO_QUERY);
261 uno::Reference<sdb::XDocumentDataSource> xDocument( xChild->getParent(), uno::UNO_QUERY );
262 if ( xDocument.is() )
264 uno::Reference<frame::XModel>
xModel(xDocument->getDatabaseDocument(),uno::UNO_QUERY);
266 rDescriptor[ DataAccessDescriptorProperty::DatabaseLocation ] <<=
xModel->getURL();
275 ColumnInfo* pInfo = weld::fromId<ColumnInfo*>(m_xListBox->get_id(rSelected));
281void OAddFieldWindow::_elementInserted(
const container::ContainerEvent& _rEvent )
284 if ( !((_rEvent.Accessor >>=
sName) && m_xColumns->hasByName(
sName)) )
287 uno::Reference< beans::XPropertySet>
xColumn(m_xColumns->getByName(
sName),UNO_QUERY_THROW);
293 if (!sLabel.isEmpty())
294 m_xListBox->append(
sId, sLabel);
299void OAddFieldWindow::_elementRemoved(
const container::ContainerEvent& )
302 m_aListBoxData.clear();
303 if ( m_xColumns.is() )
304 addToList(m_xColumns);
307void OAddFieldWindow::_elementReplaced(
const container::ContainerEvent& )
313 m_xActions->set_item_sensitive(
"insert", m_xListBox->get_selected_index() != -1);
318 m_aCreateLink.Call(*
this);
324 if (rCurItem ==
"insert")
326 OnDoubleClickHdl(*m_xListBox);
330 const OUString aIds[] = {
"up",
"down" };
332 if (rCurItem ==
"delete")
334 for (
size_t j = 0; j< std::size(aIds); ++j)
335 m_xActions->set_item_active(aIds[j],
false);
337 m_xListBox->make_unsorted();
342 for (
size_t j = 0; j< std::size(aIds); ++j)
343 m_xActions->set_item_active(aIds[j], rCurItem == aIds[j]);
345 m_xListBox->make_sorted();
346 if (m_xActions->get_item_active(
"down"))
347 m_xListBox->set_sort_order(
false);
Reference< XExecutableDialog > m_xDialog
OAddFieldWindow(const OAddFieldWindow &)=delete
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
OUString RptResId(TranslateId aId)
#define DBG_UNHANDLED_EXCEPTION(...)
ScXMLEditAttributeMap::Entry const aEntries[]
#define HID_RPT_FIELD_SEL_WIN
constexpr OUStringLiteral HID_RPT_FIELD_SEL
#define LINK(Instance, Class, Member)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
IMPL_LINK_NOARG(OAddFieldWindow, OnDoubleClickHdl, weld::TreeView &, bool)
css::uno::Sequence< OUString > getParameterNames(const css::uno::Reference< css::sdbc::XRowSet > &_rxRowSet)
retrieves the names of the parameters of the command which the given RowSet is bound to
IMPL_LINK(OAddFieldWindow, OnSortAction, const OUString &, rCurItem, void)
IMPL_LINK(OAddFieldWindow, DragBeginHdl, bool &, rUnsetDragIcon, bool)
OUString toId(const void *pValue)
constexpr OUStringLiteral PROPERTY_LABEL
constexpr OUStringLiteral PROPERTY_COMMAND
constexpr OUStringLiteral PROPERTY_ACTIVECONNECTION
constexpr OUStringLiteral PROPERTY_COMMANDTYPE
constexpr OUStringLiteral PROPERTY_FILTER
constexpr OUStringLiteral PROPERTY_ESCAPEPROCESSING
Reference< XModel > xModel