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