List of usage examples for org.eclipse.jface.dialogs MessageDialog openConfirm
public static boolean openConfirm(Shell parent, String title, String message)
From source file:com.clustercontrol.notify.view.action.NotifyDisableAction.java
License:Open Source License
/** * // w w w . ja v a 2 s. com */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { // ??? this.viewPart = HandlerUtil.getActivePart(event); NotifyListView view = null; try { view = (NotifyListView) this.viewPart.getAdapter(NotifyListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } NotifyListComposite composite = (NotifyListComposite) view.getListComposite(); StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection(); Object[] objs = selection.toArray(); // 1???????? if (objs.length == 0) { MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.notify.8")); return null; } // 1?????? String notifyId = null; String[] args; StringBuffer targetList = new StringBuffer(); StringBuffer successList = new StringBuffer(); StringBuffer failureList = new StringBuffer(); Map<String, List<String>> disableMap = new ConcurrentHashMap<String, List<String>>(); for (int i = 0; i < objs.length; i++) { String managerName = (String) ((ArrayList<?>) objs[i]).get(NotifyTableDefineNoCheckBox.MANAGER_NAME); disableMap.put(managerName, new ArrayList<String>()); } for (int i = 0; i < objs.length; i++) { notifyId = (String) ((ArrayList<?>) objs[i]).get(NotifyTableDefineNoCheckBox.NOTIFY_ID); String managerName = (String) ((ArrayList<?>) objs[i]).get(NotifyTableDefineNoCheckBox.MANAGER_NAME); disableMap.get(managerName).add(notifyId); targetList.append(notifyId + "\n"); } // ?(NG) args = new String[] { targetList.toString() }; if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.notify.37", args))) { return null; } boolean hasRole = true; // for (Map.Entry<String, List<String>> map : disableMap.entrySet()) { String managerName = map.getKey(); NotifyEndpointWrapper wrapper = NotifyEndpointWrapper.getWrapper(managerName); for (String targetId : map.getValue()) { try { wrapper.setNotifyStatus(targetId, false); successList.append(targetId + "(" + managerName + ")" + "\n"); } catch (InvalidRole_Exception e) { failureList.append(targetId + "\n"); m_log.warn("run() setNotifyStatus targetId=" + targetId + ", " + e.getMessage(), e); hasRole = false; } catch (Exception e) { failureList.append(targetId + "\n"); m_log.warn("run() setNotifyStatus targetId=" + targetId + ", " + e.getMessage(), e); } } } if (!hasRole) { // ???????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } // ? if (successList.length() != 0) { args = new String[] { successList.toString() }; MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.notify.38", args)); } // if (failureList.length() != 0) { args = new String[] { failureList.toString() }; MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.notify.39", args)); } // ? composite.update(); return null; }
From source file:com.clustercontrol.notify.view.action.NotifyEnableAction.java
License:Open Source License
/** * // w ww.j av a 2 s . c om */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { // ??? this.viewPart = HandlerUtil.getActivePart(event); NotifyListView view = null; try { view = (NotifyListView) this.viewPart.getAdapter(NotifyListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } NotifyListComposite composite = (NotifyListComposite) view.getListComposite(); StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection(); Object[] objs = selection.toArray(); // 1???????? if (objs.length == 0) { MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.notify.8")); return null; } // 1?????? String notifyId = null; String[] args; StringBuffer targetList = new StringBuffer(); StringBuffer successList = new StringBuffer(); StringBuffer failureList = new StringBuffer(); Map<String, List<String>> enableMap = new ConcurrentHashMap<String, List<String>>(); for (int i = 0; i < objs.length; i++) { String managerName = (String) ((ArrayList<?>) objs[i]).get(NotifyTableDefineNoCheckBox.MANAGER_NAME); enableMap.put(managerName, new ArrayList<String>()); } for (int i = 0; i < objs.length; i++) { notifyId = (String) ((ArrayList<?>) objs[i]).get(NotifyTableDefineNoCheckBox.NOTIFY_ID); String managerName = (String) ((ArrayList<?>) objs[i]).get(NotifyTableDefineNoCheckBox.MANAGER_NAME); enableMap.get(managerName).add(notifyId); targetList.append(notifyId + "\n"); } // ?(NG) args = new String[] { targetList.toString() }; if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.notify.34", args))) { return null; } boolean hasRole = true; // for (Map.Entry<String, List<String>> map : enableMap.entrySet()) { String managerName = map.getKey(); NotifyEndpointWrapper wrapper = NotifyEndpointWrapper.getWrapper(map.getKey()); for (String targetId : map.getValue()) { try { wrapper.setNotifyStatus(targetId, true); successList.append(targetId + "(" + managerName + ")" + "\n"); } catch (InvalidRole_Exception e) { failureList.append(targetId + "\n"); m_log.warn("run() setNotifyStatus targetId=" + targetId + ", " + e.getMessage(), e); hasRole = false; } catch (Exception e) { failureList.append(targetId + "\n"); m_log.warn("run() setNotifyStatus targetId=" + targetId + ", " + e.getMessage(), e); } } } if (!hasRole) { // ???????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } // ? if (successList.length() != 0) { args = new String[] { successList.toString() }; MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.notify.35", args)); } // if (failureList.length() != 0) { args = new String[] { failureList.toString() }; MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.notify.36", args)); } // ? composite.update(); return null; }
From source file:com.clustercontrol.repository.view.action.AgentRestartAction.java
License:Open Source License
/** * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) *//*from w w w . j a va 2 s . com*/ @Override public Object execute(ExecutionEvent event) throws ExecutionException { this.viewPart = HandlerUtil.getActivePart(event); AgentListView view = null; try { view = (AgentListView) this.viewPart.getAdapter(AgentListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection(); List<?> selectionList = selection.toList(); if (selectionList.size() == 0) { return null; } Map<String, ArrayList<String>> map = new ConcurrentHashMap<String, ArrayList<String>>(); for (Object o : selectionList) { List<?> list = (List<?>) o; if (list == null) { continue; } String managerName = (String) list.get(GetAgentListTableDefine.MANAGER_NAME); if (map.get(managerName) == null) { map.put(managerName, new ArrayList<String>()); } } StringBuffer message = new StringBuffer(); boolean flag = true; for (Object o : selectionList) { List<?> list = (List<?>) o; String managerName = null; String facilityId = null; String facilityName = null; if (list != null) { managerName = (String) list.get(GetAgentListTableDefine.MANAGER_NAME); facilityId = (String) list.get(GetAgentListTableDefine.FACILITY_ID); facilityName = (String) list.get(GetAgentListTableDefine.FACILITY_NAME); map.get(managerName).add(facilityId); } // ID????????? if (facilityId == null) { return null; } else if ("".equals(facilityId)) { return null; } // ????????? if (flag) { flag = false; } else { message.append(", "); } message.append(facilityName + "(" + facilityId + ")"); } // ?? String[] args = { message.toString() }; if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.repository.44", args))) { m_log.debug("cancel"); return null; } Map<String, String> errorMsgs = new ConcurrentHashMap<>(); for (Map.Entry<String, ArrayList<String>> entry : map.entrySet()) { String managerName = entry.getKey(); ArrayList<String> facilityIdList = entry.getValue(); try { RepositoryEndpointWrapper wrapper = RepositoryEndpointWrapper.getWrapper(managerName); wrapper.restartAgent(facilityIdList, AgentCommandConstant.RESTART); } catch (InvalidRole_Exception e) { // ?????? Object[] arg = { managerName }; errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16", arg)); } catch (Exception e) { m_log.warn("run(), " + e.getMessage(), e); errorMsgs.put(managerName, Messages.getString("message.hinemos.failure.unexpected") + HinemosMessage.replace(e.getMessage())); } } // if (0 < errorMsgs.size()) { UIManager.showMessageBox(errorMsgs, true); } return null; }
From source file:com.clustercontrol.repository.view.action.AgentUpdateAction.java
License:Open Source License
/** * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) *///from w w w. j a va 2 s.c o m @Override public Object execute(ExecutionEvent event) throws ExecutionException { this.viewPart = HandlerUtil.getActivePart(event); AgentListView view = null; try { view = (AgentListView) this.viewPart.getAdapter(AgentListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection(); List<?> selectionList = selection.toList(); if (selectionList.size() == 0) { return null; } Map<String, ArrayList<String>> map = new ConcurrentHashMap<String, ArrayList<String>>(); for (Object o : selectionList) { List<?> list = (List<?>) o; if (list == null) { continue; } String managerName = (String) list.get(GetAgentListTableDefine.MANAGER_NAME); if (map.get(managerName) == null) { map.put(managerName, new ArrayList<String>()); } } StringBuffer message = new StringBuffer(); boolean flag = true; for (Object o : selectionList) { List<?> list = (List<?>) o; String managerName = null; String facilityId = null; String facilityName = null; if (list != null) { facilityId = (String) list.get(GetAgentListTableDefine.FACILITY_ID); // ID????????? if (facilityId == null) { return null; } else if ("".equals(facilityId)) { return null; } managerName = (String) list.get(GetAgentListTableDefine.MANAGER_NAME); facilityName = (String) list.get(GetAgentListTableDefine.FACILITY_NAME); map.get(managerName).add(facilityId); } // ????????? if (flag) { flag = false; } else { message.append(", "); } message.append(facilityName + "(" + facilityId + ")"); } // ?? String[] args = { message.toString() }; if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.repository.45", args))) { m_log.debug("cancel"); return null; } Map<String, String> errorMsgs = new ConcurrentHashMap<>(); for (Map.Entry<String, ArrayList<String>> entry : map.entrySet()) { String managerName = entry.getKey(); ArrayList<String> facilityIdList = entry.getValue(); try { RepositoryEndpointWrapper wrapper = RepositoryEndpointWrapper.getWrapper(managerName); wrapper.restartAgent(facilityIdList, AgentCommandConstant.UPDATE); } catch (InvalidRole_Exception e) { // ?????? Object[] arg = { managerName }; errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16", arg)); } catch (Exception e) { m_log.warn("run(), " + e.getMessage(), e); errorMsgs.put(managerName, Messages.getString("message.hinemos.failure.unexpected") + HinemosMessage.replace(e.getMessage())); } } // if (0 < errorMsgs.size()) { UIManager.showMessageBox(errorMsgs, true); } return null; }
From source file:com.clustercontrol.repository.view.action.NodeDeleteAction.java
License:Open Source License
/** * @see org.eclipse.core.commands.IHandler#execute *//* w w w . ja v a2s. c o m*/ @Override public Object execute(ExecutionEvent event) throws ExecutionException { this.viewPart = HandlerUtil.getActivePart(event); // ??????ID? NodeListView nodeListView = null; try { nodeListView = (NodeListView) this.viewPart.getAdapter(NodeListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (nodeListView == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = (StructuredSelection) nodeListView.getComposite().getTableViewer() .getSelection(); List<?> sList = (List<?>) selection.toList(); Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>(); for (Object obj : sList) { List<?> list = (List<?>) obj; String managerName = null; if (list != null) { managerName = (String) list.get(GetNodeListTableDefine.MANAGER_NAME); if (map.get(managerName) == null) { map.put(managerName, new ArrayList<String>()); } } } int size = 0; String facilityName = null; String facilityId = null; for (Object obj : sList) { List<?> list = (List<?>) obj; String managerName = null; if (list != null) { managerName = (String) list.get(GetNodeListTableDefine.MANAGER_NAME); String id = (String) list.get(GetNodeListTableDefine.FACILITY_ID); facilityName = (String) list.get(GetNodeListTableDefine.FACILITY_NAME); facilityId = id; map.get(managerName).add(id); size++; } } if (size > 0) { // ??????????? String msg = ""; String[] args = new String[2]; if (size == 1) { args[0] = facilityName; args[1] = facilityId; msg = "message.repository.1"; } else { args[0] = Integer.toString(size); msg = "message.repository.51"; } if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString(msg, args)) == false) { return null; } for (Map.Entry<String, List<String>> entry : map.entrySet()) { new DeleteNodeProperty().delete(entry.getKey(), entry.getValue()); } } // nodeListView.update(); return null; }
From source file:com.clustercontrol.repository.view.action.ProgramExecutionAction.java
License:Open Source License
/** * @see org.eclipse.core.commands.IHandler#execute *//* w w w . j av a2 s. c o m*/ @Override public Object execute(ExecutionEvent event) throws ExecutionException { this.viewPart = HandlerUtil.getActivePart(event); // ??????ID? NodeListView view = null; try { view = (NodeListView) this.viewPart.getAdapter(NodeListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection(); List<?> list = (List<?>) selection.getFirstElement(); if (list == null) { return null; } String managerName = (String) list.get(GetNodeListTableDefine.MANAGER_NAME); String facilityId = (String) list.get(GetNodeListTableDefine.FACILITY_ID); if (facilityId == null) { return null; } // ? String execProg = ClusterControlPlugin.getDefault().getPreferenceStore() .getString(RepositoryPreferencePage.P_PROGRAM_EXECUTION); // ?? if (execProg.equals("")) { MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.repository.49")); return null; } // ???????#????? if (execProg.indexOf("#") != -1) { try { // ???????????? RepositoryEndpointWrapper wrapper = RepositoryEndpointWrapper.getWrapper(managerName); execProg = wrapper.replaceNodeVariable(facilityId, execProg); } catch (InvalidRole_Exception e) { // ?????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } catch (Exception e) { m_log.warn("run(), " + e.getMessage(), e); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.hinemos.failure.unexpected") + ", " + HinemosMessage.replace(e.getMessage())); } } // ????? String[] args = null; try { String user = System.getProperty("user.name"); args = CommandCreator.createCommand(user, execProg, PlatformType.WINDOWS, false); } catch (HinemosUnknown e) { m_log.warn("run(), " + e.getMessage(), e); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.hinemos.failure.unexpected") + ", " + HinemosMessage.replace(e.getMessage())); } StringBuffer message = new StringBuffer(); for (String arg : args) { message.append(arg + " "); } String messageStr = message.toString(); if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.repository.46", new String[] { messageStr }))) { // ? m_log.debug("program execution start : " + messageStr); try { new CommandExecutor(args).execute(); } catch (Exception e) { MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.repository.48") + ", " + HinemosMessage.replace(e.getMessage())); } } return null; }
From source file:com.clustercontrol.repository.view.action.ScopeDeleteAction.java
License:Open Source License
/** * @see org.eclipse.core.commands.IHandler#execute *//*from w w w . ja va2s. c om*/ @Override public Object execute(ExecutionEvent event) throws ExecutionException { // ?????? // ?????? this.viewPart = HandlerUtil.getActivePart(event); ScopeListView scopeListView = null; try { scopeListView = (ScopeListView) this.viewPart.getAdapter(ScopeListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (scopeListView == null) { m_log.info("execute: view is null"); return null; } List<?> selectionList = scopeListView.getSelectedScopeItems(); if (null == selectionList) { return null; } Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>(); List<String> facilityNameList = new ArrayList<String>(); for (Object obj : selectionList) { if (obj instanceof FacilityTreeItem) { FacilityTreeItem item = (FacilityTreeItem) obj; FacilityTreeItem manager = ScopePropertyUtil.getManager(item); String managerName = null; if (manager == null) { managerName = item.getChildren().get(0).getData().getFacilityId(); } else { managerName = manager.getData().getFacilityId(); } if (map.get(managerName) == null) { map.put(managerName, new ArrayList<String>()); } } } int size = 0; String facilityId = null; for (Object obj : selectionList) { String managerName = null; if (obj instanceof FacilityTreeItem) { FacilityTreeItem item = (FacilityTreeItem) obj; // ????????? FacilityInfo info = item.getData(); if (info.getFacilityType() == FacilityConstant.TYPE_COMPOSITE || info.getFacilityType() == FacilityConstant.TYPE_NODE) { continue; } FacilityTreeItem manager = ScopePropertyUtil.getManager(item); if (manager == null) { managerName = item.getChildren().get(0).getData().getFacilityId(); } else { managerName = manager.getData().getFacilityId(); } facilityId = item.getData().getFacilityId(); map.get(managerName).add(facilityId); facilityNameList.add(item.getData().getFacilityName()); } else { List<?> sList = (List<?>) obj; facilityId = null; String facilityName = null; if (sList != null) { managerName = (String) sList.get(GetScopeListTableDefine.MANAGER_NAME); facilityId = (String) sList.get(GetScopeListTableDefine.FACILITY_ID); facilityName = (String) sList.get(GetScopeListTableDefine.FACILITY_NAME); facilityNameList.add(facilityName); map.get(managerName).add(facilityId); } } size++; } // ??????????? if (map.isEmpty()) { return null; } // ??????????? String msg = ""; String[] args = new String[2]; if (size == 1) { args[0] = facilityNameList.get(0); args[1] = facilityId; msg = "message.repository.3"; } else { args[0] = Integer.toString(size); msg = "message.repository.52"; } if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString(msg, args)) == false) { return null; } for (Map.Entry<String, List<String>> entry : map.entrySet()) { String managerName = entry.getKey(); List<String> facilityIdList = entry.getValue(); new DeleteScopeProperty().delete(managerName, facilityIdList); } // scopeListView.update(); return null; }
From source file:com.clustercontrol.snmptrap.composite.TrapDefineListComposite.java
License:Open Source License
/** * ?????// w w w. jav a2 s . c o m */ protected void initialize() { GridLayout layout = new GridLayout(1, true); this.setLayout(layout); layout.marginHeight = 0; layout.marginWidth = 0; layout.numColumns = MAX_COLUMN; //???? Label label = null; // Group groupFilter = new Group(this, SWT.NONE); WidgetTestUtil.setTestId(this, "filter", groupFilter); layout = new GridLayout(1, true); layout.marginWidth = 5; layout.marginHeight = 5; layout.numColumns = MAX_COLUMN; groupFilter.setLayout(layout); GridData gridData = new GridData(); gridData.horizontalSpan = MAX_COLUMN; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; groupFilter.setLayoutData(gridData); groupFilter.setText(Messages.getString("filter") + " : "); /* * MIB */ // label = new Label(groupFilter, SWT.NONE); WidgetTestUtil.setTestId(this, "mib", label); gridData = new GridData(); gridData.horizontalSpan = WIDTH_TITLE; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; label.setLayoutData(gridData); label.setText(Messages.getString("mib") + " : "); // this.cmbMib = new Combo(groupFilter, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL); WidgetTestUtil.setTestId(this, "mib", cmbMib); gridData = new GridData(); gridData.horizontalSpan = MAX_COLUMN - WIDTH_TITLE - 3; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.heightHint = 30; this.cmbMib.setLayoutData(gridData); this.cmbMib.setVisibleItemCount(10); // MIB? this.cmbMib.add(""); this.cmbMib.select(0); this.cmbMib.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { //? update(); } }); // Utility??????? if (true) { label = new Label(groupFilter, SWT.NONE); WidgetTestUtil.setTestId(this, null, label); gridData = new GridData(); gridData.horizontalSpan = 3; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; label.setLayoutData(gridData); } /* * */ // label = new Label(groupFilter, SWT.NONE); WidgetTestUtil.setTestId(this, "trapname", label); gridData = new GridData(); gridData.horizontalSpan = WIDTH_TITLE; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; label.setLayoutData(gridData); label.setText(Messages.getString("trap.name") + " : "); // this.txtFilter = new Text(groupFilter, SWT.BORDER | SWT.LEFT); WidgetTestUtil.setTestId(this, "filter", txtFilter); gridData = new GridData(); gridData.horizontalSpan = 10; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; this.txtFilter.setLayoutData(gridData); this.txtFilter.addVerifyListener(new StringVerifyListener(DataRangeConstant.VARCHAR_256)); // this.btnClearFilter = new Button(groupFilter, SWT.NONE); WidgetTestUtil.setTestId(this, "clearfilter", btnClearFilter); this.btnClearFilter.setText(Messages.getString("clear")); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; this.btnClearFilter.setLayoutData(gridData); this.btnClearFilter.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { txtFilter.setText(""); update(); } }); // this.btnShowOidTable = new Button(groupFilter, SWT.NONE); WidgetTestUtil.setTestId(this, "oidtable", btnShowOidTable); this.btnShowOidTable.setText(Messages.getString("show")); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; this.btnShowOidTable.setLayoutData(gridData); this.btnShowOidTable.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { //? update(); } }); /* * */ this.infoList = new TrapDefineTableComposite(this, SWT.BORDER, this.define); WidgetTestUtil.setTestId(this, "pagelist", infoList); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = MAX_COLUMN; gridData.heightHint = 150; this.infoList.setLayoutData(gridData); this.infoList.getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { checkButtonEnabled(); } }); /* * ? */ Composite composite = new Composite(this, SWT.NONE); WidgetTestUtil.setTestId(this, null, composite); layout = new GridLayout(6, true); composite.setLayout(layout); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = MAX_COLUMN; composite.setLayoutData(gridData); /* * */ labelRecordNumber = new Label(composite, SWT.NONE); WidgetTestUtil.setTestId(this, "recordNumber", label); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 2; labelRecordNumber.setLayoutData(gridData); updateRecordNumber(0, 0); // ??????? int validButtonCount = 0; validButtonCount += (this.define.getButtonOptions() & ITableItemCompositeDefine.ADD) != 0 ? 1 : 0; validButtonCount += (this.define.getButtonOptions() & ITableItemCompositeDefine.MODIFY) != 0 ? 1 : 0; validButtonCount += (this.define.getButtonOptions() & ITableItemCompositeDefine.DELETE) != 0 ? 1 : 0; validButtonCount += (this.define.getButtonOptions() & ITableItemCompositeDefine.COPY) != 0 ? 1 : 0; if (4 - validButtonCount > 0) { label = new Label(composite, SWT.NONE); WidgetTestUtil.setTestId(this, "dummy", label); gridData = new GridData(); gridData.horizontalSpan = 4 - validButtonCount; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; label.setLayoutData(gridData); } // if ((this.define.getButtonOptions() & ITableItemCompositeDefine.ADD) != 0) { this.btnAdd = this.createButton(composite, Messages.getString("add")); WidgetTestUtil.setTestId(this, "add", btnAdd); this.btnAdd.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // ? Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); CommonDialog dialog = define.createDialog(shell); if (dialog.open() == IDialogConstants.OK_ID) { define.getTableItemInfoManager().add(define.getCurrentCreatedItem()); addItem(define.getCurrentCreatedItem()); updateMibList(); update(); } } }); } // if ((this.define.getButtonOptions() & ITableItemCompositeDefine.MODIFY) != 0) { this.btnModify = this.createButton(composite, Messages.getString("modify")); WidgetTestUtil.setTestId(this, "modify", btnModify); this.btnModify.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TrapValueInfo item = getSelectedItem(); if (item != null) { // ? Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); CommonDialog dialog = define.createDialog(shell, item); if (dialog.open() == IDialogConstants.OK_ID) { Table table = infoList.getTableViewer().getTable(); WidgetTestUtil.setTestId(this, "modify", table); int selectIndex = table.getSelectionIndex(); define.getTableItemInfoManager().modify(item, define.getCurrentCreatedItem()); table.setSelection(selectIndex); removeItem(item); addItem(define.getCurrentCreatedItem()); updateMibList(); update(); } } else { MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30")); } } }); } // if ((this.define.getButtonOptions() & ITableItemCompositeDefine.DELETE) != 0) { this.btnDelete = this.createButton(composite, Messages.getString("delete")); WidgetTestUtil.setTestId(this, "delete", btnDelete); this.btnDelete.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { List<TrapValueInfo> infos = getSelectedItems(); if (infos.size() > 0) { if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.monitor.snmptrap.confirm.to.delete.selected.items"))) { define.getTableItemInfoManager().delete(infos); removeItem(infos.toArray(new TrapValueInfo[0])); updateMibList(); update(); } } else { MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30")); } } }); } // if ((this.define.getButtonOptions() & ITableItemCompositeDefine.COPY) != 0) { this.btnCopy = this.createButton(composite, Messages.getString("copy")); WidgetTestUtil.setTestId(this, "copy", btnCopy); this.btnCopy.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TrapValueInfo item = getSelectedItem(); if (item != null) { // ? Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); CommonDialog dialog = define.createDialog(shell, item); if (dialog.open() == IDialogConstants.OK_ID) { Table table = infoList.getTableViewer().getTable(); WidgetTestUtil.setTestId(this, "modify", table); int selectIndex = table.getSelectionIndex(); define.getTableItemInfoManager().add(define.getCurrentCreatedItem()); table.setSelection(selectIndex); addItem(define.getCurrentCreatedItem()); updateMibList(); update(); } } else { MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30")); } } }); } this.update(); }
From source file:com.collabnet.ccf.migration.wizards.MigrateLandscapeWizard.java
License:Open Source License
@Override public boolean performFinish() { saveSelections();/*from ww w .j a va 2 s. com*/ participantConfigs = null; landscapeConfigs = null; directionConfigs = null; migrationResults = new ArrayList<MigrationResult>(); exception = null; canceled = false; showMigrationResults = true; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { String taskName = "Migrating landscape"; monitor.setTaskName(taskName); int taskCount = 25 + (mappingPage.getSelectedProjectMappings().length * 2) + mappingPage.getSelectedRepositoryMappings().length; monitor.beginTask(taskName, taskCount); try { projectMappings = mappingPage.getSelectedProjectMappings(); if (projectMappings == null) { projectMappings = getProjectMappings(monitor); } else { projectIds = mappingPage.getSelectedProjectIds(); } boolean resumedMappingSelected = false; for (SynchronizationStatus projectMapping : projectMappings) { if (!projectMapping.isPaused()) { resumedMappingSelected = true; break; } } if (resumedMappingSelected) { Display.getDefault().syncExec(new Runnable() { public void run() { if (!MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Migrate Landscape to CCF 2.x", "Before migration starts, all selected CCF 1.x project mappings will be paused. This is to prevent situation where CCF 1.x and CCF 2.x are trying to synchronize the same entities which might result in conflicts and duplicate artifacts. After the migration has been finished, please resume the repository mapping directions in CCF 2.x again and make sure that they are not resumed again in CCF 1.x. The reason this migrator does not automatically delete CCF 1.x project mappings after successful migration is that you should still have the chance to fall back to CCF 1.x if you are not satisfied with the migration result.\n\nPause selected CCF 1.x project mappings and continue with migration?")) { canceled = true; showMigrationResults = false; } } }); if (canceled == true) { return; } monitor.subTask("Pausing CCF 1.x project mappings"); for (SynchronizationStatus projectMapping : projectMappings) { if (!projectMapping.isPaused()) { getCcfDataProvider().pauseSynchronization(projectMapping); } } } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } if (projectMappingMap == null) { projectMappingMap = getProjectMappingMap(monitor); } teamForgeClient.getConnection().login(); if (!teamForgeClient.getConnection().supports54()) { exception = new Exception("TeamForge 5.4 or higher is required to migrate landscape."); return; } UserDO userDO = teamForgeClient.getConnection().getTeamForgeClient() .getUserData(ccfMasterPage.getCcfMasterUser()); if (!userDO.getSuperUser()) { exception = new Exception( "TeamForge site admin privileges are required to migrate landscape."); return; } monitor.worked(1); monitor.subTask("Checking for existing CCF Master participants"); String otherType; if (landscape.getType1().equals("TF")) { otherType = landscape.getType2(); } else { otherType = landscape.getType1(); } Participant[] participants = getCcfMasterClient().getParticipants(); Participant teamForgeParticipant = null; Participant otherParticipant = null; for (Participant participant : participants) { if (participant.getSystemKind().equals("TF")) { teamForgeParticipant = participant; migrationResults.add( new MigrationResult("TeamForge participant already exists in CCF Master.")); } else { otherParticipant = participant; migrationResults.add(new MigrationResult(getParticipantDescription(otherType) + " participant already exists in CCF Master.")); } } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } boolean teamForgeParticipantAlreadyExists = teamForgeParticipant != null; if (teamForgeParticipant == null) { monitor.subTask("Creating CCF Master TeamForge participant"); teamForgeParticipant = new Participant(); teamForgeParticipant.setSystemId("TeamForge"); teamForgeParticipant.setDescription("TeamForge"); teamForgeParticipant.setSystemKind("TF"); if (landscape.getType2().equals("TF")) { teamForgeParticipant.setTimezone(landscape.getTimezone2()); } else { teamForgeParticipant.setTimezone(landscape.getTimezone1()); } teamForgeParticipant = getCcfMasterClient().createParticipant(teamForgeParticipant); migrationResults.add(new MigrationResult("TeamForge participant created in CCF Master.")); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } ParticipantConfig teamForgeParticipantConfig = new ParticipantConfig(); teamForgeParticipantConfig.setName(ParticipantConfig.TF_URL); if (landscape.getType2().equals("TF")) { teamForgeParticipantConfig.setVal(landscape.getUrl(2)); } else { teamForgeParticipantConfig.setVal(landscape.getUrl(1)); } teamForgeParticipantConfig.setParticipant(teamForgeParticipant); if (createOrUpdateParticipantConfig(getCcfMasterClient(), teamForgeParticipant, teamForgeParticipantAlreadyExists, teamForgeParticipantConfig)) { migrationResults .add(new MigrationResult("TeamForge participant properties set in CCF Master.")); } else { String message = "CCF Master landscape already exists and refers to a different TeamForge site."; migrationResults .add(new MigrationResult(message, MigrationResult.ERROR, new Exception(message))); return; } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } boolean otherParticipantAlreadyExists = otherParticipant != null; if (otherParticipant == null) { String otherDescription = getParticipantDescription(otherType); monitor.subTask("Creating CCF Master " + otherDescription + " participant"); otherParticipant = new Participant(); if (otherType.equals("QC")) { otherParticipant.setSystemId("Quality Center"); } else { otherParticipant.setSystemId(otherType); } otherParticipant.setDescription(otherDescription); otherParticipant.setSystemKind(otherType); if (landscape.getType2().equals("TF")) { otherParticipant.setTimezone(landscape.getTimezone1()); } else { otherParticipant.setTimezone(landscape.getTimezone2()); } otherParticipant = getCcfMasterClient().createParticipant(otherParticipant); migrationResults.add(new MigrationResult( getParticipantDescription(otherType) + " participant created in CCF Master.")); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } ParticipantConfig otherParticipantConfig = new ParticipantConfig(); if (otherType.equals("SWP")) { otherParticipantConfig.setName(ParticipantConfig.SWP_URL); } else { otherParticipantConfig.setName(ParticipantConfig.QC_URL); } if (landscape.getType2().equals("TF")) { otherParticipantConfig.setVal(landscape.getUrl(1)); } else { otherParticipantConfig.setVal(landscape.getUrl(2)); } otherParticipantConfig.setParticipant(otherParticipant); if (createOrUpdateParticipantConfig(getCcfMasterClient(), otherParticipant, otherParticipantAlreadyExists, otherParticipantConfig)) { migrationResults.add(new MigrationResult(getParticipantDescription(otherType) + " participant properties set in CCF Master.")); } else { String participantDescription; if (otherType.equals("SWP")) { participantDescription = "ScrumWorks Pro"; } else { participantDescription = "Quality Center"; } String message = "CCF Master landscape already exists and refers to a different " + participantDescription + " site."; migrationResults .add(new MigrationResult(message, MigrationResult.ERROR, new Exception(message))); return; } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } monitor.subTask("Checking for existing CCF Master landscape"); com.collabnet.ccf.api.model.Landscape ccfMasterLandscape = null; com.collabnet.ccf.api.model.Landscape[] landscapes = getCcfMasterClient().getLandscapes(true); for (com.collabnet.ccf.api.model.Landscape landscape : landscapes) { ccfMasterLandscape = landscape; migrationResults.add(new MigrationResult( "Landscape " + ccfMasterLandscape.getName() + " already exists in CCF Master.")); break; } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } boolean landscapeAlreadyExists = ccfMasterLandscape != null; if (ccfMasterLandscape == null) { monitor.subTask("Creating CCF Master landscape"); ccfMasterLandscape = new com.collabnet.ccf.api.model.Landscape(); ccfMasterLandscape.setName(landscape.getDescription()); ccfMasterLandscape.setParticipant(otherParticipant); ccfMasterLandscape.setTeamForge(teamForgeParticipant); ccfMasterLandscape = getCcfMasterClient().createLandscape(ccfMasterLandscape); migrationResults.add(new MigrationResult( "Landscape " + ccfMasterLandscape.getName() + " created in CCF Master.")); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } String teamForgeUsername = null; String teamForgePassword = null; String otherUsername = null; String otherPassword = null; String swpResyncUsername = null; String swpResyncPassword = null; if (landscape.getType2().equals("TF")) { teamForgeUsername = landscape.getProperties2().getProperty(Activator.PROPERTIES_SFEE_USER, ""); teamForgePassword = landscape.getProperties2() .getProperty(Activator.PROPERTIES_SFEE_PASSWORD, ""); if (otherType.equals("QC")) { otherUsername = landscape.getProperties1().getProperty(Activator.PROPERTIES_QC_USER, ""); otherPassword = landscape.getProperties1().getProperty(Activator.PROPERTIES_QC_PASSWORD, ""); } else if (otherType.equals("SWP")) { otherUsername = landscape.getProperties1().getProperty(Activator.PROPERTIES_SW_USER, ""); otherPassword = landscape.getProperties1().getProperty(Activator.PROPERTIES_SW_PASSWORD, ""); swpResyncUsername = landscape.getProperties1() .getProperty(Activator.PROPERTIES_SW_RESYNC_USER, ""); swpResyncPassword = landscape.getProperties1() .getProperty(Activator.PROPERTIES_SW_RESYNC_PASSWORD, ""); } } else { teamForgeUsername = landscape.getProperties1().getProperty(Activator.PROPERTIES_SFEE_USER, ""); teamForgePassword = landscape.getProperties1() .getProperty(Activator.PROPERTIES_SFEE_PASSWORD, ""); if (otherType.equals("QC")) { otherUsername = landscape.getProperties2().getProperty(Activator.PROPERTIES_QC_USER, ""); otherPassword = landscape.getProperties2().getProperty(Activator.PROPERTIES_QC_PASSWORD, ""); } else if (otherType.equals("SWP")) { otherUsername = landscape.getProperties2().getProperty(Activator.PROPERTIES_SW_USER, ""); otherPassword = landscape.getProperties2().getProperty(Activator.PROPERTIES_SW_PASSWORD, ""); swpResyncUsername = landscape.getProperties2() .getProperty(Activator.PROPERTIES_SW_RESYNC_USER, ""); swpResyncPassword = landscape.getProperties2() .getProperty(Activator.PROPERTIES_SW_RESYNC_PASSWORD, ""); } } LandscapeConfig landscapeConfig = new LandscapeConfig(); landscapeConfig.setLandscape(ccfMasterLandscape); landscapeConfig.setName(LandscapeConfig.TF_USERNAME); landscapeConfig.setVal(teamForgeUsername); createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape, landscapeAlreadyExists, landscapeConfig); monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } landscapeConfig.setName(LandscapeConfig.TF_PASSWORD); landscapeConfig.setVal(obfuscatePassword(teamForgePassword)); createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape, landscapeAlreadyExists, landscapeConfig); monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } if (otherUsername != null) { if (otherType.equals("SWP")) { landscapeConfig.setName(LandscapeConfig.SWP_USERNAME); } else { landscapeConfig.setName(LandscapeConfig.QC_USERNAME); } landscapeConfig.setVal(otherUsername); createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape, landscapeAlreadyExists, landscapeConfig); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } if (otherPassword != null) { if (otherType.equals("SWP")) { landscapeConfig.setName(LandscapeConfig.SWP_PASSWORD); } else { landscapeConfig.setName(LandscapeConfig.QC_PASSWORD); } landscapeConfig.setVal(obfuscatePassword(otherPassword)); createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape, landscapeAlreadyExists, landscapeConfig); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } if (swpResyncUsername != null) { landscapeConfig.setName(LandscapeConfig.SWP_RESYNC_USERNAME); landscapeConfig.setVal(swpResyncUsername); createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape, landscapeAlreadyExists, landscapeConfig); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } if (swpResyncPassword != null) { landscapeConfig.setName(LandscapeConfig.SWP_RESYNC_PASSWORD); landscapeConfig.setVal(obfuscatePassword(swpResyncPassword)); createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape, landscapeAlreadyExists, landscapeConfig); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } migrationResults.add(new MigrationResult( "Landscape " + ccfMasterLandscape.getName() + " properties set in CCF Master.")); Direction forward = null; Direction reverse = null; if (landscapeAlreadyExists) { monitor.subTask("Checking for existing CCF Master directions"); Direction[] directions = getCcfMasterClient().getDirections(ccfMasterLandscape, null, true); for (Direction direction : directions) { if (direction.getLandscape().getId() == ccfMasterLandscape.getId()) { if (direction.getDirections().equals(Directions.FORWARD)) { forward = direction; migrationResults.add(new MigrationResult("Direction " + forward.getDescription() + " (FORWARD) already exists in CCF Master.")); } else if (direction.getDirections().equals(Directions.REVERSE)) { reverse = direction; migrationResults.add(new MigrationResult("Direction " + reverse.getDescription() + " (REVERSE) already exists in CCF Master.")); } if (forward != null && reverse != null) { break; } } } } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } if (forward == null || reverse == null) { monitor.subTask("Creating CCF Master directions"); } if (forward == null) { forward = new Direction(); forward.setLandscape(ccfMasterLandscape); forward.setDirections(Directions.FORWARD); if (landscape.getType1().equals("TF")) { forward.setDescription(landscape.getType1() + landscape.getType2()); } else { forward.setDescription(landscape.getType2() + landscape.getType1()); } forward.setShouldStartAutomatically(Boolean.valueOf(false)); forward = getCcfMasterClient().createDirection(forward); migrationResults.add(new MigrationResult( "Direction " + forward.getDescription() + " (FORWARD) created in CCF Master.")); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } DirectionConfig forwardConfig = new DirectionConfig(); String teamForgeMaxAttachmentSize = null; String otherMaxAttachmentSize = null; if (landscape.getType1().equals("TF")) { forwardConfig.setVal(landscape.getLogMessageTemplate1()); teamForgeMaxAttachmentSize = landscape.getProperties1() .getProperty(Activator.PROPERTIES_SFEE_ATTACHMENT_SIZE, "10485760"); if (otherType.equals("SWP")) { otherMaxAttachmentSize = landscape.getProperties2() .getProperty(Activator.PROPERTIES_SW_ATTACHMENT_SIZE, "10485760"); } else { otherMaxAttachmentSize = landscape.getProperties2() .getProperty(Activator.PROPERTIES_QC_ATTACHMENT_SIZE, "10485760"); } } else { forwardConfig.setVal(landscape.getLogMessageTemplate2()); teamForgeMaxAttachmentSize = landscape.getProperties2() .getProperty(Activator.PROPERTIES_SFEE_ATTACHMENT_SIZE, "10485760"); if (otherType.equals("SWP")) { otherMaxAttachmentSize = landscape.getProperties1() .getProperty(Activator.PROPERTIES_SW_ATTACHMENT_SIZE, "10485760"); } else { otherMaxAttachmentSize = landscape.getProperties1() .getProperty(Activator.PROPERTIES_QC_ATTACHMENT_SIZE, "10485760"); } } forwardConfig.setDirection(forward); forwardConfig.setName(DirectionConfig.LOG_MESSAGE_TEMPLATE); createOrUpdateDirectionConfig(getCcfMasterClient(), forward, forwardConfig); monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } if (teamForgeMaxAttachmentSize != null) { forwardConfig.setName(DirectionConfig.TF_MAX_ATTACHMENT_SIZE); forwardConfig.setVal(teamForgeMaxAttachmentSize); createOrUpdateDirectionConfig(getCcfMasterClient(), forward, forwardConfig); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } migrationResults.add(new MigrationResult( "Direction " + forward.getDescription() + " (FORWARD) properties set in CCF Master.")); if (reverse == null) { reverse = new Direction(); reverse.setLandscape(ccfMasterLandscape); reverse.setDirections(Directions.REVERSE); if (landscape.getType1().equals("TF")) { reverse.setDescription(landscape.getType2() + landscape.getType1()); } else { reverse.setDescription(landscape.getType1() + landscape.getType2()); } reverse.setShouldStartAutomatically(Boolean.valueOf(false)); reverse = getCcfMasterClient().createDirection(reverse); migrationResults.add(new MigrationResult( "Direction " + reverse.getDescription() + " (REVERSE) created in CCF Master.")); // Null out existing direction configs because next time we check them we want them to be retrieved again since creating // the reverse direction will have resulted in more configs being created automatically. directionConfigs = null; } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } DirectionConfig reverseConfig = new DirectionConfig(); teamForgeMaxAttachmentSize = null; otherMaxAttachmentSize = null; if (landscape.getType1().equals("TF")) { reverseConfig.setVal(landscape.getLogMessageTemplate2()); teamForgeMaxAttachmentSize = landscape.getProperties1() .getProperty(Activator.PROPERTIES_SFEE_ATTACHMENT_SIZE, "10485760"); if (otherType.equals("SWP")) { otherMaxAttachmentSize = landscape.getProperties2() .getProperty(Activator.PROPERTIES_SW_ATTACHMENT_SIZE, "10485760"); } else { otherMaxAttachmentSize = landscape.getProperties2() .getProperty(Activator.PROPERTIES_QC_ATTACHMENT_SIZE, "10485760"); } } else { reverseConfig.setVal(landscape.getLogMessageTemplate1()); teamForgeMaxAttachmentSize = landscape.getProperties2() .getProperty(Activator.PROPERTIES_SFEE_ATTACHMENT_SIZE, "10485760"); if (otherType.equals("SWP")) { otherMaxAttachmentSize = landscape.getProperties1() .getProperty(Activator.PROPERTIES_SW_ATTACHMENT_SIZE, "10485760"); } else { otherMaxAttachmentSize = landscape.getProperties1() .getProperty(Activator.PROPERTIES_QC_ATTACHMENT_SIZE, "10485760"); } } reverseConfig.setDirection(reverse); reverseConfig.setName(DirectionConfig.LOG_MESSAGE_TEMPLATE); createOrUpdateDirectionConfig(getCcfMasterClient(), reverse, reverseConfig); monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } if (otherMaxAttachmentSize != null) { if (otherType.equals("SWP")) { reverseConfig.setName(DirectionConfig.SWP_MAX_ATTACHMENT_SIZE); } else { reverseConfig.setName(DirectionConfig.QC_MAX_ATTACHMENT_SIZE); } reverseConfig.setVal(otherMaxAttachmentSize); createOrUpdateDirectionConfig(getCcfMasterClient(), reverse, reverseConfig); } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } migrationResults.add(new MigrationResult( "Direction " + reverse.getDescription() + " (REVERSE) properties set in CCF Master.")); Map<String, ExternalApp> externalAppMap = new HashMap<String, ExternalApp>(); monitor.subTask("Creating CCF Master external applications:"); ExternalApp[] externalApps = getCcfMasterClient().getExternalApps(ccfMasterLandscape, true); for (String project : projectIds) { ProjectDO projectDO = projectMap.get(project); ExternalApp externalApp = new ExternalApp(); externalApp.setProjectPath(projectDO.getPath()); externalApp.setProjectTitle(projectDO.getTitle()); externalApp.setLandscape(ccfMasterLandscape); ExternalApp existingApp = getExternalApp(externalApp, externalApps); if (existingApp != null) { externalApp = existingApp; migrationResults .add(new MigrationResult("External application " + externalApp.getLinkId() + " (" + project + ") already exists in CCF Master.")); } else { monitor.subTask( "Creating CCF Master external applications: " + externalApp.getProjectTitle()); externalApp = getCcfMasterClient().createExternalApp(externalApp); migrationResults.add(new MigrationResult("External application " + externalApp.getLinkId() + " (" + project + ") created in CCF Master.")); } externalAppMap.put(project, externalApp); if (monitor.isCanceled()) { canceled = true; return; } } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } monitor.subTask("Creating CCF Master repository mappings:"); List<String> repositoryMappingList = new ArrayList<String>(); RepositoryMapping[] repositoryMappings = getCcfMasterClient().getRepositoryMappings(true); for (SynchronizationStatus projectMapping : projectMappings) { String projectId = projectMappingMap.get(projectMapping); if (projectId != null) { ExternalApp externalApp = externalAppMap.get(projectId); if (externalApp != null) { String teamForgeRepositoryId = null; String participantRepositoryId = null; if (projectMapping.getSourceSystemKind().startsWith("TF")) { teamForgeRepositoryId = projectMapping.getSourceRepositoryId(); participantRepositoryId = projectMapping.getTargetRepositoryId(); } else if (projectMapping.getTargetSystemKind().startsWith("TF")) { teamForgeRepositoryId = projectMapping.getTargetRepositoryId(); participantRepositoryId = projectMapping.getSourceRepositoryId(); } if (teamForgeRepositoryId != null) { if (!repositoryMappingList.contains( projectId + teamForgeRepositoryId + participantRepositoryId)) { RepositoryMapping repositoryMapping = new RepositoryMapping(); String description = null; if (otherType.equals("SWP")) { int index = participantRepositoryId.lastIndexOf("-"); if (index != -1) { description = participantRepositoryId.substring(index + 1); } } if (description == null) { description = teamForgeRepositoryId + " " + "\u21D4" + " " + participantRepositoryId; } repositoryMapping.setDescription(description); repositoryMapping.setExternalApp(externalApp); repositoryMapping.setParticipantRepositoryId(participantRepositoryId); repositoryMapping.setTeamForgeRepositoryId(teamForgeRepositoryId); RepositoryMapping checkMapping = getRepositoryMapping(repositoryMapping, repositoryMappings); if (checkMapping == null) { monitor.subTask("Creating CCF Master repository mappings: " + repositoryMapping.getDescription()); repositoryMapping = getCcfMasterClient() .createRepositoryMapping(repositoryMapping); migrationResults.add(new MigrationResult( "Repository mapping " + repositoryMapping.getDescription() + " created in CCF Master.")); } else { repositoryMapping = checkMapping; migrationResults.add(new MigrationResult( "Repository mapping " + repositoryMapping.getDescription() + " already exists in CCF Master.")); } repositoryMappingList .add(projectId + teamForgeRepositoryId + participantRepositoryId); } } } if (monitor.isCanceled()) { canceled = true; return; } } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } } monitor.subTask("Creating CCF Master repository mapping directions:"); repositoryMappings = getCcfMasterClient().getRepositoryMappings(ccfMasterLandscape, true); RepositoryMappingDirection[] repositoryMappingDirections = getCcfMasterClient() .getRepositoryMappingDirections(ccfMasterLandscape, true); if (monitor.isCanceled()) { canceled = true; return; } for (SynchronizationStatus projectMapping : projectMappings) { if (projectMapping.getSourceSystemKind().startsWith("TF") || projectMapping.getTargetSystemKind().startsWith("TF")) { RepositoryMappingDirection repositoryMappingDirection = new RepositoryMappingDirection(); if (projectMapping.getTargetSystemKind().startsWith("TF")) { repositoryMappingDirection.setDirection(Directions.REVERSE); } else { repositoryMappingDirection.setDirection(Directions.FORWARD); } repositoryMappingDirection .setRepositoryMapping(getRepositoryMapping(projectMapping, repositoryMappings)); if (projectMapping.isPaused()) { repositoryMappingDirection.setStatus(RepositoryMappingDirectionStatus.PAUSED); } else { repositoryMappingDirection.setStatus(RepositoryMappingDirectionStatus.RUNNING); } repositoryMappingDirection.setLastSourceArtifactModificationDate( projectMapping.getSourceLastModificationTime()); repositoryMappingDirection .setLastSourceArtifactVersion(projectMapping.getSourceLastArtifactVersion()); repositoryMappingDirection .setLastSourceArtifactId(projectMapping.getSourceLastArtifactId()); String conflictResolutionPolicy = projectMapping.getConflictResolutionPriority(); if (conflictResolutionPolicy.equals(ConflictResolutionPolicy.alwaysIgnore.toString())) { repositoryMappingDirection .setConflictResolutionPolicy(ConflictResolutionPolicy.alwaysIgnore); } else if (conflictResolutionPolicy .equals(ConflictResolutionPolicy.quarantineArtifact.toString())) { repositoryMappingDirection .setConflictResolutionPolicy(ConflictResolutionPolicy.quarantineArtifact); } else if (conflictResolutionPolicy .equals(ConflictResolutionPolicy.alwaysOverrideAndIgnoreLocks.toString())) { repositoryMappingDirection.setConflictResolutionPolicy( ConflictResolutionPolicy.alwaysOverrideAndIgnoreLocks); } else { repositoryMappingDirection .setConflictResolutionPolicy(ConflictResolutionPolicy.alwaysOverride); } RepositoryMappingDirection checkRepositoryMappingDirection = getRepositoryMappingDirection( repositoryMappingDirection, repositoryMappingDirections); if (checkRepositoryMappingDirection == null) { monitor.subTask("Creating CCF Master repository mapping directions: " + repositoryMappingDirection.getRepositoryMapping().getDescription() + " (" + repositoryMappingDirection.getDirection() + ")"); repositoryMappingDirection = getCcfMasterClient() .createRepositoryMappingDirection(repositoryMappingDirection); migrationResults.add(new MigrationResult("Repository mapping direction " + repositoryMappingDirection.getRepositoryMapping().getDescription() + " (" + repositoryMappingDirection.getDirection() + ") created in CCF Master.")); if (projectMapping.getSourceRepositoryKind().contains("Template")) { FieldMapping fieldMapping = new FieldMapping(); fieldMapping.setParent(repositoryMappingDirection); fieldMapping.setScope(FieldMappingScope.CCF_CORE); String fieldMappingName; int index = projectMapping.getSourceRepositoryKind().indexOf(".xsl"); if (index == -1) { fieldMappingName = projectMapping.getSourceRepositoryKind(); } else { fieldMappingName = projectMapping.getSourceRepositoryKind().substring(0, index); } fieldMapping.setName(fieldMappingName); fieldMapping.setKind(FieldMappingKind.CUSTOM_XSLT); fieldMapping = getCcfMasterClient().createFieldMapping(fieldMapping); repositoryMappingDirection.setActiveFieldMapping(fieldMapping); repositoryMappingDirection = getCcfMasterClient() .updateRepositoryMappingDirection(repositoryMappingDirection); } else if (projectMapping.getSourceRepositoryKind().contains(".xsl")) { List<FieldMappingRule> fieldMappingRules = new ArrayList<FieldMappingRule>(); File preFile = projectMapping.getGenericArtifactToSourceRepositorySchemaFile(); File postFile = projectMapping.getTargetRepositorySchemaToGenericArtifactFile(); File mfdFile = projectMapping.getMappingFile(projectMapping.getMFDFileName()); File mainFile = projectMapping.getGraphicalXslFile(); File sourceRepositorySchemaFile = projectMapping .getSourceRepositorySchemaFile(); File targetRepositorySchemaFile = projectMapping .getTargetRepositorySchemaFile(); FieldMapping fieldMapping = new FieldMapping(); fieldMapping.setParent(repositoryMappingDirection); fieldMapping.setScope(FieldMappingScope.REPOSITORY_MAPPING_DIRECTION); fieldMapping.setKind(FieldMappingKind.MAPFORCE); fieldMapping.setName(FieldMappingKind.MAPFORCE.toString()); if (sourceRepositorySchemaFile.exists()) { fieldMappingRules.add( getFieldMappingRule(FieldMappingRuleType.SOURCE_REPOSITORY_LAYOUT, sourceRepositorySchemaFile)); } if (targetRepositorySchemaFile.exists()) { fieldMappingRules.add( getFieldMappingRule(FieldMappingRuleType.TARGET_REPOSITORY_LAYOUT, targetRepositorySchemaFile)); } if (preFile.exists()) { fieldMappingRules.add( getFieldMappingRule(FieldMappingRuleType.MAPFORCE_PRE, preFile)); } if (mainFile.exists()) { fieldMappingRules.add( getFieldMappingRule(FieldMappingRuleType.MAPFORCE_MAIN, mainFile)); } if (postFile.exists()) { fieldMappingRules.add( getFieldMappingRule(FieldMappingRuleType.MAPFORCE_POST, postFile)); } if (mfdFile.exists()) { XSLTInitialMFDGeneratorScriptGenerator generator = new XSLTInitialMFDGeneratorScriptGenerator(); Document mfdDocument = generator.generateCreateInitialMFDScript( mfdFile.getAbsolutePath(), projectMapping.getSourceRepositorySchemaFileName(), projectMapping.getTargetRepositorySchemaFileName()); //$NON-NLS-1$ //$NON-NLS-2$ FieldMappingRule mfdFieldMappingRule = getFieldMappingRule( FieldMappingRuleType.MAPFORCE_MFD, mfdFile); mfdFieldMappingRule.setXmlContent(mfdDocument.asXML()); fieldMappingRules.add(mfdFieldMappingRule); } fieldMapping.setRules(fieldMappingRules); fieldMapping = getCcfMasterClient().createFieldMapping(fieldMapping); repositoryMappingDirection.setActiveFieldMapping(fieldMapping); repositoryMappingDirection = getCcfMasterClient() .updateRepositoryMappingDirection(repositoryMappingDirection); } else { FieldMapping fieldMapping = new FieldMapping(); fieldMapping.setParent(repositoryMappingDirection); fieldMapping.setScope(FieldMappingScope.REPOSITORY_MAPPING_DIRECTION); fieldMapping.setKind(FieldMappingKind.CUSTOM_XSLT); fieldMapping.setName(FieldMappingKind.CUSTOM_XSLT.toString()); FieldMappingRule fieldMappingRule = new FieldMappingRule(); fieldMappingRule.setType(FieldMappingRuleType.CUSTOM_XSLT_DOCUMENT); fieldMappingRule.setSource("source"); fieldMappingRule.setSourceIsTopLevelAttribute(Boolean.valueOf(false)); fieldMappingRule.setTarget("target"); fieldMappingRule.setTargetIsTopLevelAttribute(Boolean.valueOf(false)); File xslFile = projectMapping.getXslFile(); if (!xslFile.exists()) { xslFile = projectMapping.getSampleXslFile(); } fieldMappingRule.setXmlContent(CcfMasterClient.readFile(xslFile)); List<FieldMappingRule> fieldMappingRules = new ArrayList<FieldMappingRule>(); fieldMappingRules.add(fieldMappingRule); fieldMapping.setRules(fieldMappingRules); fieldMapping = getCcfMasterClient().createFieldMapping(fieldMapping); repositoryMappingDirection.setActiveFieldMapping(fieldMapping); repositoryMappingDirection = getCcfMasterClient() .updateRepositoryMappingDirection(repositoryMappingDirection); } } else { repositoryMappingDirection = checkRepositoryMappingDirection; migrationResults.add(new MigrationResult("Repository mapping direction " + repositoryMappingDirection.getRepositoryMapping().getDescription() + " (" + repositoryMappingDirection.getDirection() + ") already exists in CCF Master.")); } if (monitor.isCanceled()) { canceled = true; return; } } monitor.worked(1); if (monitor.isCanceled()) { canceled = true; return; } } repositoryMappingDirections = getCcfMasterClient() .getRepositoryMappingDirections(ccfMasterLandscape, true); monitor.subTask("Creating CCF Master identity mappings:"); createdCount = 0; notCreatedCount = 0; alreadyExistedCount = 0; for (RepositoryMapping repositoryMapping : mappingPage.getSelectedRepositoryMappings()) { List<String> identityMappingList = new ArrayList<String>(); Filter forwardSourceRepositoryFilter = new Filter( CcfDataProvider.IDENTITY_MAPPING_SOURCE_REPOSITORY_ID, repositoryMapping.getTeamForgeRepositoryId(), true); Filter forwardTargetRepositoryFilter = new Filter( CcfDataProvider.IDENTITY_MAPPING_TARGET_REPOSITORY_ID, repositoryMapping.getParticipantRepositoryId(), true); Filter[] forwardFilter = { forwardSourceRepositoryFilter, forwardTargetRepositoryFilter }; Filter reverseSourceRepositoryFilter = new Filter( CcfDataProvider.IDENTITY_MAPPING_SOURCE_REPOSITORY_ID, repositoryMapping.getParticipantRepositoryId(), true); Filter reverseTargetRepositoryFilter = new Filter( CcfDataProvider.IDENTITY_MAPPING_TARGET_REPOSITORY_ID, repositoryMapping.getTeamForgeRepositoryId(), true); Filter[] reverseFilter = { reverseSourceRepositoryFilter, reverseTargetRepositoryFilter }; Filter[][] filter = { forwardFilter, reverseFilter }; IdentityMapping[] identityMappings = getCcfDataProvider().getIdentityMappings(landscape, filter); // First select source = TF, version != -1 for (IdentityMapping mapping : identityMappings) { if (mapping.getSourceSystemKind().startsWith("TF") && !mapping.getArtifactType().equals("attachment") && !"-1".equals(mapping.getSourceArtifactVersion()) && !"-1".equals(mapping.getTargetArtifactVersion())) { com.collabnet.ccf.api.model.IdentityMapping identityMapping = getIdentityMapping( mapping); if (!identityMappingList.contains(identityMapping.getSourceArtifactId() + identityMapping.getArtifactType())) { identityMapping.setRepositoryMapping( getRepositoryMapping(mapping, repositoryMappings)); try { getCcfMasterClient().createIdentityMapping(identityMapping); createdCount++; } catch (Exception e) { handleIdentityMappingMigrationError(mapping, e); } identityMappingList.add(identityMapping.getSourceArtifactId() + identityMapping.getArtifactType()); monitor.subTask( "Creating CCF Master identity mappings: " + getStatusMessage("")); } if (monitor.isCanceled()) { if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) { migrationResults .add(new MigrationResult(getStatusMessage("identity mappings"))); } canceled = true; return; } } } // Next, target = TF, version != -1 (and attachments) for (IdentityMapping mapping : identityMappings) { if (mapping.getTargetSystemKind().startsWith("TF") && (mapping.getArtifactType().equals("attachment") || (!"-1".equals(mapping.getSourceArtifactVersion()) && !"-1".equals(mapping.getTargetArtifactVersion())))) { com.collabnet.ccf.api.model.IdentityMapping identityMapping = getIdentityMapping( mapping); if (!identityMappingList.contains(identityMapping.getSourceArtifactId() + identityMapping.getArtifactType())) { identityMapping.setRepositoryMapping( getRepositoryMapping(mapping, repositoryMappings)); try { getCcfMasterClient().createIdentityMapping(identityMapping); createdCount++; } catch (Exception e) { handleIdentityMappingMigrationError(mapping, e); } identityMappingList.add(identityMapping.getSourceArtifactId() + identityMapping.getArtifactType()); monitor.subTask( "Creating CCF Master identity mappings: " + getStatusMessage("")); } if (monitor.isCanceled()) { if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) { migrationResults .add(new MigrationResult(getStatusMessage("identity mappings"))); } canceled = true; return; } } } // Next source = TF, version = -1 for (IdentityMapping mapping : identityMappings) { if (mapping.getSourceSystemKind().startsWith("TF") && !mapping.getArtifactType().equals("attachment") && ("-1".equals(mapping.getSourceArtifactVersion()) || "-1".equals(mapping.getTargetArtifactVersion()))) { com.collabnet.ccf.api.model.IdentityMapping identityMapping = getIdentityMapping( mapping); if (!identityMappingList.contains(identityMapping.getSourceArtifactId() + identityMapping.getArtifactType())) { identityMapping.setRepositoryMapping( getRepositoryMapping(mapping, repositoryMappings)); try { getCcfMasterClient().createIdentityMapping(identityMapping); createdCount++; } catch (Exception e) { handleIdentityMappingMigrationError(mapping, e); } identityMappingList.add(identityMapping.getSourceArtifactId() + identityMapping.getArtifactType()); monitor.subTask( "Creating CCF Master identity mappings: " + getStatusMessage("")); } if (monitor.isCanceled()) { if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) { migrationResults .add(new MigrationResult(getStatusMessage("identity mappings"))); } canceled = true; return; } } } // Finally target = TF, version = -1 for (IdentityMapping mapping : identityMappings) { if (mapping.getTargetSystemKind().startsWith("TF") && !mapping.getArtifactType().equals("attachment") && ("-1".equals(mapping.getSourceArtifactVersion()) || "-1".equals(mapping.getTargetArtifactVersion()))) { com.collabnet.ccf.api.model.IdentityMapping identityMapping = getIdentityMapping( mapping); if (!identityMappingList.contains(identityMapping.getSourceArtifactId() + identityMapping.getArtifactType())) { identityMapping.setRepositoryMapping( getRepositoryMapping(mapping, repositoryMappings)); try { getCcfMasterClient().createIdentityMapping(identityMapping); createdCount++; } catch (Exception e) { handleIdentityMappingMigrationError(mapping, e); } identityMappingList.add(identityMapping.getSourceArtifactId() + identityMapping.getArtifactType()); monitor.subTask( "Creating CCF Master identity mappings: " + getStatusMessage("")); } if (monitor.isCanceled()) { if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) { migrationResults .add(new MigrationResult(getStatusMessage("identity mappings"))); } canceled = true; return; } } } monitor.worked(1); } if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) { migrationResults.add(new MigrationResult(getStatusMessage("identity mappings"))); } if (monitor.isCanceled()) { canceled = true; return; } } catch (Exception e) { exception = e; return; } finally { monitor.done(); } } }; try { getContainer().run(true, true, runnable); } catch (Exception e) { Activator.handleError(e); if (e.getMessage() != null && e.getMessage().contains("<html>")) { MigrateLandscapeErrorDialog dialog = new MigrateLandscapeErrorDialog(getShell(), e); dialog.open(); } else { ExceptionDetailsErrorDialog.openError(getShell(), "Migrate Landscape to CCF 2.x", e.getMessage(), new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e)); } migrationResults.add(new MigrationResult(e)); return false; } if (exception != null) { Activator.handleError(exception); if (exception.getMessage() != null && exception.getMessage().contains("<html>")) { MigrateLandscapeErrorDialog dialog = new MigrateLandscapeErrorDialog(getShell(), exception); dialog.open(); } else { ExceptionDetailsErrorDialog.openError(getShell(), "Migrate Landscape to CCF 2.x", exception.getMessage(), new Status(IStatus.ERROR, Activator.PLUGIN_ID, exception.getLocalizedMessage(), exception)); } migrationResults.add(new MigrationResult(exception)); } if (showMigrationResults) { if (canceled) { migrationResults.add(new MigrationResult(new Exception("Migration canceled by user."))); } MigrationResult[] migrationResultArray = new MigrationResult[migrationResults.size()]; migrationResults.toArray(migrationResultArray); MigrateLandscapeResultsDialog dialog = new MigrateLandscapeResultsDialog(getShell(), migrationResultArray); if (dialog.open() == MigrateLandscapeResultsDialog.CANCEL) { return false; } } return exception == null && !canceled; }
From source file:com.collabnet.subversion.merge.actions.DeleteMergeOutputAction.java
License:Open Source License
public void run(IAction action) { ArrayList deletions = new ArrayList(); Iterator iter = fSelection.iterator(); while (iter.hasNext()) { Object object = iter.next(); if (object instanceof MergeOutput) { deletions.add(object);//from w ww .j a v a 2s . c o m } } if (deletions.size() == 0) return; String message; if (deletions.size() == 1) { MergeOutput mergeOutput = (MergeOutput) deletions.get(0); message = Messages.DeleteMergeOutputAction_confirm + mergeOutput.getEditableValue() + "'?"; //$NON-NLS-1$ } else { message = Messages.DeleteMergeOutputAction_confirmMultiple + deletions.size() + Messages.DeleteMergeOutputAction_confirmMultiple2; } if (!MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), Messages.DeleteMergeOutputAction_title, message)) return; iter = deletions.iterator(); while (iter.hasNext()) { MergeOutput mergeOutput = (MergeOutput) iter.next(); mergeOutput.delete(); } if (MergeResultsView.getView() != null) MergeResultsView.getView().refresh(); }