update dev300-m58
[ooovba.git] / svx / source / cui / optjava.cxx
blobd9b2acc3f066025a00af9e77eef50cb0fb72964f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optjava.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
40 #include "optjava.hxx"
41 #include <svx/dialmgr.hxx>
43 #include "optjava.hrc"
44 #include <svx/dialogs.hrc>
45 #include "helpid.hrc"
46 #include <vcl/svapp.hxx>
47 #include <vcl/help.hxx>
48 #include <tools/urlobj.hxx>
49 #include <vcl/msgbox.hxx>
50 #include <vcl/waitobj.hxx>
51 #include <svtools/pathoptions.hxx>
52 #include <svtools/imagemgr.hxx>
53 #include <sfx2/filedlghelper.hxx>
54 #include <comphelper/processfactory.hxx>
55 #include <ucbhelper/contentbroker.hxx>
56 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
57 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
58 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
59 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
60 #include <com/sun/star/ucb/XContentProvider.hpp>
61 #include <jvmfwk/framework.h>
63 // define ----------------------------------------------------------------
65 #define CLASSPATH_DELIMITER SAL_PATHSEPARATOR
66 #define STRIM( s ) s.EraseLeadingChars().EraseTrailingChars()
67 #define BUTTON_BORDER 2
68 #define RESET_TIMEOUT 300
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::ucb;
72 using namespace ::com::sun::star::ui::dialogs;
73 using namespace ::com::sun::star::uno;
75 // class SvxJavaTable ----------------------------------------------------
77 SvxJavaTable::SvxJavaTable( Window* _pParent, const ResId& _rId ) :
79 SvxSimpleTable( _pParent, _rId )
84 SvxJavaTable::~SvxJavaTable()
88 void SvxJavaTable::SetTabs()
90 SvxSimpleTable::SetTabs();
92 USHORT nAdjust = SV_LBOXTAB_ADJUST_RIGHT | SV_LBOXTAB_ADJUST_LEFT |
93 SV_LBOXTAB_ADJUST_CENTER | SV_LBOXTAB_ADJUST_NUMERIC | SV_LBOXTAB_FORCE;
94 if ( aTabs.Count() > 0 )
96 SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(0);
97 pTab->nFlags &= ~nAdjust;
98 pTab->nFlags |= SV_LBOXTAB_PUSHABLE | SV_LBOXTAB_ADJUST_CENTER | SV_LBOXTAB_FORCE;
103 void SvxJavaTable::MouseButtonUp( const MouseEvent& _rMEvt )
105 m_aCurMousePoint = _rMEvt.GetPosPixel();
106 SvxSimpleTable::MouseButtonUp( _rMEvt );
109 void SvxJavaTable::KeyInput( const KeyEvent& rKEvt )
111 if ( !rKEvt.GetKeyCode().GetModifier() && KEY_SPACE == rKEvt.GetKeyCode().GetCode() )
113 SvLBoxEntry* pEntry = FirstSelected();
114 if ( GetCheckButtonState( pEntry ) == SV_BUTTON_UNCHECKED )
116 SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
117 GetCheckButtonHdl().Call( NULL );
118 return ;
122 SvxSimpleTable::KeyInput( rKEvt );
125 // -----------------------------------------------------------------------
127 bool areListsEqual( const Sequence< ::rtl::OUString >& rListA, const Sequence< ::rtl::OUString >& rListB )
129 bool bRet = true;
130 const sal_Int32 nLen = rListA.getLength();
132 if ( rListB.getLength() != nLen )
133 bRet = false;
134 else
136 const ::rtl::OUString* pStringA = rListA.getConstArray();
137 const ::rtl::OUString* pStringB = rListB.getConstArray();
139 for ( sal_Int32 i = 0; i < nLen; ++i )
141 if ( *pStringA++ != *pStringB++ )
143 bRet = false;
144 break;
149 return bRet;
152 // class SvxJavaOptionsPage ----------------------------------------------
154 SvxJavaOptionsPage::SvxJavaOptionsPage( Window* pParent, const SfxItemSet& rSet ) :
156 SfxTabPage( pParent, SVX_RES( RID_SVXPAGE_OPTIONS_JAVA ), rSet ),
158 m_aJavaLine ( this, SVX_RES( FL_JAVA ) ),
159 m_aJavaEnableCB ( this, SVX_RES( CB_JAVA_ENABLE ) ),
160 m_aJavaFoundLabel ( this, SVX_RES( FT_JAVA_FOUND ) ),
161 m_aJavaList ( this, SVX_RES( LB_JAVA ) ),
162 m_aJavaPathText ( this, SVX_RES( FT_JAVA_PATH ) ),
163 m_aAddBtn ( this, SVX_RES( PB_ADD ) ),
164 m_aParameterBtn ( this, SVX_RES( PB_PARAMETER ) ),
165 m_aClassPathBtn ( this, SVX_RES( PB_CLASSPATH ) ),
167 m_pParamDlg ( NULL ),
168 m_pPathDlg ( NULL ),
169 m_parJavaInfo ( NULL ),
170 m_parParameters ( NULL ),
171 m_pClassPath ( NULL ),
172 m_nInfoSize ( 0 ),
173 m_nParamSize ( 0 ),
174 m_sInstallText ( SVX_RES( STR_INSTALLED_IN ) ),
175 m_sAccessibilityText( SVX_RES( STR_ACCESSIBILITY ) ),
176 m_sAddDialogText ( SVX_RES( STR_ADDDLGTEXT ) ),
178 xDialogListener ( new ::svt::DialogClosedListener() )
181 m_aJavaEnableCB.SetClickHdl( LINK( this, SvxJavaOptionsPage, EnableHdl_Impl ) );
182 m_aJavaList.SetCheckButtonHdl( LINK( this, SvxJavaOptionsPage, CheckHdl_Impl ) );
183 m_aJavaList.SetSelectHdl( LINK( this, SvxJavaOptionsPage, SelectHdl_Impl ) );
184 m_aAddBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, AddHdl_Impl ) );
185 m_aParameterBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, ParameterHdl_Impl ) );
186 m_aClassPathBtn.SetClickHdl( LINK( this, SvxJavaOptionsPage, ClassPathHdl_Impl ) );
187 m_aResetTimer.SetTimeoutHdl( LINK( this, SvxJavaOptionsPage, ResetHdl_Impl ) );
188 m_aResetTimer.SetTimeout( RESET_TIMEOUT );
190 //! m_aJavaList.EnableCheckButton( new SvLBoxButtonData( &m_aJavaList, true ) );
192 static long aStaticTabs[]=
194 5, 0, 15, 90, 130, 300
197 m_aJavaList.SvxSimpleTable::SetTabs( aStaticTabs );
198 String sHeader( '\t' );
199 sHeader += String( SVX_RES( STR_HEADER_VENDOR ) );
200 sHeader += '\t';
201 sHeader += String( SVX_RES( STR_HEADER_VERSION ) );
202 sHeader += '\t';
203 sHeader += String( SVX_RES( STR_HEADER_FEATURES ) );
204 sHeader += '\t';
205 m_aJavaList.InsertHeaderEntry( sHeader, HEADERBAR_APPEND, HIB_LEFT );
207 m_aJavaList.SetHelpId( HID_OPTIONS_JAVA_LIST );
209 FreeResource();
211 xDialogListener->SetDialogClosedLink( LINK( this, SvxJavaOptionsPage, DialogClosedHdl ) );
213 EnableHdl_Impl( &m_aJavaEnableCB );
214 jfw_lock();
216 //check if the text fits into the class path button
217 Size aButtonSize = m_aClassPathBtn.GetOutputSizePixel();
218 sal_Int32 nTextWidth = m_aClassPathBtn.GetTextWidth(m_aClassPathBtn.GetText());
219 //add some additional space
220 sal_Int32 nDiff = nTextWidth + 4 - aButtonSize.Width();
221 if( nDiff > 0)
223 Point aPos(m_aClassPathBtn.GetPosPixel());
224 aPos.X() -= nDiff;
225 aButtonSize.Width() += nDiff;
226 m_aClassPathBtn.SetPosSizePixel(aPos, aButtonSize);
227 aPos = m_aAddBtn.GetPosPixel();
228 aPos.X() -= nDiff;
229 m_aAddBtn.SetPosSizePixel(aPos, aButtonSize);
230 aPos = m_aParameterBtn.GetPosPixel();
231 aPos.X() -= nDiff;
232 m_aParameterBtn.SetPosSizePixel(aPos, aButtonSize);
233 Size aSize = m_aJavaList.GetSizePixel();
234 aSize.Width() -= nDiff;
235 m_aJavaList.SetSizePixel(aSize);
239 // -----------------------------------------------------------------------
241 SvxJavaOptionsPage::~SvxJavaOptionsPage()
243 delete m_pParamDlg;
244 delete m_pPathDlg;
245 ClearJavaInfo();
246 std::vector< JavaInfo* >::iterator pIter;
247 for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
249 JavaInfo* pInfo = *pIter;
250 jfw_freeJavaInfo( pInfo );
253 rtl_uString** pParamArr = m_parParameters;
254 for ( sal_Int32 i = 0; i < m_nParamSize; ++i )
255 rtl_uString_release( *pParamArr++ );
256 rtl_freeMemory( m_parParameters );
257 rtl_uString_release( m_pClassPath );
259 jfw_unlock();
262 // -----------------------------------------------------------------------
264 IMPL_LINK( SvxJavaOptionsPage, EnableHdl_Impl, CheckBox *, EMPTYARG )
266 BOOL bEnable = m_aJavaEnableCB.IsChecked();
267 m_aJavaFoundLabel.Enable( bEnable );
268 m_aJavaPathText.Enable( bEnable );
269 m_aAddBtn.Enable( bEnable );
270 m_aParameterBtn.Enable( bEnable );
271 m_aClassPathBtn.Enable( bEnable );
273 bEnable ? m_aJavaList.EnableTable() : m_aJavaList.DisableTable();
275 return 0;
278 // -----------------------------------------------------------------------
280 IMPL_LINK( SvxJavaOptionsPage, CheckHdl_Impl, SvxSimpleTable *, pList )
282 SvLBoxEntry* pEntry = pList ? m_aJavaList.GetEntry( m_aJavaList.GetCurMousePoint() )
283 : m_aJavaList.FirstSelected();
284 if ( pEntry )
285 m_aJavaList.HandleEntryChecked( pEntry );
286 return 0;
289 // -----------------------------------------------------------------------
291 IMPL_LINK( SvxJavaOptionsPage, SelectHdl_Impl, SvxSimpleTable *, EMPTYARG )
293 // set installation directory info
294 SvLBoxEntry* pEntry = m_aJavaList.FirstSelected();
295 DBG_ASSERT( pEntry, "SvxJavaOptionsPage::SelectHdl_Impl(): no entry" );
296 String* pLocation = static_cast< String* >( pEntry->GetUserData() );
297 DBG_ASSERT( pLocation, "invalid location string" );
298 String sInfo = m_sInstallText;
299 if ( pLocation )
300 sInfo += *pLocation;
301 m_aJavaPathText.SetText( sInfo );
302 return 0;
305 // -----------------------------------------------------------------------
307 IMPL_LINK( SvxJavaOptionsPage, AddHdl_Impl, PushButton *, EMPTYARG )
311 Reference < XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
312 xFolderPicker = Reference< XFolderPicker >(
313 xMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FolderPicker" ) ), UNO_QUERY );
315 String sWorkFolder = SvtPathOptions().GetWorkPath();
316 xFolderPicker->setDisplayDirectory( sWorkFolder );
317 xFolderPicker->setDescription( m_sAddDialogText );
319 Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
320 if ( xAsyncDlg.is() )
321 xAsyncDlg->startExecuteModal( xDialogListener.get() );
322 else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
323 AddFolder( xFolderPicker->getDirectory() );
325 catch ( Exception& )
327 #ifdef DBG_UTIL
328 DBG_ERRORFILE( "SvxJavaOptionsPage::AddHdl_Impl(): caught exception" );
329 #endif
332 return 0;
335 // -----------------------------------------------------------------------
337 IMPL_LINK( SvxJavaOptionsPage, ParameterHdl_Impl, PushButton *, EMPTYARG )
339 Sequence< ::rtl::OUString > aParameterList;
340 if ( !m_pParamDlg )
342 m_pParamDlg = new SvxJavaParameterDlg( this );
343 javaFrameworkError eErr = jfw_getVMParameters( &m_parParameters, &m_nParamSize );
344 if ( JFW_E_NONE == eErr && m_parParameters && m_nParamSize > 0 )
346 rtl_uString** pParamArr = m_parParameters;
347 aParameterList.realloc( m_nParamSize );
348 ::rtl::OUString* pParams = aParameterList.getArray();
349 for ( sal_Int32 i = 0; i < m_nParamSize; ++i )
351 rtl_uString* pParam = *pParamArr++;
352 pParams[i] = ::rtl::OUString( pParam );
354 m_pParamDlg->SetParameters( aParameterList );
357 else
358 aParameterList = m_pParamDlg->GetParameters();
360 if ( m_pParamDlg->Execute() == RET_OK )
362 if ( !areListsEqual( aParameterList, m_pParamDlg->GetParameters() ) )
364 aParameterList = m_pParamDlg->GetParameters();
365 sal_Bool bRunning = sal_False;
366 javaFrameworkError eErr = jfw_isVMRunning( &bRunning );
367 DBG_ASSERT( JFW_E_NONE == eErr,
368 "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
369 (void)eErr;
370 if ( bRunning )
372 WarningBox aWarnBox( this, SVX_RES( RID_SVX_MSGBOX_JAVA_RESTART2 ) );
373 aWarnBox.Execute();
377 else
378 m_pParamDlg->SetParameters( aParameterList );
380 return 0;
383 // -----------------------------------------------------------------------
385 IMPL_LINK( SvxJavaOptionsPage, ClassPathHdl_Impl, PushButton *, EMPTYARG )
387 String sClassPath;
389 if ( !m_pPathDlg )
391 m_pPathDlg = new SvxJavaClassPathDlg( this );
392 javaFrameworkError eErr = jfw_getUserClassPath( &m_pClassPath );
393 if ( JFW_E_NONE == eErr && m_pClassPath )
395 sClassPath = String( ::rtl::OUString( m_pClassPath ) );
396 m_pPathDlg->SetClassPath( sClassPath );
399 else
400 sClassPath = m_pPathDlg->GetClassPath();
402 m_pPathDlg->SetFocus();
403 if ( m_pPathDlg->Execute() == RET_OK )
406 if ( m_pPathDlg->GetClassPath() != sClassPath )
408 sClassPath = m_pPathDlg->GetClassPath();
409 sal_Bool bRunning = sal_False;
410 javaFrameworkError eErr = jfw_isVMRunning( &bRunning );
411 DBG_ASSERT( JFW_E_NONE == eErr,
412 "SvxJavaOptionsPage::ParameterHdl_Impl(): error in jfw_isVMRunning" );
413 (void)eErr;
414 if ( bRunning )
416 WarningBox aWarnBox( this, SVX_RES( RID_SVX_MSGBOX_JAVA_RESTART2 ) );
417 aWarnBox.Execute();
421 else
422 m_pPathDlg->SetClassPath( sClassPath );
424 return 0;
427 // -----------------------------------------------------------------------
429 IMPL_LINK( SvxJavaOptionsPage, ResetHdl_Impl, Timer *, EMPTYARG )
431 LoadJREs();
432 return 0;
435 // -----------------------------------------------------------------------
437 IMPL_LINK( SvxJavaOptionsPage, StartFolderPickerHdl, void*, EMPTYARG )
441 Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
442 if ( xAsyncDlg.is() )
443 xAsyncDlg->startExecuteModal( xDialogListener.get() );
444 else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
445 AddFolder( xFolderPicker->getDirectory() );
447 catch ( Exception& )
449 #ifdef DBG_UTIL
450 DBG_ERRORFILE( "SvxJavaOptionsPage::StartFolderPickerHdl(): caught exception" );
451 #endif
454 return 0L;
457 // -----------------------------------------------------------------------
459 IMPL_LINK( SvxJavaOptionsPage, DialogClosedHdl, DialogClosedEvent*, pEvt )
461 if ( RET_OK == pEvt->DialogResult )
463 DBG_ASSERT( xFolderPicker.is() == sal_True, "SvxJavaOptionsPage::DialogClosedHdl(): no folder picker" );
465 AddFolder( xFolderPicker->getDirectory() );
467 return 0L;
470 // -----------------------------------------------------------------------
472 void SvxJavaOptionsPage::ClearJavaInfo()
474 if ( m_parJavaInfo )
476 JavaInfo** parInfo = m_parJavaInfo;
477 for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
479 JavaInfo* pInfo = *parInfo++;
480 jfw_freeJavaInfo( pInfo );
483 rtl_freeMemory( m_parJavaInfo );
484 m_parJavaInfo = NULL;
485 m_nInfoSize = 0;
489 // -----------------------------------------------------------------------
491 void SvxJavaOptionsPage::ClearJavaList()
493 SvLBoxEntry* pEntry = m_aJavaList.First();
494 while ( pEntry )
496 String* pLocation = static_cast< String* >( pEntry->GetUserData() );
497 delete pLocation;
498 pEntry = m_aJavaList.Next( pEntry );
500 m_aJavaList.Clear();
503 // -----------------------------------------------------------------------
505 void SvxJavaOptionsPage::LoadJREs()
507 WaitObject aWaitObj( &m_aJavaList );
508 javaFrameworkError eErr = jfw_findAllJREs( &m_parJavaInfo, &m_nInfoSize );
509 if ( JFW_E_NONE == eErr && m_parJavaInfo )
511 JavaInfo** parInfo = m_parJavaInfo;
512 for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
514 JavaInfo* pInfo = *parInfo++;
515 AddJRE( pInfo );
519 std::vector< JavaInfo* >::iterator pIter;
520 for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
522 JavaInfo* pInfo = *pIter;
523 AddJRE( pInfo );
526 JavaInfo* pSelectedJava = NULL;
527 eErr = jfw_getSelectedJRE( &pSelectedJava );
528 if ( JFW_E_NONE == eErr && pSelectedJava )
530 JavaInfo** parInfo = m_parJavaInfo;
531 for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
533 JavaInfo* pCmpInfo = *parInfo++;
534 if ( jfw_areEqualJavaInfo( pCmpInfo, pSelectedJava ) )
536 SvLBoxEntry* pEntry = m_aJavaList.GetEntry(i);
537 if ( pEntry )
538 m_aJavaList.HandleEntryChecked( pEntry );
539 break;
544 jfw_freeJavaInfo( pSelectedJava );
547 // -----------------------------------------------------------------------
549 void SvxJavaOptionsPage::AddJRE( JavaInfo* _pInfo )
551 String sEntry( '\t' );
552 sEntry += String( ::rtl::OUString( _pInfo->sVendor ) );
553 sEntry += '\t';
554 sEntry += String( ::rtl::OUString( _pInfo->sVersion ) );
555 sEntry += '\t';
556 if ( ( _pInfo->nFeatures & JFW_FEATURE_ACCESSBRIDGE ) == JFW_FEATURE_ACCESSBRIDGE )
557 sEntry += m_sAccessibilityText;
558 SvLBoxEntry* pEntry = m_aJavaList.InsertEntry( sEntry );
559 INetURLObject aLocObj( ::rtl::OUString( _pInfo->sLocation ) );
560 String* pLocation = new String( aLocObj.getFSysPath( INetURLObject::FSYS_DETECT ) );
561 pEntry->SetUserData( pLocation );
564 // -----------------------------------------------------------------------
566 void SvxJavaOptionsPage::HandleCheckEntry( SvLBoxEntry* _pEntry )
568 m_aJavaList.Select( _pEntry, TRUE );
569 SvButtonState eState = m_aJavaList.GetCheckButtonState( _pEntry );
571 if ( SV_BUTTON_CHECKED == eState )
573 // we have radio button behavior -> so uncheck the other entries
574 SvLBoxEntry* pEntry = m_aJavaList.First();
575 while ( pEntry )
577 if ( pEntry != _pEntry )
578 m_aJavaList.SetCheckButtonState( pEntry, SV_BUTTON_UNCHECKED );
579 pEntry = m_aJavaList.Next( pEntry );
582 else
583 m_aJavaList.SetCheckButtonState( _pEntry, SV_BUTTON_CHECKED );
586 // -----------------------------------------------------------------------
588 void SvxJavaOptionsPage::AddFolder( const ::rtl::OUString& _rFolder )
590 bool bStartAgain = true;
591 sal_Int32 nPos = 0;
592 JavaInfo* pInfo = NULL;
593 javaFrameworkError eErr = jfw_getJavaInfoByPath( _rFolder.pData, &pInfo );
594 if ( JFW_E_NONE == eErr && pInfo )
596 bool bFound = false;
597 JavaInfo** parInfo = m_parJavaInfo;
598 for ( sal_Int32 i = 0; i < m_nInfoSize; ++i )
600 JavaInfo* pCmpInfo = *parInfo++;
601 if ( jfw_areEqualJavaInfo( pCmpInfo, pInfo ) )
603 bFound = true;
604 nPos = i;
605 break;
609 if ( !bFound )
611 std::vector< JavaInfo* >::iterator pIter;
612 for ( pIter = m_aAddedInfos.begin(); pIter != m_aAddedInfos.end(); ++pIter )
614 JavaInfo* pCmpInfo = *pIter;
615 if ( jfw_areEqualJavaInfo( pCmpInfo, pInfo ) )
617 bFound = true;
618 break;
623 if ( !bFound )
625 jfw_addJRELocation( pInfo->sLocation );
626 AddJRE( pInfo );
627 m_aAddedInfos.push_back( pInfo );
628 nPos = m_aJavaList.GetEntryCount() - 1;
630 else
631 jfw_freeJavaInfo( pInfo );
633 SvLBoxEntry* pEntry = m_aJavaList.GetEntry( nPos );
634 m_aJavaList.Select( pEntry );
635 m_aJavaList.SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
636 HandleCheckEntry( pEntry );
637 bStartAgain = false;
639 else if ( JFW_E_NOT_RECOGNIZED == eErr )
641 ErrorBox aErrBox( this, SVX_RES( RID_SVXERR_JRE_NOT_RECOGNIZED ) );
642 aErrBox.Execute();
644 else if ( JFW_E_FAILED_VERSION == eErr )
646 ErrorBox aErrBox( this, SVX_RES( RID_SVXERR_JRE_FAILED_VERSION ) );
647 aErrBox.Execute();
650 if ( bStartAgain )
652 xFolderPicker->setDisplayDirectory( _rFolder );
653 Application::PostUserEvent( LINK( this, SvxJavaOptionsPage, StartFolderPickerHdl ) );
657 // -----------------------------------------------------------------------
659 SfxTabPage* SvxJavaOptionsPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
661 return ( new SvxJavaOptionsPage( pParent, rAttrSet ) );
664 // -----------------------------------------------------------------------
666 BOOL SvxJavaOptionsPage::FillItemSet( SfxItemSet& /*rCoreSet*/ )
668 BOOL bModified = FALSE;
669 javaFrameworkError eErr = JFW_E_NONE;
670 if ( m_pParamDlg )
672 Sequence< ::rtl::OUString > aParamList = m_pParamDlg->GetParameters();
673 sal_Int32 i, nSize = aParamList.getLength();
674 rtl_uString** pParamArr = (rtl_uString**)rtl_allocateMemory( sizeof(rtl_uString*) * nSize );
675 rtl_uString** pParamArrIter = pParamArr;
676 const ::rtl::OUString* pList = aParamList.getConstArray();
677 for ( i = 0; i < nSize; ++i )
678 pParamArr[i] = pList[i].pData;
679 eErr = jfw_setVMParameters( pParamArrIter, nSize );
680 DBG_ASSERT( JFW_E_NONE == eErr,
681 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters" );
682 pParamArrIter = pParamArr;
683 rtl_freeMemory( pParamArr );
684 bModified = TRUE;
687 if ( m_pPathDlg )
689 ::rtl::OUString sPath( m_pPathDlg->GetClassPath() );
690 if ( m_pPathDlg->GetOldPath() != String( sPath ) )
692 eErr = jfw_setUserClassPath( sPath.pData );
693 DBG_ASSERT( JFW_E_NONE == eErr,
694 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setUserClassPath" );
695 bModified = TRUE;
699 ULONG nCount = m_aJavaList.GetEntryCount();
700 for ( ULONG i = 0; i < nCount; ++i )
702 if ( m_aJavaList.GetCheckButtonState( m_aJavaList.GetEntry(i) ) == SV_BUTTON_CHECKED )
704 JavaInfo* pInfo = NULL;
705 if ( i < static_cast< ULONG >( m_nInfoSize ) )
706 pInfo = m_parJavaInfo[i];
707 else
708 pInfo = m_aAddedInfos[ i - m_nInfoSize ];
710 JavaInfo* pSelectedJava = NULL;
711 eErr = jfw_getSelectedJRE( &pSelectedJava );
712 if ( JFW_E_NONE == eErr || JFW_E_INVALID_SETTINGS == eErr )
714 if (pSelectedJava == NULL || !jfw_areEqualJavaInfo( pInfo, pSelectedJava ) )
716 sal_Bool bRunning = sal_False;
717 eErr = jfw_isVMRunning( &bRunning );
718 DBG_ASSERT( JFW_E_NONE == eErr,
719 "SvxJavaOptionsPage::FillItemSet(): error in jfw_isVMRunning" );
720 if ( bRunning ||
721 ( ( pInfo->nRequirements & JFW_REQUIRE_NEEDRESTART ) == JFW_REQUIRE_NEEDRESTART ) )
723 WarningBox aWarnBox( this, SVX_RES( RID_SVX_MSGBOX_JAVA_RESTART ) );
724 aWarnBox.Execute();
727 eErr = jfw_setSelectedJRE( pInfo );
728 DBG_ASSERT( JFW_E_NONE == eErr,
729 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE" );
730 bModified = TRUE;
733 jfw_freeJavaInfo( pSelectedJava );
734 break;
738 sal_Bool bEnabled = sal_False;
739 eErr = jfw_getEnabled( &bEnabled );
740 DBG_ASSERT( JFW_E_NONE == eErr,
741 "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
742 if ( bEnabled != m_aJavaEnableCB.IsChecked() )
744 eErr = jfw_setEnabled( m_aJavaEnableCB.IsChecked() );
745 DBG_ASSERT( JFW_E_NONE == eErr,
746 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
747 bModified = TRUE;
750 return bModified;
753 // -----------------------------------------------------------------------
755 void SvxJavaOptionsPage::Reset( const SfxItemSet& /*rSet*/ )
757 ClearJavaInfo();
758 ClearJavaList();
760 sal_Bool bEnabled = sal_False;
761 javaFrameworkError eErr = jfw_getEnabled( &bEnabled );
762 if ( eErr != JFW_E_NONE )
763 bEnabled = sal_False;
764 m_aJavaEnableCB.Check( bEnabled );
765 EnableHdl_Impl( &m_aJavaEnableCB );
767 m_aResetTimer.Start();
770 // -----------------------------------------------------------------------
772 void SvxJavaOptionsPage::FillUserData()
774 String aUserData;
775 SetUserData( aUserData );
778 // class SvxJavaParameterDlg ---------------------------------------------
780 SvxJavaParameterDlg::SvxJavaParameterDlg( Window* pParent ) :
782 ModalDialog( pParent, SVX_RES( RID_SVXDLG_JAVA_PARAMETER ) ),
784 m_aParameterLabel ( this, SVX_RES( FT_PARAMETER ) ),
785 m_aParameterEdit ( this, SVX_RES( ED_PARAMETER ) ),
786 m_aAssignBtn ( this, SVX_RES( PB_ASSIGN ) ),
787 m_aAssignedLabel ( this, SVX_RES( FT_ASSIGNED ) ),
788 m_aAssignedList ( this, SVX_RES( LB_ASSIGNED ) ),
789 m_aExampleText ( this, SVX_RES( FT_EXAMPLE ) ),
790 m_aRemoveBtn ( this, SVX_RES( PB_REMOVE ) ),
791 m_aButtonsLine ( this, SVX_RES( FL_BUTTONS ) ),
792 m_aOKBtn ( this, SVX_RES( PB_PARAMETER_OK ) ),
793 m_aCancelBtn ( this, SVX_RES( PB_PARAMETER_ESC ) ),
794 m_aHelpBtn ( this, SVX_RES( PB_PARAMETER_HLP ) )
797 FreeResource();
799 m_aParameterEdit.SetModifyHdl( LINK( this, SvxJavaParameterDlg, ModifyHdl_Impl ) );
800 m_aAssignBtn.SetClickHdl( LINK( this, SvxJavaParameterDlg, AssignHdl_Impl ) );
801 m_aRemoveBtn.SetClickHdl( LINK( this, SvxJavaParameterDlg, RemoveHdl_Impl ) );
802 m_aAssignedList.SetSelectHdl( LINK( this, SvxJavaParameterDlg, SelectHdl_Impl ) );
803 m_aAssignedList.SetDoubleClickHdl( LINK( this, SvxJavaParameterDlg, DblClickHdl_Impl ) );
805 ModifyHdl_Impl( &m_aParameterEdit );
806 EnableRemoveButton();
809 // -----------------------------------------------------------------------
811 SvxJavaParameterDlg::~SvxJavaParameterDlg()
815 // -----------------------------------------------------------------------
817 IMPL_LINK( SvxJavaParameterDlg, ModifyHdl_Impl, Edit *, EMPTYARG )
819 String sParam = STRIM( m_aParameterEdit.GetText() );
820 m_aAssignBtn.Enable( sParam.Len() > 0 );
822 return 0;
825 // -----------------------------------------------------------------------
827 IMPL_LINK( SvxJavaParameterDlg, AssignHdl_Impl, PushButton *, EMPTYARG )
829 String sParam = STRIM( m_aParameterEdit.GetText() );
830 if ( sParam.Len() > 0 )
832 USHORT nPos = m_aAssignedList.GetEntryPos( sParam );
833 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
834 nPos = m_aAssignedList.InsertEntry( sParam );
835 m_aAssignedList.SelectEntryPos( nPos );
836 m_aParameterEdit.SetText( String() );
837 ModifyHdl_Impl( &m_aParameterEdit );
838 EnableRemoveButton();
841 return 0;
844 // -----------------------------------------------------------------------
846 IMPL_LINK( SvxJavaParameterDlg, SelectHdl_Impl, ListBox *, EMPTYARG )
848 EnableRemoveButton();
849 return 0;
852 // -----------------------------------------------------------------------
854 IMPL_LINK( SvxJavaParameterDlg, DblClickHdl_Impl, ListBox *, EMPTYARG )
856 USHORT nPos = m_aAssignedList.GetSelectEntryPos();
857 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
858 m_aParameterEdit.SetText( m_aAssignedList.GetEntry( nPos ) );
859 return 0;
862 // -----------------------------------------------------------------------
864 IMPL_LINK( SvxJavaParameterDlg, RemoveHdl_Impl, PushButton *, EMPTYARG )
866 USHORT nPos = m_aAssignedList.GetSelectEntryPos();
867 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
869 m_aAssignedList.RemoveEntry( nPos );
870 USHORT nCount = m_aAssignedList.GetEntryCount();
871 if ( nCount )
873 if ( nPos >= nCount )
874 nPos = ( nCount - 1 );
875 m_aAssignedList.SelectEntryPos( nPos );
878 EnableRemoveButton();
880 return 0;
883 // -----------------------------------------------------------------------
885 short SvxJavaParameterDlg::Execute()
887 m_aParameterEdit.GrabFocus();
888 m_aAssignedList.SetNoSelection();
889 return ModalDialog::Execute();
892 // -----------------------------------------------------------------------
894 Sequence< ::rtl::OUString > SvxJavaParameterDlg::GetParameters() const
896 USHORT nCount = m_aAssignedList.GetEntryCount();
897 Sequence< ::rtl::OUString > aParamList( nCount );
898 ::rtl::OUString* pArray = aParamList.getArray();
899 for ( USHORT i = 0; i < nCount; ++i )
900 pArray[i] = ::rtl::OUString( m_aAssignedList.GetEntry(i) );
901 return aParamList;
904 // -----------------------------------------------------------------------
906 void SvxJavaParameterDlg::SetParameters( Sequence< ::rtl::OUString >& rParams )
908 m_aAssignedList.Clear();
909 ULONG i, nCount = rParams.getLength();
910 const ::rtl::OUString* pArray = rParams.getConstArray();
911 for ( i = 0; i < nCount; ++i )
913 String sParam = String( *pArray++ );
914 m_aAssignedList.InsertEntry( sParam );
918 // class SvxJavaClassPathDlg ---------------------------------------------
920 SvxJavaClassPathDlg::SvxJavaClassPathDlg( Window* pParent ) :
922 ModalDialog( pParent, SVX_RES( RID_SVXDLG_JAVA_CLASSPATH ) ),
924 m_aPathLabel ( this, SVX_RES( FT_PATH ) ),
925 m_aPathList ( this, SVX_RES( LB_PATH ) ),
926 m_aAddArchiveBtn ( this, SVX_RES( PB_ADDARCHIVE ) ),
927 m_aAddPathBtn ( this, SVX_RES( PB_ADDPATH ) ),
928 m_aRemoveBtn ( this, SVX_RES( PB_REMOVE_PATH ) ),
929 m_aButtonsLine ( this, SVX_RES( FL_PATH_BUTTONS ) ),
930 m_aOKBtn ( this, SVX_RES( PB_PATH_OK ) ),
931 m_aCancelBtn ( this, SVX_RES( PB_PATH_ESC ) ),
932 m_aHelpBtn ( this, SVX_RES( PB_PATH_HLP ) )
935 FreeResource();
937 m_aAddArchiveBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, AddArchiveHdl_Impl ) );
938 m_aAddPathBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, AddPathHdl_Impl ) );
939 m_aRemoveBtn.SetClickHdl( LINK( this, SvxJavaClassPathDlg, RemoveHdl_Impl ) );
940 m_aPathList.SetSelectHdl( LINK( this, SvxJavaClassPathDlg, SelectHdl_Impl ) );
942 // check if the buttons text are not too wide otherwise we have to stretch the buttons
943 // and shrink the listbox
944 long nTxtWidth1 = m_aAddArchiveBtn.GetTextWidth( m_aAddArchiveBtn.GetText() );
945 long nTxtWidth2 = m_aAddPathBtn.GetTextWidth( m_aAddPathBtn.GetText() );
946 Size aBtnSz = m_aAddArchiveBtn.GetSizePixel();
947 if ( nTxtWidth1 > aBtnSz.Width() || nTxtWidth2 > aBtnSz.Width() )
949 long nW = ( nTxtWidth1 > aBtnSz.Width() ) ? nTxtWidth1 : nTxtWidth2;
950 long nDelta = nW - aBtnSz.Width() + 2 * BUTTON_BORDER;
951 aBtnSz.Width() += nDelta;
952 Point aBtnPnt = m_aAddArchiveBtn.GetPosPixel();
953 aBtnPnt.X() -= nDelta;
954 m_aAddArchiveBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
955 aBtnPnt = m_aAddPathBtn.GetPosPixel();
956 aBtnPnt.X() -= nDelta;
957 m_aAddPathBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
958 aBtnPnt = m_aRemoveBtn.GetPosPixel();
959 aBtnPnt.X() -= nDelta;
960 m_aRemoveBtn.SetPosSizePixel( aBtnPnt, aBtnSz );
961 Size aBoxSz = m_aPathList.GetSizePixel();
962 aBoxSz.Width() -= nDelta;
963 m_aPathList.SetSizePixel( aBoxSz );
966 // set initial focus to path list
967 m_aPathList.GrabFocus();
970 // -----------------------------------------------------------------------
972 SvxJavaClassPathDlg::~SvxJavaClassPathDlg()
974 USHORT i, nCount = m_aPathList.GetEntryCount();
975 for ( i = 0; i < nCount; ++i )
976 delete static_cast< String* >( m_aPathList.GetEntryData(i) );
979 // -----------------------------------------------------------------------
981 IMPL_LINK( SvxJavaClassPathDlg, AddArchiveHdl_Impl, PushButton *, EMPTYARG )
983 sfx2::FileDialogHelper aDlg( TemplateDescription::FILEOPEN_SIMPLE, 0 );
984 aDlg.SetTitle( SVX_RES( RID_SVXSTR_ARCHIVE_TITLE ) );
985 aDlg.AddFilter( SVX_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), String::CreateFromAscii("*.jar;*.zip") );
986 String sFolder;
987 if ( m_aPathList.GetSelectEntryCount() > 0 )
989 INetURLObject aObj( m_aPathList.GetSelectEntry(), INetURLObject::FSYS_DETECT );
990 sFolder = aObj.GetMainURL( INetURLObject::NO_DECODE );
992 else
993 sFolder = SvtPathOptions().GetWorkPath();
994 aDlg.SetDisplayDirectory( sFolder );
995 if ( aDlg.Execute() == ERRCODE_NONE )
997 String sURL = aDlg.GetPath();
998 INetURLObject aURL( sURL );
999 String sFile = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
1000 if ( !IsPathDuplicate( sURL ) )
1002 USHORT nPos = m_aPathList.InsertEntry( sFile, SvFileInformationManager::GetImage( aURL ) );
1003 m_aPathList.SelectEntryPos( nPos );
1005 else
1007 String sMsg( SVX_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
1008 sMsg.SearchAndReplaceAscii( "%1", sFile );
1009 ErrorBox( this, WB_OK, sMsg ).Execute();
1012 EnableRemoveButton();
1013 return 0;
1016 // -----------------------------------------------------------------------
1018 IMPL_LINK( SvxJavaClassPathDlg, AddPathHdl_Impl, PushButton *, EMPTYARG )
1020 rtl::OUString sService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker" ) );
1021 Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
1022 Reference < XFolderPicker > xFolderPicker( xFactory->createInstance( sService ), UNO_QUERY );
1024 String sOldFolder;
1025 if ( m_aPathList.GetSelectEntryCount() > 0 )
1027 INetURLObject aObj( m_aPathList.GetSelectEntry(), INetURLObject::FSYS_DETECT );
1028 sOldFolder = aObj.GetMainURL( INetURLObject::NO_DECODE );
1030 else
1031 sOldFolder = SvtPathOptions().GetWorkPath();
1032 xFolderPicker->setDisplayDirectory( sOldFolder );
1033 if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
1035 String sFolderURL( xFolderPicker->getDirectory() );
1036 INetURLObject aURL( sFolderURL );
1037 String sNewFolder = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
1038 if ( !IsPathDuplicate( sFolderURL ) )
1040 USHORT nPos = m_aPathList.InsertEntry( sNewFolder, SvFileInformationManager::GetImage( aURL ) );
1041 m_aPathList.SelectEntryPos( nPos );
1043 else
1045 String sMsg( SVX_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
1046 sMsg.SearchAndReplaceAscii( "%1", sNewFolder );
1047 ErrorBox( this, WB_OK, sMsg ).Execute();
1050 EnableRemoveButton();
1051 return 0;
1054 // -----------------------------------------------------------------------
1056 IMPL_LINK( SvxJavaClassPathDlg, RemoveHdl_Impl, PushButton *, EMPTYARG )
1058 USHORT nPos = m_aPathList.GetSelectEntryPos();
1059 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1061 m_aPathList.RemoveEntry( nPos );
1062 USHORT nCount = m_aPathList.GetEntryCount();
1063 if ( nCount )
1065 if ( nPos >= nCount )
1066 nPos = ( nCount - 1 );
1067 m_aPathList.SelectEntryPos( nPos );
1071 EnableRemoveButton();
1072 return 0;
1075 // -----------------------------------------------------------------------
1077 IMPL_LINK( SvxJavaClassPathDlg, SelectHdl_Impl, ListBox *, EMPTYARG )
1079 EnableRemoveButton();
1080 return 0;
1083 // -----------------------------------------------------------------------
1085 bool SvxJavaClassPathDlg::IsPathDuplicate( const String& _rPath )
1087 bool bRet = false;
1088 INetURLObject aFileObj( _rPath );
1089 USHORT nCount = m_aPathList.GetEntryCount();
1090 for ( USHORT i = 0; i < nCount; ++i )
1092 INetURLObject aOtherObj( m_aPathList.GetEntry(i), INetURLObject::FSYS_DETECT );
1093 if ( aOtherObj == aFileObj )
1095 bRet = true;
1096 break;
1100 return bRet;
1103 // -----------------------------------------------------------------------
1105 String SvxJavaClassPathDlg::GetClassPath() const
1107 String sPath;
1108 USHORT nCount = m_aPathList.GetEntryCount();
1109 for ( USHORT i = 0; i < nCount; ++i )
1111 if ( sPath.Len() > 0 )
1112 sPath += CLASSPATH_DELIMITER;
1113 String* pFullPath = static_cast< String* >( m_aPathList.GetEntryData(i) );
1114 if ( pFullPath )
1115 sPath += *pFullPath;
1116 else
1117 sPath += m_aPathList.GetEntry(i);
1119 return sPath;
1122 // -----------------------------------------------------------------------
1124 void SvxJavaClassPathDlg::SetClassPath( const String& _rPath )
1126 if ( m_sOldPath.Len() == 0 )
1127 m_sOldPath = _rPath;
1128 m_aPathList.Clear();
1129 xub_StrLen i, nIdx = 0;
1130 xub_StrLen nCount = _rPath.GetTokenCount( CLASSPATH_DELIMITER );
1131 for ( i = 0; i < nCount; ++i )
1133 String sToken = _rPath.GetToken( 0, CLASSPATH_DELIMITER, nIdx );
1134 INetURLObject aURL( sToken, INetURLObject::FSYS_DETECT );
1135 String sPath = aURL.getFSysPath( INetURLObject::FSYS_DETECT );
1136 m_aPathList.InsertEntry( sPath, SvFileInformationManager::GetImage( aURL ) );
1138 // select first entry
1139 m_aPathList.SelectEntryPos(0);
1140 SelectHdl_Impl( NULL );