001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024:
025: package com.bostechcorp.cbesb.ui.ide.security;
026:
027: import java.io.File;
028:
029: import org.eclipse.jface.wizard.IWizardPage;
030: import org.eclipse.swt.SWT;
031: import org.eclipse.swt.events.ModifyEvent;
032: import org.eclipse.swt.events.ModifyListener;
033: import org.eclipse.swt.events.SelectionAdapter;
034: import org.eclipse.swt.events.SelectionEvent;
035: import org.eclipse.swt.layout.GridData;
036: import org.eclipse.swt.layout.GridLayout;
037: import org.eclipse.swt.widgets.Button;
038: import org.eclipse.swt.widgets.Composite;
039: import org.eclipse.swt.widgets.Label;
040: import org.eclipse.swt.widgets.Text;
041:
042: import com.bostechcorp.cbesb.common.i18n.I18N;
043: import com.bostechcorp.cbesb.common.i18n.Messages;
044: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
045: import com.bostechcorp.cbesb.common.util.macro.MacroUtil;
046: import com.bostechcorp.cbesb.ui.util.AuthenticationUtil;
047:
048: public class CMWAdvViewTF extends CMWContextAwarePage {
049:
050: private Button viewButton;
051: private Text text_2;
052: private Text text_1;
053: private Text text;
054:
055: protected CMWAdvViewTF(String pageName) {
056: super (pageName);
057: setTitle(I18N.getString(Messages.CMW_ADVANCED_VIEW_TF_TITLE));
058: setDescription(I18N
059: .getString(Messages.CMW_ADVANCED_VIEW_TF_DESCRIPTION));
060:
061: }
062:
063: public void createControl(Composite parent) {
064: Composite shell = new Composite(parent, SWT.NONE);
065: final GridLayout gridLayout = new GridLayout();
066: gridLayout.numColumns = 3;
067: shell.setLayout(gridLayout);
068:
069: final Label keystoreFileLabel = new Label(shell, SWT.NONE);
070: keystoreFileLabel.setLayoutData(new GridData(SWT.FILL,
071: SWT.CENTER, false, false));
072: keystoreFileLabel.setText(I18N
073: .getString(Messages.CMW_ADVANCED_LABEL_TRUSTSTORE));
074:
075: text = new Text(shell, SWT.READ_ONLY | SWT.BORDER);
076: text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
077: false));
078:
079: final Button browseButton = new Button(shell, SWT.NONE);
080: browseButton.addSelectionListener(new SelectionAdapter() {
081: public void widgetSelected(final SelectionEvent e) {
082: projectCersBrowse(text);
083: }
084: });
085: browseButton.setText(I18N
086: .getString(Messages.CMW_ADVANCED_LABEL_BROWSE));
087:
088: final Label passwordLabel = new Label(shell, SWT.NONE);
089: passwordLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
090: false, false));
091: passwordLabel
092: .setText(I18N
093: .getString(Messages.CMW_ADVANCED_LABEL_PASSWORD_TRUST_STORE));
094:
095: text_1 = new Text(shell, SWT.PASSWORD | SWT.BORDER);
096: text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
097: false, 2, 1));
098:
099: text_2 = new Text(shell, SWT.V_SCROLL | SWT.MULTI
100: | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
101: text_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,
102: true, 3, 1));
103:
104: final Label label = new Label(shell, SWT.SEPARATOR
105: | SWT.HORIZONTAL);
106: label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
107: false, 3, 1));
108:
109: viewButton = new Button(shell, SWT.NONE);
110: viewButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
111: false, false));
112: viewButton.addSelectionListener(new SelectionAdapter() {
113: public void widgetSelected(final SelectionEvent e) {
114: performAction();
115: }
116: });
117: viewButton.setText(I18N
118: .getString(Messages.CMW_ADVANCED_LABEL_VIEW_BUTTON));
119: new Label(shell, SWT.NONE);
120: new Label(shell, SWT.NONE);
121: //
122: setControl(shell);
123: // some Listeners
124: ModifyListener mody = new ModifyListener() {
125: public void modifyText(ModifyEvent e) {
126: updatePageComplete();
127: }
128: };
129:
130: text.addModifyListener(mody);
131: text_1.addModifyListener(mody);
132: //
133: updatePageComplete();
134: }
135:
136: @Override
137: public IWizardPage getNextPage() {
138: CertificateManagerWizard parent = (CertificateManagerWizard) getWizard();
139: return parent.getNextPage(this );
140: }
141:
142: @Override
143: public IWizardPage getPreviousPage() {
144: CertificateManagerWizard parent = (CertificateManagerWizard) getWizard();
145: return parent.getPreviousPage(this );
146: }
147:
148: @Override
149: protected void updatePageComplete() {
150: setPageComplete(verify());
151: if (viewButton != null)
152: viewButton.setEnabled(verify());
153: }
154:
155: private boolean verify() {
156: if (text == null)
157: return false;
158: if (text.getText().equals("")) {
159: showError(I18N
160: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_SELECT_TRUST_FILE));
161: return false;
162: } else if (text_1.getText().equals("")) {
163: showError(I18N
164: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_PASSWORD_MISSING));
165: return false;
166: } else if (text_1.getText().length() < 6) {
167: showError(I18N
168: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_PASSWORD_SHORT));
169: return false;
170: }
171:
172: showClean();
173: return true;
174: }
175:
176: /**
177: * executes action if Finish is pressed
178: */
179: public boolean performFinish() {
180: //return performAction();
181: return false;
182: }
183:
184: /**
185: * Executes the certificate deletion
186: * @return
187: */
188: protected boolean performAction() {
189: //String filePath=getPro_path()+"/"+text.getText().substring(text.getText().indexOf("::")+2);
190: //File file= new File(filePath);
191: String filePath = "";
192: try {
193: filePath = EsbPathHelper.getFullPathForDef(MacroUtil
194: .resolveBuiltinMacro(text.getText(), this
195: .getCurr_pro_name()));
196: } catch (Exception e1) {
197: setPageComplete(false);
198: showError(I18N
199: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_EXCEPTION));
200: e1.printStackTrace();
201: currentExceptionMessage = e1.getMessage();
202: }
203: File file = new File(filePath);
204:
205: showWarning(I18N
206: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_PRGRESS));
207: try {
208: text_2.setText(AuthenticationUtil.trustStoreFileToString(
209: file, text_1.getText()));
210: showInfo(I18N
211: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_SUCCES));
212: } catch (Exception e) {
213: setPageComplete(false);
214: showError(I18N
215: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_EXCEPTION));
216: e.printStackTrace();
217: currentExceptionMessage = e.getMessage();
218: return false;
219: }
220: return true;
221: }
222:
223: @Override
224: public boolean canFinish() {
225: //if ( getWizard().getNextPage(this)==null && verify()) return true;
226: return false;
227: }
228:
229: }
|