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 "optjava.hxx"
21 : #include <dialmgr.hxx>
22 :
23 : #include <svtools/miscopt.hxx>
24 :
25 : #include "optjava.hrc"
26 : #include <cuires.hrc>
27 : #include "helpid.hrc"
28 : #include <vcl/svapp.hxx>
29 : #include <vcl/help.hxx>
30 : #include <tools/urlobj.hxx>
31 : #include <vcl/msgbox.hxx>
32 : #include <vcl/waitobj.hxx>
33 : #include <unotools/pathoptions.hxx>
34 : #include <svtools/imagemgr.hxx>
35 : #include "svtools/restartdialog.hxx"
36 : #include "svtools/treelistentry.hxx"
37 : #include <sfx2/filedlghelper.hxx>
38 : #include <comphelper/processfactory.hxx>
39 : #include <comphelper/string.hxx>
40 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
42 : #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
43 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
44 : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
45 : #include <com/sun/star/ucb/XContentProvider.hpp>
46 : #include <jvmfwk/framework.h>
47 :
48 : // define ----------------------------------------------------------------
49 :
50 : #define CLASSPATH_DELIMITER SAL_PATHSEPARATOR
51 : #define BUTTON_BORDER 2
52 : #define RESET_TIMEOUT 300
53 :
54 : using namespace ::com::sun::star::lang;
55 : using namespace ::com::sun::star::ucb;
56 : using namespace ::com::sun::star::ui::dialogs;
57 : using namespace ::com::sun::star::uno;
58 :
59 : // -----------------------------------------------------------------------
60 :
61 0 : bool areListsEqual( const Sequence< ::rtl::OUString >& rListA, const Sequence< ::rtl::OUString >& rListB )
62 : {
63 0 : bool bRet = true;
64 0 : const sal_Int32 nLen = rListA.getLength();
65 :
66 0 : if ( rListB.getLength() != nLen )
67 0 : bRet = false;
68 : else
69 : {
70 0 : const ::rtl::OUString* pStringA = rListA.getConstArray();
71 0 : const ::rtl::OUString* pStringB = rListB.getConstArray();
72 :
73 0 : for ( sal_Int32 i = 0; i < nLen; ++i )
74 : {
75 0 : if ( *pStringA++ != *pStringB++ )
76 : {
77 0 : bRet = false;
78 0 : break;
79 : }
80 : }
81 : }
82 :
83 0 : return bRet;
84 : }
85 :
86 : // class SvxJavaOptionsPage ----------------------------------------------
87 :
88 0 : SvxJavaOptionsPage::SvxJavaOptionsPage( Window* pParent, const SfxItemSet& rSet ) :
89 :
90 0 : SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_OPTIONS_JAVA ), rSet ),
91 :
92 0 : m_aJavaLine ( this, CUI_RES( FL_JAVA ) ),
93 0 : m_aJavaEnableCB ( this, CUI_RES( CB_JAVA_ENABLE ) ),
94 0 : m_aJavaFoundLabel ( this, CUI_RES( FT_JAVA_FOUND ) ),
95 0 : m_aJavaListContainer(this, CUI_RES(LB_JAVA)),
96 : m_aJavaList(m_aJavaListContainer),
97 0 : m_aJavaPathText ( this, CUI_RES( FT_JAVA_PATH ) ),
98 0 : m_aAddBtn ( this, CUI_RES( PB_ADD ) ),
99 0 : m_aParameterBtn ( this, CUI_RES( PB_PARAMETER ) ),
100 0 : m_aClassPathBtn ( this, CUI_RES( PB_CLASSPATH ) ),
101 :
102 : m_pParamDlg ( NULL ),
103 : m_pPathDlg ( NULL ),
104 : m_parJavaInfo ( NULL ),
105 : m_parParameters ( NULL ),
106 : m_pClassPath ( NULL ),
107 : m_nInfoSize ( 0 ),
108 : m_nParamSize ( 0 ),
109 0 : m_sInstallText ( CUI_RES( STR_INSTALLED_IN ) ),
110 0 : m_sAccessibilityText( CUI_RES( STR_ACCESSIBILITY ) ),
111 0 : m_sAddDialogText ( CUI_RES( STR_ADDDLGTEXT ) ),
112 :
113 0 : m_aExperimental ( this, CUI_RES( FL_EXPERIMENTAL ) ),
114 0 : m_aExperimentalCB ( this, CUI_RES( CB_EXPERIMENTAL ) ),
115 0 : m_aMacroCB ( this, CUI_RES( CB_MACRO ) ),
116 :
117 0 : xDialogListener ( new ::svt::DialogClosedListener() )
118 : {
119 0 : m_aJavaEnableCB.SetClickHdl( LINK( this, SvxJavaOptionsPage, EnableHdl_Impl ) );
120 0 : m_aJavaList.SetCheckButtonHdl( LINK( this, SvxJavaOptionsPage, CheckHdl_Impl ) );
121 0 : m_aJavaList.SetSelectHdl( LINK( this, SvxJavaOptionsPage, SelectHdl_Impl ) );
122 0 : m_aAddBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, AddHdl_Impl ) );
123 0 : m_aParameterBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, ParameterHdl_Impl ) );
124 0 : m_aClassPathBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, ClassPathHdl_Impl ) );
125 0 : m_aResetTimer.SetTimeoutHdl( LINK( this, SvxJavaOptionsPage, ResetHdl_Impl ) );
126 0 : m_aResetTimer.SetTimeout( RESET_TIMEOUT );
127 :
128 : static long aStaticTabs[]=
129 : {
130 : 5, 0, 15, 90, 130, 300
131 : };
132 :
133 0 : m_aJavaList.SvxSimpleTable::SetTabs( aStaticTabs );
134 0 : rtl::OUStringBuffer sHeader;
135 0 : sHeader.append('\t');
136 0 : sHeader.append(CUI_RESSTR(STR_HEADER_VENDOR));
137 0 : sHeader.append('\t');
138 0 : sHeader.append(CUI_RESSTR(STR_HEADER_VERSION));
139 0 : sHeader.append('\t');
140 0 : sHeader.append(CUI_RESSTR(STR_HEADER_FEATURES));
141 0 : sHeader.append('\t');
142 0 : m_aJavaList.InsertHeaderEntry( sHeader.makeStringAndClear(), HEADERBAR_APPEND, HIB_LEFT );
143 :
144 0 : m_aJavaList.SetHelpId( HID_OPTIONS_JAVA_LIST );
145 :
146 0 : FreeResource();
147 :
148 0 : xDialogListener->SetDialogClosedLink( LINK( this, SvxJavaOptionsPage, DialogClosedHdl ) );
149 :
150 0 : EnableHdl_Impl( &m_aJavaEnableCB );
151 0 : jfw_lock();
152 :
153 : //check if the text fits into the class path button
154 0 : Size aButtonSize = m_aClassPathBtn.GetOutputSizePixel();
155 0 : sal_Int32 nTextWidth = m_aClassPathBtn.GetTextWidth(m_aClassPathBtn.GetText());
156 : //add some additional space
157 0 : sal_Int32 nDiff = nTextWidth + 4 - aButtonSize.Width();
158 0 : if( nDiff > 0)
159 : {
160 0 : Point aPos(m_aClassPathBtn.GetPosPixel());
161 0 : aPos.X() -= nDiff;
162 0 : aButtonSize.Width() += nDiff;
163 0 : m_aClassPathBtn.SetPosSizePixel(aPos, aButtonSize);
164 0 : aPos = m_aAddBtn.GetPosPixel();
165 0 : aPos.X() -= nDiff;
166 0 : m_aAddBtn.SetPosSizePixel(aPos, aButtonSize);
167 0 : aPos = m_aParameterBtn.GetPosPixel();
168 0 : aPos.X() -= nDiff;
169 0 : m_aParameterBtn.SetPosSizePixel(aPos, aButtonSize);
170 0 : Size aSize = m_aJavaListContainer.GetSizePixel();
171 0 : aSize.Width() -= nDiff;
172 0 : m_aJavaListContainer.SetSizePixel(aSize);
173 0 : }
174 0 : }
175 :
176 : // -----------------------------------------------------------------------
177 :
178 0 : SvxJavaOptionsPage::~SvxJavaOptionsPage()
179 : {
180 0 : delete m_pParamDlg;
181 0 : delete m_pPathDlg;
182 0 : ClearJavaInfo();
183 0 : std::vector< JavaInfo* >::iterator pIter;
184 0 : for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
185 : {
186 0 : JavaInfo* pInfo = *pIter;
187 0 : jfw_freeJavaInfo( pInfo );
188 : }
189 :
190 0 : jfw_unlock();
191 0 : }
192 :
193 : // -----------------------------------------------------------------------
194 :
195 0 : IMPL_LINK_NOARG(SvxJavaOptionsPage, EnableHdl_Impl)
196 : {
197 0 : sal_Bool bEnable = m_aJavaEnableCB.IsChecked();
198 0 : m_aJavaFoundLabel.Enable( bEnable );
199 0 : m_aJavaPathText.Enable( bEnable );
200 0 : m_aAddBtn.Enable( bEnable );
201 0 : m_aParameterBtn.Enable( bEnable );
202 0 : m_aClassPathBtn.Enable( bEnable );
203 :
204 0 : bEnable ? m_aJavaList.EnableTable() : m_aJavaList.DisableTable();
205 :
206 0 : return 0;
207 : }
208 :
209 : // -----------------------------------------------------------------------
210 :
211 0 : IMPL_LINK( SvxJavaOptionsPage, CheckHdl_Impl, SvxSimpleTable *, pList )
212 : {
213 0 : SvTreeListEntry* pEntry = pList ? m_aJavaList.GetEntry( m_aJavaList.GetCurMousePoint() )
214 0 : : m_aJavaList.FirstSelected();
215 0 : if ( pEntry )
216 0 : m_aJavaList.HandleEntryChecked( pEntry );
217 0 : return 0;
218 : }
219 :
220 : // -----------------------------------------------------------------------
221 :
222 0 : IMPL_LINK_NOARG(SvxJavaOptionsPage, SelectHdl_Impl)
223 : {
224 : // set installation directory info
225 0 : SvTreeListEntry* pEntry = m_aJavaList.FirstSelected();
226 : DBG_ASSERT( pEntry, "SvxJavaOptionsPage::SelectHdl_Impl(): no entry" );
227 0 : String* pLocation = static_cast< String* >( pEntry->GetUserData() );
228 : DBG_ASSERT( pLocation, "invalid location string" );
229 0 : String sInfo = m_sInstallText;
230 0 : if ( pLocation )
231 0 : sInfo += *pLocation;
232 0 : m_aJavaPathText.SetText( sInfo );
233 0 : return 0;
234 : }
235 :
236 : // -----------------------------------------------------------------------
237 :
238 0 : IMPL_LINK_NOARG(SvxJavaOptionsPage, AddHdl_Impl)
239 : {
240 : try
241 : {
242 0 : Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
243 0 : xFolderPicker = FolderPicker::create(xContext);
244 :
245 0 : String sWorkFolder = SvtPathOptions().GetWorkPath();
246 0 : xFolderPicker->setDisplayDirectory( sWorkFolder );
247 0 : xFolderPicker->setDescription( m_sAddDialogText );
248 :
249 0 : Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
250 0 : if ( xAsyncDlg.is() )
251 0 : xAsyncDlg->startExecuteModal( xDialogListener.get() );
252 0 : else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
253 0 : AddFolder( xFolderPicker->getDirectory() );
254 : }
255 0 : catch (const Exception&)
256 : {
257 : SAL_WARN( "cui.options", "SvxJavaOptionsPage::AddHdl_Impl(): caught exception" );
258 : }
259 :
260 0 : return 0;
261 : }
262 :
263 : // -----------------------------------------------------------------------
264 :
265 0 : IMPL_LINK_NOARG(SvxJavaOptionsPage, ParameterHdl_Impl)
266 : {
267 0 : Sequence< ::rtl::OUString > aParameterList;
268 0 : if ( !m_pParamDlg )
269 : {
270 0 : m_pParamDlg = new SvxJavaParameterDlg( this );
271 0 : javaFrameworkError eErr = jfw_getVMParameters( &m_parParameters, &m_nParamSize );
272 0 : if ( JFW_E_NONE == eErr && m_parParameters && m_nParamSize > 0 )
273 : {
274 0 : rtl_uString** pParamArr = m_parParameters;
275 0 : aParameterList.realloc( m_nParamSize );
276 0 : ::rtl::OUString* pParams = aParameterList.getArray();
277 0 : for ( sal_Int32 i = 0; i < m_nParamSize; ++i )
278 : {
279 0 : rtl_uString* pParam = *pParamArr++;
280 0 : pParams[i] = ::rtl::OUString( pParam );
281 : }
282 0 : m_pParamDlg->SetParameters( aParameterList );
283 : }
284 : }
285 : else
286 0 : aParameterList = m_pParamDlg->GetParameters();
287 :
288 0 : if ( m_pParamDlg->Execute() == RET_OK )
289 : {
290 0 : if ( !areListsEqual( aParameterList, m_pParamDlg->GetParameters() ) )
291 : {
292 0 : aParameterList = m_pParamDlg->GetParameters();
293 0 : sal_Bool bRunning = sal_False;
294 0 : javaFrameworkError eErr = jfw_isVMRunning( &bRunning );
295 : DBG_ASSERT( JFW_E_NONE == eErr,
296 : "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
297 : (void)eErr;
298 0 : if ( bRunning )
299 : {
300 0 : WarningBox aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_OPTIONS_RESTART ) );
301 0 : aWarnBox.Execute();
302 : }
303 : }
304 : }
305 : else
306 0 : m_pParamDlg->SetParameters( aParameterList );
307 :
308 0 : return 0;
309 : }
310 :
311 : // -----------------------------------------------------------------------
312 :
313 0 : IMPL_LINK_NOARG(SvxJavaOptionsPage, ClassPathHdl_Impl)
314 : {
315 0 : String sClassPath;
316 :
317 0 : if ( !m_pPathDlg )
318 : {
319 0 : m_pPathDlg = new SvxJavaClassPathDlg( this );
320 0 : javaFrameworkError eErr = jfw_getUserClassPath( &m_pClassPath );
321 0 : if ( JFW_E_NONE == eErr && m_pClassPath )
322 : {
323 0 : sClassPath = String( ::rtl::OUString( m_pClassPath ) );
324 0 : m_pPathDlg->SetClassPath( sClassPath );
325 : }
326 : }
327 : else
328 0 : sClassPath = m_pPathDlg->GetClassPath();
329 :
330 0 : m_pPathDlg->SetFocus();
331 0 : if ( m_pPathDlg->Execute() == RET_OK )
332 : {
333 :
334 0 : if ( m_pPathDlg->GetClassPath() != sClassPath )
335 : {
336 0 : sClassPath = m_pPathDlg->GetClassPath();
337 0 : sal_Bool bRunning = sal_False;
338 0 : javaFrameworkError eErr = jfw_isVMRunning( &bRunning );
339 : DBG_ASSERT( JFW_E_NONE == eErr,
340 : "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
341 : (void)eErr;
342 0 : if ( bRunning )
343 : {
344 0 : WarningBox aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_OPTIONS_RESTART ) );
345 0 : aWarnBox.Execute();
346 : }
347 : }
348 : }
349 : else
350 0 : m_pPathDlg->SetClassPath( sClassPath );
351 :
352 0 : return 0;
353 : }
354 :
355 : // -----------------------------------------------------------------------
356 :
357 0 : IMPL_LINK_NOARG(SvxJavaOptionsPage, ResetHdl_Impl)
358 : {
359 0 : LoadJREs();
360 0 : return 0;
361 : }
362 :
363 : // -----------------------------------------------------------------------
364 :
365 0 : IMPL_LINK_NOARG(SvxJavaOptionsPage, StartFolderPickerHdl)
366 : {
367 : try
368 : {
369 0 : Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
370 0 : if ( xAsyncDlg.is() )
371 0 : xAsyncDlg->startExecuteModal( xDialogListener.get() );
372 0 : else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
373 0 : AddFolder( xFolderPicker->getDirectory() );
374 : }
375 0 : catch ( Exception& )
376 : {
377 : SAL_WARN( "cui.options", "SvxJavaOptionsPage::StartFolderPickerHdl(): caught exception" );
378 : }
379 :
380 0 : return 0L;
381 : }
382 :
383 : // -----------------------------------------------------------------------
384 :
385 0 : IMPL_LINK( SvxJavaOptionsPage, DialogClosedHdl, DialogClosedEvent*, pEvt )
386 : {
387 0 : if ( RET_OK == pEvt->DialogResult )
388 : {
389 : DBG_ASSERT( xFolderPicker.is() == sal_True, "SvxJavaOptionsPage::DialogClosedHdl(): no folder picker" );
390 :
391 0 : AddFolder( xFolderPicker->getDirectory() );
392 : }
393 0 : return 0L;
394 : }
395 :
396 : // -----------------------------------------------------------------------
397 :
398 0 : void SvxJavaOptionsPage::ClearJavaInfo()
399 : {
400 0 : if ( m_parJavaInfo )
401 : {
402 0 : JavaInfo** parInfo = m_parJavaInfo;
403 0 : for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
404 : {
405 0 : JavaInfo* pInfo = *parInfo++;
406 0 : jfw_freeJavaInfo( pInfo );
407 : }
408 :
409 0 : rtl_freeMemory( m_parJavaInfo );
410 0 : m_parJavaInfo = NULL;
411 0 : m_nInfoSize = 0;
412 : }
413 0 : }
414 :
415 : // -----------------------------------------------------------------------
416 :
417 0 : void SvxJavaOptionsPage::ClearJavaList()
418 : {
419 0 : SvTreeListEntry* pEntry = m_aJavaList.First();
420 0 : while ( pEntry )
421 : {
422 0 : String* pLocation = static_cast< String* >( pEntry->GetUserData() );
423 0 : delete pLocation;
424 0 : pEntry = m_aJavaList.Next( pEntry );
425 : }
426 0 : m_aJavaList.Clear();
427 0 : }
428 :
429 : // -----------------------------------------------------------------------
430 :
431 0 : void SvxJavaOptionsPage::LoadJREs()
432 : {
433 0 : WaitObject aWaitObj( &m_aJavaList );
434 0 : javaFrameworkError eErr = jfw_findAllJREs( &m_parJavaInfo, &m_nInfoSize );
435 0 : if ( JFW_E_NONE == eErr && m_parJavaInfo )
436 : {
437 0 : JavaInfo** parInfo = m_parJavaInfo;
438 0 : for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
439 : {
440 0 : JavaInfo* pInfo = *parInfo++;
441 0 : AddJRE( pInfo );
442 : }
443 : }
444 :
445 0 : std::vector< JavaInfo* >::iterator pIter;
446 0 : for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
447 : {
448 0 : JavaInfo* pInfo = *pIter;
449 0 : AddJRE( pInfo );
450 : }
451 :
452 0 : JavaInfo* pSelectedJava = NULL;
453 0 : eErr = jfw_getSelectedJRE( &pSelectedJava );
454 0 : if ( JFW_E_NONE == eErr && pSelectedJava )
455 : {
456 0 : JavaInfo** parInfo = m_parJavaInfo;
457 0 : for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
458 : {
459 0 : JavaInfo* pCmpInfo = *parInfo++;
460 0 : if ( jfw_areEqualJavaInfo( pCmpInfo, pSelectedJava ) )
461 : {
462 0 : SvTreeListEntry* pEntry = m_aJavaList.GetEntry(i);
463 0 : if ( pEntry )
464 0 : m_aJavaList.HandleEntryChecked( pEntry );
465 0 : break;
466 : }
467 : }
468 : }
469 :
470 0 : jfw_freeJavaInfo( pSelectedJava );
471 0 : }
472 :
473 : // -----------------------------------------------------------------------
474 :
475 0 : void SvxJavaOptionsPage::AddJRE( JavaInfo* _pInfo )
476 : {
477 0 : rtl::OUStringBuffer sEntry;
478 0 : sEntry.append('\t');
479 0 : sEntry.append(_pInfo->sVendor);
480 0 : sEntry.append('\t');
481 0 : sEntry.append(_pInfo->sVersion);
482 0 : sEntry.append('\t');
483 0 : if ( ( _pInfo->nFeatures & JFW_FEATURE_ACCESSBRIDGE ) == JFW_FEATURE_ACCESSBRIDGE )
484 0 : sEntry.append(m_sAccessibilityText);
485 0 : SvTreeListEntry* pEntry = m_aJavaList.InsertEntry(sEntry.makeStringAndClear());
486 0 : INetURLObject aLocObj( ::rtl::OUString( _pInfo->sLocation ) );
487 0 : String* pLocation = new String( aLocObj.getFSysPath( INetURLObject::FSYS_DETECT ) );
488 0 : pEntry->SetUserData( pLocation );
489 0 : }
490 :
491 : // -----------------------------------------------------------------------
492 :
493 0 : void SvxJavaOptionsPage::HandleCheckEntry( SvTreeListEntry* _pEntry )
494 : {
495 0 : m_aJavaList.Select( _pEntry, sal_True );
496 0 : SvButtonState eState = m_aJavaList.GetCheckButtonState( _pEntry );
497 :
498 0 : if ( SV_BUTTON_CHECKED == eState )
499 : {
500 : // we have radio button behavior -> so uncheck the other entries
501 0 : SvTreeListEntry* pEntry = m_aJavaList.First();
502 0 : while ( pEntry )
503 : {
504 0 : if ( pEntry != _pEntry )
505 0 : m_aJavaList.SetCheckButtonState( pEntry, SV_BUTTON_UNCHECKED );
506 0 : pEntry = m_aJavaList.Next( pEntry );
507 : }
508 : }
509 : else
510 0 : m_aJavaList.SetCheckButtonState( _pEntry, SV_BUTTON_CHECKED );
511 0 : }
512 :
513 : // -----------------------------------------------------------------------
514 :
515 0 : void SvxJavaOptionsPage::AddFolder( const ::rtl::OUString& _rFolder )
516 : {
517 0 : bool bStartAgain = true;
518 0 : JavaInfo* pInfo = NULL;
519 0 : javaFrameworkError eErr = jfw_getJavaInfoByPath( _rFolder.pData, &pInfo );
520 0 : if ( JFW_E_NONE == eErr && pInfo )
521 : {
522 0 : sal_Int32 nPos = 0;
523 0 : bool bFound = false;
524 0 : JavaInfo** parInfo = m_parJavaInfo;
525 0 : for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
526 : {
527 0 : JavaInfo* pCmpInfo = *parInfo++;
528 0 : if ( jfw_areEqualJavaInfo( pCmpInfo, pInfo ) )
529 : {
530 0 : bFound = true;
531 0 : nPos = i;
532 0 : break;
533 : }
534 : }
535 :
536 0 : if ( !bFound )
537 : {
538 0 : std::vector< JavaInfo* >::iterator pIter;
539 0 : for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
540 : {
541 0 : JavaInfo* pCmpInfo = *pIter;
542 0 : if ( jfw_areEqualJavaInfo( pCmpInfo, pInfo ) )
543 : {
544 0 : bFound = true;
545 0 : break;
546 : }
547 : }
548 : }
549 :
550 0 : if ( !bFound )
551 : {
552 0 : jfw_addJRELocation( pInfo->sLocation );
553 0 : AddJRE( pInfo );
554 0 : m_aAddedInfos.push_back( pInfo );
555 0 : nPos = m_aJavaList.GetEntryCount() - 1;
556 : }
557 : else
558 0 : jfw_freeJavaInfo( pInfo );
559 :
560 0 : SvTreeListEntry* pEntry = m_aJavaList.GetEntry( nPos );
561 0 : m_aJavaList.Select( pEntry );
562 0 : m_aJavaList.SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
563 0 : HandleCheckEntry( pEntry );
564 0 : bStartAgain = false;
565 : }
566 0 : else if ( JFW_E_NOT_RECOGNIZED == eErr )
567 : {
568 0 : ErrorBox aErrBox( this, CUI_RES( RID_SVXERR_JRE_NOT_RECOGNIZED ) );
569 0 : aErrBox.Execute();
570 : }
571 0 : else if ( JFW_E_FAILED_VERSION == eErr )
572 : {
573 0 : ErrorBox aErrBox( this, CUI_RES( RID_SVXERR_JRE_FAILED_VERSION ) );
574 0 : aErrBox.Execute();
575 : }
576 :
577 0 : if ( bStartAgain )
578 : {
579 0 : xFolderPicker->setDisplayDirectory( _rFolder );
580 0 : Application::PostUserEvent( LINK( this, SvxJavaOptionsPage, StartFolderPickerHdl ) );
581 : }
582 0 : }
583 :
584 : // -----------------------------------------------------------------------
585 :
586 0 : SfxTabPage* SvxJavaOptionsPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
587 : {
588 0 : return ( new SvxJavaOptionsPage( pParent, rAttrSet ) );
589 : }
590 :
591 : // -----------------------------------------------------------------------
592 :
593 0 : sal_Bool SvxJavaOptionsPage::FillItemSet( SfxItemSet& /*rCoreSet*/ )
594 : {
595 0 : sal_Bool bModified = sal_False;
596 0 : javaFrameworkError eErr = JFW_E_NONE;
597 0 : if ( m_pParamDlg )
598 : {
599 0 : Sequence< ::rtl::OUString > aParamList = m_pParamDlg->GetParameters();
600 0 : sal_Int32 i, nSize = aParamList.getLength();
601 0 : rtl_uString** pParamArr = (rtl_uString**)rtl_allocateMemory( sizeof(rtl_uString*) * nSize );
602 0 : rtl_uString** pParamArrIter = pParamArr;
603 0 : const ::rtl::OUString* pList = aParamList.getConstArray();
604 0 : for ( i = 0; i < nSize; ++i )
605 0 : pParamArr[i] = pList[i].pData;
606 0 : eErr = jfw_setVMParameters( pParamArrIter, nSize );
607 : DBG_ASSERT( JFW_E_NONE == eErr,
608 : "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters" );
609 0 : pParamArrIter = pParamArr;
610 0 : rtl_freeMemory( pParamArr );
611 0 : bModified = sal_True;
612 : }
613 :
614 0 : if ( m_aExperimentalCB.IsChecked() != m_aExperimentalCB.GetSavedValue() )
615 : {
616 0 : SvtMiscOptions aMiscOpt;
617 0 : aMiscOpt.SetExperimentalMode( m_aExperimentalCB.IsChecked() );
618 0 : bModified = sal_True;
619 : }
620 :
621 0 : if ( m_aMacroCB.IsChecked() != m_aMacroCB.GetSavedValue() )
622 : {
623 0 : SvtMiscOptions aMiscOpt;
624 0 : aMiscOpt.SetMacroRecorderMode( m_aMacroCB.IsChecked() );
625 0 : bModified = sal_True;
626 : }
627 :
628 :
629 :
630 0 : if ( m_pPathDlg )
631 : {
632 0 : ::rtl::OUString sPath( m_pPathDlg->GetClassPath() );
633 0 : if ( m_pPathDlg->GetOldPath() != String( sPath ) )
634 : {
635 0 : eErr = jfw_setUserClassPath( sPath.pData );
636 : DBG_ASSERT( JFW_E_NONE == eErr,
637 : "SvxJavaOptionsPage::FillItemSet(): error in jfw_setUserClassPath" );
638 0 : bModified = sal_True;
639 0 : }
640 : }
641 :
642 0 : sal_uLong nCount = m_aJavaList.GetEntryCount();
643 0 : for ( sal_uLong i = 0; i < nCount; ++i )
644 : {
645 0 : if ( m_aJavaList.GetCheckButtonState( m_aJavaList.GetEntry(i) ) == SV_BUTTON_CHECKED )
646 : {
647 0 : JavaInfo* pInfo = NULL;
648 0 : if ( i < static_cast< sal_uLong >( m_nInfoSize ) )
649 0 : pInfo = m_parJavaInfo[i];
650 : else
651 0 : pInfo = m_aAddedInfos[ i - m_nInfoSize ];
652 :
653 0 : JavaInfo* pSelectedJava = NULL;
654 0 : eErr = jfw_getSelectedJRE( &pSelectedJava );
655 0 : if ( JFW_E_NONE == eErr || JFW_E_INVALID_SETTINGS == eErr )
656 : {
657 0 : if (pSelectedJava == NULL || !jfw_areEqualJavaInfo( pInfo, pSelectedJava ) )
658 : {
659 0 : sal_Bool bRunning = sal_False;
660 0 : eErr = jfw_isVMRunning( &bRunning );
661 : DBG_ASSERT( JFW_E_NONE == eErr,
662 : "SvxJavaOptionsPage::FillItemSet(): error in jfw_isVMRunning" );
663 0 : if ( bRunning ||
664 : ( ( pInfo->nRequirements & JFW_REQUIRE_NEEDRESTART ) == JFW_REQUIRE_NEEDRESTART ) )
665 : {
666 : svtools::executeRestartDialog(
667 : comphelper::getProcessComponentContext(), this,
668 0 : svtools::RESTART_REASON_JAVA);
669 : }
670 :
671 0 : eErr = jfw_setSelectedJRE( pInfo );
672 : DBG_ASSERT( JFW_E_NONE == eErr,
673 : "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE" );
674 0 : bModified = sal_True;
675 : }
676 : }
677 0 : jfw_freeJavaInfo( pSelectedJava );
678 : break;
679 : }
680 : }
681 :
682 0 : sal_Bool bEnabled = sal_False;
683 0 : eErr = jfw_getEnabled( &bEnabled );
684 : DBG_ASSERT( JFW_E_NONE == eErr,
685 : "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
686 0 : if ( bEnabled != m_aJavaEnableCB.IsChecked() )
687 : {
688 0 : eErr = jfw_setEnabled( m_aJavaEnableCB.IsChecked() );
689 : DBG_ASSERT( JFW_E_NONE == eErr,
690 : "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
691 0 : bModified = sal_True;
692 : }
693 :
694 0 : return bModified;
695 : }
696 :
697 : // -----------------------------------------------------------------------
698 :
699 0 : void SvxJavaOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
700 : {
701 0 : ClearJavaInfo();
702 0 : ClearJavaList();
703 :
704 0 : SvtMiscOptions aMiscOpt;
705 :
706 0 : sal_Bool bEnabled = sal_False;
707 0 : javaFrameworkError eErr = jfw_getEnabled( &bEnabled );
708 0 : if ( eErr != JFW_E_NONE )
709 0 : bEnabled = sal_False;
710 0 : m_aJavaEnableCB.Check( bEnabled );
711 0 : EnableHdl_Impl( &m_aJavaEnableCB );
712 :
713 0 : m_aExperimentalCB.Check( aMiscOpt.IsExperimentalMode() );
714 0 : m_aExperimentalCB.SaveValue();
715 0 : m_aMacroCB.Check( aMiscOpt.IsMacroRecorderMode() );
716 0 : m_aMacroCB.SaveValue();
717 :
718 0 : m_aResetTimer.Start();
719 0 : }
720 :
721 : // -----------------------------------------------------------------------
722 :
723 0 : void SvxJavaOptionsPage::FillUserData()
724 : {
725 0 : String aUserData;
726 0 : SetUserData( aUserData );
727 0 : }
728 :
729 : // class SvxJavaParameterDlg ---------------------------------------------
730 :
731 0 : SvxJavaParameterDlg::SvxJavaParameterDlg( Window* pParent ) :
732 :
733 0 : ModalDialog( pParent, CUI_RES( RID_SVXDLG_JAVA_PARAMETER ) ),
734 :
735 0 : m_aParameterLabel ( this, CUI_RES( FT_PARAMETER ) ),
736 0 : m_aParameterEdit ( this, CUI_RES( ED_PARAMETER ) ),
737 0 : m_aAssignBtn ( this, CUI_RES( PB_ASSIGN ) ),
738 0 : m_aAssignedLabel ( this, CUI_RES( FT_ASSIGNED ) ),
739 0 : m_aAssignedList ( this, CUI_RES( LB_ASSIGNED ) ),
740 0 : m_aExampleText ( this, CUI_RES( FT_EXAMPLE ) ),
741 0 : m_aRemoveBtn ( this, CUI_RES( PB_REMOVE ) ),
742 0 : m_aButtonsLine ( this, CUI_RES( FL_BUTTONS ) ),
743 0 : m_aOKBtn ( this, CUI_RES( PB_PARAMETER_OK ) ),
744 0 : m_aCancelBtn ( this, CUI_RES( PB_PARAMETER_ESC ) ),
745 0 : m_aHelpBtn ( this, CUI_RES( PB_PARAMETER_HLP ) )
746 :
747 : {
748 0 : FreeResource();
749 :
750 0 : m_aParameterEdit.SetModifyHdl( LINK( this, SvxJavaParameterDlg, ModifyHdl_Impl ) );
751 0 : m_aAssignBtn.SetClickHdl( LINK( this, SvxJavaParameterDlg, AssignHdl_Impl ) );
752 0 : m_aRemoveBtn.SetClickHdl( LINK( this, SvxJavaParameterDlg, RemoveHdl_Impl ) );
753 0 : m_aAssignedList.SetSelectHdl( LINK( this, SvxJavaParameterDlg, SelectHdl_Impl ) );
754 0 : m_aAssignedList.SetDoubleClickHdl( LINK( this, SvxJavaParameterDlg, DblClickHdl_Impl ) );
755 :
756 0 : ModifyHdl_Impl( &m_aParameterEdit );
757 0 : EnableRemoveButton();
758 0 : }
759 :
760 : // -----------------------------------------------------------------------
761 :
762 0 : SvxJavaParameterDlg::~SvxJavaParameterDlg()
763 : {
764 0 : }
765 :
766 : // -----------------------------------------------------------------------
767 :
768 0 : IMPL_LINK_NOARG(SvxJavaParameterDlg, ModifyHdl_Impl)
769 : {
770 0 : rtl::OUString sParam = comphelper::string::strip(m_aParameterEdit.GetText(), ' ');
771 0 : m_aAssignBtn.Enable(!sParam.isEmpty());
772 :
773 0 : return 0;
774 : }
775 :
776 : // -----------------------------------------------------------------------
777 :
778 0 : IMPL_LINK_NOARG(SvxJavaParameterDlg, AssignHdl_Impl)
779 : {
780 0 : rtl::OUString sParam = comphelper::string::strip(m_aParameterEdit.GetText(), ' ');
781 0 : if (!sParam.isEmpty())
782 : {
783 0 : sal_uInt16 nPos = m_aAssignedList.GetEntryPos( sParam );
784 0 : if ( LISTBOX_ENTRY_NOTFOUND == nPos )
785 0 : nPos = m_aAssignedList.InsertEntry( sParam );
786 0 : m_aAssignedList.SelectEntryPos( nPos );
787 0 : m_aParameterEdit.SetText( String() );
788 0 : ModifyHdl_Impl( &m_aParameterEdit );
789 0 : EnableRemoveButton();
790 : }
791 :
792 0 : return 0;
793 : }
794 :
795 : // -----------------------------------------------------------------------
796 :
797 0 : IMPL_LINK_NOARG(SvxJavaParameterDlg, SelectHdl_Impl)
798 : {
799 0 : EnableRemoveButton();
800 0 : return 0;
801 : }
802 :
803 : // -----------------------------------------------------------------------
804 :
805 0 : IMPL_LINK_NOARG(SvxJavaParameterDlg, DblClickHdl_Impl)
806 : {
807 0 : sal_uInt16 nPos = m_aAssignedList.GetSelectEntryPos();
808 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
809 0 : m_aParameterEdit.SetText( m_aAssignedList.GetEntry( nPos ) );
810 0 : return 0;
811 : }
812 :
813 : // -----------------------------------------------------------------------
814 :
815 0 : IMPL_LINK_NOARG(SvxJavaParameterDlg, RemoveHdl_Impl)
816 : {
817 0 : sal_uInt16 nPos = m_aAssignedList.GetSelectEntryPos();
818 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
819 : {
820 0 : m_aAssignedList.RemoveEntry( nPos );
821 0 : sal_uInt16 nCount = m_aAssignedList.GetEntryCount();
822 0 : if ( nCount )
823 : {
824 0 : if ( nPos >= nCount )
825 0 : nPos = ( nCount - 1 );
826 0 : m_aAssignedList.SelectEntryPos( nPos );
827 : }
828 : }
829 0 : EnableRemoveButton();
830 :
831 0 : return 0;
832 : }
833 :
834 : // -----------------------------------------------------------------------
835 :
836 0 : short SvxJavaParameterDlg::Execute()
837 : {
838 0 : m_aParameterEdit.GrabFocus();
839 0 : m_aAssignedList.SetNoSelection();
840 0 : return ModalDialog::Execute();
841 : }
842 :
843 : // -----------------------------------------------------------------------
844 :
845 0 : Sequence< ::rtl::OUString > SvxJavaParameterDlg::GetParameters() const
846 : {
847 0 : sal_uInt16 nCount = m_aAssignedList.GetEntryCount();
848 0 : Sequence< ::rtl::OUString > aParamList( nCount );
849 0 : ::rtl::OUString* pArray = aParamList.getArray();
850 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
851 0 : pArray[i] = ::rtl::OUString( m_aAssignedList.GetEntry(i) );
852 0 : return aParamList;
853 : }
854 :
855 : // -----------------------------------------------------------------------
856 :
857 0 : void SvxJavaParameterDlg::SetParameters( Sequence< ::rtl::OUString >& rParams )
858 : {
859 0 : m_aAssignedList.Clear();
860 0 : sal_uLong i, nCount = rParams.getLength();
861 0 : const ::rtl::OUString* pArray = rParams.getConstArray();
862 0 : for ( i = 0; i < nCount; ++i )
863 : {
864 0 : String sParam = String( *pArray++ );
865 0 : m_aAssignedList.InsertEntry( sParam );
866 0 : }
867 0 : }
868 :
869 : // class SvxJavaClassPathDlg ---------------------------------------------
870 :
871 0 : SvxJavaClassPathDlg::SvxJavaClassPathDlg( Window* pParent ) :
872 :
873 0 : ModalDialog( pParent, CUI_RES( RID_SVXDLG_JAVA_CLASSPATH ) ),
874 :
875 0 : m_aPathLabel ( this, CUI_RES( FT_PATH ) ),
876 0 : m_aPathList ( this, CUI_RES( LB_PATH ) ),
877 0 : m_aAddArchiveBtn ( this, CUI_RES( PB_ADDARCHIVE ) ),
878 0 : m_aAddPathBtn ( this, CUI_RES( PB_ADDPATH ) ),
879 0 : m_aRemoveBtn ( this, CUI_RES( PB_REMOVE_PATH ) ),
880 0 : m_aButtonsLine ( this, CUI_RES( FL_PATH_BUTTONS ) ),
881 0 : m_aOKBtn ( this, CUI_RES( PB_PATH_OK ) ),
882 0 : m_aCancelBtn ( this, CUI_RES( PB_PATH_ESC ) ),
883 0 : m_aHelpBtn ( this, CUI_RES( PB_PATH_HLP ) )
884 :
885 : {
886 0 : FreeResource();
887 :
888 0 : m_aAddArchiveBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, AddArchiveHdl_Impl ) );
889 0 : m_aAddPathBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, AddPathHdl_Impl ) );
890 0 : m_aRemoveBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, RemoveHdl_Impl ) );
891 0 : m_aPathList.SetSelectHdl( LINK( this, SvxJavaClassPathDlg, SelectHdl_Impl ) );
892 :
893 : // check if the buttons text are not too wide otherwise we have to stretch the buttons
894 : // and shrink the listbox
895 0 : long nTxtWidth1 = m_aAddArchiveBtn.GetTextWidth( m_aAddArchiveBtn.GetText() );
896 0 : long nTxtWidth2 = m_aAddPathBtn.GetTextWidth( m_aAddPathBtn.GetText() );
897 0 : Size aBtnSz = m_aAddArchiveBtn.GetSizePixel();
898 0 : if ( nTxtWidth1 > aBtnSz.Width() || nTxtWidth2 > aBtnSz.Width() )
899 : {
900 0 : long nW = ( nTxtWidth1 > aBtnSz.Width() ) ? nTxtWidth1 : nTxtWidth2;
901 0 : long nDelta = nW - aBtnSz.Width() + 2 * BUTTON_BORDER;
902 0 : aBtnSz.Width() += nDelta;
903 0 : Point aBtnPnt = m_aAddArchiveBtn.GetPosPixel();
904 0 : aBtnPnt.X() -= nDelta;
905 0 : m_aAddArchiveBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
906 0 : aBtnPnt = m_aAddPathBtn.GetPosPixel();
907 0 : aBtnPnt.X() -= nDelta;
908 0 : m_aAddPathBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
909 0 : aBtnPnt = m_aRemoveBtn.GetPosPixel();
910 0 : aBtnPnt.X() -= nDelta;
911 0 : m_aRemoveBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
912 0 : Size aBoxSz = m_aPathList.GetSizePixel();
913 0 : aBoxSz.Width() -= nDelta;
914 0 : m_aPathList.SetSizePixel( aBoxSz );
915 : }
916 :
917 : // set initial focus to path list
918 0 : m_aPathList.GrabFocus();
919 0 : }
920 :
921 : // -----------------------------------------------------------------------
922 :
923 0 : SvxJavaClassPathDlg::~SvxJavaClassPathDlg()
924 : {
925 0 : sal_uInt16 i, nCount = m_aPathList.GetEntryCount();
926 0 : for ( i = 0; i < nCount; ++i )
927 0 : delete static_cast< String* >( m_aPathList.GetEntryData(i) );
928 0 : }
929 :
930 : // -----------------------------------------------------------------------
931 :
932 0 : IMPL_LINK_NOARG(SvxJavaClassPathDlg, AddArchiveHdl_Impl)
933 : {
934 0 : sfx2::FileDialogHelper aDlg( TemplateDescription::FILEOPEN_SIMPLE, 0 );
935 0 : aDlg.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE ) );
936 0 : aDlg.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), rtl::OUString("*.jar;*.zip") );
937 0 : String sFolder;
938 0 : if ( m_aPathList.GetSelectEntryCount() > 0 )
939 : {
940 0 : INetURLObject aObj( m_aPathList.GetSelectEntry(), INetURLObject::FSYS_DETECT );
941 0 : sFolder = aObj.GetMainURL( INetURLObject::NO_DECODE );
942 : }
943 : else
944 0 : sFolder = SvtPathOptions().GetWorkPath();
945 0 : aDlg.SetDisplayDirectory( sFolder );
946 0 : if ( aDlg.Execute() == ERRCODE_NONE )
947 : {
948 0 : String sURL = aDlg.GetPath();
949 0 : INetURLObject aURL( sURL );
950 0 : String sFile = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
951 0 : if ( !IsPathDuplicate( sURL ) )
952 : {
953 0 : sal_uInt16 nPos = m_aPathList.InsertEntry( sFile, SvFileInformationManager::GetImage( aURL, false ) );
954 0 : m_aPathList.SelectEntryPos( nPos );
955 : }
956 : else
957 : {
958 0 : String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
959 0 : sMsg.SearchAndReplaceAscii( "%1", sFile );
960 0 : ErrorBox( this, WB_OK, sMsg ).Execute();
961 0 : }
962 : }
963 0 : EnableRemoveButton();
964 0 : return 0;
965 : }
966 :
967 : // -----------------------------------------------------------------------
968 :
969 0 : IMPL_LINK_NOARG(SvxJavaClassPathDlg, AddPathHdl_Impl)
970 : {
971 0 : Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
972 0 : Reference < XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);;
973 :
974 0 : String sOldFolder;
975 0 : if ( m_aPathList.GetSelectEntryCount() > 0 )
976 : {
977 0 : INetURLObject aObj( m_aPathList.GetSelectEntry(), INetURLObject::FSYS_DETECT );
978 0 : sOldFolder = aObj.GetMainURL( INetURLObject::NO_DECODE );
979 : }
980 : else
981 0 : sOldFolder = SvtPathOptions().GetWorkPath();
982 0 : xFolderPicker->setDisplayDirectory( sOldFolder );
983 0 : if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
984 : {
985 0 : String sFolderURL( xFolderPicker->getDirectory() );
986 0 : INetURLObject aURL( sFolderURL );
987 0 : String sNewFolder = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
988 0 : if ( !IsPathDuplicate( sFolderURL ) )
989 : {
990 0 : sal_uInt16 nPos = m_aPathList.InsertEntry( sNewFolder, SvFileInformationManager::GetImage( aURL, false ) );
991 0 : m_aPathList.SelectEntryPos( nPos );
992 : }
993 : else
994 : {
995 0 : String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
996 0 : sMsg.SearchAndReplaceAscii( "%1", sNewFolder );
997 0 : ErrorBox( this, WB_OK, sMsg ).Execute();
998 0 : }
999 : }
1000 0 : EnableRemoveButton();
1001 0 : return 0;
1002 : }
1003 :
1004 : // -----------------------------------------------------------------------
1005 :
1006 0 : IMPL_LINK_NOARG(SvxJavaClassPathDlg, RemoveHdl_Impl)
1007 : {
1008 0 : sal_uInt16 nPos = m_aPathList.GetSelectEntryPos();
1009 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1010 : {
1011 0 : m_aPathList.RemoveEntry( nPos );
1012 0 : sal_uInt16 nCount = m_aPathList.GetEntryCount();
1013 0 : if ( nCount )
1014 : {
1015 0 : if ( nPos >= nCount )
1016 0 : nPos = ( nCount - 1 );
1017 0 : m_aPathList.SelectEntryPos( nPos );
1018 : }
1019 : }
1020 :
1021 0 : EnableRemoveButton();
1022 0 : return 0;
1023 : }
1024 :
1025 : // -----------------------------------------------------------------------
1026 :
1027 0 : IMPL_LINK_NOARG(SvxJavaClassPathDlg, SelectHdl_Impl)
1028 : {
1029 0 : EnableRemoveButton();
1030 0 : return 0;
1031 : }
1032 :
1033 : // -----------------------------------------------------------------------
1034 :
1035 0 : bool SvxJavaClassPathDlg::IsPathDuplicate( const String& _rPath )
1036 : {
1037 0 : bool bRet = false;
1038 0 : INetURLObject aFileObj( _rPath );
1039 0 : sal_uInt16 nCount = m_aPathList.GetEntryCount();
1040 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
1041 : {
1042 0 : INetURLObject aOtherObj( m_aPathList.GetEntry(i), INetURLObject::FSYS_DETECT );
1043 0 : if ( aOtherObj == aFileObj )
1044 : {
1045 0 : bRet = true;
1046 : break;
1047 : }
1048 0 : }
1049 :
1050 0 : return bRet;
1051 : }
1052 :
1053 : // -----------------------------------------------------------------------
1054 :
1055 0 : String SvxJavaClassPathDlg::GetClassPath() const
1056 : {
1057 0 : String sPath;
1058 0 : sal_uInt16 nCount = m_aPathList.GetEntryCount();
1059 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
1060 : {
1061 0 : if ( sPath.Len() > 0 )
1062 0 : sPath += CLASSPATH_DELIMITER;
1063 0 : String* pFullPath = static_cast< String* >( m_aPathList.GetEntryData(i) );
1064 0 : if ( pFullPath )
1065 0 : sPath += *pFullPath;
1066 : else
1067 0 : sPath += m_aPathList.GetEntry(i);
1068 : }
1069 0 : return sPath;
1070 : }
1071 :
1072 : // -----------------------------------------------------------------------
1073 :
1074 0 : void SvxJavaClassPathDlg::SetClassPath( const String& _rPath )
1075 : {
1076 0 : if ( m_sOldPath.Len() == 0 )
1077 0 : m_sOldPath = _rPath;
1078 0 : m_aPathList.Clear();
1079 0 : xub_StrLen i, nIdx = 0;
1080 0 : xub_StrLen nCount = comphelper::string::getTokenCount(_rPath, CLASSPATH_DELIMITER);
1081 0 : for ( i = 0; i < nCount; ++i )
1082 : {
1083 0 : String sToken = _rPath.GetToken( 0, CLASSPATH_DELIMITER, nIdx );
1084 0 : INetURLObject aURL( sToken, INetURLObject::FSYS_DETECT );
1085 0 : String sPath = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
1086 0 : m_aPathList.InsertEntry( sPath, SvFileInformationManager::GetImage( aURL, false ) );
1087 0 : }
1088 : // select first entry
1089 0 : m_aPathList.SelectEntryPos(0);
1090 0 : SelectHdl_Impl( NULL );
1091 3 : }
1092 :
1093 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1094 :
1095 :
|