1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "optjava.hxx"
21 #include <dialmgr.hxx>
23 #include <svtools/miscopt.hxx>
25 #include "optjava.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>
48 // define ----------------------------------------------------------------
50 #define CLASSPATH_DELIMITER SAL_PATHSEPARATOR
51 #define BUTTON_BORDER 2
52 #define RESET_TIMEOUT 300
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
;
59 // -----------------------------------------------------------------------
61 bool areListsEqual( const Sequence
< ::rtl::OUString
>& rListA
, const Sequence
< ::rtl::OUString
>& rListB
)
64 const sal_Int32 nLen
= rListA
.getLength();
66 if ( rListB
.getLength() != nLen
)
70 const ::rtl::OUString
* pStringA
= rListA
.getConstArray();
71 const ::rtl::OUString
* pStringB
= rListB
.getConstArray();
73 for ( sal_Int32 i
= 0; i
< nLen
; ++i
)
75 if ( *pStringA
++ != *pStringB
++ )
86 // class SvxJavaOptionsPage ----------------------------------------------
88 SvxJavaOptionsPage::SvxJavaOptionsPage( Window
* pParent
, const SfxItemSet
& rSet
) :
90 SfxTabPage( pParent
, CUI_RES( RID_SVXPAGE_OPTIONS_JAVA
), rSet
),
92 m_aJavaLine ( this, CUI_RES( FL_JAVA
) ),
93 m_aJavaEnableCB ( this, CUI_RES( CB_JAVA_ENABLE
) ),
94 m_aJavaFoundLabel ( this, CUI_RES( FT_JAVA_FOUND
) ),
95 m_aJavaListContainer(this, CUI_RES(LB_JAVA
)),
96 m_aJavaList(m_aJavaListContainer
),
97 m_aJavaPathText ( this, CUI_RES( FT_JAVA_PATH
) ),
98 m_aAddBtn ( this, CUI_RES( PB_ADD
) ),
99 m_aParameterBtn ( this, CUI_RES( PB_PARAMETER
) ),
100 m_aClassPathBtn ( this, CUI_RES( PB_CLASSPATH
) ),
102 m_pParamDlg ( NULL
),
104 m_parJavaInfo ( NULL
),
105 m_parParameters ( NULL
),
106 m_pClassPath ( NULL
),
109 m_sInstallText ( CUI_RES( STR_INSTALLED_IN
) ),
110 m_sAccessibilityText( CUI_RES( STR_ACCESSIBILITY
) ),
111 m_sAddDialogText ( CUI_RES( STR_ADDDLGTEXT
) ),
113 m_aExperimental ( this, CUI_RES( FL_EXPERIMENTAL
) ),
114 m_aExperimentalCB ( this, CUI_RES( CB_EXPERIMENTAL
) ),
115 m_aMacroCB ( this, CUI_RES( CB_MACRO
) ),
117 xDialogListener ( new ::svt::DialogClosedListener() )
119 m_aJavaEnableCB
.SetClickHdl( LINK( this, SvxJavaOptionsPage
, EnableHdl_Impl
) );
120 m_aJavaList
.SetCheckButtonHdl( LINK( this, SvxJavaOptionsPage
, CheckHdl_Impl
) );
121 m_aJavaList
.SetSelectHdl( LINK( this, SvxJavaOptionsPage
, SelectHdl_Impl
) );
122 m_aAddBtn
.SetClickHdl( LINK( this, SvxJavaOptionsPage
, AddHdl_Impl
) );
123 m_aParameterBtn
.SetClickHdl( LINK( this, SvxJavaOptionsPage
, ParameterHdl_Impl
) );
124 m_aClassPathBtn
.SetClickHdl( LINK( this, SvxJavaOptionsPage
, ClassPathHdl_Impl
) );
125 m_aResetTimer
.SetTimeoutHdl( LINK( this, SvxJavaOptionsPage
, ResetHdl_Impl
) );
126 m_aResetTimer
.SetTimeout( RESET_TIMEOUT
);
128 static long aStaticTabs
[]=
130 5, 0, 15, 90, 130, 300
133 m_aJavaList
.SvxSimpleTable::SetTabs( aStaticTabs
);
134 rtl::OUStringBuffer sHeader
;
135 sHeader
.append('\t');
136 sHeader
.append(CUI_RESSTR(STR_HEADER_VENDOR
));
137 sHeader
.append('\t');
138 sHeader
.append(CUI_RESSTR(STR_HEADER_VERSION
));
139 sHeader
.append('\t');
140 sHeader
.append(CUI_RESSTR(STR_HEADER_FEATURES
));
141 sHeader
.append('\t');
142 m_aJavaList
.InsertHeaderEntry( sHeader
.makeStringAndClear(), HEADERBAR_APPEND
, HIB_LEFT
);
144 m_aJavaList
.SetHelpId( HID_OPTIONS_JAVA_LIST
);
148 xDialogListener
->SetDialogClosedLink( LINK( this, SvxJavaOptionsPage
, DialogClosedHdl
) );
150 EnableHdl_Impl( &m_aJavaEnableCB
);
153 //check if the text fits into the class path button
154 Size aButtonSize
= m_aClassPathBtn
.GetOutputSizePixel();
155 sal_Int32 nTextWidth
= m_aClassPathBtn
.GetTextWidth(m_aClassPathBtn
.GetText());
156 //add some additional space
157 sal_Int32 nDiff
= nTextWidth
+ 4 - aButtonSize
.Width();
160 Point
aPos(m_aClassPathBtn
.GetPosPixel());
162 aButtonSize
.Width() += nDiff
;
163 m_aClassPathBtn
.SetPosSizePixel(aPos
, aButtonSize
);
164 aPos
= m_aAddBtn
.GetPosPixel();
166 m_aAddBtn
.SetPosSizePixel(aPos
, aButtonSize
);
167 aPos
= m_aParameterBtn
.GetPosPixel();
169 m_aParameterBtn
.SetPosSizePixel(aPos
, aButtonSize
);
170 Size aSize
= m_aJavaListContainer
.GetSizePixel();
171 aSize
.Width() -= nDiff
;
172 m_aJavaListContainer
.SetSizePixel(aSize
);
176 // -----------------------------------------------------------------------
178 SvxJavaOptionsPage::~SvxJavaOptionsPage()
183 std::vector
< JavaInfo
* >::iterator pIter
;
184 for ( pIter
= m_aAddedInfos
.begin(); pIter
!= m_aAddedInfos
.end(); ++pIter
)
186 JavaInfo
* pInfo
= *pIter
;
187 jfw_freeJavaInfo( pInfo
);
193 // -----------------------------------------------------------------------
195 IMPL_LINK_NOARG(SvxJavaOptionsPage
, EnableHdl_Impl
)
197 sal_Bool bEnable
= m_aJavaEnableCB
.IsChecked();
198 m_aJavaFoundLabel
.Enable( bEnable
);
199 m_aJavaPathText
.Enable( bEnable
);
200 m_aAddBtn
.Enable( bEnable
);
201 m_aParameterBtn
.Enable( bEnable
);
202 m_aClassPathBtn
.Enable( bEnable
);
204 bEnable
? m_aJavaList
.EnableTable() : m_aJavaList
.DisableTable();
209 // -----------------------------------------------------------------------
211 IMPL_LINK( SvxJavaOptionsPage
, CheckHdl_Impl
, SvxSimpleTable
*, pList
)
213 SvTreeListEntry
* pEntry
= pList
? m_aJavaList
.GetEntry( m_aJavaList
.GetCurMousePoint() )
214 : m_aJavaList
.FirstSelected();
216 m_aJavaList
.HandleEntryChecked( pEntry
);
220 // -----------------------------------------------------------------------
222 IMPL_LINK_NOARG(SvxJavaOptionsPage
, SelectHdl_Impl
)
224 // set installation directory info
225 SvTreeListEntry
* pEntry
= m_aJavaList
.FirstSelected();
226 DBG_ASSERT( pEntry
, "SvxJavaOptionsPage::SelectHdl_Impl(): no entry" );
227 String
* pLocation
= static_cast< String
* >( pEntry
->GetUserData() );
228 DBG_ASSERT( pLocation
, "invalid location string" );
229 String sInfo
= m_sInstallText
;
232 m_aJavaPathText
.SetText( sInfo
);
236 // -----------------------------------------------------------------------
238 IMPL_LINK_NOARG(SvxJavaOptionsPage
, AddHdl_Impl
)
242 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
243 xFolderPicker
= FolderPicker::create(xContext
);
245 String sWorkFolder
= SvtPathOptions().GetWorkPath();
246 xFolderPicker
->setDisplayDirectory( sWorkFolder
);
247 xFolderPicker
->setDescription( m_sAddDialogText
);
249 Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
250 if ( xAsyncDlg
.is() )
251 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
252 else if ( xFolderPicker
.is() && xFolderPicker
->execute() == ExecutableDialogResults::OK
)
253 AddFolder( xFolderPicker
->getDirectory() );
255 catch (const Exception
&)
257 SAL_WARN( "cui.options", "SvxJavaOptionsPage::AddHdl_Impl(): caught exception" );
263 // -----------------------------------------------------------------------
265 IMPL_LINK_NOARG(SvxJavaOptionsPage
, ParameterHdl_Impl
)
267 Sequence
< ::rtl::OUString
> aParameterList
;
270 m_pParamDlg
= new SvxJavaParameterDlg( this );
271 javaFrameworkError eErr
= jfw_getVMParameters( &m_parParameters
, &m_nParamSize
);
272 if ( JFW_E_NONE
== eErr
&& m_parParameters
&& m_nParamSize
> 0 )
274 rtl_uString
** pParamArr
= m_parParameters
;
275 aParameterList
.realloc( m_nParamSize
);
276 ::rtl::OUString
* pParams
= aParameterList
.getArray();
277 for ( sal_Int32 i
= 0; i
< m_nParamSize
; ++i
)
279 rtl_uString
* pParam
= *pParamArr
++;
280 pParams
[i
] = ::rtl::OUString( pParam
);
282 m_pParamDlg
->SetParameters( aParameterList
);
286 aParameterList
= m_pParamDlg
->GetParameters();
288 if ( m_pParamDlg
->Execute() == RET_OK
)
290 if ( !areListsEqual( aParameterList
, m_pParamDlg
->GetParameters() ) )
292 aParameterList
= m_pParamDlg
->GetParameters();
293 sal_Bool bRunning
= sal_False
;
294 javaFrameworkError eErr
= jfw_isVMRunning( &bRunning
);
295 DBG_ASSERT( JFW_E_NONE
== eErr
,
296 "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
300 WarningBox
aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_OPTIONS_RESTART
) );
306 m_pParamDlg
->SetParameters( aParameterList
);
311 // -----------------------------------------------------------------------
313 IMPL_LINK_NOARG(SvxJavaOptionsPage
, ClassPathHdl_Impl
)
319 m_pPathDlg
= new SvxJavaClassPathDlg( this );
320 javaFrameworkError eErr
= jfw_getUserClassPath( &m_pClassPath
);
321 if ( JFW_E_NONE
== eErr
&& m_pClassPath
)
323 sClassPath
= String( ::rtl::OUString( m_pClassPath
) );
324 m_pPathDlg
->SetClassPath( sClassPath
);
328 sClassPath
= m_pPathDlg
->GetClassPath();
330 m_pPathDlg
->SetFocus();
331 if ( m_pPathDlg
->Execute() == RET_OK
)
334 if ( m_pPathDlg
->GetClassPath() != sClassPath
)
336 sClassPath
= m_pPathDlg
->GetClassPath();
337 sal_Bool bRunning
= sal_False
;
338 javaFrameworkError eErr
= jfw_isVMRunning( &bRunning
);
339 DBG_ASSERT( JFW_E_NONE
== eErr
,
340 "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
344 WarningBox
aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_OPTIONS_RESTART
) );
350 m_pPathDlg
->SetClassPath( sClassPath
);
355 // -----------------------------------------------------------------------
357 IMPL_LINK_NOARG(SvxJavaOptionsPage
, ResetHdl_Impl
)
363 // -----------------------------------------------------------------------
365 IMPL_LINK_NOARG(SvxJavaOptionsPage
, StartFolderPickerHdl
)
369 Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
370 if ( xAsyncDlg
.is() )
371 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
372 else if ( xFolderPicker
.is() && xFolderPicker
->execute() == ExecutableDialogResults::OK
)
373 AddFolder( xFolderPicker
->getDirectory() );
377 SAL_WARN( "cui.options", "SvxJavaOptionsPage::StartFolderPickerHdl(): caught exception" );
383 // -----------------------------------------------------------------------
385 IMPL_LINK( SvxJavaOptionsPage
, DialogClosedHdl
, DialogClosedEvent
*, pEvt
)
387 if ( RET_OK
== pEvt
->DialogResult
)
389 DBG_ASSERT( xFolderPicker
.is() == sal_True
, "SvxJavaOptionsPage::DialogClosedHdl(): no folder picker" );
391 AddFolder( xFolderPicker
->getDirectory() );
396 // -----------------------------------------------------------------------
398 void SvxJavaOptionsPage::ClearJavaInfo()
402 JavaInfo
** parInfo
= m_parJavaInfo
;
403 for ( sal_Int32 i
= 0; i
< m_nInfoSize
; ++i
)
405 JavaInfo
* pInfo
= *parInfo
++;
406 jfw_freeJavaInfo( pInfo
);
409 rtl_freeMemory( m_parJavaInfo
);
410 m_parJavaInfo
= NULL
;
415 // -----------------------------------------------------------------------
417 void SvxJavaOptionsPage::ClearJavaList()
419 SvTreeListEntry
* pEntry
= m_aJavaList
.First();
422 String
* pLocation
= static_cast< String
* >( pEntry
->GetUserData() );
424 pEntry
= m_aJavaList
.Next( pEntry
);
429 // -----------------------------------------------------------------------
431 void SvxJavaOptionsPage::LoadJREs()
433 WaitObject
aWaitObj( &m_aJavaList
);
434 javaFrameworkError eErr
= jfw_findAllJREs( &m_parJavaInfo
, &m_nInfoSize
);
435 if ( JFW_E_NONE
== eErr
&& m_parJavaInfo
)
437 JavaInfo
** parInfo
= m_parJavaInfo
;
438 for ( sal_Int32 i
= 0; i
< m_nInfoSize
; ++i
)
440 JavaInfo
* pInfo
= *parInfo
++;
445 std::vector
< JavaInfo
* >::iterator pIter
;
446 for ( pIter
= m_aAddedInfos
.begin(); pIter
!= m_aAddedInfos
.end(); ++pIter
)
448 JavaInfo
* pInfo
= *pIter
;
452 JavaInfo
* pSelectedJava
= NULL
;
453 eErr
= jfw_getSelectedJRE( &pSelectedJava
);
454 if ( JFW_E_NONE
== eErr
&& pSelectedJava
)
456 JavaInfo
** parInfo
= m_parJavaInfo
;
457 for ( sal_Int32 i
= 0; i
< m_nInfoSize
; ++i
)
459 JavaInfo
* pCmpInfo
= *parInfo
++;
460 if ( jfw_areEqualJavaInfo( pCmpInfo
, pSelectedJava
) )
462 SvTreeListEntry
* pEntry
= m_aJavaList
.GetEntry(i
);
464 m_aJavaList
.HandleEntryChecked( pEntry
);
470 jfw_freeJavaInfo( pSelectedJava
);
473 // -----------------------------------------------------------------------
475 void SvxJavaOptionsPage::AddJRE( JavaInfo
* _pInfo
)
477 rtl::OUStringBuffer sEntry
;
479 sEntry
.append(_pInfo
->sVendor
);
481 sEntry
.append(_pInfo
->sVersion
);
483 if ( ( _pInfo
->nFeatures
& JFW_FEATURE_ACCESSBRIDGE
) == JFW_FEATURE_ACCESSBRIDGE
)
484 sEntry
.append(m_sAccessibilityText
);
485 SvTreeListEntry
* pEntry
= m_aJavaList
.InsertEntry(sEntry
.makeStringAndClear());
486 INetURLObject
aLocObj( ::rtl::OUString( _pInfo
->sLocation
) );
487 String
* pLocation
= new String( aLocObj
.getFSysPath( INetURLObject::FSYS_DETECT
) );
488 pEntry
->SetUserData( pLocation
);
491 // -----------------------------------------------------------------------
493 void SvxJavaOptionsPage::HandleCheckEntry( SvTreeListEntry
* _pEntry
)
495 m_aJavaList
.Select( _pEntry
, sal_True
);
496 SvButtonState eState
= m_aJavaList
.GetCheckButtonState( _pEntry
);
498 if ( SV_BUTTON_CHECKED
== eState
)
500 // we have radio button behavior -> so uncheck the other entries
501 SvTreeListEntry
* pEntry
= m_aJavaList
.First();
504 if ( pEntry
!= _pEntry
)
505 m_aJavaList
.SetCheckButtonState( pEntry
, SV_BUTTON_UNCHECKED
);
506 pEntry
= m_aJavaList
.Next( pEntry
);
510 m_aJavaList
.SetCheckButtonState( _pEntry
, SV_BUTTON_CHECKED
);
513 // -----------------------------------------------------------------------
515 void SvxJavaOptionsPage::AddFolder( const ::rtl::OUString
& _rFolder
)
517 bool bStartAgain
= true;
518 JavaInfo
* pInfo
= NULL
;
519 javaFrameworkError eErr
= jfw_getJavaInfoByPath( _rFolder
.pData
, &pInfo
);
520 if ( JFW_E_NONE
== eErr
&& pInfo
)
524 JavaInfo
** parInfo
= m_parJavaInfo
;
525 for ( sal_Int32 i
= 0; i
< m_nInfoSize
; ++i
)
527 JavaInfo
* pCmpInfo
= *parInfo
++;
528 if ( jfw_areEqualJavaInfo( pCmpInfo
, pInfo
) )
538 std::vector
< JavaInfo
* >::iterator pIter
;
539 for ( pIter
= m_aAddedInfos
.begin(); pIter
!= m_aAddedInfos
.end(); ++pIter
)
541 JavaInfo
* pCmpInfo
= *pIter
;
542 if ( jfw_areEqualJavaInfo( pCmpInfo
, pInfo
) )
552 jfw_addJRELocation( pInfo
->sLocation
);
554 m_aAddedInfos
.push_back( pInfo
);
555 nPos
= m_aJavaList
.GetEntryCount() - 1;
558 jfw_freeJavaInfo( pInfo
);
560 SvTreeListEntry
* pEntry
= m_aJavaList
.GetEntry( nPos
);
561 m_aJavaList
.Select( pEntry
);
562 m_aJavaList
.SetCheckButtonState( pEntry
, SV_BUTTON_CHECKED
);
563 HandleCheckEntry( pEntry
);
566 else if ( JFW_E_NOT_RECOGNIZED
== eErr
)
568 ErrorBox
aErrBox( this, CUI_RES( RID_SVXERR_JRE_NOT_RECOGNIZED
) );
571 else if ( JFW_E_FAILED_VERSION
== eErr
)
573 ErrorBox
aErrBox( this, CUI_RES( RID_SVXERR_JRE_FAILED_VERSION
) );
579 xFolderPicker
->setDisplayDirectory( _rFolder
);
580 Application::PostUserEvent( LINK( this, SvxJavaOptionsPage
, StartFolderPickerHdl
) );
584 // -----------------------------------------------------------------------
586 SfxTabPage
* SvxJavaOptionsPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
588 return ( new SvxJavaOptionsPage( pParent
, rAttrSet
) );
591 // -----------------------------------------------------------------------
593 sal_Bool
SvxJavaOptionsPage::FillItemSet( SfxItemSet
& /*rCoreSet*/ )
595 sal_Bool bModified
= sal_False
;
596 javaFrameworkError eErr
= JFW_E_NONE
;
599 Sequence
< ::rtl::OUString
> aParamList
= m_pParamDlg
->GetParameters();
600 sal_Int32 i
, nSize
= aParamList
.getLength();
601 rtl_uString
** pParamArr
= (rtl_uString
**)rtl_allocateMemory( sizeof(rtl_uString
*) * nSize
);
602 rtl_uString
** pParamArrIter
= pParamArr
;
603 const ::rtl::OUString
* pList
= aParamList
.getConstArray();
604 for ( i
= 0; i
< nSize
; ++i
)
605 pParamArr
[i
] = pList
[i
].pData
;
606 eErr
= jfw_setVMParameters( pParamArrIter
, nSize
);
607 DBG_ASSERT( JFW_E_NONE
== eErr
,
608 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters" );
609 pParamArrIter
= pParamArr
;
610 rtl_freeMemory( pParamArr
);
611 bModified
= sal_True
;
614 if ( m_aExperimentalCB
.IsChecked() != m_aExperimentalCB
.GetSavedValue() )
616 SvtMiscOptions aMiscOpt
;
617 aMiscOpt
.SetExperimentalMode( m_aExperimentalCB
.IsChecked() );
618 bModified
= sal_True
;
621 if ( m_aMacroCB
.IsChecked() != m_aMacroCB
.GetSavedValue() )
623 SvtMiscOptions aMiscOpt
;
624 aMiscOpt
.SetMacroRecorderMode( m_aMacroCB
.IsChecked() );
625 bModified
= sal_True
;
632 ::rtl::OUString
sPath( m_pPathDlg
->GetClassPath() );
633 if ( m_pPathDlg
->GetOldPath() != String( sPath
) )
635 eErr
= jfw_setUserClassPath( sPath
.pData
);
636 DBG_ASSERT( JFW_E_NONE
== eErr
,
637 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setUserClassPath" );
638 bModified
= sal_True
;
642 sal_uLong nCount
= m_aJavaList
.GetEntryCount();
643 for ( sal_uLong i
= 0; i
< nCount
; ++i
)
645 if ( m_aJavaList
.GetCheckButtonState( m_aJavaList
.GetEntry(i
) ) == SV_BUTTON_CHECKED
)
647 JavaInfo
* pInfo
= NULL
;
648 if ( i
< static_cast< sal_uLong
>( m_nInfoSize
) )
649 pInfo
= m_parJavaInfo
[i
];
651 pInfo
= m_aAddedInfos
[ i
- m_nInfoSize
];
653 JavaInfo
* pSelectedJava
= NULL
;
654 eErr
= jfw_getSelectedJRE( &pSelectedJava
);
655 if ( JFW_E_NONE
== eErr
|| JFW_E_INVALID_SETTINGS
== eErr
)
657 if (pSelectedJava
== NULL
|| !jfw_areEqualJavaInfo( pInfo
, pSelectedJava
) )
659 sal_Bool bRunning
= sal_False
;
660 eErr
= jfw_isVMRunning( &bRunning
);
661 DBG_ASSERT( JFW_E_NONE
== eErr
,
662 "SvxJavaOptionsPage::FillItemSet(): error in jfw_isVMRunning" );
664 ( ( pInfo
->nRequirements
& JFW_REQUIRE_NEEDRESTART
) == JFW_REQUIRE_NEEDRESTART
) )
666 svtools::executeRestartDialog(
667 comphelper::getProcessComponentContext(), this,
668 svtools::RESTART_REASON_JAVA
);
671 eErr
= jfw_setSelectedJRE( pInfo
);
672 DBG_ASSERT( JFW_E_NONE
== eErr
,
673 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE" );
674 bModified
= sal_True
;
677 jfw_freeJavaInfo( pSelectedJava
);
682 sal_Bool bEnabled
= sal_False
;
683 eErr
= jfw_getEnabled( &bEnabled
);
684 DBG_ASSERT( JFW_E_NONE
== eErr
,
685 "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
686 if ( bEnabled
!= m_aJavaEnableCB
.IsChecked() )
688 eErr
= jfw_setEnabled( m_aJavaEnableCB
.IsChecked() );
689 DBG_ASSERT( JFW_E_NONE
== eErr
,
690 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
691 bModified
= sal_True
;
697 // -----------------------------------------------------------------------
699 void SvxJavaOptionsPage::Reset( const SfxItemSet
& /*rSet*/ )
704 SvtMiscOptions aMiscOpt
;
706 sal_Bool bEnabled
= sal_False
;
707 javaFrameworkError eErr
= jfw_getEnabled( &bEnabled
);
708 if ( eErr
!= JFW_E_NONE
)
709 bEnabled
= sal_False
;
710 m_aJavaEnableCB
.Check( bEnabled
);
711 EnableHdl_Impl( &m_aJavaEnableCB
);
713 m_aExperimentalCB
.Check( aMiscOpt
.IsExperimentalMode() );
714 m_aExperimentalCB
.SaveValue();
715 m_aMacroCB
.Check( aMiscOpt
.IsMacroRecorderMode() );
716 m_aMacroCB
.SaveValue();
718 m_aResetTimer
.Start();
721 // -----------------------------------------------------------------------
723 void SvxJavaOptionsPage::FillUserData()
726 SetUserData( aUserData
);
729 // class SvxJavaParameterDlg ---------------------------------------------
731 SvxJavaParameterDlg::SvxJavaParameterDlg( Window
* pParent
) :
733 ModalDialog( pParent
, CUI_RES( RID_SVXDLG_JAVA_PARAMETER
) ),
735 m_aParameterLabel ( this, CUI_RES( FT_PARAMETER
) ),
736 m_aParameterEdit ( this, CUI_RES( ED_PARAMETER
) ),
737 m_aAssignBtn ( this, CUI_RES( PB_ASSIGN
) ),
738 m_aAssignedLabel ( this, CUI_RES( FT_ASSIGNED
) ),
739 m_aAssignedList ( this, CUI_RES( LB_ASSIGNED
) ),
740 m_aExampleText ( this, CUI_RES( FT_EXAMPLE
) ),
741 m_aRemoveBtn ( this, CUI_RES( PB_REMOVE
) ),
742 m_aButtonsLine ( this, CUI_RES( FL_BUTTONS
) ),
743 m_aOKBtn ( this, CUI_RES( PB_PARAMETER_OK
) ),
744 m_aCancelBtn ( this, CUI_RES( PB_PARAMETER_ESC
) ),
745 m_aHelpBtn ( this, CUI_RES( PB_PARAMETER_HLP
) )
750 m_aParameterEdit
.SetModifyHdl( LINK( this, SvxJavaParameterDlg
, ModifyHdl_Impl
) );
751 m_aAssignBtn
.SetClickHdl( LINK( this, SvxJavaParameterDlg
, AssignHdl_Impl
) );
752 m_aRemoveBtn
.SetClickHdl( LINK( this, SvxJavaParameterDlg
, RemoveHdl_Impl
) );
753 m_aAssignedList
.SetSelectHdl( LINK( this, SvxJavaParameterDlg
, SelectHdl_Impl
) );
754 m_aAssignedList
.SetDoubleClickHdl( LINK( this, SvxJavaParameterDlg
, DblClickHdl_Impl
) );
756 ModifyHdl_Impl( &m_aParameterEdit
);
757 EnableRemoveButton();
760 // -----------------------------------------------------------------------
762 SvxJavaParameterDlg::~SvxJavaParameterDlg()
766 // -----------------------------------------------------------------------
768 IMPL_LINK_NOARG(SvxJavaParameterDlg
, ModifyHdl_Impl
)
770 rtl::OUString sParam
= comphelper::string::strip(m_aParameterEdit
.GetText(), ' ');
771 m_aAssignBtn
.Enable(!sParam
.isEmpty());
776 // -----------------------------------------------------------------------
778 IMPL_LINK_NOARG(SvxJavaParameterDlg
, AssignHdl_Impl
)
780 rtl::OUString sParam
= comphelper::string::strip(m_aParameterEdit
.GetText(), ' ');
781 if (!sParam
.isEmpty())
783 sal_uInt16 nPos
= m_aAssignedList
.GetEntryPos( sParam
);
784 if ( LISTBOX_ENTRY_NOTFOUND
== nPos
)
785 nPos
= m_aAssignedList
.InsertEntry( sParam
);
786 m_aAssignedList
.SelectEntryPos( nPos
);
787 m_aParameterEdit
.SetText( String() );
788 ModifyHdl_Impl( &m_aParameterEdit
);
789 EnableRemoveButton();
795 // -----------------------------------------------------------------------
797 IMPL_LINK_NOARG(SvxJavaParameterDlg
, SelectHdl_Impl
)
799 EnableRemoveButton();
803 // -----------------------------------------------------------------------
805 IMPL_LINK_NOARG(SvxJavaParameterDlg
, DblClickHdl_Impl
)
807 sal_uInt16 nPos
= m_aAssignedList
.GetSelectEntryPos();
808 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
809 m_aParameterEdit
.SetText( m_aAssignedList
.GetEntry( nPos
) );
813 // -----------------------------------------------------------------------
815 IMPL_LINK_NOARG(SvxJavaParameterDlg
, RemoveHdl_Impl
)
817 sal_uInt16 nPos
= m_aAssignedList
.GetSelectEntryPos();
818 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
820 m_aAssignedList
.RemoveEntry( nPos
);
821 sal_uInt16 nCount
= m_aAssignedList
.GetEntryCount();
824 if ( nPos
>= nCount
)
825 nPos
= ( nCount
- 1 );
826 m_aAssignedList
.SelectEntryPos( nPos
);
829 EnableRemoveButton();
834 // -----------------------------------------------------------------------
836 short SvxJavaParameterDlg::Execute()
838 m_aParameterEdit
.GrabFocus();
839 m_aAssignedList
.SetNoSelection();
840 return ModalDialog::Execute();
843 // -----------------------------------------------------------------------
845 Sequence
< ::rtl::OUString
> SvxJavaParameterDlg::GetParameters() const
847 sal_uInt16 nCount
= m_aAssignedList
.GetEntryCount();
848 Sequence
< ::rtl::OUString
> aParamList( nCount
);
849 ::rtl::OUString
* pArray
= aParamList
.getArray();
850 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
851 pArray
[i
] = ::rtl::OUString( m_aAssignedList
.GetEntry(i
) );
855 // -----------------------------------------------------------------------
857 void SvxJavaParameterDlg::SetParameters( Sequence
< ::rtl::OUString
>& rParams
)
859 m_aAssignedList
.Clear();
860 sal_uLong i
, nCount
= rParams
.getLength();
861 const ::rtl::OUString
* pArray
= rParams
.getConstArray();
862 for ( i
= 0; i
< nCount
; ++i
)
864 String sParam
= String( *pArray
++ );
865 m_aAssignedList
.InsertEntry( sParam
);
869 // class SvxJavaClassPathDlg ---------------------------------------------
871 SvxJavaClassPathDlg::SvxJavaClassPathDlg( Window
* pParent
) :
873 ModalDialog( pParent
, CUI_RES( RID_SVXDLG_JAVA_CLASSPATH
) ),
875 m_aPathLabel ( this, CUI_RES( FT_PATH
) ),
876 m_aPathList ( this, CUI_RES( LB_PATH
) ),
877 m_aAddArchiveBtn ( this, CUI_RES( PB_ADDARCHIVE
) ),
878 m_aAddPathBtn ( this, CUI_RES( PB_ADDPATH
) ),
879 m_aRemoveBtn ( this, CUI_RES( PB_REMOVE_PATH
) ),
880 m_aButtonsLine ( this, CUI_RES( FL_PATH_BUTTONS
) ),
881 m_aOKBtn ( this, CUI_RES( PB_PATH_OK
) ),
882 m_aCancelBtn ( this, CUI_RES( PB_PATH_ESC
) ),
883 m_aHelpBtn ( this, CUI_RES( PB_PATH_HLP
) )
888 m_aAddArchiveBtn
.SetClickHdl( LINK( this, SvxJavaClassPathDlg
, AddArchiveHdl_Impl
) );
889 m_aAddPathBtn
.SetClickHdl( LINK( this, SvxJavaClassPathDlg
, AddPathHdl_Impl
) );
890 m_aRemoveBtn
.SetClickHdl( LINK( this, SvxJavaClassPathDlg
, RemoveHdl_Impl
) );
891 m_aPathList
.SetSelectHdl( LINK( this, SvxJavaClassPathDlg
, SelectHdl_Impl
) );
893 // check if the buttons text are not too wide otherwise we have to stretch the buttons
894 // and shrink the listbox
895 long nTxtWidth1
= m_aAddArchiveBtn
.GetTextWidth( m_aAddArchiveBtn
.GetText() );
896 long nTxtWidth2
= m_aAddPathBtn
.GetTextWidth( m_aAddPathBtn
.GetText() );
897 Size aBtnSz
= m_aAddArchiveBtn
.GetSizePixel();
898 if ( nTxtWidth1
> aBtnSz
.Width() || nTxtWidth2
> aBtnSz
.Width() )
900 long nW
= ( nTxtWidth1
> aBtnSz
.Width() ) ? nTxtWidth1
: nTxtWidth2
;
901 long nDelta
= nW
- aBtnSz
.Width() + 2 * BUTTON_BORDER
;
902 aBtnSz
.Width() += nDelta
;
903 Point aBtnPnt
= m_aAddArchiveBtn
.GetPosPixel();
904 aBtnPnt
.X() -= nDelta
;
905 m_aAddArchiveBtn
.SetPosSizePixel( aBtnPnt
, aBtnSz
);
906 aBtnPnt
= m_aAddPathBtn
.GetPosPixel();
907 aBtnPnt
.X() -= nDelta
;
908 m_aAddPathBtn
.SetPosSizePixel( aBtnPnt
, aBtnSz
);
909 aBtnPnt
= m_aRemoveBtn
.GetPosPixel();
910 aBtnPnt
.X() -= nDelta
;
911 m_aRemoveBtn
.SetPosSizePixel( aBtnPnt
, aBtnSz
);
912 Size aBoxSz
= m_aPathList
.GetSizePixel();
913 aBoxSz
.Width() -= nDelta
;
914 m_aPathList
.SetSizePixel( aBoxSz
);
917 // set initial focus to path list
918 m_aPathList
.GrabFocus();
921 // -----------------------------------------------------------------------
923 SvxJavaClassPathDlg::~SvxJavaClassPathDlg()
925 sal_uInt16 i
, nCount
= m_aPathList
.GetEntryCount();
926 for ( i
= 0; i
< nCount
; ++i
)
927 delete static_cast< String
* >( m_aPathList
.GetEntryData(i
) );
930 // -----------------------------------------------------------------------
932 IMPL_LINK_NOARG(SvxJavaClassPathDlg
, AddArchiveHdl_Impl
)
934 sfx2::FileDialogHelper
aDlg( TemplateDescription::FILEOPEN_SIMPLE
, 0 );
935 aDlg
.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE
) );
936 aDlg
.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE
), rtl::OUString("*.jar;*.zip") );
938 if ( m_aPathList
.GetSelectEntryCount() > 0 )
940 INetURLObject
aObj( m_aPathList
.GetSelectEntry(), INetURLObject::FSYS_DETECT
);
941 sFolder
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
944 sFolder
= SvtPathOptions().GetWorkPath();
945 aDlg
.SetDisplayDirectory( sFolder
);
946 if ( aDlg
.Execute() == ERRCODE_NONE
)
948 String sURL
= aDlg
.GetPath();
949 INetURLObject
aURL( sURL
);
950 String sFile
= aURL
.getFSysPath( INetURLObject::FSYS_DETECT
);
951 if ( !IsPathDuplicate( sURL
) )
953 sal_uInt16 nPos
= m_aPathList
.InsertEntry( sFile
, SvFileInformationManager::GetImage( aURL
, false ) );
954 m_aPathList
.SelectEntryPos( nPos
);
958 String
sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR
) );
959 sMsg
.SearchAndReplaceAscii( "%1", sFile
);
960 ErrorBox( this, WB_OK
, sMsg
).Execute();
963 EnableRemoveButton();
967 // -----------------------------------------------------------------------
969 IMPL_LINK_NOARG(SvxJavaClassPathDlg
, AddPathHdl_Impl
)
971 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
972 Reference
< XFolderPicker2
> xFolderPicker
= FolderPicker::create(xContext
);;
975 if ( m_aPathList
.GetSelectEntryCount() > 0 )
977 INetURLObject
aObj( m_aPathList
.GetSelectEntry(), INetURLObject::FSYS_DETECT
);
978 sOldFolder
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
981 sOldFolder
= SvtPathOptions().GetWorkPath();
982 xFolderPicker
->setDisplayDirectory( sOldFolder
);
983 if ( xFolderPicker
->execute() == ExecutableDialogResults::OK
)
985 String
sFolderURL( xFolderPicker
->getDirectory() );
986 INetURLObject
aURL( sFolderURL
);
987 String sNewFolder
= aURL
.getFSysPath( INetURLObject::FSYS_DETECT
);
988 if ( !IsPathDuplicate( sFolderURL
) )
990 sal_uInt16 nPos
= m_aPathList
.InsertEntry( sNewFolder
, SvFileInformationManager::GetImage( aURL
, false ) );
991 m_aPathList
.SelectEntryPos( nPos
);
995 String
sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR
) );
996 sMsg
.SearchAndReplaceAscii( "%1", sNewFolder
);
997 ErrorBox( this, WB_OK
, sMsg
).Execute();
1000 EnableRemoveButton();
1004 // -----------------------------------------------------------------------
1006 IMPL_LINK_NOARG(SvxJavaClassPathDlg
, RemoveHdl_Impl
)
1008 sal_uInt16 nPos
= m_aPathList
.GetSelectEntryPos();
1009 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
1011 m_aPathList
.RemoveEntry( nPos
);
1012 sal_uInt16 nCount
= m_aPathList
.GetEntryCount();
1015 if ( nPos
>= nCount
)
1016 nPos
= ( nCount
- 1 );
1017 m_aPathList
.SelectEntryPos( nPos
);
1021 EnableRemoveButton();
1025 // -----------------------------------------------------------------------
1027 IMPL_LINK_NOARG(SvxJavaClassPathDlg
, SelectHdl_Impl
)
1029 EnableRemoveButton();
1033 // -----------------------------------------------------------------------
1035 bool SvxJavaClassPathDlg::IsPathDuplicate( const String
& _rPath
)
1038 INetURLObject
aFileObj( _rPath
);
1039 sal_uInt16 nCount
= m_aPathList
.GetEntryCount();
1040 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
1042 INetURLObject
aOtherObj( m_aPathList
.GetEntry(i
), INetURLObject::FSYS_DETECT
);
1043 if ( aOtherObj
== aFileObj
)
1053 // -----------------------------------------------------------------------
1055 String
SvxJavaClassPathDlg::GetClassPath() const
1058 sal_uInt16 nCount
= m_aPathList
.GetEntryCount();
1059 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
1061 if ( sPath
.Len() > 0 )
1062 sPath
+= CLASSPATH_DELIMITER
;
1063 String
* pFullPath
= static_cast< String
* >( m_aPathList
.GetEntryData(i
) );
1065 sPath
+= *pFullPath
;
1067 sPath
+= m_aPathList
.GetEntry(i
);
1072 // -----------------------------------------------------------------------
1074 void SvxJavaClassPathDlg::SetClassPath( const String
& _rPath
)
1076 if ( m_sOldPath
.Len() == 0 )
1077 m_sOldPath
= _rPath
;
1078 m_aPathList
.Clear();
1079 xub_StrLen i
, nIdx
= 0;
1080 xub_StrLen nCount
= comphelper::string::getTokenCount(_rPath
, CLASSPATH_DELIMITER
);
1081 for ( i
= 0; i
< nCount
; ++i
)
1083 String sToken
= _rPath
.GetToken( 0, CLASSPATH_DELIMITER
, nIdx
);
1084 INetURLObject
aURL( sToken
, INetURLObject::FSYS_DETECT
);
1085 String sPath
= aURL
.getFSysPath( INetURLObject::FSYS_DETECT
);
1086 m_aPathList
.InsertEntry( sPath
, SvFileInformationManager::GetImage( aURL
, false ) );
1088 // select first entry
1089 m_aPathList
.SelectEntryPos(0);
1090 SelectHdl_Impl( NULL
);
1093 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */