⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 securitylinkeditors.java

📁 用java 实现的IE browser适合于学者
💻 JAVA
字号:
package com.hnjchina.example.editors;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ControlEditor;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.TableCursor;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import com.hnjchina.securityManager.SecurityObjectCellModifier;
import com.hnjchina.securityManager.SecurityObjectContentProvider;
import com.hnjchina.securityManager.SecurityObjectEditor;
import com.hnjchina.securityManager.SecurityObjectLabelProvider;
import com.hnjchina.securityManager.SecurityObjectSorter;
import com.hnjchina.securityView.Logon;


public class SecurityLinkEditors  extends EditorPart{
    private	Table	tabledetail,tablemaster;
    private TableViewer	tvmaster,tvdetail;
    private SashForm sashForm;
    Logon	logon=new Logon();
    private	int tablestyle = SWT.SINGLE|SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION|SWT.HIDE_SELECTION;
    private	Color ROWCOLOR;
public void doSave(IProgressMonitor monitor) {
    
}

public void doSaveAs() {
    
}
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
}

public boolean isDirty() {
    return false;
}

public boolean isSaveAsAllowed() {
    return false;
}
public void createPartControl(Composite parent) {
    createsash(parent);
//    createTableCursor(parent);
}
public	void	createsash(Composite parent){
    ROWCOLOR=parent.getDisplay().getSystemColor(SWT.COLOR_GREEN);
    parent.setLayout(new GridLayout(1, false));
    Composite buttonBar = new Composite(parent, SWT.NONE);
    buttonBar.setLayout(new RowLayout());
    Button flip = new Button(buttonBar, SWT.PUSH);
    flip.setText("Switch Orientation");
    Button weights = new Button(buttonBar, SWT.PUSH);
    weights.setText("Restore Weights");

    // Create the SashForm
    Composite sash = new Composite(parent, SWT.NONE);
    sash.setLayout(new FillLayout());
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    sashForm = new SashForm(sash, SWT.HORIZONTAL);

    // Change the width of the sashes
    sashForm.SASH_WIDTH =2;

    // Change the color used to paint the sashes
    sashForm.setBackground(parent.getBackground());
    
    // Create the tablemaster and tabledetail  their event handlers
    createtablemaster(parent);
    getAppcationObject();
//    createTableMasterViewer();
    createtabledetail(parent);
    getObjects("hnpfc");
//    createTableDetailViewer();

    
    
    // Set the relative weights for the buttons
    sashForm.setWeights(new int[] { 1, 2});

    // Add the Switch Orientation functionality
    flip.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        switch (sashForm.getOrientation()) {
        case SWT.HORIZONTAL:
          sashForm.setOrientation(SWT.VERTICAL);
          break;
        case SWT.VERTICAL:
          sashForm.setOrientation(SWT.HORIZONTAL);
          break;
        }
      }
    });

    // Add the Restore Weights functionality
    weights.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        sashForm.setWeights(new int[] { 1, 2});
      }
    }); 
}
public	void	createtablemaster(Composite parent){
	tablemaster = new Table(sashForm, tablestyle);
	tablemaster.setHeaderVisible(true);
	tablemaster.setLinesVisible(true);
    tablemaster.addSelectionListener(new SelectionAdapter(){
        public	void widgetSelected(SelectionEvent e){
            getObjects(tablemaster.getItem(tablemaster.getSelectionIndex()).getText());
        }
    }
            );
    TableColumn column = new TableColumn(tablemaster, SWT.LEFT,0);
    column.setText("Application");
    column.setWidth(80);
    column=new TableColumn(tablemaster, SWT.LEFT,1);
    column.setText("Description");
    column.setWidth(150);
    column.addSelectionListener(new SelectionAdapter(){
        public	void widgetSelected(SelectionEvent e){
            tvmaster.setSorter(new SecurityObjectSorter(SecurityObjectSorter.DESCRIPTION));
        }
    });
    tablemaster.addMouseListener(new MouseAdapter() { 
        public void mouseDoubleClick(MouseEvent e) {//鼠标双击事件的方法
            maximizeHelper(tablemaster, sashForm);
        }
    });
}
public	void	createtabledetail(Composite parent){
    tabledetail = new Table(sashForm,tablestyle);
	tabledetail.setHeaderVisible(true);
	tabledetail.setLinesVisible(true);
    TableColumn column = new TableColumn(tabledetail, SWT.LEFT,0);
    column.setText("window");
    column.setWidth(150);
    column = new TableColumn(tabledetail, SWT.LEFT,1);
    column.setText("control");
    column.setWidth(80);
    column = new TableColumn(tabledetail, SWT.LEFT,2);
    column.setText("description");
    column.setWidth(200);
    tabledetail.addMouseListener(new MouseAdapter(){
        public	void	mouseDoubleClick(MouseEvent e){
            maximizeHelper(tabledetail,sashForm);
        }
    });
    createTableCursor(parent);
}

