use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.
the class UpdateManagerUtils method refreshRelatedViewers.
/**
*
* ggu Comment method "refreshViewers".
*/
@SuppressWarnings("unchecked")
private static void refreshRelatedViewers(List results) {
boolean context = false;
boolean jobSetting = false;
boolean componentSettings = false;
boolean palette = false;
for (UpdateResult result : (List<UpdateResult>) results) {
// if (!result.isChecked()) {
// continue;
// }
IUpdateItemType updateType = result.getUpdateType();
if (updateType != null) {
if (EUpdateItemType.CONTEXT.equals(updateType)) {
if (result.isJoblet() && !result.isChecked()) {
continue;
}
context = true;
} else if (EUpdateItemType.JOB_PROPERTY_EXTRA.equals(updateType) || EUpdateItemType.JOB_PROPERTY_STATS_LOGS.equals(updateType) || EUpdateItemType.JOB_PROPERTY_HEADERFOOTER.equals(updateType)) {
jobSetting = true;
} else if (EUpdateItemType.NODE_PROPERTY.equals(updateType) || EUpdateItemType.NODE_QUERY.equals(updateType) || EUpdateItemType.NODE_SCHEMA.equals(updateType)) {
componentSettings = true;
} else if (EUpdateItemType.RELOAD.equals(updateType) || EUpdateItemType.JOBLET_RENAMED.equals(updateType) || EUpdateItemType.JOBLET_SCHEMA.equals(updateType)) {
if (result.isJoblet() && !result.isChecked()) {
continue;
}
palette = true;
}
}
}
// recheck from the providers
Set<String> viewIds = UpdateManagerProviderDetector.INSTANCE.needRefreshRelatedViews(results);
// context
if (!context) {
context = viewIds.contains(AbstractContextView.CTX_ID_DESIGNER);
}
if (context) {
Contexts.switchToCurContextsView();
}
// jobsetting
if (!jobSetting) {
jobSetting = viewIds.contains(JobSettingsView.ID);
}
if (jobSetting) {
JobSettings.switchToCurJobSettingsView();
}
// component setting
if (!componentSettings) {
componentSettings = viewIds.contains(ComponentSettingsView.ID);
}
if (componentSettings) {
ComponentSettings.switchToCurComponentSettingsView();
}
// }
if (palette) {
ComponentPaletteUtilities.updatePalette();
}
}
use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.
the class UpdateManagerUtils method doExecuteUpdates.
private static boolean doExecuteUpdates(final List<UpdateResult> results, final boolean updateAllJobs) {
if (results == null || results.isEmpty()) {
return false;
}
try {
IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
monitor.setCanceled(false);
int size = (results.size() * 2 + 1) * UpdatesConstants.SCALE;
//$NON-NLS-1$
monitor.beginTask(Messages.getString("UpdateManagerUtils.Update"), size);
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
// first list by job we need to update
Map<String, Set<String>> jobIdToVersion = new HashMap<String, Set<String>>();
Map<String, Boolean> jobIdClosed = new HashMap<String, Boolean>();
for (UpdateResult result : results) {
// if (!result.isChecked()) {
// continue;
// }
String id = result.getObjectId();
String version = result.getObjectVersion();
if (id == null) {
if (result.getJob() != null && result.getJob() instanceof IProcess) {
IProcess process = (IProcess) result.getJob();
if (process instanceof IProcess2 && ERepositoryStatus.LOCK_BY_OTHER.equals(factory.getStatus(((IProcess2) process).getProperty().getItem()))) {
// file.
continue;
}
id = process.getId();
version = process.getVersion();
result.setObjectId(id);
result.setObjectVersion(version);
} else {
continue;
}
}
Set<String> versionList;
if (!jobIdToVersion.containsKey(id)) {
versionList = new HashSet<String>();
jobIdToVersion.put(id, versionList);
} else {
versionList = jobIdToVersion.get(id);
}
versionList.add(version);
//$NON-NLS-1$
jobIdClosed.put(id + " - " + version, result.isFromItem());
}
// now will execute updates only for the job selected depends this list.
for (String currentId : jobIdToVersion.keySet()) {
for (String version : jobIdToVersion.get(currentId)) {
IRepositoryViewObject currentObj = null;
//$NON-NLS-1$
boolean closedItem = jobIdClosed.get(currentId + " - " + version);
IProcess process = null;
Item item = null;
if (closedItem) {
// if item is closed, then just load it.
boolean checkOnlyLastVersion = Boolean.parseBoolean(DesignerPlugin.getDefault().getPreferenceStore().getString(//$NON-NLS-1$
"checkOnlyLastVersion"));
try {
if (checkOnlyLastVersion || version == null) {
currentObj = factory.getLastVersion(currentId);
} else {
List<IRepositoryViewObject> allVersion = factory.getAllVersion(currentId);
for (IRepositoryViewObject obj : allVersion) {
if (obj.getVersion().equals(version)) {
currentObj = obj;
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (currentObj == null) {
// item not found, don't do anything
continue;
}
item = currentObj.getProperty().getItem();
IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
if (item instanceof ProcessItem) {
process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
} else if (item instanceof JobletProcessItem) {
process = designerCoreService.getProcessFromJobletProcessItem((JobletProcessItem) item);
}
}
for (UpdateResult result : results) {
// }
if (!StringUtils.equals(currentId, result.getObjectId())) {
// not the current job we need to update
continue;
}
if (closedItem) {
if (result.getJob() == null) {
result.setJob(process);
} else {
process = (IProcess) result.getJob();
}
IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
if (process != null && jobletContextType != null && (jobletContextType.equals(result.getUpdateType()))) {
if ((result.getParameter() instanceof List) && process.getContextManager() != null) {
process.getContextManager().setListContext((List<IContext>) result.getParameter());
}
}
}
// execute
executeUpdate(result, monitor, updateAllJobs);
if (closedItem) {
result.setJob(null);
}
}
boolean isTestContainer = false;
ITestContainerProviderService testContainerService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
isTestContainer = testContainerService.isTestContainerItem(item);
}
}
if (closedItem && process instanceof IProcess2) {
IProcess2 process2 = (IProcess2) process;
ProcessType processType;
try {
processType = process2.saveXmlFile(false);
if (isTestContainer) {
testContainerService.setTestContainerProcess(processType, item);
} else if (item instanceof JobletProcessItem) {
((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
} else {
((ProcessItem) item).setProcess(processType);
}
factory.save(item);
} catch (IOException e) {
ExceptionHandler.process(e);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
if (closedItem && !ERepositoryStatus.LOCK_BY_USER.equals(factory.getStatus(item))) {
// unload item from memory, but only if this one is not locked by current user.
try {
factory.unloadResources(item.getProperty());
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
UpdateManagerProviderDetector.INSTANCE.postUpdate(results);
// update joblet reference
upadateJobletReferenceInfor();
final List<UpdateResult> tempResults = new ArrayList<UpdateResult>(results);
// refresh
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
refreshRelatedViewers(tempResults);
// hyWang add method checkandRefreshProcess for bug7248
checkandRefreshProcess(tempResults);
}
});
monitor.worked(1 * UpdatesConstants.SCALE);
monitor.done();
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
}
return !results.isEmpty();
} finally {
results.clear();
}
}
use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.
the class UpdateManagerUtils method executeUpdate.
private static void executeUpdate(UpdateResult result, IProgressMonitor monitor, boolean updateAllJobs) {
if (result.isReadOnlyProcess()) {
return;
}
// update
Command command = null;
IUpdateItemType updateType = result.getUpdateType();
if (updateType instanceof EUpdateItemType) {
switch((EUpdateItemType) updateType) {
case NODE_PROPERTY:
case NODE_SCHEMA:
case NODE_QUERY:
case NODE_SAP_IDOC:
case NODE_SAP_FUNCTION:
case NODE_VALIDATION_RULE:
command = new UpdateNodeParameterCommand(result);
break;
case JOB_PROPERTY_EXTRA:
case JOB_PROPERTY_STATS_LOGS:
case JOB_PROPERTY_HEADERFOOTER:
case JOB_PROPERTY_STORM:
case JOB_PROPERTY_MAPREDUCE:
command = new UpdateMainParameterCommand(result);
break;
case CONTEXT:
command = executeContextUpdates(result);
break;
case CONTEXT_GROUP:
command = executeContextGroupUpdates(result);
break;
case JOBLET_RENAMED:
case JOBLET_SCHEMA:
case RELOAD:
command = executeJobletNodesUpdates(result);
break;
case JUNIT_RELOAD:
command = executeJunitNodesUpdates(result);
break;
// break;
case MAP_PATH:
command = new UpdateNodePathCommand(result);
break;
default:
break;
}
}
if (command != null) {
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1 * UpdatesConstants.SCALE, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask(UpdatesConstants.EMPTY, 1);
subMonitor.subTask(getResultTaskInfor(result));
//
Object job = result.getJob();
boolean executed = false;
if (job != null && job instanceof IGEFProcess) {
IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
if (designerCoreUIService != null) {
executed = designerCoreUIService.executeCommand((IGEFProcess) job, command);
}
}
if (!executed) {
command.execute();
}
subMonitor.worked(1);
}
// from extension point
UpdateManagerProviderDetector.INSTANCE.doUpdate(monitor, result);
}
use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.
the class UpdateViewerHelper method checkItemResultState.
private void checkItemResultState(Item item, boolean state) {
if (item == null) {
return;
}
List<IProcess2> openedProcesses = UpdateManagerUtils.getOpenedProcess();
boolean isOpened = openedProcesses.contains(item.getResultObject().getJob());
boolean jobletUpdate = false;
boolean jobletContext = false;
if (item.getParent() != null && item.getParent().getNode() != null && (item.getParent().getNode() instanceof Node) && ((Node) item.getParent().getNode()).isJoblet()) {
jobletUpdate = true;
}
IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
if (jobletContextType != null && item.getParent() != null && jobletContextType.equals(item.getParent().getType())) {
jobletContext = true;
}
// not checked
if (!state && !item.getResultObject().isReadOnly()) {
EUpdateResult resultType = item.getResultObject().getResultType();
if (resultType == EUpdateResult.UPDATE || resultType == EUpdateResult.ADD || resultType == EUpdateResult.DELETE) {
item.setChecked(false);
} else if ((jobletUpdate || jobletContext) && !isOpened && (resultType == EUpdateResult.JOBLET_UPDATE || resultType == EUpdateResult.RELOAD)) {
item.setChecked(state);
}
} else if (item.getResultObject().isReadOnly() && jobletUpdate) {
return;
} else {
// keep the checked
item.setChecked(true);
}
}
use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.
the class UpdateNodePathCommand method execute.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.commands.Command#execute()
*/
@Override
public void execute() {
IUpdateItemType updateType = result.getUpdateType();
if (result == null || updateType == null) {
return;
}
Object updateObject = result.getUpdateObject();
if (updateObject == null || (!(updateObject instanceof Node))) {
return;
}
// instance of node before might not be good (loaded while check updates needed)
// so get the instance of the node of the current job in this object.
IProcess process = (IProcess) result.getJob();
for (INode node : process.getGraphicalNodes()) {
if (node.getUniqueName().equals(((Node) updateObject).getUniqueName())) {
updateObject = node;
result.setUpdateObject(updateObject);
break;
}
}
Node node = (Node) updateObject;
if (updateType instanceof EUpdateItemType) {
switch((EUpdateItemType) updateType) {
case MAP_PATH:
Object parameter = result.getParameter();
if (!(parameter instanceof List)) {
return;
}
List<Object> params = (List<Object>) parameter;
if (params.size() != 3) {
return;
}
IElementParameter param = (IElementParameter) params.get(0);
if (param == null) {
return;
}
String oldPath = (String) params.get(1);
String newPath = (String) params.get(2);
String relativeNewPath = new Path(newPath).removeFirstSegments(2).removeFileExtension().toPortableString();
String fullOldPath = new Path(oldPath).removeFileExtension().toPortableString();
String relativeOldPath = new Path(oldPath).removeFirstSegments(2).removeFileExtension().toPortableString();
Object value = TalendTextUtils.removeQuotes(String.valueOf(param.getValue()));
if (!fullOldPath.equals(value) && !relativeOldPath.equals(value)) {
return;
}
if (fullOldPath.equals(value)) {
String newValue = TalendTextUtils.addQuotes(new Path(newPath).removeFileExtension().toPortableString());
param.setValue(newValue);
} else if (relativeOldPath.equals(value)) {
param.setValue(TalendTextUtils.addQuotes(relativeNewPath));
}
break;
default:
}
}
if (node.getProcess() instanceof IProcess2) {
PropertyChangeCommand pcc = new PropertyChangeCommand(node, EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
boolean executed = false;
if (process instanceof IGEFProcess) {
IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
if (designerCoreUIService != null) {
executed = designerCoreUIService.executeCommand((IGEFProcess) process, pcc);
}
}
if (!executed) {
pcc.execute();
}
}
}
Aggregations