Skip to content
Snippets Groups Projects
Commit 5c06c6cd authored by Andreas Wandinger's avatar Andreas Wandinger
Browse files

Removed Windows line encoding.

refs 587
parent cf6ba315
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.views;
import java.util.Set;
import org.conqat.lib.commons.collections.IdentityHashSet;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.eclipse.ui.part.ViewPart;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.service.IPrototypeService;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.extension.base.EditorBase;
import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor;
import org.fortiss.tooling.kernel.ui.listener.ExtendableMultiPageEditorPageChangeListener;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
* {@link ViewPart} for the model element library view.
*
* @author hoelzl
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: BCCA1EB912DDAD468B639287D818733B
*/
public class LibraryView extends ViewPart {
/** The viewer. */
private TreeViewer viewer;
/** Filter text field for the tree viewer. */
private FilteredTree filteredTree;
/** Current active {@link ExtendableMultiPageEditor}. */
private ExtendableMultiPageEditor activeBindingEditor = null;
/** Stores the editor activation listener. */
private EditorActivationListener editorActivationListener = new EditorActivationListener();
/** The container object used. */
private EObject containerObject = null;
/** The prototypes supported by the current editor. */
private Set<Prototype> supportedBaseClasses = new IdentityHashSet<Prototype>();
/** Listener for reacting to changes of the embedded editor. */
private final ExtendableMultiPageEditorPageChangeListener bindingEditorPageChangeListener = new ExtendableMultiPageEditorPageChangeListener() {
@Override
public void pageChanged() {
updateEditorFilters(activeBindingEditor.getActiveModelEditor());
}
};
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
filteredTree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL
| SWT.V_SCROLL, patternFilter, false);
viewer = filteredTree.getViewer();
viewer.setContentProvider(new LibraryTreeContentProvider());
viewer.setLabelProvider(new LibraryLabelProvider());
LibraryViewDragSourceAdapter dndAdapter = new LibraryViewDragSourceAdapter(
viewer);
viewer.addDragSupport(dndAdapter.getSupportedDNDOperations(),
new Transfer[] { dndAdapter.getPreferredTransfer() },
dndAdapter);
viewer.setInput(IPrototypeService.INSTANCE.getAllPrototypes().toArray());
viewer.addFilter(new LibraryViewerFilter());
getViewSite().setSelectionProvider(viewer);
getSite().getWorkbenchWindow().getPartService()
.addPartListener(editorActivationListener);
}
/** Switches to the given workbench editor part. */
private void switchWorkbenchEditor(IEditorPart editor) {
if (activeBindingEditor != null) {
activeBindingEditor
.removeBindingEditorListener(bindingEditorPageChangeListener);
activeBindingEditor = null;
}
if (editor instanceof ExtendableMultiPageEditor) {
activeBindingEditor = (ExtendableMultiPageEditor) editor;
activeBindingEditor
.addBindingEditorListener(bindingEditorPageChangeListener);
updateEditorFilters(activeBindingEditor.getActiveModelEditor());
} else if (editor != null) {
updateEditorFilters(editor);
}
}
/** Updates the filters according to the given editor. */
@SuppressWarnings("unchecked")
private void updateEditorFilters(IEditorPart editor) {
supportedBaseClasses.clear();
if (editor instanceof EditorBase
&& ((EditorBase<? extends EObject>) editor).enableLibraryView()) {
EditorBase<? extends EObject> editorBase = (EditorBase<? extends EObject>) editor;
containerObject = editorBase.getEditedObject();
for (Class<? extends EObject> clazz : editorBase
.getVisibleEObjectTypes()) {
supportedBaseClasses.addAll(IPrototypeService.INSTANCE
.getComposablePrototypes(clazz));
}
} else {
containerObject = null;
}
if (!viewer.getControl().isDisposed()) {
viewer.refresh();
}
}
/** {@inheritDoc} */
@Override
public void setFocus() {
viewer.getControl().setFocus();
}
/** The label provider used in the library view. */
private class LibraryLabelProvider extends LabelProvider {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
if (element instanceof Prototype) {
Prototype prototype = (Prototype) element;
return prototype.getName();
}
return super.getText(element);
}
/** {@inheritDoc} */
@Override
public Image getImage(Object element) {
if (element instanceof Prototype) {
Prototype prototype = (Prototype) element;
// delegate to the model element handlers
IModelElementHandler<EObject> handler = IModelElementHandlerService.INSTANCE
.getModelElementHandler(prototype.getPrototype());
if (handler != null) {
return handler.getIcon();
}
}
return super.getImage(element);
}
}
/** The content provider used in the library view. */
private class LibraryTreeContentProvider implements ITreeContentProvider {
/** {@inheritDoc} */
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof Object[]) {
return (Object[]) inputElement;
}
return new Object[0];
}
/** {@inheritDoc} */
@Override
public void dispose() {
// ignore
}
/** {@inheritDoc} */
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// ignore
}
/** {@inheritDoc} */
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
/** {@inheritDoc} */
@Override
public Object getParent(Object element) {
return null;
}
/** {@inheritDoc} */
@Override
public boolean hasChildren(Object element) {
return false;
}
}
/** The filter used in the library view. */
private class LibraryViewerFilter extends ViewerFilter {
/** {@inheritDoc} */
@Override
public boolean select(Viewer viewer, Object parentElement,
Object element) {
if (containerObject == null || supportedBaseClasses.isEmpty()) {
return false;
}
return supportedBaseClasses.contains(element);
}
}
/** If an editor in a different Project is opened the Model is reinitialized */
private class EditorActivationListener implements IPartListener {
/**
* Change the tree viewer content whenever workbench part changes.
*/
@Override
public void partActivated(IWorkbenchPart workbenchPart) {
if (!(workbenchPart instanceof IEditorPart)) {
return;
}
IEditorPart part = (IEditorPart) workbenchPart;
switchWorkbenchEditor(part);
}
/** {@inheritDoc} */
@Override
public void partBroughtToTop(IWorkbenchPart part) {
// to react on activated is enough
}
/** {@inheritDoc} */
@Override
public void partClosed(IWorkbenchPart part) {
// nothing to do
}
/** {@inheritDoc} */
@Override
public void partDeactivated(IWorkbenchPart part) {
// nothing to do
}
/** {@inheritDoc} */
@Override
public void partOpened(IWorkbenchPart part) {
// nothing to do
}
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.views;
import java.util.Set;
import org.conqat.lib.commons.collections.IdentityHashSet;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.eclipse.ui.part.ViewPart;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.service.IPrototypeService;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.extension.base.EditorBase;
import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor;
import org.fortiss.tooling.kernel.ui.listener.ExtendableMultiPageEditorPageChangeListener;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
* {@link ViewPart} for the model element library view.
*
* @author hoelzl
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: BCCA1EB912DDAD468B639287D818733B
*/
public class LibraryView extends ViewPart {
/** The viewer. */
private TreeViewer viewer;
/** Filter text field for the tree viewer. */
private FilteredTree filteredTree;
/** Current active {@link ExtendableMultiPageEditor}. */
private ExtendableMultiPageEditor activeBindingEditor = null;
/** Stores the editor activation listener. */
private EditorActivationListener editorActivationListener = new EditorActivationListener();
/** The container object used. */
private EObject containerObject = null;
/** The prototypes supported by the current editor. */
private Set<Prototype> supportedBaseClasses = new IdentityHashSet<Prototype>();
/** Listener for reacting to changes of the embedded editor. */
private final ExtendableMultiPageEditorPageChangeListener bindingEditorPageChangeListener = new ExtendableMultiPageEditorPageChangeListener() {
@Override
public void pageChanged() {
updateEditorFilters(activeBindingEditor.getActiveModelEditor());
}
};
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
filteredTree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL
| SWT.V_SCROLL, patternFilter, false);
viewer = filteredTree.getViewer();
viewer.setContentProvider(new LibraryTreeContentProvider());
viewer.setLabelProvider(new LibraryLabelProvider());
LibraryViewDragSourceAdapter dndAdapter = new LibraryViewDragSourceAdapter(
viewer);
viewer.addDragSupport(dndAdapter.getSupportedDNDOperations(),
new Transfer[] { dndAdapter.getPreferredTransfer() },
dndAdapter);
viewer.setInput(IPrototypeService.INSTANCE.getAllPrototypes().toArray());
viewer.addFilter(new LibraryViewerFilter());
getViewSite().setSelectionProvider(viewer);
getSite().getWorkbenchWindow().getPartService()
.addPartListener(editorActivationListener);
}
/** Switches to the given workbench editor part. */
private void switchWorkbenchEditor(IEditorPart editor) {
if (activeBindingEditor != null) {
activeBindingEditor
.removeBindingEditorListener(bindingEditorPageChangeListener);
activeBindingEditor = null;
}
if (editor instanceof ExtendableMultiPageEditor) {
activeBindingEditor = (ExtendableMultiPageEditor) editor;
activeBindingEditor
.addBindingEditorListener(bindingEditorPageChangeListener);
updateEditorFilters(activeBindingEditor.getActiveModelEditor());
} else if (editor != null) {
updateEditorFilters(editor);
}
}
/** Updates the filters according to the given editor. */
@SuppressWarnings("unchecked")
private void updateEditorFilters(IEditorPart editor) {
supportedBaseClasses.clear();
if (editor instanceof EditorBase
&& ((EditorBase<? extends EObject>) editor).enableLibraryView()) {
EditorBase<? extends EObject> editorBase = (EditorBase<? extends EObject>) editor;
containerObject = editorBase.getEditedObject();
for (Class<? extends EObject> clazz : editorBase
.getVisibleEObjectTypes()) {
supportedBaseClasses.addAll(IPrototypeService.INSTANCE
.getComposablePrototypes(clazz));
}
} else {
containerObject = null;
}
if (!viewer.getControl().isDisposed()) {
viewer.refresh();
}
}
/** {@inheritDoc} */
@Override
public void setFocus() {
viewer.getControl().setFocus();
}
/** The label provider used in the library view. */
private class LibraryLabelProvider extends LabelProvider {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
if (element instanceof Prototype) {
Prototype prototype = (Prototype) element;
return prototype.getName();
}
return super.getText(element);
}
/** {@inheritDoc} */
@Override
public Image getImage(Object element) {
if (element instanceof Prototype) {
Prototype prototype = (Prototype) element;
// delegate to the model element handlers
IModelElementHandler<EObject> handler = IModelElementHandlerService.INSTANCE
.getModelElementHandler(prototype.getPrototype());
if (handler != null) {
return handler.getIcon();
}
}
return super.getImage(element);
}
}
/** The content provider used in the library view. */
private class LibraryTreeContentProvider implements ITreeContentProvider {
/** {@inheritDoc} */
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof Object[]) {
return (Object[]) inputElement;
}
return new Object[0];
}
/** {@inheritDoc} */
@Override
public void dispose() {
// ignore
}
/** {@inheritDoc} */
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// ignore
}
/** {@inheritDoc} */
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
/** {@inheritDoc} */
@Override
public Object getParent(Object element) {
return null;
}
/** {@inheritDoc} */
@Override
public boolean hasChildren(Object element) {
return false;
}
}
/** The filter used in the library view. */
private class LibraryViewerFilter extends ViewerFilter {
/** {@inheritDoc} */
@Override
public boolean select(Viewer viewer, Object parentElement,
Object element) {
if (containerObject == null || supportedBaseClasses.isEmpty()) {
return false;
}
return supportedBaseClasses.contains(element);
}
}
/** If an editor in a different Project is opened the Model is reinitialized */
private class EditorActivationListener implements IPartListener {
/**
* Change the tree viewer content whenever workbench part changes.
*/
@Override
public void partActivated(IWorkbenchPart workbenchPart) {
if (!(workbenchPart instanceof IEditorPart)) {
return;
}
IEditorPart part = (IEditorPart) workbenchPart;
switchWorkbenchEditor(part);
}
/** {@inheritDoc} */
@Override
public void partBroughtToTop(IWorkbenchPart part) {
// to react on activated is enough
}
/** {@inheritDoc} */
@Override
public void partClosed(IWorkbenchPart part) {
// nothing to do
}
/** {@inheritDoc} */
@Override
public void partDeactivated(IWorkbenchPart part) {
// nothing to do
}
/** {@inheritDoc} */
@Override
public void partOpened(IWorkbenchPart part) {
// nothing to do
}
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.views;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionDragSourceAdapter;
/**
* Drag and drop support for {@link LibraryView}.
*
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: C27A60ED7A9CF15253ED52862AACC49F
*/
public class LibraryViewDragSourceAdapter extends
ElementCompositionDragSourceAdapter {
/** Library tree viewer */
private final TreeViewer libraryViewer;
/** Constructor */
public LibraryViewDragSourceAdapter(TreeViewer libraryViewer) {
this.libraryViewer = libraryViewer;
}
/** {@inheritDoc} */
@Override
protected EObject getSourceElement() {
IStructuredSelection sel = (IStructuredSelection) libraryViewer
.getSelection();
return ((Prototype) sel.getFirstElement()).getPrototypeCopy();
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.views;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.ui.dnd.ElementCompositionDragSourceAdapter;
/**
* Drag and drop support for {@link LibraryView}.
*
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: C27A60ED7A9CF15253ED52862AACC49F
*/
public class LibraryViewDragSourceAdapter extends
ElementCompositionDragSourceAdapter {
/** Library tree viewer */
private final TreeViewer libraryViewer;
/** Constructor */
public LibraryViewDragSourceAdapter(TreeViewer libraryViewer) {
this.libraryViewer = libraryViewer;
}
/** {@inheritDoc} */
@Override
protected EObject getSourceElement() {
IStructuredSelection sel = (IStructuredSelection) libraryViewer
.getSelection();
return ((Prototype) sel.getFirstElement()).getPrototypeCopy();
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.listener;
import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor;
/**
* Listener for page changes of the {@link ExtendableMultiPageEditor}.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: 91B289F5381A5A8C733F4A3E702E455D
*/
public interface ExtendableMultiPageEditorPageChangeListener {
/** Indicates a page change. */
void pageChanged();
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.listener;
import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor;
/**
* Listener for page changes of the {@link ExtendableMultiPageEditor}.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: 91B289F5381A5A8C733F4A3E702E455D
*/
public interface ExtendableMultiPageEditorPageChangeListener {
/** Indicates a page change. */
void pageChanged();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment