Java tutorial
/* Copyright (C) 2006 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.view; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import com.clustercontrol.composite.FacilityTreeComposite; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; import com.clustercontrol.ws.repository.FacilityTreeItem; /** * ??????????????<BR> * <p> * * ???createContents???????? <br> * ???????doSelectTreeItem????? ????? * * @version 1.0.0 * @since 1.0.0 */ public abstract class ScopeListBaseView extends AutoUpdateView { private static Log m_log = LogFactory.getLog(ScopeListBaseView.class); // ----- instance ----- // /** */ private SashForm treeSash = null; /** ?? */ private FacilityTreeComposite scopeTreeComposite = null; /** ?? */ private Composite baseComposite = null; /** ? */ private Composite listComposite = null; /** ? */ private Label pathLabel = null; /** ???? */ private boolean scopeOnly = false; /** ????**/ private boolean unregistered = true; /** ????**/ private boolean internal = true; /** ???????? **/ private boolean topicRefresh = true; /** ????????? */ private int sashPer = 30; // ----- ----- // /** * ????? */ public ScopeListBaseView() { super(); this.scopeOnly = false; this.unregistered = true; this.internal = true; this.topicRefresh = true; } /** * ????? * * @param scopeOnly ????????? * @param unregistered UNREGISTERED??????? * @param internal INTERNAL??????? * @param topicRefresh ??????????? */ public ScopeListBaseView(boolean scopeOnly, boolean unregistered, boolean internal, boolean topicRefresh) { super(); this.scopeOnly = scopeOnly; this.unregistered = unregistered; this.internal = internal; this.topicRefresh = topicRefresh; } // ----- instance ----- // /** * ???? * * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ @Override public void createPartControl(Composite parent) { m_log.trace("createPartControl"); super.createPartControl(parent); // GridLayout layout = new GridLayout(1, true); parent.setLayout(layout); layout.marginHeight = 0; layout.marginWidth = 0; // ??? this.treeSash = new SashForm(parent, SWT.HORIZONTAL); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = 1; this.treeSash.setLayoutData(gridData); // ? this.scopeTreeComposite = new FacilityTreeComposite(treeSash, SWT.NONE, null, this.scopeOnly, this.unregistered, this.internal, this.topicRefresh, false); // ??? this.baseComposite = new Composite(this.treeSash, SWT.NONE); WidgetTestUtil.setTestId(this, null, baseComposite); // ? this.pathLabel = new Label(this.baseComposite, SWT.NONE); WidgetTestUtil.setTestId(this, "path", pathLabel); this.pathLabel.setText(Messages.getString("scope") + " : "); // this.pathLabel.pack(); // ? this.listComposite = this.createListContents(this.baseComposite); // Sash? 30% ?70% treeSash.setWeights(new int[] { sashPer, 100 - sashPer }); // ?? this.scopeTreeComposite.getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { // ??(?????????) StructuredSelection selection = (StructuredSelection) event.getSelection(); FacilityTreeItem selectItem = (FacilityTreeItem) selection.getFirstElement(); if (selectItem != null) { // ? baseComposite.layout(true, true); // ?? doSelectTreeItem(selectItem); } } }); } /** * Sash?????????? * ???? * @param per */ protected void setSash(int per) { sashPer = per; } /** * ???? * <p> * * ?????????? * * @param parent * ?? */ protected abstract Composite createListContents(Composite parent); /** * ??????????? * <p> * * ?????????????? * * @param item * */ protected void doSelectTreeItem(FacilityTreeItem item) { } /** * ????????? * * ????????????????? * @param item */ protected void doSelectTreeItems(FacilityTreeItem[] item) { } /** * ??????? * * @return */ public SashForm getTreeSash() { return this.treeSash; } /** * ????? * * @return ?? */ public FacilityTreeComposite getScopeTreeComposite() { return this.scopeTreeComposite; } /** * ????? * * @return ?? */ public Composite getBaseComposite() { return this.baseComposite; } /** * ???? * * @return ? */ public Composite getListComposite() { return this.listComposite; } /** * ???? * * @return ? */ public void setPathLabel(String str) { if (str != null) { pathLabel.setText(str); pathLabel.pack(); } } /** * ??? */ public void show() { this.treeSash.setMaximizedControl(null); } /** * ??? */ public void hide() { this.treeSash.setMaximizedControl(this.baseComposite); } }