24#include <core_resource.hxx>
27#include <bitmaps.hlst>
32#include <com/sun/star/sdb/SQLContext.hpp>
34#include <osl/diagnose.h>
55 return std::equal(_rLHS.begin(), _rLHS.end(), _rRHS.begin(), _rRHS.end());
60 return !(_rLHS == _rRHS);
68 : GenericDialogController(pParent,
"dbaccess/ui/indexdesigndialog.ui",
"IndexDesignDialog")
70 , m_bEditingActive(false)
72 , m_bNoHandlerCall(false)
74 , m_xActions(m_xBuilder->weld_toolbar(
"ACTIONS"))
75 , m_xIndexList(m_xBuilder->weld_tree_view(
"INDEX_LIST"))
76 , m_xIndexDetails(m_xBuilder->weld_label(
"INDEX_DETAILS"))
77 , m_xDescriptionLabel(m_xBuilder->weld_label(
"DESC_LABEL"))
78 , m_xDescription(m_xBuilder->weld_label(
"DESCRIPTION"))
79 , m_xUnique(m_xBuilder->weld_check_button(
"UNIQUE"))
80 , m_xFieldsLabel(m_xBuilder->weld_label(
"FIELDS_LABEL"))
81 , m_xClose(m_xBuilder->weld_button(
"close"))
82 , m_xTable(m_xBuilder->weld_container(
"FIELDS"))
83 , m_xTableCtrlParent(m_xTable->CreateChildFrame())
89 int nWidth =
m_xIndexList->get_approximate_digit_width() * 60;
91 m_xTable->set_size_request(nWidth, nHeight);
100 m_xFields->Init(_rFieldNames, ::dbtools::getBooleanDataSourceSetting(
m_xConnection,
"AddIndexAppendix" ));
108 catch(SQLException& e)
114 OSL_FAIL(
"DbaIndexDialog::DbaIndexDialog: could not retrieve basic information from the UNO collection!");
128 if (!
check.sDescription.isEmpty())
147 bool bSelectedAnything = nSelected != -1;
148 if (bSelectedAnything)
152 m_xActions->set_item_sensitive(
"ID_INDEX_SAVE", aSelectedPos->isModified() || aSelectedPos->isNew());
153 m_xActions->set_item_sensitive(
"ID_INDEX_RESET", aSelectedPos->isModified() || aSelectedPos->isNew());
154 bSelectedAnything = !aSelectedPos->bPrimaryKey;
158 m_xActions->set_item_sensitive(
"ID_INDEX_SAVE",
false);
159 m_xActions->set_item_sensitive(
"ID_INDEX_RESET",
false);
161 m_xActions->set_item_sensitive(
"ID_INDEX_DROP", bSelectedAnything);
162 m_xActions->set_item_sensitive(
"ID_INDEX_RENAME", bSelectedAnything);
167 OUString aPKeyIcon(BMP_PKEYICON);
174 if (indexLoop.bPrimaryKey)
195 assert(pEntry &&
"DbaIndexDialog::implCommit: invalid entry!");
201 if (!aCommitPos->isNew())
226 return !aExceptionInfo.
isValid();
236 OUString sNewIndexName;
237 const OUString sNewIndexNameBase(
DBA_RES(STR_LOGICAL_INDEX_NAME));
240 for (
i = 1;
i < 0x7FFFFFFF; ++
i )
242 sNewIndexName = sNewIndexNameBase + OUString::number(
i);
248 OSL_FAIL(
"DbaIndexDialog::OnNewIndex: no free index name found!");
253 std::unique_ptr<weld::TreeIter> xNewEntry(
m_xIndexList->make_iterator());
254 m_xIndexList->insert(
nullptr, -1, &sNewIndexName,
nullptr,
nullptr,
nullptr,
false, xNewEntry.get());
261 OSL_ENSURE(aAfterInsertPos !=
m_xIndexes->end(),
"DbaIndexDialog::OnNewIndex: problems with one of the entries!");
278 std::unique_ptr<weld::TreeIter> xSelected(
m_xIndexList->make_iterator());
286 OUString sConfirm(
DBA_RES(STR_CONFIRM_DROP_INDEX));
287 sConfirm = sConfirm.replaceFirst(
"$name$",
m_xIndexList->get_text(*xSelected));
289 VclMessageType::Question, VclButtonsType::YesNo,
291 if (
RET_YES != xConfirm->run())
306 OSL_ENSURE(aDropPos !=
m_xIndexes->end(),
"DbaIndexDialog::OnDropIndex: did not find the index in my collection!");
309 bool bSuccess =
false;
312 if (_bRemoveFromCollection)
315 bSuccess =
m_xIndexes->dropNoRemove(aDropPos);
323 else if (bSuccess && _bRemoveFromCollection)
338 OSL_ENSURE(aAfterDropPos !=
m_xIndexes->end(),
"DbaIndexDialog::OnDropIndex: problems with one of the remaining entries!");
348 return !aExceptionInfo.
isValid();
354 std::unique_ptr<weld::TreeIter> xSelected(
m_xIndexList->make_iterator());
378 std::unique_ptr<weld::TreeIter> xSelected(
m_xIndexList->make_iterator());
382 OSL_ENSURE(xSelected,
"DbaIndexDialog::OnResetIndex: invalid call!");
388 if (aResetPos->isNew())
414 if (rClicked ==
"ID_INDEX_NEW")
416 else if (rClicked ==
"ID_INDEX_DROP")
418 else if (rClicked ==
"ID_INDEX_RENAME")
420 else if (rClicked ==
"ID_INDEX_SAVE")
422 else if (rClicked ==
"ID_INDEX_RESET")
428 if (m_bEditingActive)
430 OSL_ENSURE(!m_bEditAgain,
"DbaIndexDialog::OnCloseDialog: somebody was faster than hell!");
433 m_xIndexList->end_editing();
440 std::unique_ptr<weld::TreeIter> xSelected(m_xIndexList->make_iterator());
442 if (!m_xIndexList->get_selected(xSelected.get()))
445 OSL_ENSURE(xSelected && m_xPreviousSelection && xSelected->equal(*m_xPreviousSelection),
"DbaIndexDialog::OnCloseDialog: inconsistence!");
447 sal_Int32 nResponse =
RET_NO;
451 Indexes::const_iterator aSelected = m_xIndexes->begin() + m_xIndexList->get_id(*xSelected).toUInt32();
452 if (aSelected->isModified() || aSelected->isNew())
455 std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog(
"SaveIndexDialog"));
456 nResponse = xQuery->run();
463 if (!implCommitPreviouslySelected())
478 m_bEditAgain =
false;
479 m_xIndexList->grab_focus();
480 m_xIndexList->start_editing(*pEntry);
486 m_bEditingActive =
true;
492 m_bEditingActive =
false;
495 OUString sNewName = rIterString.second;
497 Indexes::iterator aPosition = m_xIndexes->begin() + m_xIndexList->get_id(rEntry).toUInt32();
499 OSL_ENSURE(aPosition >= m_xIndexes->begin() && aPosition < m_xIndexes->
end(),
500 "DbaIndexDialog::OnEntryEdited: invalid entry!");
502 Indexes::const_iterator aSameName = m_xIndexes->find(sNewName);
503 if (aSameName != aPosition && m_xIndexes->end() != aSameName)
505 OUString sError(
DBA_RES(STR_INDEX_NAME_ALREADY_USED));
506 sError = sError.replaceFirst(
"$name$", sNewName);
508 VclMessageType::Warning, VclButtonsType::Ok,
514 std::unique_ptr<weld::TreeIter> xEntry(m_xIndexList->make_iterator(&rEntry));
519 aPosition->sName = sNewName;
522 if (aPosition->isNew())
529 if (aPosition->sName != aPosition->getOriginalName())
531 aPosition->setModified(
true);
547 Indexes::iterator aPreviouslySelected =
m_xIndexes->begin() +
m_xIndexList->get_id(*m_xPreviousSelection).toUInt32();
550 aPreviouslySelected->bUnique =
m_xUnique->get_active();
551 if (
m_xUnique->get_state_changed_from_saved())
552 aPreviouslySelected->setModified(
true);
555 m_xFields->commitTo(aPreviouslySelected->aFields);
556 if (
m_xFields->GetSavedValue() != aPreviouslySelected->aFields)
557 aPreviouslySelected->setModified(
true);
569 if (_rPos->aFields.empty())
572 VclMessageType::Warning, VclButtonsType::Ok,
573 DBA_RES(STR_NEED_INDEX_FIELDS)));
580 std::set< OUString > aExistentFields;
581 for (
auto const& fieldCheck : _rPos->aFields)
583 if (aExistentFields.end() != aExistentFields.find(fieldCheck.sFieldName))
589 VclMessageType::Warning, VclButtonsType::Ok,
595 aExistentFields.insert(fieldCheck.sFieldName);
605 Indexes::const_iterator aPreviouslySelected =
m_xIndexes->begin() +
m_xIndexList->get_id(*m_xPreviousSelection).toUInt32();
620 OnModified(*m_xFields);
625 assert(m_xPreviousSelection &&
"DbaIndexDialog, OnModified: invalid call!");
626 Indexes::iterator aPosition = m_xIndexes->begin() + m_xIndexList->get_id(*m_xPreviousSelection).toUInt32();
628 aPosition->setModified(
true);
640 m_xUnique->set_active(aSelectedIndex->bUnique);
641 m_xUnique->set_sensitive(!aSelectedIndex->bPrimaryKey);
644 m_xFields->initializeFrom(std::vector(aSelectedIndex->aFields));
645 m_xFields->Enable(!aSelectedIndex->bPrimaryKey);
666 std::unique_ptr<weld::TreeIter> xSelected(
m_xIndexList->make_iterator());
685 m_xUnique->set_sensitive(xSelected !=
nullptr);
701 if (m_bNoHandlerCall)
Reference< XExecutableDialog > m_xDialog
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< weld::Container > m_xTable
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Reference< css::awt::XWindow > m_xTableCtrlParent
std::unique_ptr< OIndexCollection > m_xIndexes
virtual ~DbaIndexDialog() override
bool implCommitPreviouslySelected()
std::unique_ptr< weld::Label > m_xDescription
css::uno::Reference< css::sdbc::XConnection > m_xConnection
std::unique_ptr< weld::Label > m_xDescriptionLabel
std::unique_ptr< weld::Toolbar > m_xActions
std::unique_ptr< weld::Button > m_xClose
void updateControls(const weld::TreeIter *pEntry)
DbaIndexDialog(weld::Window *_pParent, const css::uno::Sequence< OUString > &_rFieldNames, const css::uno::Reference< css::container::XNameAccess > &_rxIndexes, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
std::unique_ptr< weld::Label > m_xIndexDetails
bool implDropIndex(const weld::TreeIter *pEntry, bool _bRemoveFromCollection)
std::unique_ptr< weld::TreeIter > m_xPreviousSelection
std::unique_ptr< weld::TreeView > m_xIndexList
void OnDropIndex(bool _bConfirm=true)
bool implSaveModified(bool _bPlausibility=true)
VclPtr< IndexFieldsControl > m_xFields
std::unique_ptr< weld::CheckButton > m_xUnique
bool implCheckPlausibility(const Indexes::const_iterator &_rPos)
bool implCommit(const weld::TreeIter *pEntry)
std::unique_ptr< weld::Label > m_xFieldsLabel
std::shared_ptr< weld::Dialog > m_xDialog
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
Reference< XComponentContext > m_xContext
#define LINK(Instance, Class, Member)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
static bool operator==(const OIndexField &_rLHS, const OIndexField &_rRHS)
std::vector< OIndexField > IndexFields
static bool operator!=(const IndexFields &_rLHS, const IndexFields &_rRHS)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > > check(dp_misc::DescriptionInfoset const &infoset)
Reference< XConnection > m_xConnection