use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class MigrationUtil method getProblemsFromTreeNode.
@SuppressWarnings("rawtypes")
public static List<Problem> getProblemsFromTreeNode(ISelection selection) {
List<Problem> allProblems = new ArrayList<>();
if (selection instanceof IStructuredSelection) {
final IStructuredSelection ss = (IStructuredSelection) selection;
Iterator iterator = ss.iterator();
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof FileProblems) {
FileProblems fp = (FileProblems) element;
allProblems.addAll(fp.getProblems());
} else if (element instanceof MigrationProblems) {
MigrationProblems migrationProblems = (MigrationProblems) element;
for (FileProblems fProblems : migrationProblems.getProblems()) {
allProblems.addAll(fProblems.getProblems());
}
} else if (element instanceof MigrationProblemsContainer) {
MigrationProblemsContainer migrationProblemsContainer = (MigrationProblemsContainer) element;
for (MigrationProblems migrationProblems : migrationProblemsContainer.getProblemsArray()) {
for (FileProblems fProblems : migrationProblems.getProblems()) {
allProblems.addAll(fProblems.getProblems());
}
}
}
}
// remove duplicate problem
HashSet<Problem> hashSet = new HashSet<>(allProblems);
allProblems.clear();
allProblems.addAll(hashSet);
return allProblems;
}
return allProblems;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class MigrationUtil method getProblemsFromSelection.
public static List<Problem> getProblemsFromSelection(ISelection selection) {
final List<Problem> problems = new ArrayList<>();
if (selection instanceof IStructuredSelection) {
final IStructuredSelection ss = (IStructuredSelection) selection;
Iterator<?> elements = ss.iterator();
while (elements.hasNext()) {
Object element = elements.next();
if (element instanceof Problem) {
problems.add((Problem) element);
}
}
}
return problems;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class IgnoreAlwaysAction method run.
@Override
public void run() {
final Problem problem = MigrationUtil.getProblemFromSelection(getSelection());
_storeIgnoredProblem(problem);
new WorkspaceJob("Ignore all problems of this type") {
public IStatus runInWorkspace(IProgressMonitor monitor) {
IStatus retval = Status.OK_STATUS;
try {
FindBreakingChangesPage page = UpgradeView.getPage(Page.findbreackingchangesPageId, FindBreakingChangesPage.class);
TreeViewer treeViewer = page.getTreeViewer();
MigrationContentProvider contentProvider = (MigrationContentProvider) treeViewer.getContentProvider();
final MigrationProblemsContainer mpContainer = (MigrationProblemsContainer) contentProvider.getProblems().get(0);
final MigrationProblems[] projectProblem = mpContainer.getProblemsArray();
for (MigrationProblems pProblem : projectProblem) {
FileProblems[] fProblems = pProblem.getProblems();
for (FileProblems fp : fProblems) {
List<Problem> problems = fp.getProblems();
Iterator<Problem> iterator = problems.iterator();
while (iterator.hasNext()) {
Problem p = iterator.next();
if (p.getTicket().equals(problem.getTicket())) {
new IgnoreAction().run(p, _provider);
}
}
}
}
} catch (Exception e) {
retval = ProjectUI.createErrorStatus("Unable to get file from problem");
}
return retval;
}
}.schedule();
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class MigrationDecorator method decorate.
@Override
public void decorate(Object element, IDecoration decoration) {
final List<Problem> problems = new ArrayList<>();
final List<Problem> resolvedProblems = new ArrayList<>();
final List<Problem> ignoreProblems = new ArrayList<>();
if (element instanceof FileProblems) {
final FileProblems fileProblems = (FileProblems) element;
problems.addAll(fileProblems.getProblems());
resolvedProblems.addAll(fileProblems.getProblems(Problem.STATUS_RESOLVED));
ignoreProblems.addAll(fileProblems.getProblems(Problem.STATUS_IGNORE));
} else if (element instanceof UpgradeProblems) {
final UpgradeProblems upgradeProblems = (UpgradeProblems) element;
for (FileProblems fileProblems : upgradeProblems.getProblems()) {
problems.addAll(fileProblems.getProblems());
resolvedProblems.addAll(fileProblems.getProblems(Problem.STATUS_RESOLVED));
ignoreProblems.addAll(fileProblems.getProblems(Problem.STATUS_IGNORE));
}
} else if (element instanceof ProblemsContainer) {
ProblemsContainer problemsContainer = (ProblemsContainer) element;
for (UpgradeProblems upgradeProblems : problemsContainer.getProblemsArray()) {
for (FileProblems fileProblems : upgradeProblems.getProblems()) {
problems.addAll(fileProblems.getProblems());
resolvedProblems.addAll(fileProblems.getProblems(Problem.STATUS_RESOLVED));
ignoreProblems.addAll(fileProblems.getProblems(Problem.STATUS_IGNORE));
}
}
}
if (ListUtil.isNotEmpty(problems)) {
StringBuilder sb = new StringBuilder();
sb.append("[");
sb.append(problems.size()).append(" total");
if (ListUtil.isNotEmpty(resolvedProblems)) {
sb.append(", ");
sb.append(resolvedProblems.size());
sb.append(" resolved");
}
if (ListUtil.isNotEmpty(ignoreProblems)) {
sb.append(", ");
sb.append(ignoreProblems.size());
sb.append(" ignored");
}
sb.append("]");
decoration.addSuffix(sb.toString());
}
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class AutoCorrectAction method selectionChanged.
@Override
public void selectionChanged(IStructuredSelection selection) {
if (selection.isEmpty()) {
setEnabled(false);
} else {
boolean selectionCompatible = true;
Iterator<?> items = selection.iterator();
Object lastItem = null;
while (items.hasNext()) {
Object item = items.next();
if (!(item instanceof Problem)) {
selectionCompatible = false;
break;
}
Problem problem = (Problem) item;
if (problem.autoCorrectContext == null) {
selectionCompatible = false;
break;
}
if (lastItem != null) {
String prCurrentKey = ((Problem) item).autoCorrectContext.substring(0, problem.autoCorrectContext.indexOf(":"));
String prLastKey = ((Problem) lastItem).autoCorrectContext.substring(0, problem.autoCorrectContext.indexOf(":"));
if (!(prCurrentKey.equals(prLastKey))) {
selectionCompatible = false;
break;
}
}
lastItem = item;
}
Iterator<?> items2 = selection.iterator();
List<String> autoCorrectContexts = new ArrayList<>();
while (items2.hasNext()) {
Object item = items2.next();
if (item instanceof Problem && ((Problem) item).autoCorrectContext != null) {
autoCorrectContexts.add(((Problem) item).autoCorrectContext);
}
}
setEnabled(selectionCompatible);
List<String> allAutoCorrectContexts = new ArrayList<>();
if (_provider instanceof TableViewer) {
TableViewer viewer = (TableViewer) _provider;
Object obj = viewer.getInput();
if (obj instanceof Object[]) {
Object[] problems = (Object[]) obj;
for (Object o : problems) {
if (o instanceof Problem && ((Problem) o).autoCorrectContext != null) {
allAutoCorrectContexts.add(((Problem) o).autoCorrectContext);
}
}
} else if (obj instanceof List<?>) {
List<?> list = (List<?>) obj;
for (Object p : list) {
if (p instanceof Problem) {
Problem problem = (Problem) p;
if (problem.autoCorrectContext != null) {
allAutoCorrectContexts.add(problem.autoCorrectContext);
}
}
}
}
}
setText("Correct automatically");
}
}
Aggregations