public	void	createTableMasterViewer(){
    tvmaster = new TableViewer(tablemaster);
    tvmaster.setContentProvider(new SecurityObjectContentProvider());
    tvmaster.setLabelProvider(new SecurityObjectLabelProvider());
    
    CellEditor[] editors = new CellEditor[2];
    editors[0] = new TextCellEditor(tablemaster);
    editors[1] = new TextCellEditor(tablemaster); 
    tvmaster.setColumnProperties(SecurityObjectEditor.PROPS);
    tvmaster.setCellModifier(new SecurityObjectCellModifier(tvmaster));	    
    tvmaster.setCellEditors(editors);
//    tv.setInput(getSecurityObject());
}
public	void	createTableDetailViewer(){
    tvdetail = new TableViewer(tabledetail);
    tvdetail.setContentProvider(new SecurityObjectContentProvider());
    tvdetail.setLabelProvider(new SecurityObjectLabelProvider());
    CellEditor[] editors = new CellEditor[2];
    editors[0] = new TextCellEditor(tabledetail);
    editors[1] = new TextCellEditor(tabledetail); 
    tvdetail.setColumnProperties(SecurityObjectEditor.PROPS);
    tvdetail.setCellModifier(new SecurityObjectCellModifier(tvdetail));	    
    tvdetail.setCellEditors(editors);
//    tv.setInput(getSecurityObject());
}
public void setFocus() {
}
private void maximizeHelper(Control control, SashForm sashForm) {
    // See if the control is already maximized
    if (control == sashForm.getMaximizedControl()) {
      // Already maximized; restore it
      sashForm.setMaximizedControl(null);
    } else {
      // Not yet maximized, so maximize it
      sashForm.setMaximizedControl(control);
    }
  }
public	void	getAppcationObject(){
    int			li_idx=0;
    ResultSet	resultset=logon.exesql("select	application,description from	security_apps");
    try {
        while	(resultset.next()){
            li_idx++;
            TableItem item = new TableItem(tablemaster, SWT.NONE);
            item.setText(0,resultset.getString("application"));
            item.setText(1,resultset.getString("description"));
            if	(li_idx%2==0)item.setBackground(ROWCOLOR);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
public	void	getObjects(String appname){
    int			li_idx = 0;
    ResultSet	resultset=logon.exesql("select	a.window,a.control,a.description from	security_objects a,security_apps b where	a.appid=b.appid  and b.application='"+appname+"'");
    tabledetail.removeAll();
    try {
        while	(resultset.next()){
            li_idx++;
            TableItem item = new TableItem(tabledetail, SWT.NONE);
            item.setText(0,resultset.getString("window"));
            item.setText(1,resultset.getString("control"));
            item.setText(2,resultset.getString("description"));
            if	(li_idx%2==0)item.setBackground(ROWCOLOR);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
public	void	createTableCursor(Composite parent){
    final TableCursor cursor = new TableCursor(tabledetail, SWT.NONE);

    // Create the editor
    // Use a ControlEditor, not a TableEditor, because the cursor is the parent
    final ControlEditor editor = new ControlEditor(cursor);
    editor.grabHorizontal = true;
    editor.grabVertical = true;

    // Add the event handling
    cursor.addSelectionListener(new SelectionAdapter() {
      // This is called as the user navigates around the table
      public void widgetSelected(SelectionEvent event) {
         System.out.println("widgetSelected");
        // Select the row in the table where the TableCursor is
        tabledetail.setSelection(new TableItem[] { cursor.getRow()});
      }

      // This is called when the user hits Enter
      public void widgetDefaultSelected(SelectionEvent event) {
          System.out.println("widgetDefaultSelected");
        // Begin an editing session
        // Notice that the parent of the Text is the TableCursor, not the Table
        final Text text = new Text(cursor, SWT.NONE);
        text.setFocus();

        // Copy the text from the cell to the Text
        text.setText(cursor.getRow().getText(cursor.getColumn()));
        text.setFocus();
        // Add a handler to detect key presses
        text.addMouseListener(new MouseAdapter(){
            public	void	mouseDoubleClick(MouseEvent e){
                maximizeHelper(tabledetail,sashForm);
                System.out.println("mouseDoubleClick");
            }
        });
        text.addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent event) {
            // End the editing and save the text if the user presses Enter
            // End the editing and throw away the text if the user presses Esc
            System.out.println("keycode:"+event.keyCode);
            switch (event.keyCode) {
            case SWT.CR:
              cursor.getRow().setText(cursor.getColumn(), text.getText());
            case SWT.ESC:
              text.dispose();
              break;
            }
          }
        });
        editor.setEditor(text);
      }
    });
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -