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 #include <svtools/miscopt.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>
42 #include <unotools/pathoptions.hxx>
43 #include <svtools/imagemgr.hxx>
45 #include <sfx2/filedlghelper.hxx>
46 #include <sfx2/inputdlg.hxx>
47 #include <tools/diagnose_ex.h>
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 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
54 #include <com/sun/star/ucb/XContentProvider.hpp>
55 #if HAVE_FEATURE_JAVA
56 #include <jvmfwk/framework.hxx>
57 #endif
58 
59 // define ----------------------------------------------------------------
60 
61 #define CLASSPATH_DELIMITER SAL_PATHSEPARATOR
62 
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::ucb;
65 using namespace ::com::sun::star::ui::dialogs;
66 using namespace ::com::sun::star::uno;
67 
68 // class SvxJavaOptionsPage ----------------------------------------------
70  : SfxTabPage(pPage, pController, "cui/ui/optadvancedpage.ui", "OptAdvancedPage", &rSet)
71  , m_aResetIdle("cui options SvxJavaOptionsPage Reset")
72  , xDialogListener(new ::svt::DialogClosedListener())
73  , m_xJavaEnableCB(m_xBuilder->weld_check_button("javaenabled"))
74  , m_xJavaList(m_xBuilder->weld_tree_view("javas"))
75  , m_xJavaPathText(m_xBuilder->weld_label("javapath"))
76  , m_xAddBtn(m_xBuilder->weld_button("add"))
77  , m_xParameterBtn(m_xBuilder->weld_button("parameters"))
78  , m_xClassPathBtn(m_xBuilder->weld_button("classpath"))
79  , m_xExpertConfigBtn(m_xBuilder->weld_button("expertconfig"))
80  , m_xExperimentalCB(m_xBuilder->weld_check_button("experimental"))
81  , m_xMacroCB(m_xBuilder->weld_check_button("macrorecording"))
82  , m_xAddDialogText(m_xBuilder->weld_label("selectruntime"))
83  , m_xJavaFrame(m_xBuilder->weld_widget("javaframe"))
84 {
85  m_sInstallText = m_xJavaPathText->get_label();
86  m_sAddDialogText = m_xAddDialogText->get_label();
87 
88  m_xJavaList->set_size_request(m_xJavaList->get_approximate_digit_width() * 30,
89  m_xJavaList->get_height_rows(8));
90 
91  m_xJavaList->enable_toggle_buttons(weld::ColumnToggleType::Radio);
92  m_xJavaList->connect_toggled( LINK( this, SvxJavaOptionsPage, CheckHdl_Impl ) );
93  m_xJavaList->connect_changed( LINK( this, SvxJavaOptionsPage, SelectHdl_Impl ) );
94 
95  std::vector<int> aWidths;
96  aWidths.push_back(m_xJavaList->get_checkbox_column_width());
97  aWidths.push_back(m_xJavaList->get_pixel_size("Sun Microsystems Inc.").Width());
98  m_xJavaList->set_column_fixed_widths(aWidths);
99 
100  m_xJavaEnableCB->connect_clicked( 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 {
128  ClearJavaInfo();
129 #if HAVE_FEATURE_JAVA
130  m_aAddedInfos.clear();
131 
132  jfw_unlock();
133 #endif
134 }
135 
137 {
138  bool bEnable = m_xJavaEnableCB->get_active();
139  m_xJavaList->set_sensitive(bEnable);
140 }
141 
142 IMPL_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  {
157  xFolderPicker = FolderPicker::create(xContext);
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.get() );
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 
253 IMPL_LINK_NOARG(SvxJavaOptionsPage, ResetHdl_Impl, Timer *, void)
254 {
255  LoadJREs();
256 }
257 
258 
259 IMPL_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.get() );
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 
275 IMPL_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 
285 IMPL_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  {
336  HandleCheckEntry(i);
338  break;
339  }
340  ++i;
341  }
342 #else
343  (void) this;
344 #endif
345 }
346 
347 
348 void SvxJavaOptionsPage::AddJRE( JavaInfo const * _pInfo )
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 
386 void 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 
427  HandleCheckEntry(nPos);
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_SVXSTR_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_SVXSTR_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 {
459  OfaTreeOptionsDialog* pParentDlg(static_cast<OfaTreeOptionsDialog*>(GetDialogController()));
460  if (pParentDlg)
461  pParentDlg->SetNeedsRestart(eReason);
462 }
463 
464 std::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  SvtMiscOptions aMiscOpt;
476  aMiscOpt.SetExperimentalMode( m_xExperimentalCB->get_active() );
477  bModified = true;
479  }
480 
481  if ( m_xMacroCB->get_state_changed_from_saved() )
482  {
483  SvtMiscOptions aMiscOpt;
484  aMiscOpt.SetMacroRecorderMode(m_xMacroCB->get_active());
485  bModified = true;
486  }
487 
488 #if HAVE_FEATURE_JAVA
490  if (m_xParamDlg)
491  {
492  eErr = jfw_setVMParameters(m_xParamDlg->GetParameters());
493  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters");
494  bModified = true;
495  }
496 
497  if (m_xPathDlg)
498  {
499  OUString sPath(m_xPathDlg->GetClassPath());
500  if (m_xPathDlg->GetOldPath() != sPath)
501  {
502  eErr = jfw_setUserClassPath( sPath );
503  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setUserClassPath");
504  bModified = true;
505  }
506  }
507 
508  sal_uInt32 nCount = m_xJavaList->n_children();
509  for (sal_uInt32 i = 0; i < nCount; ++i)
510  {
511  if (m_xJavaList->get_toggle(i) == TRISTATE_TRUE)
512  {
513  JavaInfo const * pInfo;
514  if ( i < m_parJavaInfo.size() )
515  pInfo = m_parJavaInfo[i].get();
516  else
517  pInfo = m_aAddedInfos[ i - m_parJavaInfo.size() ].get();
518 
519  std::unique_ptr<JavaInfo> pSelectedJava;
520  eErr = jfw_getSelectedJRE( &pSelectedJava );
521  if ( JFW_E_NONE == eErr || JFW_E_INVALID_SETTINGS == eErr )
522  {
523  if (!pSelectedJava || !jfw_areEqualJavaInfo( pInfo, pSelectedJava.get() ) )
524  {
525  if ( jfw_isVMRunning() ||
527  {
529  }
530 
531  eErr = jfw_setSelectedJRE( pInfo );
532  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE");
533  bModified = true;
534  }
535  }
536  break;
537  }
538  }
539 
540  bool bEnabled = false;
541  eErr = jfw_getEnabled( &bEnabled );
542  DBG_ASSERT( JFW_E_NONE == eErr,
543  "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
544  if ( bEnabled != m_xJavaEnableCB->get_active() )
545  {
546  eErr = jfw_setEnabled( m_xJavaEnableCB->get_active() );
547  DBG_ASSERT( JFW_E_NONE == eErr,
548  "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
549  bModified = true;
550  }
551 #endif
552 
553  return bModified;
554 }
555 
556 
557 void SvxJavaOptionsPage::Reset( const SfxItemSet* /*rSet*/ )
558 {
559  ClearJavaInfo();
560  m_xJavaList->clear();
561 
562  SvtMiscOptions aMiscOpt;
563 
564 #if HAVE_FEATURE_JAVA
565  bool bEnabled = false;
566  javaFrameworkError eErr = jfw_getEnabled( &bEnabled );
567  if ( eErr != JFW_E_NONE )
568  bEnabled = false;
569  m_xJavaEnableCB->set_active(bEnabled);
570  EnableHdl_Impl(*m_xJavaEnableCB);
571 #else
572  m_xJavaEnableCB->set_active(false);
573  m_xJavaEnableCB->set_sensitive(false);
574 #endif
575 
576  m_xExperimentalCB->set_active( aMiscOpt.IsExperimentalMode() );
577  m_xExperimentalCB->save_state();
578  m_xMacroCB->set_active(aMiscOpt.IsMacroRecorderMode());
579  m_xMacroCB->save_state();
580 
582 }
583 
584 
586 {
587  SetUserData( OUString() );
588 }
589 
590 // class SvxJavaParameterDlg ---------------------------------------------
591 
593  : GenericDialogController(pParent, "cui/ui/javastartparametersdialog.ui",
594  "JavaStartParameters")
595  , m_xParameterEdit(m_xBuilder->weld_entry("parameterfield"))
596  , m_xAssignBtn(m_xBuilder->weld_button("assignbtn"))
597  , m_xAssignedList(m_xBuilder->weld_tree_view("assignlist"))
598  , m_xRemoveBtn(m_xBuilder->weld_button("removebtn"))
599  , m_xEditBtn(m_xBuilder->weld_button("editbtn"))
600 {
601  m_xAssignedList->set_size_request(m_xAssignedList->get_approximate_digit_width() * 54,
602  m_xAssignedList->get_height_rows(6));
603  m_xParameterEdit->connect_changed( LINK( this, SvxJavaParameterDlg, ModifyHdl_Impl ) );
604  m_xAssignBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, AssignHdl_Impl ) );
605  m_xRemoveBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, RemoveHdl_Impl ) );
606  m_xEditBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, EditHdl_Impl ) );
607  m_xAssignedList->connect_changed( LINK( this, SvxJavaParameterDlg, SelectHdl_Impl ) );
608  m_xAssignedList->connect_row_activated( LINK( this, SvxJavaParameterDlg, DblClickHdl_Impl ) );
609 
610  ModifyHdl_Impl(*m_xParameterEdit);
613 }
614 
616 {
617 }
618 
620 {
621  OUString sParam = comphelper::string::strip(m_xParameterEdit->get_text(), ' ');
622  m_xAssignBtn->set_sensitive(!sParam.isEmpty());
623 }
624 
626 {
627  OUString sParam = comphelper::string::strip(m_xParameterEdit->get_text(), ' ');
628  if (sParam.isEmpty())
629  return;
630 
631  int nPos = m_xAssignedList->find_text(sParam);
632  if (nPos == -1)
633  {
634  m_xAssignedList->append_text(sParam);
635  m_xAssignedList->select(m_xAssignedList->n_children() - 1);
636  }
637  else
638  m_xAssignedList->select(nPos);
639  m_xParameterEdit->set_text(OUString());
640  ModifyHdl_Impl(*m_xParameterEdit);
641  EnableEditButton();
642  EnableRemoveButton();
643 }
644 
646 {
647  EditParameter();
648 }
649 
651 {
652  EnableEditButton();
653  EnableRemoveButton();
654 }
655 
657 {
658  EditParameter();
659  return true;
660 }
661 
663 {
664  int nPos = m_xAssignedList->get_selected_index();
665  if (nPos != -1)
666  {
667  m_xAssignedList->remove(nPos);
668  int nCount = m_xAssignedList->n_children();
669  if (nCount)
670  {
671  if (nPos >= nCount)
672  nPos = nCount - 1;
673  m_xAssignedList->select(nPos);
674  }
675  else
676  {
677  DisableEditButton();
678  }
679  }
680  EnableRemoveButton();
681 }
682 
684 {
685  int nPos = m_xAssignedList->get_selected_index();
686  m_xParameterEdit->set_text(OUString());
687 
688  if (nPos == -1)
689  return;
690 
691  InputDialog aParamEditDlg(m_xDialog.get(), CuiResId(RID_SVXSTR_JAVA_START_PARAM));
692  OUString editableClassPath = m_xAssignedList->get_selected_text();
693  aParamEditDlg.SetEntryText(editableClassPath);
694  aParamEditDlg.HideHelpBtn();
695 
696  if (!aParamEditDlg.run())
697  return;
698  OUString editedClassPath = comphelper::string::strip(aParamEditDlg.GetEntryText(), ' ');
699 
700  if ( !editedClassPath.isEmpty() && editableClassPath != editedClassPath )
701  {
702  m_xAssignedList->remove(nPos);
703  m_xAssignedList->insert_text(nPos, editedClassPath);
704  m_xAssignedList->select(nPos);
705  }
706 }
707 
709 {
710  m_xParameterEdit->grab_focus();
711  m_xAssignedList->select(-1);
712  return GenericDialogController::run();
713 }
714 
715 std::vector< OUString > SvxJavaParameterDlg::GetParameters() const
716 {
717  int nCount = m_xAssignedList->n_children();
718  std::vector< OUString > aParamList;
719  aParamList.reserve(nCount);
720  for (int i = 0; i < nCount; ++i)
721  aParamList.push_back(m_xAssignedList->get_text(i));
722  return aParamList;
723 }
724 
726 {
730 }
731 
732 void SvxJavaParameterDlg::SetParameters( std::vector< OUString > const & rParams )
733 {
734  m_xAssignedList->clear();
735  for (auto const & sParam: rParams)
736  {
737  m_xAssignedList->append_text(sParam);
738  }
741 }
742 
743 
744 // class SvxJavaClassPathDlg ---------------------------------------------
745 
747  : GenericDialogController(pParent, "cui/ui/javaclasspathdialog.ui", "JavaClassPath")
748  , m_xPathList(m_xBuilder->weld_tree_view("paths"))
749  , m_xAddArchiveBtn(m_xBuilder->weld_button("archive"))
750  , m_xAddPathBtn(m_xBuilder->weld_button("folder"))
751  , m_xRemoveBtn(m_xBuilder->weld_button("remove"))
752 {
753  m_xPathList->set_size_request(m_xPathList->get_approximate_digit_width() * 54,
754  m_xPathList->get_height_rows(8));
755  m_xAddArchiveBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, AddArchiveHdl_Impl ) );
756  m_xAddPathBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, AddPathHdl_Impl ) );
757  m_xRemoveBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, RemoveHdl_Impl ) );
758  m_xPathList->connect_changed( LINK( this, SvxJavaClassPathDlg, SelectHdl_Impl ) );
759 
760  // set initial focus to path list
761  m_xPathList->grab_focus();
762 }
763 
765 {
766 }
767 
769 {
770  sfx2::FileDialogHelper aDlg(TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, m_xDialog.get());
771  aDlg.SetTitle( CuiResId( RID_SVXSTR_ARCHIVE_TITLE ) );
772  aDlg.AddFilter( CuiResId( RID_SVXSTR_ARCHIVE_HEADLINE ), "*.jar;*.zip" );
773  OUString sFolder;
774  if (m_xPathList->count_selected_rows() > 0)
775  {
776  osl::FileBase::getFileURLFromSystemPath(m_xPathList->get_selected_text(), sFolder);
777  // best effort
778  }
779  if (sFolder.isEmpty())
780  sFolder = SvtPathOptions().GetWorkPath();
781  aDlg.SetDisplayDirectory( sFolder );
782  if ( aDlg.Execute() == ERRCODE_NONE )
783  {
784  OUString sURL = aDlg.GetPath();
785  OUString sFile;
786  if (osl::FileBase::getSystemPathFromFileURL(sURL, sFile) == osl::FileBase::E_None)
787  {
788  INetURLObject aURL( sURL );
789  if ( !IsPathDuplicate( sFile ) )
790  {
791  m_xPathList->append("", sFile, SvFileInformationManager::GetImageId(aURL));
792  m_xPathList->select(m_xPathList->n_children() - 1);
793  }
794  else
795  {
796  OUString sMsg( CuiResId( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
797  sMsg = sMsg.replaceFirst( "%1", sFile );
798  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
799  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
800  xBox->run();
801  }
802  }
803  else
804  {
805  OUString sMsg( CuiResId( RID_SVXSTR_CANNOTCONVERTURL_ERR ) );
806  sMsg = sMsg.replaceFirst( "%1", sURL );
807  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
808  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
809  xBox->run();
810  }
811  }
812  EnableRemoveButton();
813 }
814 
816 {
818  Reference < XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);
819 
820  OUString sOldFolder;
821  if (m_xPathList->count_selected_rows() > 0)
822  {
823  osl::FileBase::getFileURLFromSystemPath(m_xPathList->get_selected_text(), sOldFolder);
824  // best effort
825  }
826  if (sOldFolder.isEmpty())
827  sOldFolder = SvtPathOptions().GetWorkPath();
828  xFolderPicker->setDisplayDirectory( sOldFolder );
829  if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
830  {
831  OUString sFolderURL( xFolderPicker->getDirectory() );
832  INetURLObject aURL( sFolderURL );
833  OUString sNewFolder;
834  if (osl::FileBase::getSystemPathFromFileURL(sFolderURL, sNewFolder)
835  == osl::FileBase::E_None)
836  {
837  if ( !IsPathDuplicate( sNewFolder ) )
838  {
839  m_xPathList->append("", sNewFolder, SvFileInformationManager::GetImageId(aURL));
840  m_xPathList->select(m_xPathList->n_children() - 1);
841  }
842  else
843  {
844  OUString sMsg( CuiResId( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
845  sMsg = sMsg.replaceFirst( "%1", sNewFolder );
846  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
847  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
848  xBox->run();
849  }
850  }
851  else
852  {
853  OUString sMsg( CuiResId( RID_SVXSTR_CANNOTCONVERTURL_ERR ) );
854  sMsg = sMsg.replaceFirst( "%1", sFolderURL );
855  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
856  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
857  xBox->run();
858  }
859  }
860  EnableRemoveButton();
861 }
862 
864 {
865  int nPos = m_xPathList->get_selected_index();
866  if (nPos != -1)
867  {
868  m_xPathList->remove(nPos);
869  int nCount = m_xPathList->n_children();
870  if (nCount)
871  {
872  if (nPos >= nCount)
873  nPos = nCount - 1;
874  m_xPathList->select( nPos );
875  }
876  }
877 
878  EnableRemoveButton();
879 }
880 
882 {
883  EnableRemoveButton();
884 }
885 
886 bool SvxJavaClassPathDlg::IsPathDuplicate( const OUString& _rPath )
887 {
888  bool bRet = false;
889  int nCount = m_xPathList->n_children();
890  for (int i = 0; i < nCount; ++i)
891  {
892  if ( m_xPathList->get_text(i) == _rPath )
893  {
894  bRet = true;
895  break;
896  }
897  }
898 
899  return bRet;
900 }
901 
903 {
904  OUStringBuffer sPath;
905  int nCount = m_xPathList->n_children();
906  for (int i = 0; i < nCount; ++i)
907  {
908  if (!sPath.isEmpty())
909  sPath.append(CLASSPATH_DELIMITER);
910  sPath.append(m_xPathList->get_text(i));
911  }
912  return sPath.makeStringAndClear();
913 }
914 
915 void SvxJavaClassPathDlg::SetClassPath( const OUString& _rPath )
916 {
917  if ( m_sOldPath.isEmpty() )
918  m_sOldPath = _rPath;
919  m_xPathList->clear();
920  if (!_rPath.isEmpty())
921  {
922  sal_Int32 nIdx = 0;
923  do
924  {
925  OUString sToken = _rPath.getToken( 0, CLASSPATH_DELIMITER, nIdx );
926  OUString sURL;
927  osl::FileBase::getFileURLFromSystemPath(sToken, sURL); // best effort
928  INetURLObject aURL( sURL );
929  m_xPathList->append("", sToken, SvFileInformationManager::GetImageId(aURL));
930  }
931  while (nIdx>=0);
932  // select first entry
933  m_xPathList->select(0);
934  }
935  SelectHdl_Impl(*m_xPathList);
936 }
937 
938 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsExperimentalMode() const
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:366
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
OUString m_sInstallText
Definition: optjava.hxx:57
std::unique_ptr< weld::Button > m_xRemoveBtn
Definition: optjava.hxx:124
#define CLASSPATH_DELIMITER
Definition: optjava.cxx:61
OUString GetClassPath() const
Definition: optjava.cxx:902
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:746
JFW_E_NOT_RECOGNIZED
#define JFW_REQUIRE_NEEDRESTART
bool IsMacroRecorderMode() const
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:386
IMPL_LINK(SvxJavaOptionsPage, CheckHdl_Impl, const weld::TreeView::iter_col &, rRowCol, void)
Definition: optjava.cxx:142
javaFrameworkError jfw_setUserClassPath(OUString const &pCp)
std::unique_ptr< weld::Button > m_xExpertConfigBtn
Definition: optjava.hxx:72
TRISTATE_TRUE
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:457
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:69
int nCount
virtual void Start() override
std::unique_ptr< weld::TreeView > m_xPathList
Definition: optjava.hxx:176
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optjava.cxx:469
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)
bool IsPathDuplicate(const OUString &_rPath)
Definition: optjava.cxx:886
void SetExperimentalMode(bool bSet)
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:915
#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:592
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:615
void SetParameters(std::vector< OUString > const &rParams)
Definition: optjava.cxx:732
javaFrameworkError jfw_setSelectedJRE(JavaInfo const *pInfo)
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
void SetTitle(const OUString &rNewTitle)
void UpdateJavaPathText()
Definition: optjava.cxx:376
std::unique_ptr< weld::Label > m_xAddDialogText
Definition: optjava.hxx:80
void SetMacroRecorderMode(bool bSet)
void EnableRemoveButton()
Definition: optjava.hxx:134
const OUString & GetWorkPath() const
void jfw_lock()
RESTART_REASON_ASSIGNING_FOLDERS
virtual ~SvxJavaOptionsPage() override
Definition: optjava.cxx:126
weld::Window * GetFrameWeld() const
std::unique_ptr< weld::Button > m_xAddArchiveBtn
Definition: optjava.hxx:177
void SetNeedsRestart(svtools::RestartReason eReason)
Definition: treeopt.cxx:1919
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
OUString sVendor
virtual void Reset(const SfxItemSet *rSet) override
Definition: optjava.cxx:557
virtual void FillUserData() override
Definition: optjava.cxx:585
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:464
std::vector< OUString > GetParameters() const
Definition: optjava.cxx:715
void DisableRemoveButton()
Definition: optjava.hxx:149
RET_OK
OString strip(const OString &rIn, char c)
RESTART_REASON_JAVA
virtual ~SvxJavaClassPathDlg() override
Definition: optjava.cxx:764
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:708
std::vector< std::unique_ptr< JavaInfo > > m_aAddedInfos
Definition: optjava.hxx:61
void AddJRE(JavaInfo const *_pInfo)
Definition: optjava.cxx:348
void ClearJavaInfo()
Definition: optjava.cxx:299
javaFrameworkError
JFW_E_NONE
IMPL_LINK_NOARG(SvxJavaOptionsPage, EnableHdl_Impl, weld::Button &, void)
Definition: optjava.cxx:136
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