📄 passwordentryaction.java
字号:
/* * Copyright 2006 Marcel Schoffelmeer * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.s10r.manager.actions;import org.eclipse.jface.viewers.ISelection;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.ui.ISelectionListener;import org.eclipse.ui.IWorkbenchPart;import org.eclipse.ui.IWorkbenchWindow;import com.s10r.manager.model.PasswordEntry;/** * Helper class for password entry specific actions. This class registers itself * as a selection listener to keep track of the selected password entry and to * enable/disable the action (only single selections of password entries are * allowed). * * @author mms * */public abstract class PasswordEntryAction extends ManagerAction implements ISelectionListener{ private PasswordEntry selectedPasswordEntry; public PasswordEntryAction() { super(); } public PasswordEntryAction(IWorkbenchWindow window) { super(window); window.getSelectionService().addSelectionListener(this); } /** * If 1 password entry is selected, this method calls passwordEntrySelected, * passing in the selected entry. In all other cases noPasswordEntrySelected * is called. * * @param part * @param selection */ public void selectionChanged(IWorkbenchPart part, ISelection selection) { this.selection = selection; boolean entrySelected = false; if (selection instanceof IStructuredSelection) { if (((IStructuredSelection) selection).size() == 1) { Object element = ((IStructuredSelection) selection) .getFirstElement(); if (element instanceof PasswordEntry) { passwordEntrySelected((PasswordEntry) element); entrySelected = true; } } } if (!entrySelected) { noPasswordEntrySelected(); } } /** * Disables the action. */ private void noPasswordEntrySelected() { this.setEnabled(false); selectedPasswordEntry = null; } /** * Enables the action, sets the selectedPasswordEntry for use by subclasses. */ private void passwordEntrySelected(PasswordEntry entry) { this.setEnabled(true); selectedPasswordEntry = entry; } protected PasswordEntry getSelectedPasswordEntry() { return selectedPasswordEntry; } /** * Removes itself as a selection listener from the selection service. */ public void dispose() { window.getSelectionService().removeSelectionListener(this); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -