Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "ColumnControlWindow.hxx"
21 : #include "FieldControls.hxx"
22 : #include <unotools/syslocale.hxx>
23 : #include <connectivity/dbtools.hxx>
24 : #include "UITools.hxx"
25 : #include "dbu_resource.hrc"
26 : #include <comphelper/processfactory.hxx>
27 : #include <com/sun/star/util/NumberFormatter.hpp>
28 :
29 :
30 : using namespace ::dbaui;
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::beans;
33 : using namespace ::com::sun::star::container;
34 : using namespace ::com::sun::star::util;
35 : using namespace ::com::sun::star::sdbc;
36 : using namespace ::com::sun::star::lang;
37 :
38 : //========================================================================
39 : // OColumnControlWindow
40 : DBG_NAME(OColumnControlWindow)
41 : //========================================================================
42 0 : OColumnControlWindow::OColumnControlWindow(Window* pParent
43 : ,const Reference<XComponentContext>& _rxContext)
44 : : OFieldDescControl(pParent,NULL)
45 : , m_xContext(_rxContext)
46 : , m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES))
47 0 : , m_bAutoIncrementEnabled(sal_True)
48 : {
49 : DBG_CTOR(OColumnControlWindow,NULL);
50 :
51 0 : setRightAligned();
52 0 : m_aLocale = SvtSysLocale().GetLanguageTag().getLocale();
53 0 : }
54 : // -----------------------------------------------------------------------------
55 0 : OColumnControlWindow::~OColumnControlWindow()
56 : {
57 :
58 : DBG_DTOR(OColumnControlWindow,NULL);
59 0 : }
60 : // -----------------------------------------------------------------------
61 0 : void OColumnControlWindow::ActivateAggregate( EControlType eType )
62 : {
63 0 : switch(eType )
64 : {
65 : case tpFormat:
66 : case tpDefault:
67 : case tpColumnName:
68 0 : break;
69 : default:
70 0 : OFieldDescControl::ActivateAggregate( eType );
71 : }
72 0 : }
73 : // -----------------------------------------------------------------------
74 0 : void OColumnControlWindow::DeactivateAggregate( EControlType eType )
75 : {
76 0 : switch(eType )
77 : {
78 : case tpFormat:
79 : case tpDefault:
80 : case tpColumnName:
81 0 : break;
82 : default:
83 0 : OFieldDescControl::DeactivateAggregate( eType );
84 : }
85 0 : }
86 : // -----------------------------------------------------------------------------
87 0 : void OColumnControlWindow::CellModified(long /*nRow*/, sal_uInt16 /*nColId*/ )
88 : {
89 0 : saveCurrentFieldDescData();
90 0 : }
91 : // -----------------------------------------------------------------------------
92 0 : ::com::sun::star::lang::Locale OColumnControlWindow::GetLocale() const
93 : {
94 0 : return m_aLocale;
95 : }
96 : // -----------------------------------------------------------------------------
97 0 : Reference< XNumberFormatter > OColumnControlWindow::GetFormatter() const
98 : {
99 0 : if ( !m_xFormatter.is() )
100 : try
101 : {
102 0 : Reference< XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(m_xConnection, sal_True, m_xContext));
103 :
104 0 : if ( xSupplier.is() )
105 : {
106 : // create a new formatter
107 0 : m_xFormatter.set( NumberFormatter::create(m_xContext), UNO_QUERY_THROW);
108 0 : m_xFormatter->attachNumberFormatsSupplier(xSupplier);
109 0 : }
110 : }
111 0 : catch(Exception&)
112 : {
113 : }
114 0 : return m_xFormatter;
115 : }
116 : // -----------------------------------------------------------------------------
117 0 : TOTypeInfoSP OColumnControlWindow::getTypeInfo(sal_Int32 _nPos)
118 : {
119 0 : return ( _nPos >= 0 && _nPos < static_cast<sal_Int32>(m_aDestTypeInfoIndex.size())) ? m_aDestTypeInfoIndex[_nPos]->second : TOTypeInfoSP();
120 : }
121 : // -----------------------------------------------------------------------------
122 0 : const OTypeInfoMap* OColumnControlWindow::getTypeInfo() const
123 : {
124 0 : return &m_aDestTypeInfo;
125 : }
126 : // -----------------------------------------------------------------------------
127 0 : Reference< XDatabaseMetaData> OColumnControlWindow::getMetaData()
128 : {
129 0 : if ( m_xConnection.is() )
130 0 : return m_xConnection->getMetaData();
131 0 : return Reference< XDatabaseMetaData>();
132 : }
133 : // -----------------------------------------------------------------------------
134 0 : Reference< XConnection> OColumnControlWindow::getConnection()
135 : {
136 0 : return m_xConnection;
137 : }
138 : // -----------------------------------------------------------------------------
139 0 : void OColumnControlWindow::setConnection(const Reference< XConnection>& _xCon)
140 : {
141 0 : m_xConnection = _xCon;
142 0 : m_xFormatter = NULL;
143 0 : m_aDestTypeInfoIndex.clear();
144 0 : m_aDestTypeInfo.clear();
145 :
146 0 : if ( m_xConnection.is() )
147 : {
148 0 : Init();
149 :
150 0 : ::dbaui::fillTypeInfo(m_xConnection,m_sTypeNames,m_aDestTypeInfo,m_aDestTypeInfoIndex);
151 : // read autoincrement value set in the datasource
152 0 : ::dbaui::fillAutoIncrementValue(m_xConnection,m_bAutoIncrementEnabled,m_sAutoIncrementValue);
153 : }
154 0 : }
155 : // -----------------------------------------------------------------------------
156 0 : sal_Bool OColumnControlWindow::isAutoIncrementValueEnabled() const
157 : {
158 0 : return m_bAutoIncrementEnabled;
159 : }
160 : // -----------------------------------------------------------------------------
161 0 : OUString OColumnControlWindow::getAutoIncrementValue() const
162 : {
163 0 : return m_sAutoIncrementValue;
164 : }
165 : // -----------------------------------------------------------------------------
166 0 : TOTypeInfoSP OColumnControlWindow::getDefaultTyp() const
167 : {
168 0 : if ( !m_pTypeInfo.get() )
169 : {
170 0 : m_pTypeInfo = TOTypeInfoSP(new OTypeInfo());
171 0 : m_pTypeInfo->aUIName = m_sTypeNames.GetToken(TYPE_OTHER);
172 : }
173 0 : return m_pTypeInfo;
174 12 : }
175 : // -----------------------------------------------------------------------------
176 :
177 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|