Java tutorial
/* Copyright (C) 2014 NTT DATA Corporation This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package com.clustercontrol.infra.dialog; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.ListViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; import com.clustercontrol.dialog.CommonDialog; import com.clustercontrol.dialog.ValidateResult; import com.clustercontrol.infra.bean.ModuleTypeMessage; import com.clustercontrol.infra.composite.ModuleTypeListComposite; import com.clustercontrol.infra.view.InfraModuleView; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; /** * ?<BR> * * @version 5.0.0 * @since 5.0.0 */ public class ModuleTypeDialog extends CommonDialog { // ----- instance ----- // // ?pack???sizeX?? private static final int sizeX = 300; private static final int sizeY = 300; // ? private ModuleTypeListComposite listComposite = null; // (listComposite?) private ListViewer moduleTypeList = null; private String managerName = null; private String managementId = null; private InfraModuleView view = null; // ----- ----- // /** * ???? * * @param parent * ?? */ public ModuleTypeDialog(Shell parent) { super(parent); } public ModuleTypeDialog(Shell parent, String managerName, String managementId, InfraModuleView view) { super(parent); this.managerName = managerName; this.managementId = managementId; this.view = view; } // ----- instance ----- // @Override protected Point getInitialSize() { return new Point(sizeX, sizeY); } /** * ??? */ @Override protected void customizeDialog(Composite parent) { Shell shell = this.getShell(); // parent.getShell().setText(Messages.getString("infra.module.type")); GridLayout layout = new GridLayout(5, true); parent.setLayout(layout); layout.marginHeight = 0; layout.marginWidth = 0; listComposite = new ModuleTypeListComposite(parent, SWT.NONE); WidgetTestUtil.setTestId(this, null, listComposite); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = 5; listComposite.setLayoutData(gridData); moduleTypeList = listComposite.getMonitorTypeList(); moduleTypeList.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return (String) element; } }); for (String moduleType : ModuleTypeMessage.getAllStrings()) { moduleTypeList.add(moduleType); } // ????????????? moduleTypeList.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { okPressed(); } }); //?pack:resize to be its preferred size shell.pack(); shell.setSize(new Point(shell.getSize().x, shell.getSize().y)); } /** * ???(?)?? * @return */ public String getSelectItem() { return this.listComposite.getSelectItem(); } /** * OK ? */ @Override protected String getOkButtonText() { return Messages.getString("next"); } /** * OK <BR> * ?????????? */ @Override protected void okPressed() { // ??null? if (this.getSelectItem() == null) { ValidateResult result = null; result = new ValidateResult(); result.setValid(false); result.setID(Messages.getString("message.hinemos.1")); result.setMessage(Messages.getString("message.infra.specify.item", new Object[] { Messages.getString("infra.module.type") })); displayError(result); } CommonDialog dialog = null; if (getSelectItem().equals(ModuleTypeMessage.STRING_COMMAND)) { dialog = new CommandModuleDialog(getShell(), this.managerName, this.managementId); } else if (getSelectItem().equals(ModuleTypeMessage.STRING_FILETRANSFER)) { dialog = new FileTransferModuleDialog(getShell(), this.managerName, this.managementId); } else { throw new InternalError("dialog is null."); } dialog.open(); view.update(this.managerName, this.managementId); // ?????? // super.okPressed(); } @Override protected void cancelPressed() { super.cancelPressed(); } /** * ? */ @Override protected String getCancelButtonText() { return Messages.getString("cancel"); } }