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 CMWAdvViewKF extends CMWContextAwarePage {
049:
050: private Button viewButton;
051: private Text text_2;
052: private Text text_1;
053: private Text text;
054:
055: protected CMWAdvViewKF(String pageName) {
056: super (pageName);
057: setTitle(I18N.getString(Messages.CMW_ADVANCED_VIEW_KF_TITLE));
058: setDescription(I18N
059: .getString(Messages.CMW_ADVANCED_VIEW_KF_DESCRIPTION));
060: }
061:
062: public void createControl(Composite parent) {
063: Composite shell = new Composite(parent, SWT.NONE);
064: final GridLayout gridLayout = new GridLayout();
065: gridLayout.numColumns = 3;
066: shell.setLayout(gridLayout);
067:
068: final Label keystoreFileLabel = new Label(shell, SWT.NONE);
069: keystoreFileLabel.setLayoutData(new GridData(SWT.FILL,
070: SWT.CENTER, false, false));
071: keystoreFileLabel.setText(I18N
072: .getString(Messages.CMW_ADVANCED_LABEL_KEYSTORE));
073:
074: text = new Text(shell, SWT.READ_ONLY | SWT.BORDER);
075: text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
076: false));
077:
078: final Button browseButton = new Button(shell, SWT.NONE);
079: browseButton.addSelectionListener(new SelectionAdapter() {
080: public void widgetSelected(final SelectionEvent e) {
081: projectKeysBrowse(text);
082: }
083: });
084: browseButton.setText(I18N
085: .getString(Messages.CMW_ADVANCED_LABEL_BROWSE));
086:
087: final Label passwordLabel = new Label(shell, SWT.NONE);
088: passwordLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
089: false, false));
090: passwordLabel
091: .setText(I18N
092: .getString(Messages.CMW_ADVANCED_LABEL_PASSWORD_KEY_STORE));
093:
094: text_1 = new Text(shell, SWT.PASSWORD | SWT.BORDER);
095: text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
096: false, 2, 1));
097:
098: text_2 = new Text(shell, SWT.V_SCROLL | SWT.MULTI
099: | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
100: text_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,
101: true, 3, 1));
102:
103: final Label label = new Label(shell, SWT.SEPARATOR
104: | SWT.HORIZONTAL);
105: label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
106: false, 3, 1));
107:
108: viewButton = new Button(shell, SWT.NONE);
109: viewButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
110: false, false));
111: viewButton.addSelectionListener(new SelectionAdapter() {
112: public void widgetSelected(final SelectionEvent e) {
113: performAction();
114: }
115: });
116: viewButton.setText(I18N
117: .getString(Messages.CMW_ADVANCED_LABEL_VIEW_BUTTON));
118: new Label(shell, SWT.NONE);
119: new Label(shell, SWT.NONE);
120: //
121: setControl(shell);
122: // some Listeners
123: ModifyListener mody = new ModifyListener() {
124: public void modifyText(ModifyEvent e) {
125: updatePageComplete();
126: }
127: };
128:
129: text.addModifyListener(mody);
130: text_1.addModifyListener(mody);
131: //
132: updatePageComplete();
133: }
134:
135: @Override
136: public IWizardPage getNextPage() {
137: CertificateManagerWizard parent = (CertificateManagerWizard) getWizard();
138: return parent.getNextPage(this );
139: }
140:
141: @Override
142: public IWizardPage getPreviousPage() {
143: CertificateManagerWizard parent = (CertificateManagerWizard) getWizard();
144: return parent.getPreviousPage(this );
145: }
146:
147: @Override
148: protected void updatePageComplete() {
149: setPageComplete(verify());
150: if (viewButton != null)
151: viewButton.setEnabled(verify());
152: }
153:
154: private boolean verify() {
155: if (text == null)
156: return false;
157: if (text.getText().equals("")) {
158: showError(I18N
159: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_SELECT_KEY_FILE));
160: return false;
161: } else if (text_1.getText().equals("")) {
162: showError(I18N
163: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_PASSWORD_MISSING));
164: return false;
165: } else if (text_1.getText().length() < 6) {
166: showError(I18N
167: .getString(Messages.CMW_ADVANCED_MESSAGE_ERROR_PASSWORD_SHORT));
168: return false;
169: }
170:
171: showClean();
172: return true;
173: }
174:
175: /**
176: * executes action if Finish is pressed
177: */
178: public boolean performFinish() {
179: //return performAction();
180: return false;
181: }
182:
183: /**
184: * Executes the certificate deletion
185: * @return
186: */
187: protected boolean performAction() {
188: //String filePath= getPro_path()+"/"+text.getText().substring(text.getText().indexOf("::")+2);
189: String filePath = "";
190: try {
191: filePath = EsbPathHelper.getFullPathForDef(MacroUtil
192: .resolveBuiltinMacro(text.getText(), this
193: .getCurr_pro_name()));
194: } catch (Exception e1) {
195: setPageComplete(false);
196: showError(I18N
197: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_EXCEPTION));
198: e1.printStackTrace();
199: currentExceptionMessage = e1.getMessage();
200: }
201: File file = new File(filePath);
202: showWarning(I18N
203: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_PRGRESS));
204: try {
205: text_2.setText(AuthenticationUtil.keyFileToString(file,
206: text_1.getText()));
207: showInfo(I18N
208: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_SUCCES));
209: } catch (Exception e) {
210: setPageComplete(false);
211: showError(I18N
212: .getString(Messages.CMW_ADVANCED_MESSAGE_OPERATION_EXCEPTION));
213: e.printStackTrace();
214: currentExceptionMessage = e.getMessage();
215: return false;
216: }
217: return true;
218: }
219:
220: @Override
221: public boolean canFinish() {
222: //if ( getWizard().getNextPage(this)==null && verify()) return true;
223: return false;
224: }
225: }
|