]>
git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/wizards/ConfirmOverwriteWizard.java
3ec3530c72fdbf6f6d13239cae9d2280e4878a67
1 package org
.argeo
.slc
.client
.ui
.wizards
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.slc
.SlcException
;
7 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
8 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
9 import org
.eclipse
.jface
.wizard
.Wizard
;
10 import org
.eclipse
.jface
.wizard
.WizardPage
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.events
.ModifyEvent
;
13 import org
.eclipse
.swt
.events
.ModifyListener
;
14 import org
.eclipse
.swt
.events
.SelectionAdapter
;
15 import org
.eclipse
.swt
.events
.SelectionEvent
;
16 import org
.eclipse
.swt
.layout
.GridData
;
17 import org
.eclipse
.swt
.layout
.GridLayout
;
18 import org
.eclipse
.swt
.widgets
.Button
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.swt
.widgets
.Label
;
22 import org
.eclipse
.swt
.widgets
.Text
;
23 import org
.eclipse
.ui
.ISharedImages
;
25 public class ConfirmOverwriteWizard
extends Wizard
{
27 // Define widget here to simplify getters
28 private Button overwriteBtn
, renameBtn
;
29 private Text newNameTxt
;
30 private Label newNameLbl
;
33 private String sourceNodeName
;
34 private Node targetParentNode
;
36 private String newName
;
37 private boolean overwrite
;
39 public ConfirmOverwriteWizard(String sourceNodeName
, Node targetParentNode
) {
40 setWindowTitle("Confirm overwrite or define a new name");
41 this.sourceNodeName
= sourceNodeName
;
42 this.targetParentNode
= targetParentNode
;
46 public void addPages() {
48 addPage(new MyPage());
49 } catch (Exception e
) {
50 throw new SlcException("Cannot add page to wizard ", e
);
53 ClientUiPlugin
.getDefault().getWorkbench().getSharedImages()
54 .getImageDescriptor(ISharedImages
.IMG_LCL_LINKTO_HELP
)
58 // Expose info to the calling view
59 public boolean overwrite() {
63 public String
newName() {
68 public boolean performFinish() {
69 boolean doFinish
= false;
72 if (overwriteBtn
.getSelection())
73 doFinish
= MessageDialog
.openConfirm(Display
.getDefault()
74 .getActiveShell(), "CAUTION", "All data contained in ["
76 + "] are about to be definitively destroyed. \n "
77 + "Are you sure you want to proceed ?");
83 overwrite
= overwriteBtn
.getSelection();
84 newName
= newNameTxt
.getText();
89 class MyPage
extends WizardPage
implements ModifyListener
{
93 setTitle("An object with same name (" + sourceNodeName
94 + ") already exists");
97 public void createControl(Composite parent
) {
98 Composite composite
= new Composite(parent
, SWT
.NONE
);
99 composite
.setLayout(new GridLayout(2, false));
101 // choose between overwrite and rename
102 overwriteBtn
= new Button(composite
, SWT
.RADIO
);
103 overwriteBtn
.setText("Overwrite");
104 GridData gd
= new GridData();
105 gd
.horizontalIndent
= 30;
106 gd
.horizontalSpan
= 2;
107 overwriteBtn
.setLayoutData(gd
);
108 overwriteBtn
.setSelection(true);
110 renameBtn
= new Button(composite
, SWT
.RADIO
);
111 renameBtn
.setText("Rename");
112 renameBtn
.setSelection(false);
113 renameBtn
.setText("Rename");
115 gd
.horizontalIndent
= 30;
116 gd
.horizontalSpan
= 2;
117 renameBtn
.setLayoutData(gd
);
119 newNameLbl
= new Label(composite
, SWT
.LEAD
);
120 newNameLbl
.setText("New name");
121 newNameLbl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false,
123 newNameLbl
.setEnabled(false);
125 newNameTxt
= new Text(composite
, SWT
.LEAD
| SWT
.BORDER
);
126 newNameTxt
.setText(sourceNodeName
);
127 newNameTxt
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
129 if (newNameTxt
!= null)
130 newNameTxt
.addModifyListener(this);
131 newNameTxt
.setEnabled(false);
133 SelectionAdapter sa
= new SelectionAdapter() {
134 public void widgetSelected(SelectionEvent e
) {
135 updateSelection(overwriteBtn
.getSelection());
138 overwriteBtn
.addSelectionListener(sa
);
139 renameBtn
.addSelectionListener(sa
);
142 setControl(composite
);
145 private void updateSelection(boolean overwrite
) {
146 newNameLbl
.setEnabled(!overwrite
);
147 newNameTxt
.setEnabled(!overwrite
);
149 setPageComplete(true);
154 protected String
getTechName() {
155 return newNameTxt
.getText();
158 public void modifyText(ModifyEvent event
) {
162 private void checkComplete() {
165 String newName
= newNameTxt
.getText();
166 if (newName
== null || "".equals(newName
.trim())) {
167 setMessage("Name cannot be blank or empty",
169 setPageComplete(false);
170 } else if (targetParentNode
.hasNode(newName
)) {
171 setMessage("An object with the same name already exists.",
173 setPageComplete(false);
175 setMessage("Complete", WizardPage
.INFORMATION
);
176 setPageComplete(true);
178 } catch (RepositoryException e
) {
179 throw new SlcException("Unexpected error while checking "
180 + "children node with same name", e
);