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