List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:com.clustercontrol.infra.composite.action.InfraManagementSelectionChangedListener.java
License:Open Source License
/** * ??????<BR>//from ww w . j av a 2 s . c o m * [?]??????????? * []??? * <P> * <ol> * <li>????????ID?ID????</li> * <li>ID?ID[?]??????</li> * <li>[]???</li> * </ol> * * @param event ? * * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */ @Override public void selectionChanged(SelectionChangedEvent event) { //[?]?? IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); //?? StructuredSelection selection = (StructuredSelection) event.getSelection(); //[?]? IViewPart viewPart = page.findView(InfraManagementView.ID); //? if (viewPart != null && selection != null) { InfraManagementView view = (InfraManagementView) viewPart.getAdapter(InfraManagementView.class); if (view == null) { m_log.info("selection changed: infra management view is null"); } else { //[?]???/??? view.setEnabledAction(selection.size(), selection); } } //[]? viewPart = page.findView(InfraModuleView.ID); if (viewPart != null && selection != null) { InfraModuleView view = (InfraModuleView) viewPart.getAdapter(InfraModuleView.class); if (view == null) { m_log.info("execute: infra module view is null"); return; } if (selection.size() == 1) { ArrayList<?> info = (ArrayList<?>) selection.getFirstElement(); // view.update((String) info.get(GetInfraManagementTableDefine.MANAGER_NAME), (String) info.get(GetInfraManagementTableDefine.MANAGEMENT_ID)); } else { //?? view.update(null, null); } view.setEnabledAction(); } }
From source file:com.clustercontrol.infra.composite.FileReplaceSettingComposite.java
License:Open Source License
/** * ????//from www . j ava2 s . co m */ private void initialize() { // ???? GridData gridData = null; GridLayout layout = new GridLayout(1, true); layout.marginHeight = 0; layout.marginWidth = 0; layout.numColumns = 12; this.setLayout(layout); Table table = new Table(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE); gridData = new GridData(); gridData.horizontalSpan = 12; gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; gridData.heightHint = 100; table.setHeaderVisible(true); table.setLinesVisible(true); table.setLayoutData(gridData); // Label label = new Label(this, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = 6; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; label.setLayoutData(gridData); m_createCondition = new Button(this, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; m_createCondition.setText(Messages.getString("add")); m_createCondition.setLayoutData(gridData); m_createCondition.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e) { ReplaceTextDialog dialog = new ReplaceTextDialog(m_shell); if (dialog.open() == IDialogConstants.OK_ID) { List<?> info = dialog.getInputData(); List<Object> list = (ArrayList<Object>) m_viewer.getInput(); if (list == null) { list = new ArrayList<Object>(); } list.add(info); m_viewer.setInput(list); } } }); //? m_modifyCondition = new Button(this, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; WidgetTestUtil.setTestId(this, "modifycondition", m_modifyCondition); m_modifyCondition.setText(Messages.getString("modify")); m_modifyCondition.setLayoutData(gridData); m_modifyCondition.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e) { StructuredSelection selection = (StructuredSelection) m_viewer.getSelection(); if (selection != null && selection.size() > 0) { m_selectItem = (List<Object>) selection.getFirstElement(); } else { m_selectItem = null; } if (m_selectItem != null) { ReplaceTextDialog dialog = new ReplaceTextDialog(m_shell, m_selectItem); if (dialog.open() == IDialogConstants.OK_ID) { List<?> info = dialog.getInputData(); List<Object> list = (ArrayList<Object>) m_viewer.getInput(); list.remove(m_selectItem); list.add(info); m_selectItem = null; m_viewer.setInput(list); } } else { } } }); //? m_deleteCondition = new Button(this, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; m_deleteCondition.setText(Messages.getString("delete")); m_deleteCondition.setLayoutData(gridData); m_deleteCondition.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e) { StructuredSelection selection = (StructuredSelection) m_viewer.getSelection(); if (selection != null && selection.size() > 0) { m_selectItem = (List<Object>) selection.getFirstElement(); } else { m_selectItem = null; } if (m_selectItem != null) { List<Object> list = (ArrayList<Object>) m_viewer.getInput(); boolean b = list.remove(m_selectItem); m_log.debug("remove " + b); m_selectItem = null; m_viewer.setInput(list); } else { m_log.debug("m_selectItem is null."); } } }); m_viewer = new CommonTableViewer(table); m_viewer.createTableColumn(GetInfraFileReplaceSettingTableDefine.get(), GetInfraFileReplaceSettingTableDefine.SORT_COLUMN_INDEX, GetInfraFileReplaceSettingTableDefine.SORT_ORDER); }
From source file:com.clustercontrol.infra.composite.ModuleTypeListComposite.java
License:Open Source License
/** * ?????// w ww. ja v a2 s. c o m */ private void createContents() { // ?? GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; this.setLayout(layout); // ?? this.moduleTypeList = new ListViewer(this, SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.BORDER); GridData gdata = new GridData(GridData.FILL_BOTH); this.moduleTypeList.getList().setLayoutData(gdata); // ?????? this.moduleTypeList.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); selectItem = (String) selection.getFirstElement(); } }); }
From source file:com.clustercontrol.infra.view.action.CheckInfraModuleAction.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; }//from w w w . j a v a 2 s .c o m // ??? this.viewPart = HandlerUtil.getActivePart(event); if (!(viewPart instanceof InfraModuleView)) { return null; } InfraModuleView infraModuleView = null; try { infraModuleView = (InfraModuleView) viewPart.getAdapter(InfraModuleView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (infraModuleView == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = null; if (infraModuleView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) infraModuleView.getComposite().getTableViewer().getSelection(); } InfraManagementInfo management = null; String managerName = infraModuleView.getComposite().getManagerName(); try { InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName); management = wrapper.getInfraManagement(infraModuleView.getComposite().getManagementId()); } catch (InvalidRole_Exception e) { // ??? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.accesscontrol.16")); return null; } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) { m_log.error("execute() : " + e.getClass().getName() + ", " + e.getMessage()); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.module.check"), Messages.getString("failed"), HinemosMessage.replace(e.getMessage()) })); return null; } if (selection == null || management == null) { return null; } String moduleId = (String) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraModuleTableDefine.MODULE_ID); boolean allRun = false; RunDialog dialog = new RunDialog(null, Messages.getString("message.infra.confirm.action", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.module.check"), moduleId })); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } allRun = dialog.isAllRun(); List<AccessInfo> accessInfoList = AccessUtil.getAccessInfoList(viewPart.getSite().getShell(), management.getFacilityId(), management.getOwnerRoleId(), managerName, infraModuleView.isUseNodeProp()); // ?????????null????? // ??????? if (accessInfoList == null) { return null; } List<String> moduleIdList = new ArrayList<String>(); moduleIdList.add(moduleId); try { InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName); String sessionId = wrapper.createSession(management.getManagementId(), moduleIdList, accessInfoList); while (true) { ModuleResult moduleResult = wrapper.checkInfraModule(sessionId, !allRun); if (!allRun && !ModuleUtil.displayResult(moduleResult.getModuleId(), moduleResult)) { break; } if (!moduleResult.isHasNext()) { break; } } MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.infra.management.check.end")); wrapper.deleteSession(sessionId); } catch (InvalidRole_Exception e) { // ??? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.accesscontrol.16")); return null; } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | InfraManagementNotFound_Exception | InfraModuleNotFound_Exception | SessionNotFound_Exception | FacilityNotFound_Exception | InvalidSetting_Exception e) { m_log.error("execute() : " + e.getClass().getName() + ", " + e.getMessage()); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.module.run"), Messages.getString("failed"), HinemosMessage.replace(e.getMessage()) })); return null; } catch (Exception e) { m_log.error("execute() : " + e.getClass().getName() + ", " + e.getMessage()); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.module.run"), Messages.getString("failed"), HinemosMessage.replace(e.getMessage()) })); return null; } infraModuleView.update(infraModuleView.getComposite().getManagerName(), infraModuleView.getComposite().getManagementId()); return null; }
From source file:com.clustercontrol.infra.view.action.CopyInfraManagementAction.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; }//from w w w . j a v a 2 s. co m this.viewPart = HandlerUtil.getActivePart(event); InfraManagementView view = null; if (viewPart instanceof InfraManagementView) { view = (InfraManagementView) viewPart; } if (view == null) { m_log.info("execute: view is null"); return null; } // view??????? StructuredSelection selection = null; if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection(); } String managerName = null; String managementId = null; if (selection != null) { managerName = (String) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraManagementTableDefine.MANAGER_NAME); managementId = (String) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraManagementTableDefine.MANAGEMENT_ID); } if (managementId != null) { // [???]?? InfraManagementDialog dialog = new InfraManagementDialog(this.viewPart.getSite().getShell(), managerName, managementId, PropertyDefineConstant.MODE_COPY); // ??????????? if (dialog.open() == IDialogConstants.OK_ID) { view.update(); } } return null; }
From source file:com.clustercontrol.infra.view.action.CopyInfraModuleAction.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; }/*from w ww . j ava 2s.com*/ // ??? this.viewPart = HandlerUtil.getActivePart(event); if (!(viewPart instanceof InfraModuleView)) { return null; } InfraModuleView infraModuleView = null; try { infraModuleView = (InfraModuleView) viewPart.getAdapter(InfraModuleView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (infraModuleView == null) { m_log.info("execute: infra module view is null"); return null; } StructuredSelection selection = null; if (infraModuleView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) infraModuleView.getComposite().getTableViewer().getSelection(); } String moduleId = null; if (selection != null) { moduleId = (String) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraModuleTableDefine.MODULE_ID); } InfraManagementInfo info = null; String managerName = infraModuleView.getComposite().getManagerName(); String managementId = infraModuleView.getComposite().getManagementId(); try { InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName); info = wrapper.getInfraManagement(managementId); } catch (InvalidRole_Exception e) { // ??? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.accesscontrol.16")); return null; } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) { m_log.debug("execute getInfraManagement, " + e.getMessage()); MessageDialog.openError(null, Messages.getString("failed"), HinemosMessage.replace(e.getMessage())); return null; } InfraModuleInfo module = null; if (info != null && info.getModuleList() != null) { for (InfraModuleInfo tmpModule : info.getModuleList()) { if (tmpModule.getModuleId().equals(moduleId)) { module = tmpModule; break; } } CommonDialog dialog = null; if (module != null) { if (module instanceof CommandModuleInfo) { dialog = new CommandModuleDialog(infraModuleView.getSite().getShell(), managerName, managementId, moduleId, PropertyDefineConstant.MODE_COPY); } else if (module instanceof FileTransferModuleInfo) { dialog = new FileTransferModuleDialog(infraModuleView.getSite().getShell(), managerName, managementId, moduleId, PropertyDefineConstant.MODE_COPY); } else { throw new InternalError("dialog is null"); } } if (dialog != null) dialog.open(); infraModuleView.update(managerName, managementId); } return null; }
From source file:com.clustercontrol.infra.view.action.DownloadInfraFileAction.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { InfraFileManagerView view = getView(event); if (view == null) { m_log.info("execute: view is null"); return null; }/*from w ww . j a v a 2 s . c o m*/ InfraFileInfo info = InfraFileUtil.getSelectedInfraFileInfo(view); if (info == null) { return null; } String action = Messages.getString("download"); FileDialog fd = new FileDialog(window.getShell(), SWT.SAVE); String fileName = info.getFileName(); fd.setFileName(fileName); String selectedFilePath = null; try { selectedFilePath = fd.open(); } catch (Exception e) { m_log.error(e); InfraFileUtil.showFailureDialog(action, HinemosMessage.replace(e.getMessage())); return null; } // path is null when dialog cancelled if (null != selectedFilePath) { StructuredSelection selection = null; if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection(); } String managerName = null; if (selection != null && selection.isEmpty() == false) { managerName = (String) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraFileManagerTableDefine.MANAGER_NAME); } InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName); FileOutputStream fos = null; try { DataHandler dh = wrapper.downloadInfraFile(info.getFileId(), fileName); fos = new FileOutputStream(new File(selectedFilePath)); dh.writeTo(fos); if (ClusterControlPlugin.isRAP()) { FileDownloader.openBrowser(window.getShell(), selectedFilePath, fileName); } else { InfraFileUtil.showSuccessDialog(action, info.getFileId()); } wrapper.deleteDownloadedInfraFile(fileName); } catch (Exception e) { m_log.error(e); InfraFileUtil.showFailureDialog(action, HinemosMessage.replace(e.getMessage())); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } return null; }
From source file:com.clustercontrol.infra.view.action.DownOrderInfraModuleAction.java
License:Open Source License
@Override public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) { boolean enable = false; IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); // page may not start at state restoring if (null != window) { IWorkbenchPage page = window.getActivePage(); if (null != page) { IWorkbenchPart part = page.getActivePart(); if (part instanceof InfraModuleView) { InfraModuleView view = (InfraModuleView) part.getAdapter(InfraModuleView.class); if (view == null) { m_log.info("execute: view is null"); return; }/* w w w.ja va2 s.c o m*/ // Enable button when 1 item is selected StructuredSelection selection = null; if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection(); } if (selection != null && selection.size() == 1 && view.getComposite().getTable().getItemCount() > 1 && (int) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraModuleTableDefine.ORDER_NO) < view.getComposite().getTable() .getItemCount()) { enable = true; } } this.setBaseEnabled(enable); } else { this.setBaseEnabled(false); } } }
From source file:com.clustercontrol.infra.view.action.ModifyInfraManagementAction.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; }/*from w w w. j a v a 2 s . c o m*/ this.viewPart = HandlerUtil.getActivePart(event); if (!(viewPart instanceof InfraManagementView)) { return null; } InfraManagementView infraManagementView = null; try { infraManagementView = (InfraManagementView) viewPart; } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } StructuredSelection selection = null; if (infraManagementView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) infraManagementView.getComposite().getTableViewer().getSelection(); } String managerName = null; String managementId = null; if (selection != null) { managerName = (String) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraManagementTableDefine.MANAGER_NAME); managementId = (String) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraManagementTableDefine.MANAGEMENT_ID); } if (managementId != null) { // [???]?? InfraManagementDialog dialog = new InfraManagementDialog(this.viewPart.getSite().getShell(), managerName, managementId, PropertyDefineConstant.MODE_MODIFY); // ??????????? if (dialog.open() == IDialogConstants.OK_ID) { infraManagementView.update(); } } return null; }
From source file:com.clustercontrol.infra.view.action.ModifyInfraModuleAction.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; }/*ww w. j ava 2 s . c o m*/ // ??? this.viewPart = HandlerUtil.getActivePart(event); if (!(viewPart instanceof InfraModuleView)) { return null; } InfraModuleView infraModuleView = null; try { infraModuleView = (InfraModuleView) viewPart.getAdapter(InfraModuleView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (infraModuleView == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = null; String managerName = null; if (infraModuleView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) infraModuleView.getComposite().getTableViewer().getSelection(); managerName = infraModuleView.getComposite().getManagerName(); } String moduleId = null; if (selection != null) { moduleId = (String) ((ArrayList<?>) selection.getFirstElement()) .get(GetInfraModuleTableDefine.MODULE_ID); } String managementId = infraModuleView.getComposite().getManagementId(); InfraManagementInfo info = null; try { InfraEndpointWrapper wrapper = InfraEndpointWrapper .getWrapper(infraModuleView.getComposite().getManagerName()); info = wrapper.getInfraManagement(infraModuleView.getComposite().getManagementId()); } catch (InvalidRole_Exception e) { // ??? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.accesscontrol.16")); return null; } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) { m_log.debug("execute getInfraManagement, " + e.getMessage()); MessageDialog.openError(null, Messages.getString("failed"), HinemosMessage.replace(e.getMessage())); return null; } InfraModuleInfo module = null; if (info != null && info.getModuleList() != null) { for (InfraModuleInfo tmpModule : info.getModuleList()) { if (tmpModule.getModuleId().equals(moduleId)) { module = tmpModule; break; } } CommonDialog dialog = null; if (moduleId != null) { if (module instanceof CommandModuleInfo) { dialog = new CommandModuleDialog(infraModuleView.getSite().getShell(), managerName, managementId, moduleId, PropertyDefineConstant.MODE_MODIFY); } else if (module instanceof FileTransferModuleInfo) { dialog = new FileTransferModuleDialog(infraModuleView.getSite().getShell(), managerName, managementId, moduleId, PropertyDefineConstant.MODE_MODIFY); } else { throw new InternalError("dialog is null"); } } if (dialog != null) dialog.open(); infraModuleView.update(managerName, managementId); } return null; }