masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / options / optjava.cxx
blob5c725bf14faf24a2f36b3d7ad472ea169ed8cb26
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 // include ---------------------------------------------------------------
33 #include "optjava.hxx"
34 #include <dialmgr.hxx>
36 #include "optjava.hrc"
37 #include <cuires.hrc>
38 #include "helpid.hrc"
39 #include <vcl/svapp.hxx>
40 #include <vcl/help.hxx>
41 #include <tools/urlobj.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <vcl/waitobj.hxx>
44 #include <unotools/pathoptions.hxx>
45 #include <svtools/imagemgr.hxx>
46 #include <sfx2/filedlghelper.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <ucbhelper/contentbroker.hxx>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
51 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
52 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
53 #include <com/sun/star/ucb/XContentProvider.hpp>
54 #include <jvmfwk/framework.h>
56 // define ----------------------------------------------------------------
58 #define CLASSPATH_DELIMITER SAL_PATHSEPARATOR
59 #define STRIM( s ) s.EraseLeadingChars().EraseTrailingChars()
60 #define BUTTON_BORDER 2
61 #define RESET_TIMEOUT 300
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::ucb;
65 using namespace ::com::sun::star::ui::dialogs;
66 using namespace ::com::sun::star::uno;
68 // -----------------------------------------------------------------------
70 bool areListsEqual( const Sequence< ::rtl::OUString >& rListA, const Sequence< ::rtl::OUString >& rListB )
72 bool bRet = true;
73 const sal_Int32 nLen = rListA.getLength();
75 if ( rListB.getLength() != nLen )
76 bRet = false;
77 else
79 const ::rtl::OUString* pStringA = rListA.getConstArray();
80 const ::rtl::OUString* pStringB = rListB.getConstArray();
82 for ( sal_Int32 i = 0; i < nLen; ++i )
84 if ( *pStringA++ != *pStringB++ )
86 bRet = false;
87 break;
92 return bRet;
95 // class SvxJavaOptionsPage ----------------------------------------------
97 SvxJavaOptionsPage::SvxJavaOptionsPage( Window* pParent, const SfxItemSet& rSet ) :
99 SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_OPTIONS_JAVA ), rSet ),
101 m_aJavaLine ( this, CUI_RES( FL_JAVA ) ),
102 m_aJavaEnableCB ( this, CUI_RES( CB_JAVA_ENABLE ) ),
103 m_aJavaFoundLabel ( this, CUI_RES( FT_JAVA_FOUND ) ),
104 m_aJavaList ( this, CUI_RES( LB_JAVA ) ),
105 m_aJavaPathText ( this, CUI_RES( FT_JAVA_PATH ) ),
106 m_aAddBtn ( this, CUI_RES( PB_ADD ) ),
107 m_aParameterBtn ( this, CUI_RES( PB_PARAMETER ) ),
108 m_aClassPathBtn ( this, CUI_RES( PB_CLASSPATH ) ),
110 m_pParamDlg ( NULL ),
111 m_pPathDlg ( NULL ),
112 m_parJavaInfo ( NULL ),
113 m_parParameters ( NULL ),
114 m_pClassPath ( NULL ),
115 m_nInfoSize ( 0 ),
116 m_nParamSize ( 0 ),
117 m_sInstallText ( CUI_RES( STR_INSTALLED_IN ) ),
118 m_sAccessibilityText( CUI_RES( STR_ACCESSIBILITY ) ),
119 m_sAddDialogText ( CUI_RES( STR_ADDDLGTEXT ) ),
121 xDialogListener ( new ::svt::DialogClosedListener() )
124 m_aJavaEnableCB.SetClickHdl( LINK( this, SvxJavaOptionsPage, EnableHdl_Impl ) );
125 m_aJavaList.SetCheckButtonHdl( LINK( this, SvxJavaOptionsPage, CheckHdl_Impl ) );
126 m_aJavaList.SetSelectHdl( LINK( this, SvxJavaOptionsPage, SelectHdl_Impl ) );
127 m_aAddBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, AddHdl_Impl ) );
128 m_aParameterBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, ParameterHdl_Impl ) );
129 m_aClassPathBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, ClassPathHdl_Impl ) );
130 m_aResetTimer.SetTimeoutHdl( LINK( this, SvxJavaOptionsPage, ResetHdl_Impl ) );
131 m_aResetTimer.SetTimeout( RESET_TIMEOUT );
133 //! m_aJavaList.EnableCheckButton( new SvLBoxButtonData( &m_aJavaList, true ) );
135 static long aStaticTabs[]=
137 5, 0, 15, 90, 130, 300
140 m_aJavaList.SvxSimpleTable::SetTabs( aStaticTabs );
141 String sHeader( '\t' );
142 sHeader += String( CUI_RES( STR_HEADER_VENDOR ) );
143 sHeader += '\t';
144 sHeader += String( CUI_RES( STR_HEADER_VERSION ) );
145 sHeader += '\t';
146 sHeader += String( CUI_RES( STR_HEADER_FEATURES ) );
147 sHeader += '\t';
148 m_aJavaList.InsertHeaderEntry( sHeader, HEADERBAR_APPEND, HIB_LEFT );
150 m_aJavaList.SetHelpId( HID_OPTIONS_JAVA_LIST );
152 FreeResource();
154 xDialogListener->SetDialogClosedLink( LINK( this, SvxJavaOptionsPage, DialogClosedHdl ) );
156 EnableHdl_Impl( &m_aJavaEnableCB );
157 jfw_lock();
159 //check if the text fits into the class path button
160 Size aButtonSize = m_aClassPathBtn.GetOutputSizePixel();
161 sal_Int32 nTextWidth = m_aClassPathBtn.GetTextWidth(m_aClassPathBtn.GetText());
162 //add some additional space
163 sal_Int32 nDiff = nTextWidth + 4 - aButtonSize.Width();
164 if( nDiff > 0)
166 Point aPos(m_aClassPathBtn.GetPosPixel());
167 aPos.X() -= nDiff;
168 aButtonSize.Width() += nDiff;
169 m_aClassPathBtn.SetPosSizePixel(aPos, aButtonSize);
170 aPos = m_aAddBtn.GetPosPixel();
171 aPos.X() -= nDiff;
172 m_aAddBtn.SetPosSizePixel(aPos, aButtonSize);
173 aPos = m_aParameterBtn.GetPosPixel();
174 aPos.X() -= nDiff;
175 m_aParameterBtn.SetPosSizePixel(aPos, aButtonSize);
176 Size aSize = m_aJavaList.GetSizePixel();
177 aSize.Width() -= nDiff;
178 m_aJavaList.SetSizePixel(aSize);
182 // -----------------------------------------------------------------------
184 SvxJavaOptionsPage::~SvxJavaOptionsPage()
186 delete m_pParamDlg;
187 delete m_pPathDlg;
188 ClearJavaInfo();
189 std::vector< JavaInfo* >::iterator pIter;
190 for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
192 JavaInfo* pInfo = *pIter;
193 jfw_freeJavaInfo( pInfo );
196 rtl_uString** pParamArr = m_parParameters;
197 for ( sal_Int32 i = 0; i < m_nParamSize; ++i )
198 rtl_uString_release( *pParamArr++ );
199 rtl_freeMemory( m_parParameters );
200 rtl_uString_release( m_pClassPath );
202 jfw_unlock();
205 // -----------------------------------------------------------------------
207 IMPL_LINK( SvxJavaOptionsPage, EnableHdl_Impl, CheckBox *, EMPTYARG )
209 sal_Bool bEnable = m_aJavaEnableCB.IsChecked();
210 m_aJavaFoundLabel.Enable( bEnable );
211 m_aJavaPathText.Enable( bEnable );
212 m_aAddBtn.Enable( bEnable );
213 m_aParameterBtn.Enable( bEnable );
214 m_aClassPathBtn.Enable( bEnable );
216 bEnable ? m_aJavaList.EnableTable() : m_aJavaList.DisableTable();
218 return 0;
221 // -----------------------------------------------------------------------
223 IMPL_LINK( SvxJavaOptionsPage, CheckHdl_Impl, SvxSimpleTable *, pList )
225 SvLBoxEntry* pEntry = pList ? m_aJavaList.GetEntry( m_aJavaList.GetCurMousePoint() )
226 : m_aJavaList.FirstSelected();
227 if ( pEntry )
228 m_aJavaList.HandleEntryChecked( pEntry );
229 return 0;
232 // -----------------------------------------------------------------------
234 IMPL_LINK( SvxJavaOptionsPage, SelectHdl_Impl, SvxSimpleTable *, EMPTYARG )
236 // set installation directory info
237 SvLBoxEntry* pEntry = m_aJavaList.FirstSelected();
238 DBG_ASSERT( pEntry, "SvxJavaOptionsPage::SelectHdl_Impl(): no entry" );
239 String* pLocation = static_cast< String* >( pEntry->GetUserData() );
240 DBG_ASSERT( pLocation, "invalid location string" );
241 String sInfo = m_sInstallText;
242 if ( pLocation )
243 sInfo += *pLocation;
244 m_aJavaPathText.SetText( sInfo );
245 return 0;
248 // -----------------------------------------------------------------------
250 IMPL_LINK( SvxJavaOptionsPage, AddHdl_Impl, PushButton *, EMPTYARG )
254 Reference < XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
255 xFolderPicker = Reference< XFolderPicker >(
256 xMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FolderPicker" ) ), UNO_QUERY );
258 String sWorkFolder = SvtPathOptions().GetWorkPath();
259 xFolderPicker->setDisplayDirectory( sWorkFolder );
260 xFolderPicker->setDescription( m_sAddDialogText );
262 Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
263 if ( xAsyncDlg.is() )
264 xAsyncDlg->startExecuteModal( xDialogListener.get() );
265 else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
266 AddFolder( xFolderPicker->getDirectory() );
268 catch ( Exception& )
270 #ifdef DBG_UTIL
271 DBG_ERRORFILE( "SvxJavaOptionsPage::AddHdl_Impl(): caught exception" );
272 #endif
275 return 0;
278 // -----------------------------------------------------------------------
280 IMPL_LINK( SvxJavaOptionsPage, ParameterHdl_Impl, PushButton *, EMPTYARG )
282 Sequence< ::rtl::OUString > aParameterList;
283 if ( !m_pParamDlg )
285 m_pParamDlg = new SvxJavaParameterDlg( this );
286 javaFrameworkError eErr = jfw_getVMParameters( &m_parParameters, &m_nParamSize );
287 if ( JFW_E_NONE == eErr && m_parParameters && m_nParamSize > 0 )
289 rtl_uString** pParamArr = m_parParameters;
290 aParameterList.realloc( m_nParamSize );
291 ::rtl::OUString* pParams = aParameterList.getArray();
292 for ( sal_Int32 i = 0; i < m_nParamSize; ++i )
294 rtl_uString* pParam = *pParamArr++;
295 pParams[i] = ::rtl::OUString( pParam );
297 m_pParamDlg->SetParameters( aParameterList );
300 else
301 aParameterList = m_pParamDlg->GetParameters();
303 if ( m_pParamDlg->Execute() == RET_OK )
305 if ( !areListsEqual( aParameterList, m_pParamDlg->GetParameters() ) )
307 aParameterList = m_pParamDlg->GetParameters();
308 sal_Bool bRunning = sal_False;
309 javaFrameworkError eErr = jfw_isVMRunning( &bRunning );
310 DBG_ASSERT( JFW_E_NONE == eErr,
311 "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
312 (void)eErr;
313 if ( bRunning )
315 WarningBox aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_JAVA_RESTART2 ) );
316 aWarnBox.Execute();
320 else
321 m_pParamDlg->SetParameters( aParameterList );
323 return 0;
326 // -----------------------------------------------------------------------
328 IMPL_LINK( SvxJavaOptionsPage, ClassPathHdl_Impl, PushButton *, EMPTYARG )
330 String sClassPath;
332 if ( !m_pPathDlg )
334 m_pPathDlg = new SvxJavaClassPathDlg( this );
335 javaFrameworkError eErr = jfw_getUserClassPath( &m_pClassPath );
336 if ( JFW_E_NONE == eErr && m_pClassPath )
338 sClassPath = String( ::rtl::OUString( m_pClassPath ) );
339 m_pPathDlg->SetClassPath( sClassPath );
342 else
343 sClassPath = m_pPathDlg->GetClassPath();
345 m_pPathDlg->SetFocus();
346 if ( m_pPathDlg->Execute() == RET_OK )
349 if ( m_pPathDlg->GetClassPath() != sClassPath )
351 sClassPath = m_pPathDlg->GetClassPath();
352 sal_Bool bRunning = sal_False;
353 javaFrameworkError eErr = jfw_isVMRunning( &bRunning );
354 DBG_ASSERT( JFW_E_NONE == eErr,
355 "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
356 (void)eErr;
357 if ( bRunning )
359 WarningBox aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_JAVA_RESTART2 ) );
360 aWarnBox.Execute();
364 else
365 m_pPathDlg->SetClassPath( sClassPath );
367 return 0;
370 // -----------------------------------------------------------------------
372 IMPL_LINK( SvxJavaOptionsPage, ResetHdl_Impl, Timer *, EMPTYARG )
374 LoadJREs();
375 return 0;
378 // -----------------------------------------------------------------------
380 IMPL_LINK( SvxJavaOptionsPage, StartFolderPickerHdl, void*, EMPTYARG )
384 Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
385 if ( xAsyncDlg.is() )
386 xAsyncDlg->startExecuteModal( xDialogListener.get() );
387 else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
388 AddFolder( xFolderPicker->getDirectory() );
390 catch ( Exception& )
392 #ifdef DBG_UTIL
393 DBG_ERRORFILE( "SvxJavaOptionsPage::StartFolderPickerHdl(): caught exception" );
394 #endif
397 return 0L;
400 // -----------------------------------------------------------------------
402 IMPL_LINK( SvxJavaOptionsPage, DialogClosedHdl, DialogClosedEvent*, pEvt )
404 if ( RET_OK == pEvt->DialogResult )
406 DBG_ASSERT( xFolderPicker.is() == sal_True, "SvxJavaOptionsPage::DialogClosedHdl(): no folder picker" );
408 AddFolder( xFolderPicker->getDirectory() );
410 return 0L;
413 // -----------------------------------------------------------------------
415 void SvxJavaOptionsPage::ClearJavaInfo()
417 if ( m_parJavaInfo )
419 JavaInfo** parInfo = m_parJavaInfo;
420 for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
422 JavaInfo* pInfo = *parInfo++;
423 jfw_freeJavaInfo( pInfo );
426 rtl_freeMemory( m_parJavaInfo );
427 m_parJavaInfo = NULL;
428 m_nInfoSize = 0;
432 // -----------------------------------------------------------------------
434 void SvxJavaOptionsPage::ClearJavaList()
436 SvLBoxEntry* pEntry = m_aJavaList.First();
437 while ( pEntry )
439 String* pLocation = static_cast< String* >( pEntry->GetUserData() );
440 delete pLocation;
441 pEntry = m_aJavaList.Next( pEntry );
443 m_aJavaList.Clear();
446 // -----------------------------------------------------------------------
448 void SvxJavaOptionsPage::LoadJREs()
450 WaitObject aWaitObj( &m_aJavaList );
451 javaFrameworkError eErr = jfw_findAllJREs( &m_parJavaInfo, &m_nInfoSize );
452 if ( JFW_E_NONE == eErr && m_parJavaInfo )
454 JavaInfo** parInfo = m_parJavaInfo;
455 for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
457 JavaInfo* pInfo = *parInfo++;
458 AddJRE( pInfo );
462 std::vector< JavaInfo* >::iterator pIter;
463 for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
465 JavaInfo* pInfo = *pIter;
466 AddJRE( pInfo );
469 JavaInfo* pSelectedJava = NULL;
470 eErr = jfw_getSelectedJRE( &pSelectedJava );
471 if ( JFW_E_NONE == eErr && pSelectedJava )
473 JavaInfo** parInfo = m_parJavaInfo;
474 for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
476 JavaInfo* pCmpInfo = *parInfo++;
477 if ( jfw_areEqualJavaInfo( pCmpInfo, pSelectedJava ) )
479 SvLBoxEntry* pEntry = m_aJavaList.GetEntry(i);
480 if ( pEntry )
481 m_aJavaList.HandleEntryChecked( pEntry );
482 break;
487 jfw_freeJavaInfo( pSelectedJava );
490 // -----------------------------------------------------------------------
492 void SvxJavaOptionsPage::AddJRE( JavaInfo* _pInfo )
494 String sEntry( '\t' );
495 sEntry += String( ::rtl::OUString( _pInfo->sVendor ) );
496 sEntry += '\t';
497 sEntry += String( ::rtl::OUString( _pInfo->sVersion ) );
498 sEntry += '\t';
499 if ( ( _pInfo->nFeatures & JFW_FEATURE_ACCESSBRIDGE ) == JFW_FEATURE_ACCESSBRIDGE )
500 sEntry += m_sAccessibilityText;
501 SvLBoxEntry* pEntry = m_aJavaList.InsertEntry( sEntry );
502 INetURLObject aLocObj( ::rtl::OUString( _pInfo->sLocation ) );
503 String* pLocation = new String( aLocObj.getFSysPath( INetURLObject::FSYS_DETECT ) );
504 pEntry->SetUserData( pLocation );
507 // -----------------------------------------------------------------------
509 void SvxJavaOptionsPage::HandleCheckEntry( SvLBoxEntry* _pEntry )
511 m_aJavaList.Select( _pEntry, sal_True );
512 SvButtonState eState = m_aJavaList.GetCheckButtonState( _pEntry );
514 if ( SV_BUTTON_CHECKED == eState )
516 // we have radio button behavior -> so uncheck the other entries
517 SvLBoxEntry* pEntry = m_aJavaList.First();
518 while ( pEntry )
520 if ( pEntry != _pEntry )
521 m_aJavaList.SetCheckButtonState( pEntry, SV_BUTTON_UNCHECKED );
522 pEntry = m_aJavaList.Next( pEntry );
525 else
526 m_aJavaList.SetCheckButtonState( _pEntry, SV_BUTTON_CHECKED );
529 // -----------------------------------------------------------------------
531 void SvxJavaOptionsPage::AddFolder( const ::rtl::OUString& _rFolder )
533 bool bStartAgain = true;
534 sal_Int32 nPos = 0;
535 JavaInfo* pInfo = NULL;
536 javaFrameworkError eErr = jfw_getJavaInfoByPath( _rFolder.pData, &pInfo );
537 if ( JFW_E_NONE == eErr && pInfo )
539 bool bFound = false;
540 JavaInfo** parInfo = m_parJavaInfo;
541 for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
543 JavaInfo* pCmpInfo = *parInfo++;
544 if ( jfw_areEqualJavaInfo( pCmpInfo, pInfo ) )
546 bFound = true;
547 nPos = i;
548 break;
552 if ( !bFound )
554 std::vector< JavaInfo* >::iterator pIter;
555 for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
557 JavaInfo* pCmpInfo = *pIter;
558 if ( jfw_areEqualJavaInfo( pCmpInfo, pInfo ) )
560 bFound = true;
561 break;
566 if ( !bFound )
568 jfw_addJRELocation( pInfo->sLocation );
569 AddJRE( pInfo );
570 m_aAddedInfos.push_back( pInfo );
571 nPos = m_aJavaList.GetEntryCount() - 1;
573 else
574 jfw_freeJavaInfo( pInfo );
576 SvLBoxEntry* pEntry = m_aJavaList.GetEntry( nPos );
577 m_aJavaList.Select( pEntry );
578 m_aJavaList.SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
579 HandleCheckEntry( pEntry );
580 bStartAgain = false;
582 else if ( JFW_E_NOT_RECOGNIZED == eErr )
584 ErrorBox aErrBox( this, CUI_RES( RID_SVXERR_JRE_NOT_RECOGNIZED ) );
585 aErrBox.Execute();
587 else if ( JFW_E_FAILED_VERSION == eErr )
589 ErrorBox aErrBox( this, CUI_RES( RID_SVXERR_JRE_FAILED_VERSION ) );
590 aErrBox.Execute();
593 if ( bStartAgain )
595 xFolderPicker->setDisplayDirectory( _rFolder );
596 Application::PostUserEvent( LINK( this, SvxJavaOptionsPage, StartFolderPickerHdl ) );
600 // -----------------------------------------------------------------------
602 SfxTabPage* SvxJavaOptionsPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
604 return ( new SvxJavaOptionsPage( pParent, rAttrSet ) );
607 // -----------------------------------------------------------------------
609 sal_Bool SvxJavaOptionsPage::FillItemSet( SfxItemSet& /*rCoreSet*/ )
611 sal_Bool bModified = sal_False;
612 javaFrameworkError eErr = JFW_E_NONE;
613 if ( m_pParamDlg )
615 Sequence< ::rtl::OUString > aParamList = m_pParamDlg->GetParameters();
616 sal_Int32 i, nSize = aParamList.getLength();
617 rtl_uString** pParamArr = (rtl_uString**)rtl_allocateMemory( sizeof(rtl_uString*) * nSize );
618 rtl_uString** pParamArrIter = pParamArr;
619 const ::rtl::OUString* pList = aParamList.getConstArray();
620 for ( i = 0; i < nSize; ++i )
621 pParamArr[i] = pList[i].pData;
622 eErr = jfw_setVMParameters( pParamArrIter, nSize );
623 DBG_ASSERT( JFW_E_NONE == eErr,
624 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters" );
625 pParamArrIter = pParamArr;
626 rtl_freeMemory( pParamArr );
627 bModified = sal_True;
630 if ( m_pPathDlg )
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];
650 else
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" );
663 if ( bRunning ||
664 ( ( pInfo->nRequirements & JFW_REQUIRE_NEEDRESTART ) == JFW_REQUIRE_NEEDRESTART ) )
666 WarningBox aWarnBox( this, CUI_RES( RID_SVX_MSGBOX_JAVA_RESTART ) );
667 aWarnBox.Execute();
670 eErr = jfw_setSelectedJRE( pInfo );
671 DBG_ASSERT( JFW_E_NONE == eErr,
672 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE" );
673 bModified = sal_True;
676 jfw_freeJavaInfo( pSelectedJava );
677 break;
681 sal_Bool bEnabled = sal_False;
682 eErr = jfw_getEnabled( &bEnabled );
683 DBG_ASSERT( JFW_E_NONE == eErr,
684 "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
685 if ( bEnabled != m_aJavaEnableCB.IsChecked() )
687 eErr = jfw_setEnabled( m_aJavaEnableCB.IsChecked() );
688 DBG_ASSERT( JFW_E_NONE == eErr,
689 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
690 bModified = sal_True;
693 return bModified;
696 // -----------------------------------------------------------------------
698 void SvxJavaOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
700 ClearJavaInfo();
701 ClearJavaList();
703 sal_Bool bEnabled = sal_False;
704 javaFrameworkError eErr = jfw_getEnabled( &bEnabled );
705 if ( eErr != JFW_E_NONE )
706 bEnabled = sal_False;
707 m_aJavaEnableCB.Check( bEnabled );
708 EnableHdl_Impl( &m_aJavaEnableCB );
710 m_aResetTimer.Start();
713 // -----------------------------------------------------------------------
715 void SvxJavaOptionsPage::FillUserData()
717 String aUserData;
718 SetUserData( aUserData );
721 // class SvxJavaParameterDlg ---------------------------------------------
723 SvxJavaParameterDlg::SvxJavaParameterDlg( Window* pParent ) :
725 ModalDialog( pParent, CUI_RES( RID_SVXDLG_JAVA_PARAMETER ) ),
727 m_aParameterLabel ( this, CUI_RES( FT_PARAMETER ) ),
728 m_aParameterEdit ( this, CUI_RES( ED_PARAMETER ) ),
729 m_aAssignBtn ( this, CUI_RES( PB_ASSIGN ) ),
730 m_aAssignedLabel ( this, CUI_RES( FT_ASSIGNED ) ),
731 m_aAssignedList ( this, CUI_RES( LB_ASSIGNED ) ),
732 m_aExampleText ( this, CUI_RES( FT_EXAMPLE ) ),
733 m_aRemoveBtn ( this, CUI_RES( PB_REMOVE ) ),
734 m_aButtonsLine ( this, CUI_RES( FL_BUTTONS ) ),
735 m_aOKBtn ( this, CUI_RES( PB_PARAMETER_OK ) ),
736 m_aCancelBtn ( this, CUI_RES( PB_PARAMETER_ESC ) ),
737 m_aHelpBtn ( this, CUI_RES( PB_PARAMETER_HLP ) )
740 FreeResource();
742 m_aParameterEdit.SetModifyHdl( LINK( this, SvxJavaParameterDlg, ModifyHdl_Impl ) );
743 m_aAssignBtn.SetClickHdl( LINK( this, SvxJavaParameterDlg, AssignHdl_Impl ) );
744 m_aRemoveBtn.SetClickHdl( LINK( this, SvxJavaParameterDlg, RemoveHdl_Impl ) );
745 m_aAssignedList.SetSelectHdl( LINK( this, SvxJavaParameterDlg, SelectHdl_Impl ) );
746 m_aAssignedList.SetDoubleClickHdl( LINK( this, SvxJavaParameterDlg, DblClickHdl_Impl ) );
748 ModifyHdl_Impl( &m_aParameterEdit );
749 EnableRemoveButton();
752 // -----------------------------------------------------------------------
754 SvxJavaParameterDlg::~SvxJavaParameterDlg()
758 // -----------------------------------------------------------------------
760 IMPL_LINK( SvxJavaParameterDlg, ModifyHdl_Impl, Edit *, EMPTYARG )
762 String sParam = STRIM( m_aParameterEdit.GetText() );
763 m_aAssignBtn.Enable( sParam.Len() > 0 );
765 return 0;
768 // -----------------------------------------------------------------------
770 IMPL_LINK( SvxJavaParameterDlg, AssignHdl_Impl, PushButton *, EMPTYARG )
772 String sParam = STRIM( m_aParameterEdit.GetText() );
773 if ( sParam.Len() > 0 )
775 sal_uInt16 nPos = m_aAssignedList.GetEntryPos( sParam );
776 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
777 nPos = m_aAssignedList.InsertEntry( sParam );
778 m_aAssignedList.SelectEntryPos( nPos );
779 m_aParameterEdit.SetText( String() );
780 ModifyHdl_Impl( &m_aParameterEdit );
781 EnableRemoveButton();
784 return 0;
787 // -----------------------------------------------------------------------
789 IMPL_LINK( SvxJavaParameterDlg, SelectHdl_Impl, ListBox *, EMPTYARG )
791 EnableRemoveButton();
792 return 0;
795 // -----------------------------------------------------------------------
797 IMPL_LINK( SvxJavaParameterDlg, DblClickHdl_Impl, ListBox *, EMPTYARG )
799 sal_uInt16 nPos = m_aAssignedList.GetSelectEntryPos();
800 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
801 m_aParameterEdit.SetText( m_aAssignedList.GetEntry( nPos ) );
802 return 0;
805 // -----------------------------------------------------------------------
807 IMPL_LINK( SvxJavaParameterDlg, RemoveHdl_Impl, PushButton *, EMPTYARG )
809 sal_uInt16 nPos = m_aAssignedList.GetSelectEntryPos();
810 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
812 m_aAssignedList.RemoveEntry( nPos );
813 sal_uInt16 nCount = m_aAssignedList.GetEntryCount();
814 if ( nCount )
816 if ( nPos >= nCount )
817 nPos = ( nCount - 1 );
818 m_aAssignedList.SelectEntryPos( nPos );
821 EnableRemoveButton();
823 return 0;
826 // -----------------------------------------------------------------------
828 short SvxJavaParameterDlg::Execute()
830 m_aParameterEdit.GrabFocus();
831 m_aAssignedList.SetNoSelection();
832 return ModalDialog::Execute();
835 // -----------------------------------------------------------------------
837 Sequence< ::rtl::OUString > SvxJavaParameterDlg::GetParameters() const
839 sal_uInt16 nCount = m_aAssignedList.GetEntryCount();
840 Sequence< ::rtl::OUString > aParamList( nCount );
841 ::rtl::OUString* pArray = aParamList.getArray();
842 for ( sal_uInt16 i = 0; i < nCount; ++i )
843 pArray[i] = ::rtl::OUString( m_aAssignedList.GetEntry(i) );
844 return aParamList;
847 // -----------------------------------------------------------------------
849 void SvxJavaParameterDlg::SetParameters( Sequence< ::rtl::OUString >& rParams )
851 m_aAssignedList.Clear();
852 sal_uLong i, nCount = rParams.getLength();
853 const ::rtl::OUString* pArray = rParams.getConstArray();
854 for ( i = 0; i < nCount; ++i )
856 String sParam = String( *pArray++ );
857 m_aAssignedList.InsertEntry( sParam );
861 // class SvxJavaClassPathDlg ---------------------------------------------
863 SvxJavaClassPathDlg::SvxJavaClassPathDlg( Window* pParent ) :
865 ModalDialog( pParent, CUI_RES( RID_SVXDLG_JAVA_CLASSPATH ) ),
867 m_aPathLabel ( this, CUI_RES( FT_PATH ) ),
868 m_aPathList ( this, CUI_RES( LB_PATH ) ),
869 m_aAddArchiveBtn ( this, CUI_RES( PB_ADDARCHIVE ) ),
870 m_aAddPathBtn ( this, CUI_RES( PB_ADDPATH ) ),
871 m_aRemoveBtn ( this, CUI_RES( PB_REMOVE_PATH ) ),
872 m_aButtonsLine ( this, CUI_RES( FL_PATH_BUTTONS ) ),
873 m_aOKBtn ( this, CUI_RES( PB_PATH_OK ) ),
874 m_aCancelBtn ( this, CUI_RES( PB_PATH_ESC ) ),
875 m_aHelpBtn ( this, CUI_RES( PB_PATH_HLP ) )
878 FreeResource();
880 m_aAddArchiveBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, AddArchiveHdl_Impl ) );
881 m_aAddPathBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, AddPathHdl_Impl ) );
882 m_aRemoveBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, RemoveHdl_Impl ) );
883 m_aPathList.SetSelectHdl( LINK( this, SvxJavaClassPathDlg, SelectHdl_Impl ) );
885 // check if the buttons text are not too wide otherwise we have to stretch the buttons
886 // and shrink the listbox
887 long nTxtWidth1 = m_aAddArchiveBtn.GetTextWidth( m_aAddArchiveBtn.GetText() );
888 long nTxtWidth2 = m_aAddPathBtn.GetTextWidth( m_aAddPathBtn.GetText() );
889 Size aBtnSz = m_aAddArchiveBtn.GetSizePixel();
890 if ( nTxtWidth1 > aBtnSz.Width() || nTxtWidth2 > aBtnSz.Width() )
892 long nW = ( nTxtWidth1 > aBtnSz.Width() ) ? nTxtWidth1 : nTxtWidth2;
893 long nDelta = nW - aBtnSz.Width() + 2 * BUTTON_BORDER;
894 aBtnSz.Width() += nDelta;
895 Point aBtnPnt = m_aAddArchiveBtn.GetPosPixel();
896 aBtnPnt.X() -= nDelta;
897 m_aAddArchiveBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
898 aBtnPnt = m_aAddPathBtn.GetPosPixel();
899 aBtnPnt.X() -= nDelta;
900 m_aAddPathBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
901 aBtnPnt = m_aRemoveBtn.GetPosPixel();
902 aBtnPnt.X() -= nDelta;
903 m_aRemoveBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
904 Size aBoxSz = m_aPathList.GetSizePixel();
905 aBoxSz.Width() -= nDelta;
906 m_aPathList.SetSizePixel( aBoxSz );
909 // set initial focus to path list
910 m_aPathList.GrabFocus();
913 // -----------------------------------------------------------------------
915 SvxJavaClassPathDlg::~SvxJavaClassPathDlg()
917 sal_uInt16 i, nCount = m_aPathList.GetEntryCount();
918 for ( i = 0; i < nCount; ++i )
919 delete static_cast< String* >( m_aPathList.GetEntryData(i) );
922 // -----------------------------------------------------------------------
924 IMPL_LINK( SvxJavaClassPathDlg, AddArchiveHdl_Impl, PushButton *, EMPTYARG )
926 sfx2::FileDialogHelper aDlg( TemplateDescription::FILEOPEN_SIMPLE, 0 );
927 aDlg.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE ) );
928 aDlg.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), String::CreateFromAscii("*.jar;*.zip") );
929 String sFolder;
930 if ( m_aPathList.GetSelectEntryCount() > 0 )
932 INetURLObject aObj( m_aPathList.GetSelectEntry(), INetURLObject::FSYS_DETECT );
933 sFolder = aObj.GetMainURL( INetURLObject::NO_DECODE );
935 else
936 sFolder = SvtPathOptions().GetWorkPath();
937 aDlg.SetDisplayDirectory( sFolder );
938 if ( aDlg.Execute() == ERRCODE_NONE )
940 String sURL = aDlg.GetPath();
941 INetURLObject aURL( sURL );
942 String sFile = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
943 if ( !IsPathDuplicate( sURL ) )
945 sal_uInt16 nPos = m_aPathList.InsertEntry( sFile, SvFileInformationManager::GetImage( aURL ) );
946 m_aPathList.SelectEntryPos( nPos );
948 else
950 String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
951 sMsg.SearchAndReplaceAscii( "%1", sFile );
952 ErrorBox( this, WB_OK, sMsg ).Execute();
955 EnableRemoveButton();
956 return 0;
959 // -----------------------------------------------------------------------
961 IMPL_LINK( SvxJavaClassPathDlg, AddPathHdl_Impl, PushButton *, EMPTYARG )
963 rtl::OUString sService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker" ) );
964 Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
965 Reference < XFolderPicker > xFolderPicker( xFactory->createInstance( sService ), UNO_QUERY );
967 String sOldFolder;
968 if ( m_aPathList.GetSelectEntryCount() > 0 )
970 INetURLObject aObj( m_aPathList.GetSelectEntry(), INetURLObject::FSYS_DETECT );
971 sOldFolder = aObj.GetMainURL( INetURLObject::NO_DECODE );
973 else
974 sOldFolder = SvtPathOptions().GetWorkPath();
975 xFolderPicker->setDisplayDirectory( sOldFolder );
976 if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
978 String sFolderURL( xFolderPicker->getDirectory() );
979 INetURLObject aURL( sFolderURL );
980 String sNewFolder = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
981 if ( !IsPathDuplicate( sFolderURL ) )
983 sal_uInt16 nPos = m_aPathList.InsertEntry( sNewFolder, SvFileInformationManager::GetImage( aURL ) );
984 m_aPathList.SelectEntryPos( nPos );
986 else
988 String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
989 sMsg.SearchAndReplaceAscii( "%1", sNewFolder );
990 ErrorBox( this, WB_OK, sMsg ).Execute();
993 EnableRemoveButton();
994 return 0;
997 // -----------------------------------------------------------------------
999 IMPL_LINK( SvxJavaClassPathDlg, RemoveHdl_Impl, PushButton *, EMPTYARG )
1001 sal_uInt16 nPos = m_aPathList.GetSelectEntryPos();
1002 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1004 m_aPathList.RemoveEntry( nPos );
1005 sal_uInt16 nCount = m_aPathList.GetEntryCount();
1006 if ( nCount )
1008 if ( nPos >= nCount )
1009 nPos = ( nCount - 1 );
1010 m_aPathList.SelectEntryPos( nPos );
1014 EnableRemoveButton();
1015 return 0;
1018 // -----------------------------------------------------------------------
1020 IMPL_LINK( SvxJavaClassPathDlg, SelectHdl_Impl, ListBox *, EMPTYARG )
1022 EnableRemoveButton();
1023 return 0;
1026 // -----------------------------------------------------------------------
1028 bool SvxJavaClassPathDlg::IsPathDuplicate( const String& _rPath )
1030 bool bRet = false;
1031 INetURLObject aFileObj( _rPath );
1032 sal_uInt16 nCount = m_aPathList.GetEntryCount();
1033 for ( sal_uInt16 i = 0; i < nCount; ++i )
1035 INetURLObject aOtherObj( m_aPathList.GetEntry(i), INetURLObject::FSYS_DETECT );
1036 if ( aOtherObj == aFileObj )
1038 bRet = true;
1039 break;
1043 return bRet;
1046 // -----------------------------------------------------------------------
1048 String SvxJavaClassPathDlg::GetClassPath() const
1050 String sPath;
1051 sal_uInt16 nCount = m_aPathList.GetEntryCount();
1052 for ( sal_uInt16 i = 0; i < nCount; ++i )
1054 if ( sPath.Len() > 0 )
1055 sPath += CLASSPATH_DELIMITER;
1056 String* pFullPath = static_cast< String* >( m_aPathList.GetEntryData(i) );
1057 if ( pFullPath )
1058 sPath += *pFullPath;
1059 else
1060 sPath += m_aPathList.GetEntry(i);
1062 return sPath;
1065 // -----------------------------------------------------------------------
1067 void SvxJavaClassPathDlg::SetClassPath( const String& _rPath )
1069 if ( m_sOldPath.Len() == 0 )
1070 m_sOldPath = _rPath;
1071 m_aPathList.Clear();
1072 xub_StrLen i, nIdx = 0;
1073 xub_StrLen nCount = _rPath.GetTokenCount( CLASSPATH_DELIMITER );
1074 for ( i = 0; i < nCount; ++i )
1076 String sToken = _rPath.GetToken( 0, CLASSPATH_DELIMITER, nIdx );
1077 INetURLObject aURL( sToken, INetURLObject::FSYS_DETECT );
1078 String sPath = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
1079 m_aPathList.InsertEntry( sPath, SvFileInformationManager::GetImage( aURL ) );
1081 // select first entry
1082 m_aPathList.SelectEntryPos(0);
1083 SelectHdl_Impl( NULL );