exceptiondetailsection.java
来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 369 行
JAVA
369 行
/*
* $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/exception/ExceptionDetailSection.java,v 1.1.1.1 2004/07/01 09:07:45 wang_j Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/07/01 09:07:45 $
*
* ====================================================================
*
* The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
*
* Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
* IT Forest Corporation
* All rights reserved.
*
* This software is the confidential and proprietary information of
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
* You shall not disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into with
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
*/
package com.webpump.ui.exception;
import org.eclipse.jface.viewers.*;
import org.eclipse.pde.core.*;
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
import org.eclipse.pde.internal.ui.parts.TreePart;
import com.webpump.ui.exception.data.*;
import com.webpump.ui.perspective.MacroResource;
import com.webpump.ui.perspective.WebpumpIDEPlugin;
import com.webpump.ui.base.data.*;
import com.webpump.ui.base.gui.*;
/**
* Class for the tree part of the exception editor.
*
* @author zhao_f
* @version 2.0.0 2004-2-13
*/
public class ExceptionDetailSection
extends BaseTreeSection{
/**
* Class for providing the content of the tree part
*/
class TreeContentProvider
extends DefaultContentProvider
implements ITreeContentProvider {
/**
* Get the Children of the node
* @param parent the node who owns the children
*/
public Object[] getChildren(Object parent) {
Object[] children = null;
if ((parent instanceof BaseObject)
&&(!(parent instanceof ExceptionInfo))
&&(!(parent instanceof ExceptionName))
) {
return ((BaseDataObject)parent).getChild();
}
if (children == null)
children = new Object[0];
return children;
}
/**
* Identify whether the node has children
*/
public boolean hasChildren(Object parent) {
return getChildren(parent).length > 0;
}
/**
* Get the parent of the node
* @param child the node who has a parent
*/
public Object getParent(Object child) {
if (child instanceof BaseObject)
return ((BaseObject) child).getParent();
return null;
}
/**
* Get all the children of the node in the form of Object group
* @param parent the node who owns children
*/
public Object[] getElements(Object parent) {
return getChildren(parent);
}
}
/**
* the constructor which define the content of this part
* @param page the page in which the part lies
*/
public ExceptionDetailSection(BasePage page) {
//Define the layout of the part using the super class's constructor
super(page, new String[] {"<<",null,">>"});
//Set the head text of this part
this.setHeaderText(WebpumpIDEPlugin.getResourceString(MacroResource.EXCEPTIONDETAILSECTION_EXCEPTION_DEFINITION));
handleDefaultButton = false;
}
/**
* Initialize the layout of this part
* @param input the input in "exception.xml"
*/
public void initialize(Object input) {
ExceptionModel model = (ExceptionModel) input;
//Initialize this part by inputting the model's ExceptionConfig in it
exceptionTree.setInput(((ExceptionList)(model.getDataObject())).getExceptionConfig());
boolean editable = model.isEditable();
setReadOnly(!editable);
TreePart treePart = getTreePart();
treePart.setButtonEnabled(0, editable);
treePart.setButtonEnabled(2, false);
treePart.setButtonEnabled(3, false);
model.addModelChangedListener(this);
}
/**
* Dispose this part
*/
public void dispose() {
//Get the model on this part
ExceptionModel model = (ExceptionModel) getFormPage().getModel();
//Remove the Model Changed Listener on this model
model.removeModelChangedListener(this);
super.dispose();
}
public void modelChanged(IModelChangedEvent event) {
if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
ExceptionModel model = (ExceptionModel) getFormPage().getModel();
exceptionTree.setInput(((ExceptionList)(model.getDataObject())).getExceptionConfig());
exceptionTree.refresh();
return;
}
//Get the changed object
Object changeObject = event.getChangedObjects()[0];
//Define the action to the tableViewer if the changed object is an instance of ExceptionName
if (changeObject instanceof ExceptionName
&& event.getChangeType() == IModelChangedEvent.CHANGE) {
IStructuredSelection sel =
(IStructuredSelection) exceptionTree.getSelection();
BaseObject extension =
(BaseObject) sel.getFirstElement();
exceptionTree.refresh();
exceptionTree.setSelection(new StructuredSelection(extension));
return;
}
//Define the action to the tableViewer if the changed object is an instance of ExceptionList
if (!(changeObject instanceof ExceptionList)) {
BaseObject pobj = (BaseObject) changeObject;
BaseObject parent = pobj.getParent();
////Add a new element in the tableViewer if the changed type is insert
if (event.getChangeType() == IModelChangedEvent.INSERT) {
exceptionTree.add(parent, pobj);
}
//Delete an element from the table viewer if the changed type is remove
else if (event.getChangeType() == IModelChangedEvent.REMOVE) {
exceptionTree.remove(pobj);
}
}
}
/**
* Define what to do when selecting one of the botton
* @param index a param which indicates the botton which has been selected
*/
protected void buttonSelected(int index) {
if (index == 0)
handleAdd();
if (index == 2)
handleRemove();
}
/**
* Define the action when having selected the "add" botton
*/
private void handleAdd() {
//Get the selected item on the treeViewer
IStructuredSelection sel =
(IStructuredSelection) exceptionTree.getSelection();
BaseObject object = (BaseObject) sel.getFirstElement();
BaseObject objControl;
//If the selected item is an instance of ExceptionName, get its parent
if (object instanceof ExceptionName)
{
objControl = object.getParent() ;
}
//If the selected item is an instance of ActionList, get its first child
if (object instanceof ActionList)
{
objControl = (BaseObject)object.getChild()[0];
}
//If the selected belongs to none of the above, get itself
else
{
objControl = object;
}
//If the item got above is an instance of GlobalExceptions, add it in the model
if (objControl instanceof GlobalExceptions)
{
ExceptionAllSection objExceptionAllSection = ((ExceptionForm)(getFormPage().getForm())).getExceptionAllSection();
String strSelectName = objExceptionAllSection.getSelectName();
ExceptionName objExceptionName = new ExceptionName();
((GlobalExceptions)objControl).addException(objExceptionName);
objExceptionName.setExceptionName(strSelectName);
}
//If the item got above is an instance of ActionException, add it in the model
if (objControl instanceof ActionException)
{
ExceptionAllSection objExceptionAllSection = ((ExceptionForm)(getFormPage().getForm())).getExceptionAllSection();
String strSelectName = objExceptionAllSection.getSelectName();
ExceptionName objExceptionName = new ExceptionName();
((ActionException)objControl).addException(objExceptionName);
objExceptionName.setExceptionName(strSelectName);
}
}
/**
* Define the action when having selected the "remove" botton
*/
private void handleRemove() {
//Get the selected item on the treeViewer
IStructuredSelection sel =
(IStructuredSelection) exceptionTree.getSelection();
BaseObject object = (BaseObject) sel.getFirstElement();
BaseObject objControl = null;
//If the selected item is an instance of ExceptionInfo, get its parent
if (object instanceof ExceptionName)
{
objControl = object.getParent() ;
}
//Remove the item from the exception model as a child of GlobalExceptions
if (objControl instanceof GlobalExceptions)
{
((GlobalExceptions)objControl).remove((ExceptionName)object);
}
//Remove the item from the exception model as a child of ActionException
if (objControl instanceof ActionException)
{
((ActionException)objControl).remove((ExceptionName)object);
}
}
/**
* Define the action to the treeViewer after the selection is changed
* @param selection the selected item
*/
protected void selectionChanged(IStructuredSelection selection) {
Object item = selection.getFirstElement();
fireSelectionNotification(item);
getFormPage().setSelection(selection);
setButtonStyle(item);
}
/**
* Set the botton style according to the selection
* @param item the selected item
*/
public void setButtonStyle(Object item) {
if (isReadOnly())
return;
boolean addEnabled = false;
boolean removeEnabled = false;
if (item != null) {
if (item instanceof GlobalExceptions) {
addEnabled = true;
removeEnabled = false;
} else if (item instanceof ActionList) {
addEnabled = false;
removeEnabled = false;
}
else if (item instanceof ActionException) {
addEnabled = true;
removeEnabled = false;
}
else if (item instanceof ExceptionName) {
addEnabled = false;
removeEnabled = true;
}
}
//Get an object of ExceptionAllSection
ExceptionAllSection objExceptionAllSection = ((ExceptionForm)(getFormPage().getForm())).getExceptionAllSection();
//Get the Selected item from the table part
String strSelectName = objExceptionAllSection.getSelectName();
if (strSelectName==null)
{
addEnabled = false;
}
if(addEnabled == true)
{
Object[] strChild = null;
if (item instanceof GlobalExceptions) {
strChild = ((GlobalExceptions)item).getChild();
}
if (item instanceof ActionException) {
strChild = ((ActionException)item).getChild();
}
if (strChild!=null&&strChild.length>0 )
{
for (int i=0;i<strChild.length;i++)
{
if (strSelectName.equals(((ExceptionName)strChild[i]).toString()))
{
addEnabled = false;
break;
}
}
}
}
//Register the botton style to each botton
getTreePart().setButtonEnabled(0, addEnabled);
getTreePart().setButtonEnabled(2, removeEnabled);
}
/**
* Set the botton style
*/
public void setButtonStyle() {
//Get the selected item from the tree viewer
IStructuredSelection sel =
(IStructuredSelection) exceptionTree.getSelection();
Object item = sel.getFirstElement();
//Set the botton style on the selection
setButtonStyle(item);
}
/**
* Initialize the images
*/
private void initializeImages() {
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?