PageRenderTime 68ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/SeeIT3D/src/seeit3d/internal/SeeIT3D.java

https://github.com/davidmr/seeit3d
Java | 144 lines | 104 code | 18 blank | 22 comment | 2 complexity | 925448fdd01d44becc0ef7330fc041ce MD5 | raw file
  1. /**
  2. *
  3. * Copyright 2011 David Montaño
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package seeit3d.internal;
  18. import org.eclipse.core.commands.Command;
  19. import org.eclipse.core.resources.IWorkspace;
  20. import org.eclipse.core.resources.ResourcesPlugin;
  21. import org.eclipse.core.runtime.IProgressMonitor;
  22. import org.eclipse.core.runtime.IStatus;
  23. import org.eclipse.core.runtime.Status;
  24. import org.eclipse.jface.preference.IPreferenceStore;
  25. import org.eclipse.swt.widgets.Display;
  26. import org.eclipse.swt.widgets.Shell;
  27. import org.eclipse.ui.PlatformUI;
  28. import org.eclipse.ui.commands.ICommandService;
  29. import org.eclipse.ui.progress.UIJob;
  30. import seeit3d.internal.base.SeeIT3DModule;
  31. import seeit3d.internal.base.core.api.ISeeIT3DPreferences;
  32. import seeit3d.internal.base.error.ErrorHandler;
  33. import seeit3d.internal.base.ui.ide.commands.ChangeSortingPolyCylindersCriteriaCommand;
  34. import seeit3d.internal.base.ui.ide.observers.WorkspaceClosedObserver;
  35. import seeit3d.internal.base.visual.api.IColorScaleRegistry;
  36. import seeit3d.internal.base.visual.api.IRelationshipsRegistry;
  37. import seeit3d.internal.base.visual.colorscale.imp.BlueGreenRed;
  38. import seeit3d.internal.base.visual.colorscale.imp.BlueToYellow;
  39. import seeit3d.internal.base.visual.colorscale.imp.BlueTone;
  40. import seeit3d.internal.base.visual.colorscale.imp.ColdToHotColorScale;
  41. import seeit3d.internal.base.visual.colorscale.imp.GrayColorScale;
  42. import seeit3d.internal.base.visual.colorscale.imp.HeatedObject;
  43. import seeit3d.internal.base.visual.colorscale.imp.LinearOptimal;
  44. import seeit3d.internal.base.visual.colorscale.imp.MagentaTone;
  45. import seeit3d.internal.base.visual.colorscale.imp.Rainbow;
  46. import seeit3d.internal.base.visual.relationships.imp.ArcBasedGenerator;
  47. import seeit3d.internal.base.visual.relationships.imp.CommonBaseGenerator;
  48. import seeit3d.internal.base.visual.relationships.imp.LineBaseGenerator;
  49. import seeit3d.internal.base.visual.relationships.imp.MovementBasedGenerator;
  50. import seeit3d.internal.base.visual.relationships.imp.NoRelationships;
  51. import com.google.inject.Guice;
  52. import com.google.inject.Injector;
  53. /**
  54. * Class in charge of loading contributions and initialize data for the plugin
  55. *
  56. * @author David Montaño
  57. *
  58. */
  59. public class SeeIT3D {
  60. private static Injector injector;
  61. public static void initialize() {
  62. try {
  63. injector = Guice.createInjector(new SeeIT3DModule());
  64. initializeColorScales();
  65. initializeRelationshipsGenerator();
  66. initializePreferences();
  67. initializeSortRadio();
  68. registerGlobalListener();
  69. ErrorHandler.setShell(new Shell(Display.getDefault()));
  70. } catch (Exception e) {
  71. ErrorHandler.error(e);
  72. }
  73. }
  74. private static void initializeColorScales() {
  75. IColorScaleRegistry registry = injector.getInstance(IColorScaleRegistry.class);
  76. registry.registerColorScale(new BlueTone());
  77. registry.registerColorScale(new BlueToYellow());
  78. registry.registerColorScale(new BlueGreenRed());
  79. registry.registerColorScale(new ColdToHotColorScale());
  80. registry.registerColorScale(new GrayColorScale());
  81. registry.registerColorScale(new HeatedObject());
  82. registry.registerColorScale(new LinearOptimal());
  83. registry.registerColorScale(new MagentaTone());
  84. registry.registerColorScale(new Rainbow());
  85. }
  86. private static void initializeRelationshipsGenerator() {
  87. IRelationshipsRegistry registry = injector.getInstance(IRelationshipsRegistry.class);
  88. registry.registerRelationshipGenerator(NoRelationships.class);
  89. registry.registerRelationshipGenerator(CommonBaseGenerator.class);
  90. registry.registerRelationshipGenerator(LineBaseGenerator.class);
  91. registry.registerRelationshipGenerator(ArcBasedGenerator.class);
  92. registry.registerRelationshipGenerator(MovementBasedGenerator.class);
  93. }
  94. private static void initializePreferences() {
  95. ISeeIT3DPreferences preferences = injector.getInstance(ISeeIT3DPreferences.class);
  96. IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
  97. preferences.setPreferencesDefaults(preferenceStore);
  98. preferences.loadStoredPreferences(preferenceStore);
  99. preferenceStore.addPropertyChangeListener(preferences);
  100. }
  101. private static void registerGlobalListener() {
  102. IWorkspace workspace = ResourcesPlugin.getWorkspace();
  103. workspace.addResourceChangeListener(new WorkspaceClosedObserver());
  104. }
  105. private static void initializeSortRadio() {
  106. UIJob job = new UIJob("InitSortRadioState") {
  107. @Override
  108. public IStatus runInUIThread(IProgressMonitor monitor) {
  109. ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class);
  110. Command command = commandService.getCommand(ChangeSortingPolyCylindersCriteriaCommand.CHANGE_SORT_COMMAND_ID);
  111. command.isEnabled();
  112. return new Status(IStatus.OK, Activator.PLUGIN_ID, "Init commands workaround performed succesfully");
  113. }
  114. };
  115. job.schedule();
  116. }
  117. public static Injector injector() {
  118. checkInitialized();
  119. return injector;
  120. }
  121. private static void checkInitialized() {
  122. if (injector == null) {
  123. throw new IllegalStateException("SeeIT 3D not initialized");
  124. }
  125. }
  126. }