use of org.talend.core.ui.editor.JobEditorInput in project tdi-studio-se by Talend.
the class AbstractTalendEditor method setInput.
// ------------------------------------------------------------------------
// Overridden from EditorPart
@Override
protected void setInput(final IEditorInput input) {
super.setInput(input);
try {
if (input instanceof JobEditorInput) {
// process = ((JobEditorInput) input).getLoadedProcess();
projectName = CorePlugin.getDefault().getProxyRepositoryFactory().getProject(((RepositoryEditorInput) input).getItem()).getLabel();
}
} catch (Exception e) {
MessageBoxExceptionHandler.process(e);
return;
}
IProcess2 process = getProcess();
if (process != null && process.getProperty().getItem() instanceof ProcessItem) {
currentJobResource.setJobInfo(new JobInfo((ProcessItem) process.getProperty().getItem(), process.getProperty(), process.getContextManager().getDefaultContext().getName()));
currentJobResource.setProjectName(projectName);
JobResourceManager.getInstance().addProtection(this);
}
}
use of org.talend.core.ui.editor.JobEditorInput in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method init.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.MultiPageEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
*/
@Override
public void init(final IEditorSite site, IEditorInput editorInput) throws PartInitException {
setSite(site);
setInput(editorInput);
if (!(editorInput instanceof JobEditorInput)) {
return;
}
site.setSelectionProvider(new MultiPageTalendSelectionProvider(this));
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
// Lock the process :
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
processEditorInput = (JobEditorInput) editorInput;
final IProcess2 currentProcess = processEditorInput.getLoadedProcess();
if (!currentProcess.isReadOnly()) {
try {
Property property = processEditorInput.getItem().getProperty();
propertyInformation = new ArrayList(property.getInformations());
property.eAdapters().add(dirtyListener);
repFactory.lock(currentProcess);
boolean locked = repFactory.getStatus(currentProcess) == ERepositoryStatus.LOCK_BY_USER;
if (!locked) {
setReadOnly(true);
}
revisionChanged = true;
} catch (PersistenceException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
} catch (BusinessException e) {
// Nothing to do
ExceptionHandler.process(e);
}
} else {
setReadOnly(true);
Bundle bundle = FrameworkUtil.getBundle(AbstractMultiPageTalendEditor.class);
final Display display = getSite().getShell().getDisplay();
this.lockService = bundle.getBundleContext().registerService(EventHandler.class.getName(), new EventHandler() {
@Override
public void handleEvent(Event event) {
String lockTopic = Constant.REPOSITORY_ITEM_EVENT_PREFIX + Constant.ITEM_LOCK_EVENT_SUFFIX;
if (lockTopic.equals(event.getTopic())) {
Object o = event.getProperty(Constant.ITEM_EVENT_PROPERTY_KEY);
if (o != null && o instanceof Item) {
Item item = (Item) o;
String itemId = item.getProperty().getId();
if (itemId.equals(currentProcess.getId())) {
if (currentProcess.isReadOnly()) {
boolean readOnly = currentProcess.checkReadOnly();
boolean orginalReadOnlyStatus = designerEditor.isReadOnly();
setReadOnly(readOnly);
if (!readOnly) {
display.asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
}
});
if (orginalReadOnlyStatus == true) {
// refresh to the given item version, nomally it is the latest
// version,
// means the editor/process will be refreshed to the latest version
refreshProcess(item, false);
}
Property property = processEditorInput.getItem().getProperty();
propertyInformation = new ArrayList(property.getInformations());
property.eAdapters().add(dirtyListener);
}
}
}
}
}
}
}, new Hashtable<String, String>(Collections.singletonMap(EventConstants.EVENT_TOPIC, //$NON-NLS-1$
Constant.REPOSITORY_ITEM_EVENT_PREFIX + "*")));
revisionChanged = true;
}
// setTitleImage(ImageProvider.getImage(getEditorTitleImage()));
updateTitleImage(processEditorInput.getItem().getProperty());
getSite().getWorkbenchWindow().getPartService().addPartListener(partListener);
}
use of org.talend.core.ui.editor.JobEditorInput in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method turnToJobScriptPage.
protected void turnToJobScriptPage(int newPageIndex) {
if (jobletEditor != getEditor(newPageIndex)) {
return;
}
ICreateXtextProcessService convertJobtoScriptService = CorePlugin.getDefault().getCreateXtextProcessService();
try {
final String scriptValue = convertJobtoScriptService.convertJobtoScript(getProcess().saveXmlFile());
IFile file = (IFile) jobletEditor.getEditorInput().getAdapter(IResource.class);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(scriptValue.getBytes());
if (file.exists()) {
jobletEditor.getDocumentProvider().getDocument(jobletEditor.getEditorInput()).set(scriptValue);
boolean isProcessReadOnly = ((JobEditorInput) getEditor(0).getEditorInput()).isReadOnly();
IProxyRepositoryFactory rFactory = ProxyRepositoryFactory.getInstance();
if (isProcessReadOnly || rFactory.isUserReadOnlyOnCurrentProject()) {
IDocumentProvider provider = jobletEditor.getDocumentProvider();
Class p = provider.getClass();
Class[] type = new Class[1];
type[0] = Boolean.TYPE;
Object[] para = new Object[1];
para[0] = Boolean.TRUE;
Method method = p.getMethod("setReadOnly", type);
method.invoke(provider, para);
}
//$NON-NLS-1$
IAction action = jobletEditor.getAction("FoldingRestore");
action.run();
jobletEditor.doSave(null);
} else {
file.create(byteArrayInputStream, true, null);
}
if (propertyListener == null) {
propertyListener = new IPropertyListener() {
@Override
public void propertyChanged(Object source, int propId) {
if (source instanceof IEditorPart && ((IEditorPart) source).isDirty()) {
getProcess().setProcessModified(true);
getProcess().setNeedRegenerateCode(true);
}
}
};
jobletEditor.addPropertyListener(propertyListener);
}
} catch (PartInitException e) {
ExceptionHandler.process(e);
} catch (CoreException e) {
ExceptionHandler.process(e);
} catch (IOException e) {
ExceptionHandler.process(e);
} catch (SecurityException e) {
ExceptionHandler.process(e);
} catch (NoSuchMethodException e) {
ExceptionHandler.process(e);
} catch (IllegalArgumentException e) {
ExceptionHandler.process(e);
} catch (IllegalAccessException e) {
ExceptionHandler.process(e);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
}
changeContextsViewStatus(false);
}
use of org.talend.core.ui.editor.JobEditorInput in project tdi-studio-se by Talend.
the class OpenExistVersionProcessAction method getCorrespondingEditor.
@Override
protected IEditorPart getCorrespondingEditor(IRepositoryNode node) {
IEditorReference[] eidtors = getActivePage().getEditorReferences();
for (IEditorReference eidtor : eidtors) {
try {
IEditorInput input = eidtor.getEditorInput();
if (!(input instanceof JobEditorInput)) {
continue;
}
JobEditorInput repositoryInput = (JobEditorInput) input;
checkUnLoadedNodeForProcess(repositoryInput);
if (repositoryInput.getItem().equals(node.getObject().getProperty().getItem())) {
IPath path = repositoryInput.getFile().getLocation();
return eidtor.getEditor(false);
}
} catch (PartInitException e) {
continue;
}
}
return null;
}
use of org.talend.core.ui.editor.JobEditorInput in project tdi-studio-se by Talend.
the class ContextsView method handleDropContext.
/*
* (non-Javadoc)
*
* @see org.talend.core.ui.context.view.AbstractContextView#handleDrop(org.talend.core.model.properties.ContextItem,
* java.util.Set, org.eclipse.ui.IEditorInput)
*/
@Override
protected boolean handleDropContext(ContextItem contextItem, Set<String> contextSet, IEditorInput editorInput) {
boolean created = false;
if (editorInput instanceof JobEditorInput) {
JobEditorInput jobInput = (JobEditorInput) editorInput;
IProcess2 process = jobInput.getLoadedProcess();
IContextManager contextManager = process.getContextManager();
// context group will reflect absolutely if no context variable in contextViewer
if (!ConnectionContextHelper.containsVariable(contextManager)) {
// for bug 15608
ConnectionContextHelper.addContextVarForJob(process, contextItem, contextManager);
// ConnectionContextHelper.checkAndAddContextsVarDND(contextItem,
// contextManager);
created = true;
} else {
Set<String> addedContext = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, contextManager, false);
if (addedContext != null && addedContext.size() > 0) {
ConnectionContextHelper.addContextVarForJob(process, contextItem, contextSet);
created = true;
}
}
}
return created;
}
Aggregations