001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.tool.service.eclipse.ui;
021:
022: import org.apache.axis2.tool.service.bean.LibrarySelectionBean;
023: import org.apache.axis2.tool.service.eclipse.plugin.ServiceArchiver;
024: import org.eclipse.swt.SWT;
025: import org.eclipse.swt.events.ModifyEvent;
026: import org.eclipse.swt.events.ModifyListener;
027: import org.eclipse.swt.events.MouseAdapter;
028: import org.eclipse.swt.events.MouseEvent;
029: import org.eclipse.swt.layout.GridData;
030: import org.eclipse.swt.layout.GridLayout;
031: import org.eclipse.swt.widgets.Button;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.FileDialog;
034: import org.eclipse.swt.widgets.Label;
035: import org.eclipse.swt.widgets.List;
036: import org.eclipse.swt.widgets.Text;
037:
038: public class LibraryAddingPage extends AbstractServiceWizardPage {
039:
040: private Label libraryNameLabel;
041: private Text libraryNameText;
042: private Button browseButton;
043: private Button addButton;
044: private Button removeButton;
045: private List jarFileList;
046: private Label jarFilecountLabel;
047:
048: /**
049: *
050: */
051: public LibraryAddingPage() {
052: super ("page6");
053:
054: }
055:
056: /* (non-Javadoc)
057: * @see org.apache.axis2.tool.service.eclipse.ui.AbstractServiceWizardPage#initializeDefaultSettings()
058: */
059: protected void initializeDefaultSettings() {
060: settings.put(PREF_LIB_LIBNAMES, new String[] {});//put an empty array
061:
062: }
063:
064: /* (non-Javadoc)
065: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
066: */
067: public void createControl(Composite parent) {
068: Composite container = new Composite(parent, SWT.NULL);
069: GridLayout layout = new GridLayout();
070: layout.numColumns = 3;
071: container.setLayout(layout);
072:
073: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
074: gd.horizontalSpan = 3;
075: libraryNameText = new Text(container, SWT.BORDER);
076: libraryNameText.setLayoutData(gd);
077:
078: libraryNameText.addModifyListener(new ModifyListener() {
079: public void modifyText(ModifyEvent e) {
080: //handleModify();
081: }
082: });
083:
084: gd = new GridData(GridData.FILL_HORIZONTAL);
085: browseButton = new Button(container, SWT.PUSH);
086: browseButton.setLayoutData(gd);
087: browseButton.setText(ServiceArchiver
088: .getResourceString("general.browse"));
089: browseButton.addMouseListener(new MouseAdapter() {
090: public void mouseUp(MouseEvent e) {
091: handleBrowse();
092: }
093: });
094:
095: gd = new GridData(GridData.FILL_HORIZONTAL);
096: addButton = new Button(container, SWT.PUSH);
097: addButton.setLayoutData(gd);
098: addButton.setText(ServiceArchiver
099: .getResourceString("page6.add"));
100: addButton.addMouseListener(new MouseAdapter() {
101: public void mouseUp(MouseEvent e) {
102: handleAdd();
103: }
104:
105: });
106:
107: gd = new GridData(GridData.FILL_HORIZONTAL);
108: removeButton = new Button(container, SWT.PUSH);
109: removeButton.setLayoutData(gd);
110: removeButton.setText(ServiceArchiver
111: .getResourceString("page6.remove"));
112: removeButton.addMouseListener(new MouseAdapter() {
113: public void mouseUp(MouseEvent e) {
114: handleRemove();
115: }
116:
117: });
118:
119: gd = new GridData(GridData.FILL_HORIZONTAL);
120: gd.horizontalSpan = 3;
121: Label dummyLabel = new Label(container, SWT.NONE);
122: dummyLabel.setText(ServiceArchiver
123: .getResourceString("page6.liblist.caption"));
124: dummyLabel.setLayoutData(gd);
125:
126: gd = new GridData(GridData.FILL_BOTH);
127: gd.horizontalSpan = 3;
128: gd.verticalSpan = 5;
129:
130: jarFileList = new List(container, SWT.BORDER | SWT.V_SCROLL);
131: jarFileList.setItems(settings.getArray(PREF_LIB_LIBNAMES));
132: jarFileList.setLayoutData(gd);
133:
134: // Label for the count
135: gd = new GridData(GridData.FILL_HORIZONTAL);
136: gd.horizontalSpan = 3;
137: jarFilecountLabel = new Label(container, SWT.NONE);
138: jarFilecountLabel.setLayoutData(gd);
139:
140: setControl(container);
141: setPageComplete(true);
142: }
143:
144: private void handleBrowse() {
145: FileDialog fileDialog = new FileDialog(this .getShell());
146: fileDialog.setFilterExtensions(new String[] { "*.jar" });
147: String returnFileName = fileDialog.open();
148: if (returnFileName != null) {
149: this .libraryNameText.setText(returnFileName);
150: }
151: }
152:
153: private void handleAdd() {
154: String libName = libraryNameText.getText().trim();
155: if (!libName.equals("")) {
156: //add the libs to the list
157: jarFileList.add(libName);
158: updateList();
159: libraryNameText.setText("");
160: }
161: }
162:
163: private void handleRemove() {
164: int selectedIndex = jarFileList.getSelectionIndex();
165: //-1 is returned when nothing is selected
166: if (selectedIndex != -1) {
167: jarFileList.remove(selectedIndex);
168: updateList();
169: }
170: }
171:
172: private void updateList() {
173: jarFilecountLabel
174: .setText(jarFileList.getItemCount()
175: + " "
176: + ServiceArchiver
177: .getResourceString("page6.liblist.count.caption"));
178: settings.put(PREF_LIB_LIBNAMES, jarFileList.getItems());
179: }
180:
181: public LibrarySelectionBean getBean() {
182: LibrarySelectionBean bean = new LibrarySelectionBean();
183: bean.setFileList(jarFileList.getItems());
184: return bean;
185: }
186:
187: protected boolean getWizardComplete() {
188: return false;
189: }
190:
191: }
|