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
< OUString
>& rListA
, const Sequence
< OUString
>& rListB
)
64 const sal_Int32 nLen
= rListA
.getLength();
66 if ( rListB
.getLength() != nLen
)
70 const OUString
* pStringA
= rListA
.getConstArray();
71 const OUString
* pStringB
= rListB
.getConstArray();
73 for ( sal_Int32 i
= 0; i
< nLen
; ++i
)
75 if ( *pStringA
++ != *pStringB
++ )
86 class SvxJavaListBox
: public svx::SvxRadioButtonListBox
89 const OUString m_sAccessibilityText
;
91 SvxJavaListBox(SvxSimpleTableContainer
& rParent
, const OUString
&rAccessibilityText
)
92 : SvxRadioButtonListBox(rParent
, 0)
93 , m_sAccessibilityText(rAccessibilityText
)
98 HeaderBar
&rBar
= GetTheHeaderBar();
99 if (rBar
.GetItemCount() < 4)
101 long nCheckWidth
= std::max(GetControlColumnWidth() + 12,
102 rBar
.LogicToPixel(Size(15, 0), MAP_APPFONT
).Width());
103 long nVersionWidth
= 12 +
104 std::max(rBar
.GetTextWidth(rBar
.GetItemText(3)),
105 GetTextWidth(OUString("0.0.0_00-icedtea")));
106 long nFeatureWidth
= 12 +
107 std::max(rBar
.GetTextWidth(rBar
.GetItemText(4)),
108 GetTextWidth(m_sAccessibilityText
));
110 std::max(GetSizePixel().Width() - (nCheckWidth
+ nVersionWidth
+ nFeatureWidth
),
111 6 + std::max(rBar
.GetTextWidth(rBar
.GetItemText(2)),
112 GetTextWidth(OUString("Sun Microsystems Inc."))));
113 long aStaticTabs
[]= { 4, 0, 0, 0, 0, 0 };
114 aStaticTabs
[2] = nCheckWidth
;
115 aStaticTabs
[3] = aStaticTabs
[2] + nVendorWidth
;
116 aStaticTabs
[4] = aStaticTabs
[3] + nVersionWidth
;
117 SvxSimpleTable::SetTabs(aStaticTabs
, MAP_PIXEL
);
119 virtual void Resize()
121 svx::SvxRadioButtonListBox::Resize();
126 // class SvxJavaOptionsPage ----------------------------------------------
128 SvxJavaOptionsPage::SvxJavaOptionsPage( Window
* pParent
, const SfxItemSet
& rSet
)
129 : SfxTabPage(pParent
, "OptAdvancedPage", "cui/ui/optadvancedpage.ui", rSet
)
132 , m_parJavaInfo(NULL
)
133 , m_parParameters(NULL
)
137 , xDialogListener(new ::svt::DialogClosedListener())
139 get(m_pJavaEnableCB
, "javaenabled");
140 get(m_pJavaBox
, "javabox");
141 get(m_pJavaPathText
, "javapath");
142 m_sInstallText
= m_pJavaPathText
->GetText();
143 get(m_pAddBtn
, "add");
144 get(m_pParameterBtn
, "parameters");
145 get(m_pClassPathBtn
, "classpath");
146 get(m_pExperimentalCB
, "experimental");
147 get(m_pExpSidebarCB
, "exp_sidebar");
148 get(m_pMacroCB
, "macrorecording");
149 m_sAccessibilityText
= get
<FixedText
>("a11y")->GetText();
150 m_sAddDialogText
= get
<FixedText
>("selectruntime")->GetText();
152 SvxSimpleTableContainer
*pJavaListContainer
= get
<SvxSimpleTableContainer
>("javas");
153 Size
aControlSize(177, 60);
154 aControlSize
= LogicToPixel(aControlSize
, MAP_APPFONT
);
155 pJavaListContainer
->set_width_request(aControlSize
.Width());
156 pJavaListContainer
->set_height_request(aControlSize
.Height());
157 m_pJavaList
= new SvxJavaListBox(*pJavaListContainer
, m_sAccessibilityText
);
159 long aStaticTabs
[]= { 4, 0, 0, 0, 0 };
161 m_pJavaList
->SvxSimpleTable::SetTabs( aStaticTabs
);
163 OUStringBuffer sHeader
;
164 sHeader
.append("\t").append(get
<FixedText
>("vendor")->GetText())
165 .append("\t").append(get
<FixedText
>("version")->GetText())
166 .append("\t").append(get
<FixedText
>("features")->GetText())
168 m_pJavaList
->InsertHeaderEntry(sHeader
.makeStringAndClear(), HEADERBAR_APPEND
, HIB_LEFT
);
169 m_pJavaList
->setColSizes();
171 m_pJavaEnableCB
->SetClickHdl( LINK( this, SvxJavaOptionsPage
, EnableHdl_Impl
) );
172 m_pJavaList
->SetCheckButtonHdl( LINK( this, SvxJavaOptionsPage
, CheckHdl_Impl
) );
173 m_pJavaList
->SetSelectHdl( LINK( this, SvxJavaOptionsPage
, SelectHdl_Impl
) );
174 m_pAddBtn
->SetClickHdl( LINK( this, SvxJavaOptionsPage
, AddHdl_Impl
) );
175 m_pParameterBtn
->SetClickHdl( LINK( this, SvxJavaOptionsPage
, ParameterHdl_Impl
) );
176 m_pClassPathBtn
->SetClickHdl( LINK( this, SvxJavaOptionsPage
, ClassPathHdl_Impl
) );
177 m_aResetTimer
.SetTimeoutHdl( LINK( this, SvxJavaOptionsPage
, ResetHdl_Impl
) );
178 m_aResetTimer
.SetTimeout( RESET_TIMEOUT
);
180 xDialogListener
->SetDialogClosedLink( LINK( this, SvxJavaOptionsPage
, DialogClosedHdl
) );
182 EnableHdl_Impl(m_pJavaEnableCB
);
186 // -----------------------------------------------------------------------
188 SvxJavaOptionsPage::~SvxJavaOptionsPage()
194 std::vector
< JavaInfo
* >::iterator pIter
;
195 for ( pIter
= m_aAddedInfos
.begin(); pIter
!= m_aAddedInfos
.end(); ++pIter
)
197 JavaInfo
* pInfo
= *pIter
;
198 jfw_freeJavaInfo( pInfo
);
204 // -----------------------------------------------------------------------
206 IMPL_LINK_NOARG(SvxJavaOptionsPage
, EnableHdl_Impl
)
208 sal_Bool bEnable
= m_pJavaEnableCB
->IsChecked();
209 m_pJavaBox
->Enable(bEnable
);
210 bEnable
? m_pJavaList
->EnableTable() : m_pJavaList
->DisableTable();
214 // -----------------------------------------------------------------------
216 IMPL_LINK( SvxJavaOptionsPage
, CheckHdl_Impl
, SvxSimpleTable
*, pList
)
218 SvTreeListEntry
* pEntry
= pList
? m_pJavaList
->GetEntry( m_pJavaList
->GetCurMousePoint() )
219 : m_pJavaList
->FirstSelected();
221 m_pJavaList
->HandleEntryChecked( pEntry
);
225 // -----------------------------------------------------------------------
227 IMPL_LINK_NOARG(SvxJavaOptionsPage
, SelectHdl_Impl
)
229 // set installation directory info
230 SvTreeListEntry
* pEntry
= m_pJavaList
->FirstSelected();
231 DBG_ASSERT( pEntry
, "SvxJavaOptionsPage::SelectHdl_Impl(): no entry" );
232 String
* pLocation
= static_cast< String
* >( pEntry
->GetUserData() );
233 DBG_ASSERT( pLocation
, "invalid location string" );
234 String sInfo
= m_sInstallText
;
237 m_pJavaPathText
->SetText(sInfo
);
241 // -----------------------------------------------------------------------
243 IMPL_LINK_NOARG(SvxJavaOptionsPage
, AddHdl_Impl
)
247 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
248 xFolderPicker
= FolderPicker::create(xContext
);
250 String sWorkFolder
= SvtPathOptions().GetWorkPath();
251 xFolderPicker
->setDisplayDirectory( sWorkFolder
);
252 xFolderPicker
->setDescription( m_sAddDialogText
);
254 Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
255 if ( xAsyncDlg
.is() )
256 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
257 else if ( xFolderPicker
.is() && xFolderPicker
->execute() == ExecutableDialogResults::OK
)
258 AddFolder( xFolderPicker
->getDirectory() );
260 catch (const Exception
&)
262 SAL_WARN( "cui.options", "SvxJavaOptionsPage::AddHdl_Impl(): caught exception" );
268 // -----------------------------------------------------------------------
270 IMPL_LINK_NOARG(SvxJavaOptionsPage
, ParameterHdl_Impl
)
272 Sequence
< OUString
> aParameterList
;
275 m_pParamDlg
= new SvxJavaParameterDlg( this );
276 javaFrameworkError eErr
= jfw_getVMParameters( &m_parParameters
, &m_nParamSize
);
277 if ( JFW_E_NONE
== eErr
&& m_parParameters
&& m_nParamSize
> 0 )
279 rtl_uString
** pParamArr
= m_parParameters
;
280 aParameterList
.realloc( m_nParamSize
);
281 OUString
* pParams
= aParameterList
.getArray();
282 for ( sal_Int32 i
= 0; i
< m_nParamSize
; ++i
)
284 rtl_uString
* pParam
= *pParamArr
++;
285 pParams
[i
] = OUString( pParam
);
287 m_pParamDlg
->SetParameters( aParameterList
);
291 aParameterList
= m_pParamDlg
->GetParameters();
293 if ( m_pParamDlg
->Execute() == RET_OK
)
295 if ( !areListsEqual( aParameterList
, m_pParamDlg
->GetParameters() ) )
297 aParameterList
= m_pParamDlg
->GetParameters();
298 sal_Bool bRunning
= sal_False
;
299 javaFrameworkError eErr
= jfw_isVMRunning( &bRunning
);
300 DBG_ASSERT( JFW_E_NONE
== eErr
,
301 "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
305 WarningBox
aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_OPTIONS_RESTART
) );
311 m_pParamDlg
->SetParameters( aParameterList
);
316 // -----------------------------------------------------------------------
318 IMPL_LINK_NOARG(SvxJavaOptionsPage
, ClassPathHdl_Impl
)
324 m_pPathDlg
= new SvxJavaClassPathDlg( this );
325 javaFrameworkError eErr
= jfw_getUserClassPath( &m_pClassPath
);
326 if ( JFW_E_NONE
== eErr
&& m_pClassPath
)
328 sClassPath
= String( OUString( m_pClassPath
) );
329 m_pPathDlg
->SetClassPath( sClassPath
);
333 sClassPath
= m_pPathDlg
->GetClassPath();
335 m_pPathDlg
->SetFocus();
336 if ( m_pPathDlg
->Execute() == RET_OK
)
339 if ( m_pPathDlg
->GetClassPath() != sClassPath
)
341 sClassPath
= m_pPathDlg
->GetClassPath();
342 sal_Bool bRunning
= sal_False
;
343 javaFrameworkError eErr
= jfw_isVMRunning( &bRunning
);
344 DBG_ASSERT( JFW_E_NONE
== eErr
,
345 "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
349 WarningBox
aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_OPTIONS_RESTART
) );
355 m_pPathDlg
->SetClassPath( sClassPath
);
360 // -----------------------------------------------------------------------
362 IMPL_LINK_NOARG(SvxJavaOptionsPage
, ResetHdl_Impl
)
368 // -----------------------------------------------------------------------
370 IMPL_LINK_NOARG(SvxJavaOptionsPage
, StartFolderPickerHdl
)
374 Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
375 if ( xAsyncDlg
.is() )
376 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
377 else if ( xFolderPicker
.is() && xFolderPicker
->execute() == ExecutableDialogResults::OK
)
378 AddFolder( xFolderPicker
->getDirectory() );
382 SAL_WARN( "cui.options", "SvxJavaOptionsPage::StartFolderPickerHdl(): caught exception" );
388 // -----------------------------------------------------------------------
390 IMPL_LINK( SvxJavaOptionsPage
, DialogClosedHdl
, DialogClosedEvent
*, pEvt
)
392 if ( RET_OK
== pEvt
->DialogResult
)
394 DBG_ASSERT( xFolderPicker
.is() == sal_True
, "SvxJavaOptionsPage::DialogClosedHdl(): no folder picker" );
396 AddFolder( xFolderPicker
->getDirectory() );
401 // -----------------------------------------------------------------------
403 void SvxJavaOptionsPage::ClearJavaInfo()
407 JavaInfo
** parInfo
= m_parJavaInfo
;
408 for ( sal_Int32 i
= 0; i
< m_nInfoSize
; ++i
)
410 JavaInfo
* pInfo
= *parInfo
++;
411 jfw_freeJavaInfo( pInfo
);
414 rtl_freeMemory( m_parJavaInfo
);
415 m_parJavaInfo
= NULL
;
420 // -----------------------------------------------------------------------
422 void SvxJavaOptionsPage::ClearJavaList()
424 SvTreeListEntry
* pEntry
= m_pJavaList
->First();
427 String
* pLocation
= static_cast< String
* >( pEntry
->GetUserData() );
429 pEntry
= m_pJavaList
->Next( pEntry
);
431 m_pJavaList
->Clear();
434 // -----------------------------------------------------------------------
436 void SvxJavaOptionsPage::LoadJREs()
438 WaitObject
aWaitObj(m_pJavaList
);
439 javaFrameworkError eErr
= jfw_findAllJREs( &m_parJavaInfo
, &m_nInfoSize
);
440 if ( JFW_E_NONE
== eErr
&& m_parJavaInfo
)
442 JavaInfo
** parInfo
= m_parJavaInfo
;
443 for ( sal_Int32 i
= 0; i
< m_nInfoSize
; ++i
)
445 JavaInfo
* pInfo
= *parInfo
++;
450 std::vector
< JavaInfo
* >::iterator pIter
;
451 for ( pIter
= m_aAddedInfos
.begin(); pIter
!= m_aAddedInfos
.end(); ++pIter
)
453 JavaInfo
* pInfo
= *pIter
;
457 JavaInfo
* pSelectedJava
= NULL
;
458 eErr
= jfw_getSelectedJRE( &pSelectedJava
);
459 if ( JFW_E_NONE
== eErr
&& pSelectedJava
)
461 JavaInfo
** parInfo
= m_parJavaInfo
;
462 for ( sal_Int32 i
= 0; i
< m_nInfoSize
; ++i
)
464 JavaInfo
* pCmpInfo
= *parInfo
++;
465 if ( jfw_areEqualJavaInfo( pCmpInfo
, pSelectedJava
) )
467 SvTreeListEntry
* pEntry
= m_pJavaList
->GetEntry(i
);
469 m_pJavaList
->HandleEntryChecked( pEntry
);
475 jfw_freeJavaInfo( pSelectedJava
);
478 // -----------------------------------------------------------------------
480 void SvxJavaOptionsPage::AddJRE( JavaInfo
* _pInfo
)
482 OUStringBuffer sEntry
;
484 sEntry
.append(_pInfo
->sVendor
);
486 sEntry
.append(_pInfo
->sVersion
);
488 if ( ( _pInfo
->nFeatures
& JFW_FEATURE_ACCESSBRIDGE
) == JFW_FEATURE_ACCESSBRIDGE
)
489 sEntry
.append(m_sAccessibilityText
);
490 SvTreeListEntry
* pEntry
= m_pJavaList
->InsertEntry(sEntry
.makeStringAndClear());
491 INetURLObject
aLocObj( OUString( _pInfo
->sLocation
) );
492 String
* pLocation
= new String( aLocObj
.getFSysPath( INetURLObject::FSYS_DETECT
) );
493 pEntry
->SetUserData( pLocation
);
496 // -----------------------------------------------------------------------
498 void SvxJavaOptionsPage::HandleCheckEntry( SvTreeListEntry
* _pEntry
)
500 m_pJavaList
->Select( _pEntry
, sal_True
);
501 SvButtonState eState
= m_pJavaList
->GetCheckButtonState( _pEntry
);
503 if ( SV_BUTTON_CHECKED
== eState
)
505 // we have radio button behavior -> so uncheck the other entries
506 SvTreeListEntry
* pEntry
= m_pJavaList
->First();
509 if ( pEntry
!= _pEntry
)
510 m_pJavaList
->SetCheckButtonState( pEntry
, SV_BUTTON_UNCHECKED
);
511 pEntry
= m_pJavaList
->Next( pEntry
);
515 m_pJavaList
->SetCheckButtonState( _pEntry
, SV_BUTTON_CHECKED
);
518 // -----------------------------------------------------------------------
520 void SvxJavaOptionsPage::AddFolder( const OUString
& _rFolder
)
522 bool bStartAgain
= true;
523 JavaInfo
* pInfo
= NULL
;
524 javaFrameworkError eErr
= jfw_getJavaInfoByPath( _rFolder
.pData
, &pInfo
);
525 if ( JFW_E_NONE
== eErr
&& pInfo
)
529 JavaInfo
** parInfo
= m_parJavaInfo
;
530 for ( sal_Int32 i
= 0; i
< m_nInfoSize
; ++i
)
532 JavaInfo
* pCmpInfo
= *parInfo
++;
533 if ( jfw_areEqualJavaInfo( pCmpInfo
, pInfo
) )
543 std::vector
< JavaInfo
* >::iterator pIter
;
544 for ( pIter
= m_aAddedInfos
.begin(); pIter
!= m_aAddedInfos
.end(); ++pIter
)
546 JavaInfo
* pCmpInfo
= *pIter
;
547 if ( jfw_areEqualJavaInfo( pCmpInfo
, pInfo
) )
557 jfw_addJRELocation( pInfo
->sLocation
);
559 m_aAddedInfos
.push_back( pInfo
);
560 nPos
= m_pJavaList
->GetEntryCount() - 1;
563 jfw_freeJavaInfo( pInfo
);
565 SvTreeListEntry
* pEntry
= m_pJavaList
->GetEntry( nPos
);
566 m_pJavaList
->Select( pEntry
);
567 m_pJavaList
->SetCheckButtonState( pEntry
, SV_BUTTON_CHECKED
);
568 HandleCheckEntry( pEntry
);
571 else if ( JFW_E_NOT_RECOGNIZED
== eErr
)
573 ErrorBox
aErrBox( this, CUI_RES( RID_SVXERR_JRE_NOT_RECOGNIZED
) );
576 else if ( JFW_E_FAILED_VERSION
== eErr
)
578 ErrorBox
aErrBox( this, CUI_RES( RID_SVXERR_JRE_FAILED_VERSION
) );
584 xFolderPicker
->setDisplayDirectory( _rFolder
);
585 Application::PostUserEvent( LINK( this, SvxJavaOptionsPage
, StartFolderPickerHdl
) );
589 // -----------------------------------------------------------------------
591 SfxTabPage
* SvxJavaOptionsPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
593 return ( new SvxJavaOptionsPage( pParent
, rAttrSet
) );
596 // -----------------------------------------------------------------------
598 sal_Bool
SvxJavaOptionsPage::FillItemSet( SfxItemSet
& /*rCoreSet*/ )
600 sal_Bool bModified
= sal_False
;
601 javaFrameworkError eErr
= JFW_E_NONE
;
604 Sequence
< OUString
> aParamList
= m_pParamDlg
->GetParameters();
605 sal_Int32 i
, nSize
= aParamList
.getLength();
606 rtl_uString
** pParamArr
= (rtl_uString
**)rtl_allocateMemory( sizeof(rtl_uString
*) * nSize
);
607 rtl_uString
** pParamArrIter
= pParamArr
;
608 const OUString
* pList
= aParamList
.getConstArray();
609 for ( i
= 0; i
< nSize
; ++i
)
610 pParamArr
[i
] = pList
[i
].pData
;
611 eErr
= jfw_setVMParameters( pParamArrIter
, nSize
);
612 DBG_ASSERT( JFW_E_NONE
== eErr
,
613 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters" );
614 pParamArrIter
= pParamArr
;
615 rtl_freeMemory( pParamArr
);
616 bModified
= sal_True
;
619 if ( m_pExperimentalCB
->IsChecked() != m_pExperimentalCB
->GetSavedValue() )
621 SvtMiscOptions aMiscOpt
;
622 aMiscOpt
.SetExperimentalMode( m_pExperimentalCB
->IsChecked() );
623 bModified
= sal_True
;
626 if ( m_pExpSidebarCB
->IsChecked() != m_pExpSidebarCB
->GetSavedValue() )
628 SvtMiscOptions aMiscOpt
;
629 aMiscOpt
.SetExperimentalSidebar( m_pExpSidebarCB
->IsChecked() );
631 svtools::executeRestartDialog(
632 comphelper::getProcessComponentContext(), this,
633 svtools::RESTART_REASON_MODIFIED_SIDEBAR
);
635 bModified
= sal_True
;
638 if ( m_pMacroCB
->IsChecked() != m_pMacroCB
->GetSavedValue() )
640 SvtMiscOptions aMiscOpt
;
641 aMiscOpt
.SetMacroRecorderMode( m_pMacroCB
->IsChecked() );
642 bModified
= sal_True
;
647 OUString
sPath( m_pPathDlg
->GetClassPath() );
648 if ( m_pPathDlg
->GetOldPath() != String( sPath
) )
650 eErr
= jfw_setUserClassPath( sPath
.pData
);
651 DBG_ASSERT( JFW_E_NONE
== eErr
,
652 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setUserClassPath" );
653 bModified
= sal_True
;
657 sal_uLong nCount
= m_pJavaList
->GetEntryCount();
658 for ( sal_uLong i
= 0; i
< nCount
; ++i
)
660 if ( m_pJavaList
->GetCheckButtonState( m_pJavaList
->GetEntry(i
) ) == SV_BUTTON_CHECKED
)
662 JavaInfo
* pInfo
= NULL
;
663 if ( i
< static_cast< sal_uLong
>( m_nInfoSize
) )
664 pInfo
= m_parJavaInfo
[i
];
666 pInfo
= m_aAddedInfos
[ i
- m_nInfoSize
];
668 JavaInfo
* pSelectedJava
= NULL
;
669 eErr
= jfw_getSelectedJRE( &pSelectedJava
);
670 if ( JFW_E_NONE
== eErr
|| JFW_E_INVALID_SETTINGS
== eErr
)
672 if (pSelectedJava
== NULL
|| !jfw_areEqualJavaInfo( pInfo
, pSelectedJava
) )
674 sal_Bool bRunning
= sal_False
;
675 eErr
= jfw_isVMRunning( &bRunning
);
676 DBG_ASSERT( JFW_E_NONE
== eErr
,
677 "SvxJavaOptionsPage::FillItemSet(): error in jfw_isVMRunning" );
679 ( ( pInfo
->nRequirements
& JFW_REQUIRE_NEEDRESTART
) == JFW_REQUIRE_NEEDRESTART
) )
681 svtools::executeRestartDialog(
682 comphelper::getProcessComponentContext(), this,
683 svtools::RESTART_REASON_JAVA
);
686 eErr
= jfw_setSelectedJRE( pInfo
);
687 DBG_ASSERT( JFW_E_NONE
== eErr
,
688 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE" );
689 bModified
= sal_True
;
692 jfw_freeJavaInfo( pSelectedJava
);
697 sal_Bool bEnabled
= sal_False
;
698 eErr
= jfw_getEnabled( &bEnabled
);
699 DBG_ASSERT( JFW_E_NONE
== eErr
,
700 "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
701 if ( bEnabled
!= m_pJavaEnableCB
->IsChecked() )
703 eErr
= jfw_setEnabled( m_pJavaEnableCB
->IsChecked() );
704 DBG_ASSERT( JFW_E_NONE
== eErr
,
705 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
706 bModified
= sal_True
;
712 // -----------------------------------------------------------------------
714 void SvxJavaOptionsPage::Reset( const SfxItemSet
& /*rSet*/ )
719 SvtMiscOptions aMiscOpt
;
721 sal_Bool bEnabled
= sal_False
;
722 javaFrameworkError eErr
= jfw_getEnabled( &bEnabled
);
723 if ( eErr
!= JFW_E_NONE
)
724 bEnabled
= sal_False
;
725 m_pJavaEnableCB
->Check( bEnabled
);
726 EnableHdl_Impl(m_pJavaEnableCB
);
728 m_pExperimentalCB
->Check( aMiscOpt
.IsExperimentalMode() );
729 m_pExperimentalCB
->SaveValue();
730 m_pExpSidebarCB
->Check( aMiscOpt
.IsExperimentalSidebar() );
731 m_pExpSidebarCB
->SaveValue();
732 m_pMacroCB
->Check( aMiscOpt
.IsMacroRecorderMode() );
733 m_pMacroCB
->SaveValue();
735 m_aResetTimer
.Start();
738 // -----------------------------------------------------------------------
740 void SvxJavaOptionsPage::FillUserData()
743 SetUserData( aUserData
);
746 // class SvxJavaParameterDlg ---------------------------------------------
748 SvxJavaParameterDlg::SvxJavaParameterDlg( Window
* pParent
) :
750 ModalDialog( pParent
, CUI_RES( RID_SVXDLG_JAVA_PARAMETER
) ),
752 m_aParameterLabel ( this, CUI_RES( FT_PARAMETER
) ),
753 m_aParameterEdit ( this, CUI_RES( ED_PARAMETER
) ),
754 m_aAssignBtn ( this, CUI_RES( PB_ASSIGN
) ),
755 m_aAssignedLabel ( this, CUI_RES( FT_ASSIGNED
) ),
756 m_aAssignedList ( this, CUI_RES( LB_ASSIGNED
) ),
757 m_aExampleText ( this, CUI_RES( FT_EXAMPLE
) ),
758 m_aRemoveBtn ( this, CUI_RES( PB_REMOVE
) ),
759 m_aButtonsLine ( this, CUI_RES( FL_BUTTONS
) ),
760 m_aOKBtn ( this, CUI_RES( PB_PARAMETER_OK
) ),
761 m_aCancelBtn ( this, CUI_RES( PB_PARAMETER_ESC
) ),
762 m_aHelpBtn ( this, CUI_RES( PB_PARAMETER_HLP
) )
767 m_aParameterEdit
.SetModifyHdl( LINK( this, SvxJavaParameterDlg
, ModifyHdl_Impl
) );
768 m_aAssignBtn
.SetClickHdl( LINK( this, SvxJavaParameterDlg
, AssignHdl_Impl
) );
769 m_aRemoveBtn
.SetClickHdl( LINK( this, SvxJavaParameterDlg
, RemoveHdl_Impl
) );
770 m_aAssignedList
.SetSelectHdl( LINK( this, SvxJavaParameterDlg
, SelectHdl_Impl
) );
771 m_aAssignedList
.SetDoubleClickHdl( LINK( this, SvxJavaParameterDlg
, DblClickHdl_Impl
) );
773 ModifyHdl_Impl( &m_aParameterEdit
);
774 EnableRemoveButton();
777 // -----------------------------------------------------------------------
779 SvxJavaParameterDlg::~SvxJavaParameterDlg()
783 // -----------------------------------------------------------------------
785 IMPL_LINK_NOARG(SvxJavaParameterDlg
, ModifyHdl_Impl
)
787 OUString sParam
= comphelper::string::strip(m_aParameterEdit
.GetText(), ' ');
788 m_aAssignBtn
.Enable(!sParam
.isEmpty());
793 // -----------------------------------------------------------------------
795 IMPL_LINK_NOARG(SvxJavaParameterDlg
, AssignHdl_Impl
)
797 OUString sParam
= comphelper::string::strip(m_aParameterEdit
.GetText(), ' ');
798 if (!sParam
.isEmpty())
800 sal_uInt16 nPos
= m_aAssignedList
.GetEntryPos( sParam
);
801 if ( LISTBOX_ENTRY_NOTFOUND
== nPos
)
802 nPos
= m_aAssignedList
.InsertEntry( sParam
);
803 m_aAssignedList
.SelectEntryPos( nPos
);
804 m_aParameterEdit
.SetText( String() );
805 ModifyHdl_Impl( &m_aParameterEdit
);
806 EnableRemoveButton();
812 // -----------------------------------------------------------------------
814 IMPL_LINK_NOARG(SvxJavaParameterDlg
, SelectHdl_Impl
)
816 EnableRemoveButton();
820 // -----------------------------------------------------------------------
822 IMPL_LINK_NOARG(SvxJavaParameterDlg
, DblClickHdl_Impl
)
824 sal_uInt16 nPos
= m_aAssignedList
.GetSelectEntryPos();
825 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
826 m_aParameterEdit
.SetText( m_aAssignedList
.GetEntry( nPos
) );
830 // -----------------------------------------------------------------------
832 IMPL_LINK_NOARG(SvxJavaParameterDlg
, RemoveHdl_Impl
)
834 sal_uInt16 nPos
= m_aAssignedList
.GetSelectEntryPos();
835 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
837 m_aAssignedList
.RemoveEntry( nPos
);
838 sal_uInt16 nCount
= m_aAssignedList
.GetEntryCount();
841 if ( nPos
>= nCount
)
842 nPos
= ( nCount
- 1 );
843 m_aAssignedList
.SelectEntryPos( nPos
);
846 EnableRemoveButton();
851 // -----------------------------------------------------------------------
853 short SvxJavaParameterDlg::Execute()
855 m_aParameterEdit
.GrabFocus();
856 m_aAssignedList
.SetNoSelection();
857 return ModalDialog::Execute();
860 // -----------------------------------------------------------------------
862 Sequence
< OUString
> SvxJavaParameterDlg::GetParameters() const
864 sal_uInt16 nCount
= m_aAssignedList
.GetEntryCount();
865 Sequence
< OUString
> aParamList( nCount
);
866 OUString
* pArray
= aParamList
.getArray();
867 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
868 pArray
[i
] = OUString( m_aAssignedList
.GetEntry(i
) );
872 // -----------------------------------------------------------------------
874 void SvxJavaParameterDlg::SetParameters( Sequence
< OUString
>& rParams
)
876 m_aAssignedList
.Clear();
877 sal_uLong i
, nCount
= rParams
.getLength();
878 const OUString
* pArray
= rParams
.getConstArray();
879 for ( i
= 0; i
< nCount
; ++i
)
881 String sParam
= String( *pArray
++ );
882 m_aAssignedList
.InsertEntry( sParam
);
886 // class SvxJavaClassPathDlg ---------------------------------------------
888 SvxJavaClassPathDlg::SvxJavaClassPathDlg( Window
* pParent
) :
890 ModalDialog( pParent
, CUI_RES( RID_SVXDLG_JAVA_CLASSPATH
) ),
892 m_aPathLabel ( this, CUI_RES( FT_PATH
) ),
893 m_aPathList ( this, CUI_RES( LB_PATH
) ),
894 m_aAddArchiveBtn ( this, CUI_RES( PB_ADDARCHIVE
) ),
895 m_aAddPathBtn ( this, CUI_RES( PB_ADDPATH
) ),
896 m_aRemoveBtn ( this, CUI_RES( PB_REMOVE_PATH
) ),
897 m_aButtonsLine ( this, CUI_RES( FL_PATH_BUTTONS
) ),
898 m_aOKBtn ( this, CUI_RES( PB_PATH_OK
) ),
899 m_aCancelBtn ( this, CUI_RES( PB_PATH_ESC
) ),
900 m_aHelpBtn ( this, CUI_RES( PB_PATH_HLP
) )
905 m_aAddArchiveBtn
.SetClickHdl( LINK( this, SvxJavaClassPathDlg
, AddArchiveHdl_Impl
) );
906 m_aAddPathBtn
.SetClickHdl( LINK( this, SvxJavaClassPathDlg
, AddPathHdl_Impl
) );
907 m_aRemoveBtn
.SetClickHdl( LINK( this, SvxJavaClassPathDlg
, RemoveHdl_Impl
) );
908 m_aPathList
.SetSelectHdl( LINK( this, SvxJavaClassPathDlg
, SelectHdl_Impl
) );
910 // check if the buttons text are not too wide otherwise we have to stretch the buttons
911 // and shrink the listbox
912 long nTxtWidth1
= m_aAddArchiveBtn
.GetTextWidth( m_aAddArchiveBtn
.GetText() );
913 long nTxtWidth2
= m_aAddPathBtn
.GetTextWidth( m_aAddPathBtn
.GetText() );
914 Size aBtnSz
= m_aAddArchiveBtn
.GetSizePixel();
915 if ( nTxtWidth1
> aBtnSz
.Width() || nTxtWidth2
> aBtnSz
.Width() )
917 long nW
= ( nTxtWidth1
> aBtnSz
.Width() ) ? nTxtWidth1
: nTxtWidth2
;
918 long nDelta
= nW
- aBtnSz
.Width() + 2 * BUTTON_BORDER
;
919 aBtnSz
.Width() += nDelta
;
920 Point aBtnPnt
= m_aAddArchiveBtn
.GetPosPixel();
921 aBtnPnt
.X() -= nDelta
;
922 m_aAddArchiveBtn
.SetPosSizePixel( aBtnPnt
, aBtnSz
);
923 aBtnPnt
= m_aAddPathBtn
.GetPosPixel();
924 aBtnPnt
.X() -= nDelta
;
925 m_aAddPathBtn
.SetPosSizePixel( aBtnPnt
, aBtnSz
);
926 aBtnPnt
= m_aRemoveBtn
.GetPosPixel();
927 aBtnPnt
.X() -= nDelta
;
928 m_aRemoveBtn
.SetPosSizePixel( aBtnPnt
, aBtnSz
);
929 Size aBoxSz
= m_aPathList
.GetSizePixel();
930 aBoxSz
.Width() -= nDelta
;
931 m_aPathList
.SetSizePixel( aBoxSz
);
934 // set initial focus to path list
935 m_aPathList
.GrabFocus();
938 // -----------------------------------------------------------------------
940 SvxJavaClassPathDlg::~SvxJavaClassPathDlg()
942 sal_uInt16 i
, nCount
= m_aPathList
.GetEntryCount();
943 for ( i
= 0; i
< nCount
; ++i
)
944 delete static_cast< String
* >( m_aPathList
.GetEntryData(i
) );
947 // -----------------------------------------------------------------------
949 IMPL_LINK_NOARG(SvxJavaClassPathDlg
, AddArchiveHdl_Impl
)
951 sfx2::FileDialogHelper
aDlg( TemplateDescription::FILEOPEN_SIMPLE
, 0 );
952 aDlg
.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE
) );
953 aDlg
.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE
), OUString("*.jar;*.zip") );
955 if ( m_aPathList
.GetSelectEntryCount() > 0 )
957 INetURLObject
aObj( m_aPathList
.GetSelectEntry(), INetURLObject::FSYS_DETECT
);
958 sFolder
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
961 sFolder
= SvtPathOptions().GetWorkPath();
962 aDlg
.SetDisplayDirectory( sFolder
);
963 if ( aDlg
.Execute() == ERRCODE_NONE
)
965 String sURL
= aDlg
.GetPath();
966 INetURLObject
aURL( sURL
);
967 String sFile
= aURL
.getFSysPath( INetURLObject::FSYS_DETECT
);
968 if ( !IsPathDuplicate( sURL
) )
970 sal_uInt16 nPos
= m_aPathList
.InsertEntry( sFile
, SvFileInformationManager::GetImage( aURL
, false ) );
971 m_aPathList
.SelectEntryPos( nPos
);
975 String
sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR
) );
976 sMsg
.SearchAndReplaceAscii( "%1", sFile
);
977 ErrorBox( this, WB_OK
, sMsg
).Execute();
980 EnableRemoveButton();
984 // -----------------------------------------------------------------------
986 IMPL_LINK_NOARG(SvxJavaClassPathDlg
, AddPathHdl_Impl
)
988 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
989 Reference
< XFolderPicker2
> xFolderPicker
= FolderPicker::create(xContext
);;
992 if ( m_aPathList
.GetSelectEntryCount() > 0 )
994 INetURLObject
aObj( m_aPathList
.GetSelectEntry(), INetURLObject::FSYS_DETECT
);
995 sOldFolder
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
998 sOldFolder
= SvtPathOptions().GetWorkPath();
999 xFolderPicker
->setDisplayDirectory( sOldFolder
);
1000 if ( xFolderPicker
->execute() == ExecutableDialogResults::OK
)
1002 String
sFolderURL( xFolderPicker
->getDirectory() );
1003 INetURLObject
aURL( sFolderURL
);
1004 String sNewFolder
= aURL
.getFSysPath( INetURLObject::FSYS_DETECT
);
1005 if ( !IsPathDuplicate( sFolderURL
) )
1007 sal_uInt16 nPos
= m_aPathList
.InsertEntry( sNewFolder
, SvFileInformationManager::GetImage( aURL
, false ) );
1008 m_aPathList
.SelectEntryPos( nPos
);
1012 String
sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR
) );
1013 sMsg
.SearchAndReplaceAscii( "%1", sNewFolder
);
1014 ErrorBox( this, WB_OK
, sMsg
).Execute();
1017 EnableRemoveButton();
1021 // -----------------------------------------------------------------------
1023 IMPL_LINK_NOARG(SvxJavaClassPathDlg
, RemoveHdl_Impl
)
1025 sal_uInt16 nPos
= m_aPathList
.GetSelectEntryPos();
1026 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
1028 m_aPathList
.RemoveEntry( nPos
);
1029 sal_uInt16 nCount
= m_aPathList
.GetEntryCount();
1032 if ( nPos
>= nCount
)
1033 nPos
= ( nCount
- 1 );
1034 m_aPathList
.SelectEntryPos( nPos
);
1038 EnableRemoveButton();
1042 // -----------------------------------------------------------------------
1044 IMPL_LINK_NOARG(SvxJavaClassPathDlg
, SelectHdl_Impl
)
1046 EnableRemoveButton();
1050 // -----------------------------------------------------------------------
1052 bool SvxJavaClassPathDlg::IsPathDuplicate( const String
& _rPath
)
1055 INetURLObject
aFileObj( _rPath
);
1056 sal_uInt16 nCount
= m_aPathList
.GetEntryCount();
1057 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
1059 INetURLObject
aOtherObj( m_aPathList
.GetEntry(i
), INetURLObject::FSYS_DETECT
);
1060 if ( aOtherObj
== aFileObj
)
1070 // -----------------------------------------------------------------------
1072 String
SvxJavaClassPathDlg::GetClassPath() const
1075 sal_uInt16 nCount
= m_aPathList
.GetEntryCount();
1076 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
1078 if ( sPath
.Len() > 0 )
1079 sPath
+= CLASSPATH_DELIMITER
;
1080 String
* pFullPath
= static_cast< String
* >( m_aPathList
.GetEntryData(i
) );
1082 sPath
+= *pFullPath
;
1084 sPath
+= m_aPathList
.GetEntry(i
);
1089 // -----------------------------------------------------------------------
1091 void SvxJavaClassPathDlg::SetClassPath( const String
& _rPath
)
1093 if ( m_sOldPath
.Len() == 0 )
1094 m_sOldPath
= _rPath
;
1095 m_aPathList
.Clear();
1098 xub_StrLen nCount
= comphelper::string::getTokenCount(_rPath
, CLASSPATH_DELIMITER
);
1099 for ( i
= 0; i
< nCount
; ++i
)
1101 String sToken
= _rPath
.GetToken( 0, CLASSPATH_DELIMITER
, nIdx
);
1102 INetURLObject
aURL( sToken
, INetURLObject::FSYS_DETECT
);
1103 String sPath
= aURL
.getFSysPath( INetURLObject::FSYS_DETECT
);
1104 m_aPathList
.InsertEntry( sPath
, SvFileInformationManager::GetImage( aURL
, false ) );
1106 // select first entry
1107 m_aPathList
.SelectEntryPos(0);
1108 SelectHdl_Impl( NULL
);
1111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */