use of org.eclipse.ui.IWorkbenchPart in project translationstudio8 by heartsome.
the class ExportDocxHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
IFile file = null;
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
// ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
ArrayList<IFile> lstXliff = new ArrayList<IFile>();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile tempFile = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
lstXliff.add(tempFile);
}
}
}
if (lstXliff.size() > 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg1"));
return null;
}
if (lstXliff.size() == 1) {
file = lstXliff.get(0);
}
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IXliffEditor xliffEditor = (IXliffEditor) editor;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
return null;
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
file = iFile;
}
}
if (file != null) {
XLFValidator.resetFlag();
if (!XLFValidator.validateXliffFile(file)) {
return null;
}
XLFValidator.resetFlag();
}
ExportDocxDialog dialog = new ExportDocxDialog(shell, file == null ? "" : file.getFullPath().toOSString(), file == null ? "" : ResourceUtils.iFileToOSPath(file));
dialog.open();
return null;
}
use of org.eclipse.ui.IWorkbenchPart in project tdi-studio-se by Talend.
the class ClipboardActionHandler method getCommand.
@Override
public ICommand getCommand(IGlobalActionContext cntxt) {
IWorkbenchPart part = cntxt.getActivePart();
if (!(part instanceof IDiagramWorkbenchPart)) {
return null;
}
IDiagramWorkbenchPart workbenchPart = (IDiagramWorkbenchPart) part;
DiagramEditPart diagramEditPart = workbenchPart.getDiagramEditPart();
ICommand command = null;
String actionId = cntxt.getActionId();
if (actionId.equals(GlobalActionId.COPY)) {
command = getCopyCommand(cntxt, workbenchPart, false);
transfer(cntxt.getSelection());
isCut = false;
older = workbenchPart;
orginalCopyFrom = workbenchPart;
clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
} else if (actionId.equals(GlobalActionId.CUT) && cntxt.getSelection() != null) {
saveCut(cntxt.getSelection());
command = getCutCommand(cntxt, workbenchPart);
transfer(cntxt.getSelection());
isCut = true;
older = workbenchPart;
clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
} else if (actionId.equals(GlobalActionId.SAVE)) {
if (workbenchPart instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart) workbenchPart;
if (editorPart.isDirty()) {
IWorkbenchPage page = editorPart.getSite().getPage();
page.saveEditor(editorPart, false);
}
}
}
if (actionId.equals(GlobalActionId.PASTE)) {
// diagramPart.getDiagramGraphicalViewer().setSelection(new
// StructuredSelection(diagramPart.getDiagramEditPart()));
PasteViewRequest pasteReq = createPasteViewRequest();
CommandStack cs = workbenchPart.getDiagramEditDomain().getDiagramCommandStack();
IStructuredSelection selection = (IStructuredSelection) cntxt.getSelection();
if (!(selection.getFirstElement() instanceof BusinessProcessEditPart)) {
selection = new StructuredSelection(workbenchPart.getDiagramEditPart());
}
Object[] objects = selection.toArray();
Collection returnValues = null;
if (objects.length == 1) {
Command paste = ((EditPart) objects[0]).getCommand(pasteReq);
if (paste != null) {
cs.execute(paste);
workbenchPart.getDiagramEditPart().getFigure().invalidate();
workbenchPart.getDiagramEditPart().getFigure().validate();
returnValues = DiagramCommandStack.getReturnValues(paste);
// selectAddedObject(diagramPart.getDiagramGraphicalViewer(), returnValues);
}
}
Object elements = TemplateTransfer.getInstance().getObject();
if (elements instanceof List) {
List<BusinessItem> list = (List<BusinessItem>) elements;
boolean inEditors = false;
if (older != workbenchPart) {
inEditors = true;
} else if (!this.isCut && orginalCopyFrom != workbenchPart) {
// bug 16065 fixed, by xtan. to resolve the copy(A)/parse(B)/parse(B)/parse(B)... problem.
inEditors = true;
}
// always keep the last one as the current selection.
older = workbenchPart;
GmfPastCommand pastBusiness = new GmfPastCommand((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement(), list, diagramEditPart, this.cutItemIds, this.isCut | inEditors);
pastBusiness.setClonedSourceProcessItemsList(clonedSourceProcessItemsList);
try {
pastBusiness.execute(null, null);
} catch (ExecutionException e) {
ExceptionHandler.process(e);
}
}
if (returnValues != null) {
selectAddedObject(workbenchPart.getDiagramGraphicalViewer(), returnValues);
}
return null;
}
return command;
}
use of org.eclipse.ui.IWorkbenchPart in project tdi-studio-se by Talend.
the class NodePart method performRequest.
@Override
public void performRequest(Request req) {
Node node = (Node) getModel();
IExternalData oldExternalData = node.getExternalData();
if (req.getType().equals(RequestConstants.REQ_OPEN)) {
IExternalNode externalNode = null;
if (node.isExternalNode()) {
IElementParameter externalParam = node.getElementParameterFromField(EParameterFieldType.EXTERNAL);
if (externalParam != null && externalParam.isShow(node.getElementParameters())) {
externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
}
}
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (externalNode != null && (part instanceof AbstractMultiPageTalendEditor)) {
boolean isOriginalNode = false;
ITestContainerProviderService testContainerService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
isOriginalNode = testContainerService.isOriginalNode(node);
if (isOriginalNode) {
testContainerService.renameConnection(node, true);
}
}
}
int returnValue = externalNode.open(getViewer().getControl().getShell());
if (!node.isReadOnly()) {
if (returnValue == SWT.OK) {
Command cmd = new ExternalNodeChangeCommand(node, externalNode, oldExternalData);
CommandStack cmdStack = (CommandStack) part.getAdapter(CommandStack.class);
cmdStack.execute(cmd);
} else {
externalNode.setExternalData(oldExternalData);
}
}
if (isOriginalNode && (testContainerService != null)) {
testContainerService.renameConnection(node, false);
}
} else {
// add for feature 13361
boolean isJoblet = false;
if (PluginChecker.isJobLetPluginLoaded()) {
AbstractProcessProvider jobletProcessProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
final IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
boolean isAvoidShowJobletAfterDoubleClick = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
IComponentsLocalProviderService componentService = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
if (componentService != null) {
isAvoidShowJobletAfterDoubleClick = componentService.isAvoidToShowJobletAfterDoubleClick();
}
}
if (service != null && service.isJobletComponent(node) && !isAvoidShowJobletAfterDoubleClick) {
isJoblet = true;
String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
final Item jobletItem = jobletProcessProvider.getJobletItem(node, version);
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
if (jobletItem != null) {
service.openJobletItem((JobletProcessItem) jobletItem);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
}
}
if (!isJoblet) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String processName = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_PROCESS.getName());
String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
boolean isAvoidShowJobAfterDoubleClick = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
if (service != null) {
isAvoidShowJobAfterDoubleClick = service.isAvoidToShowJobAfterDoubleClick();
}
}
// bug 20796
boolean isSelectUseDynamic = false;
Object useDynamicJobValue = node.getPropertyValue(EParameterName.USE_DYNAMIC_JOB.getName());
if (useDynamicJobValue != null && useDynamicJobValue instanceof Boolean) {
isSelectUseDynamic = (Boolean) useDynamicJobValue;
}
if (processName != null && !"".equals(processName) && !isAvoidShowJobAfterDoubleClick && !isSelectUseDynamic) {
//$NON-NLS-1$
ItemCacheManager.clearCache();
ProcessItem processItem = ItemCacheManager.getProcessItem(processName, version);
if (processItem == null) {
return;
}
Property updatedProperty = null;
try {
updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(processItem)), processName).getProperty();
} catch (PersistenceException e) {
CommonExceptionHandler.process(e);
}
// update the property of the node repository object
// node.getObject().setProperty(updatedProperty);
processItem = (ProcessItem) updatedProperty.getItem();
final ProcessItem item = processItem;
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
try {
if (item != null) {
ERepositoryObjectType repObjType = ERepositoryObjectType.getItemType(item);
IJobEditorHandler editorInputFactory = JobEditorHandlerManager.getInstance().extractEditorInputFactory(repObjType.getType());
editorInputFactory.openJobEditor(editorInputFactory.createJobEditorInput(item, true));
}
} catch (PartInitException e) {
MessageBoxExceptionHandler.process(e);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
} else {
try {
// modified for feature 2454.
page.showView(ComponentSettingsView.ID);
} catch (PartInitException e) {
CommonExceptionHandler.process(e);
}
}
}
}
}
super.performRequest(req);
}
use of org.eclipse.ui.IWorkbenchPart in project tdi-studio-se by Talend.
the class ActiveProcessTracker method getJobFromActivatedEditor.
public IProcess2 getJobFromActivatedEditor(IWorkbenchPart part) {
IWorkbenchPart testedPart = part;
if (!(part instanceof AbstractMultiPageTalendEditor)) {
testedPart = part.getSite().getWorkbenchWindow().getActivePage().getActiveEditor();
}
if (testedPart instanceof AbstractMultiPageTalendEditor) {
AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) testedPart;
mpte.setName();
IProcess2 process = mpte.getTalendEditor().getProcess();
return process;
} else {
// No editor
}
return null;
}
use of org.eclipse.ui.IWorkbenchPart in project tdi-studio-se by Talend.
the class AbstractElementPropertySectionController method fixedCursorPosition.
/**
* qzhang Comment method "fixedCursorPosition".
*
* @param param
* @param labelText
* @param value
* @param valueChanged
*/
protected void fixedCursorPosition(IElementParameter param, Control labelText, Object value, boolean valueChanged) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkbenchPart workbenchPart = page.getActivePart();
if ((workbenchPart instanceof PropertySheet) || (workbenchPart instanceof JobSettingsView) || (workbenchPart instanceof ComponentSettingsView)) {
Object control = editionControlHelper.undoRedoHelper.typedTextCommandExecutor.getActiveControl();
if (param.getName().equals(control) && valueChanged && !param.isRepositoryValueUsed()) {
String previousText = editionControlHelper.undoRedoHelper.typedTextCommandExecutor.getPreviousText2();
String currentText = String.valueOf(value);
labelText.setFocus();
ControlUtils.setCursorPosition(labelText, getcursorPosition(previousText, currentText));
}
}
}
Aggregations