LibreOffice Module cui (master) 1
optjava.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <o3tl/safeint.hxx>
21#include <sal/config.h>
22#include <sal/log.hxx>
23
24#include <cassert>
25#include <memory>
26
27#include <config_java.h>
28
29#include "optaboutconfig.hxx"
30#include "optjava.hxx"
31#include <treeopt.hxx>
32#include <dialmgr.hxx>
33
34#include <officecfg/Office/Common.hxx>
35#include <osl/file.hxx>
36
37#include <strings.hrc>
38#include <vcl/svapp.hxx>
39#include <tools/debug.hxx>
40#include <tools/urlobj.hxx>
41#include <vcl/weld.hxx>
43#include <svtools/imagemgr.hxx>
46#include <sfx2/inputdlg.hxx>
49#include <comphelper/string.hxx>
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#if HAVE_FEATURE_JAVA
54#include <jvmfwk/framework.hxx>
55#endif
56
57// define ----------------------------------------------------------------
58
59#define CLASSPATH_DELIMITER SAL_PATHSEPARATOR
60
61using namespace ::com::sun::star::lang;
62using namespace ::com::sun::star::ucb;
63using namespace ::com::sun::star::ui::dialogs;
64using namespace ::com::sun::star::uno;
65
66// class SvxJavaOptionsPage ----------------------------------------------
68 : SfxTabPage(pPage, pController, "cui/ui/optadvancedpage.ui", "OptAdvancedPage", &rSet)
69 , m_aResetIdle("cui options SvxJavaOptionsPage Reset")
70 , xDialogListener(new ::svt::DialogClosedListener())
71 , m_xJavaEnableCB(m_xBuilder->weld_check_button("javaenabled"))
72 , m_xJavaList(m_xBuilder->weld_tree_view("javas"))
73 , m_xJavaPathText(m_xBuilder->weld_label("javapath"))
74 , m_xAddBtn(m_xBuilder->weld_button("add"))
75 , m_xParameterBtn(m_xBuilder->weld_button("parameters"))
76 , m_xClassPathBtn(m_xBuilder->weld_button("classpath"))
77 , m_xExpertConfigBtn(m_xBuilder->weld_button("expertconfig"))
78 , m_xExperimentalCB(m_xBuilder->weld_check_button("experimental"))
79 , m_xMacroCB(m_xBuilder->weld_check_button("macrorecording"))
80 , m_xAddDialogText(m_xBuilder->weld_label("selectruntime"))
81 , m_xJavaFrame(m_xBuilder->weld_widget("javaframe"))
82{
83 m_sInstallText = m_xJavaPathText->get_label();
85
86 m_xJavaList->set_size_request(m_xJavaList->get_approximate_digit_width() * 30,
87 m_xJavaList->get_height_rows(8));
88
89 m_xJavaList->enable_toggle_buttons(weld::ColumnToggleType::Radio);
90 m_xJavaList->connect_toggled( LINK( this, SvxJavaOptionsPage, CheckHdl_Impl ) );
91 m_xJavaList->connect_changed( LINK( this, SvxJavaOptionsPage, SelectHdl_Impl ) );
92
93 std::vector<int> aWidths
94 {
95 m_xJavaList->get_checkbox_column_width(),
96 o3tl::narrowing<int>(m_xJavaList->get_pixel_size("Sun Microsystems Inc.").Width())
97 };
98 m_xJavaList->set_column_fixed_widths(aWidths);
99
100 m_xJavaEnableCB->connect_toggled( LINK( this, SvxJavaOptionsPage, EnableHdl_Impl ) );
101 m_xAddBtn->connect_clicked( LINK( this, SvxJavaOptionsPage, AddHdl_Impl ) );
102 m_xParameterBtn->connect_clicked( LINK( this, SvxJavaOptionsPage, ParameterHdl_Impl ) );
103 m_xClassPathBtn->connect_clicked( LINK( this, SvxJavaOptionsPage, ClassPathHdl_Impl ) );
104 m_aResetIdle.SetInvokeHandler( LINK( this, SvxJavaOptionsPage, ResetHdl_Impl ) );
105
106 m_xExpertConfigBtn->connect_clicked( LINK( this, SvxJavaOptionsPage, ExpertConfigHdl_Impl) );
107 if (!officecfg::Office::Common::Security::EnableExpertConfiguration::get())
108 m_xExpertConfigBtn->set_sensitive(false);
109
110 if (officecfg::Office::Common::Misc::MacroRecorderMode::isReadOnly())
111 m_xMacroCB->set_sensitive(false);
112
113 if (officecfg::Office::Common::Misc::ExperimentalMode::isReadOnly())
114 m_xExperimentalCB->set_sensitive(false);
115
116 xDialogListener->SetDialogClosedLink( LINK( this, SvxJavaOptionsPage, DialogClosedHdl ) );
117
118 EnableHdl_Impl(*m_xJavaEnableCB);
119#if HAVE_FEATURE_JAVA
120 jfw_lock();
121#else
122 m_xJavaFrame->set_sensitive(false);
123#endif
124}
125
127{
129#if HAVE_FEATURE_JAVA
130 m_aAddedInfos.clear();
131
132 jfw_unlock();
133#endif
134}
135
137{
138 bool bEnable = m_xJavaFrame->get_sensitive() && m_xJavaEnableCB->get_active();
139 m_xJavaList->set_sensitive(bEnable);
140}
141
142IMPL_LINK(SvxJavaOptionsPage, CheckHdl_Impl, const weld::TreeView::iter_col&, rRowCol, void)
143{
144 HandleCheckEntry(m_xJavaList->get_iter_index_in_parent(rRowCol.first));
145}
146
148{
149 UpdateJavaPathText();
150}
151
153{
154 try
155 {
156 Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
157 xFolderPicker = sfx2::createFolderPicker(xContext, GetFrameWeld());
158
159 OUString sWorkFolder = SvtPathOptions().GetWorkPath();
160 xFolderPicker->setDisplayDirectory( sWorkFolder );
161 xFolderPicker->setDescription( m_sAddDialogText );
162
163 Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
164 if ( xAsyncDlg.is() )
165 xAsyncDlg->startExecuteModal( xDialogListener );
166 else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
167 AddFolder( xFolderPicker->getDirectory() );
168 }
169 catch (const Exception&)
170 {
171 TOOLS_WARN_EXCEPTION( "cui.options", "SvxJavaOptionsPage::AddHdl_Impl()");
172 }
173}
174
176{
177#if HAVE_FEATURE_JAVA
178 std::vector< OUString > aParameterList;
179 if (!m_xParamDlg)
180 {
181 m_xParamDlg.reset(new SvxJavaParameterDlg(GetFrameWeld()));
182 javaFrameworkError eErr = jfw_getVMParameters( &m_parParameters );
183 if ( JFW_E_NONE == eErr && !m_parParameters.empty() )
184 {
185 aParameterList = m_parParameters;
186 m_xParamDlg->SetParameters( aParameterList );
187 }
188 }
189 else
190 {
191 aParameterList = m_xParamDlg->GetParameters();
192 m_xParamDlg->DisableButtons(); //disable add, edit and remove button when dialog is reopened
193 }
194
195 if (m_xParamDlg->run() == RET_OK)
196 {
197 if ( aParameterList != m_xParamDlg->GetParameters() )
198 {
199 aParameterList = m_xParamDlg->GetParameters();
200 if ( jfw_isVMRunning() )
201 {
203 }
204 }
205 }
206 else
207 m_xParamDlg->SetParameters( aParameterList );
208#else
209 (void) this; // Silence loplugin:staticmethods
210#endif
211}
212
213
215{
216#if HAVE_FEATURE_JAVA
217 OUString sClassPath;
218
219 if ( !m_xPathDlg )
220 {
221 m_xPathDlg.reset(new SvxJavaClassPathDlg(GetFrameWeld()));
222 javaFrameworkError eErr = jfw_getUserClassPath( &m_pClassPath );
223 if ( JFW_E_NONE == eErr )
224 {
225 sClassPath = m_pClassPath;
226 m_xPathDlg->SetClassPath( sClassPath );
227 }
228 }
229 else
230 sClassPath = m_xPathDlg->GetClassPath();
231
232 m_xPathDlg->SetFocus();
233 if (m_xPathDlg->run() == RET_OK)
234 {
235
236 if (m_xPathDlg->GetClassPath() != sClassPath)
237 {
238 sClassPath = m_xPathDlg->GetClassPath();
239 if ( jfw_isVMRunning() )
240 {
242 }
243 }
244 }
245 else
246 m_xPathDlg->SetClassPath( sClassPath );
247#else
248 (void) this;
249#endif
250}
251
252
254{
255 LoadJREs();
256}
257
258
259IMPL_LINK_NOARG(SvxJavaOptionsPage, StartFolderPickerHdl, void*, void)
260{
261 try
262 {
263 Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
264 if ( xAsyncDlg.is() )
265 xAsyncDlg->startExecuteModal( xDialogListener );
266 else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
267 AddFolder( xFolderPicker->getDirectory() );
268 }
269 catch ( Exception const & )
270 {
271 TOOLS_WARN_EXCEPTION( "cui.options", "SvxJavaOptionsPage::StartFolderPickerHdl()" );
272 }
273}
274
275IMPL_LINK( SvxJavaOptionsPage, DialogClosedHdl, DialogClosedEvent*, pEvt, void )
276{
277 if ( RET_OK == pEvt->DialogResult )
278 {
279 DBG_ASSERT( xFolderPicker.is(), "SvxJavaOptionsPage::DialogClosedHdl(): no folder picker" );
280
281 AddFolder( xFolderPicker->getDirectory() );
282 }
283}
284
285IMPL_LINK_NOARG(SvxJavaOptionsPage, ExpertConfigHdl_Impl, weld::Button&, void)
286{
287 CuiAboutConfigTabPage aExpertConfigDlg(GetFrameWeld());
288 {
290 aExpertConfigDlg.Reset();//initialize and reset function
291 }
292
293 if (RET_OK == aExpertConfigDlg.run())
294 {
295 aExpertConfigDlg.FillItemSet();//save changes if there are any
296 }
297}
298
300{
301#if HAVE_FEATURE_JAVA
302 m_parJavaInfo.clear();
303#else
304 (void) this;
305#endif
306}
307
309{
310#if HAVE_FEATURE_JAVA
311 weld::WaitObject aWaitObj(GetFrameWeld());
312 javaFrameworkError eErr = jfw_findAllJREs( &m_parJavaInfo );
313 if ( JFW_E_NONE == eErr )
314 {
315 for (auto const & pInfo: m_parJavaInfo)
316 {
317 AddJRE( pInfo.get() );
318 }
319 }
320
321 for (auto const & pInfo: m_aAddedInfos)
322 {
323 AddJRE( pInfo.get() );
324 }
325
326 std::unique_ptr<JavaInfo> pSelectedJava;
327 eErr = jfw_getSelectedJRE( &pSelectedJava );
328 if ( !(JFW_E_NONE == eErr && pSelectedJava) )
329 return;
330
331 sal_Int32 i = 0;
332 for (auto const & pCmpInfo: m_parJavaInfo)
333 {
334 if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pSelectedJava.get() ) )
335 {
338 break;
339 }
340 ++i;
341 }
342#else
343 (void) this;
344#endif
345}
346
347
349{
350#if HAVE_FEATURE_JAVA
351 int nPos = m_xJavaList->n_children();
352 m_xJavaList->append();
353 m_xJavaList->set_toggle(nPos, TRISTATE_FALSE);
354 m_xJavaList->set_text(nPos, _pInfo->sVendor, 1);
355 m_xJavaList->set_text(nPos, _pInfo->sVersion, 2);
356
357 INetURLObject aLocObj(_pInfo->sLocation);
358 OUString sLocation = aLocObj.getFSysPath(FSysStyle::Detect);
359 m_xJavaList->set_id(nPos, sLocation);
360#else
361 (void) this;
362 (void)_pInfo;
363#endif
364}
365
367{
368 m_xJavaList->select(nCheckedRow);
369 for (int i = 0, nCount = m_xJavaList->n_children(); i < nCount; ++i)
370 {
371 // we have radio button behavior -> so uncheck the other entries
372 m_xJavaList->set_toggle(i, i == nCheckedRow ? TRISTATE_TRUE : TRISTATE_FALSE);
373 }
374}
375
377{
378 assert(m_xJavaList->get_selected_index() != -1);
379 // set installation directory info
380 OUString sLocation = m_xJavaList->get_selected_id();
381 // tdf#80646 insert LTR mark after label
382 OUString sInfo = m_sInstallText + u"\u200E" + sLocation;
383 m_xJavaPathText->set_label(sInfo);
384}
385
386void SvxJavaOptionsPage::AddFolder( const OUString& _rFolder )
387{
388#if HAVE_FEATURE_JAVA
389 bool bStartAgain = true;
390 std::unique_ptr<JavaInfo> pInfo;
391 javaFrameworkError eErr = jfw_getJavaInfoByPath( _rFolder, &pInfo );
392 if ( JFW_E_NONE == eErr && pInfo )
393 {
394 sal_Int32 nPos = 0;
395 bool bFound = false;
396 for (auto const & pCmpInfo: m_parJavaInfo)
397 {
398 if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pInfo.get() ) )
399 {
400 bFound = true;
401 break;
402 }
403 ++nPos;
404 }
405
406 if ( !bFound )
407 {
408 for (auto const & pCmpInfo: m_aAddedInfos)
409 {
410 if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pInfo.get() ) )
411 {
412 bFound = true;
413 break;
414 }
415 ++nPos;
416 }
417 }
418
419 if ( !bFound )
420 {
421 jfw_addJRELocation( pInfo->sLocation );
422 AddJRE( pInfo.get() );
423 m_aAddedInfos.push_back( std::move(pInfo) );
424 nPos = m_xJavaList->n_children() - 1;
425 }
426
429 bStartAgain = false;
430 }
431 else if ( JFW_E_NOT_RECOGNIZED == eErr )
432 {
433 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
434 VclMessageType::Warning, VclButtonsType::Ok,
435 CuiResId(RID_CUISTR_JRE_NOT_RECOGNIZED)));
436 xBox->run();
437 }
438 else if ( JFW_E_FAILED_VERSION == eErr )
439 {
440 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
441 VclMessageType::Warning, VclButtonsType::Ok,
442 CuiResId(RID_CUISTR_JRE_FAILED_VERSION)));
443 xBox->run();
444 }
445
446 if ( bStartAgain )
447 {
448 xFolderPicker->setDisplayDirectory( _rFolder );
449 Application::PostUserEvent( LINK( this, SvxJavaOptionsPage, StartFolderPickerHdl ) );
450 }
451#else
452 (void) this;
453 (void)_rFolder;
454#endif
455}
456
458{
460 if (pParentDlg)
461 pParentDlg->SetNeedsRestart(eReason);
462}
463
464std::unique_ptr<SfxTabPage> SvxJavaOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
465{
466 return std::make_unique<SvxJavaOptionsPage>(pPage, pController, *rAttrSet);
467}
468
470{
471 bool bModified = false;
472
473 if ( m_xExperimentalCB->get_state_changed_from_saved() )
474 {
475 std::shared_ptr< comphelper::ConfigurationChanges > xChanges(
477 officecfg::Office::Common::Misc::ExperimentalMode::set( m_xExperimentalCB->get_active(), xChanges );
478 xChanges->commit();
479 bModified = true;
481 }
482
483 if ( m_xMacroCB->get_state_changed_from_saved() )
484 {
485 std::shared_ptr< comphelper::ConfigurationChanges > xChanges(
487 officecfg::Office::Common::Misc::MacroRecorderMode::set( m_xMacroCB->get_active(), xChanges );
488 xChanges->commit();
489 bModified = true;
490 }
491
492#if HAVE_FEATURE_JAVA
494 if (m_xParamDlg)
495 {
496 eErr = jfw_setVMParameters(m_xParamDlg->GetParameters());
497 SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters");
498 bModified = true;
499 }
500
501 if (m_xPathDlg)
502 {
503 OUString sPath(m_xPathDlg->GetClassPath());
504 if (m_xPathDlg->GetOldPath() != sPath)
505 {
506 eErr = jfw_setUserClassPath( sPath );
507 SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setUserClassPath");
508 bModified = true;
509 }
510 }
511
512 sal_uInt32 nCount = m_xJavaList->n_children();
513 for (sal_uInt32 i = 0; i < nCount; ++i)
514 {
515 if (m_xJavaList->get_toggle(i) == TRISTATE_TRUE)
516 {
517 JavaInfo const * pInfo;
518 if ( i < m_parJavaInfo.size() )
519 pInfo = m_parJavaInfo[i].get();
520 else
521 pInfo = m_aAddedInfos[ i - m_parJavaInfo.size() ].get();
522
523 std::unique_ptr<JavaInfo> pSelectedJava;
524 eErr = jfw_getSelectedJRE( &pSelectedJava );
525 if ( JFW_E_NONE == eErr || JFW_E_INVALID_SETTINGS == eErr )
526 {
527 if (!pSelectedJava || !jfw_areEqualJavaInfo( pInfo, pSelectedJava.get() ) )
528 {
529 if ( jfw_isVMRunning() ||
531 {
533 }
534
535 eErr = jfw_setSelectedJRE( pInfo );
536 SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE");
537 bModified = true;
538 }
539 }
540 break;
541 }
542 }
543
544 bool bEnabled = false;
545 eErr = jfw_getEnabled( &bEnabled );
546 DBG_ASSERT( JFW_E_NONE == eErr,
547 "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
548 if ( bEnabled != m_xJavaEnableCB->get_active() )
549 {
550 eErr = jfw_setEnabled( m_xJavaEnableCB->get_active() );
551 DBG_ASSERT( JFW_E_NONE == eErr,
552 "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
553 bModified = true;
554 }
555#endif
556
557 return bModified;
558}
559
560
562{
564 m_xJavaList->clear();
565
566#if HAVE_FEATURE_JAVA
567 bool bEnabled = false;
568 javaFrameworkError eErr = jfw_getEnabled( &bEnabled );
569 if (eErr == JFW_E_DIRECT_MODE)
570 {
571 // direct mode disregards Java settings made here, so gray them out
572 m_xJavaFrame->set_sensitive(false);
573 // check whether a usable JRE was set
574 std::unique_ptr<JavaInfo> pSelectedJava;
575 eErr = jfw_getSelectedJRE( &pSelectedJava );
576 bEnabled = (eErr == JFW_E_NONE);
577 }
578 else if ( eErr != JFW_E_NONE )
579 bEnabled = false;
580 m_xJavaEnableCB->set_active(bEnabled);
581 EnableHdl_Impl(*m_xJavaEnableCB);
582#else
583 m_xJavaEnableCB->set_active(false);
584 m_xJavaEnableCB->set_sensitive(false);
585#endif
586
587 m_xExperimentalCB->set_active( officecfg::Office::Common::Misc::ExperimentalMode::get() );
588 m_xExperimentalCB->save_state();
589 m_xMacroCB->set_active( officecfg::Office::Common::Misc::MacroRecorderMode::get() );
590 m_xMacroCB->save_state();
591
593}
594
595
597{
598 SetUserData( OUString() );
599}
600
601// class SvxJavaParameterDlg ---------------------------------------------
602
604 : GenericDialogController(pParent, "cui/ui/javastartparametersdialog.ui",
605 "JavaStartParameters")
606 , m_xParameterEdit(m_xBuilder->weld_entry("parameterfield"))
607 , m_xAssignBtn(m_xBuilder->weld_button("assignbtn"))
608 , m_xAssignedList(m_xBuilder->weld_tree_view("assignlist"))
609 , m_xRemoveBtn(m_xBuilder->weld_button("removebtn"))
610 , m_xEditBtn(m_xBuilder->weld_button("editbtn"))
611{
612 m_xAssignedList->set_size_request(m_xAssignedList->get_approximate_digit_width() * 54,
613 m_xAssignedList->get_height_rows(6));
614 m_xParameterEdit->connect_changed( LINK( this, SvxJavaParameterDlg, ModifyHdl_Impl ) );
615 m_xParameterEdit->connect_activate(LINK(this, SvxJavaParameterDlg, ActivateHdl_Impl));
616 m_xAssignBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, AssignHdl_Impl ) );
617 m_xRemoveBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, RemoveHdl_Impl ) );
618 m_xEditBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, EditHdl_Impl ) );
619 m_xAssignedList->connect_changed( LINK( this, SvxJavaParameterDlg, SelectHdl_Impl ) );
620 m_xAssignedList->connect_row_activated( LINK( this, SvxJavaParameterDlg, DblClickHdl_Impl ) );
621
622 ModifyHdl_Impl(*m_xParameterEdit);
625}
626
628{
629}
630
632{
633 OUString sParam = comphelper::string::strip(m_xParameterEdit->get_text(), ' ');
634 m_xAssignBtn->set_sensitive(!sParam.isEmpty());
635}
636
638{
639 OUString sParam = comphelper::string::strip(m_xParameterEdit->get_text(), ' ');
640 if (sParam.isEmpty())
641 return;
642
643 int nPos = m_xAssignedList->find_text(sParam);
644 if (nPos == -1)
645 {
646 m_xAssignedList->append_text(sParam);
647 m_xAssignedList->select(m_xAssignedList->n_children() - 1);
648 }
649 else
650 m_xAssignedList->select(nPos);
651 m_xParameterEdit->set_text(OUString());
652 ModifyHdl_Impl(*m_xParameterEdit);
653 EnableEditButton();
654 EnableRemoveButton();
655}
656
658{
659 if (m_xAssignBtn->get_sensitive())
660 {
661 AssignHdl_Impl(*m_xAssignBtn);
662 return true;
663 }
664 return false;
665}
666
668{
669 EditParameter();
670}
671
673{
674 EnableEditButton();
675 EnableRemoveButton();
676}
677
679{
680 EditParameter();
681 return true;
682}
683
685{
686 int nPos = m_xAssignedList->get_selected_index();
687 if (nPos != -1)
688 {
689 m_xAssignedList->remove(nPos);
690 int nCount = m_xAssignedList->n_children();
691 if (nCount)
692 {
693 if (nPos >= nCount)
694 nPos = nCount - 1;
695 m_xAssignedList->select(nPos);
696 }
697 else
698 {
699 DisableEditButton();
700 }
701 }
702 EnableRemoveButton();
703}
704
706{
707 int nPos = m_xAssignedList->get_selected_index();
708 m_xParameterEdit->set_text(OUString());
709
710 if (nPos == -1)
711 return;
712
713 InputDialog aParamEditDlg(m_xDialog.get(), CuiResId(RID_CUISTR_JAVA_START_PARAM));
714 OUString editableClassPath = m_xAssignedList->get_selected_text();
715 aParamEditDlg.SetEntryText(editableClassPath);
716 aParamEditDlg.HideHelpBtn();
717
718 if (!aParamEditDlg.run())
719 return;
720 OUString editedClassPath = comphelper::string::strip(aParamEditDlg.GetEntryText(), ' ');
721
722 if ( !editedClassPath.isEmpty() && editableClassPath != editedClassPath )
723 {
724 m_xAssignedList->remove(nPos);
725 m_xAssignedList->insert_text(nPos, editedClassPath);
726 m_xAssignedList->select(nPos);
727 }
728}
729
731{
732 m_xParameterEdit->grab_focus();
733 m_xAssignedList->select(-1);
734 return GenericDialogController::run();
735}
736
737std::vector< OUString > SvxJavaParameterDlg::GetParameters() const
738{
739 int nCount = m_xAssignedList->n_children();
740 std::vector< OUString > aParamList;
741 aParamList.reserve(nCount);
742 for (int i = 0; i < nCount; ++i)
743 aParamList.push_back(m_xAssignedList->get_text(i));
744 return aParamList;
745}
746
748{
752}
753
754void SvxJavaParameterDlg::SetParameters( std::vector< OUString > const & rParams )
755{
756 m_xAssignedList->clear();
757 for (auto const & sParam: rParams)
758 {
759 m_xAssignedList->append_text(sParam);
760 }
763}
764
765
766// class SvxJavaClassPathDlg ---------------------------------------------
767
769 : GenericDialogController(pParent, "cui/ui/javaclasspathdialog.ui", "JavaClassPath")
770 , m_xPathList(m_xBuilder->weld_tree_view("paths"))
771 , m_xAddArchiveBtn(m_xBuilder->weld_button("archive"))
772 , m_xAddPathBtn(m_xBuilder->weld_button("folder"))
773 , m_xRemoveBtn(m_xBuilder->weld_button("remove"))
774{
775 m_xPathList->set_size_request(m_xPathList->get_approximate_digit_width() * 54,
776 m_xPathList->get_height_rows(8));
777 m_xAddArchiveBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, AddArchiveHdl_Impl ) );
778 m_xAddPathBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, AddPathHdl_Impl ) );
779 m_xRemoveBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, RemoveHdl_Impl ) );
780 m_xPathList->connect_changed( LINK( this, SvxJavaClassPathDlg, SelectHdl_Impl ) );
781
782 // set initial focus to path list
783 m_xPathList->grab_focus();
784}
785
787{
788}
789
791{
792 sfx2::FileDialogHelper aDlg(TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, m_xDialog.get());
793 aDlg.SetTitle( CuiResId( RID_CUISTR_ARCHIVE_TITLE ) );
794 aDlg.AddFilter( CuiResId( RID_CUISTR_ARCHIVE_HEADLINE ), "*.jar;*.zip" );
796 OUString sFolder;
797 if (m_xPathList->count_selected_rows() > 0)
798 {
799 osl::FileBase::getFileURLFromSystemPath(m_xPathList->get_selected_text(), sFolder);
800 // best effort
801 }
802 if (!sFolder.isEmpty())
803 aDlg.SetDisplayDirectory( sFolder );
804 if ( aDlg.Execute() == ERRCODE_NONE )
805 {
806 OUString sURL = aDlg.GetPath();
807 OUString sFile;
808 if (osl::FileBase::getSystemPathFromFileURL(sURL, sFile) == osl::FileBase::E_None)
809 {
810 INetURLObject aURL( sURL );
811 if ( !IsPathDuplicate( sFile ) )
812 {
813 m_xPathList->append("", sFile, SvFileInformationManager::GetImageId(aURL));
814 m_xPathList->select(m_xPathList->n_children() - 1);
815 }
816 else
817 {
818 OUString sMsg( CuiResId( RID_CUISTR_MULTIFILE_DBL_ERR ) );
819 sMsg = sMsg.replaceFirst( "%1", sFile );
820 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
821 VclMessageType::Warning, VclButtonsType::Ok, sMsg));
822 xBox->run();
823 }
824 }
825 else
826 {
827 OUString sMsg( CuiResId( RID_CUISTR_CANNOTCONVERTURL_ERR ) );
828 sMsg = sMsg.replaceFirst( "%1", sURL );
829 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
830 VclMessageType::Warning, VclButtonsType::Ok, sMsg));
831 xBox->run();
832 }
833 }
834 EnableRemoveButton();
835}
836
838{
839 Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
840 Reference < XFolderPicker2 > xFolderPicker = sfx2::createFolderPicker(xContext, m_xDialog.get());
841
842 OUString sOldFolder;
843 if (m_xPathList->count_selected_rows() > 0)
844 {
845 osl::FileBase::getFileURLFromSystemPath(m_xPathList->get_selected_text(), sOldFolder);
846 // best effort
847 }
848 if (sOldFolder.isEmpty())
849 sOldFolder = SvtPathOptions().GetWorkPath();
850 xFolderPicker->setDisplayDirectory( sOldFolder );
851 if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
852 {
853 OUString sFolderURL( xFolderPicker->getDirectory() );
854 INetURLObject aURL( sFolderURL );
855 OUString sNewFolder;
856 if (osl::FileBase::getSystemPathFromFileURL(sFolderURL, sNewFolder)
857 == osl::FileBase::E_None)
858 {
859 if ( !IsPathDuplicate( sNewFolder ) )
860 {
861 m_xPathList->append("", sNewFolder, SvFileInformationManager::GetImageId(aURL));
862 m_xPathList->select(m_xPathList->n_children() - 1);
863 }
864 else
865 {
866 OUString sMsg( CuiResId( RID_CUISTR_MULTIFILE_DBL_ERR ) );
867 sMsg = sMsg.replaceFirst( "%1", sNewFolder );
868 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
869 VclMessageType::Warning, VclButtonsType::Ok, sMsg));
870 xBox->run();
871 }
872 }
873 else
874 {
875 OUString sMsg( CuiResId( RID_CUISTR_CANNOTCONVERTURL_ERR ) );
876 sMsg = sMsg.replaceFirst( "%1", sFolderURL );
877 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
878 VclMessageType::Warning, VclButtonsType::Ok, sMsg));
879 xBox->run();
880 }
881 }
882 EnableRemoveButton();
883}
884
886{
887 int nPos = m_xPathList->get_selected_index();
888 if (nPos != -1)
889 {
890 m_xPathList->remove(nPos);
891 int nCount = m_xPathList->n_children();
892 if (nCount)
893 {
894 if (nPos >= nCount)
895 nPos = nCount - 1;
896 m_xPathList->select( nPos );
897 }
898 }
899
900 EnableRemoveButton();
901}
902
904{
905 EnableRemoveButton();
906}
907
908bool SvxJavaClassPathDlg::IsPathDuplicate( std::u16string_view _rPath )
909{
910 bool bRet = false;
911 int nCount = m_xPathList->n_children();
912 for (int i = 0; i < nCount; ++i)
913 {
914 if ( m_xPathList->get_text(i) == _rPath )
915 {
916 bRet = true;
917 break;
918 }
919 }
920
921 return bRet;
922}
923
925{
926 OUStringBuffer sPath;
927 int nCount = m_xPathList->n_children();
928 for (int i = 0; i < nCount; ++i)
929 {
930 if (!sPath.isEmpty())
931 sPath.append(CLASSPATH_DELIMITER);
932 sPath.append(m_xPathList->get_text(i));
933 }
934 return sPath.makeStringAndClear();
935}
936
937void SvxJavaClassPathDlg::SetClassPath( const OUString& _rPath )
938{
939 if ( m_sOldPath.isEmpty() )
940 m_sOldPath = _rPath;
941 m_xPathList->clear();
942 if (!_rPath.isEmpty())
943 {
944 sal_Int32 nIdx = 0;
945 do
946 {
947 OUString sToken = _rPath.getToken( 0, CLASSPATH_DELIMITER, nIdx );
948 OUString sURL;
949 osl::FileBase::getFileURLFromSystemPath(sToken, sURL); // best effort
950 INetURLObject aURL( sURL );
952 }
953 while (nIdx>=0);
954 // select first entry
955 m_xPathList->select(0);
956 }
957 SelectHdl_Impl(*m_xPathList);
958}
959
960/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
OUString getFSysPath(FSysStyle eStyle, sal_Unicode *pDelimiter=nullptr) const
virtual void Start(bool bStartTimer=true) override
OUString GetEntryText() const
void SetEntryText(const OUString &rStr)
void HideHelpBtn()
void SetNeedsRestart(svtools::RestartReason eReason)
Definition: treeopt.cxx:1939
SfxOkDialogController * GetDialogController() const
void SetUserData(const OUString &rString)
weld::Window * GetFrameWeld() const
static SVT_DLLPUBLIC OUString GetImageId(const INetURLObject &rURL, bool bBig=false)
const OUString & GetWorkPath() const
OUString m_sOldPath
Definition: optjava.hxx:182
SvxJavaClassPathDlg(weld::Window *pParent)
Definition: optjava.cxx:768
std::unique_ptr< weld::Button > m_xAddArchiveBtn
Definition: optjava.hxx:178
std::unique_ptr< weld::TreeView > m_xPathList
Definition: optjava.hxx:177
bool IsPathDuplicate(std::u16string_view _rPath)
Definition: optjava.cxx:908
OUString GetClassPath() const
Definition: optjava.cxx:924
std::unique_ptr< weld::Button > m_xRemoveBtn
Definition: optjava.hxx:180
virtual ~SvxJavaClassPathDlg() override
Definition: optjava.cxx:786
void SetClassPath(const OUString &_rPath)
Definition: optjava.cxx:937
std::unique_ptr< weld::Button > m_xAddPathBtn
Definition: optjava.hxx:179
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optjava.cxx:469
std::unique_ptr< weld::CheckButton > m_xMacroCB
Definition: optjava.hxx:78
std::unique_ptr< weld::CheckButton > m_xJavaEnableCB
Definition: optjava.hxx:66
OUString m_sAddDialogText
Definition: optjava.hxx:58
std::unique_ptr< weld::Button > m_xExpertConfigBtn
Definition: optjava.hxx:72
void HandleCheckEntry(int nCheckedRow)
Definition: optjava.cxx:366
void RequestRestart(svtools::RestartReason eReason)
Definition: optjava.cxx:457
void UpdateJavaPathText()
Definition: optjava.cxx:376
OUString m_sInstallText
Definition: optjava.hxx:57
std::unique_ptr< SvxJavaClassPathDlg > m_xPathDlg
Definition: optjava.hxx:75
std::unique_ptr< weld::TreeView > m_xJavaList
Definition: optjava.hxx:67
std::unique_ptr< weld::Button > m_xAddBtn
Definition: optjava.hxx:69
void AddFolder(const OUString &_rFolder)
Definition: optjava.cxx:386
std::unique_ptr< SvxJavaParameterDlg > m_xParamDlg
Definition: optjava.hxx:74
rtl::Reference< ::svt::DialogClosedListener > xDialogListener
Definition: optjava.hxx:63
std::unique_ptr< weld::Label > m_xJavaPathText
Definition: optjava.hxx:68
virtual void FillUserData() override
Definition: optjava.cxx:596
std::unique_ptr< weld::Widget > m_xJavaFrame
Definition: optjava.hxx:82
void ClearJavaInfo()
Definition: optjava.cxx:299
std::unique_ptr< weld::CheckButton > m_xExperimentalCB
Definition: optjava.hxx:77
virtual ~SvxJavaOptionsPage() override
Definition: optjava.cxx:126
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > xFolderPicker
Definition: optjava.hxx:64
std::unique_ptr< weld::Button > m_xParameterBtn
Definition: optjava.hxx:70
void AddJRE(JavaInfo const *_pInfo)
Definition: optjava.cxx:348
std::unique_ptr< weld::Label > m_xAddDialogText
Definition: optjava.hxx:80
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: optjava.cxx:464
virtual void Reset(const SfxItemSet *rSet) override
Definition: optjava.cxx:561
SvxJavaOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optjava.cxx:67
std::unique_ptr< weld::Button > m_xClassPathBtn
Definition: optjava.hxx:71
std::vector< std::unique_ptr< JavaInfo > > m_aAddedInfos
Definition: optjava.hxx:61
void EnableRemoveButton()
Definition: optjava.hxx:135
void SetParameters(std::vector< OUString > const &rParams)
Definition: optjava.cxx:754
void EnableEditButton()
Definition: optjava.hxx:140
void DisableRemoveButton()
Definition: optjava.hxx:150
std::vector< OUString > GetParameters() const
Definition: optjava.cxx:737
SvxJavaParameterDlg(weld::Window *pParent)
Definition: optjava.cxx:603
std::unique_ptr< weld::Button > m_xAssignBtn
Definition: optjava.hxx:122
void DisableEditButton()
Definition: optjava.hxx:155
void DisableAssignButton()
Definition: optjava.hxx:145
virtual ~SvxJavaParameterDlg() override
Definition: optjava.cxx:627
std::unique_ptr< weld::Button > m_xEditBtn
Definition: optjava.hxx:125
virtual short run() override
Definition: optjava.cxx:730
std::unique_ptr< weld::Button > m_xRemoveBtn
Definition: optjava.hxx:124
std::unique_ptr< weld::Entry > m_xParameterEdit
Definition: optjava.hxx:121
std::unique_ptr< weld::TreeView > m_xAssignedList
Definition: optjava.hxx:123
void SetInvokeHandler(const Link< Timer *, void > &rLink)
static std::shared_ptr< ConfigurationChanges > create()
OUString GetPath() const
void AddFilter(const OUString &rFilterName, const OUString &rExtension)
void SetDisplayDirectory(const OUString &rPath)
void SetTitle(const OUString &rNewTitle)
void SetContext(Context _eNewContext)
virtual short run()
std::shared_ptr< weld::Dialog > m_xDialog
std::pair< const TreeIter &, int > iter_col
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
int nCount
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
URL aURL
float u
#define ERRCODE_NONE
javaFrameworkError jfw_setSelectedJRE(JavaInfo const *pInfo)
javaFrameworkError jfw_getJavaInfoByPath(OUString const &pPath, std::unique_ptr< JavaInfo > *ppInfo)
void jfw_lock()
javaFrameworkError jfw_setVMParameters(std::vector< OUString > const &arOptions)
javaFrameworkError jfw_addJRELocation(OUString const &sLocation)
javaFrameworkError jfw_setUserClassPath(OUString const &pCp)
javaFrameworkError jfw_getSelectedJRE(std::unique_ptr< JavaInfo > *ppInfo)
javaFrameworkError jfw_getVMParameters(std::vector< OUString > *parOptions)
void jfw_unlock()
bool jfw_areEqualJavaInfo(JavaInfo const *pInfoA, JavaInfo const *pInfoB)
javaFrameworkError jfw_getUserClassPath(OUString *ppCP)
bool jfw_isVMRunning()
javaFrameworkError jfw_setEnabled(bool bEnabled)
javaFrameworkError jfw_findAllJREs(std::vector< std::unique_ptr< JavaInfo > > *pparInfo)
javaFrameworkError jfw_getEnabled(bool *pbEnabled)
TRISTATE_FALSE
TRISTATE_TRUE
#define JFW_REQUIRE_NEEDRESTART
javaFrameworkError
JFW_E_NOT_RECOGNIZED
JFW_E_DIRECT_MODE
JFW_E_INVALID_SETTINGS
JFW_E_NONE
JFW_E_FAILED_VERSION
sal_uInt16 nPos
#define SAL_WARN_IF(condition, area, stream)
@ Exception
OString strip(const OString &rIn, char c)
int i
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
RESTART_REASON_JAVA
RESTART_REASON_ASSIGNING_JAVAPARAMETERS
RESTART_REASON_EXP_FEATURES
RESTART_REASON_ASSIGNING_FOLDERS
#define CLASSPATH_DELIMITER
Definition: optjava.cxx:59
IMPL_LINK(SvxJavaOptionsPage, CheckHdl_Impl, const weld::TreeView::iter_col &, rRowCol, void)
Definition: optjava.cxx:142
IMPL_LINK_NOARG(SvxJavaOptionsPage, EnableHdl_Impl, weld::Toggleable &, void)
Definition: optjava.cxx:136
static SfxItemSet & rSet
OUString sVersion
sal_uInt64 nRequirements
OUString sLocation
OUString sVendor
RET_OK