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